



























@@ -26,6 +26,33 @@ const runCronIsolatedAgentTurn = await loadRunCronIsolatedAgentTurn();
2626const makeSkillJob = makeIsolatedAgentTurnJob;
2727const makeSkillParams = makeIsolatedAgentTurnParams;
282829+function requireRecord(value: unknown, label: string): Record<string, unknown> {
30+if (typeof value !== "object" || value === null || Array.isArray(value)) {
31+throw new Error(`expected ${label} to be an object`);
32+}
33+return value as Record<string, unknown>;
34+}
35+36+function getMockCallArg(
37+mock: { mock: { calls: readonly unknown[][] } },
38+callIndex: number,
39+argIndex: number,
40+label: string,
41+): unknown {
42+const call = mock.mock.calls[callIndex];
43+if (!call) {
44+throw new Error(`expected ${label} call ${callIndex}`);
45+}
46+return call[argIndex];
47+}
48+49+function getFirstMockArg(
50+mock: { mock: { calls: readonly unknown[][] } },
51+label: string,
52+): Record<string, unknown> {
53+return requireRecord(getMockCallArg(mock, 0, 0, label), `${label} params`);
54+}
55+2956// ---------- tests ----------
30573158describe("runCronIsolatedAgentTurn — skill filter", () => {
@@ -39,8 +66,10 @@ describe("runCronIsolatedAgentTurn — skill filter", () => {
39664067function expectDefaultModelCall(params: { primary: string; fallbacks: string[] }) {
4168expect(runWithModelFallbackMock).toHaveBeenCalledOnce();
42-const callCfg = runWithModelFallbackMock.mock.calls[0][0].cfg;
43-const model = callCfg?.agents?.defaults?.model as { primary?: string; fallbacks?: string[] };
69+const callCfg = getFirstMockArg(runWithModelFallbackMock, "model fallback").cfg as
70+| { agents?: { defaults?: { model?: { primary?: string; fallbacks?: string[] } } } }
71+| undefined;
72+const model = callCfg?.agents?.defaults?.model;
4473expect(model?.primary).toBe(params.primary);
4574expect(model?.fallbacks).toEqual(params.fallbacks);
4675}
@@ -62,10 +91,10 @@ describe("runCronIsolatedAgentTurn — skill filter", () => {
6291agentId: "scout",
6392});
6493expect(buildWorkspaceSkillSnapshotMock).toHaveBeenCalledOnce();
65-expect(buildWorkspaceSkillSnapshotMock.mock.calls[0][1]).toHaveProperty("skillFilter", [
66-"meme-factory",
67-"weather",
68-]);
94+expect(getMockCallArg(buildWorkspaceSkillSnapshotMock, 0, 1, "skill snapshot")).toHaveProperty(
95+"skillFilter",
96+["meme-factory", "weather"],
97+);
6998});
709971100it("omits skillFilter when agent has no skills config", async () => {
@@ -77,7 +106,12 @@ describe("runCronIsolatedAgentTurn — skill filter", () => {
77106});
78107expect(buildWorkspaceSkillSnapshotMock).toHaveBeenCalledOnce();
79108// When no skills config, skillFilter should be undefined (no filtering applied)
80-expect(buildWorkspaceSkillSnapshotMock.mock.calls[0][1].skillFilter).toBeUndefined();
109+expect(
110+requireRecord(
111+getMockCallArg(buildWorkspaceSkillSnapshotMock, 0, 1, "skill snapshot"),
112+"skill snapshot options",
113+).skillFilter,
114+).toBeUndefined();
81115});
8211683117it("passes empty skillFilter when agent explicitly disables all skills", async () => {
@@ -89,7 +123,10 @@ describe("runCronIsolatedAgentTurn — skill filter", () => {
89123});
90124expect(buildWorkspaceSkillSnapshotMock).toHaveBeenCalledOnce();
91125// Explicit empty skills list should forward [] to filter out all skills
92-expect(buildWorkspaceSkillSnapshotMock.mock.calls[0][1]).toHaveProperty("skillFilter", []);
126+expect(getMockCallArg(buildWorkspaceSkillSnapshotMock, 0, 1, "skill snapshot")).toHaveProperty(
127+"skillFilter",
128+[],
129+);
93130});
9413195132it("refreshes cached snapshot when skillFilter changes without version bump", async () => {
@@ -116,15 +153,16 @@ describe("runCronIsolatedAgentTurn — skill filter", () => {
116153agentId: "weather-bot",
117154});
118155expect(buildWorkspaceSkillSnapshotMock).toHaveBeenCalledOnce();
119-expect(buildWorkspaceSkillSnapshotMock.mock.calls[0][1]).toHaveProperty("skillFilter", [
120-"weather",
121-]);
156+expect(getMockCallArg(buildWorkspaceSkillSnapshotMock, 0, 1, "skill snapshot")).toHaveProperty(
157+"skillFilter",
158+["weather"],
159+);
122160});
123161124162it("forces a fresh session for isolated cron runs", async () => {
125163await runSkillFilterCase();
126164expect(resolveCronSessionMock).toHaveBeenCalledOnce();
127-expect(resolveCronSessionMock.mock.calls[0]?.[0]?.forceNew).toBe(true);
165+expect(getFirstMockArg(resolveCronSessionMock, "cron session").forceNew).toBe(true);
128166});
129167130168it("reuses cached snapshot when version and normalized skillFilter are unchanged", async () => {
@@ -204,7 +242,7 @@ describe("runCronIsolatedAgentTurn — skill filter", () => {
204242expect(result.status).toBe("ok");
205243expect(logWarnMock).not.toHaveBeenCalled();
206244expect(runWithModelFallbackMock).toHaveBeenCalledOnce();
207-const runParams = runWithModelFallbackMock.mock.calls[0][0];
245+const runParams = getFirstMockArg(runWithModelFallbackMock, "model fallback");
208246expect(runParams.provider).toBe("anthropic");
209247expect(runParams.model).toBe("claude-sonnet-4-6");
210248});
@@ -329,7 +367,7 @@ describe("runCronIsolatedAgentTurn — skill filter", () => {
329367330368expect(runCliAgentMock).toHaveBeenCalledOnce();
331369// Fresh session: cliSessionId must be undefined, not the stored value.
332-expect(runCliAgentMock.mock.calls[0][0]).toHaveProperty("cliSessionId", undefined);
370+expect(getFirstMockArg(runCliAgentMock, "CLI run")).toHaveProperty("cliSessionId", undefined);
333371});
334372335373it("reuses stored cliSessionId on continuation runs (isNewSession=false)", async () => {
@@ -360,7 +398,7 @@ describe("runCronIsolatedAgentTurn — skill filter", () => {
360398361399expect(runCliAgentMock).toHaveBeenCalledOnce();
362400// Continuation: cliSessionId should be passed through for session resume.
363-expect(runCliAgentMock.mock.calls[0][0]).toHaveProperty(
401+expect(getFirstMockArg(runCliAgentMock, "CLI run")).toHaveProperty(
364402"cliSessionId",
365403"existing-cli-session-def",
366404);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。