Fix chrome extension bundled path resolution#8914
Conversation
| const tmp = path.join(process.cwd(), ".tmp-test-openclaw-state", String(Date.now())); | ||
|
|
||
| const sourceDir = path.resolve(process.cwd(), "assets/chrome-extension"); | ||
| const result = await installChromeExtension({ stateDir: tmp, sourceDir }); | ||
| const result = await installChromeExtension({ stateDir: tmp }); |
There was a problem hiding this comment.
[P1] Test writes to a non-unique, non-cleaned state directory
Using path.join(process.cwd(), ".tmp-test-openclaw-state", String(Date.now())) can collide in parallel test runs (same ms) and leaves artifacts in the repo if the test fails/succeeds. This makes CI flakier and can dirty local working trees. Prefer a unique temp dir via fs.mkdtempSync(os.tmpdir()) (or include PID + random) and clean it up in a finally block.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cli/browser-cli-extension.test.ts
Line: 11:13
Comment:
[P1] Test writes to a non-unique, non-cleaned state directory
Using `path.join(process.cwd(), ".tmp-test-openclaw-state", String(Date.now()))` can collide in parallel test runs (same ms) and leaves artifacts in the repo if the test fails/succeeds. This makes CI flakier and can dirty local working trees. Prefer a unique temp dir via `fs.mkdtempSync(os.tmpdir())` (or include PID + random) and clean it up in a `finally` block.
How can I resolve this? If you propose a fix, please make it concise.| expect(result.path).toContain(path.join("browser", "chrome-extension")); | ||
| expect(fs.existsSync(path.join(result.path, "manifest.json"))).toBe(true); |
There was a problem hiding this comment.
[P2] Assertion is weaker than needed for the intended regression
expect(result.path).toContain(path.join("browser", "chrome-extension")) will pass even if result.path points somewhere unexpected (e.g., a longer unrelated path containing that substring). Since installChromeExtension({ stateDir: tmp }) should deterministically install to path.join(tmp, "browser", "chrome-extension"), asserting exact equality would better lock in the behavior this test cares about.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cli/browser-cli-extension.test.ts
Line: 15:16
Comment:
[P2] Assertion is weaker than needed for the intended regression
`expect(result.path).toContain(path.join("browser", "chrome-extension"))` will pass even if `result.path` points somewhere unexpected (e.g., a longer unrelated path containing that substring). Since `installChromeExtension({ stateDir: tmp })` should deterministically install to `path.join(tmp, "browser", "chrome-extension")`, asserting exact equality would better lock in the behavior this test cares about.
How can I resolve this? If you propose a fix, please make it concise.
src/cli/browser-cli-extension.ts
Outdated
| // `dist/` lives at `<packageRoot>/dist` in npm installs. | ||
| // The bundled extension lives at `<packageRoot>/assets/chrome-extension`. | ||
| // So we need to go up ONE level from `dist`. | ||
| return path.resolve(here, "../assets/chrome-extension"); |
There was a problem hiding this comment.
[P3] Comment claims here is dist/, but it’s a file directory
here = path.dirname(fileURLToPath(import.meta.url)) resolves to the directory containing the compiled file (e.g., <packageRoot>/dist/cli), not <packageRoot>/dist. The ../assets/... path is likely still correct, but the comment is slightly misleading and could confuse future adjustments.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cli/browser-cli-extension.ts
Line: 18:21
Comment:
[P3] Comment claims `here` is `dist/`, but it’s a file directory
`here = path.dirname(fileURLToPath(import.meta.url))` resolves to the directory containing the compiled file (e.g., `<packageRoot>/dist/cli`), not `<packageRoot>/dist`. The `../assets/...` path is likely still correct, but the comment is slightly misleading and could confuse future adjustments.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d7c26010d5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
src/cli/browser-cli-extension.ts
Outdated
| function bundledExtensionRootDir() { | ||
| const here = path.dirname(fileURLToPath(import.meta.url)); | ||
| return path.resolve(here, "../../assets/chrome-extension"); | ||
|
|
||
| // `dist/` lives at `<packageRoot>/dist` in npm installs. | ||
| // The bundled extension lives at `<packageRoot>/assets/chrome-extension`. | ||
| // So we need to go up ONE level from `dist`. | ||
| return path.resolve(here, "../assets/chrome-extension"); | ||
| } |
There was a problem hiding this comment.
Restore source-tree bundled extension path fallback
The new path calculation only works when import.meta.url is inside dist/…, but in dev/test runs pnpm openclaw … executes the TypeScript from src/cli, so path.resolve(here, "../assets/chrome-extension") resolves to src/assets/chrome-extension (which doesn’t exist). That makes installChromeExtension() throw “Bundled Chrome extension is missing” for local development and tests that use the default path. Consider checking for ../assets and falling back to ../../assets when running from the source tree.
Useful? React with 👍 / 👎.
|
Landed via temp rebase onto main.\n\n- Gate: pnpm lint && pnpm build && pnpm test (fails: src/auto-reply/command-control.test.ts, src/agents/pi-tools.safe-bins.test.ts, src/agents/pi-tools.workspace-paths.test.ts, src/cli/program.smoke.test.ts, src/hooks/bundled/session-memory/handler.test.ts)\n- Land commit: 63ec16f\n- Merge commit: 1ee1522\n\nThanks @kelvinCB! |
Fixes
openclaw browser extension installfailing on global installs by resolving the bundled extension directory relative todist/(npm layout is<root>/dist, extension at<root>/assets/chrome-extension).bundledExtensionRootDir()to use../assets/chrome-extensionTests:
pnpm test src/cli/browser-cli-extension.test.tsGreptile Overview
Greptile Summary
This PR updates Chrome extension install logic to resolve the bundled extension directory relative to the compiled
dist/output (so global/npm installs can findassets/chrome-extension), and adjusts the unit test to exercise the default bundled-path install.The change fits into the CLI’s
browser extension installcommand by altering the internalbundledExtensionRootDir()used when nosourceDiroverride is provided, ensuring installs copy from the packaged assets into the user’s state directory.Confidence Score: 4/5
(2/5) Greptile learns from your feedback when you react with thumbs up/down!