From eec7d14cfac8c43f75ac2a2367de716efed39d16 Mon Sep 17 00:00:00 2001 From: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com> Date: Mon, 14 Sep 2026 12:29:39 +0800 Subject: [PATCH] fix(suite): isolate restored bundle operations Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com> --- .../suite/suite-bundle-import.test.tsx | 60 ++++++++++++++++++- .../features/suite/suite-bundle-import.tsx | 14 ++++- web/src/i18n/locales/en.json | 1 + web/src/i18n/locales/ru.json | 1 + web/src/i18n/locales/zh.json | 1 + web/src/pages/dashboard/suite-editor.tsx | 15 ++--- 6 files changed, 83 insertions(+), 9 deletions(-) diff --git a/web/src/features/suite/suite-bundle-import.test.tsx b/web/src/features/suite/suite-bundle-import.test.tsx index 3aceaa715..41bdafc3e 100644 --- a/web/src/features/suite/suite-bundle-import.test.tsx +++ b/web/src/features/suite/suite-bundle-import.test.tsx @@ -18,6 +18,7 @@ const mocks = vi.hoisted(() => ({ packageFolder: vi.fn(), toast: { error: vi.fn() }, navigate: vi.fn(), + requestedOperationIds: [] as Array, })) vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) })) @@ -44,7 +45,10 @@ vi.mock('@/shared/hooks/use-suite-queries', () => ({ useConfirmSuiteBundle: () => mocks.confirm, useCancelSuiteBundleOperation: () => mocks.cancel, useRetrySuiteBundleOperation: () => mocks.retry, - useSuiteBundleOperation: () => mocks.operation, + useSuiteBundleOperation: (operationId?: string) => { + mocks.requestedOperationIds.push(operationId) + return mocks.operation + }, })) function folderFile(path: string): File { @@ -83,6 +87,7 @@ describe('SuiteBundleImport', () => { mocks.operation.data = undefined mocks.operation.error = null mocks.preview.isPending = false + mocks.requestedOperationIds = [] }) it('uploads one archive, requires explicit warning acceptance and confirms the exact preview', async () => { @@ -278,6 +283,7 @@ describe('SuiteBundleImport', () => { mocks.operation.data = { operationId: 'operation-1', status: 'BLOCKED_RETRYABLE', + mode: 'CREATE', members: [{ position: 0, status: 'FAILED_RETRYABLE', redacted: true }], } render() @@ -329,6 +335,7 @@ describe('SuiteBundleImport', () => { mocks.operation.data = { operationId: 'operation-waiting', status: 'WAITING_FOR_MEMBERS', + mode: 'CREATE', members: [{ position: 0, status: 'WAITING_FOR_MEMBER', @@ -360,6 +367,7 @@ describe('SuiteBundleImport', () => { mocks.operation.data = { operationId: 'operation-complete', status: 'SUITE_DRAFT_CREATED', + mode: 'CREATE', targetCoordinate: '@global/generated-suite', targetVersion: '1.2.0', members: [], @@ -373,4 +381,54 @@ describe('SuiteBundleImport', () => { search: { version: '1.2.0' }, }) }) + + it('reads the new Suite recovery key when an UPDATE route changes without a full page reload', async () => { + window.sessionStorage.setItem( + 'skillhub:suite-bundle-operation:UPDATE:@global/suite-a', + 'operation-a', + ) + window.sessionStorage.setItem( + 'skillhub:suite-bundle-operation:UPDATE:@global/suite-b', + 'operation-b', + ) + const Harness = ({ coordinate }: { coordinate: string }) => ( + + ) + const { rerender } = render() + expect(mocks.requestedOperationIds[mocks.requestedOperationIds.length - 1]).toBe('operation-a') + + rerender() + + await waitFor(() => expect( + mocks.requestedOperationIds[mocks.requestedOperationIds.length - 1] + ).toBe('operation-b')) + expect(window.sessionStorage.getItem( + 'skillhub:suite-bundle-operation:UPDATE:@global/suite-b' + )).toBe('operation-b') + }) + + it('clears a restored UPDATE operation that belongs to another Suite without exposing actions', async () => { + const key = 'skillhub:suite-bundle-operation:UPDATE:@global/suite-b' + window.sessionStorage.setItem(key, 'operation-a') + mocks.operation.data = { + operationId: 'operation-a', + status: 'BLOCKED_RETRYABLE', + mode: 'UPDATE', + targetCoordinate: '@global/suite-a', + members: [{ position: 0, status: 'FAILED_RETRYABLE', redacted: true }], + } + + render() + + expect(screen.queryByText('suite.bundle.redactedMember')).toBeNull() + expect(screen.queryByRole('button', { name: /suite.bundle.retry/ })).toBeNull() + expect(screen.queryByRole('button', { name: 'suite.bundle.cancelOperation' })).toBeNull() + await waitFor(() => expect(window.sessionStorage.getItem(key)).toBeNull()) + expect(screen.getByText('suite.bundle.uploadTitle')).not.toBeNull() + expect(mocks.toast.error).toHaveBeenCalledWith('suite.bundle.operationTargetMismatch') + }) }) diff --git a/web/src/features/suite/suite-bundle-import.tsx b/web/src/features/suite/suite-bundle-import.tsx index c3ccd12ee..2e8dfb4cc 100644 --- a/web/src/features/suite/suite-bundle-import.tsx +++ b/web/src/features/suite/suite-bundle-import.tsx @@ -71,12 +71,22 @@ export function SuiteBundleImport({ expectedMode, expectedCoordinate }: { const selectionVersionRef = useRef(0) const idempotencyKeyRef = useRef(null) const operationQuery = useSuiteBundleOperation(operationId) + const operation = operationQuery.data + const operationMatchesTarget = !operation + || (operation.mode === expectedMode + && (expectedCoordinate === undefined || operation.targetCoordinate === expectedCoordinate)) useEffect(() => () => { selectionVersionRef.current += 1 requestRef.current?.abort() }, []) useEffect(() => writeStoredOperation(storageKey, operationId), [operationId, storageKey]) + useEffect(() => { + if (!operationId || !operation || operationMatchesTarget) return + writeStoredOperation(storageKey) + setOperationId(undefined) + toast.error(t('suite.bundle.operationTargetMismatch')) + }, [operation, operationId, operationMatchesTarget, storageKey, t]) useEffect(() => { if (!preview) return undefined const timer = window.setInterval(() => setNow(Date.now()), 1_000) @@ -185,7 +195,9 @@ export function SuiteBundleImport({ expectedMode, expectedCoordinate }: { } if (operationId) { - const operation = operationQuery.data + if (!operationMatchesTarget) { + return {t('suite.bundle.operationTargetMismatch')} + } const status = operation?.status const draftCoordinate = splitCoordinate(operation?.targetCoordinate) const resetOperation = () => { diff --git a/web/src/i18n/locales/en.json b/web/src/i18n/locales/en.json index 116dc68ff..4e6cccca1 100644 --- a/web/src/i18n/locales/en.json +++ b/web/src/i18n/locales/en.json @@ -2021,6 +2021,7 @@ "progressTitle": "Bundle publishing progress", "loadingOperation": "Loading operation status", "operationLoadFailed": "Unable to load the Bundle operation. Check your connection and try again.", + "operationTargetMismatch": "The restored Bundle operation does not match this Suite. Its recovery entry was cleared.", "reloadOperation": "Reload", "redactedMember": "Member hidden by access policy", "viewMemberReview": "View Skill version and review status", diff --git a/web/src/i18n/locales/ru.json b/web/src/i18n/locales/ru.json index c95bf89c6..7054dfeb9 100644 --- a/web/src/i18n/locales/ru.json +++ b/web/src/i18n/locales/ru.json @@ -2018,6 +2018,7 @@ "progressTitle": "Ход публикации Bundle", "loadingOperation": "Загрузка состояния операции", "operationLoadFailed": "Не удалось загрузить операцию Bundle. Проверьте подключение и повторите попытку.", + "operationTargetMismatch": "Восстановленная операция Bundle не соответствует этому набору. Запись восстановления удалена.", "reloadOperation": "Загрузить снова", "redactedMember": "Участник скрыт политикой доступа", "viewMemberReview": "Открыть версию Skill и состояние проверки", diff --git a/web/src/i18n/locales/zh.json b/web/src/i18n/locales/zh.json index 91ad19c71..7acd88761 100644 --- a/web/src/i18n/locales/zh.json +++ b/web/src/i18n/locales/zh.json @@ -2020,6 +2020,7 @@ "progressTitle": "Bundle 发布进度", "loadingOperation": "正在读取操作状态", "operationLoadFailed": "无法读取 Bundle 操作状态,请检查网络后重试。", + "operationTargetMismatch": "恢复的 Bundle 操作与当前套件不匹配,已清除该恢复记录。", "reloadOperation": "重新读取", "redactedMember": "无权查看的成员", "viewMemberReview": "查看技能版本与审核状态", diff --git a/web/src/pages/dashboard/suite-editor.tsx b/web/src/pages/dashboard/suite-editor.tsx index 03f73d0cc..39d8670cb 100644 --- a/web/src/pages/dashboard/suite-editor.tsx +++ b/web/src/pages/dashboard/suite-editor.tsx @@ -39,6 +39,10 @@ export function SuiteEditor({ namespace: routeNamespace, slug: routeSlug, versio }) { const editing = mode === 'edit' const creatingVersion = mode === 'new-version' + const bundleMode = creatingVersion ? 'UPDATE' : 'CREATE' + const bundleCoordinate = creatingVersion && routeNamespace && routeSlug + ? `@${routeNamespace}/${routeSlug}` + : undefined const loadingSource = editing || creatingVersion const { t } = useTranslation() const { hasRole } = useAuth() @@ -61,11 +65,7 @@ export function SuiteEditor({ namespace: routeNamespace, slug: routeSlug, versio const [pendingVersionUpdate, setPendingVersionUpdate] = useState(null) const [authoringMode, setAuthoringMode] = useState<'manual' | 'import'>(() => { if (editing) return 'manual' - const bundleMode = creatingVersion ? 'UPDATE' : 'CREATE' - const coordinate = creatingVersion && routeNamespace && routeSlug - ? `@${routeNamespace}/${routeSlug}` - : undefined - return hasStoredSuiteBundleOperation(bundleMode, coordinate) ? 'import' : 'manual' + return hasStoredSuiteBundleOperation(bundleMode, bundleCoordinate) ? 'import' : 'manual' }) const debouncedQuery = useDebounce(candidateQuery.trim(), 250) const { data: candidates, isLoading: isLoadingCandidates } = useSuiteMemberCandidates( @@ -250,8 +250,9 @@ export function SuiteEditor({ namespace: routeNamespace, slug: routeSlug, versio {!editing && authoringMode === 'import' ? ( ) : ( <>