Files
ECC/tests/lib/compute-sponsor.test.js
Affaan Mustafa 5af4395e5c test(lib): cover five untested scripts/lib modules (#3641)
* test(lib): cover feedback-links routes and payload

Pins the three public issue routes to the ECC repository and checks each template name actually exists under .github/ISSUE_TEMPLATE. Also locks the ecc.feedback.v1 payload shape, the no-diagnostics-upload promise, and that every call returns fresh copies so a caller cannot alter the frozen route table.

* test(lib): cover cursor-agent-names prefixing and path handling

Pins the ecc- prefix rule the Cursor install applies to agent files: idempotent, lowercase-prefix only, empty names pass through. Covers the relative path variant across backslash, repeated, and trailing separators, and that a leading separator cannot re-root the destination under the target agents directory.

* test(lib): cover agent-tool-map Pi mapping and authority invariant

Pins the Claude to Pi tool table: six core tools, every target a real Pi built-in, and read-only tools never escalating to bash, edit, or write. Covers the unsupported path for MCP, web, unknown, empty, and non-string names, and that prototype member names like constructor are not treated as table hits.

* test(lib): cover compute-sponsor URL and passive copy

Pins the compute URL to the bare https route with no path, query, or credentials, and that the sponsor copy links it exactly once and nowhere else. Locks the wording that keeps the link passive, keeps the ecc ito find bridge opt-in and non-reserving, and does not claim managed inference is live. The existing surface test only reads docs and CLI output, so the module itself had no direct test.

* test(lib): cover invocation-environment precedence and isolation

Pins the three branches every install path relies on: an explicit env is copied and wins, a scoped homeDir yields an empty environment so ambient variables cannot leak into a contained install, and anything else snapshots process.env. Also checks the copy is shallow, own-keys only, and never writes back.
2026-10-19 18:41:26 -04:00

78 lines
3.0 KiB
JavaScript

'use strict';
const test = require('node:test');
const assert = require('node:assert/strict');
const computeSponsor = require('../../scripts/lib/compute-sponsor');
const { ITO_COMPUTE_URL, getComputeSponsorCopy } = computeSponsor;
const URL_TOKEN_PATTERN = /https?:\/\/[^\s<>"'`(){}\\]+/g;
function urlsIn(text) {
return (text.match(URL_TOKEN_PATTERN) || []).map(token => token.replace(/[.,;:!?]+$/, ''));
}
test('the compute URL is the exact Ito route with no path, query, hash, or credentials', () => {
const parsed = new URL(ITO_COMPUTE_URL);
assert.equal(parsed.protocol, 'https:');
assert.equal(parsed.hostname, 'compute.itomarkets.com');
assert.equal(parsed.port, '');
assert.equal(parsed.username, '');
assert.equal(parsed.password, '');
assert.equal(parsed.pathname, '/');
assert.equal(parsed.search, '');
assert.equal(parsed.hash, '');
assert.equal(ITO_COMPUTE_URL, 'https://compute.itomarkets.com');
});
test('the copy links the compute URL exactly once and links nowhere else', () => {
assert.deepEqual(urlsIn(getComputeSponsorCopy()), [ITO_COMPUTE_URL]);
});
test('the copy names Ito as the preferred sponsor and keeps other providers open', () => {
const copy = getComputeSponsorCopy();
assert.match(copy, /^Run or self-host any open-source model\./);
assert.match(copy, /Itô is ECC's preferred compute sponsor/);
assert.match(copy, /Any GPU provider works\./);
});
test('the copy keeps the sponsorship link passive', () => {
const copy = getComputeSponsorCopy();
assert.match(copy, /This sponsorship link is passive/);
assert.match(copy, /does not invoke an RFQ, reserve capacity, provision compute, or configure serving/);
});
test('the copy keeps the ecc ito find bridge separate, opt-in, and non-reserving', () => {
const copy = getComputeSponsorCopy();
assert.match(copy, /Separately, the opt-in "ecc ito find" bridge/);
assert.match(copy, /explicitly configured canonical Itô CLI/);
assert.match(copy, /submits a live authenticated RFQ; it does not reserve capacity\./);
});
test('the copy does not claim managed inference is live', () => {
assert.match(getComputeSponsorCopy(), /Managed inference through Itô is not live yet\.$/);
});
test('the copy is a single trimmed line of printable text', () => {
const copy = getComputeSponsorCopy();
assert.equal(typeof copy, 'string');
assert.ok(copy.length > 0);
assert.equal(copy, copy.trim());
// eslint-disable-next-line no-control-regex
assert.doesNotMatch(copy, /[\x00-\x1f\x7f]/);
assert.doesNotMatch(copy, / {2}/);
});
test('the copy is deterministic across calls', () => {
assert.equal(getComputeSponsorCopy(), getComputeSponsorCopy());
});
test('the module surface is frozen and exports only the URL and the copy builder', () => {
assert.ok(Object.isFrozen(computeSponsor));
assert.deepEqual(Object.keys(computeSponsor).sort(), ['ITO_COMPUTE_URL', 'getComputeSponsorCopy']);
assert.throws(() => {
computeSponsor.ITO_COMPUTE_URL = 'https://example.invalid/';
}, TypeError);
assert.equal(computeSponsor.ITO_COMPUTE_URL, 'https://compute.itomarkets.com');
});