feat(operations): add audited runtime catalog

This commit is contained in:
chick
2026-07-17 09:07:50 +08:00
parent 243565a75e
commit 8018b36adf
15 changed files with 1617 additions and 21 deletions
@@ -10,7 +10,25 @@ import {
} from '../src/index.ts';
import { upstream58e2204Operations } from '../src/upstream-58e2204.ts';
import { operationAcceptanceOverrides58e2204 } from '../src/acceptance-58e2204.ts';
import { operationMetadata58e2204 } from '../src/catalog-metadata-58e2204.ts';
test('generated API catalog is an exact safe projection of the runtime registry', async () => {
const { default: generated } = await import(
'../../../apps/api/src/application/operations/operation-catalog-58e2204.json',
{ with: { type: 'json' } }
);
const expected = listOperations().map(
({ operationId, title, riskLevel, capability, batchable, parameterSchemaId }) => ({
operationId,
title,
riskLevel,
capability,
batchable,
parameterSchemaId,
}),
);
assert.deepEqual(generated, expected);
});
test('runtime registry projects exactly 117 descriptors in stable operationId order', () => {
const listed = listOperations();
assert.equal(listed.length, 117);
@@ -34,13 +52,18 @@ test('runtime registry projects exactly 117 descriptors in stable operationId or
test('runtime construction rejects duplicate rows and missing acceptance overrides', () => {
const rows = upstream58e2204Operations as readonly (typeof upstream58e2204Operations)[number][];
assert.throws(
() => new OperationRegistry([...rows, rows[0]], operationAcceptanceOverrides58e2204),
() =>
new OperationRegistry(
[...rows, rows[0]],
operationAcceptanceOverrides58e2204,
operationMetadata58e2204,
),
/duplicate operationId: getDevice/,
);
const missing = { ...operationAcceptanceOverrides58e2204 };
delete (missing as Record<string, unknown>).getDevice;
assert.throws(
() => new OperationRegistry(rows, missing),
() => new OperationRegistry(rows, missing, operationMetadata58e2204),
/missing acceptance override: getDevice/,
);
});
@@ -86,6 +109,18 @@ test('dedicated auth flows are catalogued but cannot cross executable boundary',
id,
);
}
const malformed = new OperationRegistry(
upstream58e2204Operations.map((row) =>
row.operationId === 'getDevice' ? { ...row, executionPolicy: 'futurePolicy' } : row,
),
operationAcceptanceOverrides58e2204,
operationMetadata58e2204,
);
assert.throws(
() => malformed.requireExecutableOperation('getDevice'),
(error: unknown) =>
error instanceof RuntimeRegistryError && error.code === 'DEDICATED_FLOW_REQUIRED',
);
assert.strictEqual(requireExecutableOperation('getDevice'), requireOperation('getDevice'));
});