@warpgogol/forge 9.2.3 → 9.3.1
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.
- package/CHANGELOG.md +33 -0
- package/bin/cli.ts +3 -2
- package/dist/bin/cli.js +3 -2
- package/dist/bin/cli.js.map +1 -1
- package/dist/os/adr/handlers/implement-stamp.d.ts +6 -0
- package/dist/os/adr/handlers/implement-stamp.d.ts.map +1 -1
- package/dist/os/adr/handlers/implement-stamp.js +23 -15
- package/dist/os/adr/handlers/implement-stamp.js.map +1 -1
- package/dist/os/checks/handlers/counters-journal.d.ts.map +1 -1
- package/dist/os/checks/handlers/counters-journal.js +9 -1
- package/dist/os/checks/handlers/counters-journal.js.map +1 -1
- package/dist/os/core/core.module.d.ts.map +1 -1
- package/dist/os/core/core.module.js +27 -36
- package/dist/os/core/core.module.js.map +1 -1
- package/dist/os/core/lock-holder.d.ts +32 -0
- package/dist/os/core/lock-holder.d.ts.map +1 -0
- package/dist/os/core/lock-holder.js +81 -0
- package/dist/os/core/lock-holder.js.map +1 -0
- package/dist/os/core/stamp-lock.d.ts +30 -0
- package/dist/os/core/stamp-lock.d.ts.map +1 -0
- package/dist/os/core/stamp-lock.js +112 -0
- package/dist/os/core/stamp-lock.js.map +1 -0
- package/dist/os/flow/digest.d.ts +19 -0
- package/dist/os/flow/digest.d.ts.map +1 -1
- package/dist/os/flow/digest.js +33 -4
- package/dist/os/flow/digest.js.map +1 -1
- package/dist/os/flow/flow.module.d.ts.map +1 -1
- package/dist/os/flow/flow.module.js +61 -6
- package/dist/os/flow/flow.module.js.map +1 -1
- package/dist/os/flow/handlers/flow-cut.d.ts +8 -0
- package/dist/os/flow/handlers/flow-cut.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-cut.js +91 -5
- package/dist/os/flow/handlers/flow-cut.js.map +1 -1
- package/dist/os/flow/handlers/flow-digest.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-digest.js +6 -0
- package/dist/os/flow/handlers/flow-digest.js.map +1 -1
- package/dist/os/flow/handlers/flow-discard.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-discard.js +17 -13
- package/dist/os/flow/handlers/flow-discard.js.map +1 -1
- package/dist/os/flow/handlers/flow-fix.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-fix.js +99 -10
- package/dist/os/flow/handlers/flow-fix.js.map +1 -1
- package/dist/os/flow/handlers/flow-integrate.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-integrate.js +32 -15
- package/dist/os/flow/handlers/flow-integrate.js.map +1 -1
- package/dist/os/flow/handlers/flow-publication-retire.d.ts +17 -0
- package/dist/os/flow/handlers/flow-publication-retire.d.ts.map +1 -0
- package/dist/os/flow/handlers/flow-publication-retire.js +132 -0
- package/dist/os/flow/handlers/flow-publication-retire.js.map +1 -0
- package/dist/os/flow/handlers/flow-push.d.ts +7 -0
- package/dist/os/flow/handlers/flow-push.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-push.js +106 -15
- package/dist/os/flow/handlers/flow-push.js.map +1 -1
- package/dist/os/flow/locks.d.ts +6 -1
- package/dist/os/flow/locks.d.ts.map +1 -1
- package/dist/os/flow/locks.js +53 -23
- package/dist/os/flow/locks.js.map +1 -1
- package/dist/os/flow/publication-order.d.ts +25 -0
- package/dist/os/flow/publication-order.d.ts.map +1 -0
- package/dist/os/flow/publication-order.js +75 -0
- package/dist/os/flow/publication-order.js.map +1 -0
- package/dist/os/flow/publish.d.ts +18 -0
- package/dist/os/flow/publish.d.ts.map +1 -1
- package/dist/os/flow/publish.js +58 -2
- package/dist/os/flow/publish.js.map +1 -1
- package/dist/os/flow/registry.d.ts +1 -1
- package/dist/os/flow/registry.d.ts.map +1 -1
- package/dist/os/flow/registry.js +2 -1
- package/dist/os/flow/registry.js.map +1 -1
- package/dist/os/flow/release-tags.d.ts +1 -0
- package/dist/os/flow/release-tags.d.ts.map +1 -1
- package/dist/os/flow/release-tags.js +5 -4
- package/dist/os/flow/release-tags.js.map +1 -1
- package/dist/os/flow/scripts.d.ts +1 -1
- package/dist/os/flow/scripts.d.ts.map +1 -1
- package/dist/os/flow/scripts.js +6 -1
- package/dist/os/flow/scripts.js.map +1 -1
- package/dist/os/flow/task-files.d.ts +11 -0
- package/dist/os/flow/task-files.d.ts.map +1 -0
- package/dist/os/flow/task-files.js +51 -0
- package/dist/os/flow/task-files.js.map +1 -0
- package/dist/os/flow/tests/helpers.d.ts +4 -1
- package/dist/os/flow/tests/helpers.d.ts.map +1 -1
- package/dist/os/flow/tests/helpers.js +9 -5
- package/dist/os/flow/tests/helpers.js.map +1 -1
- package/dist/os/mission/handlers/archive.d.ts.map +1 -1
- package/dist/os/mission/handlers/archive.js +30 -74
- package/dist/os/mission/handlers/archive.js.map +1 -1
- package/dist/os/mission/lockfile.d.ts +21 -0
- package/dist/os/mission/lockfile.d.ts.map +1 -0
- package/dist/os/mission/lockfile.js +76 -0
- package/dist/os/mission/lockfile.js.map +1 -0
- package/dist/os/mission/mission.module.d.ts.map +1 -1
- package/dist/os/mission/mission.module.js +2 -1
- package/dist/os/mission/mission.module.js.map +1 -1
- package/dist/os/rfc/handlers/implement-stamp.d.ts +6 -0
- package/dist/os/rfc/handlers/implement-stamp.d.ts.map +1 -1
- package/dist/os/rfc/handlers/implement-stamp.js +24 -19
- package/dist/os/rfc/handlers/implement-stamp.js.map +1 -1
- package/dist/os/system/handlers/outbox-validate.d.ts +8 -0
- package/dist/os/system/handlers/outbox-validate.d.ts.map +1 -0
- package/dist/os/system/handlers/outbox-validate.js +102 -0
- package/dist/os/system/handlers/outbox-validate.js.map +1 -0
- package/dist/os/system/handlers/system-map-validate.d.ts +13 -0
- package/dist/os/system/handlers/system-map-validate.d.ts.map +1 -0
- package/dist/os/system/handlers/system-map-validate.js +78 -0
- package/dist/os/system/handlers/system-map-validate.js.map +1 -0
- package/dist/os/system/handlers/system-outbox-scan.d.ts +10 -0
- package/dist/os/system/handlers/system-outbox-scan.d.ts.map +1 -0
- package/dist/os/system/handlers/system-outbox-scan.js +195 -0
- package/dist/os/system/handlers/system-outbox-scan.js.map +1 -0
- package/dist/os/system/handlers/system-task-collect.d.ts +13 -0
- package/dist/os/system/handlers/system-task-collect.d.ts.map +1 -0
- package/dist/os/system/handlers/system-task-collect.js +238 -0
- package/dist/os/system/handlers/system-task-collect.js.map +1 -0
- package/dist/os/system/handlers/system-task-create.d.ts +32 -0
- package/dist/os/system/handlers/system-task-create.d.ts.map +1 -0
- package/dist/os/system/handlers/system-task-create.js +216 -0
- package/dist/os/system/handlers/system-task-create.js.map +1 -0
- package/dist/os/system/handlers/system-task-dispatch.d.ts +14 -0
- package/dist/os/system/handlers/system-task-dispatch.d.ts.map +1 -0
- package/dist/os/system/handlers/system-task-dispatch.js +290 -0
- package/dist/os/system/handlers/system-task-dispatch.js.map +1 -0
- package/dist/os/system/handlers/system-task-move.d.ts +12 -0
- package/dist/os/system/handlers/system-task-move.d.ts.map +1 -0
- package/dist/os/system/handlers/system-task-move.js +217 -0
- package/dist/os/system/handlers/system-task-move.js.map +1 -0
- package/dist/os/system/handlers/system-task-status.d.ts +20 -0
- package/dist/os/system/handlers/system-task-status.d.ts.map +1 -0
- package/dist/os/system/handlers/system-task-status.js +139 -0
- package/dist/os/system/handlers/system-task-status.js.map +1 -0
- package/dist/os/system/handlers/system-versionset-record.d.ts +12 -0
- package/dist/os/system/handlers/system-versionset-record.d.ts.map +1 -0
- package/dist/os/system/handlers/system-versionset-record.js +332 -0
- package/dist/os/system/handlers/system-versionset-record.js.map +1 -0
- package/dist/os/system/index.d.ts +6 -0
- package/dist/os/system/index.d.ts.map +1 -0
- package/dist/os/system/index.js +18 -0
- package/dist/os/system/index.js.map +1 -0
- package/dist/os/system/outbox-schema.d.ts +30 -0
- package/dist/os/system/outbox-schema.d.ts.map +1 -0
- package/dist/os/system/outbox-schema.js +29 -0
- package/dist/os/system/outbox-schema.js.map +1 -0
- package/dist/os/system/repo.d.ts +64 -0
- package/dist/os/system/repo.d.ts.map +1 -0
- package/dist/os/system/repo.js +364 -0
- package/dist/os/system/repo.js.map +1 -0
- package/dist/os/system/scenario-schemas.d.ts +26 -0
- package/dist/os/system/scenario-schemas.d.ts.map +1 -0
- package/dist/os/system/scenario-schemas.js +53 -0
- package/dist/os/system/scenario-schemas.js.map +1 -0
- package/dist/os/system/schemas.d.ts +63 -0
- package/dist/os/system/schemas.d.ts.map +1 -0
- package/dist/os/system/schemas.js +83 -0
- package/dist/os/system/schemas.js.map +1 -0
- package/dist/os/system/system.module.d.ts +3 -0
- package/dist/os/system/system.module.d.ts.map +1 -0
- package/dist/os/system/system.module.js +429 -0
- package/dist/os/system/system.module.js.map +1 -0
- package/dist/os/system/task-schemas.d.ts +108 -0
- package/dist/os/system/task-schemas.d.ts.map +1 -0
- package/dist/os/system/task-schemas.js +152 -0
- package/dist/os/system/task-schemas.js.map +1 -0
- package/dist/os/system/task-store.d.ts +41 -0
- package/dist/os/system/task-store.d.ts.map +1 -0
- package/dist/os/system/task-store.js +142 -0
- package/dist/os/system/task-store.js.map +1 -0
- package/dist/os/system/tests/helpers.d.ts +30 -0
- package/dist/os/system/tests/helpers.d.ts.map +1 -0
- package/dist/os/system/tests/helpers.js +178 -0
- package/dist/os/system/tests/helpers.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -4
- package/dist/src/index.js.map +1 -1
- package/os/adr/handlers/implement-stamp-lock.test.ts +90 -0
- package/os/adr/handlers/implement-stamp.ts +29 -20
- package/os/checks/handlers/counters-journal.test.ts +10 -0
- package/os/checks/handlers/counters-journal.ts +8 -1
- package/os/core/core.module.ts +32 -36
- package/os/core/lock-holder.ts +88 -0
- package/os/core/stamp-lock.ts +142 -0
- package/os/flow/digest.ts +46 -4
- package/os/flow/flow.module.ts +62 -6
- package/os/flow/handlers/flow-cut.ts +118 -5
- package/os/flow/handlers/flow-digest.ts +6 -0
- package/os/flow/handlers/flow-discard.ts +22 -13
- package/os/flow/handlers/flow-fix.ts +116 -10
- package/os/flow/handlers/flow-integrate.ts +31 -15
- package/os/flow/handlers/flow-publication-retire.ts +156 -0
- package/os/flow/handlers/flow-push.ts +128 -13
- package/os/flow/locks.ts +75 -25
- package/os/flow/publication-order.ts +99 -0
- package/os/flow/publish.ts +73 -2
- package/os/flow/registry.ts +5 -2
- package/os/flow/release-tags.ts +5 -4
- package/os/flow/scripts.ts +12 -5
- package/os/flow/task-files.ts +59 -0
- package/os/flow/tests/flow-cut-prepare.test.ts +298 -0
- package/os/flow/tests/flow-cut.test.ts +5 -1
- package/os/flow/tests/flow-publication-retire.test.ts +191 -0
- package/os/flow/tests/flow-push-supersede.test.ts +221 -0
- package/os/flow/tests/flow-task-files.test.ts +59 -0
- package/os/flow/tests/helpers.ts +9 -5
- package/os/flow/tests/locks.test.ts +219 -0
- package/os/flow/tests/publication-order.test.ts +102 -0
- package/os/flow/tests/scripts.test.ts +13 -0
- package/os/mission/handlers/archive.test.ts +97 -52
- package/os/mission/handlers/archive.ts +31 -76
- package/os/mission/lockfile.ts +84 -0
- package/os/mission/mission.module.ts +2 -1
- package/os/rfc/handlers/implement-stamp-lock.test.ts +133 -0
- package/os/rfc/handlers/implement-stamp.ts +30 -24
- package/os/system/handlers/outbox-validate.ts +120 -0
- package/os/system/handlers/system-map-validate.ts +107 -0
- package/os/system/handlers/system-outbox-scan.ts +320 -0
- package/os/system/handlers/system-task-collect.ts +305 -0
- package/os/system/handlers/system-task-create.ts +271 -0
- package/os/system/handlers/system-task-dispatch.ts +387 -0
- package/os/system/handlers/system-task-move.ts +353 -0
- package/os/system/handlers/system-task-status.ts +176 -0
- package/os/system/handlers/system-versionset-record.ts +476 -0
- package/os/system/index.ts +47 -0
- package/os/system/outbox-schema.ts +47 -0
- package/os/system/repo.ts +451 -0
- package/os/system/scenario-schemas.ts +62 -0
- package/os/system/schemas.ts +102 -0
- package/os/system/system.module.ts +449 -0
- package/os/system/task-schemas.ts +190 -0
- package/os/system/task-store.ts +184 -0
- package/os/system/tests/helpers.ts +189 -0
- package/os/system/tests/outbox-validate.test.ts +92 -0
- package/os/system/tests/system-map-validate.test.ts +321 -0
- package/os/system/tests/system-outbox-scan.test.ts +273 -0
- package/os/system/tests/system-profile.test.ts +90 -0
- package/os/system/tests/system-task-collect.test.ts +293 -0
- package/os/system/tests/system-task-dispatch.test.ts +279 -0
- package/os/system/tests/system-task-status.test.ts +153 -0
- package/os/system/tests/system-task.test.ts +330 -0
- package/os/system/tests/system-versionset.test.ts +314 -0
- package/package.json +33 -1
- package/profiles/forge-shell.yaml +1 -2
- package/profiles/knowledge.yaml +1 -1
- package/profiles/system.yaml +650 -0
- package/profiles/typescript.yaml +0 -1
- package/skills/fo/fo-outbox/SKILL.md +71 -0
- package/skills/fo/fo-system-dispatch/SKILL.md +65 -0
- package/skills/fo/fo-task-run/SKILL.md +75 -0
- package/src/index.ts +11 -4
- package/src/tests/fixtures/agents-generate-business-before.txt +6 -0
- package/src/tests/profile-flow-hooks.test.ts +15 -0
- package/src/tests/profile-schema.test.ts +2 -1
|
@@ -9,12 +9,15 @@ Unit tests for archive covering mission.archive. It also guards the documented p
|
|
|
9
9
|
</MODULE_CONTRACT>
|
|
10
10
|
<CHANGE_SUMMARY>
|
|
11
11
|
<item>RFC-1311: Compass header sweep — declares the archive suite's contract for test-file scaffold coverage.</item>
|
|
12
|
+
<item>RFC-1505: steps 3-5 — tracked lockfile restore, no side-effect commits</item>
|
|
13
|
+
<item>RFC-1505: review r1 — durable projections and lockfile restore hardening</item>
|
|
14
|
+
<item>RFC-1505: review r2 — clone-only sternsystem enumeration and mission-gated lockfile net</item>
|
|
12
15
|
</CHANGE_SUMMARY>
|
|
13
16
|
*/
|
|
14
17
|
|
|
15
18
|
import { test, expect, describe, beforeEach, afterEach, vi } from "vitest";
|
|
16
19
|
import fs from "node:fs/promises";
|
|
17
|
-
import { existsSync } from "node:fs";
|
|
20
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
18
21
|
import path from "node:path";
|
|
19
22
|
import os from "node:os";
|
|
20
23
|
import { runMissionArchive } from "./archive.ts";
|
|
@@ -25,9 +28,14 @@ vi.mock("../../../src/utils/fs-trash.ts", () => ({
|
|
|
25
28
|
}));
|
|
26
29
|
|
|
27
30
|
const execSyncMock = vi.fn<(cmd: string, opts?: Record<string, unknown>) => string | Buffer>();
|
|
31
|
+
const execFileSyncMock = vi.fn<
|
|
32
|
+
(cmd: string, args?: string[], opts?: Record<string, unknown>) => string | Buffer
|
|
33
|
+
>();
|
|
28
34
|
|
|
29
35
|
vi.mock("node:child_process", () => ({
|
|
30
36
|
execSync: (cmd: string, opts?: Record<string, unknown>) => execSyncMock(cmd, opts),
|
|
37
|
+
execFileSync: (cmd: string, args?: string[], opts?: Record<string, unknown>) =>
|
|
38
|
+
execFileSyncMock(cmd, args, opts),
|
|
31
39
|
}));
|
|
32
40
|
|
|
33
41
|
function makeContext(workspaceRoot: string): ForgeRuntimeContext {
|
|
@@ -77,6 +85,10 @@ beforeEach(async () => {
|
|
|
77
85
|
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "mission-archive-test-"));
|
|
78
86
|
missionsDir = path.join(tmpDir, "missions");
|
|
79
87
|
await fs.mkdir(missionsDir, { recursive: true });
|
|
88
|
+
execSyncMock.mockReset();
|
|
89
|
+
execSyncMock.mockReturnValue("");
|
|
90
|
+
execFileSyncMock.mockReset();
|
|
91
|
+
execFileSyncMock.mockReturnValue("");
|
|
80
92
|
});
|
|
81
93
|
|
|
82
94
|
afterEach(async () => {
|
|
@@ -435,58 +447,91 @@ describe("mission.archive", () => {
|
|
|
435
447
|
expect(installCall![1]).toMatchObject({ cwd: tmpDir });
|
|
436
448
|
});
|
|
437
449
|
|
|
438
|
-
test("RFC-
|
|
450
|
+
test("RFC-1505 AC-4: install churn on pnpm-lock.yaml is restored from HEAD, never committed", async () => {
|
|
451
|
+
const tracked = "lockfileVersion: '9.0'\n\nimporters: {}\n";
|
|
452
|
+
const churned = `${tracked}\n missions/test-m018/workpiece: {}\n`;
|
|
453
|
+
const lockfilePath = path.join(tmpDir, "pnpm-lock.yaml");
|
|
454
|
+
writeFileSync(lockfilePath, tracked);
|
|
439
455
|
execSyncMock.mockReset();
|
|
440
|
-
// pnpm install succeeds, git status shows dirty lockfile, git add/commit succeed
|
|
441
456
|
execSyncMock.mockImplementation((cmd: string) => {
|
|
442
|
-
if (cmd.startsWith("pnpm install"))
|
|
443
|
-
|
|
457
|
+
if (cmd.startsWith("pnpm install")) {
|
|
458
|
+
writeFileSync(lockfilePath, churned);
|
|
459
|
+
return "";
|
|
460
|
+
}
|
|
461
|
+
return "";
|
|
462
|
+
});
|
|
463
|
+
execFileSyncMock.mockReset();
|
|
464
|
+
execFileSyncMock.mockImplementation((cmd: string, args?: string[]) => {
|
|
465
|
+
if (cmd === "git" && args?.[0] === "show") return tracked;
|
|
444
466
|
return "";
|
|
445
467
|
});
|
|
446
468
|
await writeMissionManifest(missionsDir, "test-m018", "closed");
|
|
447
469
|
|
|
448
470
|
await runMissionArchive(makeInput(), makeContext(tmpDir));
|
|
449
471
|
|
|
450
|
-
|
|
451
|
-
|
|
472
|
+
expect(readFileSync(lockfilePath, "utf-8")).toBe(tracked);
|
|
473
|
+
// maxBuffer must cover real lockfiles (>10 MiB) — the 1 MiB execFileSync
|
|
474
|
+
// default would ENOBUFS-kill `git show` and leave the churn in place.
|
|
475
|
+
expect(execFileSyncMock).toHaveBeenCalledWith(
|
|
476
|
+
"git",
|
|
477
|
+
["show", "HEAD:pnpm-lock.yaml"],
|
|
478
|
+
expect.objectContaining({ cwd: tmpDir, maxBuffer: 64 * 1024 * 1024 }),
|
|
479
|
+
);
|
|
480
|
+
const gitWrites = execSyncMock.mock.calls.filter(
|
|
481
|
+
(c) =>
|
|
482
|
+
typeof c[0] === "string" &&
|
|
483
|
+
(c[0].startsWith("git add") ||
|
|
484
|
+
c[0].startsWith("git rm") ||
|
|
485
|
+
c[0].startsWith("git commit") ||
|
|
486
|
+
c[0].startsWith("git status")),
|
|
452
487
|
);
|
|
453
|
-
expect(
|
|
454
|
-
expect(commitCall![0]).toContain("refresh pnpm-lock.yaml after mission.archive");
|
|
488
|
+
expect(gitWrites).toEqual([]);
|
|
455
489
|
});
|
|
456
490
|
|
|
457
|
-
test("
|
|
491
|
+
test("RFC-1505 AC-4: no tracked lockfile at HEAD → churn left in place, no git calls", async () => {
|
|
492
|
+
const churned = "lockfileVersion: '9.0'\n# local churn\n";
|
|
493
|
+
const lockfilePath = path.join(tmpDir, "pnpm-lock.yaml");
|
|
458
494
|
execSyncMock.mockReset();
|
|
459
495
|
execSyncMock.mockImplementation((cmd: string) => {
|
|
460
|
-
if (cmd.startsWith("pnpm install"))
|
|
461
|
-
|
|
462
|
-
|
|
496
|
+
if (cmd.startsWith("pnpm install")) {
|
|
497
|
+
writeFileSync(lockfilePath, churned);
|
|
498
|
+
return "";
|
|
499
|
+
}
|
|
463
500
|
return "";
|
|
464
501
|
});
|
|
465
|
-
|
|
466
|
-
|
|
502
|
+
execFileSyncMock.mockReset();
|
|
503
|
+
execFileSyncMock.mockImplementation(() => {
|
|
504
|
+
throw Object.assign(new Error("fatal: path does not exist"), { status: 128 });
|
|
505
|
+
});
|
|
467
506
|
await writeMissionManifest(missionsDir, "test-m018b", "closed");
|
|
468
|
-
const warnings: string[] = [];
|
|
469
|
-
const context = makeContext(tmpDir);
|
|
470
|
-
(context.logger as { warn: (m: string) => void }).warn = (m: string) => warnings.push(m);
|
|
471
507
|
|
|
472
|
-
const data = unwrap(await runMissionArchive(makeInput(),
|
|
508
|
+
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
473
509
|
|
|
474
510
|
expect(data.moved).toHaveLength(1);
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
(c[0].startsWith("git add") || c[0].startsWith("git rm") || c[0].startsWith("git commit")),
|
|
511
|
+
expect(readFileSync(lockfilePath, "utf-8")).toBe(churned);
|
|
512
|
+
const gitCalls = execSyncMock.mock.calls.filter(
|
|
513
|
+
(c) => typeof c[0] === "string" && c[0].startsWith("git"),
|
|
479
514
|
);
|
|
480
|
-
expect(
|
|
481
|
-
expect(warnings.some((w) => w.includes("develop") && w.includes("flow.open"))).toBe(true);
|
|
515
|
+
expect(gitCalls).toEqual([]);
|
|
482
516
|
});
|
|
483
517
|
|
|
484
|
-
test("RFC-0804: pnpm install failure is non-fatal", async () => {
|
|
518
|
+
test("RFC-0804: pnpm install failure is non-fatal and still restores the lockfile", async () => {
|
|
519
|
+
const tracked = "lockfileVersion: '9.0'\n\nimporters: {}\n";
|
|
520
|
+
const churned = `${tracked}\n missions/test-m019/workpiece: {}\n`;
|
|
521
|
+
const lockfilePath = path.join(tmpDir, "pnpm-lock.yaml");
|
|
485
522
|
execSyncMock.mockReset();
|
|
486
523
|
execSyncMock.mockImplementation((cmd: string) => {
|
|
487
|
-
if (cmd.startsWith("pnpm install"))
|
|
524
|
+
if (cmd.startsWith("pnpm install")) {
|
|
525
|
+
writeFileSync(lockfilePath, churned);
|
|
526
|
+
throw new Error("ECONNREFUSED");
|
|
527
|
+
}
|
|
488
528
|
return "";
|
|
489
529
|
});
|
|
530
|
+
execFileSyncMock.mockReset();
|
|
531
|
+
execFileSyncMock.mockImplementation((cmd: string, args?: string[]) => {
|
|
532
|
+
if (cmd === "git" && args?.[0] === "show") return tracked;
|
|
533
|
+
throw Object.assign(new Error("unexpected"), { status: 1 });
|
|
534
|
+
});
|
|
490
535
|
await writeMissionManifest(missionsDir, "test-m019", "closed");
|
|
491
536
|
|
|
492
537
|
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
@@ -494,6 +539,8 @@ describe("mission.archive", () => {
|
|
|
494
539
|
expect(data.moved).toHaveLength(1);
|
|
495
540
|
expect(data.moved[0].missionId).toBe("test-m019");
|
|
496
541
|
expect(existsSync(path.join(missionsDir, "archive", "closed", "test-m019"))).toBe(true);
|
|
542
|
+
// A failed install still leaves churn — restore must run regardless.
|
|
543
|
+
expect(readFileSync(lockfilePath, "utf-8")).toBe(tracked);
|
|
497
544
|
});
|
|
498
545
|
|
|
499
546
|
test("RFC-0804: dry-run skips lockfile refresh", async () => {
|
|
@@ -651,52 +698,50 @@ describe("mission.archive", () => {
|
|
|
651
698
|
expect(data.skipped[0].reason).toContain("use --clean-orphans");
|
|
652
699
|
});
|
|
653
700
|
|
|
654
|
-
test("RFC-
|
|
701
|
+
test("RFC-1505: archive never stages or commits mission moves — no git calls at all", async () => {
|
|
655
702
|
execSyncMock.mockReset();
|
|
656
703
|
execSyncMock.mockImplementation((cmd: string) => {
|
|
657
704
|
if (cmd.startsWith("pnpm install")) return "";
|
|
658
|
-
if (cmd.startsWith("git status --porcelain pnpm-lock.yaml")) return "M pnpm-lock.yaml";
|
|
659
|
-
// git check-ignore exits 0 → path is ignored (missions/ is gitignored)
|
|
660
|
-
if (cmd.startsWith("git check-ignore")) return "";
|
|
661
705
|
return "";
|
|
662
706
|
});
|
|
707
|
+
execFileSyncMock.mockReset();
|
|
708
|
+
execFileSyncMock.mockReturnValue("tracked\n");
|
|
663
709
|
await writeMissionManifest(missionsDir, "test-r1138-01", "closed");
|
|
664
710
|
|
|
665
|
-
await runMissionArchive(makeInput(), makeContext(tmpDir));
|
|
666
|
-
|
|
667
|
-
const checkIgnoreCall = execSyncMock.mock.calls.find(
|
|
668
|
-
(c) => typeof c[0] === "string" && c[0].startsWith("git check-ignore"),
|
|
669
|
-
);
|
|
670
|
-
expect(checkIgnoreCall).toBeDefined();
|
|
711
|
+
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
671
712
|
|
|
672
|
-
|
|
673
|
-
|
|
713
|
+
expect(data.moved).toHaveLength(1);
|
|
714
|
+
expect(existsSync(path.join(missionsDir, "archive", "closed", "test-r1138-01"))).toBe(
|
|
715
|
+
true,
|
|
674
716
|
);
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
// Lockfile itself is still staged + committed
|
|
678
|
-
const lockfileAdd = execSyncMock.mock.calls.find(
|
|
679
|
-
(c) => typeof c[0] === "string" && c[0] === "git add pnpm-lock.yaml",
|
|
717
|
+
const gitCalls = execSyncMock.mock.calls.filter(
|
|
718
|
+
(c) => typeof c[0] === "string" && c[0].startsWith("git"),
|
|
680
719
|
);
|
|
681
|
-
expect(
|
|
720
|
+
expect(gitCalls).toEqual([]);
|
|
682
721
|
});
|
|
683
722
|
|
|
684
|
-
test("RFC-
|
|
723
|
+
test("RFC-1505: restore runs on any branch — no protected-branch check remains", async () => {
|
|
685
724
|
execSyncMock.mockReset();
|
|
686
725
|
execSyncMock.mockImplementation((cmd: string) => {
|
|
687
726
|
if (cmd.startsWith("pnpm install")) return "";
|
|
688
|
-
if (cmd.startsWith("git status --porcelain pnpm-lock.yaml")) return "M pnpm-lock.yaml";
|
|
689
|
-
// git check-ignore exits 1 → not ignored → execSync throws
|
|
690
|
-
if (cmd.startsWith("git check-ignore")) throw new Error("exit 1");
|
|
691
727
|
return "";
|
|
692
728
|
});
|
|
729
|
+
execFileSyncMock.mockReset();
|
|
730
|
+
execFileSyncMock.mockImplementation((cmd: string, args?: string[]) => {
|
|
731
|
+
if (cmd === "git" && args?.[0] === "show") return "tracked\n";
|
|
732
|
+
return "";
|
|
733
|
+
});
|
|
734
|
+
// A flow-adopted checkout on a protected branch — RFC-1505 removes the
|
|
735
|
+
// branch check entirely: no symbolic-ref probe, no staging, no commits.
|
|
736
|
+
await fs.mkdir(path.join(tmpDir, "hooks"), { recursive: true });
|
|
737
|
+
await fs.writeFile(path.join(tmpDir, "hooks", "flow-guard.sh"), "#!/bin/sh\n");
|
|
693
738
|
await writeMissionManifest(missionsDir, "test-r1138-02", "closed");
|
|
694
739
|
|
|
695
740
|
await runMissionArchive(makeInput(), makeContext(tmpDir));
|
|
696
741
|
|
|
697
|
-
const
|
|
698
|
-
(c) => typeof c[0] === "string" && c[0].startsWith("git
|
|
742
|
+
const gitCalls = execSyncMock.mock.calls.filter(
|
|
743
|
+
(c) => typeof c[0] === "string" && c[0].startsWith("git"),
|
|
699
744
|
);
|
|
700
|
-
expect(
|
|
745
|
+
expect(gitCalls).toEqual([]);
|
|
701
746
|
});
|
|
702
747
|
});
|
|
@@ -13,12 +13,12 @@ archive subdirectories back to missions/.
|
|
|
13
13
|
</non-goals>
|
|
14
14
|
</MODULE_CONTRACT>
|
|
15
15
|
<CHANGE_SUMMARY>
|
|
16
|
-
<item>RFC-1138: pipeline hygiene — module-scoped exempt entries, archive gitignore guard, dns upsert to deploy phases, promote auto-sync, rfc.create claim protocol, siteHasRuntime filter</item>
|
|
17
|
-
<item>RFC-1397: ship-in-flight guard — per-candidate isShipInFlight check in both move phases; SHIP-INFLIGHT-01 skip, SHIP-INFLIGHT-02 stale warn, --ship-op self-exemption for the ship's own terminal archive step.</item>
|
|
18
|
-
<item>warpgogol-m000175 fo-fix: deferred-release guard — closed missions without releaseId keep workpiece node_modules on archive (archived dirs fall outside the pnpm-workspace glob, so deps cannot be reinstalled in place and release.prepare would fail on WORKPIECE-IMPORTS-01); released missions still get full service-folder cleanup.</item>
|
|
19
16
|
<item>RFC-1397: harden ship-in-flight guard per independent review (RFC-1397)</item>
|
|
20
17
|
<item>RFC-1495: step 1 - forge state roots</item>
|
|
21
|
-
<
|
|
18
|
+
<item>RFC-1505: steps 3-5 — tracked lockfile restore, no side-effect commits</item>
|
|
19
|
+
<item>RFC-1505: review r1 — durable projections and lockfile restore hardening</item>
|
|
20
|
+
<item>RFC-1505: review r2 — clone-only sternsystem enumeration and mission-gated lockfile net</item>
|
|
21
|
+
<history>RFC-0573, RFC-0733, RFC-0801, RFC-0804, RFC-0982, RFC-1097, RFC-1138, RFC-1397, warpgogol-m000175</history>
|
|
22
22
|
</CHANGE_SUMMARY>
|
|
23
23
|
*/
|
|
24
24
|
|
|
@@ -33,6 +33,7 @@ import type {
|
|
|
33
33
|
ForgeRuntimeContext,
|
|
34
34
|
} from "../../../src/types.ts";
|
|
35
35
|
import { trashPath } from "../../../src/utils/fs-trash.ts";
|
|
36
|
+
import { writeFileIfChanged } from "../../../src/utils/fs-idempotent.ts";
|
|
36
37
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
37
38
|
// @ts-ignore — workspace dep, may not be installed when forge is used standalone from npm
|
|
38
39
|
import type { ShipInflightResult } from "@warpgogol/werkstatt-shared/kernel/ship-inflight";
|
|
@@ -46,7 +47,7 @@ import {
|
|
|
46
47
|
type MissionArchiveResult,
|
|
47
48
|
} from "../types.ts";
|
|
48
49
|
import { loadPinnedManifest, isPinned, isIntraDirMove } from "../../core/handlers/pinned-check.ts";
|
|
49
|
-
import {
|
|
50
|
+
import { restoreTrackedLockfile, execFileSyncAdapter } from "../lockfile.ts";
|
|
50
51
|
import { resolveStateRoots } from "../../flow/worktree-path.ts";
|
|
51
52
|
|
|
52
53
|
const SERVICE_FOLDERS = [
|
|
@@ -261,28 +262,6 @@ async function moveMissionDir(
|
|
|
261
262
|
};
|
|
262
263
|
}
|
|
263
264
|
|
|
264
|
-
/**
|
|
265
|
-
* The current branch when it is a protected integration branch of a repository
|
|
266
|
-
* that carries the forge flow guard — commits there are refused. `null` when
|
|
267
|
-
* commits are allowed (no guard, an auto branch, detached HEAD).
|
|
268
|
-
*/
|
|
269
|
-
function protectedFlowBranch(workspaceRoot: string): string | null {
|
|
270
|
-
if (!existsSync(path.join(workspaceRoot, "hooks", "flow-guard.sh"))) return null;
|
|
271
|
-
let branch: string;
|
|
272
|
-
try {
|
|
273
|
-
branch = String(
|
|
274
|
-
execSync("git symbolic-ref --short -q HEAD", {
|
|
275
|
-
cwd: workspaceRoot,
|
|
276
|
-
encoding: "utf-8",
|
|
277
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
278
|
-
}),
|
|
279
|
-
).trim();
|
|
280
|
-
} catch {
|
|
281
|
-
return null;
|
|
282
|
-
}
|
|
283
|
-
return (PROTECTED_BRANCHES as readonly string[]).includes(branch) ? branch : null;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
265
|
export async function runMissionArchive(
|
|
287
266
|
input: ForgeCommandInput,
|
|
288
267
|
context: ForgeRuntimeContext,
|
|
@@ -670,67 +649,43 @@ export async function runMissionArchive(
|
|
|
670
649
|
}
|
|
671
650
|
}
|
|
672
651
|
|
|
673
|
-
// RFC-0804: Post-move
|
|
652
|
+
// RFC-0804: Post-move dependency prune. RFC-1505: the local install may churn
|
|
653
|
+
// pnpm-lock.yaml — that churn is mission-local state and is never committed;
|
|
654
|
+
// the tracked lockfile is restored to HEAD bytes instead.
|
|
674
655
|
if (!dryRun && moved.length > 0) {
|
|
675
656
|
try {
|
|
657
|
+
// maxBuffer matches restoreTrackedLockfile's adapter — install output on
|
|
658
|
+
// a pruned workspace can exceed the ~1 MiB execSync default.
|
|
676
659
|
execSync("pnpm install", {
|
|
677
660
|
cwd: workspaceRoot,
|
|
678
661
|
stdio: ["pipe", "pipe", "pipe"],
|
|
679
662
|
timeout: 120_000,
|
|
663
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
680
664
|
});
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
//
|
|
688
|
-
//
|
|
689
|
-
const
|
|
690
|
-
|
|
665
|
+
} catch (installErr) {
|
|
666
|
+
logger.warn(
|
|
667
|
+
` pnpm install failed after archive — dependencies may be stale. Run 'pnpm install' manually: ${installErr instanceof Error ? installErr.message : String(installErr)}`,
|
|
668
|
+
);
|
|
669
|
+
}
|
|
670
|
+
try {
|
|
671
|
+
// Restore runs even when install failed — a partially-rewritten
|
|
672
|
+
// lockfile is still mission-local churn, never tracked bytes.
|
|
673
|
+
const restored = await restoreTrackedLockfile(workspaceRoot, {
|
|
674
|
+
...execFileSyncAdapter(),
|
|
675
|
+
writeFile: async (target, content) => {
|
|
676
|
+
await writeFileIfChanged(target, content);
|
|
677
|
+
},
|
|
678
|
+
});
|
|
679
|
+
if (restored) {
|
|
680
|
+
logger.info(" Restored pnpm-lock.yaml to HEAD bytes (install churn discarded)");
|
|
681
|
+
} else {
|
|
691
682
|
logger.warn(
|
|
692
|
-
|
|
693
|
-
);
|
|
694
|
-
} else if (lockfileStatus) {
|
|
695
|
-
execSync("git add pnpm-lock.yaml", {
|
|
696
|
-
cwd: workspaceRoot,
|
|
697
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
698
|
-
});
|
|
699
|
-
for (const m of moved) {
|
|
700
|
-
// RFC-1138: missions/ is gitignored — `git add` on the archive path is
|
|
701
|
-
// structurally guaranteed to fail. Skip staging when the target is
|
|
702
|
-
// ignored (git check-ignore exits 0 = ignored, 1 = not ignored).
|
|
703
|
-
let targetIgnored = false;
|
|
704
|
-
try {
|
|
705
|
-
execSync(`git check-ignore -q ${JSON.stringify(m.to)}`, {
|
|
706
|
-
cwd: workspaceRoot,
|
|
707
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
708
|
-
});
|
|
709
|
-
targetIgnored = true;
|
|
710
|
-
} catch {
|
|
711
|
-
targetIgnored = false;
|
|
712
|
-
}
|
|
713
|
-
if (!targetIgnored) {
|
|
714
|
-
execSync(`git add -A ${JSON.stringify(m.to)}`, {
|
|
715
|
-
cwd: workspaceRoot,
|
|
716
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
717
|
-
});
|
|
718
|
-
}
|
|
719
|
-
if (existsSync(m.from)) continue;
|
|
720
|
-
execSync(`git rm -r --cached --ignore-unmatch ${JSON.stringify(m.from)}`, {
|
|
721
|
-
cwd: workspaceRoot,
|
|
722
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
execSync(
|
|
726
|
-
`git commit -m ${JSON.stringify(`chore: refresh pnpm-lock.yaml after mission.archive (${moved.length} moved)`)}`,
|
|
727
|
-
{ cwd: workspaceRoot, stdio: ["pipe", "pipe", "pipe"] },
|
|
683
|
+
" No tracked pnpm-lock.yaml at HEAD — install churn left in place; nothing to restore",
|
|
728
684
|
);
|
|
729
|
-
logger.info(` Committed pnpm-lock.yaml refresh (${moved.length} missions archived)`);
|
|
730
685
|
}
|
|
731
686
|
} catch (refreshErr) {
|
|
732
687
|
logger.warn(
|
|
733
|
-
` Lockfile
|
|
688
|
+
` Lockfile restore failed after archive — lockfile may be stale. Run 'pnpm install' manually: ${refreshErr instanceof Error ? refreshErr.message : String(refreshErr)}`,
|
|
734
689
|
);
|
|
735
690
|
}
|
|
736
691
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>
|
|
4
|
+
Tracked lockfile restoration — after a mission lifecycle step runs `pnpm install`
|
|
5
|
+
for dependency pruning, the local install may rewrite `pnpm-lock.yaml`. That churn
|
|
6
|
+
is local mission state and must never land in tracked artifacts: this helper
|
|
7
|
+
restores the file committed at HEAD so the worktree returns clean.
|
|
8
|
+
</purpose>
|
|
9
|
+
<non-goals>
|
|
10
|
+
<item>Does not commit, stage, or delete the lockfile — only restores tracked bytes.</item>
|
|
11
|
+
<item>Does not synthesize a lockfile when HEAD carries none — returns false and changes nothing.</item>
|
|
12
|
+
</non-goals>
|
|
13
|
+
</MODULE_CONTRACT>
|
|
14
|
+
<CHANGE_SUMMARY>
|
|
15
|
+
<item>RFC-1505: step 3 — tracked lockfile restore helper</item>
|
|
16
|
+
<item>RFC-1505: steps 3-5 — tracked lockfile restore, no side-effect commits</item>
|
|
17
|
+
<item>RFC-1505: review r1 — durable projections and lockfile restore hardening</item>
|
|
18
|
+
<item>RFC-1505: review r2 — clone-only sternsystem enumeration and mission-gated lockfile net</item>
|
|
19
|
+
</CHANGE_SUMMARY>
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import path from "node:path";
|
|
23
|
+
import { execFileSync } from "../../src/utils/sync-fs.ts";
|
|
24
|
+
import type { ExecOptions, ExecResult, WorkspaceIO } from "../../src/types.ts";
|
|
25
|
+
|
|
26
|
+
const LOCKFILE_NAME = "pnpm-lock.yaml";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Restore `pnpm-lock.yaml` to the bytes committed at HEAD.
|
|
30
|
+
*
|
|
31
|
+
* Runs `git show HEAD:pnpm-lock.yaml` in `root`. On exit 0 the stdout is written
|
|
32
|
+
* back over `root/pnpm-lock.yaml` and the call returns `true`. On a non-zero
|
|
33
|
+
* exit (no such file at HEAD, not a git repository) it returns `false` and
|
|
34
|
+
* changes nothing. Spawn failures (missing git binary) propagate.
|
|
35
|
+
* `root` is the repository root — git resolves `HEAD:pnpm-lock.yaml` against
|
|
36
|
+
* the enclosing repo's top level, so passing a nested directory of a larger
|
|
37
|
+
* repo would restore that repo's root lockfile instead.
|
|
38
|
+
*/
|
|
39
|
+
export async function restoreTrackedLockfile(
|
|
40
|
+
root: string,
|
|
41
|
+
io: Pick<WorkspaceIO, "exec" | "writeFile">,
|
|
42
|
+
): Promise<boolean> {
|
|
43
|
+
const res = await io.exec("git", ["show", `HEAD:${LOCKFILE_NAME}`], { cwd: root });
|
|
44
|
+
if (res.exitCode !== 0) return false;
|
|
45
|
+
await io.writeFile(path.join(root, LOCKFILE_NAME), res.stdout);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Sync-world adapter for `io.exec` — wraps `execFileSync` so handlers that still
|
|
51
|
+
* run on `execSync`/`execFileSync` (e.g. mission.archive) can call
|
|
52
|
+
* `restoreTrackedLockfile` without duplicating its logic. A non-zero exit maps
|
|
53
|
+
* to `exitCode`; a spawn failure (missing binary) keeps throwing.
|
|
54
|
+
*/
|
|
55
|
+
export function execFileSyncAdapter(): Pick<WorkspaceIO, "exec"> {
|
|
56
|
+
return {
|
|
57
|
+
exec(command: string, args: string[], opts?: ExecOptions): Promise<ExecResult> {
|
|
58
|
+
try {
|
|
59
|
+
const stdout = execFileSync(command, args, {
|
|
60
|
+
cwd: opts?.cwd,
|
|
61
|
+
encoding: "utf-8",
|
|
62
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
63
|
+
timeout: opts?.timeoutMs,
|
|
64
|
+
// Real pnpm-lock.yaml files exceed the 1 MiB default many times over —
|
|
65
|
+
// an ENOBUFS kill carries status null and would rethrow below.
|
|
66
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
67
|
+
});
|
|
68
|
+
return Promise.resolve({ exitCode: 0, stdout, stderr: "" });
|
|
69
|
+
} catch (err) {
|
|
70
|
+
const e = err as {
|
|
71
|
+
status?: number | null;
|
|
72
|
+
stdout?: Buffer | string;
|
|
73
|
+
stderr?: Buffer | string;
|
|
74
|
+
};
|
|
75
|
+
if (e.status === undefined || e.status === null) throw err;
|
|
76
|
+
return Promise.resolve({
|
|
77
|
+
exitCode: e.status,
|
|
78
|
+
stdout: e.stdout?.toString() ?? "",
|
|
79
|
+
stderr: e.stderr?.toString() ?? "",
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
<item>RFC-0573: initial forgeMissionModule registering mission.archive command.</item>
|
|
10
10
|
<item>RFC-0982: add --clean-orphans flag for trashing orphaned remnant directories.</item>
|
|
11
11
|
<item>RFC-1397: declare internal --ship-op flag — ship's own opId marker for the terminal archive step exemption.</item>
|
|
12
|
+
<item>RFC-1505: review r2 — clone-only sternsystem enumeration and mission-gated lockfile net</item>
|
|
12
13
|
</CHANGE_SUMMARY>
|
|
13
14
|
*/
|
|
14
15
|
|
|
@@ -33,7 +34,7 @@ export async function createForgeMissionModule(): Promise<ForgeModule> {
|
|
|
33
34
|
"Prefer the docs.archive umbrella command unless you need to archive only missions.",
|
|
34
35
|
scope: "workspace",
|
|
35
36
|
mutatesState: true,
|
|
36
|
-
writes: ["missions/*", "missions/archive/**"],
|
|
37
|
+
writes: ["missions/*", "missions/archive/**", "pnpm-lock.yaml"],
|
|
37
38
|
generates: [],
|
|
38
39
|
reads: ["missions/**"],
|
|
39
40
|
cacheable: false,
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>RFC stamp-lock dead-holder tests (RFC-1504, AC-5, AC-6): a lock file
|
|
4
|
+
recording this host and a dead pid is broken and the stamp acquire succeeds;
|
|
5
|
+
a live pid keeps refusing with acquired:false (the RFC-IMP-05 path). Lock
|
|
6
|
+
files are planted by hand under a tmpdir workspace.</purpose>
|
|
7
|
+
<non-goals>
|
|
8
|
+
<item>No full stamp run — the criterion exercises the acquire path the
|
|
9
|
+
handler itself calls.</item>
|
|
10
|
+
</non-goals>
|
|
11
|
+
</MODULE_CONTRACT>
|
|
12
|
+
<CHANGE_SUMMARY>
|
|
13
|
+
<item>RFC-1504: step 4 — RFC stamp-lock tests</item>
|
|
14
|
+
<item>RFC-1504: step 1 — dead-holder lock tests</item>
|
|
15
|
+
<item>RFC-1504: review fixes — legacy acquiredAt fallback, atomic break claim, verified stamp release, onStale warnings</item>
|
|
16
|
+
</CHANGE_SUMMARY>
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
20
|
+
import { tmpdir, hostname } from "node:os";
|
|
21
|
+
import { join } from "node:path";
|
|
22
|
+
import { spawnSync } from "node:child_process";
|
|
23
|
+
|
|
24
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
25
|
+
|
|
26
|
+
import { acquireRfcLock } from "./implement-stamp.ts";
|
|
27
|
+
import { STAMP_LOCK_STALE_MS } from "../../core/stamp-lock.ts";
|
|
28
|
+
|
|
29
|
+
const dirs: string[] = [];
|
|
30
|
+
afterEach(async () => {
|
|
31
|
+
for (const dir of dirs.splice(0)) await rm(dir, { recursive: true, force: true });
|
|
32
|
+
}, 20_000);
|
|
33
|
+
|
|
34
|
+
const deadPid = (): number => {
|
|
35
|
+
const pid = spawnSync(process.execPath, ["-e", ""]).pid;
|
|
36
|
+
if (pid === undefined) throw new Error("spawn failed — cannot produce a dead pid");
|
|
37
|
+
return pid;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
async function workspaceWithLock(
|
|
41
|
+
payload: Record<string, unknown>,
|
|
42
|
+
): Promise<{ ws: string; lockPath: string }> {
|
|
43
|
+
const ws = await mkdtemp(join(tmpdir(), "rfc-lock-"));
|
|
44
|
+
dirs.push(ws);
|
|
45
|
+
const lockDir = join(ws, ".rfc-locks");
|
|
46
|
+
await mkdir(lockDir, { recursive: true });
|
|
47
|
+
const lockPath = join(lockDir, "rfc-9999.lock");
|
|
48
|
+
await writeFile(lockPath, JSON.stringify(payload));
|
|
49
|
+
return { ws, lockPath };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const freshAt = () => new Date().toISOString();
|
|
53
|
+
const oldAt = () => new Date(Date.now() - STAMP_LOCK_STALE_MS - 60_000).toISOString();
|
|
54
|
+
|
|
55
|
+
describe("rfc stamp lock dead-holder recovery (RFC-1504)", () => {
|
|
56
|
+
it("a dead pid is broken — acquire succeeds (AC-5)", async () => {
|
|
57
|
+
const { ws, lockPath } = await workspaceWithLock({
|
|
58
|
+
pid: deadPid(),
|
|
59
|
+
host: hostname(),
|
|
60
|
+
at: freshAt(),
|
|
61
|
+
});
|
|
62
|
+
const { acquired } = await acquireRfcLock(ws, "RFC-9999");
|
|
63
|
+
expect(acquired).toBe(true);
|
|
64
|
+
// The new holder's content is ours, not the dead pid's.
|
|
65
|
+
const held = JSON.parse(await readFile(lockPath, "utf8")) as { pid: number; host: string };
|
|
66
|
+
expect(held.pid).toBe(process.pid);
|
|
67
|
+
await rm(lockPath, { force: true });
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("a live pid still refuses — the RFC-IMP-05 path (AC-6)", async () => {
|
|
71
|
+
const { ws, lockPath } = await workspaceWithLock({
|
|
72
|
+
pid: process.pid,
|
|
73
|
+
host: hostname(),
|
|
74
|
+
at: freshAt(),
|
|
75
|
+
});
|
|
76
|
+
const { acquired } = await acquireRfcLock(ws, "RFC-9999");
|
|
77
|
+
expect(acquired).toBe(false);
|
|
78
|
+
const held = JSON.parse(await readFile(lockPath, "utf8")) as { pid: number };
|
|
79
|
+
expect(held.pid).toBe(process.pid);
|
|
80
|
+
await rm(lockPath, { force: true });
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("a foreign host is not broken by pid", async () => {
|
|
84
|
+
const { ws, lockPath } = await workspaceWithLock({
|
|
85
|
+
pid: deadPid(),
|
|
86
|
+
host: "other-host",
|
|
87
|
+
at: freshAt(),
|
|
88
|
+
});
|
|
89
|
+
const { acquired } = await acquireRfcLock(ws, "RFC-9999");
|
|
90
|
+
expect(acquired).toBe(false);
|
|
91
|
+
await rm(lockPath, { force: true });
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("legacy {pid, acquiredAt} locks are judged by age — an old one is broken", async () => {
|
|
95
|
+
const { ws, lockPath } = await workspaceWithLock({
|
|
96
|
+
pid: deadPid(),
|
|
97
|
+
acquiredAt: oldAt(),
|
|
98
|
+
});
|
|
99
|
+
const stale: { reason?: string }[] = [];
|
|
100
|
+
const { acquired } = await acquireRfcLock(ws, "RFC-9999", {
|
|
101
|
+
onStale: (i) => stale.push(i),
|
|
102
|
+
});
|
|
103
|
+
expect(acquired).toBe(true);
|
|
104
|
+
expect(stale[0]?.reason).toBe("stale-age");
|
|
105
|
+
await rm(lockPath, { force: true });
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("a fresh legacy {pid, acquiredAt} lock is refused — age under the limit", async () => {
|
|
109
|
+
const { ws, lockPath } = await workspaceWithLock({
|
|
110
|
+
pid: deadPid(),
|
|
111
|
+
acquiredAt: freshAt(),
|
|
112
|
+
});
|
|
113
|
+
const { acquired } = await acquireRfcLock(ws, "RFC-9999");
|
|
114
|
+
expect(acquired).toBe(false);
|
|
115
|
+
await rm(lockPath, { force: true });
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("a live pid past the stale budget is broken with reason stale-age", async () => {
|
|
119
|
+
const { ws, lockPath } = await workspaceWithLock({
|
|
120
|
+
pid: process.pid,
|
|
121
|
+
host: hostname(),
|
|
122
|
+
at: oldAt(),
|
|
123
|
+
});
|
|
124
|
+
const stale: { reason?: string; pid?: number }[] = [];
|
|
125
|
+
const { acquired } = await acquireRfcLock(ws, "RFC-9999", {
|
|
126
|
+
onStale: (i) => stale.push(i),
|
|
127
|
+
});
|
|
128
|
+
expect(acquired).toBe(true);
|
|
129
|
+
expect(stale[0]?.reason).toBe("stale-age");
|
|
130
|
+
expect(stale[0]?.pid).toBe(process.pid);
|
|
131
|
+
await rm(lockPath, { force: true });
|
|
132
|
+
});
|
|
133
|
+
});
|