Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(github): share compatible active account verification

Dash9721e56f255b
diff --git a/apps/desktop/src/main/__tests__/gitContextGhCliTokenSource.test.ts b/apps/desktop/src/main/__tests__/gitContextGhCliTokenSource.test.ts
index a4b9ca070c..fd525a72b8 100644
--- a/apps/desktop/src/main/__tests__/gitContextGhCliTokenSource.test.ts
+++ b/apps/desktop/src/main/__tests__/gitContextGhCliTokenSource.test.ts
@@ -113,7 +113,7 @@ describe('createGhCliTokenSource', () => {
expect(execFileFn).toHaveBeenCalledTimes(1);
});
- it('可用性探测只执行 gh auth status,不读取或污染 token cache', async () => {
+ it('可用性探测只执行静默账号 API,不读取或污染 token cache', async () => {
const execFileFn = vi.fn(
(
_file: string,
@@ -121,9 +121,9 @@ describe('createGhCliTokenSource', () => {
opts: { timeout: number },
cb: ExecCb,
) => {
- if (args[1] === 'status') {
+ if (args[0] === 'api') {
expect(opts.timeout).toBeLessThanOrEqual(1_000);
- cb(null, 'logged in as octocat', '');
+ cb(null, '', '');
} else {
expect(opts.timeout).toBe(3_000);
cb(null, 'gho_after_probe', '');
@@ -136,7 +136,7 @@ describe('createGhCliTokenSource', () => {
expect(await src.probeAvailability()).toBe(true);
expect(execFileFn).toHaveBeenCalledWith(
expectedGhExecutable,
- ['auth', 'status', '--active', '--hostname', 'github.com'],
+ ['api', '--hostname', 'github.com', 'user', '--silent'],
{ timeout: expect.any(Number) },
expect.any(Function),
);
diff --git a/apps/desktop/src/main/__tests__/githubSetupActiveAccount.test.ts b/apps/desktop/src/main/__tests__/githubSetupActiveAccount.test.ts
index 5655a4c699..be488bfc91 100644
--- a/apps/desktop/src/main/__tests__/githubSetupActiveAccount.test.ts
+++ b/apps/desktop/src/main/__tests__/githubSetupActiveAccount.test.ts
@@ -9,8 +9,12 @@ import { createGhCliTokenSource } from '../git-context/ghCliTokenSource';
it('connects with a valid active account even when a secondary account has expired', async () => {
mocks.execFile.mockImplementation((_binary, args, _options, callback) => {
- const secondaryFailed = args[0] === 'auth' && !args.includes('--active');
- callback(secondaryFailed ? new Error('secondary account expired') : null, '', '');
+ const failure = args.includes('--active')
+ ? 'unknown flag: --active'
+ : args[0] === 'auth'
+ ? 'secondary account expired'
+ : null;
+ callback(failure ? new Error(failure) : null, '', '');
});
mocks.spawn.mockImplementation(() => {
throw new Error('unexpected login');
@@ -28,7 +32,7 @@ it('connects with a valid active account even when a secondary account has expir
expect(await source.probeAvailability()).toBe(true);
expect(mocks.execFile).toHaveBeenCalledWith(
'gh',
- ['auth', 'status', '--active', '--hostname', 'github.com'],
+ ['api', '--hostname', 'github.com', 'user', '--silent'],
expect.any(Object),
expect.any(Function),
);
diff --git a/apps/desktop/src/main/git-context/ghCliTokenSource.ts b/apps/desktop/src/main/git-context/ghCliTokenSource.ts
index 6db649fb20..9d9b9982fe 100644
--- a/apps/desktop/src/main/git-context/ghCliTokenSource.ts
+++ b/apps/desktop/src/main/git-context/ghCliTokenSource.ts
@@ -22,6 +22,9 @@ import { createLogger } from '../logger.js';
import { resolveGhBinary as resolveSharedGhBinary, systemGhBinary } from './ghBinary.js';
const log = createLogger('git-context/gh-cli');
+// Check the active credential without the newer auth status --active flag.
+// --silent discards the account response; callers only consume the exit code.
+export const GH_AUTH_CHECK_ARGS = ['api', '--hostname', 'github.com', 'user', '--silent'];
const DEFAULT_CACHE_TTL_MS = 5 * 60_000;
const DEFAULT_NEGATIVE_CACHE_TTL_MS = 30_000;
@@ -149,7 +152,7 @@ export function createGhCliTokenSource(deps: GhCliTokenSourceDeps = {}): GhCliTo
// stdout/stderr 都不进入日志;该调用只消费退出码,绝不取得 token。
execFileFn(
bin,
- ['auth', 'status', '--active', '--hostname', 'github.com'],
+ GH_AUTH_CHECK_ARGS,
{ timeout: GH_PROBE_TIMEOUT_MS },
(err) => resolve(err === null),
);
diff --git a/apps/desktop/src/main/git-context/githubSetup.ts b/apps/desktop/src/main/git-context/githubSetup.ts
index a2c1401f80..45d30ea70c 100644
--- a/apps/desktop/src/main/git-context/githubSetup.ts
+++ b/apps/desktop/src/main/git-context/githubSetup.ts
@@ -3,6 +3,7 @@ import type { GithubSetupState } from '../../shared/githubSetup.js';
import { installTool } from '../managed-tools/installer.js';
import { ghArtifact, GH_VERSION } from './ghArtifact.js';
import { resolveGhBinary } from './ghBinary.js';
+import { GH_AUTH_CHECK_ARGS } from './ghCliTokenSource.js';
interface SetupDeps {
resolveBinary(): Promise<string>;
@@ -173,8 +174,7 @@ export function createGithubSetup(root: string, connected: () => void): GithubSe
resolveBinary: resolveGhBinary,
available: (binary) => check(binary, ['--version']),
// Token reads use the active account; stale secondary accounts must not block setup.
- authenticated: (binary) =>
- check(binary, ['auth', 'status', '--active', '--hostname', 'github.com']),
+ authenticated: (binary) => check(binary, GH_AUTH_CHECK_ARGS),
login: loginWithGh,
connected,
async install(signal, update) {
diff --git a/docs/dev-rules/verified-downloads.md b/docs/dev-rules/verified-downloads.md
index 010c7c1422..4c1c8d33b7 100644
--- a/docs/dev-rules/verified-downloads.md
+++ b/docs/dev-rules/verified-downloads.md
@@ -61,7 +61,7 @@ Renderer 只接收阶段、进度、设备码和固定 GitHub 授权地址,不
安装、下载、授权和完成各有独立文案与操作。下载复用 `DownloadMeter`,
成功后只提供「完成」,并停止轮询;再次打开不把上一次成功当作新的登录检查结果。
-登录前后用 `gh auth status --active --hostname github.com` 检查当前活动账号,避免失效备用账号干扰;成功后清除 token 和 PR 缓存,
+登录前后及插件探测共用 `gh api --hostname github.com user --silent` 检查当前活动账号,兼容不支持 `auth status --active` 的旧版 gh,也避免失效备用账号干扰;只消费退出码,不读取账号响应或 token。成功后清除 token 和 PR 缓存,
通过 `git-context:github-connected` 立即刷新顶栏及侧栏。缓存代数隔离登录前的在途响应。
安装/登录 IPC 仅限受信本机主窗口,不开放给共享任务或 device-link;SSH/手机远程查看
继续使用被控端现有 PR 查询和刷新通道,不会误操作控制端的 GitHub 账号。