Skip to content

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

TypeScript

test(control-api): r8-l22 cover buffer cap and heartbeat

Josuéd5553495adb1
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 33bf8cf7b..8d910ac94 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.693",
+ "version": "0.1.694",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.693",
+ "version": "0.1.694",
"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 43245081c..31d5b4cab 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.693",
+ "version": "0.1.694",
"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 23ee7a1a1..53b5a6adc 100644
--- a/control-api/test/routes.entityChangeStream.test.ts
+++ b/control-api/test/routes.entityChangeStream.test.ts
@@ -453,6 +453,73 @@ describe('routes/entityChangeStream', () => {
vi.useRealTimers()
})
+ it('closes before writing when the buffered response is already over the byte limit', async () => {
+ serviceMock.readEntityChangeCheckpoint.mockResolvedValue({
+ resyncRequired: false,
+ cursor: CURSOR,
+ scopes: ['gfs'],
+ })
+ const req = new FakeRequest()
+ const res = new FakeResponse()
+ res.writableLength = 64 * 1024
+
+ streamEntityChanges(
+ req as unknown as Request,
+ res as unknown as Response,
+ CURSOR,
+ async () => true,
+ 'operator',
+ 'operator-buffer-limit'
+ )
+
+ try {
+ await vi.waitFor(() => expect(res.writableEnded).toBe(true))
+ expect(res.frames).toEqual([])
+ expect(serviceMock.readEntityChangeCheckpoint).toHaveBeenCalledOnce()
+ } finally {
+ closeActiveEntityChangeStreams()
+ }
+ })
+
+ it('emits an operator heartbeat on the configured cadence without a feed change', async () => {
+ vi.useFakeTimers()
+ serviceMock.readEntityChangeCheckpoint.mockResolvedValue({
+ resyncRequired: false,
+ cursor: CURSOR,
+ scopes: [],
+ })
+ const req = new FakeRequest()
+ const res = new FakeResponse()
+
+ streamEntityChanges(
+ req as unknown as Request,
+ res as unknown as Response,
+ CURSOR,
+ async () => true,
+ 'operator',
+ 'operator-heartbeat'
+ )
+
+ try {
+ await vi.advanceTimersByTimeAsync(0)
+ expect(res.frames).toEqual([])
+ await vi.advanceTimersByTimeAsync(configMock.entityChangeStreamHeartbeatMs)
+
+ expect(res.frames.map(frame => JSON.parse(frame))).toContainEqual(
+ expect.objectContaining({
+ schemaVersion: 1,
+ type: 'heartbeat',
+ cursor: CURSOR,
+ observedAt: expect.any(String),
+ })
+ )
+ } finally {
+ closeActiveEntityChangeStreams()
+ await vi.advanceTimersByTimeAsync(0)
+ vi.useRealTimers()
+ }
+ })
+
it('closes the HTTP response after a timed-out slow-consumer write', async () => {
configMock.entityChangeStreamMaxConnections = 1
configMock.entityChangeStreamMaxConnectionsPerPrincipal = 1