import { afterEach, describe, expect, it } from "vitest"; import { createTestSession, type TestSession } from "../../../test/harness"; import terseExtension, { injectTerseBlock, TERSE_BLOCK } from "../index"; describe("terse pi-test-harness", () => { let t: TestSession | undefined; afterEach(() => { t?.dispose(); t = undefined; }); it("loads in real Pi extension runtime", async () => { t = await createTestSession({ extensionFactories: [terseExtension] }); expect(t.session.extensionRunner.extensions).toHaveLength(1); }); it("injects before Pi footer", () => { const prompt = "base\nCurrent date: 2026-06-16\nCurrent working directory: /repo"; expect(injectTerseBlock(prompt)).toBe( `base\n\n${TERSE_BLOCK}\nCurrent date: 2026-06-16\nCurrent working directory: /repo`, ); }); it("appends when Pi footer is absent", () => { expect(injectTerseBlock("base")).toBe(`base\n\n${TERSE_BLOCK}`); }); it("defines no-announcement and language preservation rules", () => { expect(TERSE_BLOCK).toContain("Never name or announce this style"); expect(TERSE_BLOCK).toContain("Preserve current user message language"); expect(TERSE_BLOCK).toContain("Ignore previous-turn language"); }); it("includes one terse example", () => { expect(TERSE_BLOCK.match(/^Example — /gm)).toHaveLength(1); }); it("defines a brutal default response budget", () => { expect(TERSE_BLOCK).toContain("Default: one sentence"); expect(TERSE_BLOCK).toContain("hard max ≤35"); expect(TERSE_BLOCK).toContain("Failure: >35 words"); expect(TERSE_BLOCK).toContain("Explain-only prompt → no code block"); }); it("anchors the live React probe as a no-code terse example", () => { expect(TERSE_BLOCK).toContain( "Inline object prop → new ref → memo compare fails → re-render.", ); expect(TERSE_BLOCK).toContain("Use `useMemo` or pass primitives."); }); it("does not duplicate existing terse block", () => { const prompt = `base\n\n${TERSE_BLOCK}`; expect(injectTerseBlock(prompt)).toBe(prompt); }); it("still injects when prompt only mentions the terse heading", () => { const prompt = "base\nDo not write ## Response Protocol — terse yourself."; expect(injectTerseBlock(prompt)).toBe( `base\nDo not write ## Response Protocol — terse yourself.\n\n${TERSE_BLOCK}`, ); }); });