m3-flows.test.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { test } from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { run as impactRun } from '../../src/commands/impact.js'
  4. import { run as gotoRun } from '../../src/commands/goto-chapter.js'
  5. import { makeGitBook, chapter } from '../state-machine/_helper.js'
  6. test('impact 命令:输出影响分析 JSON', async () => {
  7. const { ctx, cleanup } = await makeGitBook({
  8. 'book.yaml': 'spec_version: "7.0"\n书名: 测\n已发布到章: 0\n',
  9. '定稿/正文/0001-起.md': chapter(1, '林晚得到玉佩。'),
  10. })
  11. try {
  12. const r = await impactRun(['玉佩'], {}, ctx)
  13. assert.equal(r.ok, true)
  14. const out = JSON.parse(r.output)
  15. assert.deepEqual(out.未发布, [1])
  16. } finally {
  17. await cleanup()
  18. }
  19. })
  20. test('goto-chapter 命令:不带 --confirm 只展示影响', async () => {
  21. const { ctx, cleanup } = await makeGitBook(
  22. { 'book.yaml': 'spec_version: "7.0"\n书名: 测\n' },
  23. {
  24. commits: [
  25. { message: 'ch(1): 起', files: { '定稿/正文/0001-起.md': chapter(1) } },
  26. { message: 'ch(2): 承', files: { '定稿/正文/0002-承.md': chapter(2) } },
  27. ],
  28. }
  29. )
  30. try {
  31. const r = await gotoRun(['1'], {}, ctx)
  32. assert.equal(r.ok, true)
  33. assert.match(r.output, /丢弃|ch\(2\)/)
  34. } finally {
  35. await cleanup()
  36. }
  37. })
  38. test('goto-chapter 命令:非数字章号 → ok=false', async () => {
  39. const { ctx, cleanup } = await makeGitBook({ 'book.yaml': '书名: 测\n' })
  40. try {
  41. const r = await gotoRun(['abc'], {}, ctx)
  42. assert.equal(r.ok, false)
  43. } finally {
  44. await cleanup()
  45. }
  46. })