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..f2752817978c3 100644 --- a/packages/source-control-cursor-origin/src/server/OriginCli.ts +++ b/packages/source-control-cursor-origin/src/server/OriginCli.ts @@ -57,13 +57,21 @@ 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)) })), ), }); type OriginAuthStatus = typeof OriginAuthStatusSchema.Type; +/** Origin CLI 2026.11.03 exits 1 on a bare `--json`; it wants the fields named. */ +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..cde0f59d947c7 --- /dev/null +++ b/packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.test.ts @@ -0,0 +1,46 @@ +import { assert, it } from "@effect/vitest"; +import * as Effect from "effect/Effect"; +import * as Layer from "effect/Layer"; +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, + // An API-key sign-in reports no token check. + tokenValid: null, + account: { email: "dev@example.test" }, +}; + +// Origin CLI 2026.11.03 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("recognises a signed-in Origin CLI that requires --json field names", () => + 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"); + }), +); 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 9422cd60b91b7..73ca52d8b152d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2259,6 +2259,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.3)(esbuild@0.28.2)(jiti@2.7.0)(jsdom@30.1.0(@noble/hashes@1.8.0))(playwright@1.64.1)(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