Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(tracing): r1-m3 prove replay ordering across pages
Josué2b4d4c5fc233
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex be373522a..d55acd55d 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.522",+ "version": "0.1.523","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.522",+ "version": "0.1.523","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/image-policy": "file:../packages/image-policy",diff --git a/control-api/package.json b/control-api/package.jsonindex f1c4b8132..738922c09 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.522",+ "version": "0.1.523","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/test/db.realPostgresMigration.integration.test.ts b/control-api/test/db.realPostgresMigration.integration.test.tsindex 90ae00da8..9a0253c86 100644--- a/control-api/test/db.realPostgresMigration.integration.test.ts+++ b/control-api/test/db.realPostgresMigration.integration.test.ts@@ -962,6 +962,7 @@ describeRealPostgres('control-api real Postgres migrations', () => {after: null,limit: 50,promptState: 'disabled',+ order: 'latest',})for (const [label, family, filters] of [['administrative_list', 'administrative', { action: ['permission_grant'] }],@@ -2665,6 +2666,7 @@ describeRealPostgres('control-api real Postgres migrations', () => {after: null,limit: 10,promptState: 'disabled',+ order: 'latest',})expect(page.summaries).toHaveLength(1)expect(page.summaries[0]).toMatchObject({diff --git a/control-api/test/services.governedSessionReplay.test.ts b/control-api/test/services.governedSessionReplay.test.tsindex fb8c1bb04..89b7ce559 100644--- a/control-api/test/services.governedSessionReplay.test.ts+++ b/control-api/test/services.governedSessionReplay.test.ts@@ -88,4 +88,43 @@ describe('GovernedSessionReplayService', () => {})).rejects.toBeInstanceOf(GovernedSessionReplayInvalidQueryError)})++ it('preserves the selected order and tie-break anchor across producer pages', async () => {+ const occurredAt = '2026-07-01T01:00:00.000Z'+ for (const scenario of [+ { order: 'latest' as const, sessions: ['session-c', 'session-b', 'session-a'] },+ { order: 'oldest' as const, sessions: ['session-a', 'session-b', 'session-c'] },+ ]) {+ const page = scenario.sessions.map(sessionId => summary(sessionId, occurredAt))+ const anchors = scenario.sessions.map(sessionId => ({+ occurredAt,+ hostRef: 'host-a',+ sessionId,+ }))+ const captureHighWatermark = vi.fn().mockResolvedValue('42')+ const list = vi+ .fn()+ .mockResolvedValueOnce({ summaries: page, anchors })+ .mockResolvedValueOnce({ summaries: [page[2]], anchors: [anchors[2]] })+ const service = new GovernedSessionReplayService({ captureHighWatermark, list } as never)++ const first = await service.list({ filters: FILTERS, limit: 2, order: scenario.order })+ const second = await service.list({+ filters: FILTERS,+ limit: 2,+ order: scenario.order,+ cursor: first.nextCursor!,+ })++ expect([...first.sessions, ...second.sessions].map(session => session.sessionId)).toEqual(+ scenario.sessions+ )+ expect(list.mock.calls[0]?.[0]).toMatchObject({ order: scenario.order, after: undefined })+ expect(list.mock.calls[1]?.[0]).toMatchObject({+ order: scenario.order,+ after: anchors[1],+ highWatermark: '42',+ })+ }+ })})diff --git a/control-api/test/services.governedSessionReplayRepository.test.ts b/control-api/test/services.governedSessionReplayRepository.test.tsindex f7503a37c..8b1c7056d 100644--- a/control-api/test/services.governedSessionReplayRepository.test.ts+++ b/control-api/test/services.governedSessionReplayRepository.test.ts@@ -60,6 +60,7 @@ describe('PostgresGovernedSessionReplayRepository security boundaries', () => {after: null,limit: 20,promptState: 'enabled',+ order: 'latest',})const sql = String(query.mock.calls[0]![0])@@ -225,6 +226,7 @@ describe('PostgresGovernedSessionReplayRepository security boundaries', () => {after: null,limit: 20,promptState: 'enabled',+ order: 'latest',})const sql = String(query.mock.calls[0]![0])@@ -243,6 +245,111 @@ describe('PostgresGovernedSessionReplayRepository security boundaries', () => {})})+ it('paginates both session orders deterministically across equal timestamps', async () => {+ const row = (hostRef: string, sessionId: string, occurredAt: string) => ({+ host_ref: hostRef,+ session_id: sessionId,+ first_occurred_at: occurredAt,+ last_occurred_at: occurredAt,+ origins: ['direct_chat'],+ run_count: 1,+ event_count: 1,+ latest_run_outcome: 'succeeded',+ agent_subjects: [],+ human_subjects: [],+ human_user_ids: [],+ identity_issuers: [],+ human_display_name: null,+ event_human_verified: false,+ tool_calls: 0,+ distinct_tools: 0,+ internal_tool_calls: 0,+ mcp_server_tool_calls: 0,+ workflow_tool_calls: 0,+ unclassified_tool_calls: 0,+ observed_llm_calls: 0,+ metered_token_calls: 0,+ cache_reported_calls: 0,+ input_tokens: '0',+ output_tokens: '0',+ cache_read_tokens: '0',+ cache_write_tokens: '0',+ approvals_requested: 0,+ approvals_approved: 0,+ approvals_denied: 0,+ prompt_count: 0,+ })+ const earlier = '2026-07-14T09:00:00.000Z'+ const later = '2026-07-14T10:00:00.000Z'+ const filters = {+ occurredFrom: '2026-07-14T00:00:00.000Z',+ occurredTo: '2026-07-15T00:00:00.000Z',+ outcome: [],+ sourceService: [],+ sessionId: [],+ hostRef: [],+ humanUserId: [],+ agentSub: [],+ origin: [],+ toolName: [],+ approvalState: [],+ }++ for (const scenario of [+ {+ order: 'latest' as const,+ pages: [+ [row('host-z', 'session-z', later), row('host-b', 'session-b', earlier)],+ [row('host-a', 'session-a', earlier)],+ ],+ expected: ['host-z/session-z', 'host-b/session-b', 'host-a/session-a'],+ operator: '<',+ direction: 'DESC',+ },+ {+ order: 'oldest' as const,+ pages: [+ [row('host-a', 'session-a', earlier), row('host-b', 'session-b', earlier)],+ [row('host-z', 'session-z', later)],+ ],+ expected: ['host-a/session-a', 'host-b/session-b', 'host-z/session-z'],+ operator: '>',+ direction: 'ASC',+ },+ ]) {+ const query = vi+ .fn()+ .mockResolvedValueOnce({ rows: scenario.pages[0] })+ .mockResolvedValueOnce({ rows: scenario.pages[1] })+ const repository = new PostgresGovernedSessionReplayRepository({ query } as never)+ const first = await repository.list({+ filters,+ highWatermark: '10',+ after: null,+ limit: 2,+ promptState: 'disabled',+ order: scenario.order,+ })+ const second = await repository.list({+ filters,+ highWatermark: '10',+ after: first.anchors.at(-1)!,+ limit: 2,+ promptState: 'disabled',+ order: scenario.order,+ })++ expect(+ [...first.summaries, ...second.summaries].map(item => `${item.hostRef}/${item.sessionId}`)+ ).toEqual(scenario.expected)+ const secondSql = String(query.mock.calls[1]![0])+ expect(secondSql).toContain(`(last_occurred_at, host_ref, session_id) ${scenario.operator}`)+ expect(secondSql).toContain(+ `ORDER BY last_occurred_at ${scenario.direction}, host_ref ${scenario.direction}, session_id ${scenario.direction}`+ )+ }+ })+it('attributes observed execution only through the canonical approval id', async () => {const query = vi.fn().mockResolvedValue({ rows: [] })await new PostgresGovernedSessionReplayRepository({ query } as never).readApprovals(