116 lines
6.3 KiB
JavaScript
116 lines
6.3 KiB
JavaScript
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', `<section data-jotform-form-a data-form-mode="isolated-test" data-form-environment="isolated-test"><iframe src="${frame}"></iframe></section>`]),
|
|
['lp/index.html', 'noindex,nofollow', ''],
|
|
]
|
|
: mode === 'production'
|
|
? productionFrames.map(([file, frame]) => [file, 'index,follow', `<section data-jotform-form-a data-form-mode="live" data-form-environment="production"><iframe src="${frame}"></iframe></section>`])
|
|
: [['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, `<!doctype html><html><head><title>${file}</title><meta name="robots" content="${robots}"><link rel="canonical" href="https://www.azinstitute4autism.com/${file}"></head><body><main><h1>${file}</h1>${body}</main></body></html>`);
|
|
}
|
|
await fs.writeFile(path.join(root, 'sitemap.xml'), ['staging', 'isolated-test'].includes(mode) ? '<urlset></urlset>' : '<urlset><url><loc>https://www.azinstitute4autism.com/</loc></url></urlset>');
|
|
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'), '<form action="https://example.invalid/submit"></form>');
|
|
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'), '<div data-form-mode="live">https://api.azinstitute4autism.com</div>');
|
|
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'), '<a href="/lp/aba-therapy/">Campaign</a>');
|
|
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);
|
|
});
|