Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(control-api): type admission fixtures against native contracts
Alfredo Lopez611b49b66966
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 6198436cc..c50986630 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.708",+ "version": "0.1.709","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.708",+ "version": "0.1.709","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",diff --git a/control-api/package.json b/control-api/package.jsonindex 359b6ec2e..a646b73ce 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.708",+ "version": "0.1.709","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/test/llmProviderAttemptBodyAdmission.test.ts b/control-api/test/llmProviderAttemptBodyAdmission.test.tsindex 674f8e317..4a9e2f983 100644--- a/control-api/test/llmProviderAttemptBodyAdmission.test.ts+++ b/control-api/test/llmProviderAttemptBodyAdmission.test.ts@@ -188,14 +188,14 @@ describe('AuthorizeBodyAdmission policy and idempotence', () => {})const req = fakeRequest()const res = fakeResponse()- const parser = vi.fn((_req: unknown, _res: unknown, next: (err?: unknown) => void) => {+ const parser = vi.fn<RequestHandler>((_req, _res, next) => {_req.body = { retained: true }next()next(new Error('duplicate callback'))})const work = vi.fn(async () => undefined)- await gate.run(req as never, res as never, parser as RequestHandler, work)+ await gate.run(req as never, res as never, parser, work)expect(work).toHaveBeenCalledOnce()expect(req.body).toBeUndefined()@@ -277,12 +277,12 @@ describe('AuthorizeBodyAdmission parser lifecycle', () => {const requestLogger = fakeRequestLogger()req.log = requestLogger.loggerconst res = fakeResponse()- const parser = vi.fn((request: FakeRequest, _response: FakeResponse, next: () => void) => {+ const parser = vi.fn<RequestHandler>((request, _response, next) => {request.once('close', next)})const work = vi.fn(async () => undefined)- const running = gate.run(req as never, res as never, parser as RequestHandler, work)+ const running = gate.run(req as never, res as never, parser, work)await vi.waitFor(() => expect(res.body).toEqual({ error: 'request_timeout' }))await running@@ -358,13 +358,13 @@ describe('AuthorizeBodyAdmission parser lifecycle', () => {})const req = fakeRequest()const res = fakeResponse()- const parser = vi.fn((request: FakeRequest, _response: FakeResponse, next: () => void) => {+ const parser = vi.fn<RequestHandler>((request, _response, next) => {request.once('close', next)})const work = vi.fn(async () => undefined)await Promise.all([- gate.run(req as never, res as never, parser as RequestHandler, work),+ gate.run(req as never, res as never, parser, work),Promise.resolve().then(() => res.emit('close')),])@@ -461,7 +461,7 @@ describe('AuthorizeBodyAdmission HTTP fixture', () => {closeGraceMs: 10,})const parser = express.json({ limit: '1kb', inflate: false })- const work = vi.fn(async (req: express.Request, res: Response) => {+ const work = vi.fn(async (req: express.Request, res: Response, _signal: AbortSignal) => {res.status(200).json({ body: req.body })})const app = express()@@ -594,7 +594,7 @@ describe('AuthorizeBodyAdmission HTTP fixture', () => {parserStarted.resolve()parser(req, res, next)}- const work = vi.fn(async (_req: express.Request, res: Response) => {+ const work = vi.fn(async (_req: express.Request, res: Response, _signal: AbortSignal) => {res.status(200).json({ ok: true })})const app = express()diff --git a/control-api/test/routes.mcp-host.llmProviderAttempts.bodyAdmission.test.ts b/control-api/test/routes.mcp-host.llmProviderAttempts.bodyAdmission.test.tsindex 9c35ce4c2..da447aadb 100644--- a/control-api/test/routes.mcp-host.llmProviderAttempts.bodyAdmission.test.ts+++ b/control-api/test/routes.mcp-host.llmProviderAttempts.bodyAdmission.test.ts@@ -112,10 +112,13 @@ async function withApps(}observations.push(observed)const end = res.end- res.end = function (...args: Parameters<typeof res.end>) {+ vi.spyOn(res, 'end').mockImplementation(function (+ this: typeof res,+ ...args: Parameters<typeof res.end>+ ) {if (this.destroyed) observed.responseWritesAfterClose += 1return end.apply(this, args)- } as typeof res.end+ })// Observe read calls and listener installation without adding a data// listener or switching the IncomingMessage into flowing mode.const read = req.read@@ -128,12 +131,15 @@ async function withApps(return value}const on = req.on- req.on = function (event: string, listener: (...args: any[]) => void) {+ vi.spyOn(req, 'on').mockImplementation(function (+ this: typeof req,+ ...[event, listener]: Parameters<typeof req.on>+ ) {if (event === 'data') {observed.bodyDataSubscriptions += 1}return on.call(this, event, listener)- } as typeof req.on+ })app(req, res)}).listen(0)const address = listener.address()@@ -391,12 +397,13 @@ describe('createApp retained authorize-body ownership', () => {// policy remains unchanged; this test makes no numeric safety claim.const clock = vi.spyOn(globalThis, 'setTimeout')- .mockImplementation(((fn, ms, ...args) =>+ .mockImplementation((fn, ms, ...args) =>nativeSetTimeout(fn,ms === LLM_PROVIDER_ATTEMPT_ADMISSION_POLICY.workDeadlineMs ? 40 : ms,...args- )) as typeof setTimeout)+ )+ )vi.mocked(authorizer.authorizeLlmProviderAttempt).mockImplementationOnce(async (_claims, _body, deps) => {const signal = deps?.signal@@ -443,7 +450,7 @@ describe('createApp retained authorize-body ownership', () => {// Contracted clocks are explicit HTTP fixture timing, not runtime policy.const clock = vi.spyOn(globalThis, 'setTimeout')- .mockImplementation(((fn, ms, ...args) =>+ .mockImplementation((fn, ms, ...args) =>nativeSetTimeout(fn,ms === LLM_PROVIDER_ATTEMPT_ADMISSION_POLICY.readDeadlineMs@@ -452,7 +459,8 @@ describe('createApp retained authorize-body ownership', () => {? 10: ms,...args- )) as typeof setTimeout)+ )+ )try {await withApps(1, async ([app]) => {const sent = send(app.url, {diff --git a/control-api/test/routes.mcp-host.llmProviderAttempts.createApp.test.ts b/control-api/test/routes.mcp-host.llmProviderAttempts.createApp.test.tsindex e9e4fefba..bcbd2ce39 100644--- a/control-api/test/routes.mcp-host.llmProviderAttempts.createApp.test.ts+++ b/control-api/test/routes.mcp-host.llmProviderAttempts.createApp.test.ts@@ -178,11 +178,12 @@ describe('createApp authorize parser boundary', () => {await withApp(path, async url => {const parse = vi.spyOn(JSON, 'parse')try {- for (const input of [+ const inputs: Array<{ body: BodyInit; encoding: Record<string, string> }> = [{ body: malformed, encoding: {} },{ body: deep, encoding: {} },{ body: new Uint8Array(gzipSync(plain)), encoding: { 'content-encoding': 'gzip' } },- ]) {+ ]+ for (const input of inputs) {const response = await fetch(url, {method: 'POST',headers: { 'content-type': 'application/json', ...input.encoding },