Skip to content

Commit 6ddd397

Browse files
committed
fix(manifest): normalize Windows extended-length and device path prefixes (#4442)
1 parent 04d060e commit 6ddd397

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎src/codex/history-manifest.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,20 @@ export type CodexHistoryManifestValidation =
5454
readonly scope: "manifest" | "entry-shape" | "entry-provenance";
5555
};
5656

57+
function stripWindowsPathPrefix(path: string): string {
58+
if (process.platform !== "win32") return path;
59+
if (/^(\\\\(\?|\.)\\UNC\\|\/\/(\?|\.)\/UNC\/)/i.test(path)) {
60+
return "\\\\" + path.slice(8);
61+
}
62+
if (/^(\\\\(\?|\.)\\|\/\/(\?|\.)\/)/.test(path)) {
63+
return path.slice(4);
64+
}
65+
return path;
66+
}
67+
5768
function codexHistoryPathIdentity(path: string): string {
58-
const canonical = resolve(path);
69+
const stripped = stripWindowsPathPrefix(path);
70+
const canonical = resolve(stripped);
5971
return process.platform === "win32" ? canonical.toLowerCase() : canonical;
6072
}
6173

‎tests/codex-integration/codex-history-provider.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { join } from "node:path";
44
import { Database } from "bun:sqlite";
55
import { afterEach, describe, expect, setDefaultTimeout, test } from "bun:test";
66
import { classifyRecoverableHistoryError, countPendingOpencodexHistory, historyBackupPathFor, isRecoverableHistoryError, migrateHistoryToOpenai, restoreLegacyOpenaiHistory, restoredUserEventFor, setAfterNoopPendingCountForTests, setAfterStrictHistoryRolloutAppendForTests, setBeforeHistoryApplyTransactionForTests, setBeforeHistoryBackupConsumeForTests, setBeforeStrictHistoryRolloutAppendForTests, setHistoryDbBusyTimeoutForTests, snapshotCodexHistoryNoop, syncCodexHistoryProvider, withHistoryRetry } from "../../src/codex/history-provider";
7+
import { sameCodexHistoryPath } from "../../src/codex/history-manifest";
78
import { INVALID_HISTORY_BACKUP_FIXTURES, validHistoryBackupFixture } from "../helpers/codex-history-manifest-fixtures";
89
import { preflightCodexHistoryInjection, setHistoryAppendHooksForTests } from "../../src/codex/history-provider";
910

@@ -1513,4 +1514,23 @@ describe("Design B migration helpers", () => {
15131514
expect(db.query("SELECT model_provider FROM threads WHERE id = 'thread-1'").get()).toEqual({ model_provider: "openai" });
15141515
db.close();
15151516
});
1517+
1518+
test("sameCodexHistoryPath normalizes Windows extended-length and device path prefixes", () => {
1519+
if (process.platform !== "win32") return;
1520+
const std = "C:\\Users\\test\\state.db";
1521+
const ext = "\\\\?\\C:\\Users\\test\\state.db";
1522+
const dev = "\\\\.\\C:\\Users\\test\\state.db";
1523+
const fwd = "//?/C:/Users/test/state.db";
1524+
expect(sameCodexHistoryPath(std, ext)).toBe(true);
1525+
expect(sameCodexHistoryPath(ext, std)).toBe(true);
1526+
expect(sameCodexHistoryPath(std, dev)).toBe(true);
1527+
expect(sameCodexHistoryPath(std, fwd)).toBe(true);
1528+
});
1529+
1530+
test("sameCodexHistoryPath normalizes Windows UNC paths with extended prefix", () => {
1531+
if (process.platform !== "win32") return;
1532+
const unc = "\\\\server\\share\\rollout.jsonl";
1533+
const extUnc = "\\\\?\\UNC\\server\\share\\rollout.jsonl";
1534+
expect(sameCodexHistoryPath(unc, extUnc)).toBe(true);
1535+
});
15161536
});

0 commit comments

Comments
 (0)