Commit 1f472eb
authored
feat(state): port gro to cli-common state components [MON-5371] (#134)
* feat(state): port gro to cli-common state components
Adopt cli-common/statedir for the config-dir resolver (native per OS:
$XDG_CONFIG_HOME→Linux, ~/Library/Application Support→macOS,
%APPDATA%→Windows; relative $XDG_CONFIG_HOME now errors per the §1.1
intentional tightening). Make SaveConfig atomic via os.CreateTemp +
rename at 0600 under a 0700 dir.
Add a macOS/Windows config-relocation gate (copy-leave-old; fail loud
on divergence; mutation-free runtime read-fallback via the new
LoadConfigForRuntime wrapper used by non-init callers). The gate runs
ahead of EnsureMigrated in `gro init` so divergent old/new can't be
silently papered over. Whole-dir copy excludes token.json (a secret);
the existing §1.8 token migrator gains the old-hand-rolled token path
as an additional legacy candidate with full conflict semantics
(equal→migrate+delete-both; divergent→fail loud).
Replace internal/cache with a thin wrapper over cli-common/cache:
atomic temp+rename envelope, version-mismatch-as-miss, hard-coded
per-resource TTL (§4.4). The pre-MON-5371 `cache_ttl_hours` config
field, `DefaultCacheTTLHours`, GetCacheTTL{,Hours}, the AskCacheTTL
prompt and `gro config cache {show,clear,ttl}` subcommand are removed
(older config.yml that still carries the field loads cleanly — yaml
ignores unknowns; clearing the cache folds into `gro config clear
--all`).
Switch internal/credtest to delegate state-dir isolation to
cli-common/statedirtest (full 7-var set) — closes a pre-existing
Windows real-dir leak (AppData/USERPROFILE/XDG_DATA_HOME were missing).
Tests that hand-built `<tmp>/xdgconfig/<DirName>/…` paths now resolve
via the resolver so they're correct on every OS.
§3.2 acceptance matrix coverage: 8 cases × 2 surfaces (config in
internal/config/relocate_test.go; cache in internal/cache/cache_test.go).
Init reconcile coverage: detect-runs-before-migrate, divergent-aborts-
mutates-nothing, copy-needed-triggers-apply.
Closes #131
[MON-5371]
* fix(state): address Codex PR review blockers + TDD gap
- relocate detector now treats `old/config.json` as a valid legacy source
(was YAML-only); LoadConfig falls back to old/config.json when new/yml
is absent. A pre-MON-5371 macOS/Windows user on the legacy JSON form is
no longer treated as a fresh install.
- configsMaterialEqual now compares `oauth_client_path` via
oauthClientPathEquiv: each-side-at-its-own-default → equal (location
artifact); explicit non-default divergence → fail loud.
- migrateLegacyCacheDir now probes both the new statedir LegacyCacheDir
and the old hand-rolled `<old>/google-readonly/cache/` (new export
config.OldHandRolledLegacyCacheDir). Dedupes on Linux.
- Replace the stubbed TestLoadConfigForRuntime_SoftConflict with two
real assertions (soft-conflict returns canonical+nil-err;
no-conflict pass-through) via a new testable seam.
- Add TestMigrateTokenFile_OldHandRolledPath and
TestMigrateTokenFile_OldAndNewDivergent for the new old-token
enumeration; covers §1.8 equal-migrate and divergent-fail-loud paths.
[MON-5371]
* fix(state): malformed old-only config fails loud before any copy
Codex caught: detectRelocation's oldPresent+!newPresent branch was
returning CopyNeeded=true without parsing the old file, so init's
ApplyConfigRelocation would carry a malformed YAML/JSON into the new
dir before LoadConfig later choked on it — that's a §3.2 row-5 (malformed
old) regression: the contract is fail loud, mutate nothing.
Parse the old file in the old-only branch and surface
ErrRelocationConflict ahead of any copy. Add
TestRelocate_OldOnlyMalformedYAML_FailLoud_MutatesNothing and
TestRelocate_OldOnlyMalformedJSON_FailLoud_MutatesNothing asserting
the new dir is not created and CopyNeeded is false.
[MON-5371]
* fix(state): address pr-review-daemon findings
- configsMaterialEqual now uses reflect.DeepEqual on the whole Keyring
sub-struct, not just Backend, so any future KeyringConfig field is
auto-covered as a divergence.
- LoadConfig skips the new-dir re-parse and legacy-JSON re-read when relErr
is already a detect-time ErrRelocationConflict (which includes the
malformed-new-wrapped-in-conflict case). The wrapped conflict error wins,
so LoadConfigForRuntime soft-degrades cleanly instead of hard-failing on
a bare parse error.
- Add cache_test subtest seeding a warm cache exclusively at the old
hand-rolled legacy cache subdir and asserting the dual-probe carry +
legacy-dir removal.
- Delete configExistedBefore plumbing (variable + threading through
tryExistingToken / finishExisting); the AskCacheTTL gate it guarded was
removed in this same PR so the suppressor was dead code.
[MON-5371]
* fix(state): daemon round 2 — real regression + nits
- LoadConfig: attempt new-dir read unconditionally so callers soft-degrading
via LoadConfigForRuntime get the user's actual settings (OAuthClientPath,
GrantedScopes, …) alongside ErrRelocationConflict instead of an empty
Config. The relErr-set branch still suppresses bare parse-error
propagation so the soft-degrade contract holds.
- oauthClientPathEquiv: ExpandPath both sides before comparing so tilde
vs fully-expanded forms don't false-positive as divergent.
- Cache.Clear: scope to <Root>/<InstanceKey> instead of the tool-level
Root so a future multi-instance Locator can't have one instance's Clear
evict the others.
[MON-5371]
* fix(state): malformed config under conflict hard-fails at runtime
Codex final-pass blocker: LoadConfig was suppressing canonical read
failures whenever relErr was set, returning all-defaults cfg + nil
through LoadConfigForRuntime. A malformed new config (under a
both-present detect-time conflict) would therefore silently warn-and-
default, swapping CredentialRef back to google-readonly/default for
non-init commands and masking the corrupt file.
LoadConfig now tracks whether a canonical config was actually read; if
relErr is set AND no read succeeded, return (nil, relErr) instead of
(empty cfg, relErr). LoadConfigForRuntime then only soft-degrades when
cfg is non-nil, so the runtime command hard-fails on a malformed
canonical config and the user sees the conflict instead of silent
default swap.
Added TestLoadConfigForRuntime_MalformedCanonicalUnderConflict_HardFails
pinning the new contract via the testable seam (which now mirrors the
real LoadConfig + LoadConfigForRuntime branching).
[MON-5371]1 parent 7eac0dc commit 1f472eb
23 files changed
Lines changed: 1615 additions & 969 deletions
File tree
- internal
- auth
- cache
- cmd
- config
- drive
- initcmd
- me
- config
- credtest
- keychain
- noleak
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
116 | | - | |
| 115 | + | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
2 | 10 | | |
3 | 11 | | |
4 | 12 | | |
5 | 13 | | |
| 14 | + | |
| 15 | + | |
6 | 16 | | |
7 | 17 | | |
8 | 18 | | |
9 | 19 | | |
| 20 | + | |
| 21 | + | |
10 | 22 | | |
11 | 23 | | |
12 | 24 | | |
13 | 25 | | |
14 | | - | |
15 | | - | |
16 | | - | |
| 26 | + | |
| 27 | + | |
17 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
18 | 38 | | |
19 | 39 | | |
20 | | - | |
| 40 | + | |
| 41 | + | |
21 | 42 | | |
22 | 43 | | |
23 | 44 | | |
24 | 45 | | |
25 | 46 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
| 47 | + | |
34 | 48 | | |
35 | | - | |
36 | | - | |
| 49 | + | |
37 | 50 | | |
38 | 51 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
44 | 57 | | |
45 | 58 | | |
46 | 59 | | |
47 | 60 | | |
48 | | - | |
49 | 61 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | 62 | | |
56 | | - | |
57 | | - | |
| 63 | + | |
58 | 64 | | |
59 | 65 | | |
60 | 66 | | |
61 | 67 | | |
62 | 68 | | |
63 | 69 | | |
64 | | - | |
65 | | - | |
66 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
67 | 75 | | |
68 | | - | |
69 | | - | |
70 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
71 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
72 | 99 | | |
73 | | - | |
| 100 | + | |
74 | 101 | | |
75 | 102 | | |
76 | 103 | | |
77 | | - | |
| 104 | + | |
78 | 105 | | |
79 | 106 | | |
80 | 107 | | |
81 | 108 | | |
82 | | - | |
83 | | - | |
| 109 | + | |
84 | 110 | | |
85 | 111 | | |
86 | | - | |
87 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
88 | 117 | | |
89 | 118 | | |
90 | 119 | | |
91 | 120 | | |
92 | | - | |
| 121 | + | |
93 | 122 | | |
94 | 123 | | |
95 | | - | |
| 124 | + | |
96 | 125 | | |
97 | | - | |
| 126 | + | |
98 | 127 | | |
99 | 128 | | |
100 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
101 | 133 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
115 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
116 | 145 | | |
117 | 146 | | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
| 147 | + | |
| 148 | + | |
122 | 149 | | |
123 | | - | |
124 | | - | |
| 150 | + | |
125 | 151 | | |
126 | 152 | | |
127 | | - | |
| 153 | + | |
128 | 154 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
| 155 | + | |
| 156 | + | |
138 | 157 | | |
139 | | - | |
140 | | - | |
141 | | - | |
| 158 | + | |
142 | 159 | | |
143 | 160 | | |
144 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
145 | 165 | | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
| 166 | + | |
191 | 167 | | |
192 | 168 | | |
193 | | - | |
| 169 | + | |
194 | 170 | | |
195 | | - | |
| 171 | + | |
196 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
0 commit comments