Read chat logs incrementally and drain retention (Refs #62)

This commit is contained in:
2026-10-08 17:28:49 -04:00
parent 0cc4498b53
commit c10f602e8e
18 changed files with 646 additions and 39 deletions
+15 -2
View File
@@ -6,10 +6,10 @@ let fixture: Fixture;
beforeEach(async () => { vi.resetModules(); fixture = await newFixture([]); });
afterEach(async () => { await fixture.cleanup(); });
async function setup() {
async function setup(capabilities: string[] = []) {
const hosts = await import('../../src/lib/server/hosts/index.js');
const host = hosts.createHost({ name: 'Observation host' });
hosts.enrollHost(hosts.createEnrollment(host.id).token, { protocolVersion: 1 });
hosts.enrollHost(hosts.createEnrollment(host.id).token, { protocolVersion: 1, capabilities });
const { db } = await import('../../src/lib/server/db/index.js');
db().prepare("INSERT INTO servers(name) VALUES('test')").run();
db().prepare(`INSERT INTO native_instances(id,server,host_id,library_id,image,port,created_at)
@@ -20,6 +20,19 @@ async function setup() {
}
describe('overlapping native observations', () => {
it.each([false, true])('negotiates incremental log reads with agent support: %s', async incremental => {
const api = await setup(incremental ? ['logs.read-offset'] : []);
const { nativeLogChunk } = await import('../../src/lib/server/backends/files.js');
const cursor = { fileId: '1:2', offset: 3, size: 3, modified: '4', anchorLength: 3, anchorHash: 'hash' };
const request = nativeLogChunk(join(fixture.t5, 'test', 'logs/games_sp.log'), cursor);
const operation = api.listHostOperations(api.host.id)[0];
expect(operation.payload).toEqual({ path: 'logs/games_sp.log', ...(incremental ? { mode: 'incremental', cursor } : { lines: 2000 }) });
const result = incremental ? { contentBase64: '', cursor, reset: false } : { lines: ['legacy tail'] };
api.reportHostOperationStatus(api.host.id, operation.id, { state: 'completed', result });
expect(await request).toEqual(result);
expect(api.getHostOperation(operation.id)?.result).toMatchObject({ retained: false });
});
it.each(['files.read', 'files.list', 'files.stat', 'files.manifest', 'logs.read', 'instance.inspect'])('shares %s only until completion', async kind => {
const api = await setup();
const requests = Array.from({ length: 4 }, () => api.nativeRequest(api.instance, kind, { path: 'same' }));