|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | +import { readFileSync } from "fs"; |
| 3 | +import { dirname, resolve } from "path"; |
| 4 | +import { fileURLToPath } from "url"; |
| 5 | +import { parseNodeSections, findNodeSection, listNodeTypes } from "./node-reference.js"; |
| 6 | + |
| 7 | +const __dirname = dirname(fileURLToPath(import.meta.url)); |
| 8 | + |
| 9 | +// Load the real llms.txt (copied alongside the compiled output or at repo root during dev) |
| 10 | +let LLMS_TXT: string; |
| 11 | +try { |
| 12 | + // Running from dist/ (after build): llms.txt is one level up |
| 13 | + LLMS_TXT = readFileSync(resolve(__dirname, "../llms.txt"), "utf-8"); |
| 14 | +} catch { |
| 15 | + // Running via tsx from src/ in dev: llms.txt is two levels up (repo root) |
| 16 | + LLMS_TXT = readFileSync(resolve(__dirname, "../../llms.txt"), "utf-8"); |
| 17 | +} |
| 18 | + |
| 19 | +const SECTIONS = parseNodeSections(LLMS_TXT); |
| 20 | + |
| 21 | +// ─── parseNodeSections ──────────────────────────────────────────────────────── |
| 22 | + |
| 23 | +describe("parseNodeSections", () => { |
| 24 | + it("returns a non-empty map", () => { |
| 25 | + expect(SECTIONS.size).toBeGreaterThan(0); |
| 26 | + }); |
| 27 | + |
| 28 | + it("contains ModelNode", () => { |
| 29 | + expect(SECTIONS.has("modelnode")).toBe(true); |
| 30 | + }); |
| 31 | + |
| 32 | + it("contains LightNode", () => { |
| 33 | + expect(SECTIONS.has("lightnode")).toBe(true); |
| 34 | + }); |
| 35 | + |
| 36 | + it("contains Scene", () => { |
| 37 | + expect(SECTIONS.has("scene")).toBe(true); |
| 38 | + }); |
| 39 | + |
| 40 | + it("contains ARScene", () => { |
| 41 | + expect(SECTIONS.has("arscene")).toBe(true); |
| 42 | + }); |
| 43 | + |
| 44 | + it("contains AnchorNode", () => { |
| 45 | + expect(SECTIONS.has("anchornode")).toBe(true); |
| 46 | + }); |
| 47 | + |
| 48 | + it("each section has a non-empty content string", () => { |
| 49 | + for (const [, section] of SECTIONS) { |
| 50 | + expect(section.content.length).toBeGreaterThan(0); |
| 51 | + } |
| 52 | + }); |
| 53 | + |
| 54 | + it("section content starts with ### heading", () => { |
| 55 | + for (const [, section] of SECTIONS) { |
| 56 | + expect(section.content).toMatch(/^###\s/); |
| 57 | + } |
| 58 | + }); |
| 59 | + |
| 60 | + it("ModelNode content includes scaleToUnits parameter", () => { |
| 61 | + const section = SECTIONS.get("modelnode")!; |
| 62 | + expect(section.content).toContain("scaleToUnits"); |
| 63 | + }); |
| 64 | + |
| 65 | + it("LightNode content mentions apply named parameter", () => { |
| 66 | + const section = SECTIONS.get("lightnode")!; |
| 67 | + expect(section.content).toContain("apply"); |
| 68 | + }); |
| 69 | +}); |
| 70 | + |
| 71 | +// ─── findNodeSection ────────────────────────────────────────────────────────── |
| 72 | + |
| 73 | +describe("findNodeSection", () => { |
| 74 | + it("finds ModelNode case-insensitively", () => { |
| 75 | + expect(findNodeSection(SECTIONS, "ModelNode")).toBeDefined(); |
| 76 | + expect(findNodeSection(SECTIONS, "modelnode")).toBeDefined(); |
| 77 | + expect(findNodeSection(SECTIONS, "MODELNODE")).toBeDefined(); |
| 78 | + }); |
| 79 | + |
| 80 | + it("finds ARScene case-insensitively", () => { |
| 81 | + expect(findNodeSection(SECTIONS, "ARScene")).toBeDefined(); |
| 82 | + expect(findNodeSection(SECTIONS, "arscene")).toBeDefined(); |
| 83 | + }); |
| 84 | + |
| 85 | + it("returns undefined for an unknown type", () => { |
| 86 | + expect(findNodeSection(SECTIONS, "NonExistentNode")).toBeUndefined(); |
| 87 | + }); |
| 88 | + |
| 89 | + it("returned section has the correct canonical name", () => { |
| 90 | + const s = findNodeSection(SECTIONS, "lightnode"); |
| 91 | + expect(s!.name).toBe("LightNode"); |
| 92 | + }); |
| 93 | + |
| 94 | + it("returned section content is non-empty markdown", () => { |
| 95 | + const s = findNodeSection(SECTIONS, "ModelNode"); |
| 96 | + expect(s!.content.length).toBeGreaterThan(10); |
| 97 | + }); |
| 98 | +}); |
| 99 | + |
| 100 | +// ─── listNodeTypes ──────────────────────────────────────────────────────────── |
| 101 | + |
| 102 | +describe("listNodeTypes", () => { |
| 103 | + it("returns a sorted array", () => { |
| 104 | + const types = listNodeTypes(SECTIONS); |
| 105 | + const sorted = [...types].sort(); |
| 106 | + expect(types).toEqual(sorted); |
| 107 | + }); |
| 108 | + |
| 109 | + it("includes key node types", () => { |
| 110 | + const types = listNodeTypes(SECTIONS); |
| 111 | + expect(types).toContain("ModelNode"); |
| 112 | + expect(types).toContain("LightNode"); |
| 113 | + expect(types).toContain("Scene"); |
| 114 | + expect(types).toContain("ARScene"); |
| 115 | + expect(types).toContain("AnchorNode"); |
| 116 | + }); |
| 117 | + |
| 118 | + it("returns at least 10 entries (enough node types in llms.txt)", () => { |
| 119 | + expect(listNodeTypes(SECTIONS).length).toBeGreaterThanOrEqual(10); |
| 120 | + }); |
| 121 | +}); |
0 commit comments