import { existsSync, readdirSync, readFileSync } from "node:fs"; import { dirname, extname, join, relative, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { describe, expect, it } from "vitest"; const testDirectory = dirname(fileURLToPath(import.meta.url)); const repositoryRoot = resolve(testDirectory, "../../../.."); const normativeRoots = [ "packages/toolcraft-runtime/src", "apps/website/src/content/docs", "starter/docs/toolcraft", "starter/e2e", "starter/scripts", "starter/src", "cli/fixtures/generated-product/docs", "cli/fixtures/generated-product/e2e", "cli/fixtures/generated-product/src", ] as const; const supportedExtensions = new Set([".md", ".mjs", ".mts", ".ts", ".tsx"]); const forbiddenPatterns = [ ["large", "TextStressMinChars"].join(""), ["large", "TextStressMinLines"].join(""), ["media", "StressMinArea"].join(""), ["media", "StressMinLongEdge"].join(""), ["workload", "ControlPattern"].join(""), ["renderer", "Workload"].join("") + String.raw`\s*[?:]`, ["workload", "Targets"].join("") + String.raw`\s*[?:]`, ["stress", "Fixture"].join(""), ["workload", "Fixture"].join(""), ["load", "Profile"].join(""), ["smooth", "TargetRatio"].join(""), ["measured", "AlternativeEvidence"].join(""), ["expectToolcraft", "ScenarioPerformanceBudget"].join(""), ["expectToolcraft", "DiscreteSliderDragSmoothness"].join(""), ["deriveToolcraft", "PerformanceRuntimeRequirements"].join(""), ["browser", "CheckPolicy"].join(""), ["record", "-exemption"].join(""), ["experimental", "-above-smooth"].join(""), ["preview", "-render"].join(""), ["viewport", "-zoom-stress"].join(""), ["animation", "-viewport-drag"].join(""), ["viewport", "-stability"].join(""), ["max", "RenderMs"].join(""), ["playwright", "-fallback"].join(""), ["performance", "-stress-fixture"].join(""), ] as const; const retiredRuntimeFiles = [ "performance-browser-policy.ts", "performance-coverage-context.ts", "performance-coverage-renderer-policy.ts", "performance-coverage-scenario-policy.ts", "performance-coverage-target-policy.ts", "performance-fixture-validation.ts", "performance-fixture-values.ts", "performance-load-profile-validation.ts", "performance-renderer-validation.ts", ] as const; function collectNormativeFiles(directory: string): string[] { return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => { const path = join(directory, entry.name); if (entry.isDirectory()) { return collectNormativeFiles(path); } if ( !entry.isFile() || !supportedExtensions.has(extname(entry.name)) || /(?:^|\.)test\.|(?:^|\.)spec\./u.test(entry.name) ) { return []; } return [path]; }); } describe("Toolcraft canonical performance architecture", () => { it("contains no legacy authored workload semantics", () => { const violations = normativeRoots.flatMap((root) => collectNormativeFiles(resolve(repositoryRoot, root)).flatMap((path) => { const source = readFileSync(path, "utf8"); return forbiddenPatterns.flatMap((pattern) => new RegExp(pattern, "u").test(source) ? [`${relative(repositoryRoot, path)} contains /${pattern}/u`] : [], ); }), ); expect(violations).toEqual([]); }); it("does not restore retired parallel policy modules", () => { const testingRoot = resolve( repositoryRoot, "packages/toolcraft-runtime/src/testing", ); expect( retiredRuntimeFiles.filter((fileName) => existsSync(join(testingRoot, fileName)), ), ).toEqual([]); }); });