-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompatibility_test.js
More file actions
306 lines (265 loc) · 8.92 KB
/
Copy pathcompatibility_test.js
File metadata and controls
306 lines (265 loc) · 8.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#!/usr/bin/env -S deno test --allow-read --allow-write --allow-run
// SPDX-License-Identifier: MPL-2.0
// K9 Coordination Protocol — Compatibility Tests
// Verify backward/forward compatibility of K9 schema versions.
// Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
import { assertEquals, assertStringIncludes, assert } from "jsr:@std/assert@1";
import { join } from "jsr:@std/path@1";
import { existsSync } from "jsr:@std/fs@1/exists";
const GENERATOR = join(import.meta.dirname, "generate.js");
// ---------------------------------------------------------------------------
// Compat: minimal v1.0.0 schema generates correctly
// ---------------------------------------------------------------------------
Deno.test("Compat: v1.0.0 minimal schema", async () => {
const tmpDir = await Deno.makeTempDir({ prefix: "k9-compat-min-" });
const k9File = join(tmpDir, "coordination.k9");
await Deno.writeTextFile(k9File, `K9!
---
metadata:
schema: k9-coordination
schema_version: 1.0.0
project:
name: "compat-test"
description: "Minimal v1.0.0"
invariants:
- id: basic
rule: "Basic rule"
reason: "Basic reason"
`);
try {
const cmd = new Deno.Command("deno", {
args: ["run", "--allow-read", "--allow-write", GENERATOR, k9File],
stdout: "piped", stderr: "piped",
});
const { code } = await cmd.output();
assertEquals(code, 0);
assert(existsSync(join(tmpDir, "AGENTS.md")));
} finally {
await Deno.remove(tmpDir, { recursive: true });
}
});
// ---------------------------------------------------------------------------
// Compat: v1.0.0 full schema with all optional sections
// ---------------------------------------------------------------------------
Deno.test("Compat: v1.0.0 full schema with all sections", async () => {
const tmpDir = await Deno.makeTempDir({ prefix: "k9-compat-full-" });
const k9File = join(tmpDir, "coordination.k9");
await Deno.writeTextFile(k9File, `K9!
---
metadata:
schema: k9-coordination
schema_version: 1.0.0
generated_by: k9-coordination-generator
last_updated: 2026-04-03
project:
name: "full-test"
description: "Full v1.0.0 with all sections"
license: PMPL-1.0-or-later
repo: "hyperpolymath/full-test"
languages:
- Rust
- ReScript
build_system: just
runtime: deno
build_commands:
just build: "Full build"
just test: "Run tests"
invariants:
- id: no-ts
rule: "No TypeScript"
reason: "ReScript only"
severity: critical
- id: moderate-rule
rule: "Prefer X"
reason: "Because Y"
severity: moderate
protected:
- path: src/
reason: "Source code"
- path: .machine_readable/
reason: "A2ML files"
architecture:
- id: gossamer
decision: "Gossamer backend"
reason: "Migrated from Tauri"
alternatives_rejected:
- Tauri
- Electron
do_not_create:
- pattern: "**/*.ts"
reason: "TypeScript banned"
- description: "REST API"
reason: "Groove only"
terminology:
- correct: panels
incorrect:
- panes
- tabs
context: "Always panels"
ports:
dev: 8000
api: 3000
ecosystem:
depends_on:
- name: gossamer
role: "Backend"
consumed_by:
- name: other-project
role: "Consumer"
related:
- name: sibling
role: "Sibling"
coordination:
active:
- agent: claude
area: "Main feature"
started: 2026-04-03
status: in-progress
completed:
- agent: cursor
area: "CSS refactor"
completed: 2026-04-02
available:
- "Documentation"
- "Integration tests"
`);
try {
const cmd = new Deno.Command("deno", {
args: ["run", "--allow-read", "--allow-write", GENERATOR, k9File],
stdout: "piped", stderr: "piped",
});
const { code } = await cmd.output();
assertEquals(code, 0);
const content = await Deno.readTextFile(join(tmpDir, "AGENTS.md"));
// Verify all sections rendered
assertStringIncludes(content, "full-test");
assertStringIncludes(content, "Build Commands");
assertStringIncludes(content, "INVARIANTS");
assertStringIncludes(content, "Protected Files");
assertStringIncludes(content, "Architecture Decisions");
assertStringIncludes(content, "Do NOT Create");
assertStringIncludes(content, "Terminology");
assertStringIncludes(content, "Port Assignments");
assertStringIncludes(content, "Ecosystem Context");
assertStringIncludes(content, "Active Coordination");
assertStringIncludes(content, "Available work");
} finally {
await Deno.remove(tmpDir, { recursive: true });
}
});
// ---------------------------------------------------------------------------
// Compat: missing optional sections don't break generation
// ---------------------------------------------------------------------------
Deno.test("Compat: missing optional sections generate cleanly", async () => {
const optionalSections = [
"architecture", "do_not_create", "terminology", "ports",
"ecosystem", "coordination", "build_commands", "protected",
];
// Test with ONLY project + invariants (all optional sections missing)
const tmpDir = await Deno.makeTempDir({ prefix: "k9-compat-missing-" });
const k9File = join(tmpDir, "coordination.k9");
await Deno.writeTextFile(k9File, `K9!
---
project:
name: "bare-bones"
invariants:
- id: one-rule
rule: "One rule"
reason: "One reason"
`);
try {
const cmd = new Deno.Command("deno", {
args: ["run", "--allow-read", "--allow-write", GENERATOR, k9File],
stdout: "piped", stderr: "piped",
});
const { code } = await cmd.output();
assertEquals(code, 0);
const content = await Deno.readTextFile(join(tmpDir, "AGENTS.md"));
assertStringIncludes(content, "bare-bones");
assertStringIncludes(content, "One rule");
// Should NOT contain headers for missing optional sections
for (const section of ["Architecture Decisions", "Do NOT Create",
"Terminology", "Port Assignments", "Ecosystem Context", "Active Coordination"]) {
assertEquals(
content.includes(section), false,
`Should not render ${section} header when data is absent`
);
}
} finally {
await Deno.remove(tmpDir, { recursive: true });
}
});
// ---------------------------------------------------------------------------
// Compat: unknown future sections are ignored (forward compat)
// ---------------------------------------------------------------------------
Deno.test("Compat: unknown sections are silently ignored (forward compatibility)", async () => {
const tmpDir = await Deno.makeTempDir({ prefix: "k9-compat-future-" });
const k9File = join(tmpDir, "coordination.k9");
await Deno.writeTextFile(k9File, `K9!
---
metadata:
schema: k9-coordination
schema_version: 2.0.0
project:
name: "future-test"
invariants:
- id: x
rule: "x"
reason: "x"
future_section_v2:
fancy_feature: "enabled"
quantum_bits: 42
another_future_thing:
- wow: "new"
- such: "future"
`);
try {
const cmd = new Deno.Command("deno", {
args: ["run", "--allow-read", "--allow-write", GENERATOR, k9File],
stdout: "piped", stderr: "piped",
});
const { code } = await cmd.output();
assertEquals(code, 0, "Future sections should not cause failure");
const content = await Deno.readTextFile(join(tmpDir, "AGENTS.md"));
assertStringIncludes(content, "future-test");
} finally {
await Deno.remove(tmpDir, { recursive: true });
}
});
// ---------------------------------------------------------------------------
// Compat: real-world K9 files parse and generate (backward compat)
// ---------------------------------------------------------------------------
Deno.test("Compat: real ASS coordination.k9 from disk", async () => {
const assK9 = "/var/mnt/eclipse/repos/airborne-submarine-squadron/coordination.k9";
if (!existsSync(assK9)) return;
const tmpDir = await Deno.makeTempDir({ prefix: "k9-compat-ass-" });
try {
const cmd = new Deno.Command("deno", {
args: ["run", "--allow-read", "--allow-write", GENERATOR, assK9, "--output-dir", tmpDir],
stdout: "piped", stderr: "piped",
});
const { code } = await cmd.output();
assertEquals(code, 0);
assert(existsSync(join(tmpDir, "AGENTS.md")));
assert(existsSync(join(tmpDir, ".cursorrules")));
} finally {
await Deno.remove(tmpDir, { recursive: true });
}
});
Deno.test("Compat: real PanLL coordination.k9 from disk", async () => {
const panllK9 = "/var/mnt/eclipse/repos/panll/coordination.k9";
if (!existsSync(panllK9)) return;
const tmpDir = await Deno.makeTempDir({ prefix: "k9-compat-panll-" });
try {
const cmd = new Deno.Command("deno", {
args: ["run", "--allow-read", "--allow-write", GENERATOR, panllK9, "--output-dir", tmpDir],
stdout: "piped", stderr: "piped",
});
const { code } = await cmd.output();
assertEquals(code, 0);
assert(existsSync(join(tmpDir, "AGENTS.md")));
assert(existsSync(join(tmpDir, ".cursorrules")));
} finally {
await Deno.remove(tmpDir, { recursive: true });
}
});