Skip to content

fix(kicad): resolve subdirectory, cwd-relative, and file:// local 3D models in export and build - #5959

Open
tranhoangtu-it wants to merge 1 commit into
tscircuit:mainfrom
tranhoangtu-it:fix/kicad-3d-model-local-resolution
Open

tranhoangtu-it wants to merge 1 commit into
tscircuit:mainfrom
tranhoangtu-it:fix/kicad-3d-model-local-resolution

Conversation

@tranhoangtu-it

Copy link
Copy Markdown
Contributor

Problem

  • generateKicadProject (tsci build --kicad-project / --kicad-project-zip) called fs.promises.readFile(modelPath) directly from process.cwd(), which failed for file:// model URLs and for relative 3D model paths located relative to the circuit directory when building a circuit from a parent directory.
  • exportSnippet (case "kicad_zip") only called fs.promises.readFile(path.resolve(projectDir, modelPath)), failing for file:// URLs and for cwd-relative static asset URLs (e.g. ./subdir/model.step when exporting subdir/board.tsx from the repository root).

Fix

  • Add readLocalKicad3dModel (lib/shared/read-local-kicad-3d-model.ts) to resolve file:// URLs via fileURLToPath, absolute filesystem paths directly, and relative paths by searching deduplicated [...baseDirs, process.cwd()] directories with fallback to baseDirs[0] ?? process.cwd().
  • Pass baseDirs: [path.dirname(filePath), projectDir] from cli/build/register.ts through generateKicadProject (cli/build/generate-kicad-project.ts), and baseDirs: [projectDir] from exportSnippet (lib/shared/export-snippet.ts, case "kicad_zip").
  • Add unit and CLI integration tests in tests/shared/read-local-kicad-3d-model.test.ts and tests/cli/export/export-kicad-zip-subdir-3d-models.test.ts.

Verification

  • bun test tests/shared/read-local-kicad-3d-model.test.ts tests/cli/export/export-kicad-zip-subdir-3d-models.test.ts tests/cli/export/export-kicad-zip-user-3d-models.test.ts (4 pass, 0 fail)
  • bunx tsc --noEmit (exit 0)
  • bun scripts/check-for-dependencies.ts (exit 0)
  • bunx biome format on all 6 touched/new files (0 fixes needed) & bunx biome check on lib/shared/read-local-kicad-3d-model.ts, cli/build/generate-kicad-project.ts, tests/shared/read-local-kicad-3d-model.test.ts, and tests/cli/export/export-kicad-zip-subdir-3d-models.test.ts (exit 0)

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-12-01T18:29:26.088383Z
We couldn’t complete this review. Comment @codex review to try again.
a212785 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

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.

1 participant