#22348: fix(tests): pass localRoots to media test fixtures (#22191)
channel: whatsapp-web
size: XS
Cluster:
Media File Management Fixes
## Summary
Fixes #22191 -- `src/web/media.test.ts` fails on CI with `LocalMediaAccessError` because test fixtures in `/tmp` are blocked by the default allowed-roots policy.
## Problem
After recent path-hardening changes to `loadWebMedia`, local file access is restricted to explicitly allowed directories by default. The 7 affected tests write image fixtures to a temp directory but call `loadWebMedia(file, cap)` without passing `localRoots`, so the path guard rejects them:
```
LocalMediaAccessError: Local media path is not under an allowed directory:
/tmp/openclaw-media-test-xIlyyu/media-1.png
```
## Fix
Pass `{ localRoots: [fixtureRoot] }` to each of the 7 `loadWebMedia` calls that load from the temp fixture directory. This explicitly allows the test fixture path without weakening production restrictions.
**Tests fixed (all in `src/web/media.test.ts`):**
- `strips MEDIA: prefix before reading local file`
- `compresses large local images under the provided cap`
- `optimizes images when options object omits optimizeImages`
- `allows callers to disable optimization via options object`
- `sniffs mime before extension when loading local files`
- `preserves PNG alpha when under the cap`
- `falls back to JPEG when PNG alpha cannot fit under cap`
## Verification
```bash
npx vitest run src/web/media.test.ts
# 24 tests passed (24)
```
The existing `local media root guard` tests (which explicitly test the `localRoots` mechanism) are untouched and continue to pass.
Most Similar PRs
#22356: test(web): fix media test fixture local root handling
by AIflow-Labs · 2026-02-21
84.6%
#17456: fix(test): stabilize media root guard test against tmpdir HOME overlap
by widingmarcus-cyber · 2026-02-15
79.4%
#22178: test(web): allow fixture roots in media local file tests
by Kansodata · 2026-02-20
78.3%
#21935: fix: handle symlinked media roots in local media checks
by ShunsukeHayashi · 2026-02-20
76.0%
#9817: fix(media): resolve relative paths before reading local files (#8759)
by lailoo · 2026-02-05
73.2%
#22401: fix: resolve relative media paths against workspace and fix /tmp on...
by derrickburns · 2026-02-21
72.1%
#18811: fix(media): require file extension for ambiguous MEDIA: path detection
by aldoeliacim · 2026-02-17
68.5%
#23627: fix(telegram,feishu): pass mediaLocalRoots through channel action a...
by rockkoca · 2026-02-22
68.4%
#17944: fix(security): fail-closed for local media paths without sandboxRoot
by Operative-001 · 2026-02-16
68.2%
#23148: fix: forward mediaLocalRoots in whatsapp plugin sendMedia
by MunemHashmi · 2026-02-22
66.1%