validation: declare the four codes RULES was missing, and check the surface against the source (#1654) #1662

Merged
jaylouisw merged 1 commit from fix/1116-1205 into main 2026-11-16 12:30:21 +00:00
Owner

Fixes #1654.

What was wrong. test/property-validator.test.js asserted that every code connect() returns is in validation.RULES, but RULES is only validation.js's own table. E_BIDI_MISMATCH comes from media.js/optical.js, so a legitimate refusal was reported as an unknown code. The E_PORT_IN_USE exemption beside that check was the same bug, already papered over once. main went red at seed 65 because #1647's five new device specs re-rolled the seeded draw onto the BiDi pairing — the engine did not regress, the assertion was always too narrow. It passes again today only because #1657 re-rolled the draw a second time; the next device spec would move it back.

Also found while fixing it. Four codes were emitted by validation.js with no RULES entry, so the UI had nothing to render and their severity came from the W_ prefix fallback: E_OPTICAL_BUDGET, W_OPTICAL_HEADROOM, E_LINK_UNCHECKABLE, E_NOT_A_TOPOLOGY. Declared now (24 -> 28).

Changes

  • engine/validation.js: the four missing RULES entries, with descriptions.
  • test/validation.test.js: scans engine/validation.js for every code: '...' it emits; fails on an undocumented code, on a RULES entry nothing emits, and on a severity that contradicts the W_/E_ prefix.
  • test/property-validator.test.js: the connect() surface is RULES plus the codes declared by the modules validateLink delegates to (media.js, optical.js); the E_PORT_IN_USE exemption is gone; malformed codes are rejected; and E_BIDI_MISMATCH being on the surface is asserted deterministically instead of waiting for seed 65.
  • docs/CONNECTORS.md: the two missing table rows, and the paragraph no longer claims three codes are outside RULES.

Gates

  • node --test test/validation.test.js — 22 passed, 0 failed
  • node --test test/property-validator.test.js — 20 passed, 0 failed
  • npm test — 278 suites, 9913 assertions, 0 failed
  • node scripts/syntax-check.js — 348 files, all OK
  • Reverting only the engine half makes the new validation.test.js assertion fail, naming exactly those four codes.
Fixes #1654. **What was wrong.** `test/property-validator.test.js` asserted that every code `connect()` returns is in `validation.RULES`, but `RULES` is only `validation.js`'s own table. `E_BIDI_MISMATCH` comes from `media.js`/`optical.js`, so a legitimate refusal was reported as an unknown code. The `E_PORT_IN_USE` exemption beside that check was the same bug, already papered over once. main went red at seed 65 because #1647's five new device specs re-rolled the seeded draw onto the BiDi pairing — the engine did not regress, the assertion was always too narrow. It passes again today only because #1657 re-rolled the draw a second time; the next device spec would move it back. **Also found while fixing it.** Four codes were emitted by `validation.js` with no `RULES` entry, so the UI had nothing to render and their severity came from the `W_` prefix fallback: `E_OPTICAL_BUDGET`, `W_OPTICAL_HEADROOM`, `E_LINK_UNCHECKABLE`, `E_NOT_A_TOPOLOGY`. Declared now (24 -> 28). **Changes** - `engine/validation.js`: the four missing `RULES` entries, with descriptions. - `test/validation.test.js`: scans `engine/validation.js` for every `code: '...'` it emits; fails on an undocumented code, on a `RULES` entry nothing emits, and on a severity that contradicts the `W_`/`E_` prefix. - `test/property-validator.test.js`: the connect() surface is `RULES` plus the codes declared by the modules `validateLink` delegates to (`media.js`, `optical.js`); the `E_PORT_IN_USE` exemption is gone; malformed codes are rejected; and `E_BIDI_MISMATCH` being on the surface is asserted deterministically instead of waiting for seed 65. - `docs/CONNECTORS.md`: the two missing table rows, and the paragraph no longer claims three codes are outside `RULES`. **Gates** - `node --test test/validation.test.js` — 22 passed, 0 failed - `node --test test/property-validator.test.js` — 20 passed, 0 failed - `npm test` — 278 suites, 9913 assertions, 0 failed - `node scripts/syntax-check.js` — 348 files, all OK - Reverting only the engine half makes the new `validation.test.js` assertion fail, naming exactly those four codes.
validation: declare the four codes RULES was missing, and check the surface against the source (#1654)
All checks were successful
CI / Classify the change (pull_request) Successful in 11s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 14s
CI / Test (Node 18) (pull_request) Has been skipped
CI / Test (Node 20) (pull_request) Has been skipped
CI / Test (Node 22) (pull_request) Has been skipped
CI / Server smoke test (pull_request) Has been skipped
CI / Docker build (pull_request) Has been skipped
33f8b43351
main went red at seed 65 because test/property-validator.test.js asserted every
code connect() returns is in validation.RULES - and RULES is only validation.js's
own table of 24 rules. E_BIDI_MISMATCH is raised by media.js/optical.js, so a
legitimate refusal was reported as an unknown code. The E_PORT_IN_USE exemption
next to it was the same bug, papered over once already. Nothing about the engine
regressed: #1647 added five device specs, re-rolled the seeded draw, and the
lottery landed on the BiDi pairing.

Four codes were also emitted by validation.js without a RULES entry at all, so
the UI had nothing to render for them and their severity came from the W_ prefix
fallback: E_OPTICAL_BUDGET, W_OPTICAL_HEADROOM, E_LINK_UNCHECKABLE and
E_NOT_A_TOPOLOGY. They are declared now (24 -> 28 entries).

Both directions are now checked by reading the source rather than by luck:

* test/validation.test.js scans engine/validation.js for every `code: '...'` it
  emits and fails on a code missing from RULES, on a RULES entry nothing emits,
  and on a severity that contradicts the code's W_/E_ prefix.
* test/property-validator.test.js builds the connect() surface as RULES plus the
  codes declared by the modules validateLink delegates to (media.js, optical.js),
  drops the hand-written E_PORT_IN_USE exemption, rejects a malformed code, and
  asserts E_BIDI_MISMATCH is on the surface - deterministically, not at seed 65.

docs/CONNECTORS.md gains the two missing rows and no longer claims three codes
are outside RULES.

Verified: node --test test/validation.test.js 22/22, test/property-validator.js
20/20, full npm test 278 suites / 9913 assertions / 0 failed, syntax-check 348
files OK. Without the engine half, the new validation.test.js assertion fails
naming exactly those four codes.

Fixes #1654
Co-authored-by: Hermes Agent <jay@jayw.uk>
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-16 12:30:08 +00:00
jaylouisw force-pushed fix/1116-1205 from 33f8b43351
All checks were successful
CI / Classify the change (pull_request) Successful in 11s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 14s
CI / Test (Node 18) (pull_request) Has been skipped
CI / Test (Node 20) (pull_request) Has been skipped
CI / Test (Node 22) (pull_request) Has been skipped
CI / Server smoke test (pull_request) Has been skipped
CI / Docker build (pull_request) Has been skipped
to 2b221f6f93
All checks were successful
CI / Classify the change (pull_request) Successful in 13s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 15s
CI / Test (Node 18) (pull_request) Has been skipped
CI / Test (Node 20) (pull_request) Has been skipped
CI / Test (Node 22) (pull_request) Has been skipped
CI / Server smoke test (pull_request) Has been skipped
CI / Docker build (pull_request) Has been skipped
2026-11-16 12:30:11 +00:00
Compare
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jaylouisw/packetforge!1662
No description provided.