This commit is contained in:
nrslib 2026-02-10 07:30:33 +09:00
parent 0c0519eeb4
commit 55aeeab4ec
2 changed files with 26 additions and 18 deletions

View File

@ -1,8 +1,9 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { execFileSync } from 'node:child_process'; import { execFileSync } from 'node:child_process';
import { readFileSync, readdirSync, writeFileSync } from 'node:fs'; import { readFileSync, writeFileSync } from 'node:fs';
import { join, dirname, resolve } from 'node:path'; import { join, dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url'; import { fileURLToPath } from 'node:url';
import { parse as parseYaml } from 'yaml';
import { createIsolatedEnv, type IsolatedEnv } from '../helpers/isolated-env'; import { createIsolatedEnv, type IsolatedEnv } from '../helpers/isolated-env';
import { createTestRepo, type TestRepo } from '../helpers/test-repo'; import { createTestRepo, type TestRepo } from '../helpers/test-repo';
import { runTakt } from '../helpers/takt-runner'; import { runTakt } from '../helpers/takt-runner';
@ -84,12 +85,10 @@ describe('E2E: Add task from GitHub issue (takt add)', () => {
expect(result.exitCode).toBe(0); expect(result.exitCode).toBe(0);
const tasksDir = join(testRepo.path, '.takt', 'tasks'); const tasksFile = join(testRepo.path, '.takt', 'tasks.yaml');
const files = readdirSync(tasksDir).filter((file) => file.endsWith('.yaml')); const content = readFileSync(tasksFile, 'utf-8');
expect(files.length).toBe(1); const parsed = parseYaml(content) as { tasks?: Array<{ issue?: number }> };
expect(parsed.tasks?.length).toBe(1);
const taskFile = join(tasksDir, files[0] ?? ''); expect(parsed.tasks?.[0]?.issue).toBe(Number(issueNumber));
const content = readFileSync(taskFile, 'utf-8');
expect(content).toContain('issue:');
}, 240_000); }, 240_000);
}); });

View File

@ -1,8 +1,9 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { spawn } from 'node:child_process'; import { spawn } from 'node:child_process';
import { mkdirSync, writeFileSync, existsSync } from 'node:fs'; import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { join, resolve, dirname } from 'node:path'; import { join, resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url'; import { fileURLToPath } from 'node:url';
import { parse as parseYaml } from 'yaml';
import { createIsolatedEnv, type IsolatedEnv } from '../helpers/isolated-env'; import { createIsolatedEnv, type IsolatedEnv } from '../helpers/isolated-env';
import { createTestRepo, type TestRepo } from '../helpers/test-repo'; import { createTestRepo, type TestRepo } from '../helpers/test-repo';
@ -51,16 +52,21 @@ describe('E2E: Watch tasks (takt watch)', () => {
stdout += chunk.toString(); stdout += chunk.toString();
}); });
const tasksDir = join(testRepo.path, '.takt', 'tasks'); const taktDir = join(testRepo.path, '.takt');
mkdirSync(tasksDir, { recursive: true }); mkdirSync(taktDir, { recursive: true });
const tasksFile = join(taktDir, 'tasks.yaml');
const createdAt = new Date().toISOString();
const taskYaml = [ const taskYaml = [
'task: "Add a single line \\\"watch test\\\" to README.md"', 'tasks:',
`piece: "${piecePath}"`, ' - name: watch-task',
' status: pending',
' content: "Add a single line \\"watch test\\" to README.md"',
` piece: "${piecePath}"`,
` created_at: "${createdAt}"`,
' started_at: null',
' completed_at: null',
].join('\n'); ].join('\n');
writeFileSync(tasksFile, taskYaml, 'utf-8');
const taskPath = join(tasksDir, 'watch-task.yaml');
writeFileSync(taskPath, taskYaml, 'utf-8');
const completed = await new Promise<boolean>((resolvePromise) => { const completed = await new Promise<boolean>((resolvePromise) => {
const timeout = setTimeout(() => resolvePromise(false), 240_000); const timeout = setTimeout(() => resolvePromise(false), 240_000);
@ -87,6 +93,9 @@ describe('E2E: Watch tasks (takt watch)', () => {
}); });
expect(completed).toBe(true); expect(completed).toBe(true);
expect(existsSync(taskPath)).toBe(false); const tasksRaw = readFileSync(tasksFile, 'utf-8');
const parsed = parseYaml(tasksRaw) as { tasks?: Array<{ name?: string; status?: string }> };
const watchTask = parsed.tasks?.find((task) => task.name === 'watch-task');
expect(watchTask?.status).toBe('completed');
}, 240_000); }, 240_000);
}); });