Skip to content

test(backend): pin both seat-field filters on the machine heartbeat (TASK-067) - #1763

Merged
lilyshen0722 merged 1 commit into
mainfrom
kai/machine-seat-field-whitelist
Sep 19, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
kai/machine-seat-field-whitelist

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

What

Two tests pinning the two independent filters that keep machine.agentStates
at four fields. A daemon reports ten seat fields
(cli/src/lib/daemon-supervisor.js:73-85 agentStates()); the server stores four.

filter where test
1 the rebuild — no spread of the reported entry normalizeAgentStates, machineService.ts:28-47 keeps only the four stored seat fields …
2 Mongoose's default strict, against the declared subdoc Machine.ts:41-50 (four paths, no strict option) drops undeclared seat paths at the schema too …

Each filter alone holds the stored shape at four fields, so either one can be
weakened without the suite noticing
— that is the gap, and it is why there are
two tests rather than one.

  • Filter 1 feeds the real ten-field payload to the pure function.
  • Filter 2 writes the same entry straight through the model, bypassing
    normalizeAgentStates entirely, then reads the raw collection
    (mongoose.connection.collection('machines')) and asserts four keys.

Honest limit

Asserting filter 1 higher up does not work: with the schema in place, a spread in
normalizeAgentStates is invisible at recordMachineHeartbeat and at
serializeMachine (the view is rebuilt field by field), so a throwaway test at
those surfaces passed under the mutation. The pure function is the only place
filter 1 can be checked — and the corollary is that neither test protects against
a live leak today; they are tripwires for the plausible sequence (spread here,
then widen the schema).

Verification

  • cd backend && npx jest __tests__/unit/services/machineService → 7 passed
  • Two mutations, run independently, each reddening exactly one test:
    • ...e added to the object normalizeAgentStates returns → only filter 1
      fails
      , filter 2 and the other five stay green.
    • strict: false added to Machine.ts's schema options → only filter 2
      fails
      , filter 1 and the other five stay green.
      Both reverted.
  • Eslint: the file carries pre-existing errors from the un-gated .js corpus
    (the burn-down in CLAUDE.md); the added lines introduce none.

Scope

backend/__tests__/ only — tests-only, and the version guard watches $pkg/src
for cli and commonly-mcp, so no version bump.

@samxu01
samxu01 force-pushed the kai/machine-seat-field-whitelist branch from ab9b989 to 75af59d Compare September 18, 2026 20:23
@lilyshen0722 lilyshen0722 changed the title test(backend): pin the seat-field whitelist on the machine heartbeat (TASK-067) test(backend): pin both seat-field filters on the machine heartbeat (TASK-067) Sep 18, 2026
@lilyshen0722
lilyshen0722 force-pushed the kai/machine-seat-field-whitelist branch from 75af59d to 8e105a3 Compare September 19, 2026 16:22
@lilyshen0722
lilyshen0722 merged commit 7a21cf6 into main Sep 19, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant