Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/server/src/provider/AcpRegistryProbe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)} `,
Expand Down
3 changes: 2 additions & 1 deletion packages/provider-acp-registry/src/server/probe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
88 changes: 88 additions & 0 deletions scripts/scenarios/acp-session-list-keeps-empty-cursor.e2e.ts
Original file line number Diff line number Diff line change
@@ -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();
},
);
Loading