const assert = require("assert"); const fs = require("fs"); const path = require("path"); const rootDir = path.resolve(__dirname, "..", ".."); const tests = []; const test = (name, fn) => tests.push({ name, fn }); const exists = (relativePath) => fs.existsSync(path.join(rootDir, relativePath)); const read = (relativePath) => fs.readFileSync(path.join(rootDir, relativePath), "utf8"); test("known grouped facade folders exist for proven slices", async () => { [ "pages/api/subscriptions", "pages/api/documents", "pages/api/search" ].forEach((folderPath) => { assert.strictEqual(exists(folderPath), true, folderPath); }); }); test("known façade characterization test files exist", async () => { [ "tests/phase22/api-grouping-facade-subscriptions.test.cjs", "tests/phase22/api-grouping-facade-documents.test.cjs", "tests/phase22/api-grouping-facade-search.test.cjs" ].forEach((filePath) => { assert.strictEqual(exists(filePath), true, filePath); }); }); test("existing slice tests cover service adoption or retained scope checks", async () => { const subscriptionsSource = read( "tests/phase22/api-grouping-facade-subscriptions.test.cjs" ); const documentsSource = read( "tests/phase22/api-grouping-facade-documents.test.cjs" ); const searchSource = read( "tests/phase22/api-grouping-facade-search.test.cjs" ); assert.match( subscriptionsSource, /portalDirectService watched-case methods now target subscriptions facade routes/ ); assert.match( documentsSource, /searchDirectService document journey methods now target grouped documents facade routes/ ); assert.match( searchSource, /searchDirectService active public search methods now target grouped search routes/ ); assert.match( searchSource, /excluded routes remain outside grouped public search adoption scope/ ); }); test("checkpoint tests do not imply legacy handlers can be removed", async () => { const sliceSources = [ read("tests/phase22/api-grouping-facade-subscriptions.test.cjs"), read("tests/phase22/api-grouping-facade-documents.test.cjs"), read("tests/phase22/api-grouping-facade-search.test.cjs") ].join("\n"); assert.doesNotMatch(sliceSources, /legacy handlers can be removed/i); assert.doesNotMatch(sliceSources, /delete legacy/i); assert.match(sliceSources, /legacy .* remain/i); const roadmapSource = read("context/api-grouping-adoption-roadmap.md"); assert.match(roadmapSource, /does not approve route removal/i); assert.match( roadmapSource, /legacy handlers remain present and canonical/i ); }); async function run() { let failures = 0; for (const { name, fn } of tests) { try { await fn(); console.log(`✓ ${name}`); } catch (error) { failures += 1; console.error(`✗ ${name}`); console.error(error); } } if (failures > 0) { process.exit(1); } } run();