takt/e2e/specs/error-handling.e2e.ts
nrs 4a92ba2012
[#366] implement-exceeded-requeue (#374)
* takt: implement-exceeded-requeue

* takt: implement-exceeded-requeue

* takt: implement-exceeded-requeue

* ci: trigger CI

* fix: 未使用インポート削除と --create-worktree e2e テスト修正

InteractiveModeAction の不要な import を削除して lint エラーを解消する。
--create-worktree オプション削除に合わせ e2e の期待メッセージを更新する。

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-03-02 23:30:53 +09:00

136 lines
4.2 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { createIsolatedEnv, type IsolatedEnv } from '../helpers/isolated-env';
import { runTakt } from '../helpers/takt-runner';
import { createLocalRepo, type LocalRepo } from '../helpers/test-repo';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// E2E更新時は docs/testing/e2e.md も更新すること
describe('E2E: Error handling edge cases (mock)', () => {
let isolatedEnv: IsolatedEnv;
let repo: LocalRepo;
beforeEach(() => {
isolatedEnv = createIsolatedEnv();
repo = createLocalRepo();
});
afterEach(() => {
try { repo.cleanup(); } catch { /* best-effort */ }
try { isolatedEnv.cleanup(); } catch { /* best-effort */ }
});
it('should error when --piece points to a nonexistent file path', () => {
// Given: a nonexistent piece file path
// When: running with a bad piece path
const result = runTakt({
args: [
'--task', 'test',
'--piece', '/nonexistent/path/to/piece.yaml',
'--provider', 'mock',
],
cwd: repo.path,
env: isolatedEnv.env,
timeout: 240_000,
});
// Then: exits with error
expect(result.exitCode).not.toBe(0);
const combined = result.stdout + result.stderr;
expect(combined).toMatch(/not found|does not exist|ENOENT/i);
}, 240_000);
it('should report error when --piece specifies a nonexistent piece name', () => {
// Given: a nonexistent piece name
// When: running with a bad piece name
const result = runTakt({
args: [
'--task', 'test',
'--piece', 'nonexistent-piece-name-xyz',
'--provider', 'mock',
],
cwd: repo.path,
env: isolatedEnv.env,
timeout: 240_000,
});
// Then: output contains error about piece not found
// Note: takt reports the error but currently exits with code 0
const combined = result.stdout + result.stderr;
expect(combined).toMatch(/not found/i);
}, 240_000);
it('should error when --pipeline is used without --task or --issue', () => {
// Given: pipeline mode with no task or issue
const piecePath = resolve(__dirname, '../fixtures/pieces/mock-single-step.yaml');
// When: running in pipeline mode without a task
const result = runTakt({
args: [
'--pipeline',
'--piece', piecePath,
'--skip-git',
'--provider', 'mock',
],
cwd: repo.path,
env: isolatedEnv.env,
timeout: 240_000,
});
// Then: exits with error (should not hang in interactive mode due to TAKT_NO_TTY=1)
expect(result.exitCode).not.toBe(0);
const combined = result.stdout + result.stderr;
expect(combined).toMatch(/task|issue|required/i);
}, 240_000);
it('should error when deprecated --create-worktree option is used', () => {
// Given: deprecated option value
const piecePath = resolve(__dirname, '../fixtures/pieces/mock-single-step.yaml');
// When: running with invalid worktree option
const result = runTakt({
args: [
'--task', 'test',
'--piece', piecePath,
'--create-worktree', 'invalid-value',
'--provider', 'mock',
],
cwd: repo.path,
env: isolatedEnv.env,
timeout: 240_000,
});
// Then: exits with migration error
const combined = result.stdout + result.stderr;
expect(result.exitCode).not.toBe(0);
expect(combined).toContain("unknown option '--create-worktree'");
}, 240_000);
it('should error when piece file contains invalid YAML', () => {
// Given: a broken YAML piece file
const brokenPiecePath = resolve(__dirname, '../fixtures/pieces/broken.yaml');
// When: running with the broken piece
const result = runTakt({
args: [
'--task', 'test',
'--piece', brokenPiecePath,
'--provider', 'mock',
],
cwd: repo.path,
env: isolatedEnv.env,
timeout: 240_000,
});
// Then: exits with error about parsing
expect(result.exitCode).not.toBe(0);
const combined = result.stdout + result.stderr;
expect(combined).toMatch(/parse|invalid|error|validation/i);
}, 240_000);
});