Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(control-api): r7-m10 pin operator stream authorization

Josué2b670b652d4c
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index de260ddcc..9bbbfcc44 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.684",
+ "version": "0.1.685",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.684",
+ "version": "0.1.685",
"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.json
index 399bf509d..957126770 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.684",
+ "version": "0.1.685",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/test/routes.entityChangeStream.test.ts b/control-api/test/routes.entityChangeStream.test.ts
index bec91f875..10d905229 100644
--- a/control-api/test/routes.entityChangeStream.test.ts
+++ b/control-api/test/routes.entityChangeStream.test.ts
@@ -266,4 +266,75 @@ describe('routes/entityChangeStream', () => {
await vi.advanceTimersByTimeAsync(0)
vi.useRealTimers()
})
+
+ it('rechecks authorization before delivering an established operator invalidation', async () => {
+ vi.useFakeTimers()
+ serviceMock.readEntityChangeCheckpoint.mockResolvedValue({
+ resyncRequired: false,
+ cursor: CURSOR,
+ scopes: ['gfs'],
+ })
+ const req = new FakeRequest()
+ const res = new FakeResponse()
+ const isAuthorized = vi.fn().mockResolvedValueOnce(true).mockResolvedValueOnce(false)
+
+ streamEntityChanges(
+ req as unknown as Request,
+ res as unknown as Response,
+ CURSOR,
+ isAuthorized,
+ 'operator'
+ )
+ await vi.advanceTimersByTimeAsync(0)
+
+ expect(res.frames.map(frame => JSON.parse(frame))).toEqual([
+ {
+ schemaVersion: 1,
+ type: 'stream.closing',
+ cursor: CURSOR,
+ reason: 'session_expired',
+ },
+ ])
+ expect(res.writableEnded).toBe(true)
+ expect(res.frames.join('')).not.toContain('scope.invalidated')
+ expect(serviceMock.subscribeEntityChangeFeedWake).toHaveBeenCalledOnce()
+ vi.useRealTimers()
+ })
+
+ it('does not deliver a checkpoint when authorization throws and retries after recovery', async () => {
+ vi.useFakeTimers()
+ serviceMock.readEntityChangeCheckpoint.mockResolvedValue({
+ resyncRequired: false,
+ cursor: CURSOR,
+ scopes: ['gfs'],
+ })
+ const req = new FakeRequest()
+ const res = new FakeResponse()
+ const isAuthorized = vi
+ .fn()
+ .mockResolvedValueOnce(true)
+ .mockRejectedValueOnce(new Error('authorization backend unavailable'))
+ .mockResolvedValue(true)
+
+ streamEntityChanges(
+ req as unknown as Request,
+ res as unknown as Response,
+ CURSOR,
+ isAuthorized,
+ 'operator'
+ )
+ await vi.advanceTimersByTimeAsync(0)
+ expect(res.frames).toEqual([])
+
+ await vi.advanceTimersByTimeAsync(configMock.entityChangeStreamPollMs)
+ expect(res.frames.map(frame => JSON.parse(frame))).toContainEqual({
+ schemaVersion: 1,
+ type: 'scope.invalidated',
+ cursor: CURSOR,
+ scopes: ['gfs'],
+ })
+ closeActiveEntityChangeStreams()
+ await vi.advanceTimersByTimeAsync(0)
+ vi.useRealTimers()
+ })
})