import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { resolve, dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; import { mkdtempSync, writeFileSync, rmSync } from 'node:fs'; import { join } from 'node:path'; import { tmpdir } from 'node:os'; import { execFileSync } from 'node:child_process'; import { createIsolatedEnv, type IsolatedEnv } from '../helpers/isolated-env'; import { runTakt } from '../helpers/takt-runner'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); function createLocalRepo(): { path: string; cleanup: () => void } { const repoPath = mkdtempSync(join(tmpdir(), 'takt-e2e-quiet-')); execFileSync('git', ['init'], { cwd: repoPath, stdio: 'pipe' }); execFileSync('git', ['config', 'user.email', 'test@example.com'], { cwd: repoPath, stdio: 'pipe' }); execFileSync('git', ['config', 'user.name', 'Test'], { cwd: repoPath, stdio: 'pipe' }); writeFileSync(join(repoPath, 'README.md'), '# test\n'); execFileSync('git', ['add', '.'], { cwd: repoPath, stdio: 'pipe' }); execFileSync('git', ['commit', '-m', 'init'], { cwd: repoPath, stdio: 'pipe' }); return { path: repoPath, cleanup: () => { try { rmSync(repoPath, { recursive: true, force: true }); } catch { /* best-effort */ } }, }; } // E2E更新時は docs/testing/e2e.md も更新すること describe('E2E: Quiet mode (--quiet)', () => { let isolatedEnv: IsolatedEnv; let repo: { path: string; cleanup: () => void }; beforeEach(() => { isolatedEnv = createIsolatedEnv(); repo = createLocalRepo(); }); afterEach(() => { try { repo.cleanup(); } catch { /* best-effort */ } try { isolatedEnv.cleanup(); } catch { /* best-effort */ } }); it('should suppress AI stream output in quiet mode', () => { // Given: a simple piece and scenario const piecePath = resolve(__dirname, '../fixtures/pieces/mock-single-step.yaml'); const scenarioPath = resolve(__dirname, '../fixtures/scenarios/execute-done.json'); // When: running with --quiet flag const result = runTakt({ args: [ '--task', 'Test quiet mode', '--piece', piecePath, '--create-worktree', 'no', '--provider', 'mock', '--quiet', ], cwd: repo.path, env: { ...isolatedEnv.env, TAKT_MOCK_SCENARIO: scenarioPath, }, timeout: 240_000, }); // Then: completes successfully; mock content should not appear in output expect(result.exitCode).toBe(0); // In quiet mode, the raw mock response text should be suppressed expect(result.stdout).not.toContain('Mock response for persona'); }, 240_000); });