Conversation
Prompt To Fix All With AIThis is a comment left during a code review.
Path: apps/code/src/main/utils/fixPath.test.ts
Line: 69-164
Comment:
**Prefer parameterised tests for shared assertion patterns**
Tests `"merges fallback paths when shell PATH lacks /opt/homebrew/bin"` (line 69), `"falls back to fallback paths when shell resolution fails entirely"` (line 92), and `"merges fallback paths into a cached PATH that lacks them"` (line 106) all end with the same four `toContain` assertions for the fallback paths. Per the team's stated preference for parameterised tests, these cases could be collapsed into a single `it.each` that varies the mock setup (shell success / shell fail / cache hit) while sharing the assertion block, eliminating the duplication.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix: use merge path for users of oh my z..." | Re-trigger Greptile |
|
|
||
| it("merges fallback paths when shell PATH lacks /opt/homebrew/bin", async () => { | ||
| mockSpawnSync.mockReturnValue({ | ||
| status: 0, | ||
| stdout: shellOutput("/usr/local/bin:/usr/bin:/bin"), | ||
| }); | ||
|
|
||
| const { fixPath } = await import("./fixPath"); | ||
| fixPath(); | ||
|
|
||
| const parts = process.env.PATH?.split(":") ?? []; | ||
| expect(parts).toContain("/opt/homebrew/bin"); | ||
| expect(parts).toContain("/opt/homebrew/sbin"); | ||
| expect(parts).toContain("/usr/local/bin"); | ||
| expect(parts).toContain("/usr/bin"); | ||
| }); | ||
|
|
||
| it("does not duplicate fallback paths already present in shell PATH", async () => { | ||
| mockSpawnSync.mockReturnValue({ | ||
| status: 0, | ||
| stdout: shellOutput("/opt/homebrew/bin:/usr/local/bin:/usr/bin"), | ||
| }); | ||
|
|
||
| const { fixPath } = await import("./fixPath"); | ||
| fixPath(); | ||
|
|
||
| const parts = process.env.PATH?.split(":") ?? []; | ||
| const homebrewCount = parts.filter((p) => p === "/opt/homebrew/bin").length; | ||
| expect(homebrewCount).toBe(1); | ||
| const usrLocalCount = parts.filter((p) => p === "/usr/local/bin").length; | ||
| expect(usrLocalCount).toBe(1); | ||
| }); | ||
|
|
||
| it("falls back to fallback paths when shell resolution fails entirely", async () => { | ||
| mockSpawnSync.mockReturnValue({ status: 1, stdout: "" }); | ||
|
|
||
| const { fixPath } = await import("./fixPath"); | ||
| fixPath(); | ||
|
|
||
| const parts = process.env.PATH?.split(":") ?? []; | ||
| expect(parts).toContain("/opt/homebrew/bin"); | ||
| expect(parts).toContain("/opt/homebrew/sbin"); | ||
| expect(parts).toContain("/usr/local/bin"); | ||
| expect(parts).toContain("/usr/bin"); | ||
| }); | ||
|
|
||
| it("merges fallback paths into a cached PATH that lacks them", async () => { | ||
| mockExistsSync.mockReturnValue(true); | ||
| mockReadFileSync.mockReturnValue( | ||
| JSON.stringify({ | ||
| path: "/usr/local/bin:/usr/bin:/bin", | ||
| timestamp: Date.now(), | ||
| }), | ||
| ); | ||
|
|
||
| const { fixPath } = await import("./fixPath"); | ||
| fixPath(); | ||
|
|
||
| const parts = process.env.PATH?.split(":") ?? []; | ||
| expect(parts).toContain("/opt/homebrew/bin"); | ||
| expect(mockSpawnSync).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("ignores stale cache and re-resolves via shell", async () => { | ||
| mockExistsSync.mockReturnValue(true); | ||
| mockReadFileSync.mockReturnValue( | ||
| JSON.stringify({ | ||
| path: "/some/old/path", | ||
| timestamp: Date.now() - 2 * 60 * 60 * 1000, | ||
| }), | ||
| ); | ||
| mockSpawnSync.mockReturnValue({ | ||
| status: 0, | ||
| stdout: shellOutput("/usr/local/bin:/usr/bin"), | ||
| }); | ||
|
|
||
| const { fixPath } = await import("./fixPath"); | ||
| fixPath(); | ||
|
|
||
| expect(mockSpawnSync).toHaveBeenCalled(); | ||
| const parts = process.env.PATH?.split(":") ?? []; | ||
| expect(parts).not.toContain("/some/old/path"); | ||
| expect(parts).toContain("/opt/homebrew/bin"); | ||
| }); | ||
|
|
||
| it("returns early on win32 without touching PATH", async () => { | ||
| setPlatform("win32"); | ||
| process.env.PATH = "C:\\Windows\\System32"; | ||
|
|
||
| const { fixPath } = await import("./fixPath"); | ||
| fixPath(); | ||
|
|
||
| expect(mockSpawnSync).not.toHaveBeenCalled(); | ||
| expect(process.env.PATH).toBe("C:\\Windows\\System32"); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Prefer parameterised tests for shared assertion patterns
Tests "merges fallback paths when shell PATH lacks /opt/homebrew/bin" (line 69), "falls back to fallback paths when shell resolution fails entirely" (line 92), and "merges fallback paths into a cached PATH that lacks them" (line 106) all end with the same four toContain assertions for the fallback paths. Per the team's stated preference for parameterised tests, these cases could be collapsed into a single it.each that varies the mock setup (shell success / shell fail / cache hit) while sharing the assertion block, eliminating the duplication.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/main/utils/fixPath.test.ts
Line: 69-164
Comment:
**Prefer parameterised tests for shared assertion patterns**
Tests `"merges fallback paths when shell PATH lacks /opt/homebrew/bin"` (line 69), `"falls back to fallback paths when shell resolution fails entirely"` (line 92), and `"merges fallback paths into a cached PATH that lacks them"` (line 106) all end with the same four `toContain` assertions for the fallback paths. Per the team's stated preference for parameterised tests, these cases could be collapsed into a single `it.each` that varies the mock setup (shell success / shell fail / cache hit) while sharing the assertion block, eliminating the duplication.
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Problem
Changes