// One command once Kognai publishes the Sepolia rehearsal UID (acceptance A6):
// node scripts/kognai-rehearsal.mjs 0x<64 hex>
// 1. writes the UID into config.js (KOGNAI_REHEARSAL.uid), 2. verifies it live on Base Sepolia while recording every
// RPC answer and IPFS text, 3. saves the recording to test/fixtures/rehearsal.json so the A6 test replays it offline
// (Kognai's hidden tests run without network), 4. writes the result table into the README.
// Read only: eth_call and IPFS GETs, no key, no wallet, no spend.
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
import { verifyCharter, httpRpc, httpIpfs, NETWORKS } from '../verifier.js';
const uid = (process.argv[2] || '').toLowerCase();
if (!/^0x[0-9a-f]{64}$/.test(uid)) { console.error('usage: node scripts/kognai-rehearsal.mjs 0x<64 hex UID>'); process.exit(2); }
const root = new URL('../', import.meta.url);
const live = { rpc: httpRpc(NETWORKS['base-sepolia'].rpcUrl), ipfs: httpIpfs(process.env.IPFS_GATEWAY) };
const rec = { uid, network: 'base-sepolia', recordedAt: new Date().toISOString(), rpc: [], ipfs: {} };
const rpc = async (method, params) => { const result = await live.rpc(method, params); rec.rpc.push({ method, params, result }); return result; };
const ipfs = async (cid) => { const b = await live.ipfs(cid); rec.ipfs[cid] = Buffer.from(b).toString('base64'); return b; };
const r = await verifyCharter({ uid, network: 'base-sepolia', rpc, ipfs });
rec.result = r;
mkdirSync(new URL('test/fixtures/', root), { recursive: true });
writeFileSync(new URL('test/fixtures/rehearsal.json', root), JSON.stringify(rec, null, 1) + '\n');
const cfgUrl = new URL('config.js', root);
const cfg = readFileSync(cfgUrl, 'utf8').replace(/export const KOGNAI_REHEARSAL = \{[^}]*\};/, `export const KOGNAI_REHEARSAL = { network: 'base-sepolia', uid: '${uid}' };`);
writeFileSync(cfgUrl, cfg);
const rows = r.texts.map((t) => `| ${t.name} | ${t.cid} | ${t.match ? 'match' : 'MISMATCH'} | \`${t.expected}\` | \`${t.actual ?? 'not fetched'}\` |`).join('\n');
const section = `## Sepolia rehearsal UID result\n\nUID \`${uid}\` on Base Sepolia, checked ${rec.recordedAt.slice(0, 10)}: **${r.ok ? 'ok, every text matches' : 'NOT ok: ' + r.reason}**. Attester ${r.attestation.attester}, revoked ${r.attestation.revoked}.\n\n| Text | CID | Result | Expected sha256 | Actual sha256 |\n|---|---|---|---|---|\n${rows}\n`;
const readmeUrl = new URL('README.md', root);
let readme = readFileSync(readmeUrl, 'utf8');
readme = /## Sepolia rehearsal UID result\n[\s\S]*?(?=\n## |$)/.test(readme)
? readme.replace(/## Sepolia rehearsal UID result\n[\s\S]*?(?=\n## |$)/, section)
: readme.trimEnd() + '\n\n' + section;
writeFileSync(readmeUrl, readme);
console.log(`rehearsal ${uid}: ok=${r.ok}${r.ok ? '' : ' reason=' + r.reason}; fixture, config.js and README updated. Now run: npm test`);
process.exit(r.ok ? 0 : 1);
agentgate-source: code mirror on Cloudflare Pages. All repos