533db535f1
build / build (push) Successful in 1m12s
按已确认需求提供独立安全模型配置、真实探测、正式字典字段评估与原问题译中,持久批次支持只补空白、暂停恢复、有限重试、幂等和逐字段依据。覆盖固定规则、本地语言、组织关联与主表有效看板共用治理侧读模型,保留源生产和冻结历史。 验证:完整 make verify 退出0,702项Go与329项前端通过;默认118项外部/隔离集成明确跳过,另跑完整镜像及组织隔离PG竞态。12并发、输入漂移、过期租约、暂停/恢复及有限重试通过。用户授权的百炼 deepseek-v4.1-flash 完成真实后台与浏览器评估/翻译;552行、16列、11块看板及完整PNG、独立配置页测试/保存、重开恢复和零JS异常通过。仅非业务样本外发,自动处理关闭,原payload不变。 上线前治理库已做导出快照原生备份并真实恢复,60表行数与17个QA表内容哈希一致;不修改DobotAI生产或隧道。本提交时尚未部署,线上验收须独立完成。
130 lines
4.0 KiB
TypeScript
130 lines
4.0 KiB
TypeScript
import { describe, it, expect, vi, afterEach } from 'vitest'
|
|
import {
|
|
parseAISettings,
|
|
parseAIBatch,
|
|
aiBatchProgress,
|
|
parseAIStatus,
|
|
parseAIWorkState,
|
|
parseAIPreview,
|
|
parseAIEvidence,
|
|
} from './qaAITypes'
|
|
const settings = {
|
|
revision: 1,
|
|
base_url: 'https://model.example.invalid/v1',
|
|
model: 'fixture',
|
|
key_configured: true,
|
|
verification: 'verified',
|
|
checked_at: '2026-10-19T00:00:00Z',
|
|
automatic_evaluation: false,
|
|
automatic_translation: false,
|
|
storage_ready: true,
|
|
}
|
|
const batch = {
|
|
id: 'fixture',
|
|
kind: 'evaluation',
|
|
state: 'active',
|
|
total: 4,
|
|
succeeded: 2,
|
|
failed: 1,
|
|
skipped: 1,
|
|
running: 0,
|
|
queued: 0,
|
|
retry: 0,
|
|
paused: 0,
|
|
created_at: '2026-10-19T00:00:00Z',
|
|
}
|
|
describe('AI safe settings and honest batch accounting', () => {
|
|
it('accepts only a write-only key status and rejects secret-bearing settings responses', () => {
|
|
expect(parseAISettings(settings).key_configured).toBe(true)
|
|
expect(() => parseAISettings({ ...settings, api_key: 'fixture-only' })).toThrow('响应无效')
|
|
})
|
|
it('counts all terminal outcomes as finished without equating 100% with success', () => {
|
|
const parsed = parseAIBatch(batch)
|
|
expect(aiBatchProgress(parsed)).toEqual({ finished: 4, percent: 100 })
|
|
expect(parsed.failed).toBe(1)
|
|
expect(() => parseAIBatch({ ...batch, total: 5 })).toThrow('响应无效')
|
|
expect(
|
|
aiBatchProgress(parseAIBatch({ ...batch, total: 0, succeeded: 0, failed: 0, skipped: 0 })).percent
|
|
).toBeNull()
|
|
})
|
|
})
|
|
|
|
it('strictly accepts real task/evidence metadata and refuses partial preview counts', () => {
|
|
const work = {
|
|
id: 'work',
|
|
record_id: 'record',
|
|
kind: 'evaluation',
|
|
state: 'running',
|
|
stage: 'request',
|
|
attempt: 1,
|
|
error_code: '',
|
|
skip_reason: '',
|
|
started_at: '2026-10-19T00:00:00Z',
|
|
updated_at: '2026-10-19T00:00:01Z',
|
|
}
|
|
const status = {
|
|
settings,
|
|
worker_ready: true,
|
|
queues: [{ kind: 'evaluation', queued: 0, running: 1, retry: 0, failed: 0, paused: 0, succeeded: 0, skipped: 0 }],
|
|
batches: [],
|
|
recent_tasks: [work],
|
|
recent_tasks_limited: false,
|
|
}
|
|
expect(parseAIStatus(status).recent_tasks[0].stage).toBe('request')
|
|
expect(() => parseAIWorkState({ ...work, state: 'invented' })).toThrow('响应无效')
|
|
const preview = {
|
|
id: 'preview',
|
|
kind: 'evaluation',
|
|
scope_total: 4,
|
|
eligible: 3,
|
|
skipped: 1,
|
|
config_revision: 1,
|
|
expires_at: '2026-10-19T00:10:00Z',
|
|
}
|
|
expect(parseAIPreview(preview).eligible).toBe(3)
|
|
expect(() => parseAIPreview({ ...preview, eligible: 2 })).toThrow('响应无效')
|
|
const evidence = {
|
|
...work,
|
|
state: 'succeeded',
|
|
input_hash: 'a'.repeat(64),
|
|
config_revision: 1,
|
|
prompt_version: 'fixture',
|
|
dictionary_version: 'fixture',
|
|
actual_model: 'fixture',
|
|
result: {
|
|
fields: {
|
|
product_category: {
|
|
value: 'MG400',
|
|
basis: 'semantic_only',
|
|
reason: '原问题含型号',
|
|
quotes: [{ source: 'question', text: 'MG400', reference_index: 0 }],
|
|
},
|
|
},
|
|
},
|
|
applied_fields: { product_category: 'MG400' },
|
|
skipped_fields: {},
|
|
}
|
|
expect(parseAIEvidence(evidence).result.fields?.product_category.reason).toBe('原问题含型号')
|
|
})
|
|
|
|
afterEach(() => vi.unstubAllGlobals())
|
|
it('saves through the real admin API contract with explicit intent and no key on keep', async () => {
|
|
const { saveAISettings } = await import('./qaAI')
|
|
const fetcher = vi.fn().mockResolvedValue(new Response(JSON.stringify({ data: settings }), { status: 200 }))
|
|
vi.stubGlobal('fetch', fetcher)
|
|
const result = await saveAISettings({
|
|
base_revision: 1,
|
|
base_url: settings.base_url,
|
|
model: settings.model,
|
|
key_action: 'keep',
|
|
})
|
|
expect(result.key_configured).toBe(true)
|
|
const [path, request] = fetcher.mock.calls[0]
|
|
expect(path).toBe('/api/v1/qa-ops/ai/settings')
|
|
expect(request.headers['X-Governance-Action']).toBe('qa-ai')
|
|
const body = JSON.parse(request.body)
|
|
expect(body.key_action).toBe('keep')
|
|
expect(body).not.toHaveProperty('api_key')
|
|
expect(body).not.toHaveProperty('actor')
|
|
})
|