fix(desktop): unbreak safe-url test on bun by splitting pure helpers#3659
Conversation
`safe-url.ts` imports `shell` from electron at the module top level, so bun's test runner can't load the file and the whole suite fails with `SyntaxError: Export named 'shell' not found`. Moves the pure URL helpers (`isSafeExternalUrl`, `externalUrlLogLabel`) to `scheme.ts` and has the test import from there. `safeOpenExternal` stays in `safe-url.ts` with the electron import; the barrel keeps the same public surface.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe safe-url module is reorganized by extracting scheme validation and logging functions into a dedicated file. Two functions ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR fixes a CI breakage in the desktop test job caused by The fix cleanly separates concerns:
The change is minimal, surgical, and does not alter any runtime behaviour. Confidence Score: 5/5Safe to merge — pure refactor with no behaviour change and a clean public-API surface. The helper logic is moved verbatim (no edits), the barrel preserves all three exports, and the only test that exercises these functions now correctly imports from the electron-free module. There are no logic changes, no new dependencies, and no risk to callers. No files require special attention.
|
| Filename | Overview |
|---|---|
| apps/desktop/src/main/lib/safe-url/scheme.ts | New file containing pure URL helpers moved verbatim from safe-url.ts; no Electron dependency, fully testable in bun CI. |
| apps/desktop/src/main/lib/safe-url/safe-url.ts | Stripped of pure helpers; now only holds safeOpenExternal (which legitimately needs electron) and imports helpers from scheme.ts. |
| apps/desktop/src/main/lib/safe-url/index.ts | Barrel updated to re-export from both safe-url.ts and scheme.ts; public API unchanged. |
| apps/desktop/src/main/lib/safe-url/safe-url.test.ts | Import path updated from ./safe-url to ./scheme so bun can load the test without pulling in the Electron module. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["index.ts (barrel)"] -->|"re-exports safeOpenExternal"| B["safe-url.ts\n(needs electron)"]
A -->|"re-exports isSafeExternalUrl\nexternalUrlLogLabel"| C["scheme.ts\n(pure helpers, no electron)"]
B -->|"imports helpers from"| C
D["safe-url.test.ts\n(bun CI)"] -->|"imports directly from"| C
B --> E["electron shell.openExternal"]
Reviews (1): Last reviewed commit: "fix(desktop): unbreak safe-url test on b..." | Re-trigger Greptile
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
Summary
apps/desktop/src/main/lib/safe-url/safe-url.tsimportsshellfromelectronat the module top level, so bun's test runner (CI) fails loading the module withSyntaxError: Export named 'shell' not found in module '.../electron/index.js'. This broke the desktop test job on main after fix(desktop): allowlist URL schemes before shell.openExternal #3650 merged (see run 24802754721).isSafeExternalUrl,externalUrlLogLabel) intoscheme.ts. They have no electron dependency and are what the test actually exercises.safeOpenExternalstays insafe-url.tswith the electron import; it imports the pure helpers fromscheme.ts. Thesafe-url/index.tsbarrel keeps the same three exports, so no callers need to change../schemeso loading it doesn't pull electron.Test plan
bun test src/main/lib/safe-url/— 5 pass locallybun run typecheckin apps/desktopbun run lint apps/desktopSummary by cubic
Fixes Bun test failures in desktop by splitting pure URL helpers from Electron code in safe-url. Tests now import the pure module to avoid loading
electron, while the public API stays the same.isSafeExternalUrlandexternalUrlLogLabeltoscheme.ts(noelectron).safeOpenExternalinsafe-url.tsand reused the helpers.scheme; tests import./scheme.Written for commit 4330533. Summary will update on new commits.
Summary by CodeRabbit