Commit 4688e4c
fix(filebrowser): require agent_name when subdomain is false (#877)
## Description
Fixes
[REG-4](https://linear.app/codercom/issue/REG-4/filebrowser-appends-workspace-path-twice-in-url):
the `filebrowser` module opens to a non-existent URL with the workspace
path appended a second time when `subdomain = false` and `agent_name` is
not provided, e.g.:
```
https://<coder-host>/@<owner>/<workspace>/apps/filebrowser/files/@<owner>/<workspace>.<agent>/apps/filebrowser/
```
### Root cause
Coder's frontend always builds path-based app URLs as
`/@<owner>/<workspace>.<agent>/apps/<slug>/` (it always includes
`.<agent_name>`, even for single-agent templates):
https://github.com/coder/coder/blob/main/site/src/modules/apps/apps.ts
```ts
return `${path}/@${workspace.owner_name}/${workspace.name}.${agent.name}/apps/${app.slug}/`;
```
The filebrowser module, however, only includes the agent segment in
`local.server_base_path` (which becomes filebrowser's `--baseURL`) when
the user explicitly passes `agent_name`. The variable description and
the README both said `agent_name` was "only required if the template
uses multiple agents", which is incorrect.
When the URLs disagree, filebrowser's reverse-proxy `stripPrefix` cannot
strip the prefix, the path falls through filebrowser's `/:catchAll(.*)*`
Vue route, and the router redirects to `/files/${catchAll}` — producing
the duplicated path the user reported.
### Fix
- Add a `lifecycle.precondition` on `coder_script.filebrowser` that
fails `terraform apply` with a clear, actionable error when `subdomain =
false` and `agent_name == null`.
- Update the `agent_name` variable description to state it is required
whenever `subdomain` is `false`.
- Update the `README.md` example for the path-based config to call out
the requirement explicitly.
- Bump the module version from `1.1.4` → `1.1.5`.
- Add a TS test covering the new precondition.
This avoids the silent misconfiguration that produces the duplicated
URL, without breaking anyone whose existing template already sets
`agent_name` (or uses `subdomain = true`).
## Type of Change
- [ ] New module
- [ ] New template
- [x] Bug fix
- [ ] Feature/enhancement
- [ ] Documentation
- [ ] Other
## Module Information
**Path:** `registry/coder/modules/filebrowser`
**New version:** `v1.1.5`
**Breaking change:** [ ] Yes [x] No
## Testing & Validation
- [x] `bun test main.test.ts` — 8 pass, 0 fail (includes new
precondition test)
- [x] `terraform fmt -recursive`
- [x] `terraform validate`
- [x] `bun x prettier --check`
- [x] Manually verified the precondition fires with a minimal repro and
passes when `agent_name` is supplied or `subdomain = true`.
## Related Issues
- Linear:
[REG-4](https://linear.app/codercom/issue/REG-4/filebrowser-appends-workspace-path-twice-in-url)
---
Created on behalf of @matifali.
Generated with Blink.
Co-authored-by: blink-so[bot] <211532188+blink-so[bot]@users.noreply.github.com>
Co-authored-by: DevCats <christofer@coder.com>1 parent 4d96be0 commit 4688e4c
3 files changed
Lines changed: 29 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
| 53 | + | |
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
56 | | - | |
| 58 | + | |
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
105 | 120 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
105 | 112 | | |
106 | 113 | | |
107 | 114 | | |
| |||
0 commit comments