fix(server): tolerate existing workspace dirs#978
Conversation
✅ Tests passed — 1233/1237
|
Greptile SummaryThis PR introduces a shared
Confidence Score: 4/5Safe to merge; the helper correctly narrows tolerance to genuine directory-already-exists cases and all call-sites are mechanical substitutions. The implementation is sound for its stated purpose. The only gaps are a missing test for the EEXIST-from-parent-but-target-is-new scenario and the fact that statExistingDirectory swallows the secondary error when rethrowing — both affect debuggability rather than correctness on any currently exercised path. The new ensure-directory.ts and its test file warrant a second look around the statExistingDirectory error-swallowing and the incomplete mock coverage for the Windows EEXIST edge case. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["ensureDirectory(path)"] --> B["mkdir(path, { recursive: true })"]
B --> C{Success?}
C -- yes --> D[Return — directory ready]
C -- "throws EEXIST" --> E{isAlreadyExistsError?}
E -- no --> F[Re-throw error]
E -- yes --> G["stat(path)"]
G --> H{stat succeeded?}
H -- "throws (e.g. ENOENT)" --> I[Re-throw original EEXIST]
H -- yes --> J{isDirectory?}
J -- no --> K[Re-throw original EEXIST]
J -- yes --> D
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
packages/browseros-agent/apps/server/tests/lib/ensure-directory.test.ts:33-56
**Missing test: EEXIST for brand-new target (stat throws ENOENT)**
The mocked `stat` always returns `isDirectory: true`, so the test only covers the case where the target directory already exists. It leaves unverified what happens when Windows/OneDrive throws EEXIST for an intermediate parent but the target itself doesn't exist yet — in that path, `stat(target)` throws `ENOENT`, `statExistingDirectory` catches it and rethrows the original EEXIST, and the directory is never created. Adding a test where `stat` throws would document this known limitation and prevent future maintainers from assuming `ensureDirectory` is a universal fix for all Windows EEXIST variants.
### Issue 2 of 2
packages/browseros-agent/apps/server/src/lib/ensure-directory.ts:36-39
**Swallowed stat error obscures root cause**
When `stat(path)` throws (e.g. `ENOENT` because the target doesn't exist), `statExistingDirectory` discards that error and rethrows the original `EEXIST` from `mkdir`. A caller or operator debugging a failed workspace-creation on Windows will see `EEXIST` with no signal that the real problem is `ENOENT` on the target. Augmenting the original error with a `cause` or a short message before rethrowing would make the failure much easier to diagnose without changing the externally visible error code.
Reviews (1): Last reviewed commit: "fix(server): tolerate existing workspace..." | Re-trigger Greptile |
88c8c20 to
7581d55
Compare
Summary
ensureDirectoryhelper that keeps recursive mkdir behavior but toleratesEEXISTwhen the requested target already exists as a directory.EEXISTparent-directory case.Fixes #974
Test plan
bun run typecheckfrompackages/browseros-agent/apps/serverbun --env-file=.env.development test ./tests/lib/ensure-directory.test.ts ./tests/lib/agents/acpx-runtime-context.test.ts ./tests/tools/filesystem/write.test.tsfrompackages/browseros-agent/apps/server