Skip to content

project_root_for's ancestor walk is still unbounded when the file's directory has no table and no project #189

Description

@mixelpixx

Follow-up to the fix in ec705c3 (from @Pytonballoon810's #188), which stops the search when the file's own directory carries a sym-lib-table or fp-lib-table. That covers the reproducible failure and the hermetic-fixture case. It does not bound the walk in general.

Residual

project_root_for (crates/konnect-core/src/tools/library.rs) still climbs ancestors without limit when the schematic's directory carries neither a library table nor a .kicad_pro:

~/Documents/Other.kicad_pro      <- unrelated project
~/Documents/work/foo.kicad_sch   <- no table, no project beside it

The walk leaves work/, finds Other.kicad_pro, and every library lookup for foo.kicad_sch then resolves ${KIPRJMOD} against ~/Documents. Silently — the caller gets the wrong library, not an error.

Narrower than the original bug, since a real project normally has its .kicad_pro beside or above its schematics, but the failure mode is the same and it is invisible when it happens.

Why it wasn't fixed in the hotfix

Bounding the walk is a design decision rather than a one-liner, and it landed as a patch on a release cut hours earlier. Options, none obviously right:

  • Stop at a VCS root (.git) — pragmatic, but couples library resolution to source control.
  • Depth limit — arbitrary, and wrong for a deeply nested sheet hierarchy.
  • Never cross above the user's home directory — helps the common case, does nothing for a shared parent inside it.
  • Require an explicit project argument when resolution is ambiguous, and report the ambiguity — the most honest, the most disruptive.

Acceptance

  • A schematic with no table and no project beside it, nested under an unrelated .kicad_pro, does not silently resolve against that project.
  • Whatever bound is chosen is stated in the doc comment, with the reasoning.
  • A deep sheet hierarchy (<proj>/sheets/sub/x.kicad_sch) still resolves at the project root — that is a_sheet_in_a_subdirectory_resolves_against_the_project_table.
  • If ambiguity is reported rather than guessed, it is a structured error naming both candidate roots.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P0Correctness or data-safety: fix before the next releasearea:platformInstall, discovery, OS and KiCad-version compatibilityclaimedSomeone has claimed this; check the assignee before starting

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions