From 5f00135a446fa50fd3829f0f3b5d74bb45459deb Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 11 May 2026 20:16:36 +0100 Subject: [PATCH] test: guard support helper assertions --- src/acp/control-plane/manager.test.ts | 8 ++++++-- src/acp/translator.lifecycle.test.ts | 1 - src/acp/translator.session-rate-limit.test.ts | 6 ++++-- src/auto-reply/commands-registry.test.ts | 1 - ...andling.targets-active-session-native-stop.e2e.test.ts | 1 - src/crestodian/operations.test.ts | 1 - src/flows/channel-setup.test.ts | 6 ++++-- src/infra/outbound/delivery-queue.recovery.test.ts | 4 +++- src/logging/diagnostic.test.ts | 2 -- src/node-host/invoke-system-run.test.ts | 8 ++++++-- src/plugin-sdk/channel-streaming.test.ts | 1 - src/plugin-sdk/opencode.test.ts | 1 - src/plugin-sdk/provider-stream.test.ts | 1 - 13 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/acp/control-plane/manager.test.ts b/src/acp/control-plane/manager.test.ts index 384623f21fd..65af56bd6a4 100644 --- a/src/acp/control-plane/manager.test.ts +++ b/src/acp/control-plane/manager.test.ts @@ -98,7 +98,9 @@ function createDeferred(): { promise: Promise; resolve: () => void } { } function expectRecordFields(record: unknown, expected: Record) { - expect(record).toBeDefined(); + if (!record || typeof record !== "object") { + throw new Error("Expected record"); + } const actual = record as Record; for (const [key, value] of Object.entries(expected)) { expect(actual[key]).toEqual(value); @@ -136,7 +138,9 @@ function findMockCallFields(mock: ReturnType, expected: Record, expected: Record) { - expect(findMockCallFields(mock, expected)).toBeDefined(); + if (!findMockCallFields(mock, expected)) { + throw new Error(`Expected mock call ${JSON.stringify(expected)}`); + } } function expectNoMockCallFields(mock: ReturnType, expected: Record) { diff --git a/src/acp/translator.lifecycle.test.ts b/src/acp/translator.lifecycle.test.ts index 5bf5c9f5210..e558df40708 100644 --- a/src/acp/translator.lifecycle.test.ts +++ b/src/acp/translator.lifecycle.test.ts @@ -336,7 +336,6 @@ describe("acp translator stable lifecycle handlers", () => { const result = await agent.resumeSession(createResumeSessionRequest("agent:main:work")); expect(result.modes?.currentModeId).toBe("adaptive"); - expect(result.configOptions).toBeDefined(); if (!result.configOptions) { throw new Error("expected resume session config options"); } diff --git a/src/acp/translator.session-rate-limit.test.ts b/src/acp/translator.session-rate-limit.test.ts index 61b7dfdaf86..7f0bad93b4d 100644 --- a/src/acp/translator.session-rate-limit.test.ts +++ b/src/acp/translator.session-rate-limit.test.ts @@ -139,9 +139,11 @@ function configOptions(value: unknown) { function expectConfigOption(options: unknown, id: string, fields: Record) { const option = configOptions(options).find((candidate) => candidate.id === id); - expect(option, `config option ${id}`).toBeDefined(); + if (!option) { + throw new Error(`Expected config option ${id}`); + } for (const [field, value] of Object.entries(fields)) { - expect(option?.[field]).toEqual(value); + expect(option[field]).toEqual(value); } } diff --git a/src/auto-reply/commands-registry.test.ts b/src/auto-reply/commands-registry.test.ts index 152906e3a6b..17033206c93 100644 --- a/src/auto-reply/commands-registry.test.ts +++ b/src/auto-reply/commands-registry.test.ts @@ -592,7 +592,6 @@ describe("commands registry args", () => { }; const args = parseCommandArgs(command, "set foo bar baz"); - expect(args).toBeDefined(); if (!args) { throw new Error("Expected parsed command args"); } diff --git a/src/auto-reply/reply.triggers.trigger-handling.targets-active-session-native-stop.e2e.test.ts b/src/auto-reply/reply.triggers.trigger-handling.targets-active-session-native-stop.e2e.test.ts index d349599ad39..0136cc4f2e0 100644 --- a/src/auto-reply/reply.triggers.trigger-handling.targets-active-session-native-stop.e2e.test.ts +++ b/src/auto-reply/reply.triggers.trigger-handling.targets-active-session-native-stop.e2e.test.ts @@ -236,7 +236,6 @@ async function expectNextRunUsesTargetSession( const runParams = params.runEmbeddedPiAgentMock.mock.calls[0]?.[0] as | Record | undefined; - expect(runParams).toBeDefined(); if (!runParams) { throw new Error("expected embedded PI agent call params"); } diff --git a/src/crestodian/operations.test.ts b/src/crestodian/operations.test.ts index 80440130539..f3f2bbec5b5 100644 --- a/src/crestodian/operations.test.ts +++ b/src/crestodian/operations.test.ts @@ -43,7 +43,6 @@ function expectAuditRecord( function requireFirstMockCall(mock: unknown, label: string): unknown[] { const call = (mock as { mock?: { calls?: unknown[][] } }).mock?.calls?.[0]; - expect(call).toBeDefined(); if (!call) { throw new Error(`missing ${label} call`); } diff --git a/src/flows/channel-setup.test.ts b/src/flows/channel-setup.test.ts index 28e2e98e52b..692bafc82f5 100644 --- a/src/flows/channel-setup.test.ts +++ b/src/flows/channel-setup.test.ts @@ -80,8 +80,10 @@ function makePluginRegistry(overrides: Partial = {}): PluginRegi function callArg(mock: { mock: { calls: unknown[][] } }, index = 0, _type?: (value: T) => T): T { const call = mock.mock.calls[index]; - expect(call).toBeDefined(); - return call?.[0] as T; + if (!call) { + throw new Error(`Expected mock call ${index}`); + } + return call[0] as T; } function expectExternalCatalogInstallCall(index = 0) { diff --git a/src/infra/outbound/delivery-queue.recovery.test.ts b/src/infra/outbound/delivery-queue.recovery.test.ts index 9fd23f47f72..d730d7d5f7b 100644 --- a/src/infra/outbound/delivery-queue.recovery.test.ts +++ b/src/infra/outbound/delivery-queue.recovery.test.ts @@ -24,7 +24,9 @@ vi.mock("./channel-resolution.js", () => ({ function mockCallArg(mock: { mock: { calls: unknown[][] } }, index = 0): unknown { const call = mock.mock.calls[index]; - expect(call).toBeDefined(); + if (!call) { + throw new Error(`Expected mock call ${index}`); + } return call[0]; } diff --git a/src/logging/diagnostic.test.ts b/src/logging/diagnostic.test.ts index fec37c82e89..12806125e8d 100644 --- a/src/logging/diagnostic.test.ts +++ b/src/logging/diagnostic.test.ts @@ -94,7 +94,6 @@ function requireMatchingRecord( const record = item as Record; return Object.entries(fields).every(([key, value]) => Object.is(record[key], value)); }); - expect(found).toBeDefined(); if (!found) { throw new Error(`missing ${label}`); } @@ -104,7 +103,6 @@ function requireMatchingRecord( function requireFirstMockCallArg(mock: unknown, label: string) { const calls = (mock as { mock?: { calls?: unknown[][] } }).mock?.calls; const call = calls?.[0]; - expect(call).toBeDefined(); if (!call) { throw new Error(`missing ${label} call`); } diff --git a/src/node-host/invoke-system-run.test.ts b/src/node-host/invoke-system-run.test.ts index 80e14a36f3b..c962ff0c377 100644 --- a/src/node-host/invoke-system-run.test.ts +++ b/src/node-host/invoke-system-run.test.ts @@ -553,7 +553,9 @@ describe("handleSystemRunInvoke mac app exec host routing", () => { }); const shellWrapperCall = requireMacExecHostCall(shellWrapperInvoke.runViaMacAppExecHost); - expect(shellWrapperCall.approvals).toBeDefined(); + if (shellWrapperCall.approvals === undefined) { + throw new Error("Expected shell-wrapper approvals"); + } expect(shellWrapperCall.request?.command).toEqual([ "/bin/sh", "-lc", @@ -621,7 +623,9 @@ describe("handleSystemRunInvoke mac app exec host routing", () => { const canonicalCwd = fs.realpathSync(tmp); expect(invoke.runCommand).not.toHaveBeenCalled(); const macHostCall = requireMacExecHostCall(invoke.runViaMacAppExecHost); - expect(macHostCall.approvals).toBeDefined(); + if (macHostCall.approvals === undefined) { + throw new Error("Expected Mac host approvals"); + } expect(macHostCall.request?.command).toEqual(["env", "sh", "-c", "echo SAFE"]); expect(macHostCall.request?.rawCommand).toBe('env sh -c "echo SAFE"'); expect(macHostCall.request?.cwd).toBe(canonicalCwd); diff --git a/src/plugin-sdk/channel-streaming.test.ts b/src/plugin-sdk/channel-streaming.test.ts index 0715a746828..7ec391a8ad9 100644 --- a/src/plugin-sdk/channel-streaming.test.ts +++ b/src/plugin-sdk/channel-streaming.test.ts @@ -284,7 +284,6 @@ describe("channel-streaming", () => { name: "write", args: { path: "/tmp/demo/index.html" }, }); - expect(progressLine).toBeDefined(); if (!progressLine) { throw new Error("expected tool progress draft line"); } diff --git a/src/plugin-sdk/opencode.test.ts b/src/plugin-sdk/opencode.test.ts index 735e133d5e0..7dc4a29a57c 100644 --- a/src/plugin-sdk/opencode.test.ts +++ b/src/plugin-sdk/opencode.test.ts @@ -19,7 +19,6 @@ describe("createOpencodeCatalogApiKeyAuthMethod", () => { expect(method.label).toBe("OpenCode Go catalog"); expect(method.hint).toBe("Shared API key for Zen + Go catalogs"); expect(method.kind).toBe("api_key"); - expect(method.wizard).toBeDefined(); if (!method.wizard) { throw new Error("expected OpenCode auth method to include wizard metadata"); } diff --git a/src/plugin-sdk/provider-stream.test.ts b/src/plugin-sdk/provider-stream.test.ts index a4f1d2b727e..e5c92e96296 100644 --- a/src/plugin-sdk/provider-stream.test.ts +++ b/src/plugin-sdk/provider-stream.test.ts @@ -48,7 +48,6 @@ function requireRecord(value: unknown, label: string): Record { } function requirePayload(payload: Record | undefined): Record { - expect(payload).toBeDefined(); if (!payload) { throw new Error("expected captured payload"); }