#17456: fix(test): stabilize media root guard test against tmpdir HOME overlap
channel: whatsapp-web
stale
size: XS
trusted-contributor
Cluster:
Media File Management Fixes
## fix(test): stabilize media root guard test
### Problem
The test `rejects default OpenClaw state per-agent workspace-* roots without explicit local roots` in `src/web/media.test.ts` **fails on every CI run** (bun + node), including on `main`.
### Root Cause
The test harness sets `HOME` to a temp directory under `os.tmpdir()`:
```
HOME=/tmp/openclaw-test-home-xC06Jb
```
Since `os.tmpdir()` (`/tmp`) is a default allowed media root, **all paths** under the test's `HOME` directory match the tmpdir root:
```
testPath: /tmp/openclaw-test-home-xC06Jb/.openclaw-guard-reject-test/workspace-clawdy/tmp/render.bin
root /tmp → MATCH (startsWith /tmp/)
```
The test expects a rejection but gets a successful resolve because the path is "allowed" via tmpdir.
### Fix
Pin `OPENCLAW_STATE_DIR` to `/var/openclaw-guard-reject-test` (outside `/tmp`) for the duration of the test. This is the same pattern used in `be9b5cefb` for the `web media loading` describe block, which was missing from the separate `local media root guard` describe block.
### Changed Files
| File | Change |
|------|--------|
| `src/web/media.test.ts` | Pin OPENCLAW_STATE_DIR in the failing test |
### Testing
- All 22 media tests pass (previously 21 pass / 1 fail)
- This fixes the CI failure visible on `main` and all open PRs
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixed a flaky test that was failing in CI by preventing `HOME` directory overlap with `os.tmpdir()`. The test `rejects default OpenClaw state per-agent workspace-* roots without explicit local roots` was incorrectly passing because the test harness sets `HOME` under `/tmp`, which is a default allowed media root. The fix pins `OPENCLAW_STATE_DIR` to `/var/openclaw-guard-reject-test` (outside `/tmp`) for the duration of the test, ensuring the path doesn't match any default allowed roots. This follows the same pattern used in the `web media loading` describe block and properly restores the environment variable in the finally block.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with no identified risks
- The change is a focused test stabilization fix that properly isolates the test environment. It uses the correct cleanup pattern with try-finally to restore the environment variable, follows the existing pattern from another test block in the same file, and addresses a real CI failure without changing any production code.
- No files require special attention
<sub>Last reviewed commit: ebbcfe6</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#22356: test(web): fix media test fixture local root handling
by AIflow-Labs · 2026-02-21
86.7%
#22178: test(web): allow fixture roots in media local file tests
by Kansodata · 2026-02-20
82.0%
#22348: fix(tests): pass localRoots to media test fixtures (#22191)
by VikrantSingh01 · 2026-02-21
79.4%
#23085: fix(workspace): respect OPENCLAW_STATE_DIR for workspace paths, fix...
by charojo · 2026-02-22
76.9%
#22401: fix: resolve relative media paths against workspace and fix /tmp on...
by derrickburns · 2026-02-21
76.7%
#18811: fix(media): require file extension for ambiguous MEDIA: path detection
by aldoeliacim · 2026-02-17
76.3%
#9817: fix(media): resolve relative paths before reading local files (#8759)
by lailoo · 2026-02-05
76.1%
#22910: fix(browser): resolve symlinks in upload path validation
by erdinccurebal · 2026-02-21
75.7%
#23308: fix(browser): accept upload paths that traverse symlinked tmp dirs
by SidQin-cyber · 2026-02-22
75.6%
#23139: test: fix flaky auth tests when OPENCLAW_GATEWAY_TOKEN is present
by Imccccc · 2026-02-22
75.4%