fix(schematic): stop the symbol writer corrupting KiCad 8/9 files - #351
fix(schematic): stop the symbol writer corrupting KiCad 8/9 files#351Rotario wants to merge 1 commit into
Conversation
Placing a symbol made any KiCad 8 or KiCad 9 schematic unloadable, including this repo's own minimal/empty/template_with_symbols templates (all declare 20250114). Every failure surfaced only as a bare "Failed to load schematic" from eeschema and kicad-cli, naming neither token nor line. Three defects in the shared writer: - create_component_instance emitted the KiCad 10-only (body_style 1) and (in_pos_files yes) attributes unconditionally. KiCad dispatches to a parser per declared format version, so a v10 token inside a 20231120 or 20250114 file is refused - by a KiCad 10 binary too. Both are now gated on the target file's own (version ...); a file with no version token keeps v10 output. - Property values were interpolated unescaped. Stock library descriptions embed double quotes - power:GND is 'Power symbol creates a global label with name "GND" , ground' - so the first inner quote closed the token early and the rest of the block became garbage. Parentheses still balanced and sexpdata still parsed the result, which is why this stayed silent; only KiCad objected. Values now go through escape_sexpr_string. - add_schematic_component dropped its documented angle and mirrorY arguments: the TS layer nests them inside `component` (src/tools/schematic.ts) and the Python handler never read them back out, so symbols always landed at 0deg and callers had to follow up with rotate_schematic_component. Adds tests/test_schematic_writer_format_compat.py (24 tests; 17 fail before this change), including an integration test asserting real kicad-cli accepts the generated v8 and v9 files. test_symbol_instance_completeness.py asserted the v10 attributes while placing into the v9 empty.kicad_sch; it now uses a v10 fixture for those two tokens.
|
Reviewed in full — the version-token corruption you found is real and I want this fix. Verified on current main: create_component_instance unconditionally emits the KiCad-10-only tokens (body_style 1) and (in_pos_files yes), and four of the five templates this repo ships are version 20250114 (v9), so placing a symbol into a project started from any of them produces a file KiCad 8/9 refuses with a bare 'Failed to load schematic'. Your _supports_kicad10_symbol_tokens gate (>= 20260101, unknown -> v10) is the right shape, and the 24-test suite including a real kicad-cli round-trip is exactly the evidence standard this repo wants. Three asks before merge, all subtraction rather than addition:
The version-gating work with its test suite is the unique, high-value content here and it stands alone once the two duplicated hunks are gone. |
Hiya, I've been using claude to work with PCBs and doing some edits came up with some potential issues with the MCP server?
Here's claude's summary:
Placing a symbol made any KiCad 8 or KiCad 9 schematic unloadable, including this repo's own minimal/empty/template_with_symbols templates (all declare 20250114). Every failure surfaced only as a bare "Failed to load schematic" from eeschema and kicad-cli, naming neither token nor line.
Three defects in the shared writer:
create_component_instance emitted the KiCad 10-only (body_style 1) and (in_pos_files yes) attributes unconditionally. KiCad dispatches to a parser per declared format version, so a v10 token inside a 20231120 or 20250114 file is refused - by a KiCad 10 binary too. Both are now gated on the target file's own (version ...); a file with no version token keeps v10 output.
Property values were interpolated unescaped. Stock library descriptions embed double quotes - power:GND is 'Power symbol creates a global label with name "GND" , ground' - so the first inner quote closed the token early and the rest of the block became garbage. Parentheses still balanced and sexpdata still parsed the result, which is why this stayed silent; only KiCad objected. Values now go through escape_sexpr_string.
add_schematic_component dropped its documented angle and mirrorY arguments: the TS layer nests them inside
component(src/tools/schematic.ts) and the Python handler never read them back out, so symbols always landed at 0deg and callers had to follow up with rotate_schematic_component.Adds tests/test_schematic_writer_format_compat.py (24 tests; 17 fail before this change), including an integration test asserting real kicad-cli accepts the generated v8 and v9 files. test_symbol_instance_completeness.py asserted the v10 attributes while placing into the v9 empty.kicad_sch; it now uses a v10 fixture for those two tokens.