report-weak-hook-streak.test.js 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. import { test } from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { run } from '../../src/commands/report-weak-hook-streak.js'
  4. import { fixtureCtx, repoCtx } from './_helper.js'
  5. test('report-weak-hook-streak fixture 末尾无弱钩 → streak 0', async () => {
  6. const { ctx, cleanup } = await fixtureCtx()
  7. try {
  8. const r = await run([], {}, ctx)
  9. assert.equal(r.ok, true)
  10. assert.equal(JSON.parse(r.output).streak, 0)
  11. } finally {
  12. await cleanup()
  13. }
  14. })
  15. test('report-weak-hook-streak 统计末尾连续弱钩(design §6.3)', async () => {
  16. const { ctx, cleanup } = await repoCtx(null, {
  17. 'book.yaml': 'spec_version: "7.0"\n书名: 测试\n',
  18. '定稿/正文/0001-起.md': '---\n章号: 1\n标题: 起\n卷: 1\n字数: 100\n章定位: 推进\n钩子: 危机钩-强\n---\n正文。',
  19. '定稿/正文/0002-承.md': '---\n章号: 2\n标题: 承\n卷: 1\n字数: 100\n章定位: 推进\n钩子: 情绪钩-弱\n---\n正文。',
  20. '定稿/正文/0003-转.md': '---\n章号: 3\n标题: 转\n卷: 1\n字数: 100\n章定位: 推进\n钩子: 悬念钩-弱\n---\n正文。',
  21. })
  22. try {
  23. const r = await run([], {}, ctx)
  24. assert.equal(r.ok, true)
  25. // 第3、2章弱钩,第1章强钩 → 末尾连续 2
  26. assert.equal(JSON.parse(r.output).streak, 2)
  27. } finally {
  28. await cleanup()
  29. }
  30. })