oh-my-codex 0.21.47 → 0.21.48
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/Cargo.lock +6 -6
- package/Cargo.toml +1 -1
- package/dist/cli/__tests__/plugin-cache-live-pin-3790.test.js +707 -47
- package/dist/cli/__tests__/plugin-cache-live-pin-3790.test.js.map +1 -1
- package/dist/cli/__tests__/setup-install-mode.test.js +7 -1
- package/dist/cli/__tests__/setup-install-mode.test.js.map +1 -1
- package/dist/cli/plugin-marketplace.d.ts.map +1 -1
- package/dist/cli/plugin-marketplace.js +328 -142
- package/dist/cli/plugin-marketplace.js.map +1 -1
- package/dist/hooks/__tests__/sunset-routing-contract.test.js +4 -2
- package/dist/hooks/__tests__/sunset-routing-contract.test.js.map +1 -1
- package/dist/scripts/__tests__/generate-release-body.test.js +142 -5
- package/dist/scripts/__tests__/generate-release-body.test.js.map +1 -1
- package/dist/scripts/generate-release-body.d.ts.map +1 -1
- package/dist/scripts/generate-release-body.js +14 -0
- package/dist/scripts/generate-release-body.js.map +1 -1
- package/package.json +1 -1
- package/plugins/oh-my-codex/.codex-plugin/plugin.json +1 -1
- package/plugins/oh-my-codex/hooks/codex-native-hook.mjs +208 -25
- package/prompts/build-fixer.md +2 -1
- package/prompts/debugger.md +2 -1
- package/prompts/git-master.md +2 -1
- package/prompts/style-reviewer.md +2 -1
- package/prompts/team-executor.md +3 -2
- package/prompts/vision.md +2 -1
- package/prompts/writer.md +2 -1
- package/src/scripts/__tests__/generate-release-body.test.ts +151 -5
- package/src/scripts/generate-release-body.ts +16 -0
|
@@ -59,8 +59,9 @@ async function markAsPrePinManagedSnapshot(cacheDir, version, markerFormat) {
|
|
|
59
59
|
const claimDigest = await computeOmxPluginCacheClaimDigest(cacheDir);
|
|
60
60
|
await writeFile(join(cacheDir, ".omx-complete"), `${JSON.stringify({ version, claimDigest })}\n`);
|
|
61
61
|
}
|
|
62
|
-
async function writeDeadLivePin(cacheDir) {
|
|
63
|
-
const
|
|
62
|
+
async function writeDeadLivePin(cacheDir, codexHomeDir, version) {
|
|
63
|
+
const cacheBase = omxPluginCacheBase(codexHomeDir);
|
|
64
|
+
const markerDir = join(cacheBase, ".omx-pins", version);
|
|
64
65
|
await mkdir(markerDir, { recursive: true });
|
|
65
66
|
const record = {
|
|
66
67
|
version: 1,
|
|
@@ -74,6 +75,9 @@ function livePinMutationLockPath(codexHomeDir, version) {
|
|
|
74
75
|
const versionHash = createHash("sha256").update(version).digest("hex").slice(0, 24);
|
|
75
76
|
return join(omxPluginCacheBase(codexHomeDir), `.omx-live-pin-${versionHash}.lock`);
|
|
76
77
|
}
|
|
78
|
+
function livePinDirectoryPath(codexHomeDir, version) {
|
|
79
|
+
return join(omxPluginCacheBase(codexHomeDir), ".omx-pins", version);
|
|
80
|
+
}
|
|
77
81
|
function livePinIntentPath(codexHomeDir, version, sessionId) {
|
|
78
82
|
const versionHash = createHash("sha256").update(version).digest("hex").slice(0, 24);
|
|
79
83
|
const sessionHash = createHash("sha256").update(sessionId).digest("hex");
|
|
@@ -93,11 +97,13 @@ async function writeLivePinMutationLock(codexHomeDir, version, ownerPid, operati
|
|
|
93
97
|
}
|
|
94
98
|
return { path, stagePath, content };
|
|
95
99
|
}
|
|
96
|
-
async function assertDelegateSurvivesLostLeasesWithPin(wd, codexHomeDir, pluginRoot, sessionId, launchId, pinName, pinContent) {
|
|
97
|
-
const pinDirectory =
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
async function assertDelegateSurvivesLostLeasesWithPin(wd, codexHomeDir, pluginRoot, sessionId, launchId, pinName, pinContent, version) {
|
|
101
|
+
const pinDirectory = livePinDirectoryPath(codexHomeDir, version);
|
|
102
|
+
const pinPath = join(pinDirectory, pinName ?? "no-external-pin");
|
|
103
|
+
if (pinName !== null) {
|
|
104
|
+
await mkdir(pinDirectory, { recursive: true });
|
|
105
|
+
await writeFile(pinPath, pinContent);
|
|
106
|
+
}
|
|
101
107
|
const delegateStartedPath = join(wd, `${launchId}-delegate-started`);
|
|
102
108
|
const delegateStoppedPath = join(wd, `${launchId}-delegate-stopped`);
|
|
103
109
|
const delegateFinishedPath = join(wd, `${launchId}-delegate-finished`);
|
|
@@ -123,10 +129,10 @@ process.stdin.resume();
|
|
|
123
129
|
const routingPath = join(wd, "state", "plugin-hook-routing", `${launchId}.json`);
|
|
124
130
|
await mkdir(dirname(routingPath), { recursive: true });
|
|
125
131
|
await writeFile(routingPath, `${JSON.stringify({ routing: "omx-plugin-hook-routing-only:v1", ownerSessionId: sessionId })}\n`);
|
|
126
|
-
const versionHash = createHash("sha256").update(
|
|
132
|
+
const versionHash = createHash("sha256").update(version).digest("hex").slice(0, 24);
|
|
127
133
|
const cacheBase = omxPluginCacheBase(codexHomeDir);
|
|
128
134
|
const intentLockPath = join(cacheBase, `.omx-live-pin-intent-${versionHash}.lock`);
|
|
129
|
-
const mutationLockPath = livePinMutationLockPath(codexHomeDir,
|
|
135
|
+
const mutationLockPath = livePinMutationLockPath(codexHomeDir, version);
|
|
130
136
|
const preloadPath = join(wd, `${launchId}-expire-guards.mjs`);
|
|
131
137
|
await writeFile(preloadPath, `
|
|
132
138
|
import { existsSync, writeFileSync } from "node:fs";
|
|
@@ -200,7 +206,7 @@ describe("issue 3790 live plugin cache pins", () => {
|
|
|
200
206
|
const materialized = await materializePackagedOmxPluginCache(codexHomeDir, packaged);
|
|
201
207
|
assert.equal(materialized.status, "materialized");
|
|
202
208
|
const cacheDir = materialized.cacheDir;
|
|
203
|
-
const markerDir =
|
|
209
|
+
const markerDir = livePinDirectoryPath(codexHomeDir, materialized.version);
|
|
204
210
|
const launcherPath = join(cacheDir, "hooks", "omx-command.json");
|
|
205
211
|
const launcherContent = await readFile(launcherPath, "utf-8");
|
|
206
212
|
await assert.rejects(lstat(markerDir), { code: "ENOENT" });
|
|
@@ -318,7 +324,7 @@ describe("issue 3790 live plugin cache pins", () => {
|
|
|
318
324
|
},
|
|
319
325
|
});
|
|
320
326
|
assert.equal(hookResult.status, 0, hookResult.stderr || hookResult.stdout);
|
|
321
|
-
const markerDir =
|
|
327
|
+
const markerDir = livePinDirectoryPath(codexHomeDir, published.version);
|
|
322
328
|
const entries = await readdir(markerDir);
|
|
323
329
|
assert.equal(entries.length, 1);
|
|
324
330
|
const pin = JSON.parse(await readFile(join(markerDir, entries[0]), "utf-8"));
|
|
@@ -379,7 +385,11 @@ setInterval(() => {}, 60_000);
|
|
|
379
385
|
await withIsolatedUserHome(wd, async (codexHomeDir) => {
|
|
380
386
|
const snapshots = await Promise.all(["0.19.0", "0.20.0", "0.20.1"].map((version) => seedManagedSnapshot(codexHomeDir, version)));
|
|
381
387
|
const pluginRoot = snapshots[1];
|
|
382
|
-
const
|
|
388
|
+
const version = "0.20.0";
|
|
389
|
+
const legacyPinDirectory = join(pluginRoot, ".omx-live-pin");
|
|
390
|
+
const externalPinDirectory = livePinDirectoryPath(codexHomeDir, version);
|
|
391
|
+
// Create legacy pins in old location for testing legacy detection
|
|
392
|
+
await mkdir(legacyPinDirectory, { recursive: true });
|
|
383
393
|
const expiredAt = new Date(Date.now() - 60 * 60 * 1000);
|
|
384
394
|
await utimes(pluginRoot, expiredAt, expiredAt);
|
|
385
395
|
const hook = spawn(process.execPath, [join(pluginRoot, "hooks", "codex-native-hook.mjs")], {
|
|
@@ -396,7 +406,7 @@ setInterval(() => {}, 60_000);
|
|
|
396
406
|
let pendingEntries = [];
|
|
397
407
|
for (let attempt = 0; attempt < 100; attempt += 1) {
|
|
398
408
|
try {
|
|
399
|
-
pendingEntries = (await readdir(
|
|
409
|
+
pendingEntries = (await readdir(externalPinDirectory)).filter((name) => name.startsWith(".pending-"));
|
|
400
410
|
if (pendingEntries.length > 0)
|
|
401
411
|
break;
|
|
402
412
|
}
|
|
@@ -406,7 +416,7 @@ setInterval(() => {}, 60_000);
|
|
|
406
416
|
await new Promise((resolveWait) => setTimeout(resolveWait, 10));
|
|
407
417
|
}
|
|
408
418
|
assert.equal(pendingEntries.length, 1, "startup pin must exist while the wrapper waits for stdin");
|
|
409
|
-
const pending = JSON.parse(await readFile(join(
|
|
419
|
+
const pending = JSON.parse(await readFile(join(externalPinDirectory, pendingEntries[0]), "utf-8"));
|
|
410
420
|
assert.equal(pending.version, 1);
|
|
411
421
|
assert.match(pending.sessionHash, /^[0-9a-f]{64}$/);
|
|
412
422
|
assert.equal(pendingEntries[0], `.pending-${pending.sessionHash}.json`);
|
|
@@ -424,7 +434,9 @@ setInterval(() => {}, 60_000);
|
|
|
424
434
|
}));
|
|
425
435
|
const [code] = await closed;
|
|
426
436
|
assert.equal(code, 0, hookStderr);
|
|
427
|
-
|
|
437
|
+
// Verify new pins are in external directory
|
|
438
|
+
const externalEntries = await readdir(externalPinDirectory);
|
|
439
|
+
assert.equal(externalEntries.length, 1);
|
|
428
440
|
}
|
|
429
441
|
finally {
|
|
430
442
|
if (hook.exitCode === null) {
|
|
@@ -521,7 +533,7 @@ import { syncBuiltinESMExports } from "node:module";
|
|
|
521
533
|
const originalWriteFileSync = fs.writeFileSync;
|
|
522
534
|
let renamed = false;
|
|
523
535
|
fs.writeFileSync = function (path, ...args) {
|
|
524
|
-
if (!renamed && typeof path === "string" && path.includes("/.
|
|
536
|
+
if (!renamed && typeof path === "string" && path.includes("/.stage-pending-")) {
|
|
525
537
|
fs.renameSync(process.env.OMX_TEST_PLUGIN_ROOT, process.env.OMX_TEST_QUARANTINE);
|
|
526
538
|
renamed = true;
|
|
527
539
|
}
|
|
@@ -551,7 +563,9 @@ syncBuiltinESMExports();
|
|
|
551
563
|
});
|
|
552
564
|
assert.equal(hookResult.status, 0, hookResult.stderr || hookResult.stdout);
|
|
553
565
|
await assert.rejects(lstat(pluginRoot), { code: "ENOENT" });
|
|
554
|
-
assert.
|
|
566
|
+
assert.ok((await lstat(quarantinePath)).isDirectory());
|
|
567
|
+
assert.deepEqual(await readdir(livePinDirectoryPath(codexHomeDir, "0.20.0")), []);
|
|
568
|
+
await assert.rejects(lstat(join(quarantinePath, ".omx-live-pin")), { code: "ENOENT" });
|
|
555
569
|
});
|
|
556
570
|
}
|
|
557
571
|
finally {
|
|
@@ -638,8 +652,8 @@ syncBuiltinESMExports();
|
|
|
638
652
|
await withIsolatedUserHome(wd, async (codexHomeDir) => {
|
|
639
653
|
const snapshots = await Promise.all(["0.20.0", "0.20.1", "0.20.2"].map((version) => seedManagedSnapshot(codexHomeDir, version)));
|
|
640
654
|
const pluginRoot = snapshots[0];
|
|
641
|
-
const pinDirectory =
|
|
642
|
-
await mkdir(pinDirectory);
|
|
655
|
+
const pinDirectory = livePinDirectoryPath(codexHomeDir, "0.20.0");
|
|
656
|
+
await mkdir(pinDirectory, { recursive: true });
|
|
643
657
|
const expiredAt = new Date(Date.now() - 6 * 60 * 1000);
|
|
644
658
|
await utimes(pinDirectory, expiredAt, expiredAt);
|
|
645
659
|
const mutationLockPath = join(omxPluginCacheBase(codexHomeDir), `.omx-live-pin-${createHash("sha256").update("0.20.0").digest("hex").slice(0, 24)}.lock`);
|
|
@@ -652,7 +666,7 @@ import { syncBuiltinESMExports } from "node:module";
|
|
|
652
666
|
const originalWriteFileSync = fs.writeFileSync;
|
|
653
667
|
let paused = false;
|
|
654
668
|
fs.writeFileSync = function (path, ...args) {
|
|
655
|
-
if (!paused && typeof path === "string" && path.includes("/.
|
|
669
|
+
if (!paused && typeof path === "string" && path.includes("/.stage-pending-")) {
|
|
656
670
|
paused = true;
|
|
657
671
|
originalWriteFileSync.call(this, process.env.OMX_TEST_PIN_READY, "ready\\n");
|
|
658
672
|
const wait = new Int32Array(new SharedArrayBuffer(4));
|
|
@@ -886,8 +900,8 @@ syncBuiltinESMExports();
|
|
|
886
900
|
try {
|
|
887
901
|
await withIsolatedUserHome(wd, async (codexHomeDir) => {
|
|
888
902
|
const snapshots = await Promise.all(["0.20.0", "0.20.1", "0.20.2"].map((version) => seedManagedSnapshot(codexHomeDir, version)));
|
|
889
|
-
const pinDirectory =
|
|
890
|
-
await mkdir(pinDirectory);
|
|
903
|
+
const pinDirectory = livePinDirectoryPath(codexHomeDir, "0.20.0");
|
|
904
|
+
await mkdir(pinDirectory, { recursive: true });
|
|
891
905
|
const retired = await retireUnpinnedManagedSnapshots(codexHomeDir, "0.20.3");
|
|
892
906
|
assert.equal(retired.includes(snapshots[0]), false);
|
|
893
907
|
assert.equal(retired.includes(snapshots[1]), true);
|
|
@@ -905,9 +919,9 @@ syncBuiltinESMExports();
|
|
|
905
919
|
try {
|
|
906
920
|
await withIsolatedUserHome(wd, async (codexHomeDir) => {
|
|
907
921
|
const snapshots = await Promise.all(["0.20.0", "0.20.1", "0.20.2"].map((version) => seedManagedSnapshot(codexHomeDir, version)));
|
|
908
|
-
const pinDirectory = join(snapshots[0], ".omx-live-pin");
|
|
909
|
-
await mkdir(pinDirectory);
|
|
910
922
|
const expiredAt = new Date(Date.now() - 6 * 60 * 1000);
|
|
923
|
+
const pinDirectory = livePinDirectoryPath(codexHomeDir, "0.20.0");
|
|
924
|
+
await mkdir(pinDirectory, { recursive: true });
|
|
911
925
|
await utimes(pinDirectory, expiredAt, expiredAt);
|
|
912
926
|
const retired = await retireUnpinnedManagedSnapshots(codexHomeDir, "0.20.3");
|
|
913
927
|
assert.equal(retired.includes(snapshots[0]), true);
|
|
@@ -993,8 +1007,8 @@ syncBuiltinESMExports();
|
|
|
993
1007
|
await withIsolatedUserHome(wd, async (codexHomeDir) => {
|
|
994
1008
|
const snapshots = await Promise.all(["0.20.0", "0.20.1", "0.20.2"].map((version) => seedManagedSnapshot(codexHomeDir, version)));
|
|
995
1009
|
const sessionHash = createHash("sha256").update("expired-pending-session").digest("hex");
|
|
996
|
-
const pinDirectory =
|
|
997
|
-
await mkdir(pinDirectory);
|
|
1010
|
+
const pinDirectory = livePinDirectoryPath(codexHomeDir, "0.20.0");
|
|
1011
|
+
await mkdir(pinDirectory, { recursive: true });
|
|
998
1012
|
assert.equal(await registerOmxPluginCacheLivePin(snapshots[0], "pending-marker-live-session", process.pid), true);
|
|
999
1013
|
const pendingPath = join(pinDirectory, `.pending-${sessionHash}.json`);
|
|
1000
1014
|
await writeFile(pendingPath, `${JSON.stringify({ version: 1, sessionHash })}\n`);
|
|
@@ -1050,12 +1064,11 @@ syncBuiltinESMExports();
|
|
|
1050
1064
|
const intentPath = livePinIntentPath(codexHomeDir, version, `expired-${version}`);
|
|
1051
1065
|
const stagePath = join(cacheBase, `.stage-omx-live-pin-intent-${versionHash}-${sessionHash}-99999-abandoned`);
|
|
1052
1066
|
const content = `${JSON.stringify({ version: 1, cacheVersion: version, sessionHash })}\n`;
|
|
1053
|
-
const
|
|
1054
|
-
const pinDirectory = join(snapshot, ".omx-live-pin");
|
|
1067
|
+
const pinDirectory = livePinDirectoryPath(codexHomeDir, version);
|
|
1055
1068
|
const pendingPinPath = join(pinDirectory, `.pending-${sessionHash}.json`);
|
|
1056
1069
|
const pinStagePath = join(pinDirectory, `.stage-pending-${sessionHash}-99999-abandoned`);
|
|
1057
1070
|
const pinContent = `${JSON.stringify({ version: 1, sessionHash })}\n`;
|
|
1058
|
-
await mkdir(pinDirectory);
|
|
1071
|
+
await mkdir(pinDirectory, { recursive: true });
|
|
1059
1072
|
await writeFile(intentPath, content);
|
|
1060
1073
|
await writeFile(stagePath, content);
|
|
1061
1074
|
await writeFile(pendingPinPath, pinContent);
|
|
@@ -1074,7 +1087,7 @@ syncBuiltinESMExports();
|
|
|
1074
1087
|
const versionHash = createHash("sha256").update(version).digest("hex").slice(0, 24);
|
|
1075
1088
|
const sessionHash = createHash("sha256").update(`expired-${version}`).digest("hex");
|
|
1076
1089
|
await assert.rejects(lstat(join(cacheBase, `.stage-omx-live-pin-intent-${versionHash}-${sessionHash}-99999-abandoned`)), { code: "ENOENT" });
|
|
1077
|
-
const pinDirectory =
|
|
1090
|
+
const pinDirectory = livePinDirectoryPath(codexHomeDir, version);
|
|
1078
1091
|
await assert.rejects(lstat(join(pinDirectory, `.pending-${sessionHash}.json`)), { code: "ENOENT" });
|
|
1079
1092
|
await assert.rejects(lstat(join(pinDirectory, `.stage-pending-${sessionHash}-99999-abandoned`)), { code: "ENOENT" });
|
|
1080
1093
|
await lstat(snapshots[version === "0.20.1" ? 1 : 2]);
|
|
@@ -1096,8 +1109,8 @@ syncBuiltinESMExports();
|
|
|
1096
1109
|
assert.equal(await registerOmxPluginCacheLivePin(snapshots[0], "dead-lock-recovery-session", process.pid), true);
|
|
1097
1110
|
await assert.rejects(lstat(lock.path), { code: "ENOENT" });
|
|
1098
1111
|
await assert.rejects(lstat(lock.stagePath), { code: "ENOENT" });
|
|
1099
|
-
const pinDirectory = join(snapshots[0], ".omx-live-pin");
|
|
1100
1112
|
const sessionHash = createHash("sha256").update("dead-lock-recovery-session").digest("hex");
|
|
1113
|
+
const pinDirectory = livePinDirectoryPath(codexHomeDir, "0.20.0");
|
|
1101
1114
|
const records = await Promise.all((await readdir(pinDirectory)).map(async (name) => JSON.parse(await readFile(join(pinDirectory, name), "utf-8"))));
|
|
1102
1115
|
assert.ok(records.some((record) => record.sessionHash === sessionHash));
|
|
1103
1116
|
});
|
|
@@ -1178,8 +1191,8 @@ syncBuiltinESMExports();
|
|
|
1178
1191
|
const sessionId = "reused-pid-fallback-session";
|
|
1179
1192
|
const sessionHash = createHash("sha256").update(sessionId).digest("hex");
|
|
1180
1193
|
const staleProcessStartHash = "0".repeat(24);
|
|
1181
|
-
const pinDirectory =
|
|
1182
|
-
await mkdir(pinDirectory);
|
|
1194
|
+
const pinDirectory = livePinDirectoryPath(codexHomeDir, "0.20.0");
|
|
1195
|
+
await mkdir(pinDirectory, { recursive: true });
|
|
1183
1196
|
await writeFile(join(pinDirectory, `pin-${process.pid}-${sessionHash.slice(0, 24)}-${staleProcessStartHash}.json`), `${JSON.stringify({ version: 1, pid: process.pid, processStartHash: staleProcessStartHash, sessionHash })}\n`);
|
|
1184
1197
|
const mutationLock = await writeLivePinMutationLock(codexHomeDir, "0.20.0", process.pid, "pin");
|
|
1185
1198
|
const versionHash = createHash("sha256").update("0.20.0").digest("hex").slice(0, 24);
|
|
@@ -1216,8 +1229,8 @@ syncBuiltinESMExports();
|
|
|
1216
1229
|
const sessionId = "aged-same-session-pin";
|
|
1217
1230
|
const sessionHash = createHash("sha256").update(sessionId).digest("hex");
|
|
1218
1231
|
const staleProcessStartHash = "a".repeat(24);
|
|
1219
|
-
const pinDirectory =
|
|
1220
|
-
await mkdir(pinDirectory);
|
|
1232
|
+
const pinDirectory = livePinDirectoryPath(codexHomeDir, "0.20.0");
|
|
1233
|
+
await mkdir(pinDirectory, { recursive: true });
|
|
1221
1234
|
const stalePinPath = join(pinDirectory, `pin-${process.pid}-${sessionHash.slice(0, 24)}-${staleProcessStartHash}.json`);
|
|
1222
1235
|
await writeFile(stalePinPath, `${JSON.stringify({ version: 1, pid: process.pid, processStartHash: staleProcessStartHash, sessionHash })}\n`);
|
|
1223
1236
|
const expiredAt = new Date(Date.now() - 6 * 60 * 1000);
|
|
@@ -1497,8 +1510,8 @@ setTimeout(waitForDelegate, 10);
|
|
|
1497
1510
|
const pluginRoot = await seedManagedSnapshot(codexHomeDir, "0.20.0");
|
|
1498
1511
|
const sessionId = "unknown-owner-pin-session";
|
|
1499
1512
|
const sessionHash = createHash("sha256").update(sessionId).digest("hex");
|
|
1500
|
-
const pinDirectory =
|
|
1501
|
-
await mkdir(pinDirectory);
|
|
1513
|
+
const pinDirectory = livePinDirectoryPath(codexHomeDir, "0.20.0");
|
|
1514
|
+
await mkdir(pinDirectory, { recursive: true });
|
|
1502
1515
|
await writeFile(join(pinDirectory, `pin-${process.pid}-${sessionHash.slice(0, 24)}-unknown.json`), `${JSON.stringify({ version: 1, pid: process.pid, processStartHash: null, sessionHash })}\n`);
|
|
1503
1516
|
const delegateStartedPath = join(wd, "delegate-started");
|
|
1504
1517
|
const delegateStoppedPath = join(wd, "delegate-stopped");
|
|
@@ -1598,7 +1611,7 @@ setTimeout(waitForDelegate, 10);
|
|
|
1598
1611
|
try {
|
|
1599
1612
|
await withIsolatedUserHome(wd, async (codexHomeDir) => {
|
|
1600
1613
|
const pluginRoot = await seedManagedSnapshot(codexHomeDir, "0.20.0");
|
|
1601
|
-
const pinPath = await assertDelegateSurvivesLostLeasesWithPin(wd, codexHomeDir, pluginRoot, "malformed-durable-pin-session", "malformed-pin", "pin-unreadable-record.json", "{ malformed durable pin\n");
|
|
1614
|
+
const pinPath = await assertDelegateSurvivesLostLeasesWithPin(wd, codexHomeDir, pluginRoot, "malformed-durable-pin-session", "malformed-pin", "pin-unreadable-record.json", "{ malformed durable pin\n", "0.20.0");
|
|
1602
1615
|
await rm(pinPath, { force: true });
|
|
1603
1616
|
});
|
|
1604
1617
|
}
|
|
@@ -1785,7 +1798,7 @@ process.stdout.write("{}\\n");
|
|
|
1785
1798
|
assert.equal(hookResult.status, 0, hookResult.stderr || hookResult.stdout);
|
|
1786
1799
|
await assert.rejects(lstat(lock.path), { code: "ENOENT" });
|
|
1787
1800
|
await assert.rejects(lstat(lock.stagePath), { code: "ENOENT" });
|
|
1788
|
-
const pinDirectory =
|
|
1801
|
+
const pinDirectory = livePinDirectoryPath(codexHomeDir, "0.20.0");
|
|
1789
1802
|
const sessionHash = createHash("sha256").update(sessionId).digest("hex");
|
|
1790
1803
|
const records = await Promise.all((await readdir(pinDirectory)).map(async (name) => JSON.parse(await readFile(join(pinDirectory, name), "utf-8"))));
|
|
1791
1804
|
assert.ok(records.some((record) => record.sessionHash === sessionHash));
|
|
@@ -1854,7 +1867,7 @@ process.stdout.write("{}\\n");
|
|
|
1854
1867
|
try {
|
|
1855
1868
|
await withIsolatedUserHome(staleWd, async (codexHomeDir) => {
|
|
1856
1869
|
const snapshots = await Promise.all(["0.20.0", "0.20.1", "0.20.2"].map((version) => seedManagedSnapshot(codexHomeDir, version)));
|
|
1857
|
-
await writeDeadLivePin(snapshots[0]);
|
|
1870
|
+
await writeDeadLivePin(snapshots[0], codexHomeDir, "0.20.0");
|
|
1858
1871
|
const retired = await retireUnpinnedManagedSnapshots(codexHomeDir, "0.20.3");
|
|
1859
1872
|
assert.equal(retired.includes(snapshots[0]), true);
|
|
1860
1873
|
await assert.rejects(lstat(snapshots[0]), { code: "ENOENT" });
|
|
@@ -1885,7 +1898,7 @@ process.stdout.write("{}\\n");
|
|
|
1885
1898
|
assert.equal(blocked.status, "stale-launcher");
|
|
1886
1899
|
assert.match(blocked.reason ?? "", /pinned by a live Codex session/);
|
|
1887
1900
|
assert.equal(JSON.parse(await readFile(manifestPath, "utf-8")).version, "corrupted-version");
|
|
1888
|
-
await rm(
|
|
1901
|
+
await rm(livePinDirectoryPath(codexHomeDir, expectedVersion), { recursive: true, force: true });
|
|
1889
1902
|
const repaired = await materializePackagedOmxPluginCache(codexHomeDir, packaged, { repairCache: true });
|
|
1890
1903
|
assert.equal(repaired.status, "materialized", JSON.stringify(repaired));
|
|
1891
1904
|
assert.equal(repaired.version, expectedVersion);
|
|
@@ -1904,8 +1917,8 @@ process.stdout.write("{}\\n");
|
|
|
1904
1917
|
const sessionId = "fresh-stale-session-pin";
|
|
1905
1918
|
const sessionHash = createHash("sha256").update(sessionId).digest("hex");
|
|
1906
1919
|
const staleProcessStartHash = "0".repeat(24);
|
|
1907
|
-
const pinDirectory =
|
|
1908
|
-
await mkdir(pinDirectory);
|
|
1920
|
+
const pinDirectory = livePinDirectoryPath(codexHomeDir, "0.20.0");
|
|
1921
|
+
await mkdir(pinDirectory, { recursive: true });
|
|
1909
1922
|
const stalePinPath = join(pinDirectory, `pin-${process.pid}-${sessionHash.slice(0, 24)}-${staleProcessStartHash}.json`);
|
|
1910
1923
|
await writeFile(stalePinPath, `${JSON.stringify({ version: 1, pid: process.pid, processStartHash: staleProcessStartHash, sessionHash })}\n`);
|
|
1911
1924
|
assert.ok(Date.now() - (await lstat(stalePinPath)).mtimeMs < 60_000);
|
|
@@ -1934,7 +1947,7 @@ process.stdout.write("{}\\n");
|
|
|
1934
1947
|
const sessionId = "resumed-session";
|
|
1935
1948
|
const sessionHash = createHash("sha256").update(sessionId).digest("hex");
|
|
1936
1949
|
const staleProcessStartHash = "000000000000000000000000";
|
|
1937
|
-
const pinDirectory =
|
|
1950
|
+
const pinDirectory = livePinDirectoryPath(codexHomeDir, "0.20.0");
|
|
1938
1951
|
await mkdir(pinDirectory, { recursive: true });
|
|
1939
1952
|
await writeFile(join(pinDirectory, "stale-reused-pid.json"), `${JSON.stringify({
|
|
1940
1953
|
version: 1,
|
|
@@ -1993,7 +2006,7 @@ process.stdout.write("{}\\n");
|
|
|
1993
2006
|
const sessionId = "resumed-session";
|
|
1994
2007
|
const sessionHash = createHash("sha256").update(sessionId).digest("hex");
|
|
1995
2008
|
const staleProcessStartHash = "000000000000000000000000";
|
|
1996
|
-
const pinDirectory =
|
|
2009
|
+
const pinDirectory = livePinDirectoryPath(codexHomeDir, "0.20.0");
|
|
1997
2010
|
await mkdir(pinDirectory, { recursive: true });
|
|
1998
2011
|
await writeFile(join(pinDirectory, "stale-reused-pid.json"), `${JSON.stringify({
|
|
1999
2012
|
version: 1,
|
|
@@ -2035,8 +2048,8 @@ process.stdout.write("{}\\n");
|
|
|
2035
2048
|
const pluginRoot = await seedManagedSnapshot(codexHomeDir, "0.20.0");
|
|
2036
2049
|
const sessionId = "intent-lock-retry-session";
|
|
2037
2050
|
const sessionHash = createHash("sha256").update(sessionId).digest("hex");
|
|
2038
|
-
const pinDirectory =
|
|
2039
|
-
await mkdir(pinDirectory);
|
|
2051
|
+
const pinDirectory = livePinDirectoryPath(codexHomeDir, "0.20.0");
|
|
2052
|
+
await mkdir(pinDirectory, { recursive: true });
|
|
2040
2053
|
const staleHash = "a".repeat(24);
|
|
2041
2054
|
await writeFile(join(pinDirectory, "stale-reused-pid.json"), `${JSON.stringify({ version: 1, pid: process.pid, processStartHash: staleHash, sessionHash })}\n`);
|
|
2042
2055
|
const cacheBase = omxPluginCacheBase(codexHomeDir);
|
|
@@ -2106,5 +2119,652 @@ process.stdout.write("{}\\n");
|
|
|
2106
2119
|
await rm(wd, { recursive: true, force: true });
|
|
2107
2120
|
}
|
|
2108
2121
|
});
|
|
2122
|
+
it("maintains invariant fingerprint across pin lifecycle (create, renew, retire, GC)", async () => {
|
|
2123
|
+
const wd = await mkdtemp(join(tmpdir(), "omx-3790-fingerprint-invariance-"));
|
|
2124
|
+
try {
|
|
2125
|
+
await withIsolatedUserHome(wd, async (codexHomeDir) => {
|
|
2126
|
+
const packaged = await resolvePackagedOmxMarketplace(packageRoot);
|
|
2127
|
+
assert.ok(packaged);
|
|
2128
|
+
const materialized = await materializePackagedOmxPluginCache(codexHomeDir, packaged);
|
|
2129
|
+
assert.equal(materialized.status, "materialized");
|
|
2130
|
+
const cacheDir = materialized.cacheDir;
|
|
2131
|
+
const version = materialized.version;
|
|
2132
|
+
// Replicate Codex plugin_content_hash walk/exclusion rules from:
|
|
2133
|
+
// https://raw.githubusercontent.com/openai/codex/rust-v0.167.0/codex-rs/hooks/src/engine/plugin_fingerprint.rs
|
|
2134
|
+
// Excludes: __pycache__, .venv, *.pyc, *.egg-info
|
|
2135
|
+
// UNLIKE the Codex source, does NOT exclude .omx-* files (including .omx-live-pin)
|
|
2136
|
+
const computeFingerprint = async (rootPath) => {
|
|
2137
|
+
const hash = createHash("sha256");
|
|
2138
|
+
hash.update("codex-plugin-bundle-v1");
|
|
2139
|
+
const pending = [rootPath];
|
|
2140
|
+
while (pending.length > 0) {
|
|
2141
|
+
const path = pending.pop();
|
|
2142
|
+
const relativePath = path.startsWith(rootPath) ? path.slice(rootPath.length + 1) : path;
|
|
2143
|
+
// Check exclusion rules
|
|
2144
|
+
const fileName = relativePath.split(/[\\\/]/).pop() || "";
|
|
2145
|
+
if (fileName === "__pycache__" ||
|
|
2146
|
+
fileName === ".venv" ||
|
|
2147
|
+
fileName.endsWith(".pyc") ||
|
|
2148
|
+
fileName.endsWith(".egg-info")) {
|
|
2149
|
+
continue;
|
|
2150
|
+
}
|
|
2151
|
+
// Update hash with relative path
|
|
2152
|
+
const nameBytes = Buffer.from(relativePath, "utf8");
|
|
2153
|
+
const lenBuf = Buffer.alloc(8);
|
|
2154
|
+
lenBuf.writeBigUInt64LE(BigInt(nameBytes.length), 0);
|
|
2155
|
+
hash.update(lenBuf);
|
|
2156
|
+
hash.update(nameBytes);
|
|
2157
|
+
const stat = await lstat(path);
|
|
2158
|
+
if (stat.isDirectory()) {
|
|
2159
|
+
hash.update("directory");
|
|
2160
|
+
const entries = await readdir(path);
|
|
2161
|
+
entries.sort();
|
|
2162
|
+
// Add entries in reverse so they're popped in forward order
|
|
2163
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
2164
|
+
pending.push(join(path, entries[i]));
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
else if (stat.isFile()) {
|
|
2168
|
+
hash.update("file");
|
|
2169
|
+
const length = stat.size;
|
|
2170
|
+
const lenBuf2 = Buffer.alloc(8);
|
|
2171
|
+
lenBuf2.writeBigUInt64LE(BigInt(length), 0);
|
|
2172
|
+
hash.update(lenBuf2);
|
|
2173
|
+
// Read and hash file content
|
|
2174
|
+
const content = await readFile(path);
|
|
2175
|
+
if (content.length !== length) {
|
|
2176
|
+
throw new Error("plugin file changed while fingerprinting");
|
|
2177
|
+
}
|
|
2178
|
+
hash.update(content);
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
return `sha256:${hash.digest("hex")}`;
|
|
2182
|
+
};
|
|
2183
|
+
const baseFingerprint = await computeFingerprint(cacheDir);
|
|
2184
|
+
// Create a pin and verify fingerprint unchanged
|
|
2185
|
+
const result = await registerOmxPluginCacheLivePin(cacheDir, "fingerprint-test-session", process.pid);
|
|
2186
|
+
assert.ok(result, "pin registration should succeed");
|
|
2187
|
+
const afterPinFingerprint = await computeFingerprint(cacheDir);
|
|
2188
|
+
assert.equal(afterPinFingerprint, baseFingerprint, "fingerprint must be unchanged after pin creation");
|
|
2189
|
+
// Test: writing an in-tree .omx-live-pin DOES change the fingerprint (negative control)
|
|
2190
|
+
const legacyPinDir = join(cacheDir, ".omx-live-pin");
|
|
2191
|
+
await mkdir(legacyPinDir, { recursive: true });
|
|
2192
|
+
await writeFile(join(legacyPinDir, "test-legacy-pin.json"), JSON.stringify({ test: true }));
|
|
2193
|
+
const afterLegacyPinFingerprint = await computeFingerprint(cacheDir);
|
|
2194
|
+
assert.notEqual(afterLegacyPinFingerprint, baseFingerprint, "fingerprint MUST change when in-tree .omx-live-pin files are written (negative control)");
|
|
2195
|
+
// Clean up the legacy pin to restore baseline for further tests
|
|
2196
|
+
await rm(legacyPinDir, { recursive: true, force: true });
|
|
2197
|
+
const restoredFingerprint = await computeFingerprint(cacheDir);
|
|
2198
|
+
assert.equal(restoredFingerprint, baseFingerprint, "fingerprint must return to baseline after removing in-tree .omx-live-pin");
|
|
2199
|
+
// Verify external pin files exist but don't affect fingerprint
|
|
2200
|
+
const externalPinDir = livePinDirectoryPath(codexHomeDir, version);
|
|
2201
|
+
const externalPins = await readdir(externalPinDir);
|
|
2202
|
+
assert.ok(externalPins.length > 0, "external pins should be created");
|
|
2203
|
+
const finalFingerprint = await computeFingerprint(cacheDir);
|
|
2204
|
+
assert.equal(finalFingerprint, baseFingerprint, "fingerprint must remain unchanged with external pins present");
|
|
2205
|
+
});
|
|
2206
|
+
}
|
|
2207
|
+
finally {
|
|
2208
|
+
await rm(wd, { recursive: true, force: true });
|
|
2209
|
+
}
|
|
2210
|
+
});
|
|
2211
|
+
it("handles legacy .omx-live-pin pins alongside new external pins safely", async () => {
|
|
2212
|
+
const wd = await mkdtemp(join(tmpdir(), "omx-3790-legacy-coexist-"));
|
|
2213
|
+
try {
|
|
2214
|
+
await withIsolatedUserHome(wd, async (codexHomeDir) => {
|
|
2215
|
+
const packaged = await resolvePackagedOmxMarketplace(packageRoot);
|
|
2216
|
+
assert.ok(packaged);
|
|
2217
|
+
const materialized = await materializePackagedOmxPluginCache(codexHomeDir, packaged);
|
|
2218
|
+
assert.equal(materialized.status, "materialized");
|
|
2219
|
+
const cacheDir = materialized.cacheDir;
|
|
2220
|
+
const version = materialized.version;
|
|
2221
|
+
// Set up a legacy pin in the old location
|
|
2222
|
+
const legacyPinDir = join(cacheDir, ".omx-live-pin");
|
|
2223
|
+
await mkdir(legacyPinDir, { recursive: true });
|
|
2224
|
+
const legacyPin = {
|
|
2225
|
+
version: 1,
|
|
2226
|
+
pid: 99999,
|
|
2227
|
+
processStartHash: "legacylegacylegacylegacylegacy",
|
|
2228
|
+
sessionHash: createHash("sha256").update("legacy-session").digest("hex"),
|
|
2229
|
+
};
|
|
2230
|
+
await writeFile(join(legacyPinDir, "legacy-pin.json"), `${JSON.stringify(legacyPin)}\n`);
|
|
2231
|
+
// Register a new pin
|
|
2232
|
+
const newPinResult = await registerOmxPluginCacheLivePin(cacheDir, "new-session", process.pid);
|
|
2233
|
+
assert.ok(newPinResult, "new pin should be created successfully with legacy pins present");
|
|
2234
|
+
// Verify legacy pin still exists
|
|
2235
|
+
const legacyPinContent = await readFile(join(legacyPinDir, "legacy-pin.json"), "utf-8");
|
|
2236
|
+
assert.deepEqual(JSON.parse(legacyPinContent), legacyPin, "legacy pin should be preserved");
|
|
2237
|
+
// Verify new pin is in external directory
|
|
2238
|
+
const externalPinDir = livePinDirectoryPath(codexHomeDir, version);
|
|
2239
|
+
const externalPins = await readdir(externalPinDir);
|
|
2240
|
+
assert.ok(externalPins.length > 0, "new pins should be in external directory");
|
|
2241
|
+
});
|
|
2242
|
+
}
|
|
2243
|
+
finally {
|
|
2244
|
+
await rm(wd, { recursive: true, force: true });
|
|
2245
|
+
}
|
|
2246
|
+
});
|
|
2247
|
+
it("GC/repair must not remove snapshot if old hook pin present in legacy location", async () => {
|
|
2248
|
+
const wd = await mkdtemp(join(tmpdir(), "omx-3790-legacy-retirement-"));
|
|
2249
|
+
try {
|
|
2250
|
+
await withIsolatedUserHome(wd, async (codexHomeDir) => {
|
|
2251
|
+
const packaged = await resolvePackagedOmxMarketplace(packageRoot);
|
|
2252
|
+
assert.ok(packaged);
|
|
2253
|
+
// Create current version
|
|
2254
|
+
const currentMaterialized = await materializePackagedOmxPluginCache(codexHomeDir, packaged);
|
|
2255
|
+
assert.equal(currentMaterialized.status, "materialized");
|
|
2256
|
+
const currentVersion = currentMaterialized.version;
|
|
2257
|
+
// Create two old snapshot versions with legacy pins
|
|
2258
|
+
const oldVersion1 = "0.0.1";
|
|
2259
|
+
const oldCacheDir1 = await seedManagedSnapshot(codexHomeDir, oldVersion1);
|
|
2260
|
+
const oldVersion2 = "0.0.2";
|
|
2261
|
+
const oldCacheDir2 = await seedManagedSnapshot(codexHomeDir, oldVersion2);
|
|
2262
|
+
const oldCacheDir = oldCacheDir1;
|
|
2263
|
+
assert.ok(oldCacheDir);
|
|
2264
|
+
// Create legacy .omx-live-pin directory with a pin
|
|
2265
|
+
const legacyPinDir = join(oldCacheDir, ".omx-live-pin");
|
|
2266
|
+
await mkdir(legacyPinDir, { recursive: true });
|
|
2267
|
+
const legacyPin = {
|
|
2268
|
+
version: 1,
|
|
2269
|
+
pid: 88888, // Use a PID that likely doesn't exist
|
|
2270
|
+
processStartHash: "legacylegacylegacylegacylegacy",
|
|
2271
|
+
sessionHash: createHash("sha256").update("legacy-session-that-must-not-be-removed").digest("hex"),
|
|
2272
|
+
};
|
|
2273
|
+
await writeFile(join(legacyPinDir, `pin-${legacyPin.pid}-${legacyPin.sessionHash.slice(0, 24)}-${legacyPin.processStartHash}.json`), `${JSON.stringify(legacyPin)}\n`);
|
|
2274
|
+
// Verify the old snapshot exists before retirement
|
|
2275
|
+
const beforeStats = await lstat(oldCacheDir);
|
|
2276
|
+
assert.ok(beforeStats.isDirectory(), "old snapshot should exist before retirement");
|
|
2277
|
+
// Try to retire unpinned snapshots
|
|
2278
|
+
// This should NOT remove the old snapshot because it has a legacy pin
|
|
2279
|
+
const retired = await retireUnpinnedManagedSnapshots(codexHomeDir, currentVersion);
|
|
2280
|
+
// Verify the old snapshot was NOT removed (because it has a legacy pin)
|
|
2281
|
+
const afterStats = await lstat(oldCacheDir).catch(() => null);
|
|
2282
|
+
assert.ok(afterStats?.isDirectory(), `old snapshot with legacy pin should be preserved during retirement; retired: ${retired.join(", ")}`);
|
|
2283
|
+
// Verify the legacy pin still exists
|
|
2284
|
+
const legacyPinContent = await readFile(join(legacyPinDir, `pin-${legacyPin.pid}-${legacyPin.sessionHash.slice(0, 24)}-${legacyPin.processStartHash}.json`), "utf-8");
|
|
2285
|
+
assert.deepEqual(JSON.parse(legacyPinContent), legacyPin, "legacy pin should be preserved");
|
|
2286
|
+
});
|
|
2287
|
+
}
|
|
2288
|
+
finally {
|
|
2289
|
+
await rm(wd, { recursive: true, force: true });
|
|
2290
|
+
}
|
|
2291
|
+
});
|
|
2292
|
+
for (const legacyState of ["dead-record", "aged-empty", "live-record"]) {
|
|
2293
|
+
it(`validates legacy ${legacyState} pins before retirement`, async () => {
|
|
2294
|
+
const wd = await mkdtemp(join(tmpdir(), "omx-3790-legacy-content-"));
|
|
2295
|
+
try {
|
|
2296
|
+
await withIsolatedUserHome(wd, async (codexHomeDir) => {
|
|
2297
|
+
const snapshots = await Promise.all(["0.20.0", "0.20.1", "0.20.2"].map((version) => seedManagedSnapshot(codexHomeDir, version)));
|
|
2298
|
+
const legacyDir = join(snapshots[0], ".omx-live-pin");
|
|
2299
|
+
await mkdir(legacyDir);
|
|
2300
|
+
if (legacyState !== "aged-empty") {
|
|
2301
|
+
await writeFile(join(legacyDir, "legacy.json"), JSON.stringify({
|
|
2302
|
+
version: 1,
|
|
2303
|
+
pid: legacyState === "live-record" ? process.pid : 99_999_999,
|
|
2304
|
+
processStartHash: null,
|
|
2305
|
+
sessionHash: createHash("sha256").update("legacy-content").digest("hex"),
|
|
2306
|
+
}));
|
|
2307
|
+
}
|
|
2308
|
+
const expiredAt = new Date(Date.now() - 6 * 60 * 1000);
|
|
2309
|
+
await utimes(legacyDir, expiredAt, expiredAt);
|
|
2310
|
+
await writeDeadLivePin(snapshots[0], codexHomeDir, "0.20.0");
|
|
2311
|
+
const retired = await retireUnpinnedManagedSnapshots(codexHomeDir, "0.20.3");
|
|
2312
|
+
assert.equal(retired.includes(snapshots[0]), legacyState !== "live-record");
|
|
2313
|
+
assert.equal(retired.includes(snapshots[1]), true);
|
|
2314
|
+
assert.ok((await lstat(snapshots[2])).isDirectory());
|
|
2315
|
+
if (legacyState === "live-record") {
|
|
2316
|
+
assert.ok((await lstat(snapshots[0])).isDirectory());
|
|
2317
|
+
}
|
|
2318
|
+
else {
|
|
2319
|
+
await assert.rejects(lstat(snapshots[0]), { code: "ENOENT" });
|
|
2320
|
+
}
|
|
2321
|
+
});
|
|
2322
|
+
}
|
|
2323
|
+
finally {
|
|
2324
|
+
await rm(wd, { recursive: true, force: true });
|
|
2325
|
+
}
|
|
2326
|
+
});
|
|
2327
|
+
}
|
|
2328
|
+
for (const gateState of ["dead-owner", "live-owner", "malformed"]) {
|
|
2329
|
+
for (const operation of ["register", "retire"]) {
|
|
2330
|
+
it(`${operation} recovers only dead-owner retirement gates (${gateState})`, async () => {
|
|
2331
|
+
const wd = await mkdtemp(join(tmpdir(), "omx-3790-stale-gate-"));
|
|
2332
|
+
try {
|
|
2333
|
+
await withIsolatedUserHome(wd, async (codexHomeDir) => {
|
|
2334
|
+
const snapshots = await Promise.all(["0.20.0", "0.20.1", "0.20.2"].map((version) => seedManagedSnapshot(codexHomeDir, version)));
|
|
2335
|
+
const pinDirectory = livePinDirectoryPath(codexHomeDir, "0.20.0");
|
|
2336
|
+
await mkdir(pinDirectory, { recursive: true });
|
|
2337
|
+
const gatePath = join(pinDirectory, ".omx-retiring");
|
|
2338
|
+
const gateContent = gateState === "malformed" ? "not-json\n" : `${JSON.stringify({
|
|
2339
|
+
version: 1,
|
|
2340
|
+
pid: gateState === "live-owner" ? process.pid : 99_999_999,
|
|
2341
|
+
token: "11111111-1111-4111-8111-111111111111",
|
|
2342
|
+
})}\n`;
|
|
2343
|
+
await writeFile(gatePath, gateContent);
|
|
2344
|
+
if (operation === "register") {
|
|
2345
|
+
const registered = await registerOmxPluginCacheLivePin(snapshots[0], "gate-recovery", process.pid);
|
|
2346
|
+
assert.equal(Boolean(registered), gateState === "dead-owner");
|
|
2347
|
+
}
|
|
2348
|
+
else {
|
|
2349
|
+
const retired = await retireUnpinnedManagedSnapshots(codexHomeDir, "0.20.3");
|
|
2350
|
+
assert.equal(retired.includes(snapshots[0]), gateState === "dead-owner");
|
|
2351
|
+
assert.equal(retired.includes(snapshots[1]), true);
|
|
2352
|
+
}
|
|
2353
|
+
if (gateState === "dead-owner") {
|
|
2354
|
+
await assert.rejects(lstat(gatePath), { code: "ENOENT" });
|
|
2355
|
+
}
|
|
2356
|
+
else {
|
|
2357
|
+
assert.equal(await readFile(gatePath, "utf-8"), gateContent);
|
|
2358
|
+
assert.ok((await lstat(snapshots[0])).isDirectory());
|
|
2359
|
+
}
|
|
2360
|
+
});
|
|
2361
|
+
}
|
|
2362
|
+
finally {
|
|
2363
|
+
await rm(wd, { recursive: true, force: true });
|
|
2364
|
+
}
|
|
2365
|
+
});
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2368
|
+
it("same-version recreation + pin registration works after retirement gate cleanup", async () => {
|
|
2369
|
+
const wd = await mkdtemp(join(tmpdir(), "omx-3790-retirement-gate-reuse-"));
|
|
2370
|
+
try {
|
|
2371
|
+
await withIsolatedUserHome(wd, async (codexHomeDir) => {
|
|
2372
|
+
const packaged = await resolvePackagedOmxMarketplace(packageRoot);
|
|
2373
|
+
assert.ok(packaged);
|
|
2374
|
+
// Create and materialize current version
|
|
2375
|
+
const materialized = await materializePackagedOmxPluginCache(codexHomeDir, packaged);
|
|
2376
|
+
assert.equal(materialized.status, "materialized");
|
|
2377
|
+
const currentVersion = materialized.version;
|
|
2378
|
+
// Create two old snapshot versions without pins (GC keeps newest eligible predecessor)
|
|
2379
|
+
const oldVersion1 = "0.0.1";
|
|
2380
|
+
const oldCacheDir1 = await seedManagedSnapshot(codexHomeDir, oldVersion1);
|
|
2381
|
+
assert.ok(oldCacheDir1);
|
|
2382
|
+
const oldVersion2 = "0.0.2";
|
|
2383
|
+
const oldCacheDir2 = await seedManagedSnapshot(codexHomeDir, oldVersion2);
|
|
2384
|
+
assert.ok(oldCacheDir2);
|
|
2385
|
+
// Retire the old snapshots (they have no pins)
|
|
2386
|
+
const retired1 = await retireUnpinnedManagedSnapshots(codexHomeDir, currentVersion);
|
|
2387
|
+
assert.ok(retired1.includes(oldCacheDir1), "older version should be retired");
|
|
2388
|
+
await assert.rejects(lstat(oldCacheDir1), { code: "ENOENT" });
|
|
2389
|
+
assert.ok((await lstat(oldCacheDir2)).isDirectory(), "GC keeps the newest unpinned predecessor");
|
|
2390
|
+
const pinDirectory = livePinDirectoryPath(codexHomeDir, oldVersion1);
|
|
2391
|
+
await assert.rejects(lstat(join(pinDirectory, ".omx-retiring")), { code: "ENOENT" });
|
|
2392
|
+
// Recreate the retired version, whose external pin directory held the gate.
|
|
2393
|
+
assert.equal(await seedManagedSnapshot(codexHomeDir, oldVersion1), oldCacheDir1);
|
|
2394
|
+
const pinResult = await registerOmxPluginCacheLivePin(oldCacheDir1, "test-session-after-gate-cleanup", process.pid);
|
|
2395
|
+
assert.ok(pinResult, "pin registration should succeed after retirement gate cleanup");
|
|
2396
|
+
const pinFiles = (await readdir(pinDirectory)).filter((name) => name.endsWith(".json"));
|
|
2397
|
+
assert.equal(pinFiles.length, 1);
|
|
2398
|
+
const pin = JSON.parse(await readFile(join(pinDirectory, pinFiles[0]), "utf-8"));
|
|
2399
|
+
assert.equal(pin.sessionHash, createHash("sha256").update("test-session-after-gate-cleanup").digest("hex"));
|
|
2400
|
+
});
|
|
2401
|
+
}
|
|
2402
|
+
finally {
|
|
2403
|
+
await rm(wd, { recursive: true, force: true });
|
|
2404
|
+
}
|
|
2405
|
+
});
|
|
2406
|
+
it("pin operations work with alternate cache namespace (non-default cacheBase)", async () => {
|
|
2407
|
+
const wd = await mkdtemp(join(tmpdir(), "omx-3790-alternate-cache-"));
|
|
2408
|
+
try {
|
|
2409
|
+
// Create alternate CODEX_HOME directory with its own cache base
|
|
2410
|
+
const altCodexHome = join(wd, "alt-codex-home");
|
|
2411
|
+
await mkdir(altCodexHome, { recursive: true });
|
|
2412
|
+
const originalCodexHome = process.env.CODEX_HOME;
|
|
2413
|
+
try {
|
|
2414
|
+
process.env.CODEX_HOME = altCodexHome;
|
|
2415
|
+
const packaged = await resolvePackagedOmxMarketplace(packageRoot);
|
|
2416
|
+
assert.ok(packaged);
|
|
2417
|
+
// Materialize with alternate CODEX_HOME
|
|
2418
|
+
const materialized = await materializePackagedOmxPluginCache(altCodexHome, packaged);
|
|
2419
|
+
assert.equal(materialized.status, "materialized");
|
|
2420
|
+
const cacheDir = materialized.cacheDir;
|
|
2421
|
+
// Create a pin for this alternate cache namespace
|
|
2422
|
+
const pinResult = await registerOmxPluginCacheLivePin(cacheDir, "test-session-alt-cache", process.pid);
|
|
2423
|
+
assert.ok(pinResult, "pin registration should work with alternate CODEX_HOME");
|
|
2424
|
+
// Verify the pin was created in the correct cache location
|
|
2425
|
+
const version = materialized.version;
|
|
2426
|
+
const altCacheBase = omxPluginCacheBase(altCodexHome);
|
|
2427
|
+
assert.equal(cacheDir, join(altCacheBase, version));
|
|
2428
|
+
const externalPinDir = join(altCacheBase, ".omx-pins", version);
|
|
2429
|
+
const externalPins = (await readdir(externalPinDir)).filter((name) => name.endsWith(".json"));
|
|
2430
|
+
assert.equal(externalPins.length, 1, "pin should be in the alternate cache location");
|
|
2431
|
+
const pin = JSON.parse(await readFile(join(externalPinDir, externalPins[0]), "utf-8"));
|
|
2432
|
+
assert.equal(pin.pid, process.pid);
|
|
2433
|
+
assert.equal(pin.sessionHash, createHash("sha256").update("test-session-alt-cache").digest("hex"));
|
|
2434
|
+
await assert.rejects(lstat(join(cacheDir, ".omx-live-pin")), { code: "ENOENT" });
|
|
2435
|
+
}
|
|
2436
|
+
finally {
|
|
2437
|
+
if (originalCodexHome !== undefined) {
|
|
2438
|
+
process.env.CODEX_HOME = originalCodexHome;
|
|
2439
|
+
}
|
|
2440
|
+
else {
|
|
2441
|
+
delete process.env.CODEX_HOME;
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
finally {
|
|
2446
|
+
await rm(wd, { recursive: true, force: true });
|
|
2447
|
+
}
|
|
2448
|
+
});
|
|
2449
|
+
it("validates and creates .omx-pins parent safely (issue 3898 HIGH: native hook validation)", async () => {
|
|
2450
|
+
// This test verifies that the native hook code path validates the .omx-pins parent
|
|
2451
|
+
// directory before creating version subdirectories. The validation rejects symlinks
|
|
2452
|
+
// and ensures non-recursive creation of the parent.
|
|
2453
|
+
//
|
|
2454
|
+
// The TypeScript code path (registerOmxPluginCacheLivePin) already has proper validation
|
|
2455
|
+
// in openExternalLivePinDirectory and openDirectoryChild, but the native hook needs
|
|
2456
|
+
// independent validation since it creates directories directly with mkdirSync.
|
|
2457
|
+
//
|
|
2458
|
+
// The fix adds validateAndCreateLivePinParent() which checks for symlinks and
|
|
2459
|
+
// creates the parent non-recursively before version subdirectories are created.
|
|
2460
|
+
const wd = await mkdtemp(join(tmpdir(), "omx-3898-parent-validation-"));
|
|
2461
|
+
try {
|
|
2462
|
+
await withIsolatedUserHome(wd, async (codexHomeDir) => {
|
|
2463
|
+
const snapshots = await Promise.all(["0.20.0"].map((version) => seedManagedSnapshot(codexHomeDir, version)));
|
|
2464
|
+
const pluginRoot = snapshots[0];
|
|
2465
|
+
// Attempt to register a pin; should succeed and create the parent safely
|
|
2466
|
+
const pinResult = await registerOmxPluginCacheLivePin(pluginRoot, "test-session-parent-validation", process.pid);
|
|
2467
|
+
assert.ok(pinResult, "pin registration should succeed");
|
|
2468
|
+
// Verify the .omx-pins parent was created and is a real directory
|
|
2469
|
+
const cacheBase = omxPluginCacheBase(codexHomeDir);
|
|
2470
|
+
const pinsDir = join(cacheBase, ".omx-pins");
|
|
2471
|
+
const stats = await lstat(pinsDir);
|
|
2472
|
+
assert.ok(stats.isDirectory(), ".omx-pins should be a directory");
|
|
2473
|
+
assert.equal(stats.isSymbolicLink(), false, ".omx-pins should not be a symlink");
|
|
2474
|
+
});
|
|
2475
|
+
}
|
|
2476
|
+
finally {
|
|
2477
|
+
await rm(wd, { recursive: true, force: true });
|
|
2478
|
+
}
|
|
2479
|
+
});
|
|
2480
|
+
it("removes empty .omx-pins/<version> directory after gate cleanup (issue 3898 MEDIUM)", async () => {
|
|
2481
|
+
const wd = await mkdtemp(join(tmpdir(), "omx-3898-empty-dir-cleanup-"));
|
|
2482
|
+
try {
|
|
2483
|
+
await withIsolatedUserHome(wd, async (codexHomeDir) => {
|
|
2484
|
+
const snapshots = await Promise.all(["0.20.0", "0.20.1", "0.20.2"].map((version) => seedManagedSnapshot(codexHomeDir, version)));
|
|
2485
|
+
const version = "0.20.0";
|
|
2486
|
+
const pinDirectory = livePinDirectoryPath(codexHomeDir, version);
|
|
2487
|
+
// Create a pin, then remove the pin file to simulate a cleared/cancelled pin
|
|
2488
|
+
const pinResult = await registerOmxPluginCacheLivePin(snapshots[0], "test-session-for-cleanup-medium", process.pid);
|
|
2489
|
+
assert.ok(pinResult, "pin registration should succeed");
|
|
2490
|
+
// Verify the pin directory exists with a pin file
|
|
2491
|
+
let entries = await readdir(pinDirectory);
|
|
2492
|
+
assert.ok(entries.length > 0, "pin directory should have a pin file");
|
|
2493
|
+
// Remove all files from the pin directory (simulate cleanup)
|
|
2494
|
+
for (const entry of entries) {
|
|
2495
|
+
await rm(join(pinDirectory, entry), { force: true });
|
|
2496
|
+
}
|
|
2497
|
+
// Verify directory is now empty
|
|
2498
|
+
entries = await readdir(pinDirectory);
|
|
2499
|
+
assert.equal(entries.length, 0, "pin directory should be empty after file removal");
|
|
2500
|
+
// Age the directory beyond the initialization lease window (5 minutes)
|
|
2501
|
+
const agedTime = new Date(Date.now() - 6 * 60 * 1000);
|
|
2502
|
+
await utimes(pinDirectory, agedTime, agedTime);
|
|
2503
|
+
// Retire the snapshot (no active pins, so retirement gate will be created)
|
|
2504
|
+
const retired = await retireUnpinnedManagedSnapshots(codexHomeDir, "0.20.3");
|
|
2505
|
+
assert.ok(retired.includes(snapshots[0]), "snapshot should be retired");
|
|
2506
|
+
// After retirement, check if the empty pin directory was cleaned up.
|
|
2507
|
+
// The gate cleanup should remove the retirement marker, and if the directory
|
|
2508
|
+
// is empty, it should be removed to prevent it from being considered "active"
|
|
2509
|
+
// within the initialization lease window during subsequent repairs.
|
|
2510
|
+
try {
|
|
2511
|
+
await lstat(pinDirectory);
|
|
2512
|
+
// If directory still exists, it should be empty
|
|
2513
|
+
const finalEntries = await readdir(pinDirectory);
|
|
2514
|
+
assert.equal(finalEntries.length, 0, "pin directory should be empty or removed after gate cleanup");
|
|
2515
|
+
}
|
|
2516
|
+
catch (error) {
|
|
2517
|
+
// Empty directory was successfully removed (ENOENT is acceptable and preferred)
|
|
2518
|
+
if (error?.code !== "ENOENT") {
|
|
2519
|
+
throw error;
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
});
|
|
2523
|
+
}
|
|
2524
|
+
finally {
|
|
2525
|
+
await rm(wd, { recursive: true, force: true });
|
|
2526
|
+
}
|
|
2527
|
+
});
|
|
2528
|
+
it("I1: hook pin create/write/rename/lease-renewal stay inside <cacheBase>/.omx-pins/<version> when the directory is swapped for a symlink (issue 4010)", async () => {
|
|
2529
|
+
for (const swap of ["pins-parent", "version-dir"]) {
|
|
2530
|
+
const wd = await mkdtemp(join(tmpdir(), "omx-4010-i1-"));
|
|
2531
|
+
try {
|
|
2532
|
+
await withIsolatedUserHome(wd, async (codexHomeDir) => {
|
|
2533
|
+
const pluginRoot = await seedManagedSnapshot(codexHomeDir, "0.20.0");
|
|
2534
|
+
const cacheBase = omxPluginCacheBase(codexHomeDir);
|
|
2535
|
+
const pinsParent = join(cacheBase, ".omx-pins");
|
|
2536
|
+
const trapDir = join(wd, "trap-dir");
|
|
2537
|
+
await mkdir(trapDir);
|
|
2538
|
+
const sessionId = "i1-renewal-session";
|
|
2539
|
+
const sessionHash = createHash("sha256").update(sessionId).digest("hex");
|
|
2540
|
+
const pendingName = `.pending-${sessionHash}.json`;
|
|
2541
|
+
const delegatePath = join(wd, "i1-delegate.mjs");
|
|
2542
|
+
await writeFile(delegatePath, `
|
|
2543
|
+
import { existsSync } from "node:fs";
|
|
2544
|
+
const timer = setInterval(() => {
|
|
2545
|
+
if (!existsSync(process.env.OMX_TEST_DELEGATE_FINISHED)) return;
|
|
2546
|
+
clearInterval(timer);
|
|
2547
|
+
process.stdout.write("{}\\n");
|
|
2548
|
+
process.exit(0);
|
|
2549
|
+
}, 10);
|
|
2550
|
+
process.stdin.resume();
|
|
2551
|
+
`);
|
|
2552
|
+
await writeFile(join(pluginRoot, "hooks", "omx-command.json"), `${JSON.stringify({ command: process.execPath, argsPrefix: [delegatePath] })}\n`);
|
|
2553
|
+
const finishedPath = join(wd, "i1-finished");
|
|
2554
|
+
const preloadPath = join(wd, "i1-swap-then-renew.mjs");
|
|
2555
|
+
await writeFile(preloadPath, `
|
|
2556
|
+
import { existsSync, linkSync, mkdirSync, renameSync, symlinkSync, utimesSync, writeFileSync } from "node:fs";
|
|
2557
|
+
import { join } from "node:path";
|
|
2558
|
+
const realSetInterval = globalThis.setInterval;
|
|
2559
|
+
const callbacks = [];
|
|
2560
|
+
globalThis.setInterval = function (callback, delay, ...args) {
|
|
2561
|
+
if (delay === 60_000) { callbacks.push(callback); return { unref() {} }; }
|
|
2562
|
+
return realSetInterval(callback, delay, ...args);
|
|
2563
|
+
};
|
|
2564
|
+
const parent = process.env.OMX_TEST_PINS_PARENT;
|
|
2565
|
+
const trap = process.env.OMX_TEST_TRAP;
|
|
2566
|
+
const version = "0.20.0";
|
|
2567
|
+
const pendingName = process.env.OMX_TEST_PENDING_NAME;
|
|
2568
|
+
let attempts = 0;
|
|
2569
|
+
const run = () => {
|
|
2570
|
+
const pendingPath = join(parent, version, pendingName);
|
|
2571
|
+
if (!existsSync(pendingPath)) {
|
|
2572
|
+
if (++attempts < 500) setTimeout(run, 10);
|
|
2573
|
+
return;
|
|
2574
|
+
}
|
|
2575
|
+
// The trap holds a hard link to the live pending file so a renewal that
|
|
2576
|
+
// follows the symlink would visibly update it.
|
|
2577
|
+
mkdirSync(join(trap, version), { recursive: true });
|
|
2578
|
+
linkSync(pendingPath, join(trap, version, pendingName));
|
|
2579
|
+
const stale = new Date(Date.now() - 60 * 60 * 1000);
|
|
2580
|
+
utimesSync(pendingPath, stale, stale);
|
|
2581
|
+
if (process.env.OMX_TEST_SWAP === "pins-parent") {
|
|
2582
|
+
renameSync(parent, parent + ".real");
|
|
2583
|
+
symlinkSync(trap, parent);
|
|
2584
|
+
} else {
|
|
2585
|
+
renameSync(join(parent, version), join(parent, version + ".real"));
|
|
2586
|
+
symlinkSync(join(trap, version), join(parent, version));
|
|
2587
|
+
}
|
|
2588
|
+
for (const callback of callbacks) callback();
|
|
2589
|
+
setTimeout(() => writeFileSync(process.env.OMX_TEST_FINISHED, "finish"), 100);
|
|
2590
|
+
};
|
|
2591
|
+
setTimeout(run, 10);
|
|
2592
|
+
`);
|
|
2593
|
+
const hookResult = spawnSync(process.execPath, ["--import", preloadPath, join(pluginRoot, "hooks", "codex-native-hook.mjs")], {
|
|
2594
|
+
cwd: wd,
|
|
2595
|
+
input: JSON.stringify({ hook_event_name: "SessionStart", session_id: sessionId, codex_pid: process.pid, cwd: wd }),
|
|
2596
|
+
encoding: "utf-8",
|
|
2597
|
+
timeout: 15_000,
|
|
2598
|
+
env: {
|
|
2599
|
+
...process.env,
|
|
2600
|
+
CODEX_HOME: codexHomeDir,
|
|
2601
|
+
OMX_NATIVE_HOOK_COMMAND: process.execPath,
|
|
2602
|
+
OMX_TEST_PINS_PARENT: pinsParent,
|
|
2603
|
+
OMX_TEST_TRAP: trapDir,
|
|
2604
|
+
OMX_TEST_PENDING_NAME: pendingName,
|
|
2605
|
+
OMX_TEST_SWAP: swap,
|
|
2606
|
+
OMX_TEST_FINISHED: finishedPath,
|
|
2607
|
+
},
|
|
2608
|
+
});
|
|
2609
|
+
const linked = join(trapDir, "0.20.0", pendingName);
|
|
2610
|
+
const linkedStats = await lstat(linked).catch(() => null);
|
|
2611
|
+
assert.ok(linkedStats, `${swap}: the swap must have happened (hook output: ${hookResult.stderr})`);
|
|
2612
|
+
// The shared inode was aged before the swap; a renewal through the symlink would refresh it.
|
|
2613
|
+
assert.ok(Date.now() - linkedStats.mtimeMs > 30 * 60 * 1000, `${swap}: lease renewal must not follow the symlink`);
|
|
2614
|
+
const trapEntries = (await readdir(join(trapDir, "0.20.0"))).sort();
|
|
2615
|
+
assert.deepEqual(trapEntries, [pendingName], `${swap}: no file may appear in the symlink target`);
|
|
2616
|
+
assert.equal((await readdir(trapDir)).length, 1, `${swap}: nothing but the seeded link in the symlink target`);
|
|
2617
|
+
});
|
|
2618
|
+
}
|
|
2619
|
+
finally {
|
|
2620
|
+
await rm(wd, { recursive: true, force: true });
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
});
|
|
2624
|
+
it("I1 residual: hook pin mutations bind to the held directory handle when .omx-pins or the version dir is swapped immediately before the syscall (issue 4010, linux)", { skip: process.platform !== "linux" ? "anchoring via /proc/self/fd is Linux-only; non-Linux Node has no *at primitives (residual tracked in #4022)" : false }, async () => {
|
|
2625
|
+
for (const point of ["writeFileSync", "linkSync"]) {
|
|
2626
|
+
for (const swap of ["pins-parent", "version-dir"]) {
|
|
2627
|
+
const wd = await mkdtemp(join(tmpdir(), "omx-4010-i1r-"));
|
|
2628
|
+
try {
|
|
2629
|
+
await withIsolatedUserHome(wd, async (codexHomeDir) => {
|
|
2630
|
+
const pluginRoot = await seedManagedSnapshot(codexHomeDir, "0.20.0");
|
|
2631
|
+
const pinsParent = join(omxPluginCacheBase(codexHomeDir), ".omx-pins");
|
|
2632
|
+
const trapDir = join(wd, "trap-dir");
|
|
2633
|
+
await mkdir(join(trapDir, "0.20.0"), { recursive: true });
|
|
2634
|
+
const swappedMarker = join(wd, "swapped");
|
|
2635
|
+
const leakedPath = join(wd, "leaked");
|
|
2636
|
+
const preloadPath = join(wd, "i1r-swap-before-syscall.mjs");
|
|
2637
|
+
await writeFile(preloadPath, `
|
|
2638
|
+
import fs from "node:fs";
|
|
2639
|
+
import { basename } from "node:path";
|
|
2640
|
+
import { syncBuiltinESMExports } from "node:module";
|
|
2641
|
+
const parent = process.env.OMX_TEST_PINS_PARENT;
|
|
2642
|
+
const trap = process.env.OMX_TEST_TRAP;
|
|
2643
|
+
const version = "0.20.0";
|
|
2644
|
+
let swapped = false;
|
|
2645
|
+
function swapNow() {
|
|
2646
|
+
swapped = true;
|
|
2647
|
+
if (process.env.OMX_TEST_SWAP === "pins-parent") {
|
|
2648
|
+
fs.renameSync(parent, parent + ".real");
|
|
2649
|
+
fs.symlinkSync(trap, parent);
|
|
2650
|
+
} else {
|
|
2651
|
+
fs.renameSync(parent + "/" + version, parent + "/" + version + ".real");
|
|
2652
|
+
fs.symlinkSync(trap + "/" + version, parent + "/" + version);
|
|
2653
|
+
}
|
|
2654
|
+
fs.writeFileSync(process.env.OMX_TEST_SWAPPED, "swapped");
|
|
2655
|
+
}
|
|
2656
|
+
function wrap(name) {
|
|
2657
|
+
const original = fs[name];
|
|
2658
|
+
fs[name] = function (path, ...args) {
|
|
2659
|
+
if (!swapped && name === process.env.OMX_TEST_POINT && typeof path === "string" && basename(path).startsWith(".stage-pending-")) swapNow();
|
|
2660
|
+
const result = original.call(this, path, ...args);
|
|
2661
|
+
if (swapped && name === process.env.OMX_TEST_POINT) {
|
|
2662
|
+
const seen = fs.readdirSync(trap + "/" + version);
|
|
2663
|
+
if (seen.length > 0) fs.appendFileSync(process.env.OMX_TEST_LEAKED, seen.join("\\n") + "\\n");
|
|
2664
|
+
}
|
|
2665
|
+
return result;
|
|
2666
|
+
};
|
|
2667
|
+
}
|
|
2668
|
+
wrap("writeFileSync");
|
|
2669
|
+
wrap("linkSync");
|
|
2670
|
+
syncBuiltinESMExports();
|
|
2671
|
+
`);
|
|
2672
|
+
spawnSync(process.execPath, ["--import", preloadPath, join(pluginRoot, "hooks", "codex-native-hook.mjs")], {
|
|
2673
|
+
cwd: wd,
|
|
2674
|
+
input: JSON.stringify({ hook_event_name: "SessionStart", session_id: "i1r-session", codex_pid: process.pid, cwd: wd }),
|
|
2675
|
+
encoding: "utf-8",
|
|
2676
|
+
timeout: 15_000,
|
|
2677
|
+
env: {
|
|
2678
|
+
...process.env,
|
|
2679
|
+
CODEX_HOME: codexHomeDir,
|
|
2680
|
+
OMX_NATIVE_HOOK_COMMAND: process.execPath,
|
|
2681
|
+
OMX_TEST_PINS_PARENT: pinsParent,
|
|
2682
|
+
OMX_TEST_TRAP: trapDir,
|
|
2683
|
+
OMX_TEST_SWAP: swap,
|
|
2684
|
+
OMX_TEST_POINT: point,
|
|
2685
|
+
OMX_TEST_SWAPPED: swappedMarker,
|
|
2686
|
+
OMX_TEST_LEAKED: leakedPath,
|
|
2687
|
+
},
|
|
2688
|
+
});
|
|
2689
|
+
const label = `${point}/${swap}`;
|
|
2690
|
+
assert.ok(await lstat(swappedMarker).catch(() => null), `${label}: the swap must have been injected before the syscall`);
|
|
2691
|
+
const leaked = await readFile(leakedPath, "utf-8").catch(() => "");
|
|
2692
|
+
assert.equal(leaked, "", `${label}: the mutation syscall must not create anything in the symlink target (saw: ${leaked.trim()})`);
|
|
2693
|
+
assert.deepEqual(await readdir(join(trapDir, "0.20.0")), [], `${label}: nothing may be created or modified in the symlink target`);
|
|
2694
|
+
assert.deepEqual(await readdir(trapDir), ["0.20.0"], `${label}: nothing else in the symlink target`);
|
|
2695
|
+
});
|
|
2696
|
+
}
|
|
2697
|
+
finally {
|
|
2698
|
+
await rm(wd, { recursive: true, force: true });
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
});
|
|
2703
|
+
it("I2: active legacy in-tree .omx-live-pin session survives hook lease loss, GC and repair (issue 4010)", async () => {
|
|
2704
|
+
const wd = await mkdtemp(join(tmpdir(), "omx-4010-i2-"));
|
|
2705
|
+
try {
|
|
2706
|
+
await withIsolatedUserHome(wd, async (codexHomeDir) => {
|
|
2707
|
+
const packaged = await resolvePackagedOmxMarketplace(packageRoot);
|
|
2708
|
+
assert.ok(packaged);
|
|
2709
|
+
const published = await materializePackagedOmxPluginCache(codexHomeDir, packaged);
|
|
2710
|
+
assert.equal(published.status, "materialized");
|
|
2711
|
+
const cacheDir = published.cacheDir;
|
|
2712
|
+
const version = published.version;
|
|
2713
|
+
const legacyPinDir = join(cacheDir, ".omx-live-pin");
|
|
2714
|
+
await mkdir(legacyPinDir);
|
|
2715
|
+
await writeFile(join(legacyPinDir, "pin-legacy-delegate.json"), `${JSON.stringify({ version: 1, pid: process.pid, processStartHash: null, sessionHash: createHash("sha256").update("legacy-delegate-session").digest("hex") })}\n`);
|
|
2716
|
+
const olderSnapshots = await Promise.all(["0.20.1", "0.20.2"].map((v) => seedManagedSnapshot(codexHomeDir, v)));
|
|
2717
|
+
// Hook lease loss: no external pin exists and every hook lease expires; the delegate must survive.
|
|
2718
|
+
await assertDelegateSurvivesLostLeasesWithPin(wd, codexHomeDir, cacheDir, "i2-session", "i2-launch", null, "", version);
|
|
2719
|
+
await lstat(join(legacyPinDir, "pin-legacy-delegate.json"));
|
|
2720
|
+
// The hook left only an expired/empty external pin dir; the legacy pin must still decide.
|
|
2721
|
+
const externalPinEntries = await readdir(livePinDirectoryPath(codexHomeDir, version)).catch(() => []);
|
|
2722
|
+
assert.equal(externalPinEntries.some((name) => name.startsWith("pin-")), false);
|
|
2723
|
+
await utimes(livePinDirectoryPath(codexHomeDir, version), new Date(0), new Date(0)).catch(() => undefined);
|
|
2724
|
+
// GC
|
|
2725
|
+
const retired = await retireUnpinnedManagedSnapshots(codexHomeDir, "999.0.0");
|
|
2726
|
+
assert.equal(retired.includes(cacheDir), false, "legacy-pinned snapshot must survive GC");
|
|
2727
|
+
assert.equal(retired.includes(olderSnapshots[0]), true, "unpinned older snapshot is still collected");
|
|
2728
|
+
await lstat(cacheDir);
|
|
2729
|
+
// Repair
|
|
2730
|
+
const manifestPath = join(cacheDir, ".codex-plugin", "plugin.json");
|
|
2731
|
+
const manifest = JSON.parse(await readFile(manifestPath, "utf-8"));
|
|
2732
|
+
manifest.version = "corrupted-version";
|
|
2733
|
+
await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
2734
|
+
const blocked = await materializePackagedOmxPluginCache(codexHomeDir, packaged, { repairCache: true });
|
|
2735
|
+
assert.equal(blocked.status, "stale-launcher", JSON.stringify(blocked));
|
|
2736
|
+
assert.match(blocked.reason ?? "", /pinned by a live Codex session/);
|
|
2737
|
+
await lstat(join(legacyPinDir, "pin-legacy-delegate.json"));
|
|
2738
|
+
assert.equal(JSON.parse(await readFile(manifestPath, "utf-8")).version, "corrupted-version");
|
|
2739
|
+
});
|
|
2740
|
+
}
|
|
2741
|
+
finally {
|
|
2742
|
+
await rm(wd, { recursive: true, force: true });
|
|
2743
|
+
}
|
|
2744
|
+
});
|
|
2745
|
+
it("I3: second same-version repair succeeds immediately after gate cleanup, no lease wait (issue 4010)", async () => {
|
|
2746
|
+
const wd = await mkdtemp(join(tmpdir(), "omx-4010-i3-"));
|
|
2747
|
+
try {
|
|
2748
|
+
await withIsolatedUserHome(wd, async (codexHomeDir) => {
|
|
2749
|
+
const packaged = await resolvePackagedOmxMarketplace(packageRoot);
|
|
2750
|
+
assert.ok(packaged);
|
|
2751
|
+
const published = await materializePackagedOmxPluginCache(codexHomeDir, packaged);
|
|
2752
|
+
assert.equal(published.status, "materialized");
|
|
2753
|
+
const manifestPath = join(published.cacheDir, ".codex-plugin", "plugin.json");
|
|
2754
|
+
const expectedVersion = published.version;
|
|
2755
|
+
for (const round of [1, 2]) {
|
|
2756
|
+
const manifest = JSON.parse(await readFile(manifestPath, "utf-8"));
|
|
2757
|
+
manifest.version = "corrupted-version";
|
|
2758
|
+
await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
2759
|
+
const repaired = await materializePackagedOmxPluginCache(codexHomeDir, packaged, { repairCache: true });
|
|
2760
|
+
assert.equal(repaired.status, "materialized", `repair #${round}: ${JSON.stringify(repaired)}`);
|
|
2761
|
+
assert.equal(JSON.parse(await readFile(manifestPath, "utf-8")).version, expectedVersion);
|
|
2762
|
+
}
|
|
2763
|
+
});
|
|
2764
|
+
}
|
|
2765
|
+
finally {
|
|
2766
|
+
await rm(wd, { recursive: true, force: true });
|
|
2767
|
+
}
|
|
2768
|
+
});
|
|
2109
2769
|
});
|
|
2110
2770
|
//# sourceMappingURL=plugin-cache-live-pin-3790.test.js.map
|