@warpgogol/forge 9.7.1 → 10.0.0

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 (158) hide show
  1. package/AGENTS.md +50 -27
  2. package/CHANGELOG.md +27 -0
  3. package/bin/cli.js +0 -0
  4. package/dist/os/codebase/handlers/codebase-measure-symbols.d.ts.map +1 -1
  5. package/dist/os/codebase/handlers/codebase-measure-symbols.js +35 -4
  6. package/dist/os/codebase/handlers/codebase-measure-symbols.js.map +1 -1
  7. package/dist/os/core/core.module.d.ts.map +1 -1
  8. package/dist/os/core/core.module.js +1 -69
  9. package/dist/os/core/core.module.js.map +1 -1
  10. package/dist/os/core/handlers/assets-helpers.d.ts.map +1 -1
  11. package/dist/os/core/handlers/assets-helpers.js +2 -3
  12. package/dist/os/core/handlers/assets-helpers.js.map +1 -1
  13. package/dist/os/core/handlers/determinism-check.d.ts.map +1 -1
  14. package/dist/os/core/handlers/determinism-check.js +2 -3
  15. package/dist/os/core/handlers/determinism-check.js.map +1 -1
  16. package/dist/os/core/handlers/release-prepare.d.ts.map +1 -1
  17. package/dist/os/core/handlers/release-prepare.js +2 -4
  18. package/dist/os/core/handlers/release-prepare.js.map +1 -1
  19. package/dist/os/flow/handlers/flow-peers.js +1 -1
  20. package/dist/os/flow/handlers/flow-peers.js.map +1 -1
  21. package/dist/os/{mission → flow}/open-missions.d.ts +1 -2
  22. package/dist/os/flow/open-missions.d.ts.map +1 -0
  23. package/dist/os/flow/open-missions.js +37 -0
  24. package/dist/os/flow/open-missions.js.map +1 -0
  25. package/dist/os/flow/preflight.js +1 -1
  26. package/dist/os/flow/preflight.js.map +1 -1
  27. package/dist/src/command-modules.d.ts.map +1 -1
  28. package/dist/src/command-modules.js +0 -2
  29. package/dist/src/command-modules.js.map +1 -1
  30. package/dist/src/index.d.ts +0 -2
  31. package/dist/src/index.d.ts.map +1 -1
  32. package/dist/src/index.js +0 -2
  33. package/dist/src/index.js.map +1 -1
  34. package/dist/src/onboarding/doctor.d.ts +0 -5
  35. package/dist/src/onboarding/doctor.d.ts.map +1 -1
  36. package/dist/src/onboarding/doctor.js +6 -79
  37. package/dist/src/onboarding/doctor.js.map +1 -1
  38. package/dist/src/onboarding/npm-token-check.d.ts +1 -1
  39. package/dist/src/onboarding/npm-token-check.d.ts.map +1 -1
  40. package/dist/src/onboarding/npm-token-check.js +2 -2
  41. package/dist/src/onboarding/npm-token-check.js.map +1 -1
  42. package/dist/src/utils/hash.d.ts +1 -0
  43. package/dist/src/utils/hash.d.ts.map +1 -1
  44. package/dist/src/utils/hash.js +4 -0
  45. package/dist/src/utils/hash.js.map +1 -1
  46. package/dist/{os/mission → src/utils}/lockfile.d.ts +1 -18
  47. package/dist/src/utils/lockfile.d.ts.map +1 -0
  48. package/dist/src/utils/lockfile.js +70 -0
  49. package/dist/src/utils/lockfile.js.map +1 -0
  50. package/os/codebase/handlers/codebase-measure-symbols.ts +32 -4
  51. package/os/core/core.module.ts +3 -76
  52. package/os/core/handlers/assets-helpers.ts +2 -4
  53. package/os/core/handlers/determinism-check.ts +2 -3
  54. package/os/core/handlers/lifecycle-handlers.test.ts +529 -0
  55. package/os/core/handlers/release-prepare.ts +2 -4
  56. package/os/correctness/gate/trust-boundary-cx18.test.ts +1 -1
  57. package/os/flow/handlers/flow-peers.ts +1 -1
  58. package/os/flow/open-missions.ts +45 -0
  59. package/os/flow/preflight.ts +1 -1
  60. package/os/flow/tests/release-lines.test.ts +136 -0
  61. package/os/flow/tests/state-roots.test.ts +1 -48
  62. package/os/rfc/handlers/validate-corpus.test.ts +149 -0
  63. package/os/rfc/probe-batch.test.ts +253 -0
  64. package/os/rfc/verifier/rfc-1391/ac10-operating-model-policy.acceptance.test.ts +63 -0
  65. package/package.json +161 -506
  66. package/src/command-modules.ts +0 -2
  67. package/src/index.ts +0 -2
  68. package/src/onboarding/doctor.ts +9 -96
  69. package/src/onboarding/npm-token-check.ts +3 -3
  70. package/src/tests/pkg-health-self-scan.test.ts +29 -0
  71. package/src/tests/rfc-evidence-sync.test.ts +369 -0
  72. package/src/tests/skill-agents-sync.test.ts +192 -0
  73. package/src/utils/hash.ts +5 -0
  74. package/src/utils/lockfile.ts +78 -0
  75. package/dist/os/core/handlers/forge-autonomy-validate.d.ts +0 -25
  76. package/dist/os/core/handlers/forge-autonomy-validate.d.ts.map +0 -1
  77. package/dist/os/core/handlers/forge-autonomy-validate.js +0 -208
  78. package/dist/os/core/handlers/forge-autonomy-validate.js.map +0 -1
  79. package/dist/os/mission/handlers/archive.d.ts +0 -4
  80. package/dist/os/mission/handlers/archive.d.ts.map +0 -1
  81. package/dist/os/mission/handlers/archive.js +0 -583
  82. package/dist/os/mission/handlers/archive.js.map +0 -1
  83. package/dist/os/mission/importer-block.d.ts +0 -19
  84. package/dist/os/mission/importer-block.d.ts.map +0 -1
  85. package/dist/os/mission/importer-block.js +0 -124
  86. package/dist/os/mission/importer-block.js.map +0 -1
  87. package/dist/os/mission/index.d.ts +0 -2
  88. package/dist/os/mission/index.d.ts.map +0 -1
  89. package/dist/os/mission/index.js +0 -15
  90. package/dist/os/mission/index.js.map +0 -1
  91. package/dist/os/mission/lockfile.d.ts.map +0 -1
  92. package/dist/os/mission/lockfile.js +0 -138
  93. package/dist/os/mission/lockfile.js.map +0 -1
  94. package/dist/os/mission/mission.module.d.ts +0 -3
  95. package/dist/os/mission/mission.module.d.ts.map +0 -1
  96. package/dist/os/mission/mission.module.js +0 -63
  97. package/dist/os/mission/mission.module.js.map +0 -1
  98. package/dist/os/mission/open-missions.d.ts.map +0 -1
  99. package/dist/os/mission/open-missions.js +0 -42
  100. package/dist/os/mission/open-missions.js.map +0 -1
  101. package/dist/os/mission/types.d.ts +0 -23
  102. package/dist/os/mission/types.d.ts.map +0 -1
  103. package/dist/os/mission/types.js +0 -19
  104. package/dist/os/mission/types.js.map +0 -1
  105. package/dist/os/werkstatt/handlers/lock.d.ts +0 -10
  106. package/dist/os/werkstatt/handlers/lock.d.ts.map +0 -1
  107. package/dist/os/werkstatt/handlers/lock.js +0 -153
  108. package/dist/os/werkstatt/handlers/lock.js.map +0 -1
  109. package/dist/os/werkstatt/handlers/schema.d.ts +0 -33
  110. package/dist/os/werkstatt/handlers/schema.d.ts.map +0 -1
  111. package/dist/os/werkstatt/handlers/schema.js +0 -42
  112. package/dist/os/werkstatt/handlers/schema.js.map +0 -1
  113. package/dist/os/werkstatt/handlers/werkstatt-lock-recover.d.ts +0 -15
  114. package/dist/os/werkstatt/handlers/werkstatt-lock-recover.d.ts.map +0 -1
  115. package/dist/os/werkstatt/handlers/werkstatt-lock-recover.js +0 -171
  116. package/dist/os/werkstatt/handlers/werkstatt-lock-recover.js.map +0 -1
  117. package/dist/os/werkstatt/handlers/werkstatt-lock-status.d.ts +0 -18
  118. package/dist/os/werkstatt/handlers/werkstatt-lock-status.d.ts.map +0 -1
  119. package/dist/os/werkstatt/handlers/werkstatt-lock-status.js +0 -51
  120. package/dist/os/werkstatt/handlers/werkstatt-lock-status.js.map +0 -1
  121. package/dist/os/werkstatt/handlers/werkstatt-operation-validate.d.ts +0 -11
  122. package/dist/os/werkstatt/handlers/werkstatt-operation-validate.d.ts.map +0 -1
  123. package/dist/os/werkstatt/handlers/werkstatt-operation-validate.js +0 -86
  124. package/dist/os/werkstatt/handlers/werkstatt-operation-validate.js.map +0 -1
  125. package/dist/os/werkstatt/handlers/workspace-deps.d.ts +0 -12
  126. package/dist/os/werkstatt/handlers/workspace-deps.d.ts.map +0 -1
  127. package/dist/os/werkstatt/handlers/workspace-deps.js +0 -42
  128. package/dist/os/werkstatt/handlers/workspace-deps.js.map +0 -1
  129. package/dist/os/werkstatt/index.d.ts +0 -7
  130. package/dist/os/werkstatt/index.d.ts.map +0 -1
  131. package/dist/os/werkstatt/index.js +0 -18
  132. package/dist/os/werkstatt/index.js.map +0 -1
  133. package/dist/os/werkstatt/werkstatt.module.d.ts +0 -3
  134. package/dist/os/werkstatt/werkstatt.module.d.ts.map +0 -1
  135. package/dist/os/werkstatt/werkstatt.module.js +0 -91
  136. package/dist/os/werkstatt/werkstatt.module.js.map +0 -1
  137. package/os/core/handlers/forge-autonomy-validate.ts +0 -276
  138. package/os/correctness/gate/trust-boundary-cx19.test.ts +0 -514
  139. package/os/mission/handlers/archive.test.ts +0 -764
  140. package/os/mission/handlers/archive.ts +0 -711
  141. package/os/mission/handlers/ship-inflight-degraded.test.ts +0 -105
  142. package/os/mission/importer-block.ts +0 -119
  143. package/os/mission/index.ts +0 -15
  144. package/os/mission/lockfile.ts +0 -152
  145. package/os/mission/mission.module.ts +0 -68
  146. package/os/mission/open-missions.ts +0 -50
  147. package/os/mission/types.ts +0 -42
  148. package/os/werkstatt/handlers/lock.ts +0 -168
  149. package/os/werkstatt/handlers/schema.ts +0 -47
  150. package/os/werkstatt/handlers/werkstatt-lock-recover.ts +0 -206
  151. package/os/werkstatt/handlers/werkstatt-lock-status.ts +0 -82
  152. package/os/werkstatt/handlers/werkstatt-operation-validate.ts +0 -112
  153. package/os/werkstatt/handlers/workspace-deps.ts +0 -56
  154. package/os/werkstatt/index.ts +0 -39
  155. package/os/werkstatt/werkstatt.module.ts +0 -95
  156. package/src/tests/doctor-autonomy.test.ts +0 -246
  157. package/src/tests/forge-autonomy-validate.test.ts +0 -159
  158. package/src/tests/werkstatt-lock.test.ts +0 -357
@@ -0,0 +1,136 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>Release-line discovery tests (RFC-1488, AC-2 foundation): temp
4
+ workspaces exercise the pnpm-workspace glob expansion, the
5
+ `extract.config.yaml` publishability marker, negated globs and the
6
+ FLOW-VER-02 basename collision; a read-only pass over the real werkstatt
7
+ root pins the expected line set.</purpose>
8
+ <non-goals>
9
+ <item>No tag or version math — release-tags/release-level tests own those.</item>
10
+ </non-goals>
11
+ </MODULE_CONTRACT>
12
+ <CHANGE_SUMMARY>
13
+ <item>RFC-1488: step 1 — release-lines discovery tests</item>
14
+ <item>RFC-1488: step 1 — semver helper + release-line discovery (extract.config.yaml workspace globs)</item>
15
+ <item>RFC-1540: count the intake-validator release line in the werkstatt root discovery test</item>
16
+ </CHANGE_SUMMARY>
17
+ */
18
+
19
+ import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
20
+ import { tmpdir } from "node:os";
21
+ import { dirname, join } from "node:path";
22
+ import { fileURLToPath } from "node:url";
23
+
24
+ import { afterEach, describe, expect, it } from "vitest";
25
+
26
+ import { ambientIo } from "../../../src/utils/io.ts";
27
+ import { discoverReleaseLines } from "../release-lines.ts";
28
+
29
+ const dirs: string[] = [];
30
+
31
+ afterEach(async () => {
32
+ for (const dir of dirs.splice(0)) {
33
+ await rm(dir, { recursive: true, force: true });
34
+ }
35
+ });
36
+
37
+ async function tempRepo(): Promise<string> {
38
+ const dir = await mkdtemp(join(tmpdir(), "flow-lines-"));
39
+ dirs.push(dir);
40
+ return dir;
41
+ }
42
+
43
+ async function touch(repo: string, rel: string, content = ""): Promise<void> {
44
+ await mkdir(join(repo, rel.split("/").slice(0, -1).join("/")), { recursive: true });
45
+ await writeFile(join(repo, rel), content);
46
+ }
47
+
48
+ describe("discoverReleaseLines", () => {
49
+ it("reports the repo line plus every extract.config.yaml workspace dir", async () => {
50
+ const repo = await tempRepo();
51
+ await touch(repo, "package.json", '{ "version": "1.0.0" }\n');
52
+ await touch(
53
+ repo,
54
+ "pnpm-workspace.yaml",
55
+ "packages:\n - 'packages/*'\n - 'missions/*/workpiece'\n",
56
+ );
57
+ await touch(repo, "packages/forge/package.json", '{ "version": "9.0.0" }\n');
58
+ await touch(repo, "packages/forge/extract.config.yaml", "forgePlugin: true\n");
59
+ await touch(repo, "packages/pbp/package.json", '{ "version": "2.1.0" }\n');
60
+ await touch(repo, "packages/pbp/extract.config.yaml", "forgePlugin: false\n");
61
+ await touch(repo, "packages/no-extract/package.json", '{ "version": "0.0.1" }\n');
62
+ await touch(repo, "missions/m1/workpiece/src/index.ts", "// workpiece\n");
63
+
64
+ const { lines, diagnostics } = await discoverReleaseLines(repo, ambientIo);
65
+ expect(diagnostics).toEqual([]);
66
+ expect(lines.map((l) => l.id).sort()).toEqual(["forge", "pbp", "repo"]);
67
+ const forge = lines.find((l) => l.id === "forge");
68
+ expect(forge).toMatchObject({
69
+ tagPrefix: "forge@",
70
+ versionFile: "packages/forge/package.json",
71
+ paths: ["packages/forge"],
72
+ });
73
+ const repoLine = lines.find((l) => l.id === "repo");
74
+ expect(repoLine).toMatchObject({ tagPrefix: "v", versionFile: "package.json", paths: [] });
75
+ });
76
+
77
+ it("reports a null versionFile when the repo has no root package.json", async () => {
78
+ const repo = await tempRepo();
79
+ const { lines } = await discoverReleaseLines(repo, ambientIo);
80
+ expect(lines).toEqual([
81
+ { id: "repo", tagPrefix: "v", versionFile: null, paths: [] },
82
+ ]);
83
+ });
84
+
85
+ it("skips negated glob matches and node_modules", async () => {
86
+ const repo = await tempRepo();
87
+ await touch(repo, "package.json", '{ "version": "1.0.0" }\n');
88
+ await touch(
89
+ repo,
90
+ "pnpm-workspace.yaml",
91
+ "packages:\n - 'packages/*'\n - '!packages/internal'\n",
92
+ );
93
+ await touch(repo, "packages/internal/extract.config.yaml", "forgePlugin: false\n");
94
+ await touch(repo, "packages/forge/extract.config.yaml", "forgePlugin: true\n");
95
+ await touch(repo, "packages/node_modules/x/extract.config.yaml", "x: 1\n");
96
+
97
+ const { lines, diagnostics } = await discoverReleaseLines(repo, ambientIo);
98
+ expect(diagnostics).toEqual([]);
99
+ expect(lines.map((l) => l.id).sort()).toEqual(["forge", "repo"]);
100
+ });
101
+
102
+ it("refuses colliding basenames with FLOW-VER-02 naming both dirs", async () => {
103
+ const repo = await tempRepo();
104
+ await touch(repo, "package.json", '{ "version": "1.0.0" }\n');
105
+ await touch(
106
+ repo,
107
+ "pnpm-workspace.yaml",
108
+ "packages:\n - 'packages/*/x'\n - 'services/*'\n",
109
+ );
110
+ await touch(repo, "packages/a/x/extract.config.yaml", "forgePlugin: false\n");
111
+ await touch(repo, "services/x/extract.config.yaml", "forgePlugin: false\n");
112
+ await touch(repo, "services/keep/extract.config.yaml", "forgePlugin: false\n");
113
+
114
+ const { lines, diagnostics } = await discoverReleaseLines(repo, ambientIo);
115
+ const collision = diagnostics.filter((d) => d.ruleId === "FLOW-VER-02");
116
+ expect(collision).toHaveLength(1);
117
+ expect(collision[0]?.severity).toBe("error");
118
+ expect(collision[0]?.message).toContain("x");
119
+ expect(collision[0]?.message).toContain("packages/a/x");
120
+ expect(collision[0]?.message).toContain("services/x");
121
+ // The non-colliding line still lands; the collided id is absent.
122
+ expect(lines.map((l) => l.id).sort()).toEqual(["keep", "repo"]);
123
+ });
124
+
125
+ it("the real monorepo root discovers repo plus its published package lines", async () => {
126
+ const root = join(dirname(fileURLToPath(import.meta.url)), "../../../../..");
127
+ const { lines, diagnostics } = await discoverReleaseLines(root, ambientIo);
128
+ expect(diagnostics.filter((d) => d.ruleId === "FLOW-VER-02")).toEqual([]);
129
+ // v10 authoring monorepo (RFC-1649): a directory joins the release-line set
130
+ // when it carries extract.config.yaml — the publishability fact. Today that
131
+ // is packages/forge + packages/forge-typescript plus the repo line itself;
132
+ // the first-party plugin scaffolds (forge-astro, forge-repo-extract,
133
+ // forge-system) join when WP-5 makes them publishable.
134
+ expect(lines.map((l) => l.id).sort()).toEqual(["forge", "forge-typescript", "repo"]);
135
+ });
136
+ });
@@ -17,17 +17,14 @@ mission source stays where the command ran.
17
17
  */
18
18
 
19
19
  import { test, expect, describe, afterEach } from "vitest";
20
- import { mkdtemp, mkdir, writeFile, rm } from "node:fs/promises";
21
- import { existsSync } from "node:fs";
20
+ import { mkdtemp, rm } from "node:fs/promises";
22
21
  import { tmpdir } from "node:os";
23
22
  import { basename, dirname, join } from "node:path";
24
23
 
25
24
  import { ambientIo } from "../../../src/utils/io.ts";
26
25
  import { canonicalRepoDir } from "../../../src/utils/repo-path.ts";
27
- import type { ForgeCommandInput, ForgeRuntimeContext } from "../../../src/types.ts";
28
26
 
29
27
  import { resolveStateRoots } from "../worktree-path.ts";
30
- import { runMissionArchive } from "../../mission/handlers/archive.ts";
31
28
  import { gitExec, initRepo } from "./helpers.ts";
32
29
 
33
30
  const io = ambientIo;
@@ -37,26 +34,6 @@ afterEach(async () => {
37
34
  for (const d of dirs.splice(0)) await rm(d, { recursive: true, force: true });
38
35
  });
39
36
 
40
- function makeContext(workspaceRoot: string): ForgeRuntimeContext {
41
- return {
42
- workspaceRoot,
43
- io,
44
- logger: {
45
- info: () => {},
46
- success: () => {},
47
- warn: () => {},
48
- error: () => {},
49
- debug: () => {},
50
- },
51
- outputFormat: "json",
52
- dryRun: false,
53
- } as unknown as ForgeRuntimeContext;
54
- }
55
-
56
- function makeInput(flags: Record<string, unknown> = {}): ForgeCommandInput {
57
- return { commandName: "mission.archive", flags } as unknown as ForgeCommandInput;
58
- }
59
-
60
37
  describe("resolveStateRoots (RFC-1495)", () => {
61
38
  test("single-worktree repo resolves every root to itself", async () => {
62
39
  const repo = await initRepo({ prefix: "state-roots-" });
@@ -100,28 +77,4 @@ describe("resolveStateRoots (RFC-1495)", () => {
100
77
  });
101
78
  });
102
79
 
103
- test("mission.archive run in a session worktree lands in the primary archive", async () => {
104
- const repo = await initRepo({ prefix: "state-roots-" });
105
- dirs.push(repo);
106
- const wt = join(dirname(repo), `${basename(repo)}@session-y`);
107
- const add = await gitExec(repo, ["worktree", "add", "-b", "session-y", wt]);
108
- expect(add.exitCode).toBe(0);
109
- dirs.push(wt);
110
-
111
- // A closed mission exists in the session worktree only.
112
- const missionId = "acme-m000001";
113
- const missionDir = join(wt, "missions", missionId);
114
- await mkdir(missionDir, { recursive: true });
115
- await writeFile(join(missionDir, "mission.yaml"), `missionId: ${missionId}\nstate: closed\n`);
116
-
117
- const result = await runMissionArchive(makeInput(), makeContext(wt));
118
- expect(result.exitCode ?? 0).toBe(0);
119
-
120
- // Durable target: the primary's missions/archive/closed/, never the wt's.
121
- expect(existsSync(join(repo, "missions", "archive", "closed", missionId, "mission.yaml"))).toBe(
122
- true,
123
- );
124
- expect(existsSync(join(wt, "missions", "archive"))).toBe(false);
125
- expect(existsSync(missionDir)).toBe(false);
126
- });
127
80
  });
@@ -0,0 +1,149 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>
4
+ Unit tests for the frontmatter-only corpus read path — readRfcFrontmatter bounded-head semantics, >64 KiB full-parse fallback, error parity, and AC-9 frontmatter parity across the real corpus (RFC-1489).
5
+ </purpose>
6
+ <non-goals>
7
+ <item>Not a contract source of truth — the module under test owns the authoritative behavior; fixtures are minimal scaffolding only.</item>
8
+ </non-goals>
9
+ </MODULE_CONTRACT>
10
+ <CHANGE_SUMMARY>
11
+ <item>RFC-1489: frontmatter-only corpus read coverage.</item>
12
+ </CHANGE_SUMMARY>
13
+ */
14
+
15
+ import { test, expect, describe } from "vitest";
16
+ import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
17
+ import { join } from "node:path";
18
+ import { tmpdir } from "node:os";
19
+
20
+ import {
21
+ readRfcFrontmatter,
22
+ readAndParseRfc,
23
+ listRfcFiles,
24
+ } from "../frontmatter-io.ts";
25
+
26
+
27
+ describe("readRfcFrontmatter — AC-5/AC-6 corpus reads", () => {
28
+ const fmDoc = (id: string, extra = ""): string =>
29
+ `---\nid: ${id}\nstatus: draft\n${extra}---\n\n# Body ${id}\n\nSome body text.\n`;
30
+
31
+ test("returns frontmatter with an empty body (AC-5)", async () => {
32
+ const dir = mkdtempSync(join(tmpdir(), "fm-io-"));
33
+ try {
34
+ writeFileSync(join(dir, "rfc-0001-a.md"), fmDoc("RFC-0001"));
35
+ const res = await readRfcFrontmatter(dir, "rfc-0001-a.md");
36
+ expect(res && "parsed" in res ? res.parsed.frontmatter["id"] : undefined).toBe("RFC-0001");
37
+ expect(res && "parsed" in res ? res.parsed.body : "x").toBe("");
38
+ } finally {
39
+ rmSync(dir, { recursive: true, force: true });
40
+ }
41
+ });
42
+
43
+ test("falls back to full parse when the closing fence exceeds the bound (AC-6)", async () => {
44
+ const dir = mkdtempSync(join(tmpdir(), "fm-io-big-"));
45
+ try {
46
+ // A >64 KiB frontmatter block: the bounded head cannot see the fence.
47
+ const big = `note: "${"y".repeat(70 * 1024)}"\n`;
48
+ writeFileSync(join(dir, "rfc-0002-big.md"), fmDoc("RFC-0002", big));
49
+ const res = await readRfcFrontmatter(dir, "rfc-0002-big.md");
50
+ expect(res && "parsed" in res ? res.parsed.frontmatter["id"] : undefined).toBe("RFC-0002");
51
+ // Full-parse fallback populates the body.
52
+ expect(res && "parsed" in res ? res.parsed.body : "").toContain("# Body RFC-0002");
53
+ } finally {
54
+ rmSync(dir, { recursive: true, force: true });
55
+ }
56
+ });
57
+
58
+ test("small file without a closing fence yields empty frontmatter", async () => {
59
+ const dir = mkdtempSync(join(tmpdir(), "fm-io-nofm-"));
60
+ try {
61
+ writeFileSync(join(dir, "rfc-0003-bare.md"), "# No frontmatter\n\nbody\n");
62
+ const res = await readRfcFrontmatter(dir, "rfc-0003-bare.md");
63
+ expect(res && "parsed" in res ? res.parsed.frontmatter : { x: 1 }).toEqual({});
64
+ } finally {
65
+ rmSync(dir, { recursive: true, force: true });
66
+ }
67
+ });
68
+
69
+ test("malformed YAML produces the same error variant as full parse", async () => {
70
+ const dir = mkdtempSync(join(tmpdir(), "fm-io-bad-"));
71
+ try {
72
+ writeFileSync(join(dir, "rfc-0004-bad.md"), "---\nid: [unclosed\n---\nbody\n");
73
+ const slim = await readRfcFrontmatter(dir, "rfc-0004-bad.md");
74
+ const full = await readAndParseRfc(dir, "rfc-0004-bad.md");
75
+ expect(slim && "error" in slim).toBe(true);
76
+ expect(full && "error" in full).toBe(true);
77
+ expect(slim && "error" in slim ? slim.error : "").toBe(
78
+ full && "error" in full ? full.error : "",
79
+ );
80
+ } finally {
81
+ rmSync(dir, { recursive: true, force: true });
82
+ }
83
+ });
84
+ });
85
+
86
+ describe("AC-9 — frontmatter-only corpus produces the same rule input as full parse", () => {
87
+ test(
88
+ "every corpus file: frontmatter identical between the two paths",
89
+ async () => {
90
+ // v10 (RFC-1649): the authoring monorepo carries no hundred-file RFC
91
+ // corpus of its own — the v9 test scanned werkstatt's. The parity
92
+ // property is generic, so the corpus is synthesized here: diverse YAML
93
+ // shapes exercising exactly the scan/parse divergence surface (nested
94
+ // maps, flow + block sequences, multiline scalars, unicode, quotes,
95
+ // empty + malformed frontmatter).
96
+ const dir = mkdtempSync(join(tmpdir(), "fm-corpus-"));
97
+ try {
98
+ const shapes: Array<[string, string]> = [
99
+ ["simple", "id: RFC-1001\nstatus: draft\n"],
100
+ ["nested-map", "id: RFC-1002\nmeta:\n author: a\n tags:\n x: 1\n"],
101
+ ["flow-seq", "id: RFC-1003\nrefs: [RFC-0001, RFC-0002]\n"],
102
+ ["block-seq", "id: RFC-1004\nrefs:\n - RFC-0001\n - RFC-0002\n"],
103
+ ["multiline-literal", "id: RFC-1005\nnote: |\n line one\n line two\n"],
104
+ ["multiline-folded", "id: RFC-1006\nnote: >\n fold one\n fold two\n"],
105
+ ["unicode", "id: RFC-1007\ntitle: Ünïcödé — тест\n"],
106
+ ["quoted", 'id: RFC-1008\ntitle: "quoted: with colon"\n'],
107
+ ["single-quoted", "id: RFC-1009\ntitle: 'single ''quote'''\n"],
108
+ ["numbers", "id: RFC-1010\nversion: 2\nratio: 0.5\n"],
109
+ ["booleans", "id: RFC-1011\nactive: true\narchived: false\n"],
110
+ ["null-value", "id: RFC-1012\nsuperseded-by: null\n"],
111
+ ["empty-fm", ""],
112
+ ["deep-nesting", "id: RFC-1014\na:\n b:\n c:\n d: [1, 2, { e: f }]\n"],
113
+ ["colon-in-value", "id: RFC-1015\nurl: https://example.com/x\n"],
114
+ ["dashes-in-key", "id: RFC-1016\nx-custom-key: v\n"],
115
+ ["long-value", `id: RFC-1017\nnote: "${"y".repeat(2000)}"\n`],
116
+ ["mixed-types", "id: RFC-1018\nn: 1\ns: text\nb: true\nl:\n - 1\n - two\n"],
117
+ ["indented-seq", "id: RFC-1019\nitems:\n - one\n - two\n"],
118
+ ["comment-in-fm", "id: RFC-1020\n# a comment\nstatus: draft\n"],
119
+ ["date-ish", "id: RFC-1021\ncreated: 2026-11-25\n"],
120
+ ["empty-string", 'id: RFC-1022\nnote: ""\n'],
121
+ ["anchor-free-dup", "id: RFC-1023\nx: a\ny: a\nz: a\n"],
122
+ ["malformed-unclosed", "id: [unclosed\n"],
123
+ ];
124
+ for (const [name, fm] of shapes) {
125
+ writeFileSync(join(dir, `rfc-${name}.md`), `---\n${fm}---\n\n# Body\n\ntext\n`);
126
+ }
127
+ const files = await listRfcFiles(dir);
128
+ expect(files.length).toBeGreaterThan(15);
129
+ for (const f of files) {
130
+ const slim = await readRfcFrontmatter(dir, f);
131
+ const full = await readAndParseRfc(dir, f);
132
+ if (!slim || !full) continue;
133
+ if ("error" in slim || "error" in full) {
134
+ expect("error" in slim, `error parity for ${f}`).toBe("error" in full);
135
+ continue;
136
+ }
137
+ // Referential rules consume only this map — identical input means an
138
+ // identical violation set.
139
+ expect(slim.parsed.frontmatter, `frontmatter parity for ${f}`).toEqual(
140
+ full.parsed.frontmatter,
141
+ );
142
+ }
143
+ } finally {
144
+ rmSync(dir, { recursive: true, force: true });
145
+ }
146
+ },
147
+ 120_000,
148
+ );
149
+ });
@@ -0,0 +1,253 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>
4
+ Unit tests for probe-batch — segment planning across barriers, per-(file,testName) report attribution, runProbeSet ordering and --no-batch escape, and the one-spawn e2e (RFC-1489).
5
+ </purpose>
6
+ <non-goals>
7
+ <item>Not a contract source of truth — the module under test owns the authoritative behavior; fixtures are minimal scaffolding only.</item>
8
+ </non-goals>
9
+ </MODULE_CONTRACT>
10
+ <CHANGE_SUMMARY>
11
+ <item>RFC-1489: batched test-probe planning + attribution coverage.</item>
12
+ </CHANGE_SUMMARY>
13
+ */
14
+
15
+ import { test, expect, describe } from "vitest";
16
+ import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
17
+ import { join } from "node:path";
18
+ import { tmpdir } from "node:os";
19
+
20
+ import {
21
+ planProbeSegments,
22
+ attributeProbeResult,
23
+ runBatchedTestSegment,
24
+ type ProbeSegment,
25
+ } from "./probe-batch.ts";
26
+ import { runProbeSet } from "./acceptance.ts";
27
+ import type { AcceptanceProbe } from "./types.ts";
28
+
29
+ const WORKSPACE_ROOT = join(__dirname, "..", "..", "..", "..");
30
+
31
+ const testProbe = (
32
+ file: string,
33
+ overrides: Partial<Extract<AcceptanceProbe, { probe: "test" }>> = {},
34
+ ): Extract<AcceptanceProbe, { probe: "test" }> => ({
35
+ probe: "test",
36
+ file,
37
+ expect: { exitCode: 0 },
38
+ ...overrides,
39
+ });
40
+
41
+ const fileExists = (path: string): AcceptanceProbe => ({ probe: "file-exists", path });
42
+ const runProbe = (command: string): AcceptanceProbe => ({
43
+ probe: "run",
44
+ command,
45
+ expect: { exitCode: 0 },
46
+ });
47
+
48
+ describe("planProbeSegments — AC-1 barrier-free grouping", () => {
49
+ test("contiguous same-bound test probes form one segment", () => {
50
+ const probes = [
51
+ testProbe("a.test.ts"),
52
+ testProbe("b.test.ts"),
53
+ testProbe("c.test.ts", { timeoutMs: 120_000 }),
54
+ ];
55
+ expect(planProbeSegments(probes, 120_000)).toEqual([
56
+ { start: 0, members: [0, 1, 2], boundMs: 120_000 },
57
+ ]);
58
+ });
59
+
60
+ test("a timeoutMs change closes the segment", () => {
61
+ const probes = [
62
+ testProbe("a.test.ts"),
63
+ testProbe("b.test.ts", { timeoutMs: 5_000 }),
64
+ testProbe("c.test.ts"),
65
+ ];
66
+ expect(planProbeSegments(probes, 120_000)).toEqual([
67
+ { start: 0, members: [0], boundMs: 120_000 },
68
+ { start: 1, members: [1], boundMs: 5_000 },
69
+ { start: 2, members: [2], boundMs: 120_000 },
70
+ ]);
71
+ });
72
+
73
+ test("run/page/proof are the only barriers — other kinds span without splitting", () => {
74
+ const probes: AcceptanceProbe[] = [
75
+ testProbe("a.test.ts"),
76
+ runProbe("site-kernel run x"),
77
+ testProbe("b.test.ts"),
78
+ { probe: "page", target: "site", path: "/", expect: { status: 200 } } as AcceptanceProbe,
79
+ testProbe("c.test.ts"),
80
+ { probe: "proof", spec: "s.yaml" },
81
+ testProbe("d.test.ts"),
82
+ fileExists("x.txt"),
83
+ testProbe("e.test.ts"),
84
+ ];
85
+ expect(planProbeSegments(probes, 120_000)).toEqual([
86
+ { start: 0, members: [0], boundMs: 120_000 },
87
+ { start: 2, members: [2], boundMs: 120_000 },
88
+ { start: 4, members: [4], boundMs: 120_000 },
89
+ { start: 6, members: [6, 8], boundMs: 120_000 },
90
+ ]);
91
+ });
92
+ });
93
+
94
+ describe("attributeProbeResult — AC-2/AC-3 per-slice attribution", () => {
95
+ const report = {
96
+ testResults: [
97
+ {
98
+ name: join(WORKSPACE_ROOT, "os/rfc/a.test.ts"),
99
+ status: "passed",
100
+ assertionResults: [
101
+ { title: "first", fullName: "suite first", status: "passed" },
102
+ { title: "second", fullName: "suite second", status: "passed" },
103
+ ],
104
+ },
105
+ {
106
+ name: join(WORKSPACE_ROOT, "os/rfc/b.test.ts"),
107
+ status: "failed",
108
+ assertionResults: [
109
+ { title: "x", fullName: "bsuite x", status: "failed" },
110
+ { title: "y", fullName: "bsuite y", status: "passed" },
111
+ ],
112
+ },
113
+ ],
114
+ };
115
+
116
+ test("each probe derives only from its own file slice", () => {
117
+ const a = attributeProbeResult(testProbe("os/rfc/a.test.ts"), WORKSPACE_ROOT, report);
118
+ const b = attributeProbeResult(testProbe("os/rfc/b.test.ts"), WORKSPACE_ROOT, report);
119
+ expect(a.ok).toBe(true);
120
+ expect(a.verdict).toBe("pass");
121
+ expect(b.ok).toBe(false);
122
+ expect(b.verdict).toBe("fail");
123
+ expect(b.detail).toContain("expected 0");
124
+ });
125
+
126
+ test("testName attribution matches only its own assertions", () => {
127
+ const ok = attributeProbeResult(
128
+ testProbe("os/rfc/b.test.ts", { testName: "bsuite y" }),
129
+ WORKSPACE_ROOT,
130
+ report,
131
+ );
132
+ expect(ok.ok).toBe(true);
133
+ const fail = attributeProbeResult(
134
+ testProbe("os/rfc/b.test.ts", { testName: "bsuite x" }),
135
+ WORKSPACE_ROOT,
136
+ report,
137
+ );
138
+ expect(fail.ok).toBe(false);
139
+ });
140
+
141
+ test("expected-nonzero exitCode inverts the derived verdict", () => {
142
+ const p = attributeProbeResult(
143
+ testProbe("os/rfc/b.test.ts", { expect: { exitCode: 1 } }),
144
+ WORKSPACE_ROOT,
145
+ report,
146
+ );
147
+ expect(p.ok).toBe(true);
148
+ expect(p.verdict).toBe("pass");
149
+ });
150
+
151
+ test("absent file slice is unverified, never pass", () => {
152
+ const p = attributeProbeResult(testProbe("os/rfc/missing.test.ts"), WORKSPACE_ROOT, report);
153
+ expect(p.ok).toBe(false);
154
+ expect(p.verdict).toBe("unverified");
155
+ });
156
+
157
+ test("testName matching no assertion is a fail (vitest -t parity, spec §4)", () => {
158
+ const p = attributeProbeResult(
159
+ testProbe("os/rfc/a.test.ts", { testName: "no such test" }),
160
+ WORKSPACE_ROOT,
161
+ report,
162
+ );
163
+ expect(p.ok).toBe(false);
164
+ expect(p.verdict).toBe("fail");
165
+ expect(p.detail).toContain("no testName match");
166
+ });
167
+
168
+ test("file-level requires status passed — skipped cannot prove execution", () => {
169
+ const skipped = {
170
+ testResults: [
171
+ {
172
+ name: join(WORKSPACE_ROOT, "os/rfc/s.test.ts"),
173
+ status: "skipped",
174
+ assertionResults: [{ title: "x", fullName: "s x", status: "skipped" }],
175
+ },
176
+ ],
177
+ };
178
+ const p = attributeProbeResult(testProbe("os/rfc/s.test.ts"), WORKSPACE_ROOT, skipped);
179
+ expect(p.ok).toBe(false);
180
+ expect(p.verdict).not.toBe("pass");
181
+ });
182
+ });
183
+
184
+ describe("runProbeSet — AC-2 order/shape, AC-4 --no-batch", () => {
185
+ test("preserves declared order across barriers; missing files are unverified", async () => {
186
+ const dir = mkdtempSync(join(tmpdir(), "probe-set-"));
187
+ try {
188
+ writeFileSync(join(dir, "present.txt"), "x");
189
+ const probes: AcceptanceProbe[] = [
190
+ fileExists("present.txt"),
191
+ testProbe("missing-a.test.ts"),
192
+ testProbe("missing-b.test.ts"),
193
+ fileExists("absent.txt"),
194
+ testProbe("missing-c.test.ts"),
195
+ ];
196
+ const { results, durationsMs } = await runProbeSet(probes, { workspaceRoot: dir });
197
+ expect(results).toHaveLength(5);
198
+ expect(results[0]!.ok).toBe(true);
199
+ expect(results[1]!.verdict).toBe("unverified");
200
+ expect(results[1]!.detail).toContain("missing-a.test.ts");
201
+ expect(results[2]!.verdict).toBe("unverified");
202
+ expect(results[3]!.ok).toBe(false);
203
+ expect(results[3]!.verdict).not.toBe("unverified");
204
+ // Indexes 1,2,4 are all same-bound test probes with no run/page/proof
205
+ // barrier between them — they share ONE segment; each missing file is
206
+ // attributed unverified from its own slice.
207
+ expect(results[4]!.verdict).toBe("unverified");
208
+ expect(results[4]!.detail).toContain("missing-c.test.ts");
209
+ expect(durationsMs).toHaveLength(5);
210
+ // Each batched result echoes its own declared probe.
211
+ results.forEach((r, i) => expect(r.probe).toBe(probes[i]));
212
+ } finally {
213
+ rmSync(dir, { recursive: true, force: true });
214
+ }
215
+ });
216
+
217
+ test("--no-batch forces the legacy per-probe path (spawn-failure != unverified)", async () => {
218
+ const dir = mkdtempSync(join(tmpdir(), "probe-set-nb-"));
219
+ try {
220
+ const probes = [testProbe("missing-a.test.ts"), testProbe("missing-b.test.ts")];
221
+ const legacy = await runProbeSet(probes, { workspaceRoot: dir, noBatch: true });
222
+ // Legacy spawns vitest per probe in the tmp workspace — the spawn fails,
223
+ // producing a fail verdict rather than the batched "unverified".
224
+ for (const r of legacy.results) {
225
+ expect(r.verdict).not.toBe("unverified");
226
+ expect(r.ok).toBe(false);
227
+ }
228
+ } finally {
229
+ rmSync(dir, { recursive: true, force: true });
230
+ }
231
+ }, 60_000);
232
+ });
233
+
234
+ describe("e2e — one instrumented Vitest run attributes two files", () => {
235
+ test(
236
+ "two real test files in one segment produce per-file verdicts (AC-1/AC-2)",
237
+ async () => {
238
+ const segment: ProbeSegment = { start: 0, members: [0, 1], boundMs: 120_000 };
239
+ const probes = [
240
+ testProbe("packages/forge/os/rfc/verification-normalize.test.ts"),
241
+ testProbe("packages/forge/os/rfc/frontmatter-io.test.ts"),
242
+ ];
243
+ const results = await runBatchedTestSegment(probes, segment, WORKSPACE_ROOT);
244
+ expect(results.size).toBe(2);
245
+ const a = results.get(0)!;
246
+ const b = results.get(1)!;
247
+ expect(a.verdict, `probe 0 must attribute its own file — ${a.detail}`).toBe("pass");
248
+ expect(b.verdict, `probe 1 must attribute its own file — ${b.detail}`).toBe("pass");
249
+ expect(a.detail).toContain("batched:");
250
+ },
251
+ 180_000,
252
+ );
253
+ });
@@ -0,0 +1,63 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>
4
+ Independent acceptance-verifier check for RFC-1391 (ac10-operating-model-policy) — authored inside
5
+ rfc.verify.workspace by the clean-context verifier, not by the implementer.
6
+ Derives its expectation from the RFC text and the observable behavior of the
7
+ real handlers/runner it exercises.
8
+ </purpose>
9
+ <non-goals>
10
+ <item>Do not treat as implementer-authored evidence — its expectationSource is independent.</item>
11
+ <item>Do not edit to fit the code — a failure here is a counterexample, fix the implementation.</item>
12
+ </non-goals>
13
+ </MODULE_CONTRACT>
14
+ <CHANGE_SUMMARY>
15
+ <item>RFC-1391 r1 verification: independent check ac10-operating-model-policy.</item>
16
+ <item>RFC-1391: commit independent verifier checks + independent probes + round-1 pass report
17
+
18
+ Round-0 verdict counterexamples (CX-1: emit dead for proof-probe RFCs),
19
+ fixed in 1342fe21a; round-1 verdict pass — 47/47 checks, AC-1..AC-10 all
20
+ verified on the real implementation surface, non-vacuity re-verified by
21
+ mutation.</item>
22
+ </CHANGE_SUMMARY>
23
+ */
24
+
25
+ // RFC-1391 AC-10 — "The agent operating model SHALL state that only a
26
+ // mechanical checker verdict counts as formal-tier evidence."
27
+ // RFC design: an agent-written argument, a random-sampling property test, or
28
+ // an unavailable checker must never be accepted as formal evidence — the
29
+ // operating model text is the enforcement surface agents read.
30
+ //
31
+ // Independent check: the canonical source file under packages/forge/skills/
32
+ // carries the policy, and the synced .agents mirror is byte-identical (the
33
+ // documented sync contract — drift would silently un-teach agents).
34
+
35
+ import { createHash } from "node:crypto";
36
+ import { readFileSync } from "node:fs";
37
+ import { join } from "node:path";
38
+ import { describe, expect, it } from "vitest";
39
+
40
+ import { EXPORT_ROOT, FORGE_ROOT } from "./support.ts";
41
+
42
+ const SRC = join(FORGE_ROOT, "skills/_shared/agent-operating-model.md");
43
+ const MIRROR = join(EXPORT_ROOT, ".agents/skills/_shared/agent-operating-model.md");
44
+
45
+ const sha = (p: string) => createHash("sha256").update(readFileSync(p)).digest("hex");
46
+
47
+ describe("AC-10: operating model binds formal evidence to a mechanical checker verdict", () => {
48
+ it("the source operating model states the policy", () => {
49
+ const text = readFileSync(SRC, "utf8");
50
+ // The load-bearing claim: mechanical-verdict-only formal evidence.
51
+ expect(text).toContain("Only a mechanical checker verdict");
52
+ // It must name the instrument and the bound spec schema.
53
+ expect(text).toContain("proof.check");
54
+ expect(text).toContain("proved");
55
+ expect(text).toContain("forge/proof-spec@1");
56
+ // And it must exclude the non-mechanical substitutes the RFC calls out.
57
+ expect(text).toMatch(/never does|never counts/i);
58
+ });
59
+
60
+ it("the .agents mirror is byte-identical to the source (sync contract)", () => {
61
+ expect(sha(MIRROR)).toBe(sha(SRC));
62
+ });
63
+ });