repositories / pi-ext
pi-ext
bugabingas pi extensions
owned by bugabinga
extensions/terse/__tests__/harness.test.ts
RawFile outline
- terse pi-test-harness line 5
- t line 6
- afterEach line 8
- loads in real Pi extension runtime line 13
- injects before Pi footer line 19
- appends when Pi footer is absent line 28
- defines no-announcement and language preservation rules line 32
- includes one terse example line 38
- defines a brutal default response budget line 42
- anchors the live React probe as a no-code terse example line 49
- does not duplicate existing terse block line 56
- still injects when prompt only mentions the terse heading line 62
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}`,
);
});
});