impact.test.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { test } from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { analyzeImpact } from '../../../src/state-machine/flows/impact.js'
  4. import { makeGitBook, chapter } from '../_helper.js'
  5. test('影响分析:按已发布到章分两清单 + 履历/时间线命中', async () => {
  6. const { ctx, cleanup } = await makeGitBook({
  7. 'book.yaml': 'spec_version: "7.0"\n书名: 测\n已发布到章: 1\n',
  8. '定稿/正文/0001-起.md': chapter(1, '林晚得到玉佩。'),
  9. '定稿/正文/0002-承.md': chapter(2, '玉佩再次发光。'),
  10. '定稿/正文/0003-转.md': chapter(3, '与玉佩无关的一章。'.replace('玉佩', '令牌')),
  11. '大纲/伏笔/伏笔-001-玉佩.md': '---\n强度: 高\n状态: 进行\n开启章: 1\n---\n## 履历\n- 第1章:埋下玉佩',
  12. '定稿/设定/时间线/第01卷.md': '| 章 | 书内时间 | 一句话事件 | 在场 |\n|--|--|--|--|\n| 1 | 春 | 得玉佩 | 林晚 |',
  13. })
  14. try {
  15. const r = await analyzeImpact(ctx, { 关键词: '玉佩' })
  16. assert.equal(r.ok, true)
  17. assert.deepEqual(r.已发布, [1]) // 第1章已发布
  18. assert.deepEqual(r.未发布, [2]) // 第2章未发布;第3章不含玉佩
  19. assert.ok(r.履历命中.some((f) => f.includes('伏笔-001')))
  20. assert.ok(r.时间线命中.some((f) => f.includes('第01卷')))
  21. } finally {
  22. await cleanup()
  23. }
  24. })
  25. test('影响分析:缺关键词 → ok=false', async () => {
  26. const { ctx, cleanup } = await makeGitBook({ 'book.yaml': '书名: 测\n' })
  27. try {
  28. const r = await analyzeImpact(ctx, {})
  29. assert.equal(r.ok, false)
  30. } finally {
  31. await cleanup()
  32. }
  33. })