Add runtime app.health API and smoke-test health check

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-09 22:34:36 +00:00
1 parent e2a8f16e9e
commit 9ca17fd398
6 files changed
+69 -2

No files matched your search

+5
View File
@@ -85,3 +85,8 @@ The renderer depends on `nativeApi.providers.*`:
7. `onEvent`
Codex is the only implemented provider right now. `claudeCode` is reserved in contracts/UI but currently returns a not-implemented runtime error.
Runtime app utilities exposed via `nativeApi.app.*`:
1. `bootstrap`
2. `health`
+3
View File
@@ -1,5 +1,6 @@
import type {
AppBootstrapResult,
AppHealthResult,
NativeApi,
ProviderEvent,
WsClientMessage,
@@ -182,6 +183,8 @@ class WsNativeApiClient {
app: {
bootstrap: async () =>
this.request("app.bootstrap").then((value) => value as AppBootstrapResult),
health: async () =>
this.request("app.health").then((value) => value as AppHealthResult),
},
todos: {
list: async () =>
+7 -2
View File
@@ -86,13 +86,18 @@ async function main() {
JSON.stringify({
type: "request",
id: "smoke",
method: "todos.list",
method: "app.health",
}),
);
});
ws.addEventListener("message", (event) => {
const message = JSON.parse(String(event.data));
if (message.type === "response" && message.id === "smoke" && message.ok === true) {
if (
message.type === "response" &&
message.id === "smoke" &&
message.ok === true &&
message.result?.status === "ok"
) {
clearTimeout(timer);
resolve();
}
+35
View File
@@ -224,4 +224,39 @@ describe("runtimeApiServer", () => {
client.socket.close();
});
it("reports runtime health metadata", async () => {
const server = await startRuntimeApiServer({
port: 0,
launchCwd: process.cwd(),
});
servers.push(server);
const client = await connectClient(server.wsUrl);
await client.nextMessage();
const response = await sendRequest(
client.socket,
client.nextMessage,
"health-1",
"app.health",
);
expect(response.ok).toBe(true);
if (!response.ok) {
throw new Error("Expected health response to succeed.");
}
const payload = response.result as {
status: string;
launchCwd: string;
sessionCount: number;
activeClientConnected: boolean;
};
expect(payload.status).toBe("ok");
expect(payload.launchCwd).toBe(process.cwd());
expect(typeof payload.sessionCount).toBe("number");
expect(payload.activeClientConnected).toBe(true);
client.socket.close();
});
});
+11
View File
@@ -8,6 +8,7 @@ import {
EDITORS,
DEFAULT_MODEL,
type AppBootstrapResult,
type AppHealthResult,
type ProviderSession,
type WsClientMessage,
type WsResponseMessage,
@@ -359,6 +360,16 @@ export async function startRuntimeApiServer(
return payload;
}
if (method === "app.health") {
const payload: AppHealthResult = {
status: "ok",
launchCwd,
sessionCount: providerManager.listSessions().length,
activeClientConnected: activeClient !== null,
};
return payload;
}
if (method === "todos.list") return todoStore.list();
if (method === "todos.add") return todoStore.add(newTodoInputSchema.parse(params));
if (method === "todos.toggle") return todoStore.toggle(todoIdSchema.parse(params));
+8
View File
@@ -29,9 +29,17 @@ export interface AppBootstrapResult {
bootstrapError?: string;
}
export interface AppHealthResult {
status: "ok";
launchCwd: string;
sessionCount: number;
activeClientConnected: boolean;
}
export interface NativeApi {
app: {
bootstrap: () => Promise<AppBootstrapResult>;
health: () => Promise<AppHealthResult>;
};
todos: {
list: () => Promise<Todo[]>;