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";
55 55 const snapshot = (root
: string)
=> {
56 - const entries
: { path
: string; content
?: string; mode
: number; mtimeMs
: number }[]
= [];
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---/);
78 + /^---\ndescription: Diagnose The System without mutation\n---/,
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);
103 + documents.
includes(contract),
104 + `missing document contract: ${contract}`,
106 + assert.
doesNotMatch(
108 + /initialize|SYSTEM\.md|MISSION\.md|RULES\.md/i,
103 112 it(
"discovers doctor resources from both package manifests",
async ()
=> {
141 - relativeResources(path.
resolve(
root,
"../.."), repository.prompts).
includes(
142 - "extensions/the-system/prompts/system-doctor.md",
151 + path.
resolve(
root,
"../.."),
152 + repository.prompts,
153 + ).
includes(
"extensions/the-system/prompts/system-doctor.md"),
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";
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 => ({
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,
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(
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),
148 + root: path.
resolve(cwd),
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}`),
161 + "filesystem.missing",
163 + `Missing directory ${relative}`,
149 167 for (
const relative
of SYSTEM_FILES) {
extensions/the-system/prompts/system-doctor.md
Modified2 2 description: Diagnose The System without mutation
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
Modified858 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`);
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}
`);