1
0

ThreadLedgerWriter.test.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { test } from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { ThreadLedgerWriter } from '../../../src/storage/adapters/ThreadLedgerWriter.js'
  4. import { makeRepo, cleanup, read } from '../_tmprepo.js'
  5. const 伏笔文件 = `---
  6. 强度: 高
  7. 状态: 进行
  8. 开启章: 1
  9. 最后推进章: 1
  10. ---
  11. ## 描述
  12. 神秘老者身份。
  13. ## 履历
  14. - 第1章:埋下——留玉佩
  15. `
  16. test('updateThread 改 front matter,保留正文与履历', async () => {
  17. const root = await makeRepo({ '大纲/伏笔/伏笔-001-老者.md': 伏笔文件 })
  18. try {
  19. const r = await new ThreadLedgerWriter(root).updateThread('伏笔-001', {
  20. 状态: '已收尾',
  21. 最后推进章: 152,
  22. })
  23. assert.equal(r.ok, true)
  24. const c = await read(root, '大纲/伏笔/伏笔-001-老者.md')
  25. assert.match(c, /状态: 已收尾/)
  26. assert.match(c, /最后推进章: 152/)
  27. assert.match(c, /## 履历/)
  28. assert.match(c, /神秘老者身份/)
  29. } finally {
  30. await cleanup(root)
  31. }
  32. })
  33. test('appendHistory 在 ## 履历 段尾追加一行', async () => {
  34. const root = await makeRepo({ '大纲/伏笔/伏笔-001-老者.md': 伏笔文件 })
  35. try {
  36. const r = await new ThreadLedgerWriter(root).appendHistory(
  37. '伏笔-001',
  38. '第152章:推进——林晚取得实证'
  39. )
  40. assert.equal(r.ok, true)
  41. const c = await read(root, '大纲/伏笔/伏笔-001-老者.md')
  42. assert.match(c, /- 第1章:埋下——留玉佩/)
  43. assert.match(c, /- 第152章:推进——林晚取得实证/)
  44. } finally {
  45. await cleanup(root)
  46. }
  47. })
  48. test('updateThread 不存在的条目 → ok=false(不崩)', async () => {
  49. const root = await makeRepo({})
  50. try {
  51. const r = await new ThreadLedgerWriter(root).updateThread('伏笔-999', {})
  52. assert.equal(r.ok, false)
  53. } finally {
  54. await cleanup(root)
  55. }
  56. })