pi-ext
bugabingas pi extensions
owned by bugabinga
feat(the-system): expose doctor CLI
0d7d929cf27a2c60a1331c1121761aba8973f560
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
Browse filesCompare with HEAD
Changed files (3)
extensions/the-system/__tests__/doctor.test.ts
Modified 1 1 import assert
from "node:assert/strict";
2 +import { spawnSync }
from "node:child_process";
51 52 write(
root,
".system/system.css",
"/* The System styleVersion: 1 */\n");
55 +const snapshot = (root
: string)
=> {
56 + const entries
: { path
: string; content
?: string; mode
: number; mtimeMs
: number }[]
= [];
57 + const visit = (directory
: string)
=> {
58 + for (
const entry
of readdirSync(directory, { withFileTypes:
true }).
sort(
59 + (left, right)
=> left.
name.
localeCompare(right.
name),
61 + const target
= path.
join(directory, entry.
name);
62 + const stats
= statSync(target);
64 + path: path.
relative(
root, target).
split(path.sep).
join(
"/"),
66 + mtimeMs: stats.mtimeMs,
70 + ? {
...record, content:
readFileSync(target,
"utf8") }
73 + if (entry.
isDirectory())
visit(target);
55 81 for (
const root
of roots.
splice(
0))
56 82 rmSync(
root, { recursive:
true, force:
true });
148 174 assert.
deepEqual(result.references, []);
149 175 assert.
equal(result.exitCode,
0);
178 + it(
"renders stable CLI output, returns status, and does not mutate the tree", ()
=> {
179 + const root
= temporaryRoot();
183 + ".system/specs/PX-SPEC-001-contract.html",
184 + html({ id:
"PX-SPEC-001", type:
"spec" }),
186 + write(
root,
"tests/contract.test.ts",
"// SYSTEM-SPEC: PX-SPEC-001\n");
187 + const before
= snapshot(
root);
188 + const script
= path.
resolve(
import.
meta.dirname,
"../scripts/doctor.mjs");
190 + const green
= spawnSync(
192 + [
"--experimental-strip-types", script,
root],
193 + { encoding:
"utf8", env: {
...process.
env, NODE_NO_WARNINGS:
"1" } },
196 + assert.
equal(green.
status,
0);
199 + `ROOT ${root}\nREF tests/contract.test.ts PX-SPEC-001\nOK The System is valid\n`,
201 + assert.
equal(green.stderr,
"");
202 + assert.
deepEqual(
snapshot(
root), before);
204 + write(
root,
".system/system.css",
"unversioned\n");
205 + const brokenBefore
= snapshot(
root);
206 + const red
= spawnSync(
208 + [
"--experimental-strip-types", script,
root],
209 + { encoding:
"utf8", env: {
...process.
env, NODE_NO_WARNINGS:
"1" } },
212 + assert.
equal(red.
status,
1);
215 + `ROOT ${root}\nREF tests/contract.test.ts PX-SPEC-001\nERROR css.version .system/system.css: Missing The System styleVersion marker\n`,
217 + assert.
equal(red.stderr,
"");
218 + assert.
deepEqual(
snapshot(
root), brokenBefore);
extensions/the-system/documents.ts
Modified 5 5 export const STYLE_VERSION
= 1;
7 7 export class SystemDocumentError extends Error {
9 - readonly code
: string,
8 + readonly code
: string;
10 + constructor(code
: string, message
: string) {
13 13 this.
name = "SystemDocumentError";
extensions/the-system/scripts/doctor.mjs
Addednew file mode 100644 2 +import { runDoctor }
from "../doctor.ts";
4 +const result
= runDoctor(
process.
argv[
2]
?? process.
cwd());
5 +console.
log(
`ROOT ${result.root}
`);
6 +for (
const reference
of result.references)
7 + console.
log(
`REF ${reference.path}
${reference.spec}
`);
8 +for (
const finding
of result.diagnostics)
9 + console.
log(
`ERROR ${finding.code}
${finding.path}
: ${finding.message}
`);
10 +if (result.exitCode
=== 0)
console.
log(
"OK The System is valid");
11 +process.
exitCode = result.exitCode;