diff --git a/packages/extension/src/kernel-integration/handlers/send-vat-command.ts b/packages/extension/src/kernel-integration/handlers/send-vat-command.ts index 3b45a64fd..2efd68479 100644 --- a/packages/extension/src/kernel-integration/handlers/send-vat-command.ts +++ b/packages/extension/src/kernel-integration/handlers/send-vat-command.ts @@ -1,7 +1,7 @@ import { object } from '@metamask/superstruct'; import { UnsafeJsonStruct } from '@metamask/utils'; import type { Json } from '@metamask/utils'; -import { isKernelCommand, VatIdStruct } from '@ocap/kernel'; +import { isVatCommandPayloadUI, VatIdStruct } from '@ocap/kernel'; import type { Kernel, VatId } from '@ocap/kernel'; import type { MethodSpec, Handler } from '@ocap/rpc-methods'; @@ -29,7 +29,7 @@ export const sendVatCommandHandler: Handler< ...sendVatCommandSpec, hooks: { kernel: true }, implementation: async ({ kernel }, params): Promise<{ result: Json }> => { - if (!isKernelCommand(params.payload)) { + if (!isVatCommandPayloadUI(params.payload)) { throw new Error('Invalid command payload'); } diff --git a/packages/extension/test/e2e/vat-manager.test.ts b/packages/extension/test/e2e/vat-manager.test.ts index 69a916027..fda2e2373 100644 --- a/packages/extension/test/e2e/vat-manager.test.ts +++ b/packages/extension/test/e2e/vat-manager.test.ts @@ -187,6 +187,15 @@ test.describe('Vat Manager', () => { await popupPage.click('button:text("Send")'); await expect(messageOutput).toContainText('"method": "ping",'); await expect(messageOutput).toContainText('{"result":"pong"}'); + // Test deliver command + await clearLogsButton.click(); + await input.fill( + `{ "id": "v1", "payload": { "method": "deliver", "params": ["bringOutYourDead"] } }`, + ); + await popupPage.click('button:text("Send")'); + await expect(messageOutput).toContainText('"method": "deliver",'); + await expect(messageOutput).toContainText('"bringOutYourDead"'); + await expect(messageOutput).toContainText('"result":null}'); }); test('should reload kernel state and load default vats', async () => { diff --git a/packages/kernel/src/index.test.ts b/packages/kernel/src/index.test.ts index 0feabd913..bc02a6c18 100644 --- a/packages/kernel/src/index.test.ts +++ b/packages/kernel/src/index.test.ts @@ -18,6 +18,7 @@ describe('index', () => { 'isKernelCommand', 'isKernelCommandReply', 'isVatCommand', + 'isVatCommandPayloadUI', 'isVatCommandReply', 'isVatConfig', 'isVatId', diff --git a/packages/kernel/src/messages/index.ts b/packages/kernel/src/messages/index.ts index 56ab8d687..fb2313973 100644 --- a/packages/kernel/src/messages/index.ts +++ b/packages/kernel/src/messages/index.ts @@ -10,7 +10,12 @@ export type { KernelCommand, KernelCommandReply } from './kernel.ts'; // Vat commands. -export { VatCommandMethod, isVatCommand, isVatCommandReply } from './vat.ts'; +export { + VatCommandMethod, + isVatCommand, + isVatCommandReply, + isVatCommandPayloadUI, +} from './vat.ts'; export type { VatCommand, VatCommandReply, diff --git a/packages/kernel/src/messages/vat.ts b/packages/kernel/src/messages/vat.ts index 1a54945ef..36db3f48c 100644 --- a/packages/kernel/src/messages/vat.ts +++ b/packages/kernel/src/messages/vat.ts @@ -294,3 +294,12 @@ export type VatReplyParams = Infer< export type VatCommandReturnType = { [Method in keyof typeof VatReplyStructs]: VatReplyParams; }; + +const VatCommandPayloadUIStruct = union([ + VatMethodStructs.ping, + VatMethodStructs.deliver, +]); +export type VatCommandPayloadUI = Infer; +export const isVatCommandPayloadUI = ( + value: unknown, +): value is VatCommandPayloadUI => is(value, VatCommandPayloadUIStruct); diff --git a/vitest.config.ts b/vitest.config.ts index 578d57855..78cea2223 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -88,10 +88,10 @@ export default defineConfig({ lines: 80.33, }, 'packages/kernel/**': { - statements: 86.41, - functions: 92.76, + statements: 86.44, + functions: 92.79, branches: 71.18, - lines: 86.38, + lines: 86.41, }, 'packages/nodejs/**': { statements: 72.91,