Repository navigation
feat(record): read record chains in seq pages (TASK-561) #2963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+224
−18
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0dccb05
feat(record): grant and connector-call lines in the pod's record (TAS…
lilyshen0722 93a17af
fix(record): B3 and B4 read the decider the approval row stored (TASK…
lilyshen0722 56eb269
fix(record): a failed agent lookup keeps the call's lines (TASK-560)
lilyshen0722 d0b4014
test(record): an owner lookup that finds no user keeps the lines too …
lilyshen0722 b3afeab
feat(record): read record chains in seq pages (TASK-561)
lilyshen0722 352b79c
merge main into the TASK-560 grant-record branch (TASK-693)
lilyshen0722 99c022c
fix(record): a task-bound grant gets one grant.issued line (TASK-693)
lilyshen0722 d82a6f0
merge the TASK-560 stack head into the TASK-561 branch (TASK-693)
lilyshen0722 a7a805e
merge main into the TASK-561 branch (TASK-693)
lilyshen0722 3d56dc5
merge main (TASK-560 squash, #2779) into the TASK-561 branch (TASK-693)
lilyshen0722 31e1221
fix(record): an OTLP read with no cursor covers the whole chain (TASK…
lilyshen0722 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
backend/__tests__/unit/routes/podRecords.otlpFullChain.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /** | ||
| * The record route pages the NDJSON read, but ?format=otlp has no paging of | ||
| * its own. An OTLP read with no cursor must cover the whole chain, not the | ||
| * first page, or a long chain exports a silently short trace. | ||
| */ | ||
| const express = require('express'); | ||
| const request = require('supertest'); | ||
|
|
||
| const POD = 'aaaaaaaaaaaaaaaaaaaaaa01'; | ||
| const USER = 'bbbbbbbbbbbbbbbbbbbbbbb1'; | ||
|
|
||
| const mockReadRecordExport = jest.fn(); | ||
| const mockToOtlp = jest.fn(() => ({ resourceSpans: [] })); | ||
|
|
||
| jest.mock('../../../services/recordService', () => ({ | ||
| isRecordEnabled: () => true, | ||
| readRecordExport: (...args) => mockReadRecordExport(...args), | ||
| toOtlp: (...args) => mockToOtlp(...args), | ||
| RecordStoreUnavailableError: class RecordStoreUnavailableError extends Error {}, | ||
| })); | ||
| jest.mock('../../../middleware/dualAuth', () => (req, res, next) => { | ||
| req.userId = USER; | ||
| next(); | ||
| }); | ||
| jest.mock('../../../models/Pod', () => ({ | ||
| findById: () => ({ select: () => ({ lean: async () => ({ _id: POD, type: 'chat', members: [USER] }) }) }), | ||
| })); | ||
| jest.mock('../../../models/Task', () => ({ findOne: jest.fn() })); | ||
| jest.mock('../../../services/dmService', () => ({ canViewPod: async () => true })); | ||
| jest.mock('../../../middleware/ipRateLimit', () => ({ | ||
| cloudflareIpRateLimitKeyGenerator: () => 'test', | ||
| })); | ||
|
|
||
| const router = require('../../../routes/podRecords'); | ||
|
|
||
| const app = express(); | ||
| app.use('/api/pods', router); | ||
|
|
||
| // Three pages of one line each, as readRecordExport returns them. | ||
| const pages = { | ||
| start: { jsonl: '{"seq":1}\n', nextAfter: 1 }, | ||
| 1: { jsonl: '{"seq":2}\n', nextAfter: 2 }, | ||
| 2: { jsonl: '{"seq":3}\n', nextAfter: null }, | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| mockReadRecordExport.mockImplementation(async (_ref, _db, page = {}) => ( | ||
| page.after === undefined ? pages.start : pages[page.after] | ||
| )); | ||
| }); | ||
|
|
||
| describe('GET /api/pods/:podId/record?format=otlp', () => { | ||
| test('an OTLP read with no cursor exports every page of the chain', async () => { | ||
| const res = await request(app).get(`/api/pods/${POD}/record?format=otlp`); | ||
| expect(res.status).toBe(200); | ||
| expect(mockToOtlp).toHaveBeenCalledWith('{"seq":1}\n{"seq":2}\n{"seq":3}\n'); | ||
| }); | ||
|
|
||
| test('a paged NDJSON read still returns one page with its cursor', async () => { | ||
| const res = await request(app).get(`/api/pods/${POD}/record`); | ||
| expect(res.status).toBe(200); | ||
| expect(res.text).toBe('{"seq":1}\n'); | ||
| expect(res.headers['x-record-next-after']).toBe('1'); | ||
| expect(mockReadRecordExport).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| test('an OTLP read with an explicit cursor stays one page', async () => { | ||
| await request(app).get(`/api/pods/${POD}/record?format=otlp&after=1`); | ||
| expect(mockToOtlp).toHaveBeenCalledWith('{"seq":2}\n'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.