test: guard command mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 10:26:18 +01:00
parent f093033ee8
commit b37a71f2af
10 changed files with 13 additions and 10 deletions
+1 -1
View File
@@ -369,7 +369,7 @@ describe("deliverAgentCommandResult", () => {
expect(runtime.log).toHaveBeenCalledTimes(1);
expect(
JSON.parse(String((runtime.log as ReturnType<typeof vi.fn>).mock.calls[0]?.[0])),
JSON.parse(String((runtime.log as ReturnType<typeof vi.fn>).mock.calls.at(0)?.[0])),
).toEqual({
payloads: [
{
+1 -1
View File
@@ -381,7 +381,7 @@ describe("agentCommand", () => {
);
expect(pluginRegistryMocks.ensurePluginRegistryLoaded).toHaveBeenCalledOnce();
const registryLoad = pluginRegistryMocks.ensurePluginRegistryLoaded.mock.calls[0]?.[0];
const registryLoad = pluginRegistryMocks.ensurePluginRegistryLoaded.mock.calls.at(0)?.[0];
expect(registryLoad?.scope).toBe("all");
expect(registryLoad?.config).toBeTypeOf("object");
expect(registryLoad?.activationSourceConfig).toBeTypeOf("object");
+1 -1
View File
@@ -128,7 +128,7 @@ describe("agents delete command", () => {
await agentsDeleteCommand({ id: "ops", force: true, json: true }, runtime);
expect(gatewayMocks.callGateway).toHaveBeenCalledOnce();
const gatewayCall = gatewayMocks.callGateway.mock.calls[0]?.[0];
const gatewayCall = gatewayMocks.callGateway.mock.calls.at(0)?.[0];
expect(gatewayCall?.method).toBe("agents.delete");
expect(gatewayCall?.params).toEqual({ agentId: "ops", deleteFiles: true });
expect(gatewayCall?.requiredMethods).toEqual(["agents.delete"]);
+1 -1
View File
@@ -43,7 +43,7 @@ async function writeIdentityFile(workspace: string, lines: string[]) {
}
function getWrittenMainIdentity() {
const [written] = configMocks.writeConfigFile.mock.calls[0] ?? [];
const [written] = configMocks.writeConfigFile.mock.calls.at(0) ?? [];
if (!written) {
throw new Error("expected written agent config");
}
@@ -461,7 +461,10 @@ describe("applyAuthChoiceLoadedPluginProvider", () => {
const result = await applyAuthChoiceLoadedPluginProvider(buildParams());
expect(ensureOnboardingPluginInstalled).toHaveBeenCalledOnce();
const [installParams] = ensureOnboardingPluginInstalled.mock.calls[0];
const [installParams] = ensureOnboardingPluginInstalled.mock.calls.at(0) ?? [];
if (installParams === undefined) {
throw new Error("expected plugin install params");
}
expect(installParams.entry?.pluginId).toBe("local-provider-plugin");
expect(installParams.entry?.label).toBe(LOCAL_PROVIDER_LABEL);
expect(installParams.workspaceDir).toBe("/tmp/workspace");
+1 -1
View File
@@ -45,7 +45,7 @@ describe("warnIfModelConfigLooksOff", () => {
expect(loadModelCatalog).not.toHaveBeenCalled();
expect(ensureAuthProfileStore).toHaveBeenCalledOnce();
expect(listProfilesForProvider).toHaveBeenCalledOnce();
const [profileStore, providerId] = listProfilesForProvider.mock.calls[0] as unknown as [
const [profileStore, providerId] = listProfilesForProvider.mock.calls.at(0) as unknown as [
AuthProfileStore,
string,
];
@@ -125,7 +125,7 @@ describe("resolvePreferredProviderForAuthChoice", () => {
}),
).resolves.toBe("demo-provider");
expect(resolvePluginProviders).toHaveBeenCalledOnce();
const [pluginProviderOptions] = resolvePluginProviders.mock.calls[0] as unknown as [
const [pluginProviderOptions] = resolvePluginProviders.mock.calls.at(0) as unknown as [
ResolvePluginProvidersOptions,
];
expect(pluginProviderOptions?.mode).toBe("setup");
@@ -339,7 +339,7 @@ describe("channels command", () => {
// oxlint-disable-next-line typescript/no-unnecessary-type-parameters -- Test helper lets assertions ascribe written config shape.
function getWrittenConfig<T>(): T {
expect(configMocks.writeConfigFile).toHaveBeenCalledTimes(1);
const [config] = configMocks.writeConfigFile.mock.calls[0] ?? [];
const [config] = configMocks.writeConfigFile.mock.calls.at(0) ?? [];
if (config === undefined) {
throw new Error("expected written channel config");
}
+1 -1
View File
@@ -38,7 +38,7 @@ function logLine(params: { module: string; message: string }) {
}
function readJsonPayload() {
return JSON.parse(String(runtime.log.mock.calls[0]?.[0])) as {
return JSON.parse(String(runtime.log.mock.calls.at(0)?.[0])) as {
file: string;
channel: string;
lines: Array<{ message: string }>;
@@ -243,7 +243,7 @@ describe("channelsStatusCommand SecretRef fallback flow", () => {
expect(errors.join("\n")).toContain("Gateway not reachable");
expect(mocks.resolveCommandConfigWithSecrets).toHaveBeenCalledOnce();
const configResolutionRequest = mocks.resolveCommandConfigWithSecrets.mock.calls[0]?.[0];
const configResolutionRequest = mocks.resolveCommandConfigWithSecrets.mock.calls.at(0)?.[0];
expect(configResolutionRequest?.commandName).toBe("channels status");
expect(configResolutionRequest?.mode).toBe("read_only_status");
expect(