From 35ee80179f5a08b379db2c36c871f8d6a24547d2 Mon Sep 17 00:00:00 2001 From: Ahmed Bedair Date: Mon, 9 Nov 2026 19:22:54 +0000 Subject: [PATCH 1/4] fix(source-control): Cursor Origin recognises a signed-in CLI `origin auth status --json` exits 1 unless the fields are named, so the connection check read no sign-in and reported "Could not verify Cursor Origin" for a CLI that was installed and signed in. The viewer lookup ran the same command and failed the same way. Both now ask for the three fields the parser reads. Co-Authored-By: Claude --- .../source-control-cursor-origin/package.json | 1 + .../src/server/OriginCli.ts | 10 +++- .../OriginSourceControlProvider.test.ts | 48 +++++++++++++++++++ .../src/server/OriginSourceControlProvider.ts | 2 +- pnpm-lock.yaml | 3 ++ 5 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.test.ts diff --git a/packages/source-control-cursor-origin/package.json b/packages/source-control-cursor-origin/package.json index b15d11bfdb77f..31611103ccf17 100644 --- a/packages/source-control-cursor-origin/package.json +++ b/packages/source-control-cursor-origin/package.json @@ -26,6 +26,7 @@ }, "devDependencies": { "@effect/vitest": "catalog:", + "@t3tools/source-control-testing": "workspace:*", "@types/node": "catalog:", "vite-plus": "catalog:" } diff --git a/packages/source-control-cursor-origin/src/server/OriginCli.ts b/packages/source-control-cursor-origin/src/server/OriginCli.ts index 844fb223fb6f3..7204eb88fd331 100644 --- a/packages/source-control-cursor-origin/src/server/OriginCli.ts +++ b/packages/source-control-cursor-origin/src/server/OriginCli.ts @@ -64,6 +64,14 @@ const OriginAuthStatusSchema = Schema.Struct({ }); type OriginAuthStatus = typeof OriginAuthStatusSchema.Type; +/** `origin` exits 1 on a bare `--json`, so this names the fields `OriginAuthStatusSchema` reads. */ +export const ORIGIN_AUTH_STATUS_ARGS = [ + "auth", + "status", + "--json", + "authenticated,tokenValid,account", +] as const; + export function parseOriginAuthStatus(raw: string): OriginAuthStatus | null { const decoded = decodeJsonResult(OriginAuthStatusSchema)(raw); return Result.isSuccess(decoded) ? decoded.success : null; @@ -382,7 +390,7 @@ const make = Effect.gen(function* () { }); const authStatus = (cwd: string) => - run({ cwd, operation: "authStatus", args: ["auth", "status", "--json"] }).pipe( + run({ cwd, operation: "authStatus", args: ORIGIN_AUTH_STATUS_ARGS }).pipe( Effect.flatMap((result) => { const status = parseOriginAuthStatus(result.stdout); if (status !== null) return Effect.succeed(status); diff --git a/packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.test.ts b/packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.test.ts new file mode 100644 index 0000000000000..3f33a9d4098b0 --- /dev/null +++ b/packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.test.ts @@ -0,0 +1,48 @@ +import { assert, it } from "@effect/vitest"; +import * as Effect from "effect/Effect"; +import * as Layer from "effect/Layer"; +import * as Option from "effect/Option"; +import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner"; +import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost"; + +import * as OriginCli from "./OriginCli.ts"; +import * as OriginSourceControlProvider from "./OriginSourceControlProvider.ts"; + +const signedIn: Record = { + authenticated: true, + authMethod: "oauth", + tokenValid: true, + account: { email: "dev@example.test" }, +}; + +// As the real CLI does, this exits 1 on a bare `--json` and prints only the fields it is asked for. +const origin = (args: ReadonlyArray) => { + if (args[0] === "--version") return TestSourceControlHost.processOutput("2026.11.03"); + const fields = args[args.indexOf("--json") + 1]?.split(",") ?? []; + return fields.length === 0 + ? TestSourceControlHost.processOutput("", { + stderr: "Error: Specify one or more comma-separated fields for `--json`:\n authenticated", + exitCode: ChildProcessSpawner.ExitCode(1), + }) + : TestSourceControlHost.processOutput( + JSON.stringify(Object.fromEntries(fields.map((field) => [field, signedIn[field]]))), + ); +}; + +it.effect("reads the sign-in from an Origin CLI that wants its --json fields named", () => + Effect.gen(function* () { + const discovery = yield* OriginSourceControlProvider.makeDiscovery.pipe( + Effect.provide( + Layer.mergeAll( + Layer.mock(OriginCli.OriginCli)({ personalNamespace: () => Effect.succeed("acme") }), + TestSourceControlHost.layer({ + process: { run: (input) => Effect.succeed(origin(input.args)) }, + }), + ), + ), + ); + const item = yield* discovery.probe("/repo"); + assert.strictEqual(item.auth.status, "authenticated"); + assert.deepStrictEqual(item.auth.account, Option.some("acme")); + }), +); diff --git a/packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.ts b/packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.ts index 6128de0baff4e..5e1a970041731 100644 --- a/packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.ts +++ b/packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.ts @@ -31,7 +31,7 @@ const discovery = { label: "Cursor Origin", executable: OriginCli.ORIGIN_COMMAND, versionArgs: ["--version"], - authArgs: ["auth", "status", "--json"], + authArgs: OriginCli.ORIGIN_AUTH_STATUS_ARGS, parseAuth: (input) => { const status = OriginCli.parseOriginAuthStatus(input.stdout); const account = OriginCli.originAccount(status); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a31789a5863e1..65f66de41a114 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2229,6 +2229,9 @@ importers: '@effect/vitest': specifier: 4.1.2 version: 4.1.2(patch_hash=299510b71c36537a832a67e9d160a5f112a5f326a29e95c41cb45fc8234e47c7)(@astrojs/compiler-rs@0.5.1)(@types/node@24.12.4)(@vitest/browser-playwright@5.0.5)(@vitest/ui@5.0.5)(@volar/typescript@2.4.28(typescript@6.0.3))(bufferutil@4.1.0)(effect@4.1.2)(esbuild@0.28.2)(jiti@2.7.0)(jsdom@30.1.0(@noble/hashes@1.8.0))(playwright@1.60.0)(terser@5.48.0)(typescript@6.0.3)(unrun@0.2.39)(utf-8-validate@6.0.6)(yaml@2.9.0) + '@t3tools/source-control-testing': + specifier: workspace:* + version: link:../source-control-testing '@types/node': specifier: 24.12.4 version: 24.12.4 From 2c2f8796e8014353f319f6827b8e3571744da9b7 Mon Sep 17 00:00:00 2001 From: Ahmed Bedair Date: Mon, 9 Nov 2026 19:40:15 +0000 Subject: [PATCH 2/4] test(source-control): cover Origin account auth field --- .../src/server/OriginSourceControlProvider.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.test.ts b/packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.test.ts index 3f33a9d4098b0..0419f4c858b20 100644 --- a/packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.test.ts +++ b/packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.test.ts @@ -44,5 +44,12 @@ it.effect("reads the sign-in from an Origin CLI that wants its --json fields nam const item = yield* discovery.probe("/repo"); assert.strictEqual(item.auth.status, "authenticated"); assert.deepStrictEqual(item.auth.account, Option.some("acme")); + // Discovery shows the namespace instead, so only the viewer lookup needs the email. + assert.strictEqual( + OriginCli.originAccount( + OriginCli.parseOriginAuthStatus(origin(OriginCli.ORIGIN_AUTH_STATUS_ARGS).stdout), + ), + "dev@example.test", + ); }), ); From 63a18257f15fb4fdf6aebc8da042f6e69a213a2b Mon Sep 17 00:00:00 2001 From: Ahmed Bedair Date: Thu, 12 Nov 2026 22:43:03 +0000 Subject: [PATCH 3/4] fix(source-control): Cursor Origin accepts an API-key sign-in A CURSOR_API_KEY sign-in reports `tokenValid: null`, which the auth status schema rejected, so discovery still showed "Could not verify Cursor Origin". Co-Authored-By: Claude Opus 5.5 --- .../src/server/OriginCli.ts | 2 +- .../OriginSourceControlProvider.test.ts | 47 ++++++++++--------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/packages/source-control-cursor-origin/src/server/OriginCli.ts b/packages/source-control-cursor-origin/src/server/OriginCli.ts index 7204eb88fd331..f8cf87aba88fc 100644 --- a/packages/source-control-cursor-origin/src/server/OriginCli.ts +++ b/packages/source-control-cursor-origin/src/server/OriginCli.ts @@ -57,7 +57,7 @@ export class OriginCliError extends Schema.TaggedError()("Origin /** What `origin auth status --json` reports. Only the fields this package reads. */ const OriginAuthStatusSchema = Schema.Struct({ authenticated: Schema.Boolean, - tokenValid: Schema.optional(Schema.Boolean), + tokenValid: Schema.optional(Schema.NullOr(Schema.Boolean)), account: Schema.optional( Schema.NullOr(Schema.Struct({ email: Schema.optional(Schema.NullOr(Schema.String)) })), ), diff --git a/packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.test.ts b/packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.test.ts index 0419f4c858b20..80032abcd4bf1 100644 --- a/packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.test.ts +++ b/packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.test.ts @@ -8,15 +8,17 @@ import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSour import * as OriginCli from "./OriginCli.ts"; import * as OriginSourceControlProvider from "./OriginSourceControlProvider.ts"; -const signedIn: Record = { +const oauthSignIn: Record = { authenticated: true, authMethod: "oauth", tokenValid: true, account: { email: "dev@example.test" }, }; +// A `CURSOR_API_KEY` sign-in has no token to check. +const apiKeySignIn = { ...oauthSignIn, authMethod: "api-key", tokenValid: null }; // As the real CLI does, this exits 1 on a bare `--json` and prints only the fields it is asked for. -const origin = (args: ReadonlyArray) => { +const origin = (signedIn: Record) => (args: ReadonlyArray) => { if (args[0] === "--version") return TestSourceControlHost.processOutput("2026.11.03"); const fields = args[args.indexOf("--json") + 1]?.split(",") ?? []; return fields.length === 0 @@ -31,25 +33,28 @@ const origin = (args: ReadonlyArray) => { it.effect("reads the sign-in from an Origin CLI that wants its --json fields named", () => Effect.gen(function* () { - const discovery = yield* OriginSourceControlProvider.makeDiscovery.pipe( - Effect.provide( - Layer.mergeAll( - Layer.mock(OriginCli.OriginCli)({ personalNamespace: () => Effect.succeed("acme") }), - TestSourceControlHost.layer({ - process: { run: (input) => Effect.succeed(origin(input.args)) }, - }), + for (const signedIn of [oauthSignIn, apiKeySignIn]) { + const cli = origin(signedIn); + const discovery = yield* OriginSourceControlProvider.makeDiscovery.pipe( + Effect.provide( + Layer.mergeAll( + Layer.mock(OriginCli.OriginCli)({ personalNamespace: () => Effect.succeed("acme") }), + TestSourceControlHost.layer({ + process: { run: (input) => Effect.succeed(cli(input.args)) }, + }), + ), ), - ), - ); - const item = yield* discovery.probe("/repo"); - assert.strictEqual(item.auth.status, "authenticated"); - assert.deepStrictEqual(item.auth.account, Option.some("acme")); - // Discovery shows the namespace instead, so only the viewer lookup needs the email. - assert.strictEqual( - OriginCli.originAccount( - OriginCli.parseOriginAuthStatus(origin(OriginCli.ORIGIN_AUTH_STATUS_ARGS).stdout), - ), - "dev@example.test", - ); + ); + const item = yield* discovery.probe("/repo"); + assert.strictEqual(item.auth.status, "authenticated", `${signedIn.authMethod}`); + assert.deepStrictEqual(item.auth.account, Option.some("acme")); + // Discovery shows the namespace instead, so only the viewer lookup needs the email. + assert.strictEqual( + OriginCli.originAccount( + OriginCli.parseOriginAuthStatus(cli(OriginCli.ORIGIN_AUTH_STATUS_ARGS).stdout), + ), + "dev@example.test", + ); + } }), ); From a7e00b4b9b5308a85e7fd492b9802e0fb3fe0de5 Mon Sep 17 00:00:00 2001 From: Ahmed Bedair Date: Sun, 22 Nov 2026 05:51:16 +0000 Subject: [PATCH 4/4] test(source-control): cover expired and signed-out Origin auth states --- .../OriginSourceControlProvider.test.ts | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.test.ts b/packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.test.ts index 80032abcd4bf1..aac4970ca3d40 100644 --- a/packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.test.ts +++ b/packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.test.ts @@ -16,9 +16,11 @@ const oauthSignIn: Record = { }; // A `CURSOR_API_KEY` sign-in has no token to check. const apiKeySignIn = { ...oauthSignIn, authMethod: "api-key", tokenValid: null }; +const expiredToken = { ...oauthSignIn, authMethod: "expired", tokenValid: false }; +const signedOut = { authenticated: false, authMethod: "none", tokenValid: null, account: null }; // As the real CLI does, this exits 1 on a bare `--json` and prints only the fields it is asked for. -const origin = (signedIn: Record) => (args: ReadonlyArray) => { +const origin = (status: Record) => (args: ReadonlyArray) => { if (args[0] === "--version") return TestSourceControlHost.processOutput("2026.11.03"); const fields = args[args.indexOf("--json") + 1]?.split(",") ?? []; return fields.length === 0 @@ -27,15 +29,14 @@ const origin = (signedIn: Record) => (args: ReadonlyArray [field, signedIn[field]]))), + JSON.stringify(Object.fromEntries(fields.map((field) => [field, status[field]]))), ); }; it.effect("reads the sign-in from an Origin CLI that wants its --json fields named", () => Effect.gen(function* () { - for (const signedIn of [oauthSignIn, apiKeySignIn]) { - const cli = origin(signedIn); - const discovery = yield* OriginSourceControlProvider.makeDiscovery.pipe( + const probeWith = (cli: ReturnType) => + OriginSourceControlProvider.makeDiscovery.pipe( Effect.provide( Layer.mergeAll( Layer.mock(OriginCli.OriginCli)({ personalNamespace: () => Effect.succeed("acme") }), @@ -44,8 +45,12 @@ it.effect("reads the sign-in from an Origin CLI that wants its --json fields nam }), ), ), + Effect.flatMap((discovery) => discovery.probe("/repo")), ); - const item = yield* discovery.probe("/repo"); + + for (const signedIn of [oauthSignIn, apiKeySignIn]) { + const cli = origin(signedIn); + const item = yield* probeWith(cli); assert.strictEqual(item.auth.status, "authenticated", `${signedIn.authMethod}`); assert.deepStrictEqual(item.auth.account, Option.some("acme")); // Discovery shows the namespace instead, so only the viewer lookup needs the email. @@ -56,5 +61,17 @@ it.effect("reads the sign-in from an Origin CLI that wants its --json fields nam "dev@example.test", ); } + + for (const notSignedIn of [expiredToken, signedOut]) { + const cli = origin(notSignedIn); + const item = yield* probeWith(cli); + assert.strictEqual(item.auth.status, "unauthenticated", `${notSignedIn.authMethod}`); + assert.strictEqual( + OriginCli.originAccount( + OriginCli.parseOriginAuthStatus(cli(OriginCli.ORIGIN_AUTH_STATUS_ARGS).stdout), + ), + null, + ); + } }), );