Open History to see the last commit
1import { readFileSync } from "node:fs";
2import { describe, expect, it } from "vitest";
3import { compileBlueprint } from "../src/shared/blueprint";
4import { designSchema } from "../src/shared/design";
5import {
6 fitFailureMessage,
7 fitRepairFeedback,
8 fitScore,
9} from "../src/shared/design-repair";
10const lookout = designSchema.parse(
11 JSON.parse(
12 readFileSync(
13 new URL("./fixtures/ai-lookout-fit-errors.json", import.meta.url),
14 "utf8",
15 ),
16 ),
17);
18describe("AI fit feedback", () => {
19 it("maps repeated and assembled pieces back to source rows in the source coordinate frame", () => {
20 for (const front of ["+z", "-z", "+x", "-x"] as const) {
21 const design = { ...lookout, front };
22 const feedback = fitRepairFeedback(compileBlueprint(design), design);
23 expect(feedback).toContain(
24 '"id":"leftLowF_0","row":"leftLowF","x":[-4,-2],"y":[15,18],"z":[3,4]',
25 );
26 expect(feedback).toContain('"id":"step6","row":"step6"');
27 expect(feedback).toContain("stair landings");
28 expect(feedback).toContain("split repeat rows");
29 }
30 });
31 it("compares the full issue count beyond the thirty displayed examples", () => {
32 const crowded = {
33 ...lookout,
34 pieces: Array.from({ length: 40 }, (_, i) => ({
35 ...lookout.pieces[0],
36 id: `base${i}`,
37 repeat: null,
38 })),
39 };
40 const compiled = compileBlueprint(crowded);
41 expect(compiled.issues).toHaveLength(30);
42 expect(compiled.issueCounts.overlap).toBe(39);
43 expect(fitScore(compiled)).toBe(156);
44 });
45 it("explains the fit failure without blaming the prompt or losing validation detail", () => {
46 const message = fitFailureMessage(compileBlueprint(lookout));
47 expect(message).toContain(
48 "12 overlapping piece pairs and 3 pieces without support",
49 );
50 expect(message).toContain("Your model is unchanged");
51 expect(message).not.toContain("simpler");
52 expect(fitFailureMessage()).toContain("incomplete design");
53 });
54});