takt/e2e/specs/config-priority.e2e.ts
nrs 4f02c20c1d
Merge pull request #465 from nrslib/takt/420/remove-default-piece-switch
feat: デフォルトピースの概念と takt switch コマンドを削除
2026-03-04 18:02:28 +09:00

97 lines
2.9 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { dirname, join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { parse as parseYaml } from 'yaml';
import { createIsolatedEnv, updateIsolatedConfig, type IsolatedEnv } from '../helpers/isolated-env';
import { createTestRepo, type TestRepo } from '../helpers/test-repo';
import { runTakt } from '../helpers/takt-runner';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
function readFirstTask(repoPath: string): Record<string, unknown> {
const tasksPath = join(repoPath, '.takt', 'tasks.yaml');
const raw = readFileSync(tasksPath, 'utf-8');
const parsed = parseYaml(raw) as { tasks?: Array<Record<string, unknown>> } | null;
const first = parsed?.tasks?.[0];
if (!first) {
throw new Error(`No task record found in ${tasksPath}`);
}
return first;
}
// E2E更新時は docs/testing/e2e.md も更新すること
describe('E2E: Config priority (piece / autoPr)', () => {
let isolatedEnv: IsolatedEnv;
let testRepo: TestRepo;
beforeEach(() => {
isolatedEnv = createIsolatedEnv();
testRepo = createTestRepo();
});
afterEach(() => {
try {
testRepo.cleanup();
} catch {
// best-effort
}
try {
isolatedEnv.cleanup();
} catch {
// best-effort
}
});
it('should require --piece in pipeline even when config has piece', () => {
const configuredPiecePath = resolve(__dirname, '../fixtures/pieces/mock-single-step.yaml');
const scenarioPath = resolve(__dirname, '../fixtures/scenarios/execute-done.json');
const projectConfigDir = join(testRepo.path, '.takt');
mkdirSync(projectConfigDir, { recursive: true });
writeFileSync(
join(projectConfigDir, 'config.yaml'),
`piece: ${JSON.stringify(configuredPiecePath)}\n`,
'utf-8',
);
const result = runTakt({
args: [
'--pipeline',
'--task', 'Pipeline run should resolve piece from config',
'--skip-git',
'--provider', 'mock',
],
cwd: testRepo.path,
env: {
...isolatedEnv.env,
TAKT_MOCK_SCENARIO: scenarioPath,
},
timeout: 240_000,
});
expect(result.exitCode).toBe(1);
expect(`${result.stdout}${result.stderr}`).toContain('piece');
}, 240_000);
it('should default auto_pr to true when unset in config/env', () => {
const piecePath = resolve(__dirname, '../fixtures/pieces/mock-single-step.yaml');
const result = runTakt({
args: [
'--piece', piecePath,
'add',
'Auto PR default behavior',
],
cwd: testRepo.path,
env: isolatedEnv.env,
timeout: 240_000,
});
expect(result.exitCode).toBe(0);
const task = readFirstTask(testRepo.path);
expect(task['auto_pr']).toBe(true);
}, 240_000);
});