-
Notifications
You must be signed in to change notification settings - Fork 17
test: session git-path decoding + recap loop detection boundaries #401
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
Closed
anandgupta42
wants to merge
1
commit into
main
from
claude/test-discovery-20260323-session-01UgL6G8jZAPtoUUKBphH7f4
+269
−0
Closed
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
175 changes: 175 additions & 0 deletions
175
packages/opencode/test/session/summary-git-path.test.ts
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,175 @@ | ||
| import { describe, test, expect } from "bun:test" | ||
| import path from "path" | ||
| import { SessionSummary } from "../../src/session/summary" | ||
| import { Instance } from "../../src/project/instance" | ||
| import { Storage } from "../../src/storage/storage" | ||
| import { Log } from "../../src/util/log" | ||
| import { Identifier } from "../../src/id/id" | ||
|
|
||
| /** | ||
| * Tests for the unquoteGitPath function used in SessionSummary.diff(). | ||
| * | ||
| * Git quotes file paths containing non-ASCII bytes using C-style escaping with | ||
| * octal sequences (e.g., \303\251 for UTF-8 "é"). This function decodes those | ||
| * paths back to their original Unicode representation. Without correct decoding, | ||
| * session diffs show garbled filenames for non-ASCII files (CJK, accented, emoji). | ||
| * | ||
| * We test indirectly via SessionSummary.diff() which applies unquoteGitPath to | ||
| * stored FileDiff entries. | ||
| */ | ||
|
|
||
| const projectRoot = path.join(__dirname, "../..") | ||
| Log.init({ print: false }) | ||
|
|
||
| // Helper: write fake diffs to Storage for a session, then read them back via diff() | ||
| async function roundtrip(files: string[]): Promise<string[]> { | ||
| const sessionID = Identifier.ascending("session") as any | ||
| const diffs = files.map((file) => ({ | ||
| file, | ||
| before: "", | ||
| after: "", | ||
| additions: 1, | ||
| deletions: 0, | ||
| status: "added" as const, | ||
| })) | ||
|
|
||
| await Storage.write(["session_diff", sessionID], diffs) | ||
| const result = await SessionSummary.diff({ sessionID }) | ||
| return result.map((d) => d.file) | ||
| } | ||
|
|
||
| describe("SessionSummary.diff: unquoteGitPath decoding", () => { | ||
| test("plain ASCII paths pass through unchanged", async () => { | ||
| await Instance.provide({ | ||
| directory: projectRoot, | ||
| fn: async () => { | ||
| const files = await roundtrip([ | ||
| "src/index.ts", | ||
| "README.md", | ||
| "packages/opencode/test/file.test.ts", | ||
| ]) | ||
| expect(files).toEqual([ | ||
| "src/index.ts", | ||
| "README.md", | ||
| "packages/opencode/test/file.test.ts", | ||
| ]) | ||
| }, | ||
| }) | ||
| }) | ||
|
|
||
| test("git-quoted path with octal-encoded UTF-8 (2-byte: é = \\303\\251)", async () => { | ||
| await Instance.provide({ | ||
| directory: projectRoot, | ||
| fn: async () => { | ||
| // Git quotes "café.txt" as "caf\\303\\251.txt" | ||
| const files = await roundtrip(['"caf\\303\\251.txt"']) | ||
| expect(files).toEqual(["café.txt"]) | ||
| }, | ||
| }) | ||
| }) | ||
|
|
||
| test("git-quoted path with 3-byte UTF-8 octal (CJK character 中 = \\344\\270\\255)", async () => { | ||
| await Instance.provide({ | ||
| directory: projectRoot, | ||
| fn: async () => { | ||
| // Git quotes "中文.txt" as "\\344\\270\\255\\346\\226\\207.txt" | ||
| const files = await roundtrip(['"\\344\\270\\255\\346\\226\\207.txt"']) | ||
| expect(files).toEqual(["中文.txt"]) | ||
| }, | ||
| }) | ||
| }) | ||
|
|
||
| test("git-quoted path with standard escape sequences (\\n, \\t, \\\\, \\\")", async () => { | ||
| await Instance.provide({ | ||
| directory: projectRoot, | ||
| fn: async () => { | ||
| const files = await roundtrip([ | ||
| '"path\\\\with\\\\backslashes"', | ||
| '"file\\twith\\ttabs"', | ||
| '"line\\nbreak"', | ||
| ]) | ||
| expect(files).toEqual([ | ||
| "path\\with\\backslashes", | ||
| "file\twith\ttabs", | ||
| "line\nbreak", | ||
| ]) | ||
| }, | ||
| }) | ||
| }) | ||
|
|
||
| test("mixed octal and plain ASCII in one path", async () => { | ||
| await Instance.provide({ | ||
| directory: projectRoot, | ||
| fn: async () => { | ||
| // "docs/résumé.md" → git quotes accented chars only | ||
| // é = \303\251 in UTF-8 | ||
| const files = await roundtrip(['"docs/r\\303\\251sum\\303\\251.md"']) | ||
| expect(files).toEqual(["docs/résumé.md"]) | ||
| }, | ||
| }) | ||
| }) | ||
|
|
||
| test("unquoted path (no surrounding double quotes) passes through unchanged", async () => { | ||
| await Instance.provide({ | ||
| directory: projectRoot, | ||
| fn: async () => { | ||
| // If git doesn't quote the path, it should pass through as-is | ||
| const files = await roundtrip(["normal/path.ts", "another-file.js"]) | ||
| expect(files).toEqual(["normal/path.ts", "another-file.js"]) | ||
| }, | ||
| }) | ||
| }) | ||
|
|
||
| test("path with embedded double quote (\\\")", async () => { | ||
| await Instance.provide({ | ||
| directory: projectRoot, | ||
| fn: async () => { | ||
| const files = await roundtrip(['"file\\"name.txt"']) | ||
| expect(files).toEqual(['file"name.txt']) | ||
| }, | ||
| }) | ||
| }) | ||
|
|
||
| test("empty string passes through unchanged", async () => { | ||
| await Instance.provide({ | ||
| directory: projectRoot, | ||
| fn: async () => { | ||
| const files = await roundtrip([""]) | ||
| expect(files).toEqual([""]) | ||
| }, | ||
| }) | ||
| }) | ||
|
|
||
| test("Japanese filename with 3-byte UTF-8 sequences (テスト = \\343\\203\\206\\343\\202\\271\\343\\203\\210)", async () => { | ||
| await Instance.provide({ | ||
| directory: projectRoot, | ||
| fn: async () => { | ||
| // テ = E3 83 86 = \343\203\206 | ||
| // ス = E3 82 B9 = \343\202\271 | ||
| // ト = E3 83 88 = \343\203\210 | ||
| const files = await roundtrip(['"\\343\\203\\206\\343\\202\\271\\343\\203\\210.sql"']) | ||
| expect(files).toEqual(["テスト.sql"]) | ||
| }, | ||
| }) | ||
| }) | ||
|
|
||
| test("multiple files: some quoted, some not", async () => { | ||
| await Instance.provide({ | ||
| directory: projectRoot, | ||
| fn: async () => { | ||
| const files = await roundtrip([ | ||
| "plain.ts", | ||
| '"caf\\303\\251.txt"', | ||
| "normal/path.js", | ||
| '"\\344\\270\\255.md"', | ||
| ]) | ||
| expect(files).toEqual([ | ||
| "plain.ts", | ||
| "café.txt", | ||
| "normal/path.js", | ||
| "中.md", | ||
| ]) | ||
| }, | ||
| }) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
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.
🛠️ Refactor suggestion | 🟠 Major
Use per-test
tmpdir()isolation instead of repository root directory.Line 21 and repeated
Instance.providecalls run against a shared repo path; these tests should usetmpdir()withawait usingand passtmp.pathto keep storage state isolated and auto-cleaned.Suggested refactor
As per coding guidelines:
Use the tmpdir function from fixture/fixture.ts to create temporary directories for tests with automatic cleanup in test filesandAlways use await using syntax with tmpdir() for automatic cleanup when the variable goes out of scope.📝 Committable suggestion
🤖 Prompt for AI Agents