Skip to content
Merged
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
6 changes: 3 additions & 3 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,10 @@ export async function setup(ctx: Context, options: SetupOptions): Promise<number
const leftBehind: { name: string; server: string }[] = [];
/**
* Removes an agent's authorization on the server that issued it, using that server's sign-in.
* A 403 means this account lost access to its workspace, which revokes it; a switch, where the
* sign-in there may be another account, treats it as unconfirmed instead (`strict`).
* A 403 means this account lost access to its workspace, which revokes it. The sign-in on another
* server, or during a switch, may be a different account, so there a 403 is unconfirmed (`strict`).
*/
const removeRemote = async (link: AgentLink, name: string, strict = false) => {
const removeRemote = async (link: AgentLink, name: string, strict = link.server !== server) => {
const token = link.server === server ? session.token : state.servers[link.server]?.session?.token;
if (!token) {
leftBehind.push({ name, server: link.server });
Expand Down
13 changes: 13 additions & 0 deletions test/targets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,19 @@ describe("agents on several servers", () => {
expect(errors()).toContain(`Could not confirm removal of the old Cursor authorization (agent-1) at ${CLOUD}.`);
});

it("does not treat a 403 from another server as revoked when turning an agent off", async () => {
const { local, ctx, cloud } = await cursorOnCloud({ local: true });
const routed = network(local, cloud);
const { ctx: other } = context(((input: string | URL | Request, init?: RequestInit) =>
init?.method === "DELETE" && String(input).startsWith(CLOUD)
? Promise.resolve(Response.json({ message: "Forbidden" }, { status: 403 }))
: routed(input, init)) as typeof fetch);
await expect(setup({ ...ctx, api: other.api }, { local: true, disable: "cursor" })).rejects.toThrow(
`Disabled locally, but remote cleanup failed. Remove Cursor authorization (agent-1) in the Toolstile dashboard at ${CLOUD}.`,
);
expect(cloud.agents.size).toBe(1);
});

it("says where to remove access it could not revoke", async () => {
const { cloud, ctx, output } = await cursorOnCloud({ local: true });
await logout(ctx, { server: CLOUD });
Expand Down