mechanical-check.test.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 { run } from '../../src/commands/mechanical-check.js'
  6. import { tempBookCtx } from './_helper.js'
  7. test('mechanical-check 输出 pass/issues/candidates JSON', async () => {
  8. const { ctx, cleanup } = await tempBookCtx()
  9. try {
  10. const draft = `---
  11. 章号: 3
  12. 标题: 测
  13. 卷: 1
  14. 字数: 40
  15. 章定位: 推进
  16. 钩子: 危机钩-强
  17. 情绪定位: 铺垫
  18. ---
  19. 林晚立于殿前,握紧令牌,心中默念定要查明旧案,不负师门多年栽培。`
  20. await fs.writeFile(path.join(ctx.repoPath, '工作区', '草稿-A.md'), draft, 'utf8')
  21. const r = await run(['3'], {}, ctx)
  22. assert.equal(r.ok, true)
  23. const out = JSON.parse(r.output)
  24. assert.equal(typeof out.pass, 'boolean')
  25. assert.ok(Array.isArray(out.issues))
  26. assert.ok(Array.isArray(out.candidates))
  27. } finally {
  28. await cleanup()
  29. }
  30. })
  31. test('mechanical-check 非数字章号 → ok=false', async () => {
  32. const { ctx, cleanup } = await tempBookCtx()
  33. try {
  34. const r = await run(['abc'], {}, ctx)
  35. assert.equal(r.ok, false)
  36. } finally {
  37. await cleanup()
  38. }
  39. })