import { test, expect } from "bun:test" import { circuitJsonToStep } from "../../../lib/index" import { importStepWithOcct } from "../../utils/occt/importer" import { loadStepFilesFromCircuitJson } from "../../utils/load-step-files" import circuitJson from "./basics06.json" test("basics06: skip mesh generation when all components have model_step_url", async () => { // Load STEP files from local fixtures const fsMap = await loadStepFilesFromCircuitJson(circuitJson) // This should NOT throw "Failed to generate component meshes" error // because all cad_components have model_step_url and mesh generation should be skipped const stepText = await circuitJsonToStep(circuitJson as any, { includeComponents: true, includeExternalMeshes: true, productName: "TestPCB_SkipMeshGen", fsMap, }) // Verify STEP format expect(stepText).toContain("ISO-10303-21") expect(stepText).toContain("END-ISO-10303-21") // Verify product structure expect(stepText).toContain("TestPCB_SkipMeshGen") expect(stepText).toContain("MANIFOLD_SOLID_BREP") // Verify holes are created expect(stepText).toContain("CIRCLE") expect(stepText).toContain("CYLINDRICAL_SURFACE") // Should have multiple solids: board + 2 external STEP components const solidCount = (stepText.match(/MANIFOLD_SOLID_BREP/g) || []).length expect(solidCount).toBeGreaterThanOrEqual(3) // Write STEP file to debug-output const outputPath = "debug-output/basics06.step" await Bun.write(outputPath, stepText) console.log("✓ STEP file with external models generated successfully") console.log(` - Solids created: ${solidCount}`) console.log(` - STEP text length: ${stepText.length} bytes`) console.log(` - Output: ${outputPath}`) console.log( "✓ Mesh generation was correctly skipped (no components needed fallback)", ) // Validate STEP file can be imported with occt-import-js const occtResult = await importStepWithOcct(stepText) expect(occtResult.success).toBe(true) expect(occtResult.meshes.length).toBeGreaterThan(0) const [firstMesh] = occtResult.meshes expect(firstMesh.attributes.position.array.length).toBeGreaterThan(0) expect(firstMesh.index.array.length).toBeGreaterThan(0) console.log("✓ STEP file successfully validated with occt-import-js") await expect(stepText).toMatchStepSnapshot(import.meta.path, "basics06") }, 30000)