import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { TOOLS, SERVICES } from '../functions/tools.js';
import { sitemapEntries, sitemapXml } from '../scripts/gen_sitemap.mjs';
import { indexHtml, llmsTxt } from '../functions/root.js';
const PUB = new URL('../public/', import.meta.url);
const env = { PUBLIC_HOST: 'api.youraitools.co' };
test('sitemap entries: index + every tool/service landing + samples; no paid, /v1, /mcp, JSON or .well-known routes', () => {
const paths = sitemapEntries().map((e) => e.path);
assert.equal(paths[0], '/');
for (const t of [...TOOLS, ...SERVICES]) assert.ok(paths.includes(`/${t.prefix}/`), t.prefix);
for (const p of paths) assert.doesNotMatch(p, /\/v1\/|\/mcp|\.well-known|\.json$/);
assert.equal(new Set(paths).size, paths.length);
const xml = sitemapXml(sitemapEntries(), '2026-10-22');
assert.match(xml, /^<\?xml version="1.0" encoding="UTF-8"\?>\n<urlset xmlns="http:\/\/www.sitemaps.org\/schemas\/sitemap\/0.9">/);
assert.equal((xml.match(/<url>/g) || []).length, paths.length);
});
test('built public/sitemap.xml is current (run `npm run build` after editing tools.js) and is static', () => {
const xml = readFileSync(new URL('sitemap.xml', PUB), 'utf8');
for (const t of [...TOOLS, ...SERVICES]) assert.ok(xml.includes(`<loc>https://api.youraitools.co/${t.prefix}/</loc>`), `sitemap.xml missing ${t.prefix}: run npm run build`);
assert.match(xml, /<lastmod>\d{4}-\d{2}-\d{2}<\/lastmod>/);
assert.ok(JSON.parse(readFileSync(new URL('_routes.json', PUB), 'utf8')).exclude.includes('/sitemap.xml'));
assert.match(readFileSync(new URL('_headers', PUB), 'utf8'), /\/sitemap\.xml\n {2}Content-Type: application\/xml/);
assert.match(readFileSync(new URL('robots.txt', PUB), 'utf8'), /^Sitemap: https:\/\/api\.youraitools\.co\/sitemap\.xml$/m);
});
test('root HTML has canonical, Open Graph and parseable JSON-LD (WebSite + SoftwareApplication per tool)', () => {
const h = indexHtml(env);
for (const p of ['og:title', 'og:description', 'og:url', 'og:type']) assert.match(h, new RegExp(`property="${p}"`));
const ld = JSON.parse(h.match(/<script type="application\/ld\+json">(.*?)<\/script>/s)[1]);
assert.equal(ld['@graph'][0]['@type'], 'WebSite');
assert.equal(ld['@graph'][1].itemListElement.length, TOOLS.length);
assert.ok(ld['@graph'][1].itemListElement.every((x) => x.item['@type'] === 'SoftwareApplication'));
});
test('llms.txt has one link line per tool', () => {
const t = llmsTxt(env);
for (const x of TOOLS) assert.ok(t.includes(`- [${x.name}](https://api.youraitools.co/${x.prefix}/): `), x.prefix);
assert.match(t, /\[Sitemap\]\(https:\/\/api\.youraitools\.co\/sitemap\.xml\)/);
});
agentgate-source: code mirror on Cloudflare Pages. All repos