-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix(transfer): resolve imported thread id on Windows and surface import failures #701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JMak-Security
wants to merge
1
commit into
openai:main
Choose a base branch
from
JMak-Security:fix/windows-transfer-ledger-lookup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import test from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
|
|
||
| import { | ||
| normalizeImportPath, | ||
| importedThreadIdFromCompletion, | ||
| importFailureDetails | ||
| } from "../plugins/codex/scripts/lib/codex.mjs"; | ||
|
|
||
| // Regression coverage for issue #618: `/codex:transfer` always fails on Windows | ||
| // because the ledger lookup can never match. Codex records paths via Rust's | ||
| // fs::canonicalize (Windows verbatim `\\?\...` prefix) while the plugin compared | ||
| // them against Node's fs.realpathSync output, which never carries that prefix. | ||
|
|
||
| test("normalizeImportPath makes a Windows verbatim path match its plain form", () => { | ||
| const verbatim = String.raw`\\?\C:\Users\me\.claude\projects\p\id.jsonl`; | ||
| const plain = String.raw`C:\Users\me\.claude\projects\p\id.jsonl`; | ||
|
|
||
| const normalizedVerbatim = normalizeImportPath(verbatim); | ||
| assert.ok(normalizedVerbatim, "verbatim path should normalize to a value"); | ||
| assert.equal( | ||
| normalizedVerbatim, | ||
| normalizeImportPath(plain), | ||
| "verbatim and plain paths must normalize to the same value" | ||
| ); | ||
| assert.equal( | ||
| normalizedVerbatim.startsWith("\\\\?\\"), | ||
| false, | ||
| "the verbatim extended-length prefix must be stripped" | ||
| ); | ||
| }); | ||
|
|
||
| test("normalizeImportPath maps a verbatim UNC path onto its plain UNC form", () => { | ||
| const verbatim = String.raw`\\?\UNC\server\share\sess.jsonl`; | ||
| const plain = String.raw`\\server\share\sess.jsonl`; | ||
|
|
||
| assert.equal(normalizeImportPath(verbatim), normalizeImportPath(plain)); | ||
| }); | ||
|
|
||
| test("normalizeImportPath returns null for empty or non-string input", () => { | ||
| assert.equal(normalizeImportPath(""), null); | ||
| assert.equal(normalizeImportPath(undefined), null); | ||
| assert.equal(normalizeImportPath(42), null); | ||
| }); | ||
|
|
||
| test("importedThreadIdFromCompletion resolves target from the matching success", () => { | ||
| const source = String.raw`C:\Users\me\.claude\projects\p\id.jsonl`; | ||
| const completion = { | ||
| itemTypeResults: [ | ||
| { | ||
| itemType: "SESSIONS", | ||
| successes: [ | ||
| { | ||
| itemType: "SESSIONS", | ||
| cwd: null, | ||
| source: String.raw`\\?\C:\Users\me\.claude\projects\p\id.jsonl`, | ||
| target: "019fe103-b7aa-74c1-8fb2-ef6afd58785f" | ||
| } | ||
| ], | ||
| failures: [] | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
| assert.equal( | ||
| importedThreadIdFromCompletion(completion, source), | ||
| "019fe103-b7aa-74c1-8fb2-ef6afd58785f" | ||
| ); | ||
| }); | ||
|
|
||
| test("importedThreadIdFromCompletion falls back to the sole success target", () => { | ||
| const completion = { | ||
| itemTypeResults: [ | ||
| { successes: [{ source: "some/other/path.jsonl", target: "thread-xyz" }], failures: [] } | ||
| ] | ||
| }; | ||
|
|
||
| assert.equal( | ||
| importedThreadIdFromCompletion(completion, String.raw`C:\Users\me\unrelated.jsonl`), | ||
| "thread-xyz" | ||
| ); | ||
| }); | ||
|
|
||
| test("importedThreadIdFromCompletion returns null when there is no target", () => { | ||
| assert.equal(importedThreadIdFromCompletion(null, "x"), null); | ||
| assert.equal(importedThreadIdFromCompletion({}, "x"), null); | ||
| assert.equal( | ||
| importedThreadIdFromCompletion( | ||
| { itemTypeResults: [{ successes: [{ source: "x" }], failures: [] }] }, | ||
| "x" | ||
| ), | ||
| null | ||
| ); | ||
| }); | ||
|
|
||
| test("importFailureDetails surfaces failure reasons and is null when there are none", () => { | ||
| const withFailures = { | ||
| itemTypeResults: [ | ||
| { successes: [], failures: [{ error: "boom" }, { message: "second" }] } | ||
| ] | ||
| }; | ||
| assert.equal(importFailureDetails(withFailures), "boom\nsecond"); | ||
|
|
||
| assert.equal(importFailureDetails({ itemTypeResults: [{ successes: [], failures: [] }] }), null); | ||
| assert.equal(importFailureDetails(null), null); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this source was imported previously and a later import completes without a success target, the unconditional ledger fallback can return the earlier thread. Because
importedThreadIdForSourcenow accepts a path match even when the current content hash differs, a changed transcript whose new import fails is reported as successfully imported while the user is given a stale thread that lacks the latest session content; only use the ledger when the completion lacks result data, not when it explicitly contains no matching success.Useful? React with 👍 / 👎.