// Acceptance tests for Kognessium B1 "Best paid agent on LAX", one per item A1 to A5.
// Offline by default. LAX_LIVE=1 adds the live checks (LAX listing, 402 from the real endpoint).
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync, readdirSync } from 'node:fs';
import Ajv from 'ajv';
import { validateOffer, ownDomain, LAWS } from '../src/offer.js';
const offer = JSON.parse(readFileSync(new URL('../lax-offer.json', import.meta.url)));
const readme = readFileSync(new URL('../README.md', import.meta.url), 'utf8');
const examples = readdirSync(new URL('../examples/', import.meta.url)).filter((f) => f.endsWith('.json'))
.map((f) => ({ f, ...JSON.parse(readFileSync(new URL(`../examples/${f}`, import.meta.url))) }));
const LISTING = 'lax-ext-d898c749478a';
const LIVE = process.env.LAX_LIVE === '1';
const ajv = new Ajv({ strict: false, allErrors: true });
const cap = (id) => offer.capabilities.find((c) => c.skill_id === id);
const paid = offer.capabilities.filter((c) => c.pricing.model === 'per_call');
test('A1 the offer passes the LAX registry validation, with the Five Laws, on our own domain', () => {
assert.deepEqual(validateOffer(offer), []);
assert.equal(ownDomain(offer.endpoint), 'api.youraitools.co');
for (const l of LAWS) assert.ok(offer.constitutional_constraints.includes(l), l);
// the validator itself refuses what the registry refuses (tests that fail without the rule)
assert.match(validateOffer({ ...offer, endpoint: 'https://lax.kognai.ai/agent' }).join(), /own public domain/);
assert.match(validateOffer({ ...offer, constitutional_constraints: LAWS.slice(1) }).join(), /missing: Solidarity Oath/);
assert.match(validateOffer({ ...offer, capabilities: [{ ...offer.capabilities[0], pricing: { ...offer.capabilities[0].pricing, amount: '0' } }] }).join(), /positive decimal/);
});
test('A1 live: the listing on LAX carries this endpoint and is AIAX ready', { skip: !LIVE && 'set LAX_LIVE=1' }, async () => {
const { offer: live } = await (await fetch(`https://lax.kognai.ai/registry/offers/${LISTING}`)).json();
assert.equal(new URL(live.endpoint).hostname, 'api.youraitools.co');
assert.equal(live.aiax_ready, true);
// the listed offer is this lax-offer.json
assert.equal(live.name, offer.name); assert.equal(live.description, offer.description);
assert.deepEqual(live.capabilities.map((c) => [c.skill_id, c.pricing, c.input_schema, c.output_schema]), offer.capabilities.map((c) => [c.skill_id, c.pricing, c.input_schema, c.output_schema]));
});
test('A2 each paid capability has an input schema, an output schema and a price per call', () => {
assert.ok(paid.length >= 3);
for (const c of offer.capabilities) {
assert.equal(c.input_schema.type, 'object', c.skill_id);
assert.ok(Object.keys(c.input_schema.properties || {}).length > 0, `${c.skill_id} input properties`);
assert.equal(c.output_schema.type, 'object', c.skill_id);
assert.ok((c.output_schema.required || []).length > 0, `${c.skill_id} output required`);
assert.ok(ajv.compile(c.input_schema) && ajv.compile(c.output_schema), `${c.skill_id} schemas compile`);
assert.ok(Number(c.pricing.amount) > 0 && c.pricing.currency === 'USDC' && c.pricing.rail === 'x402');
}
for (const c of paid) assert.ok(Number(c.pricing.amount) <= 1, `${c.skill_id}: Kognai pays at most 1 USDC per test call`);
});
test('A3 three examples whose requests and responses match the schemas', () => {
assert.ok(examples.length >= 3, 'at least three examples');
assert.equal(new Set(examples.map((e) => e.capability)).size, examples.length, 'one capability per example');
for (const e of examples) {
const c = cap(e.capability); assert.ok(c, `${e.f}: capability ${e.capability} is in the offer`);
const input = e.request.body ?? e.request.query;
const vin = ajv.compile(c.input_schema); assert.ok(vin(input), `${e.f} request: ${ajv.errorsText(vin.errors)}`);
const vout = ajv.compile(c.output_schema); assert.ok(vout(e.response), `${e.f} response: ${ajv.errorsText(vout.errors)}`);
assert.equal(new URL(e.request.url).hostname, 'api.youraitools.co');
assert.ok(c.description.includes(new URL(e.request.url).pathname), `${e.f}: path documented in the capability`);
}
// a broken example is caught
const e = examples[0]; const vout = ajv.compile(cap(e.capability).output_schema);
const broken = { ...e.response }; delete broken[cap(e.capability).output_schema.required[0]];
assert.equal(vout(broken), false);
});
test('A4 the README names the live endpoint, the LAX listing id, the prices and what the agent refuses', () => {
assert.ok(readme.includes(LISTING));
assert.ok(readme.includes('https://api.youraitools.co'));
for (const c of paid) assert.ok(readme.includes(c.skill_id) && readme.includes(c.pricing.amount), `${c.skill_id} price in README`);
assert.match(readme, /## What the agent refuses/);
});
test('A4 live: the endpoint answers 402 with x402 terms in USDC on Base when unpaid', { skip: !LIVE && 'set LAX_LIVE=1' }, async () => {
for (const e of examples) {
const u = new URL(e.request.url); for (const [k, v] of Object.entries(e.request.query || {})) u.searchParams.set(k, v);
const r = await fetch(u, { method: e.request.method, headers: e.request.body ? { 'content-type': 'application/json' } : {}, body: e.request.body ? JSON.stringify(e.request.body) : undefined });
assert.equal(r.status, 402, e.f);
const terms = JSON.parse(Buffer.from(r.headers.get('payment-required'), 'base64').toString());
assert.equal(terms.accepts[0].network, 'eip155:8453');
assert.equal(terms.accepts[0].asset.toLowerCase(), '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913');
assert.equal(String(Number(terms.accepts[0].amount) / 1e6), cap(e.capability).pricing.amount);
}
});
test('A5 examples are real answers of the production handlers, paid (200 after 402)', () => {
for (const e of examples) {
assert.equal(e.recorded.unpaid_status, 402, e.f);
assert.equal(e.recorded.paid_status, 200, e.f);
}
});
// A5 Kognai's three paid calls: scripts/kognai-calls.mjs reads the three settlements from Base into
// test/fixtures/kognai-calls.json; until then this is todo. The check itself is offline.
const kcUrl = new URL('./fixtures/kognai-calls.json', import.meta.url);
let kc = null; try { kc = JSON.parse(readFileSync(kcUrl, 'utf8')); } catch {}
test('A5 three paid test calls by Kognai, one per example, answered well (recorded after the PACT)', { todo: kc ? false : 'after the PACT: node scripts/kognai-calls.mjs <tx>:<skill_id> x3' }, () => {
assert.equal(kc.calls.length, 3);
assert.deepEqual(kc.calls.map((c) => c.skill_id).sort(), examples.map((e) => e.capability).sort(), 'one call per example capability');
assert.equal(new Set(kc.calls.map((c) => c.tx)).size, 3, 'three distinct paid calls');
assert.equal(kc.payTo, offer.agent_did.split(':').pop().toLowerCase());
for (const c of kc.calls) {
assert.match(c.tx, /^0x[0-9a-f]{64}$/);
assert.equal(c.status, '0x1', `${c.skill_id} settled`);
assert.equal(c.to, kc.payTo, `${c.skill_id} paid to us`);
const amt = cap(c.skill_id).pricing.amount; const [i, f = ''] = amt.split('.');
assert.equal(c.amount_atomic, String(BigInt(i + (f + '000000').slice(0, 6))), `${c.skill_id} paid the listed price`);
assert.ok(BigInt(c.amount_atomic) <= 1000000n, 'at most 1 USDC per call');
}
});
agentgate-source: code mirror on Cloudflare Pages. All repos