mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 03:15:01 +00:00
Merge pull request #760 from nwparker/cloud/fetch-access-notice
fix(cloud): GH-FETCH-REASON the can't-reach-GitHub notice says why and offers the fix
This commit is contained in:
@@ -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()
|
||||
})
|
||||
})
|
||||
@@ -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<string | null> {
|
||||
const config = async (key: string): Promise<string | null> => {
|
||||
|
||||
@@ -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])])
|
||||
|
||||
@@ -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(<CloudSetupNoticesDock workspaceId="w1" />)
|
||||
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',
|
||||
|
||||
@@ -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 ? <Loader2 className="animate-spin" /> : <RefreshCw />,
|
||||
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 } }
|
||||
|
||||
@@ -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 ? <Loader2 className="animate-spin" /> : <RefreshCw />,
|
||||
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 ? <Check /> : <Copy />,
|
||||
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 ? <Loader2 className="animate-spin" /> : <GitPullRequestArrow />,
|
||||
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: <RotateCw />,
|
||||
run: h.restart
|
||||
}
|
||||
}
|
||||
}
|
||||
return transientLine(repoUrl, t, h)
|
||||
case 'checking':
|
||||
case 'unknown':
|
||||
return transientLine(repoUrl, t, h)
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
@@ -46,15 +46,21 @@ export async function openOrcaGitHubAppInstall(repoUrl: string): Promise<boolean
|
||||
|
||||
/**
|
||||
* Once the App's installation covers the repository (the install webhook bound it), runs the
|
||||
* sandbox's push check again and drops the notice when the push is now authorized. Returns
|
||||
* 'granted' when the push works, 'waiting' while GitHub hasn't confirmed yet, 'refused' when the
|
||||
* installation landed but the sandbox still can't push.
|
||||
* sandbox's check again and drops the push line, and the can't-reach line (GH-FETCH-REASON), that
|
||||
* pass now. Returns 'granted' when nothing is left failing, 'waiting' while GitHub hasn't confirmed
|
||||
* yet, 'refused' when the installation landed but the sandbox still can't push or reach origin
|
||||
* (a workspace started before the install needs a restart to use it).
|
||||
*/
|
||||
export async function recheckCloudPushAccess(
|
||||
environmentId: string
|
||||
): Promise<'granted' | 'waiting' | 'refused'> {
|
||||
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<string>()
|
||||
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'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user