@warpgogol/forge 9.6.1 → 9.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/CONTRIBUTING.md +19 -25
  3. package/README.md +42 -18
  4. package/README.uk.md +60 -36
  5. package/dist/os/core/core.module.d.ts.map +1 -1
  6. package/dist/os/core/core.module.js +58 -5
  7. package/dist/os/core/core.module.js.map +1 -1
  8. package/dist/os/core/handlers/package-health.d.ts.map +1 -1
  9. package/dist/os/core/handlers/package-health.js +95 -8
  10. package/dist/os/core/handlers/package-health.js.map +1 -1
  11. package/dist/os/flow/handlers/flow-cut.d.ts.map +1 -1
  12. package/dist/os/flow/handlers/flow-cut.js +27 -6
  13. package/dist/os/flow/handlers/flow-cut.js.map +1 -1
  14. package/dist/src/migration-adapters/ignored-files.d.ts +14 -0
  15. package/dist/src/migration-adapters/ignored-files.d.ts.map +1 -1
  16. package/dist/src/migration-adapters/ignored-files.js +62 -0
  17. package/dist/src/migration-adapters/ignored-files.js.map +1 -1
  18. package/dist/src/migration-adapters/index.d.ts +3 -3
  19. package/dist/src/migration-adapters/index.d.ts.map +1 -1
  20. package/dist/src/migration-adapters/index.js +2 -2
  21. package/dist/src/migration-adapters/index.js.map +1 -1
  22. package/dist/src/migration-adapters/node-typescript-pnpm/index.d.ts.map +1 -1
  23. package/dist/src/migration-adapters/node-typescript-pnpm/index.js +9 -7
  24. package/dist/src/migration-adapters/node-typescript-pnpm/index.js.map +1 -1
  25. package/dist/src/migration-adapters/phaser-pnpm/index.d.ts.map +1 -1
  26. package/dist/src/migration-adapters/phaser-pnpm/index.js +9 -7
  27. package/dist/src/migration-adapters/phaser-pnpm/index.js.map +1 -1
  28. package/dist/src/migration-adapters/types.d.ts +19 -1
  29. package/dist/src/migration-adapters/types.d.ts.map +1 -1
  30. package/dist/src/migration-adapters/types.js +19 -0
  31. package/dist/src/migration-adapters/types.js.map +1 -1
  32. package/dist/src/onboarding/scaffold-project.d.ts.map +1 -1
  33. package/dist/src/onboarding/scaffold-project.js +21 -2
  34. package/dist/src/onboarding/scaffold-project.js.map +1 -1
  35. package/dist/src/validators/skill-doc-sync.d.ts +76 -0
  36. package/dist/src/validators/skill-doc-sync.d.ts.map +1 -0
  37. package/dist/src/validators/skill-doc-sync.js +333 -0
  38. package/dist/src/validators/skill-doc-sync.js.map +1 -0
  39. package/docs/concepts/governance-model.md +9 -1
  40. package/docs/concepts/verification-model.md +31 -0
  41. package/docs/concepts/why-forge.md +1 -1
  42. package/docs/evidence/release-9.6.2.md +31 -0
  43. package/docs/grants/devin-startups.md +25 -0
  44. package/docs/guides/existing-project.md +15 -3
  45. package/docs/guides/skills.md +27 -8
  46. package/docs/guides/upgrading.md +6 -2
  47. package/docs/guides/verification-and-evidence.md +45 -0
  48. package/docs/integrations/devin.md +63 -0
  49. package/docs/reference/cli.md +13 -2
  50. package/docs/reference/fleet-measurement.md +52 -0
  51. package/docs/reference/forge-yaml.md +1 -1
  52. package/docs/reference/programmatic-api.md +62 -33
  53. package/os/core/core.module.ts +70 -11
  54. package/os/core/handlers/package-health.test.ts +104 -23
  55. package/os/core/handlers/package-health.ts +133 -19
  56. package/os/flow/handlers/flow-cut.ts +27 -6
  57. package/os/flow/tests/flow-cut.rerun.test.ts +54 -4
  58. package/package.json +3 -2
  59. package/profiles/forge-shell.yaml +1 -0
  60. package/profiles/godot-game.yaml +1 -0
  61. package/profiles/phaser-game.yaml +1 -0
  62. package/profiles/site-workshop.yaml +1 -0
  63. package/profiles/system.yaml +1 -0
  64. package/profiles/typescript.yaml +1 -0
  65. package/skills/meta/forge-bootstrap/SKILL.md +18 -12
  66. package/src/migration-adapters/ignored-files.ts +64 -0
  67. package/src/migration-adapters/index.ts +19 -3
  68. package/src/migration-adapters/node-typescript-pnpm/index.ts +21 -5
  69. package/src/migration-adapters/phaser-pnpm/index.ts +21 -5
  70. package/src/migration-adapters/types.ts +36 -1
  71. package/src/onboarding/scaffold-project.ts +19 -2
  72. package/src/tests/migration-adapters.test.ts +73 -5
  73. package/src/tests/skill-doc-sync.test.ts +233 -0
  74. package/src/validators/skill-doc-sync.ts +449 -0
@@ -15,6 +15,20 @@ Mechanical v1 to v2 header migration across the workspace: 942 files rewritten
15
15
  <item>RFC-1097: sweep — werkstatt-engine clean
16
16
 
17
17
  Sweep batch 4: 73 Compass headers on headerless engine files (certification, component-runtime, isolation, evolution, testing), real KEY_DECISIONS on 75 files (kernel, cache, dht, swim, gitmesh, runtime), ~80 purpose expansions (CONTRACT-02/PURPOSE-02), non-goals on 13 CONTRACT-03 files, CS-07 history literal fix repo-wide (253 files). Policy: .template.ts/.template.astro excludedPaths. werkstatt-engine now 0 diagnostics.</item>
18
+ <item>RFC-1585: review wave — write-path corruptions, --check flag, scaffold hydration
19
+
20
+ Independent fo-review (isolation: subagent) found: empty marker pairs lost
21
+ their open tag on --write, multi-line regions collapsed line numbers, a
22
+ leading fence injected a phantom line, --check was undocumented-undeclared,
23
+ and --write exited 1 on a successful heal. Fixes: open-marker capture,
24
+ newline-preserving placeholder, empty-chunk skip, check flag, healedRegions
25
+ split (write always exits 0), dryRun/io threading, byte-exact inventory
26
+ compare on the prettier-stable canonical form, CHECK-13 delegated through
27
+ commandRegistry/invoke so the registry-integrity scan stays within its
28
+ slice cap (KNOWN_TRUNCATED_SCANS is shrink-only), record-tree exclusions
29
+ extended, two real stale claims corrected, profile templates ship empty
30
+ markers hydrated at scaffold write time. RFC amended to implemented
31
+ grammar/result/exclusions; command moved to commands.added.</item>
18
32
  </CHANGE_SUMMARY>
19
33
  */
20
34
 
@@ -23,6 +37,7 @@ import { resolveIo } from "../utils/io.ts";
23
37
  import { listStackProfiles, type StackProfile } from "../profiles/stack-profile.ts";
24
38
  import { checkNpmToken, workshopNeedsWarpgogolToken } from "./npm-token-check.ts";
25
39
  import { resolveForgeRoot } from "../config/forge-config.ts";
40
+ import { hydrateSkillDocMarkers } from "../validators/skill-doc-sync.ts";
26
41
  import type {
27
42
  ForgeCommandInput,
28
43
  ForgeCommandResult,
@@ -117,7 +132,8 @@ export async function runScaffoldProject(
117
132
  for (const file of profile.workspace.files) {
118
133
  const filePath = path.join(workspaceRoot, file.path);
119
134
  await fio.mkdir(path.dirname(filePath));
120
- const content = file.content.replace(/__PROJECT_NAME__/g, effectiveProjectName);
135
+ let content = file.content.replace(/__PROJECT_NAME__/g, effectiveProjectName);
136
+ if (file.path.endsWith(".md")) content = hydrateSkillDocMarkers(content);
121
137
  await fio.writeFile(filePath, content);
122
138
  created.push(file.path);
123
139
  }
@@ -170,9 +186,10 @@ export async function runScaffoldProject(
170
186
  const filePath = path.join(wsDir, file.path);
171
187
  await fio.mkdir(path.dirname(filePath));
172
188
  // Replace placeholder names (quoted and bare)
173
- const content = file.content
189
+ let content = file.content
174
190
  .replace(/my-site/g, effectiveProjectName)
175
191
  .replace(/my-game/g, effectiveProjectName);
192
+ if (file.path.endsWith(".md")) content = hydrateSkillDocMarkers(content);
176
193
  await fio.writeFile(filePath, content);
177
194
  created.push(`${wsPath}/${file.path}`);
178
195
  }
@@ -237,7 +237,7 @@ test("migrate skips forge-protected files", async () => {
237
237
  expect(existsSync(join(appDir, "docs", "rfcs", "rfc-0001.md"))).toBe(false);
238
238
  });
239
239
 
240
- test("migrate copies untracked/git-ignored files like .env to apps/<appName>/", async () => {
240
+ test("migrate blocks secret-looking files by default (no git, no allowedPaths)", async () => {
241
241
  const sourceDir = join(tempDir, "source");
242
242
  const targetDir = join(tempDir, "target");
243
243
 
@@ -256,16 +256,84 @@ test("migrate copies untracked/git-ignored files like .env to apps/<appName>/",
256
256
  const analysis = nodeTypescriptPnpmAdapter.analyze(sourceDir);
257
257
  const result = nodeTypescriptPnpmAdapter.migrate(sourceDir, targetDir, analysis);
258
258
 
259
- expect(result.filesCopied).toContain(".env");
260
- expect(result.filesCopied).toContain(".env.local");
259
+ // Secrets are excluded by default — the operator did not opt in.
260
+ expect(result.filesSkipped).toContain(".env");
261
+ expect(result.filesSkipped).toContain(".env.local");
261
262
  expect(result.filesCopied).toContain(".gitignore");
262
263
 
263
264
  const appDir = join(targetDir, "apps", "test-app");
264
- expect(existsSync(join(appDir, ".env"))).toBe(true);
265
- expect(existsSync(join(appDir, ".env.local"))).toBe(true);
265
+ expect(existsSync(join(appDir, ".env"))).toBe(false);
266
+ expect(existsSync(join(appDir, ".env.local"))).toBe(false);
266
267
  expect(existsSync(join(appDir, ".gitignore"))).toBe(true);
267
268
  });
268
269
 
270
+ test("migrate copies secrets only when operator allows them via allowedPaths", async () => {
271
+ const sourceDir = join(tempDir, "source");
272
+ const targetDir = join(tempDir, "target");
273
+
274
+ await mkdir(sourceDir, { recursive: true });
275
+ await mkdir(targetDir, { recursive: true });
276
+
277
+ await writeFile(join(sourceDir, "package.json"), JSON.stringify({ name: "test-app" }));
278
+ await writeFile(join(sourceDir, "tsconfig.json"), "{}");
279
+ await writeFile(join(sourceDir, "pnpm-lock.yaml"), "");
280
+ await writeFile(join(sourceDir, ".env"), "SECRET=hello");
281
+ await writeFile(join(sourceDir, ".env.local"), "API_KEY=secret");
282
+ await writeFile(join(sourceDir, ".gitignore"), ".env\n.env.local\n");
283
+
284
+ const analysis = nodeTypescriptPnpmAdapter.analyze(sourceDir);
285
+ // Operator approved .env but declined .env.local.
286
+ const result = nodeTypescriptPnpmAdapter.migrate(sourceDir, targetDir, analysis, {
287
+ allowedPaths: [".env"],
288
+ });
289
+
290
+ expect(result.filesCopied).toContain(".env");
291
+ expect(result.filesSkipped).toContain(".env.local");
292
+
293
+ const appDir = join(targetDir, "apps", "test-app");
294
+ expect(existsSync(join(appDir, ".env"))).toBe(true);
295
+ expect(existsSync(join(appDir, ".env.local"))).toBe(false);
296
+ });
297
+
298
+ test("migrate honors operator refusal for git-ignored categories (git source)", async () => {
299
+ const sourceDir = join(tempDir, "source");
300
+ const targetDir = join(tempDir, "target");
301
+
302
+ await mkdir(sourceDir, { recursive: true });
303
+ await mkdir(targetDir, { recursive: true });
304
+ await mkdir(join(sourceDir, "data"), { recursive: true });
305
+
306
+ await writeFile(join(sourceDir, "package.json"), JSON.stringify({ name: "test-app" }));
307
+ await writeFile(join(sourceDir, "tsconfig.json"), "{}");
308
+ await writeFile(join(sourceDir, "pnpm-lock.yaml"), "");
309
+ await writeFile(join(sourceDir, ".env"), "SECRET=hello");
310
+ await writeFile(join(sourceDir, "data", "dump.db"), "binary-db");
311
+ await writeFile(join(sourceDir, ".gitignore"), ".env\ndata/\n");
312
+
313
+ const { execSync } = await import("node:child_process");
314
+ execSync("git init", { cwd: sourceDir, stdio: "pipe" });
315
+ execSync('git config user.email "test@test.com"', { cwd: sourceDir, stdio: "pipe" });
316
+ execSync('git config user.name "Test"', { cwd: sourceDir, stdio: "pipe" });
317
+ execSync("git add .gitignore package.json tsconfig.json pnpm-lock.yaml", {
318
+ cwd: sourceDir,
319
+ stdio: "pipe",
320
+ });
321
+ execSync("git commit -m initial", { cwd: sourceDir, stdio: "pipe" });
322
+
323
+ // Operator declined the config/secrets category but approved the data dir.
324
+ const analysis = nodeTypescriptPnpmAdapter.analyze(sourceDir);
325
+ const result = nodeTypescriptPnpmAdapter.migrate(sourceDir, targetDir, analysis, {
326
+ allowedPaths: ["data"],
327
+ });
328
+
329
+ expect(result.filesSkipped).toContain(".env");
330
+ expect(result.filesCopied).toContain("data/dump.db");
331
+
332
+ const appDir = join(targetDir, "apps", "test-app");
333
+ expect(existsSync(join(appDir, ".env"))).toBe(false);
334
+ expect(existsSync(join(appDir, "data", "dump.db"))).toBe(true);
335
+ });
336
+
269
337
  test("migrate excludes .git directory from copy", async () => {
270
338
  const sourceDir = join(tempDir, "source");
271
339
  const targetDir = join(tempDir, "target");
@@ -0,0 +1,233 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>
4
+ Unit tests for RFC-1585 skill.doc-sync — marked-region render/drift, claim lint grammar,
5
+ doc-surface discovery, and the --write path.
6
+ </purpose>
7
+ <non-goals>
8
+ <item>Not a registry contract test — fixtures use synthetic ForgeSkillEntry lists, never FORGE_SKILLS.</item>
9
+ </non-goals>
10
+ </MODULE_CONTRACT>
11
+ <CHANGE_SUMMARY>
12
+ <item>RFC-1585: initial suite — requirement AC-1 (marked-region render), AC-2 (drift detection), AC-3 (claim lint), AC-4 (check gate exit).</item>
13
+ <item>RFC-1585: review wave — write-path corruptions, --check flag, scaffold hydration
14
+
15
+ Independent fo-review (isolation: subagent) found: empty marker pairs lost
16
+ their open tag on --write, multi-line regions collapsed line numbers, a
17
+ leading fence injected a phantom line, --check was undocumented-undeclared,
18
+ and --write exited 1 on a successful heal. Fixes: open-marker capture,
19
+ newline-preserving placeholder, empty-chunk skip, check flag, healedRegions
20
+ split (write always exits 0), dryRun/io threading, byte-exact inventory
21
+ compare on the prettier-stable canonical form, CHECK-13 delegated through
22
+ commandRegistry/invoke so the registry-integrity scan stays within its
23
+ slice cap (KNOWN_TRUNCATED_SCANS is shrink-only), record-tree exclusions
24
+ extended, two real stale claims corrected, profile templates ship empty
25
+ markers hydrated at scaffold write time. RFC amended to implemented
26
+ grammar/result/exclusions; command moved to commands.added.</item>
27
+ </CHANGE_SUMMARY>
28
+ */
29
+
30
+ import { describe, expect, test } from "vitest";
31
+ import * as sfs from "../utils/sync-fs.ts";
32
+ import path from "node:path";
33
+ import os from "node:os";
34
+
35
+ import type { ForgeSkillEntry } from "../registry.ts";
36
+ import {
37
+ collectSkillDocFiles,
38
+ hydrateSkillDocMarkers,
39
+ lintSkillDocContent,
40
+ lintSkillDocFiles,
41
+ renderCountLiteral,
42
+ renderInventoryBlock,
43
+ runSkillDocSync,
44
+ SKILL_DOC_MARKERS,
45
+ } from "../validators/skill-doc-sync.ts";
46
+
47
+ const skill = (name: string, category: ForgeSkillEntry["category"]): ForgeSkillEntry => ({
48
+ name,
49
+ category,
50
+ invocation: "user",
51
+ concerns: "read-only",
52
+ dependsOn: [],
53
+ path: `${category}/${name}/SKILL.md`,
54
+ });
55
+
56
+ // 5 skills: 3 fo + 1 shared + 1 meta — small enough to assert exact strings.
57
+ const SKILLS: ForgeSkillEntry[] = [
58
+ skill("fo-aaa", "fo"),
59
+ skill("fo-bbb", "fo"),
60
+ skill("fo-ccc", "fo"),
61
+ skill("shared-aaa", "shared"),
62
+ skill("meta-aaa", "meta"),
63
+ ];
64
+
65
+ describe("rendering (requirement AC-1)", () => {
66
+ test("count literal decomposes the registry", () => {
67
+ expect(renderCountLiteral(SKILLS)).toBe("5 skills (3 fo + 1 shared + 1 meta)");
68
+ });
69
+
70
+ test("inventory block lists every registry name grouped by category", () => {
71
+ const block = renderInventoryBlock(SKILLS);
72
+ expect(block).toContain("**5 skills** — 3 fo, 1 shared, 1 meta.");
73
+ expect(block).toContain("- **fo (3):** `fo-aaa`, `fo-bbb`, `fo-ccc`");
74
+ expect(block).toContain("- **shared (1):** `shared-aaa`");
75
+ expect(block).toContain("- **meta (1):** `meta-aaa`");
76
+ });
77
+ });
78
+
79
+ describe("marked regions (requirement AC-1, AC-2)", () => {
80
+ test("fresh region passes; stale region drifts", () => {
81
+ const good = `<!-- ${SKILL_DOC_MARKERS.count} -->${renderCountLiteral(SKILLS)}<!-- /${SKILL_DOC_MARKERS.count} -->`;
82
+ expect(lintSkillDocContent("README.md", good, SKILLS).drift).toEqual([]);
83
+
84
+ const stale = `<!-- ${SKILL_DOC_MARKERS.count} -->99 skills (9 fo + 9 shared + 9 meta)<!-- /${SKILL_DOC_MARKERS.count} -->`;
85
+ const outcome = lintSkillDocContent("README.md", stale, SKILLS);
86
+ expect(outcome.markedRegions).toBe(1);
87
+ expect(outcome.drift).toHaveLength(1);
88
+ expect(outcome.drift[0]!.kind).toBe("marked-region");
89
+ });
90
+
91
+ test("--write re-renders only inside markers and stays idempotent", () => {
92
+ const doc = `# Title\n\n<!-- ${SKILL_DOC_MARKERS.count} -->STALE<!-- /${SKILL_DOC_MARKERS.count} -->\n\nTail 7 skills stay authored.\n`;
93
+ // The authored tail claim drifts too — suppress it so only the region is judged.
94
+ const clean = doc.replace("Tail 7 skills stay authored.", "Tail.");
95
+ const once = lintSkillDocContent("README.md", clean, SKILLS, true).rewritten!;
96
+ expect(once).toContain(
97
+ `<!-- ${SKILL_DOC_MARKERS.count} -->${renderCountLiteral(SKILLS)}<!-- /${SKILL_DOC_MARKERS.count} -->`,
98
+ );
99
+ expect(once).toContain("# Title");
100
+ const twice = lintSkillDocContent("README.md", once, SKILLS, true).rewritten!;
101
+ expect(twice).toBe(once);
102
+ });
103
+
104
+ test("inventory region renders inside markers, authored text outside survives", () => {
105
+ const doc = `Intro.\n\n<!-- ${SKILL_DOC_MARKERS.inventory} -->\nold\n<!-- /${SKILL_DOC_MARKERS.inventory} -->\n\nOutro.\n`;
106
+ const out = lintSkillDocContent("docs/guides/skills.md", doc, SKILLS, true).rewritten!;
107
+ expect(out).toContain(renderInventoryBlock(SKILLS));
108
+ expect(out).toContain("Intro.");
109
+ expect(out).toContain("Outro.");
110
+ });
111
+ });
112
+
113
+ describe("claim lint (requirement AC-3)", () => {
114
+ test("stale total, decomposition, and category claims all flag", () => {
115
+ const doc = [
116
+ "Forge ships 41 skills today.", // stale total
117
+ "Split: 33 fo + 5 shared + 3 meta.", // stale decomposition
118
+ "There are 9 fo skills.", // stale category
119
+ ].join("\n");
120
+ const drift = lintSkillDocContent("README.md", doc, SKILLS).drift;
121
+ expect(drift.map((d) => d.kind).sort()).toEqual([
122
+ "claim-category",
123
+ "claim-decomposition",
124
+ "claim-total",
125
+ ]);
126
+ });
127
+
128
+ test("correct claims, exempted lines, and fenced blocks pass", () => {
129
+ const doc = [
130
+ "Forge ships 5 skills today.",
131
+ "Split: 3 fo + 1 shared + 1 meta.",
132
+ "A pack owns 7 skills. <!-- forge-skill-count:ok: project pack count -->",
133
+ "```",
134
+ "example says 99 skills",
135
+ "```",
136
+ ].join("\n");
137
+ expect(lintSkillDocContent("README.md", doc, SKILLS).drift).toEqual([]);
138
+ });
139
+ });
140
+
141
+ describe("surface + command runner (requirement AC-4)", () => {
142
+ test("collectSkillDocFiles covers README variants and docs, skips record trees", () => {
143
+ const root = sfs.mkdtempSync(path.join(os.tmpdir(), "skill-doc-sync-"));
144
+ sfs.mkdirSync(path.join(root, "docs", "guides"), { recursive: true });
145
+ sfs.mkdirSync(path.join(root, "docs", "rfcs"), { recursive: true });
146
+ sfs.writeFileSync(path.join(root, "README.md"), "x");
147
+ sfs.writeFileSync(path.join(root, "README.uk.md"), "x");
148
+ sfs.writeFileSync(path.join(root, "AGENTS.md"), "x");
149
+ sfs.writeFileSync(path.join(root, "docs", "guides", "a.md"), "x");
150
+ sfs.writeFileSync(path.join(root, "docs", "rfcs", "rfc-1.md"), "x");
151
+ sfs.writeFileSync(path.join(root, "CHANGELOG.md"), "x");
152
+ const rel = collectSkillDocFiles(root)
153
+ .map((f) => path.relative(root, f))
154
+ .sort();
155
+ expect(rel).toEqual(["AGENTS.md", "README.md", "README.uk.md", "docs/guides/a.md"]);
156
+ });
157
+
158
+ test("runSkillDocSync fails on drift and --write heals marked regions", async () => {
159
+ const root = sfs.mkdtempSync(path.join(os.tmpdir(), "skill-doc-sync-"));
160
+ const readme = path.join(root, "README.md");
161
+ sfs.writeFileSync(
162
+ readme,
163
+ `<!-- ${SKILL_DOC_MARKERS.count} -->STALE<!-- /${SKILL_DOC_MARKERS.count} -->\n`,
164
+ );
165
+ const check = await runSkillDocSync({ flags: {} }, { workspaceRoot: root });
166
+ expect(check.status).toBe("fail");
167
+ expect(check.drift[0]!.kind).toBe("marked-region");
168
+
169
+ // --write re-renders; a re-check passes with the REAL registry rendered.
170
+ const heal = await runSkillDocSync({ flags: { write: true } }, { workspaceRoot: root });
171
+ expect(heal.written).toEqual(["README.md"]);
172
+ expect(sfs.readFileSync(readme, "utf8")).toContain(renderCountLiteral());
173
+ expect((await runSkillDocSync({ flags: {} }, { workspaceRoot: root })).status).toBe("pass");
174
+ });
175
+
176
+ test("lintSkillDocFiles is the shared per-package composition entry", async () => {
177
+ const root = sfs.mkdtempSync(path.join(os.tmpdir(), "skill-doc-sync-"));
178
+ const f = path.join(root, "README.md");
179
+ sfs.writeFileSync(f, "We ship 41 skills.");
180
+ const outcome = await lintSkillDocFiles(root, [f], SKILLS);
181
+ expect(outcome.drift).toHaveLength(1);
182
+ expect(outcome.drift[0]!.file).toBe("README.md");
183
+ });
184
+ });
185
+
186
+ describe("write-path edge cases (defect REVIEW-1585-F1/F3/F5)", () => {
187
+ test("adjacent empty marker pair heals without deleting the open marker (F-1)", () => {
188
+ const doc = `<!-- ${SKILL_DOC_MARKERS.count} --><!-- /${SKILL_DOC_MARKERS.count} -->\n`;
189
+ const out = lintSkillDocContent("README.md", doc, SKILLS, true).rewritten!;
190
+ expect(out).toContain(`<!-- ${SKILL_DOC_MARKERS.count} -->`);
191
+ expect(out).toContain(`<!-- /${SKILL_DOC_MARKERS.count} -->`);
192
+ expect(out).toContain(renderCountLiteral(SKILLS));
193
+ });
194
+
195
+ test("a file starting with a fence gains no phantom line on --write (F-3)", () => {
196
+ const doc = "```\ncode block\n```\n\nText.\n";
197
+ const out = lintSkillDocContent("README.md", doc, SKILLS, true).rewritten!;
198
+ expect(out).toBe(doc);
199
+ });
200
+
201
+ test("claim line numbers after a multi-line region stay true (F-2)", () => {
202
+ const doc = `Intro.\n\n<!-- ${SKILL_DOC_MARKERS.inventory} -->\nold\nold\nold\n<!-- /${SKILL_DOC_MARKERS.inventory} -->\n\nWe ship 99 skills.\n`;
203
+ const drift = lintSkillDocContent("README.md", doc, SKILLS).drift;
204
+ const claim = drift.find((d) => d.kind === "claim-total")!;
205
+ expect(claim.line).toBe(9);
206
+ });
207
+
208
+ test("--write exits pass even when regions were healed (F-5)", async () => {
209
+ const root = sfs.mkdtempSync(path.join(os.tmpdir(), "skill-doc-sync-"));
210
+ sfs.writeFileSync(
211
+ path.join(root, "README.md"),
212
+ `<!-- ${SKILL_DOC_MARKERS.count} -->STALE<!-- /${SKILL_DOC_MARKERS.count} -->\n`,
213
+ );
214
+ const heal = await runSkillDocSync({ flags: { write: true } }, { workspaceRoot: root });
215
+ expect(heal.status).toBe("pass");
216
+ expect(heal.healedRegions).toHaveLength(1);
217
+ });
218
+
219
+ test("--check is the explicit form of the default", async () => {
220
+ const root = sfs.mkdtempSync(path.join(os.tmpdir(), "skill-doc-sync-"));
221
+ sfs.writeFileSync(path.join(root, "README.md"), "We ship 99 skills.\n");
222
+ expect(
223
+ (await runSkillDocSync({ flags: { check: true } }, { workspaceRoot: root })).status,
224
+ ).toBe("fail");
225
+ });
226
+ });
227
+
228
+ describe("scaffold hydration (requirement AC-5)", () => {
229
+ test("empty marker pairs in templates render at create time", () => {
230
+ const tpl = `- Skills: <!-- ${SKILL_DOC_MARKERS.count} --><!-- /${SKILL_DOC_MARKERS.count} -->\n`;
231
+ expect(hydrateSkillDocMarkers(tpl, SKILLS)).toContain(renderCountLiteral(SKILLS));
232
+ });
233
+ });