repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

fix(system): allow absent empty collections

7f2caf5f2a21d5271ced2777f27370b9e21f61ca

Oliver Jan Krylow <oliver@bugabinga.net> ·

SSH signature · not checked

Browse filesCompare with HEAD

Changed files (5)

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

Modified
30 30 const markdown = (id: string, type = "spec", extra = "") =>
31 31 `---\nid: ${id}\ntype: ${type}\ntitle: Contract${extra}\n---\n\n# Contract\n`;
32 32 const validSystem = (root: string) => {
33 - for (const directory of ["specs", "phases", "plans", "issues", "research"])
34 - mkdirSync(path.join(root, ".system", directory), { recursive: true });
35 33 for (const file of ["SYSTEM.md", "MISSION.md", "RULES.md"])
36 34 write(root, `.system/${file}`, `# ${file}\n`);
37 35 write(root, ".system/config.json", '{"prefix":"PX","schemaVersion":0}');
75 73 describe("system doctor", () => {
76 - it("requires config, cores, and typed directories but not CSS", () => {
74 + it("requires the system root, config, and cores but not empty collections", () => {
77 75 const root = temporaryRoot();
78 76 const result = runDoctor(root);
79 77 assert.deepEqual(
85 83 ".system/SYSTEM.md filesystem.missing",
86 84 ".system/board.json filesystem.missing",
87 85 ".system/config.json filesystem.missing",
88 - ".system/issues filesystem.missing",
89 - ".system/phases filesystem.missing",
90 - ".system/plans filesystem.missing",
91 - ".system/research filesystem.missing",
92 - ".system/specs filesystem.missing",
90 + it("rejects collection paths that are not regular directories", () => {
91 + const root = temporaryRoot();
92 + const outside = temporaryRoot();
93 + validSystem(root);
94 + write(root, ".system/issues", "not a directory");
95 + assert.deepEqual(
96 + runDoctor(root).diagnostics.map(({ code, path }) => `${path} ${code}`),
97 + [".system/issues bundle.expected-directory"],
98 + );
99 + rmSync(path.join(root, ".system/issues"));
100 + symlinkSync(outside, path.join(root, ".system/issues"), "dir");
101 + assert.deepEqual(
102 + runDoctor(root).diagnostics.map(({ code, path }) => `${path} ${code}`),
103 + [".system/issues bundle.symbolic-link"],
104 + );
105 + });
97 107 it("combines shared bundle, graph, and test diagnostics", () => {
98 108 const root = temporaryRoot();
99 109 validSystem(root);

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

Modified
76 76 readFileSync(path.join(project, ".system/RULES.md"), "utf8"),
77 77 /Concrete operating constraints/,
79 + for (const directory of ["specs", "phases", "plans", "issues", "research"])
80 + assert.equal(
81 + lstatSync(path.join(project, ".system", directory), {
82 + throwIfNoEntry: false,
83 + }),
84 + undefined,
85 + );
79 86 const before = ["SYSTEM.md", "MISSION.md", "RULES.md"].map((name) => {
80 87 const target = path.join(project, ".system", name);
81 88 return [name, readFileSync(target, "utf8"), lstatSync(target).mtimeMs];

extensions/the-system/doctor.ts

Modified
20 20 exitCode: 0 | 1;
23 -const SYSTEM_DIRECTORIES = [
24 - ".system",
25 - ".system/specs",
26 - ".system/phases",
27 - ".system/plans",
28 - ".system/issues",
29 - ".system/research",
30 -] as const;
23 +const SYSTEM_DIRECTORIES = [".system"] as const;
31 24 const SYSTEM_FILES = [
32 25 ".system/config.json",
33 26 BOARD_PATH,

extensions/the-system/documents.ts

Modified
589 589 const directoryStats = lstatSync(absoluteDirectory, {
590 590 throwIfNoEntry: false,
592 - if (!directoryStats?.isDirectory() || directoryStats.isSymbolicLink())
592 + if (!directoryStats) continue;
593 + if (directoryStats.isSymbolicLink()) {
594 + diagnostics.push(
595 + diagnostic(
596 + "bundle.symbolic-link",
597 + relativeDirectory,
598 + `Bundle path is a symbolic link: ${relativeDirectory}`,
599 + ),
600 + );
593 601 continue;
603 + if (!directoryStats.isDirectory()) {
604 + diagnostics.push(
605 + diagnostic(
606 + "bundle.expected-directory",
607 + relativeDirectory,
608 + `Expected a document collection directory: ${relativeDirectory}`,
609 + ),
610 + );
611 + continue;
594 613 for (const entry of readdirSync(absoluteDirectory, {
595 614 withFileTypes: true,
596 615 }).sort((left, right) => left.name.localeCompare(right.name))) {

extensions/the-system/init.ts

Modified
32 32 pending: readonly string[];
35 -const DIRECTORIES = [
36 - ".system",
35 +const DIRECTORIES = [".system"] as const;
36 +const COLLECTION_DIRECTORIES = [
37 37 ".system/specs",
38 38 ".system/phases",
39 39 ".system/plans",
106 106 ): InitializationInspection {
107 107 const root = discoverProjectRoot(cwd);
108 108 for (const relative of DIRECTORIES) requireKind(root, relative, "directory");
109 + for (const relative of COLLECTION_DIRECTORIES)
110 + requireKind(root, relative, "directory");
109 111 const configKind = requireKind(root, CONFIG, "file");
110 112 const boardKind = requireKind(root, BOARD_PATH, "file");
111 113 const requested = requestedPrefix