youraitools-api / tree / test/aiax.test.js ยท raw (this view has old GitHub links rewritten for the mirror; raw is byte-exact)
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { validateSite } from 'aiax-validate';

const PUB = new URL('../public/', import.meta.url);
// answer every fetch from public/ (offline), 404 when the file is missing
const fetchLocal = async (url) => {
  try { return new Response(readFileSync(new URL('.' + new URL(url).pathname, PUB)), { status: 200, headers: { 'content-type': 'application/json' } }); }
  catch { return new Response('not found', { status: 404 }); }
};

test('AIAX manifest and every section validate with aiax-validate (score 100)', async () => {
  const r = await validateSite('https://api.youraitools.co', { fetch: fetchLocal });
  assert.deepEqual(r.errors, []);
  assert.equal(r.ok, true);
  assert.equal(r.score, 100);
  assert.ok(r.sections.length >= 5);
});

test('AIAX files are static: excluded from Functions and served as JSON', () => {
  const routes = JSON.parse(readFileSync(new URL('_routes.json', PUB), 'utf8'));
  for (const p of ['/.well-known/aiax.json', '/aiax/*']) assert.ok(routes.exclude.includes(p), p);
  const h = readFileSync(new URL('_headers', PUB), 'utf8');
  assert.match(h, /\/\.well-known\/aiax\.json\n {2}Content-Type: application\/json/);
  assert.deepEqual(JSON.parse(readFileSync(new URL('.well-known/aiax.json', PUB))), JSON.parse(readFileSync(new URL('aiax/manifest.json', PUB))));
});

agentgate-source: code mirror on Cloudflare Pages. All repos