retcon.test.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { test } from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { promises as fs } from 'node:fs'
  4. import path from 'node:path'
  5. import { retcon } from '../../../src/state-machine/flows/retcon.js'
  6. import { makeGitBook } from '../_helper.js'
  7. test('吃书 retcon:改设定 + retcon(N) commit + 留痕', async () => {
  8. const { ctx, root, git, cleanup } = await makeGitBook({
  9. 'book.yaml': 'spec_version: "7.0"\n书名: 测\n',
  10. '定稿/设定/角色/林晚.md': '---\n姓名: 林晚\n境界: 练气三层\n---\n## 设定\n外门弟子。',
  11. })
  12. try {
  13. const r = await retcon(ctx, {
  14. chapterNum: 87,
  15. 原因: '修正大长老境界设定',
  16. characterUpdates: [{ name: '林晚', updates: { 境界: '金丹初期' } }],
  17. })
  18. assert.equal(r.ok, true, r.error)
  19. const card = await fs.readFile(path.join(root, '定稿/设定/角色/林晚.md'), 'utf8')
  20. assert.match(card, /境界: 金丹初期/)
  21. const { stdout } = await git(['log', '--oneline'])
  22. assert.match(stdout, /retcon\(87\):/)
  23. } finally {
  24. await cleanup()
  25. }
  26. })
  27. test('吃书:缺原因 → ok=false(留痕要求)', async () => {
  28. const { ctx, cleanup } = await makeGitBook({ 'book.yaml': '书名: 测\n' })
  29. try {
  30. const r = await retcon(ctx, { chapterNum: 1, characterUpdates: [] })
  31. assert.equal(r.ok, false)
  32. } finally {
  33. await cleanup()
  34. }
  35. })