72 lines
2.4 KiB
TypeScript
72 lines
2.4 KiB
TypeScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { StrictDomainRuntimeHandoffSource } from './domain-runtime-handoff-source.js';
|
|
|
|
const DOMAIN_ID = 'DOM-FIFTH-0001';
|
|
const NODE_ID = 'JD-FD-PRIMARY';
|
|
|
|
function response(overrides: Record<string, unknown> = {}) {
|
|
return {
|
|
schema: 'gh-aios.domain-runtime-handoff-response/v1',
|
|
handoff: { manifest: { digest: 'untrusted-until-orchestrator-verifies' } },
|
|
signer_lookup: {
|
|
repository_id: 'REPO-014',
|
|
signer_id: 'GH-LIGHTHOUSE-001',
|
|
},
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
test('adapts one exact endpoint-neutral response without interpreting signed evidence', async () => {
|
|
const requests: unknown[] = [];
|
|
const source = new StrictDomainRuntimeHandoffSource({
|
|
async request(input) {
|
|
requests.push(input);
|
|
return response();
|
|
},
|
|
});
|
|
|
|
const candidate = await source.read(DOMAIN_ID, NODE_ID);
|
|
|
|
assert.deepEqual(requests, [{ domainId: DOMAIN_ID, nodeId: NODE_ID }]);
|
|
assert.deepEqual(candidate, {
|
|
handoff: { manifest: { digest: 'untrusted-until-orchestrator-verifies' } },
|
|
signerLookup: { repositoryId: 'REPO-014', signerId: 'GH-LIGHTHOUSE-001' },
|
|
});
|
|
assert.equal(Object.isFrozen(candidate), true);
|
|
assert.equal(Object.isFrozen(candidate?.signerLookup), true);
|
|
});
|
|
|
|
test('rejects malformed, extended and self-authorizing response envelopes', async () => {
|
|
const samples = [
|
|
null,
|
|
response({ extra: true }),
|
|
response({ schema: 'other/v1' }),
|
|
response({ signer_lookup: { repository_id: 'REPO-014', signer_id: 'bad signer' } }),
|
|
response({ signer_lookup: { repository_id: 'REPO-014', signer_id: 'GH-LIGHTHOUSE-001', public_key: 'forbidden' } }),
|
|
response({ handoff: null }),
|
|
];
|
|
let index = 0;
|
|
const source = new StrictDomainRuntimeHandoffSource({
|
|
async request() { return samples[index++]; },
|
|
});
|
|
|
|
for (const _sample of samples) {
|
|
assert.equal(await source.read(DOMAIN_ID, NODE_ID), null);
|
|
}
|
|
});
|
|
|
|
test('fails closed on invalid request identity and transport errors without leaking details', async () => {
|
|
let requests = 0;
|
|
const source = new StrictDomainRuntimeHandoffSource({
|
|
async request() {
|
|
requests += 1;
|
|
throw new Error('secret remote detail');
|
|
},
|
|
});
|
|
|
|
assert.equal(await source.read('bad domain', NODE_ID), null);
|
|
assert.equal(requests, 0);
|
|
assert.equal(await source.read(DOMAIN_ID, NODE_ID), null);
|
|
assert.equal(requests, 1);
|
|
});
|