Commit c78f36a
authored
refactor: typed event payload structs + roundtrip tests (PR F of cleanup) (#192)
* refactor: typed event payload structs + roundtrip tests (PR F of cleanup)
Server-only refactor; no SDK or proto changes.
Promotes the projector decoder Raw structs to exported payload
structs in a shared internal/eventtypes/payloads/ package. Handler
emit sites now construct typed structs instead of map[string]any
literals. Catches handler/projector schema drift at compile time
— exactly the bug class behind issue #135's partial-write hazard.
One enabler change: store.Event.Data type is broadened from
map[string]any to any so call sites can pass typed structs.
AppendEvent's existing JSON marshal accepts any JSON-marshalable
value; legacy map-literal call sites continue to compile unchanged.
Files created:
- internal/eventtypes/payloads/{user,device,action,assignment,
execution,lps_password,luks_key}.go — 36 typed payload structs
across 7 stream types
- internal/eventtypes/payloads/doc.go — package docs
- internal/eventtypes/payloads/payloads_test.go — 32 roundtrip
tests (one per payload), each marshal → unmarshal → assert.Equal
Files modified:
- internal/store/store.go — Event.Data: any
- internal/projectors/{user,device,action,assignment,execution,
lps_password,luks_key}.go — decoders use payloads.X structs
- ~30 handler emit sites converted to typed payloads:
- internal/api/user_handler.go — 11 sites
- internal/api/device_handler.go — 6 sites
- internal/api/registration_handler.go — DeviceRegistered
- internal/api/certificate_handler.go — DeviceCertRenewed
- internal/api/system_actions.go — AssignmentCreated +
UserSystemActionLinked
- internal/control/inbox_worker.go — 5 execution sites +
introduced commandOutputPayload helper
Deferred to PR G (final tech-debt audit): ~50 emit sites still
use map[string]any. They continue to work because Event.Data is
now any, but they don't get the compile-time schema-drift
guarantee. Mechanical follow-up: add payload structs in remaining
files (action.go, internal_handler.go, idp/sso/auth handlers,
SCIM, role/group handlers, settings, totp, terminal, compliance)
and update emit sites.
Note: lps_password and luks_key payload structs preserve the
masked LogValue() method from the projector originals so neither
password nor passphrase can leak into slog output.
Part of the 2026.06 cleanup-release sweep. PR G (final audit)
follows.
* test: redaction + RawCommandOutput contract tests (CR catches on PR #192)
Three nitpick test additions from CR review:
- TestLpsPasswordRotated_LogValueMasksPassword: locks the
security guarantee — routing the payload through slog (e.g.
slog.Warn("...", "payload", payload)) must NEVER emit the raw
Password value. Asserts both 'NotContains(secret)' and
'Contains([REDACTED])'.
- TestLuksKeyRotated_LogValueMasksPassphrase: sibling for LUKS.
- TestRawCommandOutput_NilOmitted +
TestRawCommandOutput_ProducesObject: locks the wire contract
used by ExecutionTerminal / ExecutionTimedOut. Nil input
produces nil so omitempty fires; non-nil input produces a
JSON object (NOT a quoted string), with the exact legacy keys
(stdout, stderr, exit_code), and round-trips cleanly through
ExecutionTerminal.
* test: assert exact legacy key count + omitempty parent contract (CR catches on PR #192)
Two more nitpick test tightenings from CR review:
- TestRoundtrip_CommandOutput + TestRawCommandOutput_ProducesObject:
added assert.Len(asMap, 3) so an extra key (regression where a
new field gets added to CommandOutput) would fail the test.
- TestRawCommandOutput_NilOmitted: added end-to-end omitempty
contract assertion via ExecutionTerminal — marshal a payload
with Output: RawCommandOutput(nil) and assert the wire JSON
does NOT contain the 'output' key. Without this the helper
could regress to []byte('null') and we'd only catch it via
downstream projector failures.1 parent 6630773 commit c78f36a
23 files changed
Lines changed: 1321 additions & 431 deletions
File tree
- internal
- api
- control
- eventtypes/payloads
- projectors
- store
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
| 86 | + | |
| 87 | + | |
85 | 88 | | |
86 | 89 | | |
87 | 90 | | |
88 | 91 | | |
89 | | - | |
90 | | - | |
91 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
92 | 95 | | |
93 | 96 | | |
94 | 97 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
215 | 216 | | |
216 | 217 | | |
217 | 218 | | |
218 | | - | |
219 | | - | |
220 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
221 | 222 | | |
222 | 223 | | |
223 | 224 | | |
| |||
260 | 261 | | |
261 | 262 | | |
262 | 263 | | |
263 | | - | |
264 | | - | |
| 264 | + | |
| 265 | + | |
265 | 266 | | |
266 | 267 | | |
267 | 268 | | |
| |||
375 | 376 | | |
376 | 377 | | |
377 | 378 | | |
| 379 | + | |
378 | 380 | | |
379 | 381 | | |
380 | 382 | | |
381 | 383 | | |
382 | | - | |
383 | | - | |
| 384 | + | |
| 385 | + | |
384 | 386 | | |
385 | 387 | | |
386 | 388 | | |
| |||
403 | 405 | | |
404 | 406 | | |
405 | 407 | | |
| 408 | + | |
406 | 409 | | |
407 | 410 | | |
408 | 411 | | |
409 | 412 | | |
410 | | - | |
411 | | - | |
| 413 | + | |
| 414 | + | |
412 | 415 | | |
413 | 416 | | |
414 | 417 | | |
| |||
480 | 483 | | |
481 | 484 | | |
482 | 485 | | |
483 | | - | |
484 | | - | |
| 486 | + | |
| 487 | + | |
485 | 488 | | |
486 | 489 | | |
487 | 490 | | |
| |||
494 | 497 | | |
495 | 498 | | |
496 | 499 | | |
497 | | - | |
498 | | - | |
| 500 | + | |
| 501 | + | |
499 | 502 | | |
500 | 503 | | |
501 | 504 | | |
| |||
533 | 536 | | |
534 | 537 | | |
535 | 538 | | |
| 539 | + | |
536 | 540 | | |
537 | 541 | | |
538 | 542 | | |
539 | 543 | | |
540 | | - | |
541 | | - | |
| 544 | + | |
| 545 | + | |
542 | 546 | | |
543 | 547 | | |
544 | 548 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
193 | 194 | | |
194 | 195 | | |
195 | 196 | | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
205 | 220 | | |
206 | 221 | | |
207 | 222 | | |
208 | 223 | | |
209 | | - | |
210 | | - | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
211 | 227 | | |
212 | 228 | | |
213 | 229 | | |
| |||
238 | 254 | | |
239 | 255 | | |
240 | 256 | | |
241 | | - | |
| 257 | + | |
242 | 258 | | |
243 | 259 | | |
244 | 260 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
529 | 530 | | |
530 | 531 | | |
531 | 532 | | |
532 | | - | |
| 533 | + | |
| 534 | + | |
533 | 535 | | |
534 | 536 | | |
535 | 537 | | |
536 | 538 | | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
544 | 546 | | |
545 | 547 | | |
546 | 548 | | |
| |||
586 | 588 | | |
587 | 589 | | |
588 | 590 | | |
589 | | - | |
590 | | - | |
591 | | - | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
592 | 594 | | |
593 | 595 | | |
594 | 596 | | |
| |||
0 commit comments