refactor(forms): enable approved Form A placements by default

This commit is contained in:
DeCentN2Madness committed 2026-10-30 15:08:02 -07:00
1 parent 55adb79705
commit 95c5f229f5
41 files changed
+862 -523

No files matched your search

+54 -33
View File
@@ -5,9 +5,9 @@ import path from 'node:path';
import test from 'node:test';
import { verifyArtifact } from './phase10-artifact-verify.mjs';
async function fixture(mode = 'staging') {
async function fixture(mode = 'staging', forms = 'live') {
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'aia-phase10-artifact-'));
const productionFrames = [
const contactLandingFrames = [
['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'],
@@ -29,24 +29,21 @@ async function fixture(mode = 'staging') {
['es/autism-evaluations/index.html', 'https://form.jotform.com/262946078314059?formContext=consultation&language=es'],
['es/learner-social-club/index.html', 'https://form.jotform.com/262946078314059?formContext=consultation&language=es'],
];
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>`]),
...consultationFrames.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>`]),
...consultationDrawers.map(([file, frame]) => [file, 'noindex,nofollow', `<section data-jotform-form-a data-form-mode="isolated-test" data-form-environment="isolated-test" data-jotform-deferred="true"><iframe data-jotform-iframe-url="${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', '']];
const robots = mode === 'staging' ? 'noindex,nofollow' : 'index,follow';
const pages = [['index.html', robots, '']];
if (mode === 'staging') pages.push(['lp/index.html', robots, '']);
if (forms === 'live') {
pages.push(...[...contactLandingFrames,...consultationFrames].map(([file, frame]) =>
[file, robots, `<section data-jotform-form-a data-form-mode="live"><iframe src="${frame}"></iframe></section>`]));
pages.push(...consultationDrawers.map(([file, frame]) =>
[file, robots, `<section data-jotform-form-a data-form-mode="live" data-jotform-deferred="true"><iframe data-jotform-iframe-url="${frame}"></iframe></section>`]));
}
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>');
await fs.writeFile(path.join(root, 'sitemap.xml'), mode === 'staging' ? '<urlset></urlset>' : '<urlset><url><loc>https://www.azinstitute4autism.com/</loc></url></urlset>');
return root;
}
@@ -64,28 +61,33 @@ test('indexing artifact requires sitemap and excludes review index', async () =>
assert.equal(result.reviewIndex, false);
});
test('isolated-test artifact permits ten static and six user-activated consultation Form A placements under staging safeguards', async () => {
const result = await verifyArtifact(await fixture('isolated-test'), 'isolated-test');
assert.equal(result.passed, true);
assert.equal(result.formAIframes, 10);
assert.equal(result.deferredFormAIframes, 6);
assert.equal(result.sitemapUrls, 0);
assert.equal(result.reviewIndex, true);
test('live forms have ten immediate and six deferred placements independently of publication mode', async () => {
for (const mode of ['staging','indexing']) {
const result = await verifyArtifact(await fixture(mode), mode);
assert.equal(result.passed, true, result.errors.join('; '));
assert.equal(result.formAIframes, 10);
assert.equal(result.deferredFormAIframes, 6);
assert.equal(result.reviewIndex, mode === 'staging');
}
});
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('off and mock artifacts contain no real frames independently of publication mode', async () => {
for (const mode of ['staging','indexing']) for (const forms of ['off','mock']) {
const root = await fixture(mode, forms);
const result = await verifyArtifact(root, mode, forms);
assert.equal(result.passed, true);
assert.equal(result.formAIframes + result.deferredFormAIframes, 0);
await fs.appendFile(path.join(root, 'index.html'), '<iframe src="https://form.jotform.com/262946078314059"></iframe>');
assert.equal((await verifyArtifact(root,mode,forms)).passed,false);
}
});
test('production artifact rejects an invalid Form A URL', async () => {
const root = await fixture('production');
test('indexing artifact rejects an invalid Form A URL', async () => {
const root = await fixture('indexing');
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');
const result = await verifyArtifact(root, 'indexing');
assert.equal(result.passed, false);
assert.ok(result.errors.some((error) => error.includes('invalid approved Form A iframe URL')));
});
@@ -98,7 +100,7 @@ test('staging artifact rejects active native form actions', async () => {
assert.ok(result.errors.some((error) => error.includes('native form action')));
});
test('artifact rejects live form mode and production API origin', async () => {
test('artifact rejects production API origin even when Form A is approved', 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');
@@ -106,12 +108,12 @@ test('artifact rejects live form mode and production API origin', async () => {
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 () => {
test('artifact rejects Form A identity outside the exact approved HTML routes', 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')));
assert.ok(result.errors.some((error) => error.includes('outside approved routes')));
});
test('artifact rejects root-relative URLs with terminal slashes', async () => {
@@ -140,3 +142,22 @@ test('release verification rejects private portal resources and encrypted payloa
assert.ok(result.errors.some((error) => error.includes('private portal ciphertext')));
assert.ok(result.errors.some((error) => error.includes('private/legacy')));
});
test('artifact rejects extra routes, wrong origins and prematurely loaded drawers', async () => {
const root = await fixture();
await fs.appendFile(path.join(root,'index.html'), '<iframe src="https://form.jotform.com/262946078314059?formContext=contact&language=en"></iframe>');
assert.equal((await verifyArtifact(root)).passed,false);
const clean = await fixture();
const file = path.join(clean,'aba-therapy/index.html');
await fs.writeFile(file,(await fs.readFile(file,'utf8')).replace('data-jotform-iframe-url=', 'src='));
assert.ok((await verifyArtifact(clean)).errors.some(e => e.includes('before activation')));
const other = await fixture();
await fs.appendFile(path.join(other,'index.html'), '<iframe src="https://unapproved.invalid/form"></iframe>');
assert.ok((await verifyArtifact(other)).errors.some(e => e.includes('unauthorized iframe')));
});
test('obsolete artifact modes are rejected with separate publication/form guidance', async () => {
await assert.rejects(verifyArtifact('/unused','isolated-test'), /--forms=live\|off\|mock/);
await assert.rejects(verifyArtifact('/unused','staging','invalid'), /live, off, or mock/);
});