mirror of
https://github.com/iflytek/skillhub.git
synced 2026-11-16 09:21:18 +00:00
fix(suite): keep active bundle pages reachable
Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
This commit is contained in:
parent
2edfe81f64
commit
4f99bb0a02
4 changed files with 93 additions and 12 deletions
|
|
@ -1,3 +1,2 @@
|
|||
CREATE INDEX idx_suite_bundle_operation_actor_active_updated
|
||||
ON skill_suite_bundle_operation(actor_id, updated_at DESC, operation_id DESC)
|
||||
WHERE status IN ('RUNNING', 'WAITING_FOR_MEMBERS', 'BLOCKED_RETRYABLE');
|
||||
CREATE INDEX idx_suite_bundle_operation_actor_status_updated
|
||||
ON skill_suite_bundle_operation(actor_id, status, updated_at DESC, operation_id DESC);
|
||||
|
|
|
|||
|
|
@ -91,12 +91,28 @@ class SkillSuiteBundleOperationQueryRepositoryTest {
|
|||
entityManager.persist(operation);
|
||||
entityManager.persist(member(0, "first", false));
|
||||
entityManager.persist(member(1, "second", true));
|
||||
SkillSuiteBundleExecutionOperation newest = createOperation(
|
||||
"operation-2", "actor", namespace, "newer-suite");
|
||||
newest.markWaitingForMembers(NOW.plusSeconds(2));
|
||||
entityManager.persist(newest);
|
||||
SkillSuiteBundleExecutionOperation terminal = createOperation(
|
||||
"operation-3", "actor", namespace, "finished-suite");
|
||||
terminal.cancel(NOW.plusSeconds(3));
|
||||
entityManager.persist(terminal);
|
||||
SkillSuiteBundleExecutionOperation anotherActor = createOperation(
|
||||
"operation-4", "another-actor", namespace, "other-suite");
|
||||
anotherActor.markWaitingForMembers(NOW.plusSeconds(4));
|
||||
entityManager.persist(anotherActor);
|
||||
entityManager.flush();
|
||||
|
||||
var page = repository.findActive("actor", 0, 1);
|
||||
var firstPage = repository.findActive("actor", 0, 1);
|
||||
var secondPage = repository.findActive("actor", 1, 1);
|
||||
|
||||
assertThat(page.total()).isEqualTo(1);
|
||||
assertThat(page.items()).singleElement().satisfies(summary -> {
|
||||
assertThat(firstPage.total()).isEqualTo(2);
|
||||
assertThat(firstPage.items()).singleElement()
|
||||
.extracting(summary -> summary.operationId())
|
||||
.isEqualTo("operation-2");
|
||||
assertThat(secondPage.items()).singleElement().satisfies(summary -> {
|
||||
assertThat(summary.operationId()).isEqualTo("operation-1");
|
||||
assertThat(summary.targetCoordinate()).isEqualTo("@team-ai/care-suite");
|
||||
assertThat(summary.baseVersion()).isEqualTo("1.0.0");
|
||||
|
|
@ -104,7 +120,14 @@ class SkillSuiteBundleOperationQueryRepositoryTest {
|
|||
assertThat(summary.completedMembers()).isZero();
|
||||
assertThat(summary.waitingMembers()).isEqualTo(1);
|
||||
});
|
||||
assertThat(repository.findActive("another-actor", 0, 1).items()).isEmpty();
|
||||
assertThat(repository.findActive("another-actor", 0, 1).items()).singleElement()
|
||||
.extracting(summary -> summary.operationId())
|
||||
.isEqualTo("operation-4");
|
||||
assertThat(entityManager.getEntityManager().createNativeQuery("""
|
||||
SELECT indexdef FROM pg_indexes
|
||||
WHERE indexname = 'idx_suite_bundle_operation_actor_status_updated'
|
||||
""").getSingleResult().toString())
|
||||
.contains("(actor_id, status, updated_at DESC, operation_id DESC)");
|
||||
}
|
||||
|
||||
private SkillSuiteBundleMemberResult member(int position, String slug, boolean waiting) {
|
||||
|
|
@ -117,4 +140,24 @@ class SkillSuiteBundleOperationQueryRepositoryTest {
|
|||
if (waiting) member.markWaiting(NOW.plusSeconds(1));
|
||||
return member;
|
||||
}
|
||||
|
||||
private SkillSuiteBundleExecutionOperation createOperation(
|
||||
String operationId,
|
||||
String actorId,
|
||||
Namespace namespace,
|
||||
String suiteSlug
|
||||
) {
|
||||
String suffix = operationId.substring(operationId.lastIndexOf('-') + 1);
|
||||
SkillSuiteBundlePreviewSession preview = entityManager.persistFlushFind(
|
||||
new SkillSuiteBundlePreviewSession(
|
||||
"preview-" + suffix, actorId, SkillSuiteBundleMode.CREATE, namespace.getId(),
|
||||
suiteSlug, null, null, "1.0.0", "staging/" + suffix + ".zip",
|
||||
suffix.repeat(64), Map.of(), Map.of(), "warning-" + suffix,
|
||||
NOW.plusSeconds(600), NOW));
|
||||
return new SkillSuiteBundleExecutionOperation(
|
||||
operationId, preview.getToken(), "request-" + suffix, actorId,
|
||||
SkillSuiteBundleMode.CREATE, namespace.getId(), suiteSlug, null, null, "1.0.0",
|
||||
"staging/" + suffix + ".zip", suffix.repeat(64), Map.of(),
|
||||
"warning-" + suffix, NOW);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/** @vitest-environment jsdom */
|
||||
|
||||
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
||||
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { PagedResponse, SkillSuiteBundleOperationSummary } from '@/api/types'
|
||||
import { MySuitesPage } from './my-suites'
|
||||
|
|
@ -8,6 +8,7 @@ import { MySuitesPage } from './my-suites'
|
|||
const mocks = vi.hoisted(() => ({
|
||||
navigate: vi.fn(),
|
||||
remember: vi.fn(),
|
||||
activeHook: vi.fn(),
|
||||
active: { items: [], total: 0, page: 0, size: 12 } as PagedResponse<SkillSuiteBundleOperationSummary>,
|
||||
}))
|
||||
|
||||
|
|
@ -18,7 +19,10 @@ vi.mock('@/features/suite/suite-bundle-import', () => ({
|
|||
}))
|
||||
vi.mock('@/shared/hooks/use-suite-queries', () => ({
|
||||
useMySuites: () => ({ data: { items: [], total: 0, page: 0, size: 12 }, isLoading: false }),
|
||||
useActiveSuiteBundleOperations: () => ({ data: mocks.active, isLoading: false }),
|
||||
useActiveSuiteBundleOperations: (page: number) => {
|
||||
mocks.activeHook(page)
|
||||
return { data: mocks.active, isLoading: false }
|
||||
},
|
||||
}))
|
||||
|
||||
describe('MySuitesPage', () => {
|
||||
|
|
@ -86,4 +90,34 @@ describe('MySuitesPage', () => {
|
|||
search: { sourceVersion: '1.0.0' },
|
||||
})
|
||||
})
|
||||
|
||||
it('returns to the previous active page when the last page becomes empty', async () => {
|
||||
mocks.active = {
|
||||
items: [{
|
||||
operationId: 'operation-13',
|
||||
mode: 'CREATE',
|
||||
targetCoordinate: '@global/suite-13',
|
||||
targetVersion: '1.0.0',
|
||||
status: 'WAITING_FOR_MEMBERS',
|
||||
failureCode: undefined,
|
||||
baseVersion: undefined,
|
||||
totalMembers: 1,
|
||||
completedMembers: 0,
|
||||
waitingMembers: 1,
|
||||
updatedAt: '2026-09-14T06:00:00Z',
|
||||
}],
|
||||
total: 13,
|
||||
page: 0,
|
||||
size: 12,
|
||||
}
|
||||
const view = render(<MySuitesPage />)
|
||||
fireEvent.click(screen.getByRole('button', { name: 'pagination.next' }))
|
||||
expect(mocks.activeHook).toHaveBeenCalledWith(1)
|
||||
|
||||
mocks.active = { items: [], total: 12, page: 1, size: 12 }
|
||||
view.rerender(<MySuitesPage />)
|
||||
|
||||
await waitFor(() => expect(mocks.activeHook).toHaveBeenLastCalledWith(0))
|
||||
expect(screen.getByRole('button', { name: 'pagination.next' })).not.toBeNull()
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { useState } from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useNavigate } from '@tanstack/react-router'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { AlertTriangle, Boxes, Loader2 } from 'lucide-react'
|
||||
|
|
@ -23,6 +23,11 @@ export function MySuitesPage() {
|
|||
const { data, isLoading } = useMySuites(query.trim(), page, PAGE_SIZE)
|
||||
const { data: activeOperations, isLoading: isLoadingOperations } =
|
||||
useActiveSuiteBundleOperations(activePage, PAGE_SIZE)
|
||||
const activeTotalPages = Math.max(1, Math.ceil((activeOperations?.total ?? 0) / PAGE_SIZE))
|
||||
|
||||
useEffect(() => {
|
||||
if (activePage >= activeTotalPages) setActivePage(activeTotalPages - 1)
|
||||
}, [activePage, activeTotalPages])
|
||||
|
||||
const continueOperation = (operation: NonNullable<typeof activeOperations>['items'][number]) => {
|
||||
rememberSuiteBundleOperation(operation.mode, operation.targetCoordinate, operation.operationId)
|
||||
|
|
@ -55,7 +60,7 @@ export function MySuitesPage() {
|
|||
/>
|
||||
{isLoadingOperations ? (
|
||||
<div className="h-28 animate-shimmer rounded-xl" />
|
||||
) : activeOperations?.items.length ? (
|
||||
) : activeOperations?.total ? (
|
||||
<section className="space-y-3" aria-labelledby="active-suite-operations-title">
|
||||
<div>
|
||||
<h2 id="active-suite-operations-title" className="text-lg font-semibold">
|
||||
|
|
@ -98,7 +103,7 @@ export function MySuitesPage() {
|
|||
</div>
|
||||
<Pagination
|
||||
page={activePage}
|
||||
totalPages={Math.max(1, Math.ceil(activeOperations.total / activeOperations.size))}
|
||||
totalPages={activeTotalPages}
|
||||
onPageChange={setActivePage}
|
||||
/>
|
||||
</section>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue