87f97a2f9b
build / build (push) Successful in 1m7s
详情使用共享主表字典,稀疏修改所选字段并保留原始问答及旧复核审计。 月周统计提供文本和下拉双入口;每租户每周一份持久草稿,按技能六节双语模板真实预填。 加入幂等自动保存、冲突保留、未知响应重试、切周及离开保护和schema58非破坏降级保护。 验证:完整make verify、隔离PostgreSQL全mirror竞态回归、真实恢复库浏览器验收通过。 浏览器实测字段精确读回、月周双输入、模板预填、MD/CSV、自动保存、冲突、失败重试与API重启恢复。 未连接或改写DobotAI生产源库,未运行付费模型;提交时尚未部署。
55 lines
2.2 KiB
TypeScript
55 lines
2.2 KiB
TypeScript
import { describe, it, expect, vi, afterEach } from 'vitest'
|
|
import { parseWeeklyDocument, weeklyTransport } from './qaWeeklyDraftAPI'
|
|
afterEach(() => vi.unstubAllGlobals())
|
|
const empty = { week: '2026-W41', revision: 0, markdown: '', seed: {}, updated_at: null }
|
|
describe('weekly document protocol', () => {
|
|
it('verifies an exact GET after POST and refuses a newer conflicting head', async () => {
|
|
const document = { ...empty, revision: 1, markdown: '用户正文', updated_at: '2026-10-19T10:00:00Z' }
|
|
const fetch = vi
|
|
.fn()
|
|
.mockResolvedValueOnce(
|
|
new Response(JSON.stringify({ data: { draft: document, replayed: false } }), { status: 200 })
|
|
)
|
|
.mockResolvedValueOnce(new Response(JSON.stringify({ data: document }), { status: 200 }))
|
|
vi.stubGlobal('fetch', fetch)
|
|
expect(
|
|
await weeklyTransport.write(empty.week, {
|
|
base_revision: 0,
|
|
nonce: 'fixture_client_weekly_0001',
|
|
markdown: document.markdown,
|
|
})
|
|
).toEqual(document)
|
|
expect(fetch.mock.calls).toHaveLength(2)
|
|
expect(fetch.mock.calls[0][1].method).toBe('POST')
|
|
expect(fetch.mock.calls[1][1].method ?? 'GET').toBe('GET')
|
|
fetch
|
|
.mockResolvedValueOnce(
|
|
new Response(JSON.stringify({ data: { draft: document, replayed: true } }), { status: 200 })
|
|
)
|
|
.mockResolvedValueOnce(
|
|
new Response(JSON.stringify({ data: { ...document, revision: 2, markdown: 'another editor' } }), {
|
|
status: 200,
|
|
})
|
|
)
|
|
await expect(
|
|
weeklyTransport.write(empty.week, {
|
|
base_revision: 0,
|
|
nonce: 'fixture_client_weekly_0001',
|
|
markdown: document.markdown,
|
|
})
|
|
).rejects.toMatchObject({ status: 409 })
|
|
})
|
|
it('refuses foreign weeks, fabricated saved content and invalid revisions rather than showing false success', () => {
|
|
expect(parseWeeklyDocument(empty, empty.week)).toEqual(empty)
|
|
for (const value of [
|
|
{ ...empty, week: '2026-W40' },
|
|
{ ...empty, revision: -1 },
|
|
{ ...empty, revision: 0, markdown: 'invented persisted content' },
|
|
{ ...empty, revision: 1, updated_at: null },
|
|
{ ...empty, seed: [] },
|
|
{ ...empty, markdown: 9 },
|
|
])
|
|
expect(() => parseWeeklyDocument(value, empty.week)).toThrow()
|
|
})
|
|
})
|