feat(plugins): add quota-limited session storage API

This commit is contained in:
geracobo
2026-07-25 18:31:44 -06:00
committed by Maurice
parent cc8e4d480e
commit 2068133de2
10 changed files with 243 additions and 23 deletions
+24
View File
@@ -131,6 +131,30 @@ describe('validateManifest', () => {
});
describe('createMockHost', () => {
it('mocks plugin UI session storage with scope isolation and production limits', async () => {
const host = createMockHost({ sessionTripId: 42 });
await host.session.set('filters', ['hotel']);
await host.session.set('filters', ['flight'], { scope: 'trip' });
await expect(host.session.get('filters')).resolves.toEqual(['hotel']);
await expect(host.session.get('filters', { scope: 'trip' })).resolves.toEqual(['flight']);
await expect(host.session.set('x'.repeat(65), true)).rejects.toThrow(/SESSION_INVALID_KEY/);
await expect(host.session.set('large', 'x'.repeat(1024))).rejects.toThrow(/SESSION_VALUE_TOO_LARGE/);
await expect(host.session.set('x'.repeat(64), 'x'.repeat(1022))).resolves.toBeUndefined();
await host.session.clear();
await host.session.clear({ scope: 'trip' });
for (let index = 0; index < 32; index += 1) await host.session.set(`key-${index}`, index);
await expect(host.session.set('key-32', 32)).rejects.toThrow(/SESSION_KEY_LIMIT/);
await expect(host.session.set('trip-key', true, { scope: 'trip' })).resolves.toBeUndefined();
});
it('requires a trip context for trip-scoped mock session storage', async () => {
const { session } = createMockHost();
await expect(session.get('filters', { scope: 'trip' })).rejects.toThrow(/NO_TRIP_CONTEXT/);
});
it('enforces the granted permission set', async () => {
const { ctx } = createMockHost({ grants: ['db:own'] });
await expect(ctx.db.migrate('1', 'CREATE TABLE t (x)')).resolves.toEqual({ applied: true });