From 24137e5b3f361cfdf13965af8663f90e92bfc1a4 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Mon, 11 May 2026 23:57:13 -0600 Subject: [PATCH] fix: preserve alphanumeric chip pin labels --- lib/getReadableNameForPin.ts | 5 +++- .../test4-chip-pin-labels-regression.test.tsx | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tests/test4-chip-pin-labels-regression.test.tsx diff --git a/lib/getReadableNameForPin.ts b/lib/getReadableNameForPin.ts index cf05e35..c6e99c5 100644 --- a/lib/getReadableNameForPin.ts +++ b/lib/getReadableNameForPin.ts @@ -46,8 +46,11 @@ export const getReadableNameForPin = ({ for (const port_hint of port.port_hints ?? []) { if (port_hint === mainPinName) continue + const isGenericPinLabel = /^pin\d+$/i.test(port_hint) + const hasSemanticAlphaNumericLabel = + /[A-Za-z]/.test(port_hint) && /\d/.test(port_hint) && !isGenericPinLabel const score = scorePhrase(port_hint) - if (score > 1) { + if (score > 1 || hasSemanticAlphaNumericLabel) { additionalPinLabels.push(port_hint) } } diff --git a/tests/test4-chip-pin-labels-regression.test.tsx b/tests/test4-chip-pin-labels-regression.test.tsx new file mode 100644 index 0000000..b819955 --- /dev/null +++ b/tests/test4-chip-pin-labels-regression.test.tsx @@ -0,0 +1,25 @@ +import { expect, it } from "bun:test" +import { getReadableNameForPin } from "lib/getReadableNameForPin" + +it("preserves semantic chip pin labels that include digits when the port name is generic", () => { + const circuitJson = [ + { + type: "source_component", + source_component_id: "source_component_0", + name: "U1", + ftype: "simple_chip", + }, + { + type: "source_port", + source_port_id: "source_port_0", + source_component_id: "source_component_0", + name: "pin14", + pin_number: 14, + port_hints: ["pin14", "GPIO17", "ADC1"], + }, + ] as any + + expect( + getReadableNameForPin({ circuitJson, source_port_id: "source_port_0" }), + ).toBe("U1 pin14 (GPIO17,ADC1)") +}) -- 2.43.0