Skip to content

Commit 2ad03df

Browse files
authored
fix: Allow sending deliver commands to vats from UI (#479)
1 parent bdfe256 commit 2ad03df

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

packages/extension/src/kernel-integration/handlers/send-vat-command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { object } from '@metamask/superstruct';
22
import { UnsafeJsonStruct } from '@metamask/utils';
33
import type { Json } from '@metamask/utils';
4-
import { isKernelCommand, VatIdStruct } from '@ocap/kernel';
4+
import { isVatCommandPayloadUI, VatIdStruct } from '@ocap/kernel';
55
import type { Kernel, VatId } from '@ocap/kernel';
66
import type { MethodSpec, Handler } from '@ocap/rpc-methods';
77

@@ -29,7 +29,7 @@ export const sendVatCommandHandler: Handler<
2929
...sendVatCommandSpec,
3030
hooks: { kernel: true },
3131
implementation: async ({ kernel }, params): Promise<{ result: Json }> => {
32-
if (!isKernelCommand(params.payload)) {
32+
if (!isVatCommandPayloadUI(params.payload)) {
3333
throw new Error('Invalid command payload');
3434
}
3535

packages/extension/test/e2e/vat-manager.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,15 @@ test.describe('Vat Manager', () => {
187187
await popupPage.click('button:text("Send")');
188188
await expect(messageOutput).toContainText('"method": "ping",');
189189
await expect(messageOutput).toContainText('{"result":"pong"}');
190+
// Test deliver command
191+
await clearLogsButton.click();
192+
await input.fill(
193+
`{ "id": "v1", "payload": { "method": "deliver", "params": ["bringOutYourDead"] } }`,
194+
);
195+
await popupPage.click('button:text("Send")');
196+
await expect(messageOutput).toContainText('"method": "deliver",');
197+
await expect(messageOutput).toContainText('"bringOutYourDead"');
198+
await expect(messageOutput).toContainText('"result":null}');
190199
});
191200

192201
test('should reload kernel state and load default vats', async () => {

packages/kernel/src/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('index', () => {
1818
'isKernelCommand',
1919
'isKernelCommandReply',
2020
'isVatCommand',
21+
'isVatCommandPayloadUI',
2122
'isVatCommandReply',
2223
'isVatConfig',
2324
'isVatId',

packages/kernel/src/messages/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ export type { KernelCommand, KernelCommandReply } from './kernel.ts';
1010

1111
// Vat commands.
1212

13-
export { VatCommandMethod, isVatCommand, isVatCommandReply } from './vat.ts';
13+
export {
14+
VatCommandMethod,
15+
isVatCommand,
16+
isVatCommandReply,
17+
isVatCommandPayloadUI,
18+
} from './vat.ts';
1419
export type {
1520
VatCommand,
1621
VatCommandReply,

packages/kernel/src/messages/vat.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,12 @@ export type VatReplyParams<Method extends keyof typeof VatReplyStructs> = Infer<
294294
export type VatCommandReturnType = {
295295
[Method in keyof typeof VatReplyStructs]: VatReplyParams<Method>;
296296
};
297+
298+
const VatCommandPayloadUIStruct = union([
299+
VatMethodStructs.ping,
300+
VatMethodStructs.deliver,
301+
]);
302+
export type VatCommandPayloadUI = Infer<typeof VatCommandPayloadUIStruct>;
303+
export const isVatCommandPayloadUI = (
304+
value: unknown,
305+
): value is VatCommandPayloadUI => is(value, VatCommandPayloadUIStruct);

vitest.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ export default defineConfig({
8888
lines: 80.33,
8989
},
9090
'packages/kernel/**': {
91-
statements: 86.41,
92-
functions: 92.76,
91+
statements: 86.44,
92+
functions: 92.79,
9393
branches: 71.18,
94-
lines: 86.38,
94+
lines: 86.41,
9595
},
9696
'packages/nodejs/**': {
9797
statements: 72.91,

0 commit comments

Comments
 (0)