refactor(server): centralize daemon-client correlated RPC wiring
What changed: - Added private helper in to centralize request-id resolution, schema parsing, and correlated RPC dispatch defaults. - Migrated checkout/worktree/branch/file-explorer/provider/speech/command request methods to use the helper while preserving existing message types and per-method timeouts. - Added a deterministic unit test covering request/response wiring. Reasoning: - The prior implementation duplicated the same correlated-RPC boilerplate across many methods, increasing maintenance cost and risk of drift. - Centralizing this path reduces logic density and keeps transport behavior consistent. - Additional test coverage protects one of the checkout RPC flows touched by the refactor. Accomplishments for next agent: - Reduced repetitive correlated RPC scaffolding in without changing external behavior. - Verified with workspace typecheck and daemon-client test suite. Challenges / follow-ups for next agent: - remains very large; this commit intentionally scoped to request plumbing only. - Next high-value split is extracting cohesive domains (for example checkout/worktree flows) behind focused modules while keeping wire contracts unchanged.
This commit is contained in:
@@ -347,6 +347,68 @@ describe("DaemonClient", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("requests checkout merge from base via RPC", async () => {
|
||||
const logger = createMockLogger();
|
||||
const mock = createMockTransport();
|
||||
|
||||
const client = new DaemonClient({
|
||||
url: "ws://test",
|
||||
logger,
|
||||
reconnect: { enabled: false },
|
||||
transportFactory: () => mock.transport,
|
||||
});
|
||||
clients.push(client);
|
||||
|
||||
const connectPromise = client.connect();
|
||||
mock.triggerOpen();
|
||||
await connectPromise;
|
||||
|
||||
const promise = client.checkoutMergeFromBase(
|
||||
"/tmp/project",
|
||||
{ baseRef: "main", requireCleanTarget: true },
|
||||
"req-merge-from-base"
|
||||
);
|
||||
|
||||
expect(mock.sent).toHaveLength(1);
|
||||
const request = JSON.parse(mock.sent[0]) as {
|
||||
type: "session";
|
||||
message: {
|
||||
type: "checkout_merge_from_base_request";
|
||||
cwd: string;
|
||||
baseRef?: string;
|
||||
requireCleanTarget?: boolean;
|
||||
requestId: string;
|
||||
};
|
||||
};
|
||||
expect(request.message.type).toBe("checkout_merge_from_base_request");
|
||||
expect(request.message.cwd).toBe("/tmp/project");
|
||||
expect(request.message.baseRef).toBe("main");
|
||||
expect(request.message.requireCleanTarget).toBe(true);
|
||||
expect(request.message.requestId).toBe("req-merge-from-base");
|
||||
|
||||
mock.triggerMessage(
|
||||
JSON.stringify({
|
||||
type: "session",
|
||||
message: {
|
||||
type: "checkout_merge_from_base_response",
|
||||
payload: {
|
||||
cwd: "/tmp/project",
|
||||
requestId: "req-merge-from-base",
|
||||
success: true,
|
||||
error: null,
|
||||
},
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
await expect(promise).resolves.toEqual({
|
||||
cwd: "/tmp/project",
|
||||
requestId: "req-merge-from-base",
|
||||
success: true,
|
||||
error: null,
|
||||
});
|
||||
});
|
||||
|
||||
test("resubscribes checkout diff streams after reconnect", async () => {
|
||||
const logger = createMockLogger();
|
||||
const mock = createMockTransport();
|
||||
|
||||
Reference in New Issue
Block a user