list-threads.test.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { test, before, after } from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { run } from '../../src/commands/list-threads.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('list-threads --type=foreshadow 只返回伏笔', async () => {
  13. const r = await run([], { type: 'foreshadow' }, ctx)
  14. assert.equal(r.ok, true)
  15. const rows = JSON.parse(r.output)
  16. assert.ok(rows.length >= 1)
  17. assert.ok(rows.every((t) => t.id.startsWith('伏笔')))
  18. })
  19. test('list-threads --type=suspense 只返回悬念', async () => {
  20. const r = await run([], { type: 'suspense' }, ctx)
  21. assert.equal(r.ok, true)
  22. const rows = JSON.parse(r.output)
  23. assert.ok(rows.some((t) => t.id === '悬念-001'))
  24. })
  25. test('list-threads --strength=高 按强度筛选', async () => {
  26. const r = await run([], { strength: '高' }, ctx)
  27. assert.equal(r.ok, true)
  28. const rows = JSON.parse(r.output)
  29. assert.ok(rows.every((t) => t.strength === '高'))
  30. assert.ok(rows.some((t) => t.id === '伏笔-001'))
  31. })
  32. test('list-threads --悬了太久 返回数组(不崩)', async () => {
  33. const r = await run([], { 悬了太久: true }, ctx)
  34. assert.equal(r.ok, true)
  35. assert.ok(Array.isArray(JSON.parse(r.output)))
  36. })
  37. test('list-threads 无筛选 → ok=false 提示', async () => {
  38. const r = await run([], {}, ctx)
  39. assert.equal(r.ok, false)
  40. })