Skip to content

Commit 6ae2612

Browse files
sirtimidclaude
andcommitted
fix(ocap-kernel): throw on unknown globals instead of warning
Requesting an unknown global now throws before vat code is evaluated, surfacing misconfigurations immediately rather than silently ignoring them. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 93076c6 commit 6ae2612

2 files changed

Lines changed: 11 additions & 46 deletions

File tree

packages/ocap-kernel/src/vats/VatSupervisor.test.ts

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -179,56 +179,16 @@ describe('VatSupervisor', () => {
179179
expect(supervisor).toBeInstanceOf(VatSupervisor);
180180
});
181181

182-
it('does not warn when all requested globals are known', async () => {
183-
const logger = {
184-
warn: vi.fn(),
185-
error: vi.fn(),
186-
subLogger: vi.fn(() => logger),
187-
} as unknown as Logger;
188-
189-
const mockFetchBlob: FetchBlob = vi.fn().mockResolvedValue({
190-
ok: true,
191-
text: vi.fn().mockResolvedValue(''),
192-
});
193-
194-
const { stream } = await makeVatSupervisor({
195-
logger,
196-
allowedGlobals: { Date: globalThis.Date },
197-
fetchBlob: mockFetchBlob,
198-
});
199-
200-
await stream.receiveInput({
201-
id: 'test-init',
202-
method: 'initVat',
203-
params: {
204-
vatConfig: {
205-
bundleSpec: 'test.bundle',
206-
parameters: {},
207-
globals: ['Date'],
208-
},
209-
state: [],
210-
},
211-
jsonrpc: '2.0',
212-
});
213-
await delay(50);
214-
215-
expect(logger.warn).not.toHaveBeenCalled();
216-
});
217-
218-
it('logs a warning when a vat requests an unknown global', async () => {
219-
const logger = {
220-
warn: vi.fn(),
221-
error: vi.fn(),
222-
subLogger: vi.fn(() => logger),
223-
} as unknown as Logger;
182+
it('throws when a vat requests an unknown global', async () => {
183+
const dispatch = vi.fn();
224184

225185
const mockFetchBlob: FetchBlob = vi.fn().mockResolvedValue({
226186
ok: true,
227187
text: vi.fn().mockResolvedValue(''),
228188
});
229189

230190
const { stream } = await makeVatSupervisor({
231-
logger,
191+
dispatch,
232192
allowedGlobals: { Date: globalThis.Date },
233193
fetchBlob: mockFetchBlob,
234194
});
@@ -248,8 +208,13 @@ describe('VatSupervisor', () => {
248208
});
249209
await delay(50);
250210

251-
expect(logger.warn).toHaveBeenCalledWith(
252-
'Vat "test-id" requested unknown global "UnknownThing"',
211+
expect(dispatch).toHaveBeenCalledWith(
212+
expect.objectContaining({
213+
id: 'test-init',
214+
error: expect.objectContaining({
215+
message: expect.stringContaining('unknown global "UnknownThing"'),
216+
}),
217+
}),
253218
);
254219
});
255220
});

packages/ocap-kernel/src/vats/VatSupervisor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export class VatSupervisor {
324324
if (hasProperty(effectiveAllowedGlobals, name)) {
325325
requestedGlobals[name] = effectiveAllowedGlobals[name];
326326
} else {
327-
this.#logger.warn(
327+
throw new Error(
328328
`Vat "${this.id}" requested unknown global "${name}"`,
329329
);
330330
}

0 commit comments

Comments
 (0)