mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 10:58:10 +00:00
Skills: keep the review-again state when re-resolving fails; one link stop at a time
This commit is contained in:
@@ -145,4 +145,32 @@ describe('SkillInstallDialog', () => {
|
||||
)
|
||||
expect(skills.installShare).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('keeps asking for review when the updated link can no longer be resolved', async () => {
|
||||
const skills = installApi(
|
||||
vi.fn().mockResolvedValue({
|
||||
status: 'ok',
|
||||
value: {
|
||||
name: 'private-skill',
|
||||
packageDigest: DIGEST,
|
||||
destinationIdentity: 'local:global',
|
||||
currentState: 'absent',
|
||||
providers: []
|
||||
}
|
||||
})
|
||||
)
|
||||
skills.installShare.mockResolvedValue({ status: 'version-changed' })
|
||||
Object.defineProperty(window, 'api', { configurable: true, value: { skills } })
|
||||
render(<SkillInstallDialog open onOpenChange={() => undefined} />)
|
||||
await inspectSkill()
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Install skill' }))
|
||||
await screen.findByText('private-skill was updated. Review it again.')
|
||||
skills.resolveShare.mockResolvedValue({ status: 'reconnect-required' })
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Review again' }))
|
||||
|
||||
expect((await screen.findByRole('alert')).textContent).toContain('This share is unavailable')
|
||||
expect(screen.getByText('private-skill was updated. Review it again.')).toBeTruthy()
|
||||
expect(screen.queryByRole('button', { name: 'Install skill' })).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -106,8 +106,6 @@ export function SkillInstallDialog({
|
||||
setResult(null)
|
||||
try {
|
||||
const operation = await resolveSkillShareForInstall(shareId)
|
||||
setVersionChanged(false)
|
||||
setDestinationPreview(null)
|
||||
if (operation.status !== 'ok') {
|
||||
setError(
|
||||
operation.status === 'unconfigured'
|
||||
@@ -119,6 +117,9 @@ export function SkillInstallDialog({
|
||||
)
|
||||
return
|
||||
}
|
||||
// Only a successful re-resolve leaves the updated state; a failure keeps it, so the stale review never returns.
|
||||
setVersionChanged(false)
|
||||
setDestinationPreview(null)
|
||||
setPreview({ shareId, version: operation.value.version })
|
||||
} catch (cause) {
|
||||
console.warn('[skills] share resolution failed:', cause)
|
||||
@@ -363,7 +364,7 @@ export function SkillInstallDialog({
|
||||
</SkillInstallReview>
|
||||
)}
|
||||
|
||||
{!bundleVersion && error ? (
|
||||
{(!bundleVersion || versionChanged) && error ? (
|
||||
<p className="text-xs text-destructive" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
|
||||
@@ -72,6 +72,7 @@ export function SkillSharedLinkRow({
|
||||
share,
|
||||
olderShares = NO_SHARES,
|
||||
busy,
|
||||
stopsDisabled = false,
|
||||
onRevoke,
|
||||
onRevokeLinks,
|
||||
onDeleted
|
||||
@@ -79,6 +80,8 @@ export function SkillSharedLinkRow({
|
||||
share: SkillCloudOwnedShare
|
||||
olderShares?: SkillCloudOwnedShare[]
|
||||
busy: boolean
|
||||
/** Another link's stop is running; stops wait for it. */
|
||||
stopsDisabled?: boolean
|
||||
onRevoke: () => void
|
||||
onRevokeLinks?: (links: SkillCloudOwnedShare[]) => void
|
||||
onDeleted: () => void
|
||||
@@ -166,7 +169,7 @@ export function SkillSharedLinkRow({
|
||||
className="shrink-0"
|
||||
// The icon unmounts on confirmation; explicitly transfer keyboard focus to its replacement.
|
||||
autoFocus
|
||||
disabled={busy || deleting}
|
||||
disabled={busy || stopsDisabled || deleting}
|
||||
onClick={() => (confirming === 'revoke' ? onRevoke() : void deletePackage())}
|
||||
>
|
||||
{busy || deleting ? <Loader2 className="animate-spin" /> : null}
|
||||
@@ -183,7 +186,7 @@ export function SkillSharedLinkRow({
|
||||
size="icon-sm"
|
||||
variant="ghost"
|
||||
className="shrink-0 text-muted-foreground hover:text-destructive"
|
||||
disabled={busy}
|
||||
disabled={busy || stopsDisabled}
|
||||
onClick={() => setConfirming('revoke')}
|
||||
aria-label={t(
|
||||
'auto.components.settings.shareSkills.stopSharing',
|
||||
@@ -204,7 +207,7 @@ export function SkillSharedLinkRow({
|
||||
size="icon-sm"
|
||||
variant="ghost"
|
||||
className="shrink-0"
|
||||
disabled={busy}
|
||||
disabled={busy || stopsDisabled}
|
||||
aria-label={t(
|
||||
'auto.components.skills.SkillSharedLinkRow.moreActions',
|
||||
'More actions for {{name}}',
|
||||
@@ -260,6 +263,7 @@ export function SkillSharedLinkRow({
|
||||
share={share}
|
||||
olderShares={olderShares}
|
||||
busy={busy}
|
||||
disabled={busy || stopsDisabled}
|
||||
onRevokeLinks={onRevokeLinks}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
@@ -69,3 +69,50 @@ it('keeps the row disabled until Stop all has stopped every link', async () => {
|
||||
await act(async () => releaseOlder1())
|
||||
await waitFor(() => expect([...live]).toEqual([]))
|
||||
})
|
||||
|
||||
it('holds every row while one stop runs so two stops cannot race', async () => {
|
||||
const shares = ['alpha', 'beta'].map((id) => ({
|
||||
id,
|
||||
packageId: `pkg_${id}`,
|
||||
name: id,
|
||||
description: '',
|
||||
url: `https://share.onorca.dev/skills/share/${id}`,
|
||||
createdAt: '2026-11-08T00:00:00.000Z',
|
||||
canonical: true,
|
||||
pinnedVersionId: 'v1'
|
||||
}))
|
||||
let releaseAlpha!: () => void
|
||||
const alphaHeld = new Promise<void>((resolve) => {
|
||||
releaseAlpha = resolve
|
||||
})
|
||||
const revokeShare = vi.fn(async (id: string) => {
|
||||
if (id === 'alpha') {
|
||||
await alphaHeld
|
||||
}
|
||||
return { status: 'ok' }
|
||||
})
|
||||
Object.defineProperty(window, 'api', {
|
||||
configurable: true,
|
||||
value: {
|
||||
skills: {
|
||||
listOwnedShares: vi.fn().mockResolvedValue({ status: 'ok', value: shares }),
|
||||
revokeShare
|
||||
}
|
||||
}
|
||||
})
|
||||
render(<SharedLinks />)
|
||||
|
||||
const [alphaStop] = await screen.findAllByRole('button', { name: 'Stop sharing' })
|
||||
fireEvent.click(alphaStop!)
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Confirm stop' }))
|
||||
await waitFor(() => expect(revokeShare).toHaveBeenCalledWith('alpha'))
|
||||
|
||||
for (const button of screen.getAllByRole('button', { name: 'Stop sharing' })) {
|
||||
expect(button).toHaveProperty('disabled', true)
|
||||
}
|
||||
await act(async () => releaseAlpha())
|
||||
await waitFor(() =>
|
||||
expect(screen.getAllByRole('button', { name: 'Stop sharing' })).toHaveLength(1)
|
||||
)
|
||||
expect(screen.getByRole('button', { name: 'Stop sharing' })).toHaveProperty('disabled', false)
|
||||
})
|
||||
|
||||
@@ -71,6 +71,7 @@ export function SkillSharedLinksView({
|
||||
share={share}
|
||||
olderShares={olderShares}
|
||||
busy={busyPackageId === share.packageId}
|
||||
stopsDisabled={busyPackageId !== null}
|
||||
onRevoke={() => void revoke(share)}
|
||||
onRevokeLinks={(links) => void revokeMany(links)}
|
||||
onDeleted={refresh}
|
||||
|
||||
@@ -9,11 +9,13 @@ export function SkillSharedOlderLinks({
|
||||
share,
|
||||
olderShares,
|
||||
busy,
|
||||
disabled,
|
||||
onRevokeLinks
|
||||
}: {
|
||||
share: SkillCloudOwnedShare
|
||||
olderShares: SkillCloudOwnedShare[]
|
||||
busy: boolean
|
||||
disabled: boolean
|
||||
onRevokeLinks: (links: SkillCloudOwnedShare[]) => void
|
||||
}): React.JSX.Element {
|
||||
const t = useTranslate()
|
||||
@@ -45,7 +47,7 @@ export function SkillSharedOlderLinks({
|
||||
type="button"
|
||||
size="xs"
|
||||
variant={confirming === older.id ? 'destructive' : 'ghost'}
|
||||
disabled={busy}
|
||||
disabled={disabled}
|
||||
onClick={() => stop(older.id, [older])}
|
||||
>
|
||||
{stopLabel(older.id)}
|
||||
@@ -57,7 +59,7 @@ export function SkillSharedOlderLinks({
|
||||
type="button"
|
||||
size="xs"
|
||||
variant={confirming === 'all' ? 'destructive' : 'outline'}
|
||||
disabled={busy}
|
||||
disabled={disabled}
|
||||
onClick={() => stop('all', [share, ...olderShares])}
|
||||
>
|
||||
{busy ? <Loader2 className="animate-spin" /> : null}
|
||||
|
||||
@@ -19,7 +19,7 @@ export type OwnedSkillShares = {
|
||||
shares: SkillCloudOwnedShare[]
|
||||
loading: boolean
|
||||
error: string | null
|
||||
/** Package whose links are being stopped; its row stays busy until every stop settles. */
|
||||
/** Package whose links are being stopped; one stop runs at a time, so every row waits for it. */
|
||||
busyPackageId: string | null
|
||||
refresh: () => void
|
||||
revoke: (share: SkillCloudOwnedShare) => Promise<void>
|
||||
@@ -33,6 +33,7 @@ export function useOwnedSkillShares(): OwnedSkillShares {
|
||||
const [busyPackageId, setBusyPackageId] = useState<string | null>(null)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const generation = useRef(0)
|
||||
const revoking = useRef(false)
|
||||
|
||||
const load = useCallback(async (): Promise<void> => {
|
||||
const current = ++generation.current
|
||||
@@ -67,6 +68,11 @@ export function useOwnedSkillShares(): OwnedSkillShares {
|
||||
}, [load])
|
||||
|
||||
const revokeMany = useCallback(async (targets: SkillCloudOwnedShare[]): Promise<void> => {
|
||||
// Why: one shared busy state and error; overlapping stops would clear or overwrite each other's.
|
||||
if (revoking.current) {
|
||||
return
|
||||
}
|
||||
revoking.current = true
|
||||
setBusyPackageId(targets[0]?.packageId ?? null)
|
||||
setError(null)
|
||||
const stopped = new Set<string>()
|
||||
@@ -89,6 +95,7 @@ export function useOwnedSkillShares(): OwnedSkillShares {
|
||||
// Why: removing rows mid-sequence would change the row's identity and re-enable its stops.
|
||||
setShares((current) => current.filter((candidate) => !stopped.has(candidate.id)))
|
||||
setBusyPackageId(null)
|
||||
revoking.current = false
|
||||
const live = targets.filter((share) => !stopped.has(share.id))
|
||||
if (live.length === 0) {
|
||||
toast.success(translate('auto.components.settings.shareSkills.linkRevoked', 'Link revoked'))
|
||||
|
||||
Reference in New Issue
Block a user