diff --git a/apps/server/src/provider/AcpRegistryProbe.test.ts b/apps/server/src/provider/AcpRegistryProbe.test.ts index c243cd1c321f..98ffcb92c0cb 100644 --- a/apps/server/src/provider/AcpRegistryProbe.test.ts +++ b/apps/server/src/provider/AcpRegistryProbe.test.ts @@ -418,6 +418,11 @@ describe("ACP Registry probe", () => { }); it.effect.each([ + { + name: "an empty cursor", + cursor: "", + expected: ["", undefined], + }, { name: "an unaltered cursor at the limit", cursor: ` ${"c".repeat(ACP_REGISTRY_SESSION_CURSOR_MAX_LENGTH - 2)} `, diff --git a/packages/provider-acp-registry/src/server/probe.ts b/packages/provider-acp-registry/src/server/probe.ts index 1db342bfbb38..add0c9e48f87 100644 --- a/packages/provider-acp-registry/src/server/probe.ts +++ b/packages/provider-acp-registry/src/server/probe.ts @@ -904,7 +904,8 @@ export const listAcpRegistrySessions = Effect.fn("AcpRegistryProbe.listSessions" }, ]; }); - const nextCursor = listed.nextCursor || null; + // ACP marks a later page by the presence of `nextCursor`, so an empty one still continues. + const nextCursor = listed.nextCursor ?? null; const isLong = nextCursor !== null && nextCursor.length > ACP_REGISTRY_LEGACY_SESSION_CURSOR_MAX_LENGTH; return AcpRegistryListSessionsResult.make({ diff --git a/scripts/scenarios/acp-session-list-keeps-empty-cursor.e2e.ts b/scripts/scenarios/acp-session-list-keeps-empty-cursor.e2e.ts new file mode 100644 index 000000000000..046075b263aa --- /dev/null +++ b/scripts/scenarios/acp-session-list-keeps-empty-cursor.e2e.ts @@ -0,0 +1,88 @@ +// @effect-diagnostics nodeBuiltinImport:off -- The scenario stages a local ACP executable. +import * as NodePath from "node:path"; + +import { ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts"; +import { expect } from "e2e"; +import * as Effect from "effect/Effect"; + +import { T3_HOME } from "../e2e.config.ts"; +import { rpcClient, runPromise, test, WEB } from "./t3.ts"; + +const ACP = ` +import { createInterface } from "node:readline"; + +const ids = Array.from({ length: 3 }, (_, index) => "sample-conversation-session-" + index); +const nextCursor = ""; +const send = (message) => process.stdout.write(JSON.stringify({ jsonrpc: "2.0", ...message }) + "\\n"); +for await (const line of createInterface({ input: process.stdin })) { + const { id, method, params } = JSON.parse(line); + if (id === undefined) continue; + if (method === "initialize") { + send({ id, result: { + protocolVersion: 1, + agentCapabilities: { loadSession: true, sessionCapabilities: { list: {} } }, + authMethods: [], + } }); + } else if (method === "session/new") { + send({ id, result: { sessionId: "probe" } }); + } else if (method === "session/list" && params.cursor === undefined) { + send({ id, result: { + nextCursor, + sessions: ids.map((sessionId, index) => ({ + sessionId, + cwd: params.cwd, + title: "Native conversation " + (index + 1), + })), + } }); + } else if (method === "session/list" && params.cursor === nextCursor) { + send({ id, result: { + sessions: [{ sessionId: "archived", cwd: params.cwd, title: "Older conversation" }], + } }); + } else { + send({ id, error: method === "session/list" + ? { code: -32602, message: "Invalid session cursor" } + : { code: -32601, message: "Method not found" }, + }); + } +} +`; + +test( + "Load more stays available when an ACP session page has an empty cursor", + WEB, + async ({ t3, app, screen }) => { + const project = await t3.project("demo", { "session-agent.mjs": ACP }); + const instanceId = ProviderInstanceId.make("scenario-empty-session-cursor"); + await runPromise( + Effect.gen(function* () { + const client = yield* rpcClient(T3_HOME, app.baseUrl ?? ""); + yield* client["server.updateSettings"]({ + patch: {}, + providerInstanceMutation: { + operation: "upsert", + instanceId, + instance: { + driver: ProviderDriverKind.make("acpRegistry"), + displayName: "Local Session Agent", + enabled: true, + config: { + source: "local", + commandPath: process.execPath, + commandArgs: [NodePath.join(project, "session-agent.mjs")], + }, + }, + }, + }); + }).pipe(Effect.scoped), + ); + + await t3.open(`/settings/providers?instanceId=${instanceId}`); + await screen.getByRole("button", "List sessions", { exact: true }).tap({ timeout: 60_000 }); + await screen.getByText("Native conversation 1", { exact: true }).waitFor(); + const more = screen.getByRole("button", "Load more", { exact: true }); + await app.screenshot("first-native-session-page"); + expect(await more.isVisible()).toBe(true); + await more.tap(); + await screen.getByText("Older conversation", { exact: true }).waitFor(); + }, +);