|
| 1 | +import { describe, expect, it } from "bun:test"; |
| 2 | +import { GROK_PROMPT_RESIDUAL } from "./model-family-policy.js"; |
| 3 | +import { |
| 4 | + buildGrokLeafAntiThrashNote, |
| 5 | + buildSubAgentSystemPrompt, |
| 6 | +} from "./prompts.js"; |
| 7 | +import { shouldApplyGrokAntiThrash } from "../subagent/provider-family.js"; |
| 8 | + |
| 9 | +// The three Grok ceremony lines (CL-7768 Design, merged by CL-8296): no git, |
| 10 | +// no pre-plan, verify once. |
| 11 | +const CEREMONY_LINES = [ |
| 12 | + "- Never run git add, git commit, git stash, or any other state-changing git command unless the user asks.", |
| 13 | + "- Do not narrate a plan before acting on a small task; act, then report.", |
| 14 | + "- Verify with the test command once at the end, not after every edit.", |
| 15 | +] as const; |
| 16 | + |
| 17 | +function countOccurrences(haystack: string, needle: string): number { |
| 18 | + return haystack.split(needle).length - 1; |
| 19 | +} |
| 20 | + |
| 21 | +describe("grok ceremony merge (CL-8296)", () => { |
| 22 | + it("exposes a single grok residual with each ceremony line exactly once", () => { |
| 23 | + expect(GROK_PROMPT_RESIDUAL).toContain("Finish bias (xAI / Grok worker):"); |
| 24 | + for (const line of CEREMONY_LINES) { |
| 25 | + expect(countOccurrences(GROK_PROMPT_RESIDUAL, line)).toBe(1); |
| 26 | + } |
| 27 | + }); |
| 28 | + |
| 29 | + it("keeps the don't re-read line exactly once — no duplicate", () => { |
| 30 | + expect( |
| 31 | + countOccurrences(GROK_PROMPT_RESIDUAL, "re-open paths you already read"), |
| 32 | + ).toBe(1); |
| 33 | + }); |
| 34 | + |
| 35 | + it("is grok-only: the finish-bias gate fires for grok leaves alone", () => { |
| 36 | + expect( |
| 37 | + shouldApplyGrokAntiThrash({ |
| 38 | + providerName: "xai/default", |
| 39 | + model: "grok-4.6", |
| 40 | + orchestrator: false, |
| 41 | + }), |
| 42 | + ).toBe(true); |
| 43 | + for (const input of [ |
| 44 | + { providerName: "anthropic", model: "claude-sonnet-4" }, |
| 45 | + { providerName: "moonshot", model: "kimi-k2" }, |
| 46 | + { providerName: "opencode-go", model: "muse-spark-1.3-contributor" }, |
| 47 | + { providerName: "openai", model: "gpt-4.1" }, |
| 48 | + ] as const) { |
| 49 | + expect(shouldApplyGrokAntiThrash({ ...input, orchestrator: false })).toBe( |
| 50 | + false, |
| 51 | + ); |
| 52 | + } |
| 53 | + expect( |
| 54 | + shouldApplyGrokAntiThrash({ |
| 55 | + providerName: "xai/default", |
| 56 | + model: "grok-4.6", |
| 57 | + orchestrator: true, |
| 58 | + }), |
| 59 | + ).toBe(false); |
| 60 | + }); |
| 61 | + |
| 62 | + it("buildGrokLeafAntiThrashNote is the same single residual (one source of truth)", () => { |
| 63 | + expect(buildGrokLeafAntiThrashNote()).toBe(GROK_PROMPT_RESIDUAL); |
| 64 | + }); |
| 65 | + |
| 66 | + it("the assembled grok worker prompt carries the merged residual exactly once", () => { |
| 67 | + const prompt = buildSubAgentSystemPrompt(undefined, undefined, undefined, { |
| 68 | + orchestrator: false, |
| 69 | + grokAntiThrash: true, |
| 70 | + }); |
| 71 | + expect(countOccurrences(prompt, "Finish bias (xAI / Grok worker):")).toBe( |
| 72 | + 1, |
| 73 | + ); |
| 74 | + for (const line of CEREMONY_LINES) { |
| 75 | + expect(countOccurrences(prompt, line)).toBe(1); |
| 76 | + } |
| 77 | + }); |
| 78 | +}); |
0 commit comments