Repository navigation
Commit d23346c
authored
refactor(cli): derive the common flag readers from the common-field table (#2292)
* refactor(cli): derive the common flag readers from the common-field table
commonInputFromFlags and selectionOptionsFromFlags in
src/commands/cli-grammar/common.ts each hand-restated the common input
key list as object literals. A key added to the common-field table in
commands/common-input-fields.ts (the schema/read/clientKey/audience
source of truth) had no structural link to either flag reader, so
keeping a new key flowing through the CLI depended on remembering to
touch both literals by hand (the failure mode #1304/#1305 hit for
--no-record).
Add a flagKey/flagIn column to CommonInputFieldSpec: flagKey names the
CliFlags property when its spelling differs from the row (only
deviceTarget, which reads flags.target), and flagIn lists which of the
two flag-derived projections ('input', 'selection') the row joins.
commonFlagProjection(flags, projection) walks the table once and
reuses the existing clientKey renaming (deviceTarget -> target) for
the 'selection' projection, matching commonToClientOptions's existing
convention. commonInputFromFlags and selectionOptionsFromFlags become
thin wrappers over that projection; COMMON_COMMAND_SUPPORTED_FLAG_KEYS
in flag-groups.ts is untouched, per its own documented reason for
staying separate.
Added src/commands/cli-grammar/common.test.ts as a characterization
test before touching the implementation: it feeds a CliFlags fixture
with every common flag set, and one with none set, and asserts the
literal objects both functions return. It passed unmodified against
both the old hand-written implementation and the new table-derived
one, proving the projections are byte-identical.
Validation: pnpm vitest run --project unit-core src/commands (575
tests, all green); pnpm check:quick (lint + typecheck) clean;
pnpm check:layering clean (cli-grammar/common.ts importing
commands/common-input-fields.ts is an intra-commands-zone import, not
core/daemon reaching into commands, so R2 commands-floor does not
apply).
* fix(cli): require a typed flagKey wherever a common row joins flagIn
Reviewer findings on the common-flag-reader refactor (9074367):
- P2: commonFlagProjection cast flags to Record<string, unknown> and
fell back to `field.flagKey ?? key`, so a row could declare
`flagIn` with a key that is not a CliFlags property at all (cwd,
debug) and compile cleanly while reading undefined forever.
CommonInputFieldSpec now requires `flagKey: keyof CliFlags`
whenever a row declares `flagIn`; the cast and fallback are gone
and commonFlagProjection reads `flags[field.flagKey]` directly.
Verified red/green: temporarily adding `flagKey: 'cwd'` made tsc
reject the table; reverted after confirming.
- P2: comments in common.ts and common-input-fields.ts claimed the
table made a dropped common key "impossible" / that flagIn "rides
structurally". A new common row that omits flagIn still silently
joins neither projection, uncaught by any compiler check -- the
flagKey fix narrows the failure mode, it doesn't close it. Reworded
both comments to say what the table actually guarantees.
- P3: common.test.ts's ALL_COMMON_FLAGS fixture left daemonBaseUrl,
daemonAuthToken, tenant, runId, and leaseId unset, so a row wrongly
gaining `flagIn: ['input']` for one of them would still pass --
compactRecord drops the unset value either way. Added
NON_PROJECTED_COMMON_FLAGS with concrete values for those keys so
such a row now surfaces as an extra key. Verified red/green:
temporarily adding `flagIn: ['input']` to daemonBaseUrl failed the
test; reverted after confirming.
- P3: flag-groups.ts's comment said the common-input-fields table
declares only envFlagKeys; it now also declares flagKey/flagIn.
Amended to name both columns.
Deferred one P3 (selectionOptionsFromFlags's cast to SelectionOptions)
with a note in .tmp/common-readers-pr-body.md -- fixing it would
import cli-grammar/types.ts back into common-input-fields.ts, reversing
the documented one-way dependency for a cast the characterization test
already pins.
No layering, fallow, or gate-manifest surface touched, so no separate
chore(gates) commit.
Checks: pnpm vitest run --project unit-core src/commands (575 tests,
green) and pnpm check:quick (lint + typecheck), both clean.1 parent 09c1cae commit d23346c
4 files changed
Lines changed: 213 additions & 59 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
59 | 80 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
| 81 | + | |
87 | 82 | | |
88 | 83 | | |
89 | 84 | | |
| |||
101 | 96 | | |
102 | 97 | | |
103 | 98 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
111 | 106 | | |
112 | 107 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
| 108 | + | |
123 | 109 | | |
124 | 110 | | |
125 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
58 | 61 | | |
59 | 62 | | |
60 | 63 | | |
| |||
0 commit comments