test: tighten cli runner assertions

This commit is contained in:
Peter Steinberger
2026-05-09 15:00:46 +01:00
parent 50cb027a88
commit 42033929d4
2 changed files with 74 additions and 49 deletions

View File

@@ -68,7 +68,8 @@ describe("loadPromptRefImages", () => {
});
const [ref, workspaceDir, options] = loadImageFromRefSpy.mock.calls[0] ?? [];
expect(ref).toMatchObject({ resolved: "/tmp/photo.png", type: "path" });
expect(ref?.resolved).toBe("/tmp/photo.png");
expect(ref?.type).toBe("path");
expect(workspaceDir).toBe("/workspace");
expect(options).toEqual({
maxBytes: MAX_IMAGE_BYTES,
@@ -468,7 +469,14 @@ describe("writeCliSystemPromptFile", () => {
} finally {
await written.cleanup();
}
await expect(fs.access(written.filePath ?? "")).rejects.toMatchObject({ code: "ENOENT" });
let err: unknown;
try {
await fs.access(written.filePath ?? "");
} catch (caught) {
err = caught;
}
expect(err).toBeInstanceOf(Error);
expect((err as NodeJS.ErrnoException).code).toBe("ENOENT");
});
});

View File

@@ -276,43 +276,57 @@ describe("shouldSkipLocalCliCredentialEpoch", () => {
expect(context.systemPrompt).toBe(
"prepend system\n\nhook system\n\nappend system\n\nCurrent model identity: test-cli/test-model. If asked what model you are, answer with this value for the current run.",
);
expect(hookRunner.runBeforePromptBuild).toHaveBeenCalledWith(
{
prompt: "latest ask",
messages: [
{ role: "user", content: "earlier context", timestamp: 1 },
{
role: "assistant",
content: [{ type: "text", text: "earlier reply" }],
api: "responses",
provider: "test-cli",
model: "test-model",
usage: {
input: 0,
output: 0,
cacheRead: 0,
cacheWrite: 0,
totalTokens: 0,
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
},
stopReason: "stop",
timestamp: 2,
expect(hookRunner.runBeforePromptBuild).toHaveBeenCalledTimes(1);
const beforePromptBuildCalls = hookRunner.runBeforePromptBuild.mock.calls as unknown as Array<
[unknown, unknown]
>;
expect(beforePromptBuildCalls[0]?.[0]).toEqual({
prompt: "latest ask",
messages: [
{ role: "user", content: "earlier context", timestamp: 1 },
{
role: "assistant",
content: [{ type: "text", text: "earlier reply" }],
api: "responses",
provider: "test-cli",
model: "test-model",
usage: {
input: 0,
output: 0,
cacheRead: 0,
cacheWrite: 0,
totalTokens: 0,
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
},
],
},
expect.objectContaining({
runId: "run-test",
agentId: "main",
sessionKey: "agent:main:test",
sessionId: "session-test",
workspaceDir: dir,
modelProviderId: "test-cli",
modelId: "test-model",
messageProvider: "acp",
trigger: "user",
channelId: "telegram",
}),
);
stopReason: "stop",
timestamp: 2,
},
],
});
const hookContext = beforePromptBuildCalls[0]?.[1] as
| {
runId?: string;
agentId?: string;
sessionKey?: string;
sessionId?: string;
workspaceDir?: string;
modelProviderId?: string;
modelId?: string;
messageProvider?: string;
trigger?: string;
channelId?: string;
}
| undefined;
expect(hookContext?.runId).toBe("run-test");
expect(hookContext?.agentId).toBe("main");
expect(hookContext?.sessionKey).toBe("agent:main:test");
expect(hookContext?.sessionId).toBe("session-test");
expect(hookContext?.workspaceDir).toBe(dir);
expect(hookContext?.modelProviderId).toBe("test-cli");
expect(hookContext?.modelId).toBe("test-model");
expect(hookContext?.messageProvider).toBe("acp");
expect(hookContext?.trigger).toBe("user");
expect(hookContext?.channelId).toBe("telegram");
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
@@ -391,17 +405,20 @@ describe("shouldSkipLocalCliCredentialEpoch", () => {
});
expect(context.params.prompt).toBe("turn prepend\n\nlatest ask\n\nturn append");
expect(hookRunner.runAgentTurnPrepare).toHaveBeenCalledWith(
{
prompt: "latest ask",
messages: [],
queuedInjections: [],
},
expect.objectContaining({
runId: "run-test-turn-prepare",
sessionKey: "agent:main:test",
}),
);
expect(hookRunner.runAgentTurnPrepare).toHaveBeenCalledTimes(1);
const agentTurnPrepareCalls = hookRunner.runAgentTurnPrepare.mock.calls as unknown as Array<
[unknown, unknown]
>;
expect(agentTurnPrepareCalls[0]?.[0]).toEqual({
prompt: "latest ask",
messages: [],
queuedInjections: [],
});
const turnPrepareContext = agentTurnPrepareCalls[0]?.[1] as
| { runId?: string; sessionKey?: string }
| undefined;
expect(turnPrepareContext?.runId).toBe("run-test-turn-prepare");
expect(turnPrepareContext?.sessionKey).toBe("agent:main:test");
expect(hookRunner.runBeforePromptBuild).not.toHaveBeenCalled();
expect(hookRunner.runBeforeAgentStart).not.toHaveBeenCalled();
} finally {