Add canonical websocket method list and runtime coverage test
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
e0a9865d02
commit
2462a90227
4 files changed
+121
-3
No files matched your search
@@ -6,6 +6,8 @@ import {
|
||||
dialogsPickFolderResultSchema,
|
||||
editorIdSchema,
|
||||
shellOpenInEditorInputSchema,
|
||||
WS_NATIVE_API_METHODS,
|
||||
wsNativeApiMethodSchema,
|
||||
} from "./ipc";
|
||||
|
||||
describe("appBootstrapResultSchema", () => {
|
||||
@@ -188,3 +190,19 @@ describe("editor and shell-open schemas", () => {
|
||||
).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("wsNativeApiMethodSchema", () => {
|
||||
it("accepts every declared websocket native API method", () => {
|
||||
for (const method of WS_NATIVE_API_METHODS) {
|
||||
expect(wsNativeApiMethodSchema.parse(method)).toBe(method);
|
||||
}
|
||||
});
|
||||
|
||||
it("rejects unknown websocket native API methods", () => {
|
||||
expect(() => wsNativeApiMethodSchema.parse("providers.abortTurn")).toThrow();
|
||||
});
|
||||
|
||||
it("keeps declared websocket native API methods unique", () => {
|
||||
expect(new Set(WS_NATIVE_API_METHODS).size).toBe(WS_NATIVE_API_METHODS.length);
|
||||
});
|
||||
});
|
||||
@@ -19,6 +19,30 @@ export const EDITORS = [
|
||||
{ id: "file-manager", label: "File Manager", command: null },
|
||||
] as const;
|
||||
|
||||
export const WS_NATIVE_API_METHODS = [
|
||||
"app.bootstrap",
|
||||
"app.health",
|
||||
"todos.list",
|
||||
"todos.add",
|
||||
"todos.toggle",
|
||||
"todos.remove",
|
||||
"dialogs.pickFolder",
|
||||
"terminal.run",
|
||||
"agent.spawn",
|
||||
"agent.kill",
|
||||
"agent.write",
|
||||
"providers.startSession",
|
||||
"providers.sendTurn",
|
||||
"providers.interruptTurn",
|
||||
"providers.respondToRequest",
|
||||
"providers.stopSession",
|
||||
"providers.listSessions",
|
||||
"shell.openInEditor",
|
||||
] as const;
|
||||
|
||||
export type WsNativeApiMethod = (typeof WS_NATIVE_API_METHODS)[number];
|
||||
export const wsNativeApiMethodSchema = z.enum(WS_NATIVE_API_METHODS);
|
||||
|
||||
export type EditorId = (typeof EDITORS)[number]["id"];
|
||||
export const editorIdSchema = z.enum(EDITORS.map((entry) => entry.id) as [EditorId, ...EditorId[]]);
|
||||
|
||||
|
||||
Reference in new issue
Block a user