Resolve stored blob references when reading agent files
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { join } from 'node:path';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { newFixture, type Fixture } from '../helpers/fixture.js';
|
||||
|
||||
@@ -74,3 +75,40 @@ describe('overlapping native observations', () => {
|
||||
expect(await current).toEqual({ generation: 2 });
|
||||
});
|
||||
});
|
||||
|
||||
describe('native file reads through stored agent receipts', () => {
|
||||
it.each([
|
||||
{ name: 'binary content', content: Buffer.from([0, 255, 1, 128, 10]) },
|
||||
{ name: 'empty content', content: Buffer.alloc(0) }
|
||||
])('resolves $name from a stored blob reference', async ({ content }) => {
|
||||
const api = await setup();
|
||||
const { readFile } = await import('../../src/lib/server/backends/files.js');
|
||||
const reading = readFile(join(fixture.t5, 'test', 'configs/server.cfg'));
|
||||
const operation = api.listHostOperations(api.host.id)[0];
|
||||
expect(operation).toMatchObject({ kind: 'files.read', payload: { path: 'configs/server.cfg' } });
|
||||
api.reportHostOperationStatus(api.host.id, operation.id, {
|
||||
state: 'completed', result: { contentBase64: content.toString('base64') }
|
||||
});
|
||||
expect(api.getHostOperationStatus(operation.id)?.result).toEqual({ contentSha256: expect.any(String) });
|
||||
expect(await reading).toEqual(content);
|
||||
});
|
||||
|
||||
it('preserves missing-file errors from the agent', async () => {
|
||||
const api = await setup();
|
||||
const { readFile } = await import('../../src/lib/server/backends/files.js');
|
||||
const reading = expect(readFile(join(fixture.t5, 'test', 'missing'))).rejects.toMatchObject({ code: 'ENOENT' });
|
||||
api.reportHostOperationStatus(api.host.id, api.listHostOperations(api.host.id)[0].id, {
|
||||
state: 'completed', result: { contentBase64: null }
|
||||
});
|
||||
await reading;
|
||||
});
|
||||
|
||||
it.each([null, {}, { contentBase64: 123 }, { contentSha256: 123 }])('reports an invalid response for malformed file content: %j', async result => {
|
||||
const api = await setup();
|
||||
const { readFile } = await import('../../src/lib/server/backends/files.js');
|
||||
const reading = expect(readFile(join(fixture.t5, 'test', 'configs/server.cfg')))
|
||||
.rejects.toThrow('Agent returned an invalid response for files.read: configs/server.cfg');
|
||||
api.reportHostOperationStatus(api.host.id, api.listHostOperations(api.host.id)[0].id, { state: 'completed', result });
|
||||
await reading;
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user