read-thread.test.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { test, before, after } from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { run } from '../../src/commands/read-thread.js'
  4. import { fixtureCtx } from './_helper.js'
  5. let ctx, cleanup
  6. before(async () => {
  7. ;({ ctx, cleanup } = await fixtureCtx())
  8. })
  9. after(async () => {
  10. await cleanup()
  11. })
  12. test('read-thread 默认返回基本信息(强度/状态)', async () => {
  13. const r = await run(['伏笔-001'], {}, ctx)
  14. assert.equal(r.ok, true)
  15. const data = JSON.parse(r.output)
  16. assert.equal(data.strength ?? data.强度, '高')
  17. assert.equal(data.status ?? data.状态, '进行')
  18. })
  19. test('read-thread --履历 返回履历列表(含章号)', async () => {
  20. const r = await run(['伏笔-001'], { 履历: true }, ctx)
  21. assert.equal(r.ok, true)
  22. const history = JSON.parse(r.output)
  23. assert.ok(Array.isArray(history))
  24. assert.ok(history.some((h) => h.章号 === 1))
  25. })
  26. test('read-thread 缺 ID → ok=false', async () => {
  27. const r = await run([], {}, ctx)
  28. assert.equal(r.ok, false)
  29. })
  30. test('read-thread 不存在的条目 → ok=false 且不崩', async () => {
  31. const r = await run(['伏笔-999'], {}, ctx)
  32. assert.equal(r.ok, false)
  33. assert.match(r.error, /不存在/)
  34. })