fix: key fuse connections on pin labels (#754) - #782
Open
adityaaa-IIT-BHU wants to merge 1 commit into
Open
Conversation
fuseProps built its connections schema by hand with z.record(z.string(), ...), so any key passed validation — pin99, "not a pin at all", even "". Every other two-pin passive builds it from its own pin labels via createConnectionsProp, which keys the record on z.enum(labels). Use createConnectionsProp(fusePinLabels), and narrow the interface to Connections<FusePinLabels> to match capacitor and resistor. Fuse was also the only component in lib/components/ exporting both an interface and an Inferred* type without calling expectTypesMatch, which is why the schema and FuseProps were able to drift apart. Add the assertion so it can't happen again.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #754
Problem
fusePropsaccepted any string as aconnectionskey, so a typo'd pin name passed validation silently:{ "not a pin at all": ... }and{ "": ... }got through too. A fuse is a two-pin passive like a resistor or capacitor, so there's no reason for it to differ.Cause
Two related gaps in
lib/components/fuse.ts:It hand-rolled the schema as
z.record(z.string(), ...)instead of using the sharedcreateConnectionsProphelper, which keys the record onz.enum(labels)so unknown keys fail.fusePinLabelswas already defined and exported in the file — it just wasn't used here.Nothing checked the schema against the interface.
FusePropsdeclaredconnections?: Connections<PinLabel>while the schema producedRecord<string, ...>. Fuse was the only component inlib/components/that exported both an interface and anInferred*type without callingexpectTypesMatch, which is why the two were able to drift.Change
connections: createConnectionsProp(fusePinLabels).optional()Connections<FusePinLabels>, matchingcapacitor.tsandresistor.tsexpectTypesMatch<FuseProps, InferredFuseProps>(true)so this can't drift againThis is the idiom AGENTS.md already calls for: "Electrical connectivity should usually be
connectionskeyed by known pin labels."Adding the assertion to the unfixed file fails, confirming the drift was real:
Behaviour
connections{ pin1: "net.VCC", pin2: ["net.GND"] }{ pin99: "..." }{ "not a pin at all": "..." }{ "": "..." }undefinedundefined(unchanged)Valid fuse connections parse to exactly the same value as before, so no real circuit changes behaviour.
Generated docs were refreshed per AGENTS.md (
generate-component-types,generate-manual-edits-docs,generate-readme-docs,generate-props-overview); the only diffs are the fuse sections.Verification
bun test— 416 pass / 0 fail (was 412; +4 new tests intests/fuse.test.ts)bunx tsc --noEmit— clean (this is what exercises the newexpectTypesMatch)bun run format:check— cleangit diff --check— clean