repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

test(the-system): complete doctor phase gate

aa4e81935818bf98b41bf2608b789c42c2df5898

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (5)

extensions/the-system/__tests__/doctor.test.ts

Modified
3 3 import assert from "node:assert/strict";
4 4 import { spawnSync } from "node:child_process";
5 5 import {
6 6 mkdirSync,
7 7 mkdtempSync,
8 - readFileSync,
9 8 readdirSync,
9 + readFileSync,
10 10 rmSync,
11 11 statSync,
12 12 writeFileSync,
55 55 const snapshot = (root: string) => {
56 - const entries: { path: string; content?: string; mode: number; mtimeMs: number }[] = [];
56 + const entries: {
57 + path: string;
58 + content?: string;
59 + mode: number;
60 + mtimeMs: number;
61 + }[] = [];
57 62 const visit = (directory: string) => {
58 63 for (const entry of readdirSync(directory, { withFileTypes: true }).sort(
59 64 (left, right) => left.name.localeCompare(right.name),

extensions/the-system/__tests__/workflow-skills.test.ts

Modified
73 73 const template = prompt("system-doctor");
74 74 const doctor = skill("system-doctor");
76 - assert.match(template, /^---\ndescription: Diagnose The System without mutation\n---/);
76 + assert.match(
77 + template,
78 + /^---\ndescription: Diagnose The System without mutation\n---/,
79 + );
77 80 assert.match(template, /system-doctor skill/);
78 81 assert.doesNotMatch(template, /config\.json|system\.css|readdir|writeFile/);
79 82 assert.match(doctor, /\.\.\/\.\.\/scripts\/doctor\.mjs/);
96 99 "Never open a browser or editor automatically",
97 100 "scripts/doctor.mjs",
99 - assert.ok(documents.includes(contract), `missing document contract: ${contract}`);
100 - assert.doesNotMatch(documents, /initialize|SYSTEM\.md|MISSION\.md|RULES\.md/i);
102 + assert.ok(
103 + documents.includes(contract),
104 + `missing document contract: ${contract}`,
105 + );
106 + assert.doesNotMatch(
107 + documents,
108 + /initialize|SYSTEM\.md|MISSION\.md|RULES\.md/i,
109 + );
103 112 it("discovers doctor resources from both package manifests", async () => {
140 149 assert.ok(
141 - relativeResources(path.resolve(root, "../.."), repository.prompts).includes(
142 - "extensions/the-system/prompts/system-doctor.md",
143 - ),
150 + relativeResources(
151 + path.resolve(root, "../.."),
152 + repository.prompts,
153 + ).includes("extensions/the-system/prompts/system-doctor.md"),
145 155 } finally {
146 156 rmSync(sandbox, { recursive: true, force: true });

extensions/the-system/doctor.ts

Modified
1 -import { readFileSync, readdirSync, statSync } from "node:fs";
1 +import { readdirSync, readFileSync, statSync } from "node:fs";
2 2 import path from "node:path";
3 3 import {
4 4 type Diagnostic,
7 7 parseSystemConfig,
8 8 SCHEMA_VERSION,
9 9 STYLE_VERSION,
10 - SystemDocumentError,
10 + type SystemDocumentError,
11 11 validateAuthoredHtml,
12 12 } from "./documents.ts";
45 45 const TEST_REFERENCE = /SYSTEM-SPEC:\s*([A-Z][A-Z0-9]{1,7}-SPEC-[0-9]{3,})/g;
46 46 const MOCKUP = /^(.*)-mockup-[a-z0-9]+(?:-[a-z0-9]+)*\.html$/;
48 -const diagnostic = (code: string, path: string, message: string): Diagnostic => ({
48 +const diagnostic = (
49 + code: string,
50 + path: string,
51 + message: string,
52 +): Diagnostic => ({
49 53 code,
50 54 path,
51 55 message,
79 83 for (const directory of DOCUMENT_DIRECTORIES) {
80 84 const absoluteDirectory = path.join(root, ".system", directory);
81 85 if (!isDirectory(absoluteDirectory)) continue;
82 - for (const entry of readdirSync(absoluteDirectory, { withFileTypes: true })) {
86 + for (const entry of readdirSync(absoluteDirectory, {
87 + withFileTypes: true,
88 + })) {
83 89 if (!entry.isFile() || !entry.name.endsWith(".html")) continue;
84 90 const relative = `.system/${directory}/${entry.name}`;
85 91 if (directory === "specs" && MOCKUP.test(entry.name)) {
124 130 for (const directory of TEST_DIRECTORIES) scan(path.join(root, directory));
125 131 return references.sort(
126 132 (left, right) =>
127 - left.path.localeCompare(right.path) || left.spec.localeCompare(right.spec),
133 + left.path.localeCompare(right.path) ||
134 + left.spec.localeCompare(right.spec),
134 141 root = discoverProjectRoot(cwd);
135 142 } catch (error) {
136 143 const value = error as SystemDocumentError;
137 - const diagnostics = [diagnostic(value.code, path.resolve(cwd), value.message)];
138 - return { root: path.resolve(cwd), diagnostics, references: [], exitCode: 1 };
144 + const diagnostics = [
145 + diagnostic(value.code, path.resolve(cwd), value.message),
146 + ];
147 + return {
148 + root: path.resolve(cwd),
149 + diagnostics,
150 + references: [],
151 + exitCode: 1,
152 + };
141 155 const diagnostics: Diagnostic[] = [];
143 157 const target = path.join(root, relative);
144 158 if (!isDirectory(target))
145 159 diagnostics.push(
146 - diagnostic("filesystem.missing", relative, `Missing directory ${relative}`),
160 + diagnostic(
161 + "filesystem.missing",
162 + relative,
163 + `Missing directory ${relative}`,
164 + ),
149 167 for (const relative of SYSTEM_FILES) {

extensions/the-system/prompts/system-doctor.md

Modified
1 1 ---
2 2 description: Diagnose The System without mutation
3 3 ---
4 5 Use the system-doctor skill to run deterministic validation for the current project and explain every reported line without changing files.

scripts/extensions.mjs

Modified
857 857 errors.push(
858 858 "root: pi.skills must be ['extensions/the-system/skills', 'extensions/ultra/skills', 'extensions/lazy/skills']",
860 - for (const key of ["prompts", "themes"])
861 - if (key in (pkg.pi ?? {})) errors.push(`root: pi.${key} must be absent`);
860 + if (
861 + JSON.stringify(pkg.pi?.prompts) !==
862 + JSON.stringify(["extensions/the-system/prompts"])
864 + errors.push("root: pi.prompts must be ['extensions/the-system/prompts']");
865 + if ("themes" in (pkg.pi ?? {})) errors.push("root: pi.themes must be absent");
862 866 if (errors.length) {
863 867 for (const e of errors) console.error(`ERROR ${e}`);
864 868 return 1;