Skip to content

Commit 91bf1a3

Browse files
committed
test(prompts): promptResidual appended once for grok leaf
1 parent 2c38c6f commit 91bf1a3

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

‎src/agent/model-family-policy.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,31 @@ describe("resolveModelFamilyPolicy", () => {
102102
expect(muse.toolDisciplineRules).toContain("Never re-read a file");
103103
expect(base.toolDisciplineRules).toBeUndefined();
104104
});
105+
106+
describe("promptResidual (CL-8297)", () => {
107+
test("grok leaf carries the generic 4-line tool-budget residual", () => {
108+
const leaf = resolveModelFamilyPolicy({
109+
providerName: "xai/default",
110+
model: "grok-4.6",
111+
});
112+
expect(leaf.family).toBe("grok");
113+
expect(leaf.promptResidual).toBeDefined();
114+
expect(leaf.promptResidual!.split("\n")).toHaveLength(4);
115+
expect(leaf.promptResidual).toContain("Tool budget:");
116+
});
117+
118+
test("grok orchestrators and default family carry no residual", () => {
119+
const orchestrator = resolveModelFamilyPolicy({
120+
providerName: "xai/default",
121+
model: "grok-4.6",
122+
orchestrator: true,
123+
});
124+
expect(orchestrator.promptResidual).toBeUndefined();
125+
const base = resolveModelFamilyPolicy({
126+
providerName: "anthropic",
127+
model: "claude-sonnet-4",
128+
});
129+
expect(base.promptResidual).toBeUndefined();
130+
});
131+
});
105132
});

‎src/agent/prompt-sizes.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,22 @@ describe("skywalker grok prefix (infer envelope vs trimmed director)", () => {
332332
}
333333
});
334334
});
335+
336+
describe("grok tool-budget residual (CL-8297)", () => {
337+
const countOccurrences = (haystack: string, needle: string): number =>
338+
haystack.split(needle).length - 1;
339+
340+
test("a grok leaf director prompt contains the tool budget exactly once", () => {
341+
const prompt = assembleDirectorPrompt("builder", "grok");
342+
expect(countOccurrences(prompt, "Tool budget:")).toBe(1);
343+
});
344+
345+
test("default-family and orchestrator prompts carry no tool budget", () => {
346+
expect(assembleDirectorPrompt("builder", "default")).not.toContain(
347+
"Tool budget:",
348+
);
349+
expect(assembleDirectorPrompt("skywalker", "grok")).not.toContain(
350+
"Tool budget:",
351+
);
352+
});
353+
});

‎src/agent/prompts.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,29 @@ describe("grok finish-bias residual gating (extends existing provider-family tes
370370
expect(prompt.toLowerCase()).not.toContain("kimi");
371371
});
372372
});
373+
374+
describe("promptResidual assembly (CL-8297)", () => {
375+
const TOOL_BUDGET =
376+
"Tool budget:\n" +
377+
"- Batch independent tool calls into a single turn.\n" +
378+
"- Never re-issue a tool call whose result you already have.\n" +
379+
"- When the next call would only repeat prior work, write the report instead.";
380+
381+
it("appends promptResidual exactly once at the tail for a grok leaf", () => {
382+
const prompt = buildSubAgentSystemPrompt(undefined, undefined, undefined, {
383+
orchestrator: false,
384+
grokAntiThrash: true,
385+
promptResidual: TOOL_BUDGET,
386+
});
387+
expect(countOccurrences(prompt, TOOL_BUDGET)).toBe(1);
388+
expect(prompt.trimEnd().endsWith(TOOL_BUDGET)).toBe(true);
389+
});
390+
391+
it("omits the tool budget when promptResidual is unset", () => {
392+
const prompt = buildSubAgentSystemPrompt(undefined, undefined, undefined, {
393+
orchestrator: false,
394+
grokAntiThrash: true,
395+
});
396+
expect(prompt).not.toContain("Tool budget:");
397+
});
398+
});

0 commit comments

Comments
 (0)