import assert from 'node:assert/strict'; import fs from 'node:fs/promises'; import os from 'node:os'; import path from 'node:path'; import test from 'node:test'; import { verifyArtifact } from './phase10-artifact-verify.mjs'; async function fixture(mode = 'staging') { const root = await fs.mkdtemp(path.join(os.tmpdir(), 'aia-phase10-artifact-')); const productionFrames = [ ['contact/index.html', 'https://form.jotform.com/262946078314059?formContext=contact&language=en'], ['es/contact/index.html', 'https://form.jotform.com/262946078314059?formContext=contact&language=es'], ['lp/aba-therapy/index.html', 'https://form.jotform.com/262946078314059?formContext=landing&language=en'], ['lp/aba-insurance/index.html', 'https://form.jotform.com/262946078314059?formContext=landing&language=en'], ['lp/aba-ahcccs/index.html', 'https://form.jotform.com/262946078314059?formContext=landing&language=en'], ['lp/aba-private-pay/index.html', 'https://form.jotform.com/262946078314059?formContext=landing&language=en'], ['lp/early-intervention/index.html', 'https://form.jotform.com/262946078314059?formContext=landing&language=en'], ]; const pages = mode === 'staging' ? [['index.html', 'noindex,nofollow', ''] , ['lp/index.html', 'noindex,nofollow', '']] : mode === 'isolated-test' ? [ ...productionFrames.map(([file, frame]) => [file, 'noindex,nofollow', `
`]), ['lp/index.html', 'noindex,nofollow', ''], ] : mode === 'production' ? productionFrames.map(([file, frame]) => [file, 'index,follow', `
`]) : [['index.html', 'index,follow', '']]; for (const [file, robots, body] of pages) { const target = path.join(root, file); await fs.mkdir(path.dirname(target), { recursive: true }); await fs.writeFile(target, `${file}

${file}

${body}
`); } await fs.writeFile(path.join(root, 'sitemap.xml'), ['staging', 'isolated-test'].includes(mode) ? '' : 'https://www.azinstitute4autism.com/'); return root; } test('staging artifact requires noindex, empty sitemap, no hreflang and review index', async () => { const result = await verifyArtifact(await fixture('staging'), 'staging'); assert.equal(result.passed, true); assert.equal(result.sitemapUrls, 0); assert.equal(result.reviewIndex, true); }); test('indexing artifact requires sitemap and excludes review index', async () => { const result = await verifyArtifact(await fixture('indexing'), 'indexing'); assert.equal(result.passed, true); assert.equal(result.sitemapUrls, 1); assert.equal(result.reviewIndex, false); }); test('isolated-test artifact permits exactly the seven approved Form A iframe placements under staging safeguards', async () => { const result = await verifyArtifact(await fixture('isolated-test'), 'isolated-test'); assert.equal(result.passed, true); assert.equal(result.formAIframes, 7); assert.equal(result.sitemapUrls, 0); assert.equal(result.reviewIndex, true); }); test('production artifact permits exactly the seven approved Form A iframe placements', async () => { const result = await verifyArtifact(await fixture('production'), 'production'); assert.equal(result.passed, true); assert.equal(result.formAIframes, 7); assert.equal(result.reviewIndex, false); }); test('production artifact rejects an invalid Form A URL', async () => { const root = await fixture('production'); const contact = path.join(root, 'contact/index.html'); const html = await fs.readFile(contact, 'utf8'); await fs.writeFile(contact, html.replace('formContext=contact&language=en', 'formContext=landing&language=en')); const result = await verifyArtifact(root, 'production'); assert.equal(result.passed, false); assert.ok(result.errors.some((error) => error.includes('invalid approved Form A iframe URL'))); }); test('staging artifact rejects active native form actions', async () => { const root = await fixture('staging'); await fs.appendFile(path.join(root, 'index.html'), '
'); const result = await verifyArtifact(root, 'staging'); assert.equal(result.passed, false); assert.ok(result.errors.some((error) => error.includes('native form action'))); }); test('artifact rejects live form mode and production API origin', async () => { const root = await fixture('staging'); await fs.appendFile(path.join(root, 'index.html'), '
https://api.azinstitute4autism.com
'); const result = await verifyArtifact(root, 'staging'); assert.equal(result.passed, false); assert.ok(result.errors.some((error) => error.includes('unsafe artifact signals'))); }); test('artifact rejects the isolated-test Form A identifier in any shipped text asset', async () => { const root = await fixture('staging'); await fs.writeFile(path.join(root, 'assets.js'), 'https://form.jotform.com/262946078314059?formContext=contact'); const result = await verifyArtifact(root, 'staging'); assert.equal(result.passed, false); assert.ok(result.errors.some((error) => error.includes('isolated-test Form A identifier'))); }); test('artifact rejects root-relative URLs with terminal slashes', async () => { const root = await fixture('staging'); await fs.appendFile(path.join(root, 'index.html'), 'Campaign'); const result = await verifyArtifact(root, 'staging'); assert.equal(result.passed, false); assert.ok(result.errors.some((error) => error.includes('root-relative URL(s) end in a slash'))); }); test('artifact digest is deterministic for unchanged files', async () => { const root = await fixture('staging'); const first = await verifyArtifact(root, 'staging'); const second = await verifyArtifact(root, 'staging'); assert.equal(first.artifactSha256, second.artifactSha256); assert.equal(first.artifactFiles, second.artifactFiles); });