feat: add audited async task reconciliation and frozen bindings
This commit is contained in:
1 parent
5be06a97c1
commit
c716ec7478
28 files changed
+1312
-76
No files matched your search
@@ -0,0 +1,36 @@
|
||||
// Dedicated UI fixture. No real backend, credentials, wallet or provider is contacted.
|
||||
import { createApp } from 'vue'
|
||||
import TaskReconciliation from '../src/components/TaskReconciliation.vue'
|
||||
import '../src/styles.css'
|
||||
import type { ReconciliationTask, ReconciliationCommand, ReconciliationReceipt } from '../src/services/task-reconciliation'
|
||||
|
||||
const task: ReconciliationTask = { id: 'ui-reconciliation-task', userId: 'isolated-test-user', modelId: 'isolated-test-model', taskType: '3d', status: 'reconciling', updatedAt: '2026-10-21T11:00:00Z', reservedAmount: '1.44000000', costAmount: null, providerId: 'isolated-test-provider', upstreamModel: 'isolated-test-upstream', providerTaskId: 'isolated-provider-task', credentialFingerprint: 'a'.repeat(64), completionStatus: null, requiresReconciliation: true, pricing: { unit: 'CNY / task', price: 1.44 }, error: { code: 'TEST_TIMEOUT', message: '隔离测试:上游结果待核账,额度仍冻结' } }
|
||||
const receipts: ReconciliationReceipt[] = []
|
||||
let accepted: ReconciliationCommand | null = null
|
||||
let attempts = 0
|
||||
const respond = (data: unknown, status = 200) => Promise.resolve(new Response(JSON.stringify(data), { status, headers: { 'Content-Type': 'application/json' } }))
|
||||
function observations() { const output = document.getElementById('preview-observations'); if (output) output.textContent = JSON.stringify({ testOnly: true, wireAttempts: attempts, uniqueReceipts: receipts.length, requestId: accepted?.requestId || null, status: task.status }, null, 2) }
|
||||
window.fetch = async (input, init) => {
|
||||
const url = new URL(typeof input === 'string' ? input : input instanceof URL ? input.href : input.url, location.origin)
|
||||
if (!url.pathname.startsWith('/api/admin/task-reconciliation')) return respond({ error: { message: '隔离测试禁止其他 API 请求' } }, 404)
|
||||
if (url.pathname.endsWith('/quote')) return respond({ expectedCost: '1.44', expectedUpdatedAt: task.updatedAt })
|
||||
if (init?.method === 'POST') {
|
||||
attempts++
|
||||
const command = JSON.parse(String(init.body)) as ReconciliationCommand
|
||||
if (!accepted) {
|
||||
accepted = command
|
||||
const before = { ...task }
|
||||
task.status = 'succeeded'; task.costAmount = '1.44000000'; task.requiresReconciliation = false; task.updatedAt = '2026-10-21T11:01:00Z'
|
||||
receipts.push({ request_id: command.requestId, actor_user_id: 'isolated-test-admin', action: command.action, evidence_reference: command.evidenceReference, note: command.note, created_at: task.updatedAt, before_state: before, after_state: { ...task } })
|
||||
observations()
|
||||
throw new TypeError('隔离测试:服务端已提交,但响应丢失,请原样重试')
|
||||
}
|
||||
observations()
|
||||
if (JSON.stringify(accepted) !== JSON.stringify(command)) return respond({ error: { message: '隔离测试发现重复提交没有保留原操作编号或请求内容' } }, 409)
|
||||
return respond({ task: { ...task }, requestId: command.requestId, replayed: true })
|
||||
}
|
||||
if (url.pathname.endsWith('/ui-reconciliation-task')) return respond({ task: { ...task }, history: receipts })
|
||||
return respond({ records: task.status === 'reconciling' ? [{ ...task }] : [], total: task.status === 'reconciling' ? 1 : 0, page: 1 })
|
||||
}
|
||||
observations()
|
||||
createApp(TaskReconciliation).mount('#app')
|
||||
Reference in new issue
Block a user