发布管理:maintenanceSummary 只看 job.state === 'failed' 就给 held 处置文案; 窗口已 released 的旧作业(libsync-internal-1793399248431728863)因此自相矛盾。 改为仅 held 时给 recoveryError,已释放时给 releasedFailure(如实记录失败,不提供强制成功)。 版本记录:LoadVersionHistorySyncState 把可空的 finished_at 扫进 time.Time; 部署重启触发的同步在"进行中"时该列为 NULL,扫描失败使整页 500 (nginx access log:GET /api/v1/version-history?limit=30 → 500,74 字节错误体)。 改为指针接值再判空。前端同时区分"未配置/加载失败"并显示服务端 code。 RED/GREEN:新增 Go 集成用例(NULL finished_at)、两条前端用例; make verify 16/16 通过(local 档案)。
This commit is contained in:
@@ -1,19 +1,40 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { fetchAcceptanceResults, fetchTestPublications, parseTestPublicationsResponse, retryPublication, retryPublicationsBatch, startTestPublications, fetchJobFailures, fetchRemovalRequiredPublications, startPublicationRemoval } from './testPublications'
|
||||
import {
|
||||
fetchAcceptanceResults,
|
||||
fetchTestPublications,
|
||||
parseTestPublicationsResponse,
|
||||
retryPublication,
|
||||
retryPublicationsBatch,
|
||||
startTestPublications,
|
||||
fetchJobFailures,
|
||||
fetchRemovalRequiredPublications,
|
||||
startPublicationRemoval,
|
||||
} from './testPublications'
|
||||
|
||||
afterEach(() => vi.unstubAllGlobals())
|
||||
|
||||
describe('parseTestPublicationsResponse', () => {
|
||||
it('parses the safe publication projection envelope', () => {
|
||||
const result = parseTestPublicationsResponse({
|
||||
data: [{
|
||||
id: 'pub-safe', title: 'Safe title', ingest_state: 'failed',
|
||||
processing_state: 'failed', retrieval_state: 'unpublished',
|
||||
target_scope: 'external', change_set_id: 'cs-1', change_type: 'updated', can_start: false,
|
||||
retry_count: 2, last_error: 'remote_parse_failed', can_retry: true,
|
||||
updated_at: '2026-09-04T05:00:00Z', test_kb_id: 'must-drop',
|
||||
}],
|
||||
data: [
|
||||
{
|
||||
id: 'pub-safe',
|
||||
title: 'Safe title',
|
||||
ingest_state: 'failed',
|
||||
processing_state: 'failed',
|
||||
retrieval_state: 'unpublished',
|
||||
target_scope: 'external',
|
||||
change_set_id: 'cs-1',
|
||||
change_type: 'updated',
|
||||
can_start: false,
|
||||
retry_count: 2,
|
||||
last_error: 'remote_parse_failed',
|
||||
can_retry: true,
|
||||
updated_at: '2026-09-04T05:00:00Z',
|
||||
test_kb_id: 'must-drop',
|
||||
},
|
||||
],
|
||||
total: 1,
|
||||
limit: 25,
|
||||
offset: 0,
|
||||
@@ -40,7 +61,7 @@ describe('fetchTestPublications', () => {
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
'/api/v1/test-publications?processing_state=failed&limit=25&offset=0',
|
||||
expect.objectContaining({ headers: { Accept: 'application/json' } }),
|
||||
expect.objectContaining({ headers: { Accept: 'application/json' } })
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -49,7 +70,9 @@ describe('fetchAcceptanceResults', () => {
|
||||
it('reads the acceptance record list', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ data: [{ check_type: 'chunks_present', state: 'passed', observed_at: '2026-09-04T05:05:00Z' }] }),
|
||||
json: async () => ({
|
||||
data: [{ check_type: 'chunks_present', state: 'passed', observed_at: '2026-09-04T05:05:00Z' }],
|
||||
}),
|
||||
})
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
|
||||
@@ -59,7 +82,7 @@ describe('fetchAcceptanceResults', () => {
|
||||
expect(records[0].check_type).toBe('chunks_present')
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
'/api/v1/test-publications/pub-safe/acceptance',
|
||||
expect.objectContaining({ headers: { Accept: 'application/json' } }),
|
||||
expect.objectContaining({ headers: { Accept: 'application/json' } })
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -73,7 +96,7 @@ describe('retryPublication', () => {
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
'/api/v1/test-publications/pub-safe/retry',
|
||||
expect.objectContaining({ method: 'POST' }),
|
||||
expect.objectContaining({ method: 'POST' })
|
||||
)
|
||||
})
|
||||
|
||||
@@ -91,7 +114,9 @@ describe('retryPublication', () => {
|
||||
|
||||
describe('需下架条目的移除入口', () => {
|
||||
it('只取被禁止但仍存活在测试库的条目', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue({ ok: true, json: async () => ({ data: [], total: 0, limit: 50, offset: 0 }) })
|
||||
const fetchMock = vi
|
||||
.fn()
|
||||
.mockResolvedValue({ ok: true, json: async () => ({ data: [], total: 0, limit: 50, offset: 0 }) })
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
|
||||
await fetchRemovalRequiredPublications()
|
||||
@@ -102,7 +127,13 @@ describe('需下架条目的移除入口', () => {
|
||||
})
|
||||
|
||||
it('带幂等键触发下架并回传任务号', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(new Response(JSON.stringify({ publication_id: 'tp-1', job_id: 'job-remove-1', state: 'disabling' }), { status: 202 }))
|
||||
const fetchMock = vi
|
||||
.fn()
|
||||
.mockResolvedValue(
|
||||
new Response(JSON.stringify({ publication_id: 'tp-1', job_id: 'job-remove-1', state: 'disabling' }), {
|
||||
status: 202,
|
||||
})
|
||||
)
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
|
||||
await expect(startPublicationRemoval('tp-1')).resolves.toEqual({ job_id: 'job-remove-1' })
|
||||
@@ -113,7 +144,9 @@ describe('需下架条目的移除入口', () => {
|
||||
})
|
||||
|
||||
it('把服务端拒绝原因原样抛给界面', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue({ status: 409, json: async () => ({ error: '该知识的检索已经移除,无需重复下架' }) })
|
||||
const fetchMock = vi
|
||||
.fn()
|
||||
.mockResolvedValue({ status: 409, json: async () => ({ error: '该知识的检索已经移除,无需重复下架' }) })
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
|
||||
await expect(startPublicationRemoval('tp-1')).rejects.toThrow('该知识的检索已经移除,无需重复下架')
|
||||
@@ -122,30 +155,58 @@ describe('需下架条目的移除入口', () => {
|
||||
|
||||
describe('startTestPublications', () => {
|
||||
it('starts only the explicitly confirmed processing plans', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(new Response(JSON.stringify({ data: { selected: 2, started: 1, already_started: 1, unavailable: 0 } }), { status: 202 }))
|
||||
const fetchMock = vi
|
||||
.fn()
|
||||
.mockResolvedValue(
|
||||
new Response(JSON.stringify({ data: { selected: 2, started: 1, already_started: 1, unavailable: 0 } }), {
|
||||
status: 202,
|
||||
})
|
||||
)
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
|
||||
await expect(startTestPublications(['pub-a', 'pub-b'], '已核对差异')).resolves.toEqual({ selected: 2, started: 1, already_started: 1, unavailable: 0 })
|
||||
expect(fetchMock).toHaveBeenCalledWith('/api/v1/test-publications/start', expect.objectContaining({
|
||||
method: 'POST',
|
||||
headers: expect.objectContaining({ 'Idempotency-Key': expect.any(String) }),
|
||||
body: JSON.stringify({ publication_ids: ['pub-a', 'pub-b'], reason: '已核对差异' }),
|
||||
}))
|
||||
await expect(startTestPublications(['pub-a', 'pub-b'], '已核对差异')).resolves.toEqual({
|
||||
selected: 2,
|
||||
started: 1,
|
||||
already_started: 1,
|
||||
unavailable: 0,
|
||||
})
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
'/api/v1/test-publications/start',
|
||||
expect.objectContaining({
|
||||
method: 'POST',
|
||||
headers: expect.objectContaining({ 'Idempotency-Key': expect.any(String) }),
|
||||
body: JSON.stringify({ publication_ids: ['pub-a', 'pub-b'], reason: '已核对差异' }),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
describe('retryPublicationsBatch', () => {
|
||||
it('sends one server-side batch request and parses per-item outcomes', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ data: { batch_key: 'op-1', total: 2, started: 1, already_running: 1, not_retryable: 0,
|
||||
outcomes: [{ publication_id: 'tp-1', result: 'started' }, { publication_id: 'tp-2', result: 'already_running' }] }, operation: 'created' }),
|
||||
json: async () => ({
|
||||
data: {
|
||||
batch_key: 'op-1',
|
||||
total: 2,
|
||||
started: 1,
|
||||
already_running: 1,
|
||||
not_retryable: 0,
|
||||
outcomes: [
|
||||
{ publication_id: 'tp-1', result: 'started' },
|
||||
{ publication_id: 'tp-2', result: 'already_running' },
|
||||
],
|
||||
},
|
||||
operation: 'created',
|
||||
}),
|
||||
})
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
|
||||
const result = await retryPublicationsBatch(['tp-1', 'tp-2'], '解析服务恢复')
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledWith('/api/v1/test-publications/retry-batch',
|
||||
expect.objectContaining({ method: 'POST' }))
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
'/api/v1/test-publications/retry-batch',
|
||||
expect.objectContaining({ method: 'POST' })
|
||||
)
|
||||
const call = fetchMock.mock.calls[0] as [string, RequestInit]
|
||||
expect(JSON.parse(String(call[1].body))).toEqual({ publication_ids: ['tp-1', 'tp-2'], reason: '解析服务恢复' })
|
||||
expect(result.started).toBe(1)
|
||||
@@ -162,13 +223,34 @@ describe('fetchJobFailures', () => {
|
||||
it('reads the open dead-letter projection', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ data: { items: [{ id: 'jf-1', job_id: 'job-1', job_type: 'test.upload', error_code: 'remote_permanent', attempt: 5, max_attempts_at_failure: 5, state: 'open', created_at: '2026-09-11T20:00:00Z' }], total: 1, limit: 50, offset: 0 } }),
|
||||
json: async () => ({
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
id: 'jf-1',
|
||||
job_id: 'job-1',
|
||||
job_type: 'test.upload',
|
||||
error_code: 'remote_permanent',
|
||||
attempt: 5,
|
||||
max_attempts_at_failure: 5,
|
||||
state: 'open',
|
||||
created_at: '2026-09-11T20:00:00Z',
|
||||
},
|
||||
],
|
||||
total: 1,
|
||||
limit: 50,
|
||||
offset: 0,
|
||||
},
|
||||
}),
|
||||
})
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
|
||||
const items = await fetchJobFailures()
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledWith('/api/v1/job-failures?state=open&limit=50', expect.objectContaining({ headers: { Accept: 'application/json' } }))
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
'/api/v1/job-failures?state=open&limit=50',
|
||||
expect.objectContaining({ headers: { Accept: 'application/json' } })
|
||||
)
|
||||
expect(items[0].error_code).toBe('remote_permanent')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user