1
0

prepare.test.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { test } from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { prepareChapterMaterials } from '../../src/prep/index.js'
  4. import { tempBookCtx } from '../commands/_helper.js'
  5. import { read } from '../storage/_tmprepo.js'
  6. test('prepareChapterMaterials 组装本章写作材料(八组件锚点)并写出', async () => {
  7. const { ctx, cleanup } = await tempBookCtx()
  8. try {
  9. const r = await prepareChapterMaterials(ctx, { chapterNum: 3 })
  10. assert.equal(r.ok, true)
  11. const c = r.content
  12. assert.match(c, /全书近况/)
  13. assert.match(c, /第\s*1\s*卷/)
  14. assert.match(c, /本章要写到的事/)
  15. assert.match(c, /查到玉佩/) // 来自细纲
  16. assert.match(c, /信息差边界/)
  17. // 边界行注入 短题/知情人/关键词/内容首句(AC7)——只给编号等于没给
  18. assert.match(
  19. c,
  20. /- 信息差-001(灭门真凶):知情人=林晚;关键词=玉佩\/宗门;内容:玉佩乃前代掌门封印邪灵之物,外人不可知。——读者未知,除知情人的对话与视角外不得出现/
  21. )
  22. assert.match(c, /文风锚点/)
  23. assert.match(c, /节奏/) // 来自文风铁律
  24. assert.match(c, /反和解/)
  25. assert.match(c, /反派恶意/) // 来自文风铁律反和解段
  26. const onDisk = await read(ctx.repoPath, '工作区/本章写作材料.md')
  27. assert.match(onDisk, /第 3 章写作材料/)
  28. } finally {
  29. await cleanup()
  30. }
  31. })
  32. test('prepareChapterMaterials 反复读清单:未体检 → 人话占位', async () => {
  33. const { ctx, cleanup } = await tempBookCtx()
  34. try {
  35. const r = await prepareChapterMaterials(ctx, { chapterNum: 3 })
  36. assert.equal(r.ok, true)
  37. assert.match(r.content, /## 反复读清单\n(尚未体检,暂无数据——首次体检后自动填充)/)
  38. } finally {
  39. await cleanup()
  40. }
  41. })
  42. test('prepareChapterMaterials 反复读清单:体检后 → top 高频意象带全书次数(AC4)', async () => {
  43. const { ctx, cleanup } = await tempBookCtx()
  44. try {
  45. await ctx.cache.run("INSERT OR REPLACE INTO meta (key, value) VALUES ('imagery_top', ?)", [
  46. JSON.stringify([
  47. { phrase: '空气仿佛凝固', count: 47, chapterCount: 12, firstChapter: 3, lastChapter: 40 },
  48. { phrase: '眼底闪过一丝', count: 21, chapterCount: 9, firstChapter: 5, lastChapter: 38 },
  49. ]),
  50. ])
  51. const r = await prepareChapterMaterials(ctx, { chapterNum: 3 })
  52. assert.equal(r.ok, true)
  53. assert.match(r.content, /- 「空气仿佛凝固」全书已用 47 次(12 章出现),本章避免再用/)
  54. assert.match(r.content, /- 「眼底闪过一丝」全书已用 21 次(9 章出现),本章避免再用/)
  55. } finally {
  56. await cleanup()
  57. }
  58. })