From d9534be69d1addb67be9d8543c8fae22559d29e3 Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 14 Nov 2026 22:22:42 -0800 Subject: [PATCH] fix(cloud): GH-FETCH-REASON the can't-reach-GitHub notice says why and offers the fix "This workspace can't reach on GitHub right now" with Check again read as transient even when Orca's GitHub app simply can't see the repository. - The doctor's git.fetch failure carries a code from git's own words: remoteDenied, remoteNotFound, remoteUnreachable (none for wording it doesn't know). - The line asks the control plane's repo access, like the push line: - the app can't see the repo: "Orca's GitHub app doesn't have access to ." with Grant access (the app's install page for that repo), or a request to copy for an owner; - the app can see it but GitHub refused this workspace (installed after it started): Restart; - the network, or no answer yet: the old words with Check again. - After Grant access, the recheck drops the line once origin answers. --- .../environment-doctor-git-fetch-code.test.ts | 56 +++++++ .../environment-doctor-git.ts | 34 ++++ .../orca-cloud/CloudSetupNotices.fixture.tsx | 34 +++- .../orca-cloud/CloudSetupNotices.test.tsx | 68 ++++++++ .../orca-cloud/CloudSetupNotices.tsx | 58 +++---- .../orca-cloud/cloud-fetch-notice-line.tsx | 148 ++++++++++++++++++ src/renderer/src/i18n/locales/en.json | 10 +- .../cloud-setup-notice-actions-fetch.test.ts | 73 +++++++++ .../orca-cloud/cloud-setup-notice-actions.ts | 47 ++++-- 9 files changed, 479 insertions(+), 49 deletions(-) create mode 100644 src/main/environment-doctor/environment-doctor-git-fetch-code.test.ts create mode 100644 src/renderer/src/components/orca-cloud/cloud-fetch-notice-line.tsx create mode 100644 src/renderer/src/lib/orca-cloud/cloud-setup-notice-actions-fetch.test.ts diff --git a/src/main/environment-doctor/environment-doctor-git-fetch-code.test.ts b/src/main/environment-doctor/environment-doctor-git-fetch-code.test.ts new file mode 100644 index 00000000000..296b7011035 --- /dev/null +++ b/src/main/environment-doctor/environment-doctor-git-fetch-code.test.ts @@ -0,0 +1,56 @@ +import { describe, expect, it } from 'vitest' +import { fetchFailureCode } from './environment-doctor-git' + +const failed = (stderr: string, timedOut = false) => ({ code: 128, stdout: '', stderr, timedOut }) + +describe('fetchFailureCode (GH-FETCH-REASON)', () => { + it('names access refusals, including the egress firewall 403', () => { + expect( + fetchFailureCode( + failed( + "fatal: unable to access 'https://github.com/stablyai/orca-plugins/': The requested URL returned error: 403" + ) + ) + ).toBe('remoteDenied') + expect( + fetchFailureCode( + failed("fatal: could not read Username for 'https://github.com': terminal prompts disabled") + ) + ).toBe('remoteDenied') + expect( + fetchFailureCode(failed("fatal: Authentication failed for 'https://github.com/o/r.git/'")) + ).toBe('remoteDenied') + }) + + it("names GitHub's not found, which a private repo it won't confirm also gets", () => { + expect( + fetchFailureCode( + failed( + "remote: Repository not found.\nfatal: repository 'https://github.com/o/r.git/' not found" + ) + ) + ).toBe('remoteNotFound') + }) + + it('names the network: DNS, connect, timeouts', () => { + expect( + fetchFailureCode( + failed( + "fatal: unable to access 'https://github.com/o/r.git/': Could not resolve host: github.com" + ) + ) + ).toBe('remoteUnreachable') + expect( + fetchFailureCode( + failed( + "fatal: unable to access 'https://github.com/o/r.git/': Failed to connect to github.com port 443" + ) + ) + ).toBe('remoteUnreachable') + expect(fetchFailureCode(failed('', true))).toBe('remoteUnreachable') + }) + + it('leaves wording it does not know without a code', () => { + expect(fetchFailureCode(failed('fatal: something new'))).toBeUndefined() + }) +}) diff --git a/src/main/environment-doctor/environment-doctor-git.ts b/src/main/environment-doctor/environment-doctor-git.ts index 9bb6e3f0e58..e1abcc31253 100644 --- a/src/main/environment-doctor/environment-doctor-git.ts +++ b/src/main/environment-doctor/environment-doctor-git.ts @@ -82,6 +82,7 @@ export async function checkGit( // A fetch failure already explains why a push would fail. return [ check('git', 'git.fetch', 'fail', `Cannot reach remote "${remote}".`, { + code: fetchFailureCode(fetch), remediation: withOutputTail( 'Check network access and Git credentials for this environment.', fetch @@ -115,6 +116,39 @@ export async function checkGit( return checks } +/** + * Why `git ls-remote` failed, from git's own words (GH-FETCH-REASON), so the workspace can say + * whether it's access (nothing to wait for) or the network (Check again). `remoteDenied`: 401/403 or + * no credential to send. `remoteNotFound`: GitHub's answer for a private repo it won't confirm, too. + * `remoteUnreachable`: DNS, connect, TLS or a timeout. Unknown wording carries no code. + */ +export type GitFetchFailureCode = 'remoteDenied' | 'remoteNotFound' | 'remoteUnreachable' + +export function fetchFailureCode( + result: EnvironmentDoctorCommandResult +): GitFetchFailureCode | undefined { + const output = `${result.stderr}\n${result.stdout}` + if (/repository '[^']*' not found|Repository not found|returned error: 404/i.test(output)) { + return 'remoteNotFound' + } + if ( + /returned error: 40[13]|Authentication failed|could not read (Username|Password)|Permission to .* denied|terminal prompts disabled/i.test( + output + ) + ) { + return 'remoteDenied' + } + if ( + result.timedOut || + /Could not resolve host|Failed to connect|Connection (refused|reset|timed out)|Operation timed out|SSL|TLS|Couldn't connect|returned error: 5\d\d/i.test( + output + ) + ) { + return 'remoteUnreachable' + } + return undefined +} + /** Where `git push` would go: pushRemote, then pushDefault, then the upstream remote, then origin. */ async function resolvePushRemote(git: GitRunner): Promise { const config = async (key: string): Promise => { diff --git a/src/renderer/src/components/orca-cloud/CloudSetupNotices.fixture.tsx b/src/renderer/src/components/orca-cloud/CloudSetupNotices.fixture.tsx index 372611c9c35..69b7ca750e9 100644 --- a/src/renderer/src/components/orca-cloud/CloudSetupNotices.fixture.tsx +++ b/src/renderer/src/components/orca-cloud/CloudSetupNotices.fixture.tsx @@ -68,6 +68,10 @@ const TOOL_MISSING: CloudSetupNotice = { } } +function fetchWith(code: string): CloudSetupNotice { + return { ...FETCH, check: { ...FETCH.check, code } } +} + function notices( list: readonly CloudSetupNotice[], options: { @@ -92,7 +96,8 @@ function notices( runSetup: noop, dismiss: noop, recheckFetch: noop, - checkingFetch: options.checkingFetch ?? false + checkingFetch: options.checkingFetch ?? false, + restart: noop } ) } @@ -142,7 +147,30 @@ export const setupOnly = cards([notices([SETUP])]) /** One family (DS-q): the action-required prompt and the warning, same chrome. */ export const agentAndPush = cards([AGENT, notices([PUSH, SETUP])]) /** ENV-ORIGIN-TOAST: origin still unreachable after two confirming checks; Check again re-runs it. */ -export const fetchFailed = cards([notices([FETCH])]) -export const fetchChecking = cards([notices([FETCH], { checkingFetch: true })]) +export const fetchFailed = cards([notices([fetchWith('remoteUnreachable')], { access: 'granted' })]) +export const fetchChecking = cards([ + notices([fetchWith('remoteUnreachable')], { access: 'granted', checkingFetch: true }) +]) +/** GH-FETCH-REASON: Orca's GitHub app can't see the repository; this person can install it. */ +export const fetchNoAccess = cards([ + notices([fetchWith('remoteDenied')], { + access: 'install', + repoUrl: 'https://github.com/stablyai/orca-plugins' + }) +]) +/** Only an owner can grant it: a request to copy. */ +export const fetchNoAccessOwnerOnly = cards([ + notices([fetchWith('remoteNotFound')], { + access: 'cantInstall', + repoUrl: 'https://github.com/octocat/Hello-World' + }) +]) +/** The app was installed after this workspace started: Restart picks it up. */ +export const fetchNeedsRestart = cards([ + notices([fetchWith('remoteDenied')], { + access: 'granted', + repoUrl: 'https://github.com/stablyai/orca-plugins' + }) +]) /** ENV-BUILD-CHURN: started without the environment's setup while it updates for a security fix. */ export const environmentHeld = cards([notices([HELD])]) diff --git a/src/renderer/src/components/orca-cloud/CloudSetupNotices.test.tsx b/src/renderer/src/components/orca-cloud/CloudSetupNotices.test.tsx index 6e6166a2273..db29a538e2e 100644 --- a/src/renderer/src/components/orca-cloud/CloudSetupNotices.test.tsx +++ b/src/renderer/src/components/orca-cloud/CloudSetupNotices.test.tsx @@ -18,6 +18,8 @@ vi.mock('@/lib/orca-cloud/cloud-push-access', () => ({ vi.mock('@/lib/orca-cloud/use-orca-cloud-repo-access', () => ({ fetchOrcaCloudRepoAccess: async () => null })) +const { restart } = vi.hoisted(() => ({ restart: vi.fn() })) +vi.mock('./use-cloud-panel-actions', () => ({ useConfirmedRestart: () => restart })) vi.mock('@/store', () => ({ useAppStore: (select: (state: unknown) => unknown) => select({ ephemeralVmRuntimesByWorkspaceId: { w1: { runtimeEnvironmentId: 'env-1' } } }) @@ -137,6 +139,72 @@ describe('CloudSetupNoticesDock (DS-o, DS-q)', () => { }) }) +describe('the can’t-reach line says why (GH-FETCH-REASON)', () => { + const fetchNotice = (code?: string): CloudSetupNotice => ({ + id: 'git.fetch', + kind: 'fetch', + check: { + id: 'git.fetch', + category: 'git', + status: 'fail', + message: 'Cannot reach remote "origin".', + ...(code ? { code } : {}) + } + }) + const show = async (access: string, code?: string) => { + pushAccess.mockResolvedValue(access) + setCloudSetupNotices({ + environmentId: 'env-1', + path: '/w', + repoId: 'r', + hostId: null, + repoUrl: 'https://github.com/stablyai/orca-plugins', + notices: [fetchNotice(code)] + }) + render() + await act(async () => {}) + const [, shown] = stack.show.mock.calls.at(-1) ?? [] + return shown.lines[0] + } + afterEach(() => pushAccess.mockReset()) + + it('the app can’t see the repo and this person can install: says so, with Grant access', async () => { + const line = await show('install', 'remoteDenied') + expect(line.text).toBe('Orca’s GitHub app doesn’t have access to stablyai/orca-plugins.') + expect(line.description).toBe('Pulls and pushes won’t work until it does.') + expect(line.action).toMatchObject({ label: 'Grant access' }) + expect(line.text).not.toContain('right now') + }) + + it('only an owner can grant it: a request to copy, no Grant access', async () => { + const line = await show('cantInstall') + expect(line.text).toBe('Orca’s GitHub app doesn’t have access to stablyai/orca-plugins.') + expect(line.description).toBe( + 'Only an owner of stablyai can grant it. Pulls and pushes won’t work until they do.' + ) + expect(line.action).toMatchObject({ label: 'Copy request for an owner' }) + }) + + it('the app can see it but GitHub refused this workspace: Restart', async () => { + const line = await show('granted', 'remoteDenied') + expect(line.text).toBe('This workspace can’t use Orca’s access to stablyai/orca-plugins yet.') + expect(line.action).toMatchObject({ label: 'Restart' }) + line.action.onClick() + expect(restart).toHaveBeenCalled() + }) + + it('the network: still “right now” with Check again, whatever the app can see', async () => { + const line = await show('install', 'remoteUnreachable') + expect(line.text).toBe('This workspace can’t reach stablyai/orca-plugins on GitHub right now.') + expect(line.action).toMatchObject({ label: 'Check again' }) + }) + + it('an older doctor (no reason) with the app granted keeps Check again', async () => { + const line = await show('granted') + expect(line.action).toMatchObject({ label: 'Check again' }) + }) +}) + const PUSH: CloudSetupNotice = { id: 'git.push', kind: 'push', diff --git a/src/renderer/src/components/orca-cloud/CloudSetupNotices.tsx b/src/renderer/src/components/orca-cloud/CloudSetupNotices.tsx index 1b32da0db94..9fbc37745b1 100644 --- a/src/renderer/src/components/orca-cloud/CloudSetupNotices.tsx +++ b/src/renderer/src/components/orca-cloud/CloudSetupNotices.tsx @@ -1,6 +1,6 @@ import { runEnvironmentSetup } from '@/lib/orca-cloud/cloud-environment-held' import React, { useEffect, useRef, useState } from 'react' -import { Loader2, Play, RefreshCw } from 'lucide-react' +import { Play } from 'lucide-react' import { useAppStore } from '@/store' import { useTranslate, type Translate } from '@/i18n/use-translate' import { @@ -13,11 +13,13 @@ import { visibleCloudSetupNotices, type CloudSetupNoticesRecord } from '@/lib/orca-cloud/cloud-setup-notices-store' -import { repoSlug, runCloudSetupScript } from '@/lib/orca-cloud/cloud-setup-notice-actions' +import { runCloudSetupScript } from '@/lib/orca-cloud/cloud-setup-notice-actions' import { recheckCloudFetch } from '@/lib/orca-cloud/cloud-fetch-notice' import { runVmEnvironmentCheck } from '@/runtime/ephemeral-vm/ephemeral-vm-environment-check' import { hideCloudToast, showCloudToast, type CloudToastView } from './cloud-toast-stack' import { cloudPushNoticeLine, type CloudPushLineHandlers } from './cloud-push-notice-line' +import { cloudFetchNoticeLine } from './cloud-fetch-notice-line' +import { useConfirmedRestart } from './use-cloud-panel-actions' import { useCloudPushNotice } from './use-cloud-push-notice' export type CloudSetupNoticeLine = { @@ -37,6 +39,8 @@ export type CloudSetupNoticeHandlers = { runSetup: () => void recheckFetch?: () => void checkingFetch?: boolean + /** Restart the workspace (asks first while agents work): the fetch line's fix after an install. */ + restart?: () => void } export function cloudSetupNoticeLine( @@ -49,33 +53,18 @@ export function cloudSetupNoticeLine( case 'push': return cloudPushNoticeLine(record.repoUrl, t, handlers.push) case 'fetch': - // ENV-ORIGIN-TOAST: shown only after a confirming check also failed; Check again re-runs it. - return { - text: record.repoUrl - ? t( - 'orcaCloud.setupNotices.fetchFailed', - 'This workspace can’t reach {{repo}} on GitHub right now.', - { repo: repoSlug(record.repoUrl) } - ) - : t( - 'orcaCloud.setupNotices.fetchFailedNoRepo', - 'This workspace can’t reach its Git remote right now.' - ), - description: t( - 'orcaCloud.setupNotices.fetchFailedMeaning', - 'Pulls and pushes won’t work until it can.' - ), - action: handlers.recheckFetch - ? { - label: handlers.checkingFetch - ? t('orcaCloud.setupNotices.checking', 'Checking…') - : t('orcaCloud.setupNotices.checkAgain', 'Check again'), - icon: handlers.checkingFetch ? : , - run: handlers.recheckFetch, - ...(handlers.checkingFetch ? { pending: true } : {}) - } - : null - } + // ENV-ORIGIN-TOAST: shown only after a confirming check also failed. GH-FETCH-REASON: the + // words and the action follow why (no app access, needs a restart, or the network). + return cloudFetchNoticeLine(notice.check, record.repoUrl, t, { + access: handlers.push.access, + install: handlers.push.install, + installing: handlers.push.installing, + copyRequest: handlers.push.copyRequest, + ...(handlers.push.copied ? { copied: true } : {}), + ...(handlers.restart ? { restart: handlers.restart } : {}), + ...(handlers.recheckFetch ? { recheck: handlers.recheckFetch } : {}), + ...(handlers.checkingFetch ? { checking: true } : {}) + }) case 'environmentHeld': // ENV-BUILD-CHURN (d): started without the environment's setup while it updates for a security fix. return { @@ -182,6 +171,7 @@ export function cloudSetupNoticesView( dismiss: (noticeId: string) => void recheckFetch?: () => void checkingFetch?: boolean + restart?: () => void } ): CloudToastView { return { @@ -192,7 +182,8 @@ export function cloudSetupNoticesView( push: handlers.push, runSetup: () => handlers.runSetup(notice.id), ...(handlers.recheckFetch ? { recheckFetch: handlers.recheckFetch } : {}), - ...(handlers.checkingFetch ? { checkingFetch: true } : {}) + ...(handlers.checkingFetch ? { checkingFetch: true } : {}), + ...(handlers.restart ? { restart: handlers.restart } : {}) }) return { key: notice.id, @@ -228,12 +219,14 @@ export function CloudSetupNoticesDock({ workspaceId }: { workspaceId: string }): const snapshot = useCloudSetupNoticesSnapshot() const record = environmentId ? snapshot.records[environmentId] : undefined const notices = visibleCloudSetupNotices(snapshot, environmentId) + // The fetch line asks the same question (GH-FETCH-REASON): can Orca's GitHub app see the repo? const push = useCloudPushNotice( environmentId, record?.repoUrl ?? null, - notices.some((notice) => notice.kind === 'push') + notices.some((notice) => notice.kind === 'push' || notice.kind === 'fetch') ) const fetch = useFetchRecheck(environmentId) + const restart = useConfirmedRestart(workspaceId) const toastId = environmentId ? cloudSetupToastId(environmentId) : null const shown = Boolean(record) && notices.length > 0 // Showing the same id again updates the toast in place (installing state, a dismissed line). @@ -256,7 +249,8 @@ export function CloudSetupNoticesDock({ workspaceId }: { workspaceId: string }): : runCloudSetupScript(workspaceId, record, noticeId)), dismiss: (noticeId) => dismissCloudSetupNotice(record.environmentId, noticeId), recheckFetch: fetch.recheck, - checkingFetch: fetch.checking + checkingFetch: fetch.checking, + restart }), // N-03: only over its own workspace; never over Settings or another workspace. { scope: { workspaceId } } diff --git a/src/renderer/src/components/orca-cloud/cloud-fetch-notice-line.tsx b/src/renderer/src/components/orca-cloud/cloud-fetch-notice-line.tsx new file mode 100644 index 00000000000..3595767a03a --- /dev/null +++ b/src/renderer/src/components/orca-cloud/cloud-fetch-notice-line.tsx @@ -0,0 +1,148 @@ +// The "can't reach origin" line (GH-FETCH-REASON). "Can't reach … right now" with Check again reads +// as transient, so it's kept for what is: the network, or no answer yet. Where Orca's GitHub app +// can't see the repository, the line says so and offers what fixes it (Grant access, or a request +// for an owner). Where the app can see it but this workspace still can't, it says Restart. +import { Check, Copy, GitPullRequestArrow, Loader2, RefreshCw, RotateCw } from 'lucide-react' +import type { Translate } from '@/i18n/use-translate' +import { repoOwner, repoSlug } from '@/lib/orca-cloud/cloud-setup-notice-actions' +import type { CloudPushAccess } from '@/lib/orca-cloud/cloud-push-access' +import { ownerRequestLabel } from '@/lib/orca-cloud/owner-request' +import type { EnvironmentDoctorCheck } from '../../../../shared/environment-doctor-types' +import type { CloudSetupNoticeLine } from './CloudSetupNotices' + +export type CloudFetchLineHandlers = { + /** What the control plane says about Orca's GitHub app and this repository. */ + access: CloudPushAccess + install: () => void + installing: boolean + copyRequest: () => void + copied?: boolean + restart?: () => void + recheck?: () => void + checking?: boolean +} + +/** The doctor's reason (GH-FETCH-REASON): git refused, or said the repository isn't there. */ +function refusedByGitHub(check: EnvironmentDoctorCheck): boolean { + return check.code === 'remoteDenied' || check.code === 'remoteNotFound' +} + +function transientLine( + repoUrl: string | null, + t: Translate, + h: CloudFetchLineHandlers +): CloudSetupNoticeLine { + return { + text: repoUrl + ? t( + 'orcaCloud.setupNotices.fetchFailed', + 'This workspace can’t reach {{repo}} on GitHub right now.', + { repo: repoSlug(repoUrl) } + ) + : t( + 'orcaCloud.setupNotices.fetchFailedNoRepo', + 'This workspace can’t reach its Git remote right now.' + ), + description: t( + 'orcaCloud.setupNotices.fetchFailedMeaning', + 'Pulls and pushes won’t work until it can.' + ), + action: h.recheck + ? { + label: h.checking + ? t('orcaCloud.setupNotices.checking', 'Checking…') + : t('orcaCloud.setupNotices.checkAgain', 'Check again'), + icon: h.checking ? : , + run: h.recheck, + ...(h.checking ? { pending: true } : {}) + } + : null + } +} + +export function cloudFetchNoticeLine( + check: EnvironmentDoctorCheck, + repoUrl: string | null, + t: Translate, + h: CloudFetchLineHandlers +): CloudSetupNoticeLine { + // The network (DNS, connect, timeout) is worth a Check again whatever the app can see. + if (!repoUrl || check.code === 'remoteUnreachable') { + return transientLine(repoUrl, t, h) + } + const repo = repoSlug(repoUrl) + const owner = repoOwner(repoUrl) + const noAccess = t( + 'orcaCloud.setupNotices.fetchNoAccess', + 'Orca’s GitHub app doesn’t have access to {{repo}}.', + { repo } + ) + const copyRequest = { + label: ownerRequestLabel(h.copied === true, t), + icon: h.copied ? : , + run: h.copyRequest + } + switch (h.access) { + case 'install': + return { + text: noAccess, + description: t( + 'orcaCloud.setupNotices.fetchNoAccessMeaning', + 'Pulls and pushes won’t work until it does.' + ), + action: { + label: h.installing + ? t('orcaCloud.setupNotices.waitingForGitHub', 'Waiting for GitHub…') + : t('orcaCloud.setupNotices.grantAccess', 'Grant access'), + icon: h.installing ? : , + run: h.install, + pending: h.installing + } + } + case 'requested': + return { + text: noAccess, + description: t( + 'orcaCloud.setupNotices.fetchNoAccessRequested', + 'An owner of {{owner}} has been asked to approve it. Pulls and pushes won’t work until they do.', + { owner } + ), + action: copyRequest + } + case 'cantInstall': + return { + text: noAccess, + description: t( + 'orcaCloud.setupNotices.fetchNoAccessCantInstall', + 'Only an owner of {{owner}} can grant it. Pulls and pushes won’t work until they do.', + { owner } + ), + action: copyRequest + } + case 'granted': + // The app reaches the repository and GitHub still refused: this workspace started without the + // app's credential (it was installed after the start). A restart picks it up. + if (refusedByGitHub(check) && h.restart) { + return { + text: t( + 'orcaCloud.setupNotices.fetchNeedsRestart', + 'This workspace can’t use Orca’s access to {{repo}} yet.', + { repo } + ), + description: t( + 'orcaCloud.setupNotices.fetchNeedsRestartMeaning', + 'Restart the workspace to pick it up. Your files are kept.' + ), + action: { + label: t('orcaCloudWorkspace.restart', 'Restart'), + icon: , + run: h.restart + } + } + } + return transientLine(repoUrl, t, h) + case 'checking': + case 'unknown': + return transientLine(repoUrl, t, h) + } +} diff --git a/src/renderer/src/i18n/locales/en.json b/src/renderer/src/i18n/locales/en.json index b687aa55b74..2fb5d2420eb 100644 --- a/src/renderer/src/i18n/locales/en.json +++ b/src/renderer/src/i18n/locales/en.json @@ -28154,7 +28154,15 @@ "environmentHeld": "Your environment’s setup hasn’t run in this workspace, so dependencies may be missing.", "environmentHeldMeaning": "The environment is rebuilding for a security update. New workspaces get its setup again in a few minutes.", "runSetupNow": "Run setup now", - "environmentSetupUnreadable": "Couldn’t read the environment’s setup. Try again in a moment." + "environmentSetupUnreadable": "Couldn’t read the environment’s setup. Try again in a moment.", + "fetchReady": "This workspace can reach {{repo}} now.", + "fetchNoAccess": "Orca’s GitHub app doesn’t have access to {{repo}}.", + "fetchNoAccessMeaning": "Pulls and pushes won’t work until it does.", + "grantAccess": "Grant access", + "fetchNoAccessRequested": "An owner of {{owner}} has been asked to approve it. Pulls and pushes won’t work until they do.", + "fetchNoAccessCantInstall": "Only an owner of {{owner}} can grant it. Pulls and pushes won’t work until they do.", + "fetchNeedsRestart": "This workspace can’t use Orca’s access to {{repo}} yet.", + "fetchNeedsRestartMeaning": "Restart the workspace to pick it up. Your files are kept." }, "toast": { "dismiss": "Dismiss" diff --git a/src/renderer/src/lib/orca-cloud/cloud-setup-notice-actions-fetch.test.ts b/src/renderer/src/lib/orca-cloud/cloud-setup-notice-actions-fetch.test.ts new file mode 100644 index 00000000000..982703b02e7 --- /dev/null +++ b/src/renderer/src/lib/orca-cloud/cloud-setup-notice-actions-fetch.test.ts @@ -0,0 +1,73 @@ +import { afterEach, describe, expect, it, vi } from 'vitest' + +const { repoAccess, runCheck, toastSuccess } = vi.hoisted(() => ({ + repoAccess: vi.fn(), + runCheck: vi.fn(), + toastSuccess: vi.fn() +})) +vi.mock('./use-orca-cloud-repo-access', () => ({ + fetchOrcaCloudRepoAccess: repoAccess, + invalidateOrcaCloudRepoAccess: vi.fn() +})) +vi.mock('@/runtime/ephemeral-vm/ephemeral-vm-environment-check', () => ({ + runVmEnvironmentCheck: runCheck +})) +vi.mock('@/runtime/repo-hooks/runtime-hooks-client', () => ({ checkRuntimeHooks: vi.fn() })) +vi.mock('@/store', () => ({ useAppStore: { getState: () => ({}) } })) +vi.mock('./orca-cloud-workspace-store', () => ({ cloudWorkspaceApi: () => null })) +vi.mock('sonner', () => ({ toast: { success: toastSuccess, error: vi.fn() } })) + +import { recheckCloudPushAccess } from './cloud-setup-notice-actions' +import { + getCloudSetupNoticesRecord, + resetCloudSetupNotices, + setCloudSetupNotices +} from './cloud-setup-notices-store' + +const FETCH = { + id: 'git.fetch', + kind: 'fetch' as const, + check: { id: 'git.fetch', category: 'git' as const, status: 'fail' as const, message: 'x' } +} + +function seed(): void { + setCloudSetupNotices({ + environmentId: 'env-1', + path: '/w', + repoId: 'r', + hostId: null, + repoUrl: 'https://github.com/stablyai/orca-plugins', + notices: [FETCH] + }) +} + +afterEach(() => { + resetCloudSetupNotices() + vi.clearAllMocks() +}) + +describe('recheckCloudPushAccess covers the can’t-reach line too (GH-FETCH-REASON)', () => { + it('waits while GitHub has not confirmed the install', async () => { + seed() + repoAccess.mockResolvedValue({ access: 'missing' }) + expect(await recheckCloudPushAccess('env-1')).toBe('waiting') + expect(runCheck).not.toHaveBeenCalled() + }) + + it('drops the line once origin answers', async () => { + seed() + repoAccess.mockResolvedValue({ access: 'granted' }) + runCheck.mockResolvedValue({ checks: [{ ...FETCH.check, status: 'pass' }] }) + expect(await recheckCloudPushAccess('env-1')).toBe('granted') + expect(getCloudSetupNoticesRecord('env-1')?.notices ?? []).toEqual([]) + expect(toastSuccess).toHaveBeenCalledWith('This workspace can reach stablyai/orca-plugins now.') + }) + + it('keeps it (refused) when the install landed but this workspace still can’t reach origin', async () => { + seed() + repoAccess.mockResolvedValue({ access: 'granted' }) + runCheck.mockResolvedValue({ checks: [FETCH.check] }) + expect(await recheckCloudPushAccess('env-1')).toBe('refused') + expect(getCloudSetupNoticesRecord('env-1')?.notices).toHaveLength(1) + }) +}) diff --git a/src/renderer/src/lib/orca-cloud/cloud-setup-notice-actions.ts b/src/renderer/src/lib/orca-cloud/cloud-setup-notice-actions.ts index 2de5140dd9d..1161cfcc75d 100644 --- a/src/renderer/src/lib/orca-cloud/cloud-setup-notice-actions.ts +++ b/src/renderer/src/lib/orca-cloud/cloud-setup-notice-actions.ts @@ -46,15 +46,21 @@ export async function openOrcaGitHubAppInstall(repoUrl: string): Promise { const record = getCloudSetupNoticesRecord(environmentId) - if (!record?.repoUrl || !record.notices.some((notice) => notice.kind === 'push')) { + const watched = new Set( + (record?.notices ?? []) + .filter((notice) => notice.kind === 'push' || notice.kind === 'fetch') + .map((notice) => notice.kind) + ) + if (!record?.repoUrl || watched.size === 0) { return 'granted' } invalidateOrcaCloudRepoAccess(record.repoUrl) @@ -63,21 +69,36 @@ export async function recheckCloudPushAccess( return 'waiting' } const result = await runVmEnvironmentCheck(null, environmentId, record.path) - const push = result.checks.find((check) => check.id === 'git.push') - const current = getCloudSetupNoticesRecord(environmentId) - if (!push || push.status === 'fail') { - return 'refused' + const passed = (id: string): boolean => { + const check = result.checks.find((candidate) => candidate.id === id) + return Boolean(check) && check!.status !== 'fail' } - if (current) { + const cleared = new Set() + if (watched.has('fetch') && passed('git.fetch')) { + cleared.add('fetch') + } + // A push is only checked once origin answers: a fetch failure stops the doctor before it. + if (watched.has('push') && passed('git.push')) { + cleared.add('push') + } + const current = getCloudSetupNoticesRecord(environmentId) + if (current && cleared.size > 0) { setCloudSetupNotices({ ...current, - notices: current.notices.filter((notice) => notice.kind !== 'push') + notices: current.notices.filter((notice) => !cleared.has(notice.kind)) }) } + if (cleared.size < watched.size) { + return 'refused' + } toast.success( - translate('orcaCloud.setupNotices.pushReady', 'Orca Cloud can push to {{repo}} now.', { - repo: repoSlug(record.repoUrl) - }) + watched.has('push') + ? translate('orcaCloud.setupNotices.pushReady', 'Orca Cloud can push to {{repo}} now.', { + repo: repoSlug(record.repoUrl) + }) + : translate('orcaCloud.setupNotices.fetchReady', 'This workspace can reach {{repo}} now.', { + repo: repoSlug(record.repoUrl) + }) ) return 'granted' }