refactor(engine): lag.js is TypeScript, and the latent require it was holding is gone #2504
No reviewers
Labels
No labels
blocked-on-build
bug
device
device-request
enhancement
from-github
needs-datasheet
needs-info
needs-triage
ready-for-agent
ready-for-human
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jaylouisw/packetforge!2504
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "migrate/lag"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
engine/lag.jsbecomesengine/lag.ts(542 → 710 lines). Every parameter, every return and everyexported value is typed, and the shapes its three jobs share are written as interfaces.
This is migration row three in
docs/TYPESCRIPT.md, and it was chosen because it is the one modulea converted file already required:
engine/segment.tssaidrequire('./lag')without an extensionbecause
lag.jswas JavaScript. That line was correct, and dead the day this file was renamed — in afile no conversion edited, for a reason nobody would connect to the diff.
node scripts/check-module-paths.tsexisted to name it, and named it:Converting lag retires that hazard rather than creating another. After this branch:
— the
segment.tsnote is gone (asserted bytest/check-module-paths.test.ts, which computes thelatent case from the tree: "engine/segment.ts no longer requires a still-JavaScript ./lag; nothing
latent to report"). What the guard prints now is
engine/lag.ts:131 require('./iface-name') -> engine/iface-name.js, which resolves today: the samedebt one link further out, reported as a note rather than failed, and paid the day
iface-nameisconverted.
The types
LagConfignormalizeLag()returns and what everything downstream is handedMemberPort/KnownMembervalidateLag()is asked to check — every field but the name isunknown, because a saved lab supplies itLagProblem/LagVerdict{code, message}rows inerrorsandwarningsMemberSuspensionengine/segment.tsinstead of restated thereNegotiationVerdictTwo values on the boundary are genuinely unknown and are narrowed, not asserted (there is no
asin the file):
isObject()andstringified field by field, so a frame with no L3 header still lands somewhere;
Device.lagFor()answers with —engine/device.jsis still JavaScript, sogroupMode()reads itsmodeand stringifies it exactly the waycanonicalMode()always did,rather than inventing a new refusal for a group whose mode is missing.
memberList()(anArray.isArraynarrowing with a declaredreadonly unknown[]return) andisObject()(aRecord<string, unknown>type predicate) are the two guards the rest of the filenarrows through; the
{ name, enabled }member records the fixtures pass are the sameunknownshape, narrowed by the
memberName()/memberEnabled()rules that were already there.Importers swept
Every one names the extension now — CommonJS does not invent a
.tsfrom an extensionless relativerequire (trap 5 of
docs/TYPESCRIPT.md):engine/cli.js— 7 call sitesengine/device.js,engine/index.js,engine/simulator.js— 1 eachengine/segment.ts:118— the latent one, nowrequire('./lag.ts'), and its localMemberSuspensioncopy is replaced byimport type { MemberSuspension } from './lag'test/—lag,lag-mode,lag-member-down,etherchannel-member-limit,channel-group-creating-receipt,brief-port-channel-row,port-channel-name-refusalBehaviour
Identical. The LAG suites pass before and after with the same counts:
Gates
npx tsc --noEmit— cleannode scripts/check-no-any.ts—0 occurrences in 0 files (9 scanned)node scripts/syntax-check.js—558 files (549 JavaScript, 9 TypeScript): all OKnode scripts/check-module-paths.ts— 0 unresolvable, the segment.ts latent note gonenode test/check-module-paths.test.ts— 29 passednode test/canonical-urls.test.js— 88 passed, tree left clean (git statusempty)Left alone
The ledger row is the only
docs/TYPESCRIPT.mdchange beyond the prose paragraph in Migrated sofar; the gate table belongs to the branch that is editing it.
docs/CLI.md,docs/SIMULATION.md,docs/UPSTREAM-DESIGN.md,docs/LINK-STATE.mdanddocs/PHYSICAL_LAYER.mdstill citeengine/lag.js:NNNin prose — the same waydocs/UPSTREAM-DESIGN.mdstill citeslink.js:NNNafterrow two — and that citation sweep is a docs change, not this conversion.
`engine/lag.js` becomes `engine/lag.ts` (542 -> 710 lines): every parameter, every return and every exported value is typed, and the shapes its three jobs share are written as interfaces - `LagConfig` (what `normalizeLag()` returns), `MemberPort` / `KnownMember` (what `validateLag()` is asked to check), `LagProblem` / `LagVerdict` (its answer), `MemberSuspension`, and a `NegotiationVerdict` that is a discriminated union rather than a boolean beside a maybe-string: a pair that bundles has no reason to give, and a pair that does not always has one. This is the module a converted file already required. `engine/segment.ts` said `require('./lag')` without an extension because `lag.js` was JavaScript - correct, and dead the moment this file was renamed, in a file no conversion edited, for a reason nobody would connect to the diff. That is the whole reason this module was next, and the conversion retires the hazard instead of inheriting it: `engine/segment.ts` names `./lag.ts` and imports `MemberSuspension` from the module rather than restating it, so the shape cannot drift from the function that returns it. Two values on that boundary are genuinely unknown and are narrowed rather than asserted: - the frame a hash is taken from - a document's own frame record, read through `isObject()` and stringified field by field, so a frame with no L3 header still lands somewhere; - the channel group `Device.lagFor()` answers with - `engine/device.js` is still JavaScript, so `groupMode()` reads its `mode` and stringifies it exactly the way `canonicalMode()` always did, instead of turning a group into a refusal this module has no business inventing. No `any`, no `as`, no `@ts-nocheck`: `node scripts/check-no-any.ts` passes on the file, and `tsc --noEmit` is clean. Every importer spells the extension, because CommonJS does not resolve a `.ts` from an extensionless relative require (trap 5 of docs/TYPESCRIPT.md): - `engine/cli.js` 7 call sites - `engine/device.js` 1 - `engine/index.js` 1 - `engine/simulator.js` 1 - `engine/segment.ts` 1 - the latent one, now `require('./lag.ts')` - `test/lag.test.js`, `test/lag-mode.test.js`, `test/lag-member-down.test.js`, `test/etherchannel-member-limit.test.js`, `test/channel-group-creating-receipt.test.js`, `test/brief-port-channel-row.test.js`, `test/port-channel-name-refusal.test.js` - 7 suites `node scripts/check-module-paths.ts` no longer prints the latent note it existed to print for this line. What it prints now is `engine/lag.ts:131 require('./iface-name') -> engine/iface-name.js`, which resolves today: the same debt one link further out, reported rather than failed, and paid the day `iface-name` is converted. Behaviour is unchanged. The LAG suites pass before and after, with identical counts: lag 57, lag-mode 54, lag-member-down 34, lag-member-checks 8, etherchannel-member-limit 45, channel-group-creating-receipt 22, channel-group-undo-grammar 20, brief-port-channel-row 19, port-channel-name-refusal 37, etherchannel-summary-layout 37, show-etherchannel-group-summary 25, show-etherchannel-views 43, stp-port-channel-cost 10, stp-port-channel-name 16, mac-table-port-channel-name 12, vlan-brief-etherchannel 13 (452 assertions); `check-module-paths` 29, canonical-urls 88, `git status` empty after the run.Whole tree, not just the LAG suites: all 476 suites pass, 0 failed (
node scripts/run-tests.js,run in two halves to fit a terminal budget — the first 258 suites and the remaining 218, both with
every line a
✓and nofailedanywhere in either log).The four gates on the final head:
The line this PR exists for —
engine/segment.ts:118 require('./lag')— is not in that output anymore, and
test/check-module-paths.test.tssays so in words: "engine/segment.ts no longer requiresa still-JavaScript ./lag; nothing latent to report".
git statusis empty after every run.engine/lag.ts, at the line the symbol is on #2509