@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.
- package/AGENTS.md +50 -27
- package/CHANGELOG.md +27 -0
- package/bin/cli.js +0 -0
- package/dist/os/codebase/handlers/codebase-measure-symbols.d.ts.map +1 -1
- package/dist/os/codebase/handlers/codebase-measure-symbols.js +35 -4
- package/dist/os/codebase/handlers/codebase-measure-symbols.js.map +1 -1
- package/dist/os/core/core.module.d.ts.map +1 -1
- package/dist/os/core/core.module.js +1 -69
- package/dist/os/core/core.module.js.map +1 -1
- package/dist/os/core/handlers/assets-helpers.d.ts.map +1 -1
- package/dist/os/core/handlers/assets-helpers.js +2 -3
- package/dist/os/core/handlers/assets-helpers.js.map +1 -1
- package/dist/os/core/handlers/determinism-check.d.ts.map +1 -1
- package/dist/os/core/handlers/determinism-check.js +2 -3
- package/dist/os/core/handlers/determinism-check.js.map +1 -1
- package/dist/os/core/handlers/release-prepare.d.ts.map +1 -1
- package/dist/os/core/handlers/release-prepare.js +2 -4
- package/dist/os/core/handlers/release-prepare.js.map +1 -1
- package/dist/os/flow/handlers/flow-peers.js +1 -1
- package/dist/os/flow/handlers/flow-peers.js.map +1 -1
- package/dist/os/{mission → flow}/open-missions.d.ts +1 -2
- package/dist/os/flow/open-missions.d.ts.map +1 -0
- package/dist/os/flow/open-missions.js +37 -0
- package/dist/os/flow/open-missions.js.map +1 -0
- package/dist/os/flow/preflight.js +1 -1
- package/dist/os/flow/preflight.js.map +1 -1
- package/dist/src/command-modules.d.ts.map +1 -1
- package/dist/src/command-modules.js +0 -2
- package/dist/src/command-modules.js.map +1 -1
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +0 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/onboarding/doctor.d.ts +0 -5
- package/dist/src/onboarding/doctor.d.ts.map +1 -1
- package/dist/src/onboarding/doctor.js +6 -79
- package/dist/src/onboarding/doctor.js.map +1 -1
- package/dist/src/onboarding/npm-token-check.d.ts +1 -1
- package/dist/src/onboarding/npm-token-check.d.ts.map +1 -1
- package/dist/src/onboarding/npm-token-check.js +2 -2
- package/dist/src/onboarding/npm-token-check.js.map +1 -1
- package/dist/src/utils/hash.d.ts +1 -0
- package/dist/src/utils/hash.d.ts.map +1 -1
- package/dist/src/utils/hash.js +4 -0
- package/dist/src/utils/hash.js.map +1 -1
- package/dist/{os/mission → src/utils}/lockfile.d.ts +1 -18
- package/dist/src/utils/lockfile.d.ts.map +1 -0
- package/dist/src/utils/lockfile.js +70 -0
- package/dist/src/utils/lockfile.js.map +1 -0
- package/os/codebase/handlers/codebase-measure-symbols.ts +32 -4
- package/os/core/core.module.ts +3 -76
- package/os/core/handlers/assets-helpers.ts +2 -4
- package/os/core/handlers/determinism-check.ts +2 -3
- package/os/core/handlers/lifecycle-handlers.test.ts +529 -0
- package/os/core/handlers/release-prepare.ts +2 -4
- package/os/correctness/gate/trust-boundary-cx18.test.ts +1 -1
- package/os/flow/handlers/flow-peers.ts +1 -1
- package/os/flow/open-missions.ts +45 -0
- package/os/flow/preflight.ts +1 -1
- package/os/flow/tests/release-lines.test.ts +136 -0
- package/os/flow/tests/state-roots.test.ts +1 -48
- package/os/rfc/handlers/validate-corpus.test.ts +149 -0
- package/os/rfc/probe-batch.test.ts +253 -0
- package/os/rfc/verifier/rfc-1391/ac10-operating-model-policy.acceptance.test.ts +63 -0
- package/package.json +161 -506
- package/src/command-modules.ts +0 -2
- package/src/index.ts +0 -2
- package/src/onboarding/doctor.ts +9 -96
- package/src/onboarding/npm-token-check.ts +3 -3
- package/src/tests/pkg-health-self-scan.test.ts +29 -0
- package/src/tests/rfc-evidence-sync.test.ts +369 -0
- package/src/tests/skill-agents-sync.test.ts +192 -0
- package/src/utils/hash.ts +5 -0
- package/src/utils/lockfile.ts +78 -0
- package/dist/os/core/handlers/forge-autonomy-validate.d.ts +0 -25
- package/dist/os/core/handlers/forge-autonomy-validate.d.ts.map +0 -1
- package/dist/os/core/handlers/forge-autonomy-validate.js +0 -208
- package/dist/os/core/handlers/forge-autonomy-validate.js.map +0 -1
- package/dist/os/mission/handlers/archive.d.ts +0 -4
- package/dist/os/mission/handlers/archive.d.ts.map +0 -1
- package/dist/os/mission/handlers/archive.js +0 -583
- package/dist/os/mission/handlers/archive.js.map +0 -1
- package/dist/os/mission/importer-block.d.ts +0 -19
- package/dist/os/mission/importer-block.d.ts.map +0 -1
- package/dist/os/mission/importer-block.js +0 -124
- package/dist/os/mission/importer-block.js.map +0 -1
- package/dist/os/mission/index.d.ts +0 -2
- package/dist/os/mission/index.d.ts.map +0 -1
- package/dist/os/mission/index.js +0 -15
- package/dist/os/mission/index.js.map +0 -1
- package/dist/os/mission/lockfile.d.ts.map +0 -1
- package/dist/os/mission/lockfile.js +0 -138
- package/dist/os/mission/lockfile.js.map +0 -1
- package/dist/os/mission/mission.module.d.ts +0 -3
- package/dist/os/mission/mission.module.d.ts.map +0 -1
- package/dist/os/mission/mission.module.js +0 -63
- package/dist/os/mission/mission.module.js.map +0 -1
- package/dist/os/mission/open-missions.d.ts.map +0 -1
- package/dist/os/mission/open-missions.js +0 -42
- package/dist/os/mission/open-missions.js.map +0 -1
- package/dist/os/mission/types.d.ts +0 -23
- package/dist/os/mission/types.d.ts.map +0 -1
- package/dist/os/mission/types.js +0 -19
- package/dist/os/mission/types.js.map +0 -1
- package/dist/os/werkstatt/handlers/lock.d.ts +0 -10
- package/dist/os/werkstatt/handlers/lock.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/lock.js +0 -153
- package/dist/os/werkstatt/handlers/lock.js.map +0 -1
- package/dist/os/werkstatt/handlers/schema.d.ts +0 -33
- package/dist/os/werkstatt/handlers/schema.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/schema.js +0 -42
- package/dist/os/werkstatt/handlers/schema.js.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-lock-recover.d.ts +0 -15
- package/dist/os/werkstatt/handlers/werkstatt-lock-recover.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-lock-recover.js +0 -171
- package/dist/os/werkstatt/handlers/werkstatt-lock-recover.js.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-lock-status.d.ts +0 -18
- package/dist/os/werkstatt/handlers/werkstatt-lock-status.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-lock-status.js +0 -51
- package/dist/os/werkstatt/handlers/werkstatt-lock-status.js.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-operation-validate.d.ts +0 -11
- package/dist/os/werkstatt/handlers/werkstatt-operation-validate.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-operation-validate.js +0 -86
- package/dist/os/werkstatt/handlers/werkstatt-operation-validate.js.map +0 -1
- package/dist/os/werkstatt/handlers/workspace-deps.d.ts +0 -12
- package/dist/os/werkstatt/handlers/workspace-deps.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/workspace-deps.js +0 -42
- package/dist/os/werkstatt/handlers/workspace-deps.js.map +0 -1
- package/dist/os/werkstatt/index.d.ts +0 -7
- package/dist/os/werkstatt/index.d.ts.map +0 -1
- package/dist/os/werkstatt/index.js +0 -18
- package/dist/os/werkstatt/index.js.map +0 -1
- package/dist/os/werkstatt/werkstatt.module.d.ts +0 -3
- package/dist/os/werkstatt/werkstatt.module.d.ts.map +0 -1
- package/dist/os/werkstatt/werkstatt.module.js +0 -91
- package/dist/os/werkstatt/werkstatt.module.js.map +0 -1
- package/os/core/handlers/forge-autonomy-validate.ts +0 -276
- package/os/correctness/gate/trust-boundary-cx19.test.ts +0 -514
- package/os/mission/handlers/archive.test.ts +0 -764
- package/os/mission/handlers/archive.ts +0 -711
- package/os/mission/handlers/ship-inflight-degraded.test.ts +0 -105
- package/os/mission/importer-block.ts +0 -119
- package/os/mission/index.ts +0 -15
- package/os/mission/lockfile.ts +0 -152
- package/os/mission/mission.module.ts +0 -68
- package/os/mission/open-missions.ts +0 -50
- package/os/mission/types.ts +0 -42
- package/os/werkstatt/handlers/lock.ts +0 -168
- package/os/werkstatt/handlers/schema.ts +0 -47
- package/os/werkstatt/handlers/werkstatt-lock-recover.ts +0 -206
- package/os/werkstatt/handlers/werkstatt-lock-status.ts +0 -82
- package/os/werkstatt/handlers/werkstatt-operation-validate.ts +0 -112
- package/os/werkstatt/handlers/workspace-deps.ts +0 -56
- package/os/werkstatt/index.ts +0 -39
- package/os/werkstatt/werkstatt.module.ts +0 -95
- package/src/tests/doctor-autonomy.test.ts +0 -246
- package/src/tests/forge-autonomy-validate.test.ts +0 -159
- package/src/tests/werkstatt-lock.test.ts +0 -357
|
@@ -1,764 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
<MODULE_CONTRACT>
|
|
3
|
-
<purpose>
|
|
4
|
-
Unit tests for archive covering mission.archive. It also guards the documented public contract and regression-sensitive edge cases.
|
|
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-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>
|
|
15
|
-
</CHANGE_SUMMARY>
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { test, expect, describe, beforeEach, afterEach, vi } from "vitest";
|
|
19
|
-
import fs from "node:fs/promises";
|
|
20
|
-
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
21
|
-
import path from "node:path";
|
|
22
|
-
import os from "node:os";
|
|
23
|
-
import { runMissionArchive } from "./archive.ts";
|
|
24
|
-
import type { ForgeCommandInput, ForgeRuntimeContext } from "../../../src/types.ts";
|
|
25
|
-
|
|
26
|
-
vi.mock("../../../src/utils/fs-trash.ts", () => ({
|
|
27
|
-
trashPath: (targetPath: string) => fs.rm(targetPath, { recursive: true, force: true }),
|
|
28
|
-
}));
|
|
29
|
-
|
|
30
|
-
const execSyncMock = vi.fn<(cmd: string, opts?: Record<string, unknown>) => string | Buffer>();
|
|
31
|
-
const execFileSyncMock =
|
|
32
|
-
vi.fn<(cmd: string, args?: string[], opts?: Record<string, unknown>) => string | Buffer>();
|
|
33
|
-
|
|
34
|
-
// The lockfile-restore path reads `HEAD:pnpm-lock.yaml` through the
|
|
35
|
-
// judged evidence channel (CX-164) — that channel spawns real git via
|
|
36
|
-
// `spawn`, so the actual child_process module must be spread in and only
|
|
37
|
-
// the legacy `execSync`/`execFileSync` entry points intercepted.
|
|
38
|
-
vi.mock("node:child_process", async (importActual) => {
|
|
39
|
-
const actual = await importActual<typeof import("node:child_process")>();
|
|
40
|
-
return {
|
|
41
|
-
...actual,
|
|
42
|
-
execSync: (cmd: string, opts?: Record<string, unknown>) => execSyncMock(cmd, opts),
|
|
43
|
-
execFileSync: (cmd: string, args?: string[], opts?: Record<string, unknown>) =>
|
|
44
|
-
execFileSyncMock(cmd, args, opts),
|
|
45
|
-
};
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* A real git repo — `verifierGit` cannot be satisfied by the execFileSync
|
|
50
|
-
* mock, so lockfile-restore tests commit the tracked bytes for real.
|
|
51
|
-
*/
|
|
52
|
-
async function initRepoWithCommit(root: string, files: Record<string, string>): Promise<void> {
|
|
53
|
-
const cp = await vi.importActual<typeof import("node:child_process")>("node:child_process");
|
|
54
|
-
const git = (args: string[]) => cp.execFileSync("git", args, { cwd: root });
|
|
55
|
-
git(["init", "-q", "."]);
|
|
56
|
-
git(["config", "user.email", "archive-test@example.com"]);
|
|
57
|
-
git(["config", "user.name", "archive-test"]);
|
|
58
|
-
for (const [name, content] of Object.entries(files)) {
|
|
59
|
-
writeFileSync(path.join(root, name), content);
|
|
60
|
-
}
|
|
61
|
-
git(["add", ...Object.keys(files)]);
|
|
62
|
-
git(["commit", "-qm", "init"]);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function makeContext(workspaceRoot: string): ForgeRuntimeContext {
|
|
66
|
-
return {
|
|
67
|
-
workspaceRoot,
|
|
68
|
-
logger: {
|
|
69
|
-
info: () => {},
|
|
70
|
-
success: () => {},
|
|
71
|
-
warn: () => {},
|
|
72
|
-
error: () => {},
|
|
73
|
-
debug: () => {},
|
|
74
|
-
},
|
|
75
|
-
outputFormat: "json",
|
|
76
|
-
dryRun: false,
|
|
77
|
-
} as unknown as ForgeRuntimeContext;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function makeInput(flags: Record<string, unknown> = {}): ForgeCommandInput {
|
|
81
|
-
return {
|
|
82
|
-
commandName: "mission.archive",
|
|
83
|
-
flags,
|
|
84
|
-
} as unknown as ForgeCommandInput;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function unwrap<T>(result: { data?: T }): T {
|
|
88
|
-
if (!result.data) throw new Error("result.data is undefined");
|
|
89
|
-
return result.data;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async function writeMissionManifest(
|
|
93
|
-
missionsDir: string,
|
|
94
|
-
missionId: string,
|
|
95
|
-
state: string,
|
|
96
|
-
): Promise<void> {
|
|
97
|
-
const missionDir = path.join(missionsDir, missionId);
|
|
98
|
-
await fs.mkdir(missionDir, { recursive: true });
|
|
99
|
-
await fs.writeFile(
|
|
100
|
-
path.join(missionDir, "mission.yaml"),
|
|
101
|
-
`missionId: ${missionId}\nstate: ${state}\n`,
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
let tmpDir: string;
|
|
106
|
-
let missionsDir: string;
|
|
107
|
-
|
|
108
|
-
beforeEach(async () => {
|
|
109
|
-
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "mission-archive-test-"));
|
|
110
|
-
missionsDir = path.join(tmpDir, "missions");
|
|
111
|
-
await fs.mkdir(missionsDir, { recursive: true });
|
|
112
|
-
execSyncMock.mockReset();
|
|
113
|
-
execSyncMock.mockReturnValue("");
|
|
114
|
-
execFileSyncMock.mockReset();
|
|
115
|
-
execFileSyncMock.mockReturnValue("");
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
afterEach(async () => {
|
|
119
|
-
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
describe("mission.archive", () => {
|
|
123
|
-
test("terminal mission (closed) → moved to archive/closed/", async () => {
|
|
124
|
-
await writeMissionManifest(missionsDir, "test-m001", "closed");
|
|
125
|
-
|
|
126
|
-
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
127
|
-
|
|
128
|
-
expect(data.moved).toHaveLength(1);
|
|
129
|
-
expect(data.moved[0].missionId).toBe("test-m001");
|
|
130
|
-
expect(data.moved[0].state).toBe("closed");
|
|
131
|
-
expect(data.moved[0].direction).toBe("into-archive");
|
|
132
|
-
expect(existsSync(path.join(missionsDir, "test-m001"))).toBe(false);
|
|
133
|
-
expect(existsSync(path.join(missionsDir, "archive", "closed", "test-m001"))).toBe(true);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
test("terminal mission (aborted) → moved to archive/aborted/", async () => {
|
|
137
|
-
await writeMissionManifest(missionsDir, "test-m002", "aborted");
|
|
138
|
-
|
|
139
|
-
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
140
|
-
|
|
141
|
-
expect(data.moved).toHaveLength(1);
|
|
142
|
-
expect(data.moved[0].missionId).toBe("test-m002");
|
|
143
|
-
expect(data.moved[0].state).toBe("aborted");
|
|
144
|
-
expect(existsSync(path.join(missionsDir, "archive", "aborted", "test-m002"))).toBe(true);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
test("open mission → skipped (non-terminal)", async () => {
|
|
148
|
-
await writeMissionManifest(missionsDir, "test-m003", "open");
|
|
149
|
-
|
|
150
|
-
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
151
|
-
|
|
152
|
-
expect(data.moved).toHaveLength(0);
|
|
153
|
-
expect(data.skipped).toHaveLength(1);
|
|
154
|
-
expect(data.skipped[0].reason).toContain("non-terminal");
|
|
155
|
-
expect(existsSync(path.join(missionsDir, "test-m003"))).toBe(true);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
test("--status closed filter → only closed missions moved", async () => {
|
|
159
|
-
await writeMissionManifest(missionsDir, "test-m004", "closed");
|
|
160
|
-
await writeMissionManifest(missionsDir, "test-m005", "aborted");
|
|
161
|
-
|
|
162
|
-
const data = unwrap(
|
|
163
|
-
await runMissionArchive(makeInput({ status: "closed" }), makeContext(tmpDir)),
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
expect(data.moved).toHaveLength(1);
|
|
167
|
-
expect(data.moved[0].missionId).toBe("test-m004");
|
|
168
|
-
expect(existsSync(path.join(missionsDir, "test-m005"))).toBe(true);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
test("--dry-run → reports moves without touching filesystem", async () => {
|
|
172
|
-
await writeMissionManifest(missionsDir, "test-m006", "closed");
|
|
173
|
-
|
|
174
|
-
const data = unwrap(
|
|
175
|
-
await runMissionArchive(makeInput({ "dry-run": true }), makeContext(tmpDir)),
|
|
176
|
-
);
|
|
177
|
-
|
|
178
|
-
expect(data.moved).toHaveLength(1);
|
|
179
|
-
expect(data.dryRun).toBe(true);
|
|
180
|
-
expect(existsSync(path.join(missionsDir, "test-m006"))).toBe(true);
|
|
181
|
-
expect(existsSync(path.join(missionsDir, "archive", "closed", "test-m006"))).toBe(false);
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
test("closed mission without releaseId → warns in pretty mode", async () => {
|
|
185
|
-
await writeMissionManifest(missionsDir, "test-m007", "closed");
|
|
186
|
-
const warnSpy = vi.fn();
|
|
187
|
-
const ctx: ForgeRuntimeContext = {
|
|
188
|
-
workspaceRoot: tmpDir,
|
|
189
|
-
logger: {
|
|
190
|
-
info: () => {},
|
|
191
|
-
success: () => {},
|
|
192
|
-
warn: warnSpy,
|
|
193
|
-
error: () => {},
|
|
194
|
-
debug: () => {},
|
|
195
|
-
},
|
|
196
|
-
outputFormat: "pretty",
|
|
197
|
-
dryRun: false,
|
|
198
|
-
} as unknown as ForgeRuntimeContext;
|
|
199
|
-
|
|
200
|
-
await runMissionArchive(makeInput(), ctx);
|
|
201
|
-
|
|
202
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
203
|
-
expect.stringContaining("test-m007: closed mission has no releaseId"),
|
|
204
|
-
);
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
test("closed mission with releaseId → no warning", async () => {
|
|
208
|
-
const missionDir = path.join(missionsDir, "test-m008");
|
|
209
|
-
await fs.mkdir(missionDir, { recursive: true });
|
|
210
|
-
await fs.writeFile(
|
|
211
|
-
path.join(missionDir, "mission.yaml"),
|
|
212
|
-
`missionId: test-m008\nstate: closed\nreleaseId: test-r000001\n`,
|
|
213
|
-
);
|
|
214
|
-
const warnSpy = vi.fn();
|
|
215
|
-
const ctx: ForgeRuntimeContext = {
|
|
216
|
-
workspaceRoot: tmpDir,
|
|
217
|
-
logger: {
|
|
218
|
-
info: () => {},
|
|
219
|
-
success: () => {},
|
|
220
|
-
warn: warnSpy,
|
|
221
|
-
error: () => {},
|
|
222
|
-
debug: () => {},
|
|
223
|
-
},
|
|
224
|
-
outputFormat: "pretty",
|
|
225
|
-
dryRun: false,
|
|
226
|
-
} as unknown as ForgeRuntimeContext;
|
|
227
|
-
|
|
228
|
-
await runMissionArchive(makeInput(), ctx);
|
|
229
|
-
|
|
230
|
-
expect(
|
|
231
|
-
warnSpy.mock.calls.some(
|
|
232
|
-
(c) =>
|
|
233
|
-
typeof c[0] === "string" && c[0].includes("test-m008: closed mission has no releaseId"),
|
|
234
|
-
),
|
|
235
|
-
).toBe(false);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
test("destination exists → skipped with 'destination exists' reason", async () => {
|
|
239
|
-
await writeMissionManifest(missionsDir, "test-m007", "closed");
|
|
240
|
-
const archiveDir = path.join(missionsDir, "archive", "closed", "test-m007");
|
|
241
|
-
await fs.mkdir(archiveDir, { recursive: true });
|
|
242
|
-
await fs.writeFile(
|
|
243
|
-
path.join(archiveDir, "mission.yaml"),
|
|
244
|
-
"missionId: test-m007\nstate: closed\n",
|
|
245
|
-
);
|
|
246
|
-
|
|
247
|
-
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
248
|
-
|
|
249
|
-
expect(data.moved).toHaveLength(0);
|
|
250
|
-
expect(data.skipped).toHaveLength(2);
|
|
251
|
-
expect(data.skipped.some((s) => s.reason === "destination exists")).toBe(true);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
test("unreadable manifest with empty dir → skipped with 'empty remnant' reason", async () => {
|
|
255
|
-
const missionDir = path.join(missionsDir, "test-m008");
|
|
256
|
-
await fs.mkdir(missionDir, { recursive: true });
|
|
257
|
-
// No mission.yaml, no workpiece — empty remnant
|
|
258
|
-
|
|
259
|
-
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
260
|
-
|
|
261
|
-
expect(data.moved).toHaveLength(0);
|
|
262
|
-
expect(data.skipped).toHaveLength(1);
|
|
263
|
-
expect(data.skipped[0].reason).toBe("empty remnant — use --clean-orphans to remove");
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
test("open mission in archive/ → moved back to missions/ (bidirectional)", async () => {
|
|
267
|
-
await writeMissionManifest(missionsDir, "test-m009", "open");
|
|
268
|
-
const archiveMissionDir = path.join(missionsDir, "archive", "closed", "test-m010");
|
|
269
|
-
await fs.mkdir(archiveMissionDir, { recursive: true });
|
|
270
|
-
await fs.writeFile(
|
|
271
|
-
path.join(archiveMissionDir, "mission.yaml"),
|
|
272
|
-
"missionId: test-m010\nstate: open\n",
|
|
273
|
-
);
|
|
274
|
-
|
|
275
|
-
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
276
|
-
|
|
277
|
-
const outOfArchive = data.moved.filter((m) => m.direction === "out-of-archive");
|
|
278
|
-
expect(outOfArchive).toHaveLength(1);
|
|
279
|
-
expect(outOfArchive[0].missionId).toBe("test-m010");
|
|
280
|
-
expect(existsSync(path.join(missionsDir, "test-m010"))).toBe(true);
|
|
281
|
-
expect(existsSync(archiveMissionDir)).toBe(false);
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
test("resurrected source path (e.g. .astro/ cache) → cleaned up after rename", async () => {
|
|
285
|
-
await writeMissionManifest(missionsDir, "test-m011", "closed");
|
|
286
|
-
const missionDir = path.join(missionsDir, "test-m011");
|
|
287
|
-
|
|
288
|
-
// Simulate a watcher recreating a stale cache dir after rename by
|
|
289
|
-
// monkey-patching fs.rename to re-create .astro/ at the source.
|
|
290
|
-
const originalRename = fs.rename;
|
|
291
|
-
const astroCacheDir = path.join(missionDir, "workpiece", ".astro");
|
|
292
|
-
vi.spyOn(fs, "rename").mockImplementation(async (src, dest) => {
|
|
293
|
-
await originalRename(src, dest);
|
|
294
|
-
// Simulate IDE/watcher recreating stale cache at old path
|
|
295
|
-
await fs.mkdir(path.join(missionDir, "workpiece", ".astro"), { recursive: true });
|
|
296
|
-
await fs.writeFile(path.join(astroCacheDir, "content.d.ts"), "// stale cache\n");
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
300
|
-
|
|
301
|
-
vi.mocked(fs.rename).mockRestore();
|
|
302
|
-
|
|
303
|
-
expect(data.moved).toHaveLength(1);
|
|
304
|
-
expect(data.moved[0].missionId).toBe("test-m011");
|
|
305
|
-
expect(existsSync(missionDir)).toBe(false);
|
|
306
|
-
expect(existsSync(path.join(missionsDir, "archive", "closed", "test-m011"))).toBe(true);
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
test("invalid --status value → throws error", async () => {
|
|
310
|
-
await expect(
|
|
311
|
-
runMissionArchive(makeInput({ status: "invalid" }), makeContext(tmpDir)),
|
|
312
|
-
).rejects.toThrow('Invalid --status "invalid"');
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
test("no missions/ directory → empty result", async () => {
|
|
316
|
-
const emptyDir = await fs.mkdtemp(path.join(os.tmpdir(), "mission-archive-empty-"));
|
|
317
|
-
try {
|
|
318
|
-
const data = unwrap(await runMissionArchive(makeInput(), makeContext(emptyDir)));
|
|
319
|
-
expect(data.moved).toHaveLength(0);
|
|
320
|
-
expect(data.skipped).toHaveLength(0);
|
|
321
|
-
} finally {
|
|
322
|
-
await fs.rm(emptyDir, { recursive: true, force: true });
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
test("RFC-0796: stale symlink in missions/ root → trashed", async () => {
|
|
327
|
-
// Create an archived mission
|
|
328
|
-
const archiveMissionDir = path.join(missionsDir, "archive", "closed", "test-m012");
|
|
329
|
-
await fs.mkdir(archiveMissionDir, { recursive: true });
|
|
330
|
-
await fs.writeFile(
|
|
331
|
-
path.join(archiveMissionDir, "mission.yaml"),
|
|
332
|
-
"missionId: test-m012\nstate: closed\n",
|
|
333
|
-
);
|
|
334
|
-
|
|
335
|
-
// Create a stale symlink pointing to the archived mission
|
|
336
|
-
const symlinkPath = path.join(missionsDir, "test-m012");
|
|
337
|
-
await fs.symlink(archiveMissionDir, symlinkPath);
|
|
338
|
-
|
|
339
|
-
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
340
|
-
|
|
341
|
-
// Symlink should be trashed
|
|
342
|
-
expect(existsSync(symlinkPath)).toBe(false);
|
|
343
|
-
// Archived mission should still exist
|
|
344
|
-
expect(existsSync(archiveMissionDir)).toBe(true);
|
|
345
|
-
// Should be reported as skipped with stale symlink reason
|
|
346
|
-
expect(data.skipped.some((s) => s.reason === "stale symlink — trashed")).toBe(true);
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
test("RFC-0796: stale symlink in --dry-run → not trashed, reported", async () => {
|
|
350
|
-
const archiveMissionDir = path.join(missionsDir, "archive", "closed", "test-m013");
|
|
351
|
-
await fs.mkdir(archiveMissionDir, { recursive: true });
|
|
352
|
-
await fs.writeFile(
|
|
353
|
-
path.join(archiveMissionDir, "mission.yaml"),
|
|
354
|
-
"missionId: test-m013\nstate: closed\n",
|
|
355
|
-
);
|
|
356
|
-
|
|
357
|
-
const symlinkPath = path.join(missionsDir, "test-m013");
|
|
358
|
-
await fs.symlink(archiveMissionDir, symlinkPath);
|
|
359
|
-
|
|
360
|
-
const data = unwrap(
|
|
361
|
-
await runMissionArchive(makeInput({ "dry-run": true }), makeContext(tmpDir)),
|
|
362
|
-
);
|
|
363
|
-
|
|
364
|
-
// In dry-run, symlink should NOT be trashed
|
|
365
|
-
expect(existsSync(symlinkPath)).toBe(true);
|
|
366
|
-
// But should be reported as skipped
|
|
367
|
-
expect(data.skipped.some((s) => s.reason === "stale symlink — trashed")).toBe(true);
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
test("RFC-0801: service folders deleted before move", async () => {
|
|
371
|
-
// Mission carries a releaseId — already released, so the deferred-release
|
|
372
|
-
// guard does not apply and all service folders are cleaned.
|
|
373
|
-
const missionDir = path.join(missionsDir, "test-m014");
|
|
374
|
-
await fs.mkdir(missionDir, { recursive: true });
|
|
375
|
-
await fs.writeFile(
|
|
376
|
-
path.join(missionDir, "mission.yaml"),
|
|
377
|
-
`missionId: test-m014\nstate: closed\nreleaseId: test-r000014\n`,
|
|
378
|
-
);
|
|
379
|
-
const workpieceDir = path.join(missionDir, "workpiece");
|
|
380
|
-
await fs.mkdir(workpieceDir, { recursive: true });
|
|
381
|
-
|
|
382
|
-
// Create service folders with dummy content
|
|
383
|
-
for (const folder of ["node_modules", "dist", ".astro", ".wrangler", ".cache", ".turbo"]) {
|
|
384
|
-
const folderPath = path.join(workpieceDir, folder);
|
|
385
|
-
await fs.mkdir(folderPath, { recursive: true });
|
|
386
|
-
await fs.writeFile(path.join(folderPath, "dummy.txt"), `content of ${folder}\n`);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
390
|
-
|
|
391
|
-
expect(data.moved).toHaveLength(1);
|
|
392
|
-
expect(data.moved[0].missionId).toBe("test-m014");
|
|
393
|
-
|
|
394
|
-
const archivedWorkpiece = path.join(missionsDir, "archive", "closed", "test-m014", "workpiece");
|
|
395
|
-
for (const folder of ["node_modules", "dist", ".astro", ".wrangler", ".cache", ".turbo"]) {
|
|
396
|
-
expect(existsSync(path.join(archivedWorkpiece, folder))).toBe(false);
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
test("deferred-release guard: closed mission without releaseId → node_modules preserved", async () => {
|
|
401
|
-
await writeMissionManifest(missionsDir, "test-m014b", "closed");
|
|
402
|
-
const missionDir = path.join(missionsDir, "test-m014b");
|
|
403
|
-
const workpieceDir = path.join(missionDir, "workpiece");
|
|
404
|
-
await fs.mkdir(workpieceDir, { recursive: true });
|
|
405
|
-
|
|
406
|
-
for (const folder of ["node_modules", "dist", ".astro"]) {
|
|
407
|
-
const folderPath = path.join(workpieceDir, folder);
|
|
408
|
-
await fs.mkdir(folderPath, { recursive: true });
|
|
409
|
-
await fs.writeFile(path.join(folderPath, "dummy.txt"), `content of ${folder}\n`);
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
413
|
-
|
|
414
|
-
expect(data.moved).toHaveLength(1);
|
|
415
|
-
const archivedWorkpiece = path.join(
|
|
416
|
-
missionsDir,
|
|
417
|
-
"archive",
|
|
418
|
-
"closed",
|
|
419
|
-
"test-m014b",
|
|
420
|
-
"workpiece",
|
|
421
|
-
);
|
|
422
|
-
// node_modules preserved so release.prepare can still run on the archived
|
|
423
|
-
// workpiece — archived dirs fall outside the pnpm-workspace glob.
|
|
424
|
-
expect(existsSync(path.join(archivedWorkpiece, "node_modules"))).toBe(true);
|
|
425
|
-
expect(existsSync(path.join(archivedWorkpiece, "node_modules", "dummy.txt"))).toBe(true);
|
|
426
|
-
// Other service folders still cleaned.
|
|
427
|
-
expect(existsSync(path.join(archivedWorkpiece, "dist"))).toBe(false);
|
|
428
|
-
expect(existsSync(path.join(archivedWorkpiece, ".astro"))).toBe(false);
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
test("RFC-0801: mission without workpiece — cleanup skipped gracefully", async () => {
|
|
432
|
-
await writeMissionManifest(missionsDir, "test-m015", "closed");
|
|
433
|
-
// No workpiece/ directory created — simulates aborted mission
|
|
434
|
-
|
|
435
|
-
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
436
|
-
|
|
437
|
-
expect(data.moved).toHaveLength(1);
|
|
438
|
-
expect(data.moved[0].missionId).toBe("test-m015");
|
|
439
|
-
expect(existsSync(path.join(missionsDir, "archive", "closed", "test-m015"))).toBe(true);
|
|
440
|
-
});
|
|
441
|
-
|
|
442
|
-
test("RFC-0801: --dry-run does not delete service folders", async () => {
|
|
443
|
-
await writeMissionManifest(missionsDir, "test-m016", "closed");
|
|
444
|
-
const missionDir = path.join(missionsDir, "test-m016");
|
|
445
|
-
const workpieceDir = path.join(missionDir, "workpiece");
|
|
446
|
-
await fs.mkdir(workpieceDir, { recursive: true });
|
|
447
|
-
await fs.mkdir(path.join(workpieceDir, "node_modules"), { recursive: true });
|
|
448
|
-
await fs.writeFile(path.join(workpieceDir, "node_modules", "pkg.txt"), "content\n");
|
|
449
|
-
|
|
450
|
-
const data = unwrap(
|
|
451
|
-
await runMissionArchive(makeInput({ "dry-run": true }), makeContext(tmpDir)),
|
|
452
|
-
);
|
|
453
|
-
|
|
454
|
-
expect(data.dryRun).toBe(true);
|
|
455
|
-
// Service folders should still exist at source in dry-run
|
|
456
|
-
expect(existsSync(path.join(workpieceDir, "node_modules"))).toBe(true);
|
|
457
|
-
expect(existsSync(path.join(workpieceDir, "node_modules", "pkg.txt"))).toBe(true);
|
|
458
|
-
});
|
|
459
|
-
|
|
460
|
-
test("RFC-0804: pnpm install called after moves", async () => {
|
|
461
|
-
execSyncMock.mockReset();
|
|
462
|
-
execSyncMock.mockReturnValue("");
|
|
463
|
-
await writeMissionManifest(missionsDir, "test-m017", "closed");
|
|
464
|
-
|
|
465
|
-
await runMissionArchive(makeInput(), makeContext(tmpDir));
|
|
466
|
-
|
|
467
|
-
const installCall = execSyncMock.mock.calls.find(
|
|
468
|
-
(c) => typeof c[0] === "string" && c[0].startsWith("pnpm install"),
|
|
469
|
-
);
|
|
470
|
-
expect(installCall).toBeDefined();
|
|
471
|
-
expect(installCall![1]).toMatchObject({ cwd: tmpDir });
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
test("RFC-1505 AC-4: install churn on pnpm-lock.yaml is restored from HEAD, never committed", async () => {
|
|
475
|
-
const tracked = "lockfileVersion: '9.0'\n\nimporters: {}\n";
|
|
476
|
-
const churned = `${tracked}\n missions/test-m018/workpiece: {}\n`;
|
|
477
|
-
const lockfilePath = path.join(tmpDir, "pnpm-lock.yaml");
|
|
478
|
-
// The HEAD-bytes read goes through the judged evidence channel on a
|
|
479
|
-
// real repo (CX-164) — the execFileSync mock cannot answer `git show`.
|
|
480
|
-
await initRepoWithCommit(tmpDir, { "pnpm-lock.yaml": tracked });
|
|
481
|
-
execSyncMock.mockReset();
|
|
482
|
-
execSyncMock.mockImplementation((cmd: string) => {
|
|
483
|
-
if (cmd.startsWith("pnpm install")) {
|
|
484
|
-
writeFileSync(lockfilePath, churned);
|
|
485
|
-
return "";
|
|
486
|
-
}
|
|
487
|
-
return "";
|
|
488
|
-
});
|
|
489
|
-
await writeMissionManifest(missionsDir, "test-m018", "closed");
|
|
490
|
-
|
|
491
|
-
await runMissionArchive(makeInput(), makeContext(tmpDir));
|
|
492
|
-
|
|
493
|
-
expect(readFileSync(lockfilePath, "utf-8")).toBe(tracked);
|
|
494
|
-
// `spawnCaptured` carries maxBuffer 64 MiB internally — real lockfiles
|
|
495
|
-
// (>10 MiB) cannot ENOBUFS the restore. And the committed-bytes read
|
|
496
|
-
// no longer travels ambient exec: a session `GIT_DIR` lever would
|
|
497
|
-
// redirect `HEAD:` to a foreign object store (CX-164), so the judged
|
|
498
|
-
// channel must own `git show` — ambient execFileSync never sees it.
|
|
499
|
-
expect(
|
|
500
|
-
execFileSyncMock.mock.calls.filter((c) => c[0] === "git" && c[1]?.[0] === "show"),
|
|
501
|
-
).toEqual([]);
|
|
502
|
-
const gitWrites = execSyncMock.mock.calls.filter(
|
|
503
|
-
(c) =>
|
|
504
|
-
typeof c[0] === "string" &&
|
|
505
|
-
(c[0].startsWith("git add") ||
|
|
506
|
-
c[0].startsWith("git rm") ||
|
|
507
|
-
c[0].startsWith("git commit") ||
|
|
508
|
-
c[0].startsWith("git status")),
|
|
509
|
-
);
|
|
510
|
-
expect(gitWrites).toEqual([]);
|
|
511
|
-
});
|
|
512
|
-
|
|
513
|
-
test("RFC-1505 AC-4: no tracked lockfile at HEAD → churn left in place, no git calls", async () => {
|
|
514
|
-
const churned = "lockfileVersion: '9.0'\n# local churn\n";
|
|
515
|
-
const lockfilePath = path.join(tmpDir, "pnpm-lock.yaml");
|
|
516
|
-
execSyncMock.mockReset();
|
|
517
|
-
execSyncMock.mockImplementation((cmd: string) => {
|
|
518
|
-
if (cmd.startsWith("pnpm install")) {
|
|
519
|
-
writeFileSync(lockfilePath, churned);
|
|
520
|
-
return "";
|
|
521
|
-
}
|
|
522
|
-
return "";
|
|
523
|
-
});
|
|
524
|
-
execFileSyncMock.mockReset();
|
|
525
|
-
execFileSyncMock.mockImplementation(() => {
|
|
526
|
-
throw Object.assign(new Error("fatal: path does not exist"), { status: 128 });
|
|
527
|
-
});
|
|
528
|
-
await writeMissionManifest(missionsDir, "test-m018b", "closed");
|
|
529
|
-
|
|
530
|
-
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
531
|
-
|
|
532
|
-
expect(data.moved).toHaveLength(1);
|
|
533
|
-
expect(readFileSync(lockfilePath, "utf-8")).toBe(churned);
|
|
534
|
-
const gitCalls = execSyncMock.mock.calls.filter(
|
|
535
|
-
(c) => typeof c[0] === "string" && c[0].startsWith("git"),
|
|
536
|
-
);
|
|
537
|
-
expect(gitCalls).toEqual([]);
|
|
538
|
-
});
|
|
539
|
-
|
|
540
|
-
test("RFC-0804: pnpm install failure is non-fatal and still restores the lockfile", async () => {
|
|
541
|
-
const tracked = "lockfileVersion: '9.0'\n\nimporters: {}\n";
|
|
542
|
-
const churned = `${tracked}\n missions/test-m019/workpiece: {}\n`;
|
|
543
|
-
const lockfilePath = path.join(tmpDir, "pnpm-lock.yaml");
|
|
544
|
-
execSyncMock.mockReset();
|
|
545
|
-
execSyncMock.mockImplementation((cmd: string) => {
|
|
546
|
-
if (cmd.startsWith("pnpm install")) {
|
|
547
|
-
writeFileSync(lockfilePath, churned);
|
|
548
|
-
throw new Error("ECONNREFUSED");
|
|
549
|
-
}
|
|
550
|
-
return "";
|
|
551
|
-
});
|
|
552
|
-
// Real repo — the judged channel serves `HEAD:pnpm-lock.yaml` (CX-164).
|
|
553
|
-
await initRepoWithCommit(tmpDir, { "pnpm-lock.yaml": tracked });
|
|
554
|
-
await writeMissionManifest(missionsDir, "test-m019", "closed");
|
|
555
|
-
|
|
556
|
-
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
557
|
-
|
|
558
|
-
expect(data.moved).toHaveLength(1);
|
|
559
|
-
expect(data.moved[0].missionId).toBe("test-m019");
|
|
560
|
-
expect(existsSync(path.join(missionsDir, "archive", "closed", "test-m019"))).toBe(true);
|
|
561
|
-
// A failed install still leaves churn — restore must run regardless.
|
|
562
|
-
expect(readFileSync(lockfilePath, "utf-8")).toBe(tracked);
|
|
563
|
-
});
|
|
564
|
-
|
|
565
|
-
test("RFC-0804: dry-run skips lockfile refresh", async () => {
|
|
566
|
-
execSyncMock.mockReset();
|
|
567
|
-
execSyncMock.mockReturnValue("");
|
|
568
|
-
await writeMissionManifest(missionsDir, "test-m020", "closed");
|
|
569
|
-
|
|
570
|
-
await runMissionArchive(makeInput({ "dry-run": true }), makeContext(tmpDir));
|
|
571
|
-
|
|
572
|
-
const installCall = execSyncMock.mock.calls.find(
|
|
573
|
-
(c) => typeof c[0] === "string" && c[0].startsWith("pnpm install"),
|
|
574
|
-
);
|
|
575
|
-
expect(installCall).toBeUndefined();
|
|
576
|
-
});
|
|
577
|
-
|
|
578
|
-
test("RFC-0804: no moves skips lockfile refresh", async () => {
|
|
579
|
-
execSyncMock.mockReset();
|
|
580
|
-
execSyncMock.mockReturnValue("");
|
|
581
|
-
|
|
582
|
-
await runMissionArchive(makeInput(), makeContext(tmpDir));
|
|
583
|
-
|
|
584
|
-
const installCall = execSyncMock.mock.calls.find(
|
|
585
|
-
(c) => typeof c[0] === "string" && c[0].startsWith("pnpm install"),
|
|
586
|
-
);
|
|
587
|
-
expect(installCall).toBeUndefined();
|
|
588
|
-
});
|
|
589
|
-
|
|
590
|
-
// RFC-0982: Fallback state detection and --clean-orphans tests
|
|
591
|
-
|
|
592
|
-
test("RFC-0982: orphaned workpiece with only .astro/ cache → state detected as closed, archived", async () => {
|
|
593
|
-
const missionDir = path.join(missionsDir, "test-r982-01");
|
|
594
|
-
const workpieceDir = path.join(missionDir, "workpiece");
|
|
595
|
-
await fs.mkdir(path.join(workpieceDir, ".astro"), { recursive: true });
|
|
596
|
-
await fs.writeFile(path.join(workpieceDir, ".astro", "cache.txt"), "cache\n");
|
|
597
|
-
// No mission.yaml — orphaned remnant
|
|
598
|
-
|
|
599
|
-
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
600
|
-
|
|
601
|
-
expect(data.moved).toHaveLength(1);
|
|
602
|
-
expect(data.moved[0].missionId).toBe("test-r982-01");
|
|
603
|
-
expect(data.moved[0].state).toBe("closed");
|
|
604
|
-
expect(data.moved[0].direction).toBe("into-archive");
|
|
605
|
-
expect(existsSync(path.join(missionsDir, "archive", "closed", "test-r982-01"))).toBe(true);
|
|
606
|
-
});
|
|
607
|
-
|
|
608
|
-
test("RFC-0982: .closed marker fallback → state detected as closed", async () => {
|
|
609
|
-
const missionDir = path.join(missionsDir, "test-r982-02");
|
|
610
|
-
const workpieceDir = path.join(missionDir, "workpiece");
|
|
611
|
-
await fs.mkdir(workpieceDir, { recursive: true });
|
|
612
|
-
await fs.writeFile(path.join(workpieceDir, ".closed"), "2026-08-29T12:00:00Z\n");
|
|
613
|
-
// Also add a source file so it's not cache-only
|
|
614
|
-
await fs.writeFile(path.join(workpieceDir, "src.ts"), "// source\n");
|
|
615
|
-
// No mission.yaml — but .closed marker present
|
|
616
|
-
|
|
617
|
-
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
618
|
-
|
|
619
|
-
expect(data.moved).toHaveLength(1);
|
|
620
|
-
expect(data.moved[0].missionId).toBe("test-r982-02");
|
|
621
|
-
expect(data.moved[0].state).toBe("closed");
|
|
622
|
-
expect(existsSync(path.join(missionsDir, "archive", "closed", "test-r982-02"))).toBe(true);
|
|
623
|
-
});
|
|
624
|
-
|
|
625
|
-
test("RFC-0982: --clean-orphans trashes orphaned remnant dir", async () => {
|
|
626
|
-
const missionDir = path.join(missionsDir, "test-r982-03");
|
|
627
|
-
const workpieceDir = path.join(missionDir, "workpiece");
|
|
628
|
-
await fs.mkdir(path.join(workpieceDir, ".astro"), { recursive: true });
|
|
629
|
-
await fs.writeFile(path.join(workpieceDir, ".astro", "cache.txt"), "cache\n");
|
|
630
|
-
// No mission.yaml — orphaned remnant with only cache
|
|
631
|
-
|
|
632
|
-
const data = unwrap(
|
|
633
|
-
await runMissionArchive(makeInput({ "clean-orphans": true }), makeContext(tmpDir)),
|
|
634
|
-
);
|
|
635
|
-
|
|
636
|
-
expect(data.moved).toHaveLength(1);
|
|
637
|
-
expect(data.moved[0].missionId).toBe("test-r982-03");
|
|
638
|
-
expect(data.moved[0].direction).toBe("trashed-orphan");
|
|
639
|
-
expect(data.moved[0].to).toBe("(trashed)");
|
|
640
|
-
expect(existsSync(missionDir)).toBe(false);
|
|
641
|
-
});
|
|
642
|
-
|
|
643
|
-
test("RFC-0982: --clean-orphans --dry-run → reported but not trashed", async () => {
|
|
644
|
-
const missionDir = path.join(missionsDir, "test-r982-04");
|
|
645
|
-
const workpieceDir = path.join(missionDir, "workpiece");
|
|
646
|
-
await fs.mkdir(path.join(workpieceDir, ".astro"), { recursive: true });
|
|
647
|
-
await fs.writeFile(path.join(workpieceDir, ".astro", "cache.txt"), "cache\n");
|
|
648
|
-
|
|
649
|
-
const data = unwrap(
|
|
650
|
-
await runMissionArchive(
|
|
651
|
-
makeInput({ "clean-orphans": true, "dry-run": true }),
|
|
652
|
-
makeContext(tmpDir),
|
|
653
|
-
),
|
|
654
|
-
);
|
|
655
|
-
|
|
656
|
-
expect(data.moved).toHaveLength(1);
|
|
657
|
-
expect(data.moved[0].direction).toBe("trashed-orphan");
|
|
658
|
-
expect(data.dryRun).toBe(true);
|
|
659
|
-
// Dir should still exist in dry-run
|
|
660
|
-
expect(existsSync(missionDir)).toBe(true);
|
|
661
|
-
});
|
|
662
|
-
|
|
663
|
-
test("RFC-0982: --clean-orphans skips non-orphaned dir with mission.yaml", async () => {
|
|
664
|
-
await writeMissionManifest(missionsDir, "test-r982-05", "closed");
|
|
665
|
-
const workpieceDir = path.join(missionsDir, "test-r982-05", "workpiece");
|
|
666
|
-
await fs.mkdir(path.join(workpieceDir, ".astro"), { recursive: true });
|
|
667
|
-
|
|
668
|
-
const data = unwrap(
|
|
669
|
-
await runMissionArchive(makeInput({ "clean-orphans": true }), makeContext(tmpDir)),
|
|
670
|
-
);
|
|
671
|
-
|
|
672
|
-
// Should be archived normally, not trashed
|
|
673
|
-
expect(data.moved).toHaveLength(1);
|
|
674
|
-
expect(data.moved[0].direction).toBe("into-archive");
|
|
675
|
-
expect(existsSync(path.join(missionsDir, "archive", "closed", "test-r982-05"))).toBe(true);
|
|
676
|
-
});
|
|
677
|
-
|
|
678
|
-
test("RFC-0982: skip reason 'manually inspect' for dir with non-cache content but no mission.yaml", async () => {
|
|
679
|
-
const missionDir = path.join(missionsDir, "test-r982-06");
|
|
680
|
-
const workpieceDir = path.join(missionDir, "workpiece");
|
|
681
|
-
await fs.mkdir(workpieceDir, { recursive: true });
|
|
682
|
-
// Source file in workpiece — non-cache content, no .closed marker
|
|
683
|
-
await fs.writeFile(path.join(workpieceDir, "src.ts"), "// source code\n");
|
|
684
|
-
// No mission.yaml
|
|
685
|
-
|
|
686
|
-
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
687
|
-
|
|
688
|
-
expect(data.moved).toHaveLength(0);
|
|
689
|
-
expect(data.skipped).toHaveLength(1);
|
|
690
|
-
expect(data.skipped[0].reason).toContain("manually inspect");
|
|
691
|
-
});
|
|
692
|
-
|
|
693
|
-
test("RFC-0982: --clean-orphans trashes empty remnant dir (no workpiece, no mission.yaml)", async () => {
|
|
694
|
-
const missionDir = path.join(missionsDir, "test-r982-08");
|
|
695
|
-
await fs.mkdir(missionDir, { recursive: true });
|
|
696
|
-
// No mission.yaml, no workpiece — empty remnant, state would be null
|
|
697
|
-
|
|
698
|
-
const data = unwrap(
|
|
699
|
-
await runMissionArchive(makeInput({ "clean-orphans": true }), makeContext(tmpDir)),
|
|
700
|
-
);
|
|
701
|
-
|
|
702
|
-
expect(data.moved).toHaveLength(1);
|
|
703
|
-
expect(data.moved[0].missionId).toBe("test-r982-08");
|
|
704
|
-
expect(data.moved[0].direction).toBe("trashed-orphan");
|
|
705
|
-
expect(existsSync(missionDir)).toBe(false);
|
|
706
|
-
});
|
|
707
|
-
|
|
708
|
-
test("RFC-0982: skip reason 'use --clean-orphans' for empty remnant dir", async () => {
|
|
709
|
-
const missionDir = path.join(missionsDir, "test-r982-07");
|
|
710
|
-
await fs.mkdir(missionDir, { recursive: true });
|
|
711
|
-
// No mission.yaml, no workpiece, no content — empty remnant
|
|
712
|
-
|
|
713
|
-
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
714
|
-
|
|
715
|
-
expect(data.moved).toHaveLength(0);
|
|
716
|
-
expect(data.skipped).toHaveLength(1);
|
|
717
|
-
expect(data.skipped[0].reason).toContain("use --clean-orphans");
|
|
718
|
-
});
|
|
719
|
-
|
|
720
|
-
test("RFC-1505: archive never stages or commits mission moves — no git calls at all", async () => {
|
|
721
|
-
execSyncMock.mockReset();
|
|
722
|
-
execSyncMock.mockImplementation((cmd: string) => {
|
|
723
|
-
if (cmd.startsWith("pnpm install")) return "";
|
|
724
|
-
return "";
|
|
725
|
-
});
|
|
726
|
-
execFileSyncMock.mockReset();
|
|
727
|
-
execFileSyncMock.mockReturnValue("tracked\n");
|
|
728
|
-
await writeMissionManifest(missionsDir, "test-r1138-01", "closed");
|
|
729
|
-
|
|
730
|
-
const data = unwrap(await runMissionArchive(makeInput(), makeContext(tmpDir)));
|
|
731
|
-
|
|
732
|
-
expect(data.moved).toHaveLength(1);
|
|
733
|
-
expect(existsSync(path.join(missionsDir, "archive", "closed", "test-r1138-01"))).toBe(true);
|
|
734
|
-
const gitCalls = execSyncMock.mock.calls.filter(
|
|
735
|
-
(c) => typeof c[0] === "string" && c[0].startsWith("git"),
|
|
736
|
-
);
|
|
737
|
-
expect(gitCalls).toEqual([]);
|
|
738
|
-
});
|
|
739
|
-
|
|
740
|
-
test("RFC-1505: restore runs on any branch — no protected-branch check remains", async () => {
|
|
741
|
-
execSyncMock.mockReset();
|
|
742
|
-
execSyncMock.mockImplementation((cmd: string) => {
|
|
743
|
-
if (cmd.startsWith("pnpm install")) return "";
|
|
744
|
-
return "";
|
|
745
|
-
});
|
|
746
|
-
execFileSyncMock.mockReset();
|
|
747
|
-
execFileSyncMock.mockImplementation((cmd: string, args?: string[]) => {
|
|
748
|
-
if (cmd === "git" && args?.[0] === "show") return "tracked\n";
|
|
749
|
-
return "";
|
|
750
|
-
});
|
|
751
|
-
// A flow-adopted checkout on a protected branch — RFC-1505 removes the
|
|
752
|
-
// branch check entirely: no symbolic-ref probe, no staging, no commits.
|
|
753
|
-
await fs.mkdir(path.join(tmpDir, "hooks"), { recursive: true });
|
|
754
|
-
await fs.writeFile(path.join(tmpDir, "hooks", "flow-guard.sh"), "#!/bin/sh\n");
|
|
755
|
-
await writeMissionManifest(missionsDir, "test-r1138-02", "closed");
|
|
756
|
-
|
|
757
|
-
await runMissionArchive(makeInput(), makeContext(tmpDir));
|
|
758
|
-
|
|
759
|
-
const gitCalls = execSyncMock.mock.calls.filter(
|
|
760
|
-
(c) => typeof c[0] === "string" && c[0].startsWith("git"),
|
|
761
|
-
);
|
|
762
|
-
expect(gitCalls).toEqual([]);
|
|
763
|
-
});
|
|
764
|
-
});
|