test: cover session search fallback on hub timeout and rejection (#13642)

* feat: add searchable session history

Rebased onto main and updated to supersede the sidebar search dialog
from #13533: the sidebar search icon now opens the indexed command bar
(Cmd/Ctrl+P) instead of a sidebar-local cmdk dialog that eagerly loaded
the entire session history via loadAllSessions(). CommandDialog gains a
shouldFilter passthrough so server-ranked FTS hits are displayed as-is.

* fix: harden session history search

* fix: evict failed restoration sessions from search

* fix: preserve deletion when search eviction fails

* fix: address session search review feedback

* fix: preserve search suppression during reconciliation

* test: cover sidecar search fallback on hub timeout and rejection

The existing search_sessions tests only exercised the index-hit and
empty-index-fallback paths with an immediately-resolved hub reply.
Add coverage for the two other realistic Hub-connection failure
modes the fallback is meant to tolerate: the hub call rejecting, and
the hub call hanging past the 750ms withSearchDeadline race.

---------

Co-authored-by: abeatrix <beatrix@cline.bot>
Co-authored-by: Bee <68532117+abeatrix@users.noreply.github.com>
This commit is contained in:
Harrison
2026-08-28 10:06:47 -07:00
committed by GitHub
parent ce71fe5eb9
commit 1fbcfab05d
@@ -288,6 +288,79 @@ describe("Code sidecar runtime capabilities", () => {
expect(list).toHaveBeenCalledOnce();
});
it("falls back to session metadata when the hub search call rejects", async () => {
const { handleCommand } = await import("./commands");
const { createSidecarContext } = await import("./context");
const ctx = createSidecarContext("/workspace/project");
const command = vi.fn(async () => {
throw new Error("hub connection lost");
});
const list = vi.fn(async () => [
{
sessionId: "session-1",
startedAt: "2026-08-27T12:00:00.000Z",
workspaceRoot: "/workspace/project",
prompt: "generate an image of a puppy",
metadata: { title: "generate an image of a puppy" },
},
]);
ctx.hubClient = { command } as never;
ctx.sessionManager = { list } as never;
const results = (await handleCommand(ctx, "search_sessions", {
query: "generate",
})) as Array<{ sessionId: string; documentId: string }>;
expect(results).toEqual([
expect.objectContaining({
sessionId: "session-1",
documentId: "session-1:metadata",
}),
]);
expect(command).toHaveBeenCalledOnce();
expect(list).toHaveBeenCalledOnce();
});
it("falls back to session metadata when the hub search call exceeds the deadline", async () => {
vi.useFakeTimers();
try {
const { handleCommand } = await import("./commands");
const { createSidecarContext } = await import("./context");
const ctx = createSidecarContext("/workspace/project");
// Never resolves: exercises the withSearchDeadline race timing out
// rather than the hub call rejecting.
const command = vi.fn(() => new Promise(() => {}));
const list = vi.fn(async () => [
{
sessionId: "session-1",
startedAt: "2026-08-27T12:00:00.000Z",
workspaceRoot: "/workspace/project",
prompt: "generate an image of a puppy",
metadata: { title: "generate an image of a puppy" },
},
]);
ctx.hubClient = { command } as never;
ctx.sessionManager = { list } as never;
const pending = handleCommand(ctx, "search_sessions", {
query: "generate",
}) as Promise<Array<{ sessionId: string; documentId: string }>>;
await vi.advanceTimersByTimeAsync(750);
const results = await pending;
expect(results).toEqual([
expect.objectContaining({
sessionId: "session-1",
documentId: "session-1:metadata",
}),
]);
expect(command).toHaveBeenCalledOnce();
expect(list).toHaveBeenCalledOnce();
} finally {
vi.useRealTimers();
}
});
it("forwards raw hub tool updates to attached desktop sessions", async () => {
const { createSidecarContext, handleHubLiveEvent } = await import(
"./context"