/** * Tests for the Phase 1 Ito compute-sponsor surface. */ const assert = require('assert'); const fs = require('fs'); const os = require('os'); const path = require('path'); const { spawnSync } = require('child_process'); const REPO_ROOT = path.join(__dirname, '..', '..'); const URL_TOKEN_PATTERN = /https?:\/\/[^\s<>"'`(){}\\]+/g; const EXPECTED_COMPUTE_ROUTE = Object.freeze({ protocol: 'https:', hostname: 'compute.itomarkets.com', port: '', username: '', password: '', pathname: '/', search: '', hash: '', }); function read(relativePath) { return fs.readFileSync(path.join(REPO_ROOT, relativePath), 'utf8'); } function readPngDimensions(relativePath) { const image = fs.readFileSync(path.join(REPO_ROOT, relativePath)); assert.strictEqual(image.subarray(1, 4).toString('ascii'), 'PNG'); return { width: image.readUInt32BE(16), height: image.readUInt32BE(20), }; } function runTest(name, fn) { try { fn(); console.log(` ✓ ${name}`); return true; } catch (error) { console.log(` ✗ ${name}`); console.error(` ${error.message}`); return false; } } function isExactComputeRoute(candidate) { try { const parsed = new URL(candidate.replace(/[.,;:!?]+$/, '')); return Object.entries(EXPECTED_COMPUTE_ROUTE).every( ([property, expected]) => parsed[property] === expected ); } catch { return false; } } function assertExactComputeRoute(content) { const candidates = content.match(URL_TOKEN_PATTERN) || []; assert.ok( candidates.some(isExactComputeRoute), 'Should include the exact Itô compute route' ); } function assertExactHref(content, expectedHref) { const expected = new URL(expectedHref); const hrefs = [...content.matchAll(/\bhref="([^"]+)"/g)].map(match => match[1]); const properties = [ 'protocol', 'hostname', 'port', 'username', 'password', 'pathname', 'search', 'hash', ]; const hasExactHref = hrefs.some((href) => { try { const candidate = new URL(href); return properties.every(property => candidate[property] === expected[property]); } catch { return false; } }); assert.ok(hasExactHref, `Should include the exact href ${expectedHref}`); } function assertHonestComputeCopy(content) { assertExactComputeRoute(content); assert.match(content, /preferred compute sponsor/i); assert.match(content, /run or self-host any open-source model/i); assert.match(content, /any GPU provider/i); assert.match(content, /sponsorship link is passive/i); assert.match(content, /ecc ito find/i); assert.match(content, /explicitly configured canonical Itô CLI/i); assert.match(content, /submits a live authenticated RFQ/i); assert.match(content, /does not reserve capacity/i); assert.match(content, /managed inference[^\n.]*not live/i); assert.doesNotMatch(content, /ECC only (?:links|provides this link)/i); } function extractNamedTable(content, ariaLabel) { const escapedLabel = ariaLabel.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); const match = content.match( new RegExp(`