feat: 建立 Sense 可靠投递状态机 (#78)

This commit is contained in:
QiuSW
2026-08-28 17:22:44 +08:00
parent e06904272a
commit 02a5af5e3b
20 changed files with 1575 additions and 0 deletions
@@ -0,0 +1,27 @@
import request from '@/utils/request'
import { getOutbox, listOutbox, requeueOutbox } from '@/api/sense/outbox'
jest.mock('@/utils/request', () => jest.fn())
describe('Sense outbox API', () => {
beforeEach(() => request.mockReset())
test('encodes identifiers and sends only the recovery fields', () => {
listOutbox({ pageIndex: 1, pageSize: 10 })
getOutbox('outbox/id unsafe')
requeueOutbox('outbox/id unsafe', 4, '出口故障已排除')
expect(request).toHaveBeenNthCalledWith(1, {
url: '/api/v1/outbox',
method: 'get',
params: { pageIndex: 1, pageSize: 10 }
})
expect(request).toHaveBeenNthCalledWith(2, {
url: '/api/v1/outbox/outbox%2Fid%20unsafe',
method: 'get'
})
expect(request).toHaveBeenNthCalledWith(3, {
url: '/api/v1/outbox/outbox%2Fid%20unsafe/requeue',
method: 'post',
data: { expectedVersion: 4, reason: '出口故障已排除' }
})
})
})
@@ -0,0 +1,37 @@
import {
buildOutboxQuery,
nextAction,
stateLabel,
stateType,
typeLabel
} from '@/views/sense/outbox/outboxState'
describe('Sense outbox presentation state', () => {
test('uses operator-facing labels and non-color-only states', () => {
expect(stateLabel('dead')).toBe('死信')
expect(stateType('dead')).toBe('danger')
expect(typeLabel('local_event_candidate')).toBe('本地事件候选')
})
test('builds an allowlisted trimmed query', () => {
expect(
buildOutboxQuery({
pageIndex: 2,
pageSize: 20,
state: 'retry',
internalType: 'local_event_candidate',
keyword: ' key ',
ignored: 'no'
})
).toEqual({
pageIndex: 2,
pageSize: 20,
state: 'retry',
internalType: 'local_event_candidate',
keyword: 'key'
})
})
test('explains the next recovery action', () => {
expect(nextAction({ state: 'dead' })).toBe('等待人工处理')
expect(nextAction({ state: 'pending' })).toBe('等待 worker 领取')
})
})