repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

test(leaks): lock spec validation ledger

ebc35a59d8632948377543f2e25044f42dcfdc48

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (1)

extensions/leaks/__tests__/ledger.test.ts

Added
new file mode 100644
1 +import { readFileSync } from "node:fs";
2 +import path from "node:path";
3 +import { describe, expect, it } from "vitest";
5 +const specPath = path.resolve(import.meta.dirname, "../SPEC.md");
6 +const spec = readFileSync(specPath, "utf8");
8 +const expectedHeadings = [
9 + "Authority",
10 + "Mission",
11 + "Core requirements",
12 + "Core model",
13 + "Pi integration strategy",
14 + "Settings",
15 + "Built-in detection",
16 + "Dotenv and environment values",
17 + "False positives",
18 + "UX and commands",
19 + "Validation ledger",
20 + "Non-goals",
21 +];
23 +const batches = [
24 + "V0 scope",
25 + "V1 provider boundary",
26 + "V2 placeholders",
27 + "V3 settings",
28 + "V4 built-ins",
29 + "V5 learned values",
30 + "V6 component parsers",
31 + "V7 false positives",
32 + "V8 UX",
33 + "V9 performance/failure",
34 +];
36 +const sectionBatchMap = new Map<string, string[]>([
37 + ["Authority", ["V0 scope"]],
38 + ["Mission", ["V0 scope", "V1 provider boundary"]],
39 + [
40 + "Core requirements",
41 + ["V1 provider boundary", "V8 UX", "V9 performance/failure"],
42 + ],
43 + ["Core model", ["V2 placeholders"]],
44 + ["Pi integration strategy", ["V1 provider boundary"]],
45 + ["Settings", ["V3 settings", "V9 performance/failure"]],
46 + ["Built-in detection", ["V4 built-ins"]],
47 + [
48 + "Dotenv and environment values",
49 + ["V5 learned values", "V6 component parsers", "V7 false positives"],
50 + ],
51 + ["False positives", ["V6 component parsers", "V7 false positives"]],
52 + ["UX and commands", ["V8 UX"]],
53 + ["Validation ledger", ["V0 scope"]],
54 + ["Non-goals", ["V0 scope"]],
55 +]);
57 +const normativeMarker =
58 + /\b(must|must not|should|do not|never|only|requires?|required|accepted|planned|rejected|out of scope|non-goals?|always|at worst|when|on)\b/i;
60 +function sections() {
61 + const result: Array<{ name: string; body: string }> = [];
62 + const matches = [...spec.matchAll(/^## (.+)$/gm)];
63 + for (let index = 0; index < matches.length; index++) {
64 + const match = matches[index];
65 + const next = matches[index + 1];
66 + result.push({
67 + name: String(match[1]),
68 + body: spec.slice(match.index! + match[0].length, next?.index),
69 + });
70 + }
71 + return result;
74 +function normativeSentences(body: string) {
75 + return body
76 + .replace(/```[\s\S]*?```/g, "")
77 + .split(/(?<=[.!?])\s+|\n+-\s+/g)
78 + .map((line) => line.trim())
79 + .filter((line) => normativeMarker.test(line));
82 +describe("leaks spec validation ledger", () => {
83 + it("keeps the spec section map stable", () => {
84 + const headings = sections().map((section) => section.name);
85 + expect(headings).toEqual(expectedHeadings);
86 + });
88 + it("records every validation batch in the ledger and evidence table", () => {
89 + for (const batch of batches) {
90 + expect(spec).toContain(`| ${batch}`);
91 + }
92 + });
94 + it("maps every normative sentence to at least one validation batch", () => {
95 + const misses = sections().flatMap((section) => {
96 + const mappedBatches = sectionBatchMap.get(section.name) ?? [];
97 + return normativeSentences(section.body)
98 + .filter(() => mappedBatches.length === 0)
99 + .map((sentence) => ({ section: section.name, sentence }));
100 + });
101 + expect(misses).toEqual([]);
102 + });
104 + it("keeps V0 authority and scope requirements explicit", () => {
105 + expect(spec).toContain("This spec is the source of truth");
106 + expect(spec).toContain("current implementation is a prototype/reference");
107 + expect(spec).toContain("Implementation must be fresh and spec-shaped");
108 + expect(spec).toContain("Avoid creating `extensions/leaks-ref`");
109 + expect(spec).toContain("Non-goals");
110 + });
111 +});