Skip to content

fix(schematic): report the pins on a net from get_net_connections - #854

Open
drakeo338 wants to merge 2 commits into
mixelpixx:mainfrom
drakeo338:claude/853-fix
Open

drakeo338 wants to merge 2 commits into
mixelpixx:mainfrom
drakeo338:claude/853-fix

Conversation

@drakeo338

Copy link
Copy Markdown
Contributor

Summary

Fixes #853.

get_net_connections is documented as returning a net's pins and labels but only built labels and a connected_points count. It now returns every placed pin on the net as {reference, pin, x, y}, as get_net_components does.

Approach

The handler never collected pins; it now resolves the net's points once and matches pin endpoints against them.

Architectural fit

Extends the existing sch_analysis tool; no workaround.

Branch and dependencies

Base: main. No dependencies.

Compatibility and safety

Additive pins field on a read-only tool.

Validation

Changed tool behavior

Behavior Contract and evidence for this change
Accepted inputs and declared defaults Not changed
Invalid/unsupported inputs and structured errors Not changed
Target, data source and prerequisite state Net resolved from the schematic file
Observed changes and preserved unrelated objects Read-only; adds pins
Failure before/after mutation, including applied work Read-only
Recovery from partial/uncertain results without repeating applied work N/A

Regression test: 0 passed, 1 failed on base; 2 passed, 0 failed with the fix. Boxes below not ticked were not run on the final head.

  • cargo fmt --all -- --check
  • cargo test --workspace --locked --lib --tests (what CI runs)
  • cargo test --workspace --locked --doc
  • cargo clippy --workspace --locked --all-targets -- -D warnings
  • Relevant viewer, plugin, packaging, and real-KiCad checks

Review checklist

  • The diff is focused and contains no generated output, personal data, or unrelated cleanup.
  • The branch includes current upstream/main, has no merge conflicts, and CI passed on this exact head.
  • For a fork PR, maintainer edits are enabled, or the author accepts
    responsibility for the final current-main refresh.
  • The branch was based on latest upstream/main, not a release tag (unless this is an approved backport).
  • The PR shows only its unique commits and diff; dependencies and series position are explicit.
  • Every review conversation is resolved; any post-review push or base refresh
    has been reviewed on the new exact head. An unchanged unique diff may use a
    focused refresh review; changed behavior received substantive re-review.
  • New names follow docs/NAMING_CONVENTIONS.md; public renames include compatibility handling.
  • New behavior and failure paths have regression coverage.
  • File mutations are atomic and preserve unrelated content.
  • IPC mutations verify the requested board; atomic/partial behavior and safe recovery are explicit under the reliability contract.
  • If tools were added/removed: counts and docs updated per CONTRIBUTING.md (registry tool_count, tool-directory.md, DEV.md stats, README count).

Maintainer merge state

  • The PR has exactly one current status:* workflow label.
  • status:ready-to-merge applies to this exact head SHA.
  • The completed review is recorded; only stale automatic CODEOWNERS requests
    were cleared under the review-request workflow (manual requests remain open).
  • All required checks and review conversations satisfy the main ruleset.
  • Merge authorization is established: standing authorization applies to a
    @mixelpixx/@neusse PR, or explicit authorization names this exact head.
  • Auto-merge uses a merge commit, or an already-green PR will be merged with gh pr merge N --merge.
  • Terminal issue closure and the next PR to promote are identified.

…xelpixx#853)

The tool is described as returning a net's pins and labels but built only
the labels and a connected_points count. Resolve the net's points once and
report every placed pin whose endpoint sits on them as
{reference, pin, x, y}, as get_net_components already does.
@drakeo338
drakeo338 requested a review from mixelpixx as a code owner October 7, 2026 12:27
@pauliuszaleckas

Copy link
Copy Markdown
Contributor

Thanks for picking this up. I checked head 325c91a against KiCad 10's netlist, and there are three things I think need changing before it closes #853:

1. Power symbols come back as pins. On the test's own fixture:

get_net_connections {"net":"GND"}
→ "pins":[{"reference":"R1","pin":"2",...},{"reference":"#PWR01","pin":"1",...}]

kicad-cli sch export netlist puts only R1.2 on GND. Power symbols name a net, but KiCad doesn't count them as nodes on it. (get_net_components has the same problem through the same loop, but pins is a new field, so it can match KiCad from day one.)

2. The test can't fail on a wrong answer. It only checks that R1 pin 2 is somewhere in pins. As a control I replaced the on_net.contains(...) filter with a check that's always true, so every pin on the sheet gets reported. Then cargo test --workspace --lib --tests --no-fail-fast had 0 failures. Could the test compare the exact pin set from kicad-cli sch export netlist, including a pin that must not appear? It would also help to cover the case from the issue: a net joined only through a pair of labels, with the fixture built by KiCad itself rather than written by hand.

3. Labels are still picked by name. matching still filters on l.net == net. On a net with two names (a +3V3 power symbol plus a VCC label), labels then lists only the labels with the requested name, while pins and connected_points cover the whole net. #853 asks for labels to be picked by root_at. If that's out of scope here, please say so in the body so Closes #853 doesn't close that part unaddressed.

Smaller points:

  • If a symbol's library entry can't be found, placed_pins_by_reference skips it, so pins silently comes back short. resolved_placed_pins_by_reference lets the tool refuse instead.
  • Adding a response field needs a docs/API_MIGRATIONS.md entry.
  • get_net_components reports each pin's name. Should pins include it too?

…xx#853)

Review on mixelpixx#854 found three gaps against `kicad-cli sch export netlist`:

- Power symbols and PWR_FLAGs came back in `pins`. They name a net but
  are not nodes on it, so they are left out, as the netlist does.
- `labels` was still picked by name, so a net with two names listed only
  the labels spelling the one asked for while `pins` and
  `connected_points` covered the whole net. Labels are now every label
  on the net's roots, each carrying the `net` it spells.
- A symbol with no library entry was skipped, so `pins` came back short
  without saying so. The tool now refuses through
  resolved_placed_pins_by_reference.

Each pin also carries its `name`, as get_net_components reports it.

The tests now compare exact pin sets with KiCad's own netlist of the
KiCad-saved two_name_nets fixture, including a net joined only by a pair
of labels, a net asked for by an alias, and pins that must not appear.
@drakeo338

Copy link
Copy Markdown
Contributor Author

Pushed ea823dd: get_net_connections now leaves power symbols out of pins, picks labels by net root (each label carries its net), refuses when a symbol library entry is missing, and adds a pin name; tests compare exact pin sets.

@pauliuszaleckas

Copy link
Copy Markdown
Contributor

Thanks. I re-checked head ea823dd2dfad2d89d892d70aa0f66764050a089b, and all three points from my last comment are fixed.

Oracle. For every net in both fixtures, I compared get_net_connections with kicad-cli sch export netlist. This includes names the tests don't ask for:

Asked as pins KiCad netlist labels
+3V3 / VCC / ALT C1.1 C2.1 TP1.1 TP7.1 U1.8 +3V3: same 5 for every name
GND / RETURN C1.2 C2.2 C3.2 U1.4 RETURN: same 5 for both names
SDA R1.2 U1.5 /SDA: same 2
SCL R2.2 U1.6 /SCL: same 2
SYS C3.1 R1.1 R2.1 TP6.1 SYS: same 3
AAA TP2.1 TP3.1 /AAA: same 3
MIX TP4.1 /MIX: same 2
power_rail GND / SIG R1.2 / R1.1 same 1 / 1

None of them includes a #PWR symbol.

Controls. I neutered each guard and ran cargo test --workspace --lib --tests --no-fail-fast. The baseline had 0 failures.

Control Failures
Power-symbol filter → true 3
Labels picked by name again (l.net == net) 1
on_net.contains(...) → true (my earlier control, which failed nothing) 4
resolved_placed_pins_by_reference → Some(placed_pins_by_reference(..)) 1

Smaller points:

  • The PR body still describes the first commit. In the changed-behavior table, the errors row says "Not changed", but a schematic with a missing library entry is now refused. The resulting-state row lists only pins, not the new label set or the net field on each label. The validation section also predates this head, and the body has no controls table.
  • net_connections_refuse_a_symbol_with_no_library_entry asserts only is_error, so any error passes it. Checking that the message says the pin geometry is unresolved would tie the test to this refusal.
  • This one is pre-existing and not for this PR. An unknown name (NOPE) and KiCad's own spelling (/SDA) both answer as an empty net, with no error. A caller can't tell a typo from a net that has no pins. I can file it separately if that's useful.

pauliuszaleckas pushed a commit to pauliuszaleckas/Konnect that referenced this pull request Oct 9, 2026
…xx#853)

Review on mixelpixx#854 found three gaps against `kicad-cli sch export netlist`:

- Power symbols and PWR_FLAGs came back in `pins`. They name a net but
  are not nodes on it, so they are left out, as the netlist does.
- `labels` was still picked by name, so a net with two names listed only
  the labels spelling the one asked for while `pins` and
  `connected_points` covered the whole net. Labels are now every label
  on the net's roots, each carrying the `net` it spells.
- A symbol with no library entry was skipped, so `pins` came back short
  without saying so. The tool now refuses through
  resolved_placed_pins_by_reference.

Each pin also carries its `name`, as get_net_components reports it.

The tests now compare exact pin sets with KiCad's own netlist of the
KiCad-saved two_name_nets fixture, including a net joined only by a pair
of labels, a net asked for by an alias, and pins that must not appear.
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.

get_net_connections says it returns a net's pins, but reports only labels

2 participants