smoke.test.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { readdirSync, readFileSync } from "node:fs";
  2. import { dirname, join } from "node:path";
  3. import { fileURLToPath } from "node:url";
  4. import { describe, expect, it } from "vitest";
  5. import { analyzeWorkflowScript } from "../src/index.js";
  6. /**
  7. * Smoke corpus: real, production-scale workflow scripts that must ANALYZE CLEAN — no throw,
  8. * every projection produced — within a budget. No goldens: these scripts are large (2,500+
  9. * trace regions each) and their exact graphs are not the point; the point is that the
  10. * analyzer scales to what authors actually write. Each file records where it came from.
  11. *
  12. * Add a script here when it breaks the analyzer in production (ITERATION_CAP, a stack
  13. * overflow, a pathological runtime) and the minimal shape has ALSO been pinned in a unit
  14. * test next to the fix — the smoke file guards the whole shape, the unit test explains it.
  15. */
  16. const smokeDir = join(dirname(fileURLToPath(import.meta.url)), "smoke");
  17. const BUDGET_MS = 10_000;
  18. describe("smoke corpus", () => {
  19. const scripts = readdirSync(smokeDir)
  20. .filter((name) => name.endsWith(".dwf.ts"))
  21. .sort();
  22. it("finds scripts", () => {
  23. expect(scripts.length).toBeGreaterThan(0);
  24. });
  25. for (const script of scripts) {
  26. it(`${script} analyzes clean within ${BUDGET_MS} ms`, () => {
  27. const source = readFileSync(join(smokeDir, script), "utf8");
  28. const started = Date.now();
  29. const result = analyzeWorkflowScript(source);
  30. const elapsed = Date.now() - started;
  31. expect(result.diagnostics).toEqual([]);
  32. expect(result.ok).toBe(true);
  33. expect(result.core).toBeDefined();
  34. expect(result.causality).toBeDefined();
  35. expect(result.flow).toBeDefined();
  36. expect(result.handoff).toBeDefined();
  37. expect(elapsed).toBeLessThan(BUDGET_MS);
  38. });
  39. }
  40. });