import { readFileSync } from "node:fs"; import { dirname, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import * as toolcraftUiControls from "@repo/ui/controls"; import * as toolcraftUiPanel from "@repo/ui/panel"; import { describe, expect, it } from "vitest"; import * as toolcraftRuntimeReact from "../react"; import { TOOLCRAFT_BUILT_IN_CONTROL_TYPES, TOOLCRAFT_COMPONENT_CONTRACTS, } from "./component-contracts"; import { TOOLCRAFT_DECISION_CONTRACT } from "./decision-contracts"; const contractsDir = dirname(fileURLToPath(import.meta.url)); const repoRoot = resolve(contractsDir, "../../../.."); const manifest = JSON.parse( readFileSync( resolve(repoRoot, "starter/scripts/toolcraft-contract-manifest.json"), "utf8", ), ); describe("Toolcraft machine-readable contract manifest", () => { it("matches every runtime decision rule with level and area", () => { expect(manifest.decisionRules).toEqual( TOOLCRAFT_DECISION_CONTRACT.map(({ area, id, level }) => ({ area, id, level, })), ); }); it("matches the canonical built-in registry and visual ownership", () => { expect(manifest.builtInControls).toEqual( TOOLCRAFT_BUILT_IN_CONTROL_TYPES.map((type) => ({ type, visualComponent: TOOLCRAFT_COMPONENT_CONTRACTS[type].visualComponent, })), ); }); it("names only real protected UI exports and runtime surfaces", () => { const publicUiExports = { ...toolcraftUiControls, ...toolcraftUiPanel, }; for (const exportName of manifest.protectedControlExportNames) { expect( exportName in publicUiExports, `Protected control export "${exportName}" must exist in @repo/ui.`, ).toBe(true); } for (const exportName of manifest.runtimeSurfaceComponentNames) { expect( exportName in toolcraftRuntimeReact, `Runtime surface "${exportName}" must exist in @repo/toolcraft-runtime/react.`, ).toBe(true); } }); });