// @vitest-environment jsdom
/**
* ツール履歴からファイルを開く導線が、チャットの実行中の行にも届いているか
* (issue #989 要望③)。
*
* 実行中に流れる tool_call コメントは ChatMessage → ProgressCard の中で
* ToolCallsSection に化ける。この受け渡しが 1 段でも抜けると、ステップが
* 終わるまでファイル名が押せない。
*/
import '../../test/dom-setup';
import { describe, it, expect, vi } from 'vitest';
import { fireEvent, screen } from '@testing-library/react';
import { renderWithProviders } from '../../test/render-helpers';
import type { LocalTaskComment } from '../../api';
import { ChatMessage } from './ChatMessage';
vi.mock('../embed/EmbedBlock', () => ({ EmbedBlock: () => null }));
const toolCallComment = {
id: 9,
taskId: 42,
author: 'agent',
kind: 'progress',
body: JSON.stringify({
type: 'tool_call',
callId: 'call-1',
movement: 'execute',
name: 'Write',
args: JSON.stringify({ file_path: 'output/report.md', content: 'x' }),
result: 'ok',
isError: false,
durationMs: 10,
}),
attachments: [],
createdAt: '2026-08-07T10:00:20.000Z',
injectedAt: null,
} as unknown as LocalTaskComment;
describe('ChatMessage のツール行', () => {
it('実行中に流れる書き込みの行でも、ファイル名を押せる', () => {
const onOpenToolFile = vi.fn();
renderWithProviders();
fireEvent.click(screen.getByRole('button', { name: 'output/report.md' }));
expect(onOpenToolFile).toHaveBeenCalledWith({
section: 'output',
path: 'report.md',
wroteFile: true,
at: '2026-08-07T10:00:20.000Z',
});
});
it('開く先が無ければリンクにしない', () => {
renderWithProviders();
expect(screen.queryByRole('button', { name: 'output/report.md' })).toBeNull();
});
});