Skip to content

Commit 9ef37d1

Browse files
committed
test: tighten assertions and harness coverage
1 parent f62618f commit 9ef37d1

822 files changed

Lines changed: 8929 additions & 6544 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎extensions/acpx/src/config.test.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ describe("embedded acpx plugin config", () => {
9898
});
9999

100100
const server = resolved.mcpServers["openclaw-plugin-tools"];
101-
expect(server).toBeDefined();
101+
expect(server).toMatchObject({
102+
command: process.execPath,
103+
args: expect.any(Array),
104+
});
102105
expect(server.command).toBe(process.execPath);
103106
expect(Array.isArray(server.args)).toBe(true);
104107
expect(server.args?.length).toBeGreaterThan(0);
@@ -113,7 +116,10 @@ describe("embedded acpx plugin config", () => {
113116
});
114117

115118
const server = resolved.mcpServers["openclaw-tools"];
116-
expect(server).toBeDefined();
119+
expect(server).toMatchObject({
120+
command: process.execPath,
121+
args: expect.any(Array),
122+
});
117123
expect(server.command).toBe(process.execPath);
118124
expect(Array.isArray(server.args)).toBe(true);
119125
expect(server.args?.length).toBeGreaterThan(0);

‎extensions/acpx/src/manifest.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe("acpx package manifest", () => {
1212
fs.readFileSync(new URL("../package.json", import.meta.url), "utf8"),
1313
) as AcpxPackageManifest;
1414

15-
expect(packageJson.dependencies?.acpx).toBeDefined();
15+
expect(packageJson.dependencies?.acpx).toEqual(expect.any(String));
1616
expect(packageJson.dependencies?.["@zed-industries/codex-acp"]).toBe("0.13.0");
1717
expect(packageJson.dependencies?.["@agentclientprotocol/claude-agent-acp"]).toBe("0.32.0");
1818
expect(packageJson.devDependencies?.["@agentclientprotocol/claude-agent-acp"]).toBeUndefined();

‎extensions/acpx/src/service.test.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,15 @@ describe("createAcpxRuntimeService", () => {
325325
await service.start(ctx);
326326

327327
const backend = getAcpRuntimeBackend("acpx");
328-
expect(backend?.runtime).toBeDefined();
328+
if (!backend) {
329+
throw new Error("expected ACPX runtime backend");
330+
}
331+
expect(backend.runtime).toMatchObject({
332+
ensureSession: expect.any(Function),
333+
});
329334
expect(acpxRuntimeConstructorMock).not.toHaveBeenCalled();
330335

331-
await backend?.runtime.ensureSession({
336+
await backend.runtime.ensureSession({
332337
agent: "codex",
333338
mode: "oneshot",
334339
sessionKey: "agent:codex:acp:test",
@@ -509,7 +514,9 @@ describe("createAcpxRuntimeService", () => {
509514
await service.start(ctx);
510515

511516
expect(probeAvailability).not.toHaveBeenCalled();
512-
expect(getAcpRuntimeBackend("acpx")).toBeTruthy();
517+
expect(getAcpRuntimeBackend("acpx")).toMatchObject({
518+
runtime: expect.any(Object),
519+
});
513520

514521
await service.stop?.(ctx);
515522
});

‎extensions/active-memory/index.test.ts‎

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,17 @@ describe("active-memory plugin", () => {
156156
vi
157157
.mocked(api.logger.warn)
158158
.mock.calls.some((call: unknown[]) => String(call[0]).includes(needle));
159+
const expectPrependContextResult = (result: unknown) => {
160+
expect(result).toMatchObject({
161+
prependContext: expect.any(String),
162+
});
163+
};
164+
const requireNonEmptyString = (value: unknown, message: string): string => {
165+
if (typeof value !== "string" || value.length === 0) {
166+
throw new Error(message);
167+
}
168+
return value;
169+
};
159170

160171
beforeEach(async () => {
161172
vi.clearAllMocks();
@@ -931,7 +942,7 @@ describe("active-memory plugin", () => {
931942
);
932943

933944
expect(runEmbeddedPiAgent).toHaveBeenCalledTimes(1);
934-
expect(result).toBeDefined();
945+
expectPrependContextResult(result);
935946
});
936947

937948
it("skips sessions whose conversation id is in deniedChatIds even when chat type is allowed", async () => {
@@ -1033,7 +1044,7 @@ describe("active-memory plugin", () => {
10331044
);
10341045

10351046
expect(runEmbeddedPiAgent).toHaveBeenCalledTimes(1);
1036-
expect(result).toBeDefined();
1047+
expectPrependContextResult(result);
10371048
});
10381049

10391050
it("matches per-peer direct session keys (agent:<id>:direct:<peer>)", async () => {
@@ -1057,7 +1068,7 @@ describe("active-memory plugin", () => {
10571068
);
10581069

10591070
expect(runEmbeddedPiAgent).toHaveBeenCalledTimes(1);
1060-
expect(result).toBeDefined();
1071+
expectPrependContextResult(result);
10611072
});
10621073

10631074
it("matches per-account-channel-peer direct session keys (agent:<id>:<channel>:<account>:direct:<peer>)", async () => {
@@ -1082,7 +1093,7 @@ describe("active-memory plugin", () => {
10821093
);
10831094

10841095
expect(runEmbeddedPiAgent).toHaveBeenCalledTimes(1);
1085-
expect(result).toBeDefined();
1096+
expectPrependContextResult(result);
10861097
});
10871098

10881099
it("strips :thread:<id> suffix before matching allowedChatIds (group)", async () => {
@@ -1109,7 +1120,7 @@ describe("active-memory plugin", () => {
11091120
);
11101121

11111122
expect(runEmbeddedPiAgent).toHaveBeenCalledTimes(1);
1112-
expect(result).toBeDefined();
1123+
expectPrependContextResult(result);
11131124
});
11141125

11151126
it("strips :thread:<id> suffix before matching deniedChatIds (direct)", async () => {
@@ -1630,13 +1641,13 @@ describe("active-memory plugin", () => {
16301641
const deprecationMessage = warnCalls
16311642
.map(([first]) => (typeof first === "string" ? first : ""))
16321643
.find((message) => message.includes("config.modelFallbackPolicy is deprecated"));
1633-
expect(deprecationMessage).toBeDefined();
1644+
const message = requireNonEmptyString(deprecationMessage, "deprecation warning missing");
16341645
// Positive: the warning describes chain-resolution last-resort behavior.
1635-
expect(deprecationMessage).toContain("chain-resolution");
1636-
expect(deprecationMessage).toContain("last-resort");
1646+
expect(message).toContain("chain-resolution");
1647+
expect(message).toContain("last-resort");
16371648
// Negative: the warning explicitly disclaims runtime failover, since
16381649
// that's the wrong mental model the previous wording invited.
1639-
expect(deprecationMessage).toMatch(/NOT a runtime failover/i);
1650+
expect(message).toMatch(/NOT a runtime failover/i);
16401651
});
16411652

16421653
it("does not use a built-in fallback model even when default-remote is configured", async () => {
@@ -1760,9 +1771,9 @@ describe("active-memory plugin", () => {
17601771
const debugLine = entries?.[0]?.lines.find((line) =>
17611772
line.startsWith("🔎 Active Memory Debug:"),
17621773
);
1763-
expect(debugLine).toBeDefined();
1764-
expect(debugLine).toContain("backend=qmd");
1765-
expect(debugLine).toContain("hits=3");
1774+
const line = requireNonEmptyString(debugLine, "active memory debug line missing");
1775+
expect(line).toContain("backend=qmd");
1776+
expect(line).toContain("hits=3");
17661777
});
17671778

17681779
it("replaces stale structured active-memory lines on a later empty run", async () => {
@@ -2033,6 +2044,7 @@ describe("active-memory plugin", () => {
20332044
it("returns partial transcript text on timeout when transcripts are temporary by default", async () => {
20342045
__testing.setMinimumTimeoutMsForTests(1);
20352046
__testing.setSetupGraceTimeoutMsForTests(0);
2047+
__testing.setTimeoutPartialDataGraceMsForTests(100);
20362048
api.pluginConfig = {
20372049
agents: ["main"],
20382050
timeoutMs: 250,
@@ -2299,9 +2311,9 @@ describe("active-memory plugin", () => {
22992311
maxBytes: 10 * 1024 * 1024,
23002312
});
23012313

2302-
expect(result).toBeTruthy();
2303-
expect(result?.length).toBeLessThanOrEqual(128);
2304-
expect(result).toContain("alpha beta gamma");
2314+
const partialText = requireNonEmptyString(result, "partial assistant text missing");
2315+
expect(partialText.length).toBeLessThanOrEqual(128);
2316+
expect(partialText).toContain("alpha beta gamma");
23052317
expect(readFileSpy).not.toHaveBeenCalled();
23062318
});
23072319

@@ -2953,9 +2965,9 @@ describe("active-memory plugin", () => {
29532965
.mocked(api.logger.info)
29542966
.mock.calls.map((call: unknown[]) => String(call[0]));
29552967
const startLine = infoLines.find((line: string) => line.includes(" start timeoutMs="));
2956-
expect(startLine).toBeTruthy();
2957-
expect(startLine && startLine.length < 500).toBe(true);
2958-
expect(startLine).toContain("...");
2968+
const line = requireNonEmptyString(startLine, "active memory start log line missing");
2969+
expect(line.length).toBeLessThan(500);
2970+
expect(line).toContain("...");
29592971
});
29602972

29612973
it("uses a canonical agent session key when only sessionId is available", async () => {

‎extensions/amazon-bedrock/index.test.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,10 @@ describe("amazon-bedrock provider plugin", () => {
539539
const discovery = pluginJson.configSchema?.properties?.discovery;
540540
const guardrail = pluginJson.configSchema?.properties?.guardrail;
541541

542-
expect(discovery).toBeDefined();
543-
expect(discovery.type).toBe("object");
544-
expect(discovery.additionalProperties).toBe(false);
542+
expect(discovery).toMatchObject({
543+
type: "object",
544+
additionalProperties: false,
545+
});
545546
expect(discovery.properties.enabled).toEqual({ type: "boolean" });
546547
expect(discovery.properties.region).toEqual({ type: "string" });
547548
expect(discovery.properties.providerFilter).toEqual({
@@ -561,9 +562,10 @@ describe("amazon-bedrock provider plugin", () => {
561562
minimum: 1,
562563
});
563564

564-
expect(guardrail).toBeDefined();
565-
expect(guardrail.type).toBe("object");
566-
expect(guardrail.additionalProperties).toBe(false);
565+
expect(guardrail).toMatchObject({
566+
type: "object",
567+
additionalProperties: false,
568+
});
567569

568570
// Required fields
569571
expect(guardrail.required).toEqual(["guardrailIdentifier", "guardrailVersion"]);

‎extensions/anthropic/index.test.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function createModelRegistry(models: ProviderRuntimeModel[]) {
4848
}
4949

5050
describe("anthropic provider replay hooks", () => {
51-
it("registers the claude-cli backend", async () => {
51+
it("registers the claude-cli backend", () => {
5252
const captured = capturePluginRegistration({ register: anthropicPlugin.register });
5353

5454
expect(captured.cliBackends).toContainEqual(
@@ -383,9 +383,11 @@ describe("anthropic provider replay hooks", () => {
383383
const provider = await registerSingleProviderPlugin(anthropicPlugin);
384384
const cliAuth = provider.auth.find((entry) => entry.id === "cli");
385385

386-
expect(cliAuth).toBeDefined();
386+
if (!cliAuth) {
387+
throw new Error("expected Anthropic CLI auth method");
388+
}
387389

388-
const result = await cliAuth?.run({
390+
const result = await cliAuth.run({
389391
config: {},
390392
} as never);
391393

‎extensions/anthropic/stream-wrappers.test.ts‎

Lines changed: 51 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,15 @@ describe("anthropic stream wrappers", () => {
8888
it("strips context-1m for Claude CLI or legacy token auth and warns", () => {
8989
const warn = vi.spyOn(__testing.log, "warn").mockImplementation(() => undefined);
9090
const headers = runWrapper("sk-ant-oat01-123");
91-
expect(headers?.["anthropic-beta"]).toBeDefined();
92-
expect(headers?.["anthropic-beta"]).toContain(OAUTH_BETA);
91+
expect(headers?.["anthropic-beta"]).toEqual(expect.stringContaining(OAUTH_BETA));
9392
expect(headers?.["anthropic-beta"]).not.toContain(CONTEXT_1M_BETA);
9493
expect(warn).toHaveBeenCalledOnce();
9594
});
9695

9796
it("keeps context-1m for API key auth", () => {
9897
const warn = vi.spyOn(__testing.log, "warn").mockImplementation(() => undefined);
9998
const headers = runWrapper("sk-ant-api-123");
100-
expect(headers?.["anthropic-beta"]).toBeDefined();
101-
expect(headers?.["anthropic-beta"]).toContain(CONTEXT_1M_BETA);
99+
expect(headers?.["anthropic-beta"]).toEqual(expect.stringContaining(CONTEXT_1M_BETA));
102100
expect(warn).not.toHaveBeenCalled();
103101
});
104102

@@ -165,80 +163,70 @@ describe("createAnthropicThinkingPrefillWrapper", () => {
165163
});
166164
});
167165

168-
describe("createAnthropicFastModeWrapper", () => {
169-
function runFastModeWrapper(params: {
170-
apiKey?: string;
171-
provider?: string;
172-
api?: string;
173-
baseUrl?: string;
174-
enabled?: boolean;
175-
}): Record<string, unknown> | undefined {
176-
return runPayloadWrapper(params, (base) =>
177-
createAnthropicFastModeWrapper(base, params.enabled ?? true),
178-
);
179-
}
166+
type ServiceTierWrapperParams = {
167+
apiKey?: string;
168+
provider?: string;
169+
api?: string;
170+
enabled?: boolean;
171+
serviceTier?: "auto" | "standard_only";
172+
};
173+
174+
const serviceTierWrapperCases: Array<{
175+
name: string;
176+
run: (params: ServiceTierWrapperParams) => Record<string, unknown> | undefined;
177+
}> = [
178+
{
179+
name: "fast mode",
180+
run: (params) =>
181+
runPayloadWrapper(params, (base) =>
182+
createAnthropicFastModeWrapper(base, params.enabled ?? true),
183+
),
184+
},
185+
{
186+
name: "explicit service tier",
187+
run: (params) =>
188+
runPayloadWrapper(params, (base) =>
189+
createAnthropicServiceTierWrapper(base, params.serviceTier ?? "auto"),
190+
),
191+
},
192+
];
180193

181-
it("does not inject service_tier for OAuth token", () => {
182-
const payload = runFastModeWrapper({ apiKey: "sk-ant-oat01-test-token" });
194+
describe("Anthropic service_tier payload wrappers", () => {
195+
it.each(serviceTierWrapperCases)("$name skips service_tier for OAuth token", ({ run }) => {
196+
const payload = run({ apiKey: "sk-ant-oat01-test-token" });
183197
expect(payload?.service_tier).toBeUndefined();
184198
});
185199

186-
it("injects service_tier for regular API keys", () => {
187-
const payload = runFastModeWrapper({ apiKey: "sk-ant-api03-test-key" });
200+
it.each(serviceTierWrapperCases)("$name injects service_tier for regular API keys", ({ run }) => {
201+
const payload = run({ apiKey: "sk-ant-api03-test-key" });
188202
expect(payload?.service_tier).toBe("auto");
189203
});
190204

191-
it("injects service_tier=standard_only when disabled for API keys", () => {
192-
const payload = runFastModeWrapper({ apiKey: "sk-ant-api03-test-key", enabled: false });
193-
expect(payload?.service_tier).toBe("standard_only");
194-
});
205+
it.each(serviceTierWrapperCases)(
206+
"$name does not inject service_tier for non-anthropic provider",
207+
({ run }) => {
208+
const payload = run({
209+
apiKey: "sk-ant-api03-test-key",
210+
provider: "openai",
211+
api: "openai-completions",
212+
});
213+
expect(payload?.service_tier).toBeUndefined();
214+
},
215+
);
195216

196-
it("does not inject service_tier for non-anthropic provider", () => {
197-
const payload = runFastModeWrapper({
217+
it("fast mode injects service_tier=standard_only when disabled for API keys", () => {
218+
const payload = serviceTierWrapperCases[0].run({
198219
apiKey: "sk-ant-api03-test-key",
199-
provider: "openai",
200-
api: "openai-completions",
220+
enabled: false,
201221
});
202-
expect(payload?.service_tier).toBeUndefined();
203-
});
204-
});
205-
206-
describe("createAnthropicServiceTierWrapper", () => {
207-
function runServiceTierWrapper(params: {
208-
apiKey?: string;
209-
provider?: string;
210-
api?: string;
211-
serviceTier?: "auto" | "standard_only";
212-
}): Record<string, unknown> | undefined {
213-
return runPayloadWrapper(params, (base) =>
214-
createAnthropicServiceTierWrapper(base, params.serviceTier ?? "auto"),
215-
);
216-
}
217-
218-
it("does not inject service_tier for OAuth token", () => {
219-
const payload = runServiceTierWrapper({ apiKey: "sk-ant-oat01-test-token" });
220-
expect(payload?.service_tier).toBeUndefined();
221-
});
222-
223-
it("injects service_tier for regular API keys", () => {
224-
const payload = runServiceTierWrapper({ apiKey: "sk-ant-api03-test-key" });
225-
expect(payload?.service_tier).toBe("auto");
222+
expect(payload?.service_tier).toBe("standard_only");
226223
});
227224

228-
it("injects service_tier=standard_only for regular API keys", () => {
229-
const payload = runServiceTierWrapper({
225+
it("explicit service tier injects service_tier=standard_only for regular API keys", () => {
226+
const payload = serviceTierWrapperCases[1].run({
230227
apiKey: "sk-ant-api03-test-key",
231228
serviceTier: "standard_only",
232229
});
233230
expect(payload?.service_tier).toBe("standard_only");
234231
});
235-
236-
it("does not inject service_tier for non-anthropic provider", () => {
237-
const payload = runServiceTierWrapper({
238-
apiKey: "sk-ant-api03-test-key",
239-
provider: "openai",
240-
api: "openai-completions",
241-
});
242-
expect(payload?.service_tier).toBeUndefined();
243-
});
244232
});

0 commit comments

Comments
 (0)