tui-transcript-presentation.test.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import { describe, expect, it } from 'vitest';
  2. import { presentTranscriptCell } from '../../src/tui/transcript/presentation/content.js';
  3. import { createTranscriptCell } from '../../src/tui/transcript/model.js';
  4. import { TranscriptPresentationController } from '../../src/tui/transcript/presentation/state.js';
  5. describe('TranscriptPresentationController', () => {
  6. it('uses the run timer format in duration summaries and search text', () => {
  7. const presentation = presentTranscriptCell(
  8. createTranscriptCell({
  9. id: 'long-run',
  10. kind: 'turn-duration',
  11. status: 'succeeded',
  12. content: '',
  13. durationMs: 7_770_999,
  14. createdAtMs: 1,
  15. }),
  16. );
  17. expect(presentation.summary).toBe('2h9min30s');
  18. expect(presentation.searchText).toContain('2h9min30s');
  19. });
  20. it('previews only live Thinking and collapses settled Thinking in compact mode', () => {
  21. const running = createTranscriptCell({
  22. id: 'thinking-running',
  23. kind: 'thinking',
  24. status: 'running',
  25. content: 'Inspecting',
  26. createdAtMs: 1,
  27. });
  28. const settled = (['succeeded', 'failed', 'cancelled'] as const).map((status) =>
  29. createTranscriptCell({
  30. id: `thinking-${status}`,
  31. kind: 'thinking',
  32. status,
  33. content: `${status} detail`,
  34. createdAtMs: 1,
  35. }),
  36. );
  37. const presentation = new TranscriptPresentationController();
  38. expect(presentation.resolveMainDisplayMode(running)).toBe('preview');
  39. expect(settled.map((cell) => presentation.resolveMainDisplayMode(cell))).toEqual([
  40. 'collapsed',
  41. 'collapsed',
  42. 'collapsed',
  43. ]);
  44. expect(presentation.toggleMainMode()).toBe('detailed');
  45. expect([running, ...settled].map((cell) => presentation.resolveMainDisplayMode(cell))).toEqual([
  46. 'expanded',
  47. 'expanded',
  48. 'expanded',
  49. 'expanded',
  50. ]);
  51. expect(
  52. [running, ...settled].every(
  53. (cell) => cell.displayMode === undefined && cell.expanded === undefined,
  54. ),
  55. ).toBe(true);
  56. });
  57. it('collapses Tool details for every lifecycle state until detailed mode is requested', () => {
  58. const tools = (['running', 'succeeded', 'failed'] as const).map((status) =>
  59. createTranscriptCell({
  60. id: `tool-${status}`,
  61. kind: 'tool',
  62. status,
  63. title: 'bash',
  64. content: '{"command":"pnpm test"}',
  65. detail: `${status} output`,
  66. createdAtMs: 1,
  67. }),
  68. );
  69. const presentation = new TranscriptPresentationController();
  70. expect(tools.map((cell) => presentation.resolveMainDisplayMode(cell))).toEqual([
  71. 'collapsed',
  72. 'collapsed',
  73. 'collapsed',
  74. ]);
  75. presentation.setMainMode('detailed');
  76. expect(tools.map((cell) => presentation.resolveMainDisplayMode(cell))).toEqual([
  77. 'expanded',
  78. 'expanded',
  79. 'expanded',
  80. ]);
  81. expect(presentation.revision).toBe(1);
  82. });
  83. it('keeps completed Tool results and structured changes collapsed', () => {
  84. const completedTool = createTranscriptCell({
  85. id: 'tool-completed',
  86. kind: 'tool',
  87. status: 'succeeded',
  88. title: 'bash',
  89. content: '{"command":"pnpm test"}',
  90. detail: '114 passed',
  91. createdAtMs: 1,
  92. });
  93. const structuredTool = createTranscriptCell({
  94. id: 'tool-structured',
  95. kind: 'tool',
  96. status: 'succeeded',
  97. title: 'edit',
  98. content: '{"path":"src/app.ts"}',
  99. structuredPreview: {
  100. schemaVersion: 1,
  101. state: 'applied',
  102. blocks: [
  103. {
  104. kind: 'diff',
  105. path: 'src/app.ts',
  106. diff: '- old\n+ new',
  107. addedLines: 1,
  108. removedLines: 1,
  109. truncated: false,
  110. },
  111. ],
  112. },
  113. createdAtMs: 2,
  114. });
  115. const presentation = new TranscriptPresentationController();
  116. expect(presentation.resolveMainDisplayMode(completedTool)).toBe('collapsed');
  117. expect(presentation.resolveMainDisplayMode(structuredTool)).toBe('collapsed');
  118. });
  119. });