Commit dff97a0
authored
Cover resource_path and all occurrences in workspace prefix rewrite (#5507)
## Why
Found during a full-repo review of the CLI. The `RewriteWorkspacePrefix`
mutator strips the legacy `/Workspace` prefix from strings that
reference `${workspace.*}` path variables, but it had three gaps:
1. `${workspace.resource_path}` was missing from the rewrite table even
though `PrependWorkspacePrefix` prefixes it, so a legacy
`/Workspace/${workspace.resource_path}` reference silently interpolated
to a doubled `/Workspace/Workspace/...` path.
2. It used `strings.Replace(..., 1)` and returned on the first match, so
only the first occurrence of the first matching pattern was fixed; any
further occurrences in the same string stayed broken.
3. Patterns were iterated in map order, so which pattern won (and which
warning was emitted) was nondeterministic when a string matched more
than one.
## Changes
Before, a string was rewritten once for one nondeterministically chosen
pattern and `resource_path` references were never rewritten; now every
occurrence of every known pattern, including `resource_path`, is
rewritten in a fixed order.
In `bundle/config/mutator/rewrite_workspace_prefix.go`:
- Added `/Workspace/${workspace.resource_path}` and
`/Workspace${workspace.resource_path}` to the rewrite table, matching
the path set handled by `PrependWorkspacePrefix`.
- Replaced the map with an ordered slice of pattern/replacement pairs so
rewrites and warnings are deterministic.
- Switched to `strings.ReplaceAll` and continue through all patterns
instead of returning after the first match. One warning is emitted per
matched pattern; strings with a single match produce exactly the same
warning as before.
## Test plan
- [x] Extended `TestNoWorkspacePrefixUsed` with `resource_path` cases
(both slash and no-slash variants), a multi-occurrence string, and a
string matching two different patterns; verified warnings and rewritten
values.
- [x] `go test ./bundle/config/mutator` passes.
- [x] `./task fmt-q`, `./task lint-q` (0 issues), and `./task checks`
pass.
This pull request and its description were written by Isaac.1 parent b0b9394 commit dff97a0
2 files changed
Lines changed: 71 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
36 | 45 | | |
37 | 46 | | |
38 | 47 | | |
| |||
44 | 53 | | |
45 | 54 | | |
46 | 55 | | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
60 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
61 | 74 | | |
62 | 75 | | |
63 | | - | |
| 76 | + | |
| 77 | + | |
64 | 78 | | |
65 | 79 | | |
66 | 80 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
55 | 75 | | |
56 | 76 | | |
57 | 77 | | |
| |||
61 | 81 | | |
62 | 82 | | |
63 | 83 | | |
64 | | - | |
| 84 | + | |
65 | 85 | | |
66 | 86 | | |
67 | | - | |
68 | | - | |
69 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
70 | 95 | | |
71 | 96 | | |
72 | 97 | | |
| |||
80 | 105 | | |
81 | 106 | | |
82 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
83 | 113 | | |
0 commit comments