takt/src/__tests__/reset-global-config.test.ts
nrslib a8223d231d refactor: config 3層モデル整理 + supervisor ペルソナのファセット分離是正
Config:
- PersistedGlobalConfig → GlobalConfig にリネーム、互換エイリアス削除
- persisted-global-config.ts → config-types.ts にリネーム
- ProjectConfig → GlobalConfig extends Omit<ProjectConfig, ...> の継承構造に整理
- verbose/logLevel/log_level を削除(logging セクションに統一)
- migration 機構(migratedProjectLocalKeys 等)を削除

Supervisor ペルソナ:
- 後方互換コードの検出・その場しのぎの検出・ボーイスカウトルールを除去(review.md ポリシー / architecture.md ナレッジと重複)
- ピース全体の見直しを supervise.md インストラクションに移動

takt-default-team-leader:
- loop_monitor のインライン instruction_template を既存ファイル参照に変更
- implement の「判断できない」ルールを ai_review → plan に修正
2026-03-06 01:29:46 +09:00

61 lines
2.5 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { mkdtempSync, mkdirSync, readFileSync, writeFileSync, existsSync, rmSync } from 'node:fs';
import { join } from 'node:path';
import { tmpdir } from 'node:os';
import { resetGlobalConfigToTemplate } from '../infra/config/global/resetConfig.js';
describe('resetGlobalConfigToTemplate', () => {
const originalEnv = process.env;
let testRoot: string;
let taktDir: string;
let configPath: string;
beforeEach(() => {
testRoot = mkdtempSync(join(tmpdir(), 'takt-reset-config-'));
taktDir = join(testRoot, '.takt');
mkdirSync(taktDir, { recursive: true });
configPath = join(taktDir, 'config.yaml');
process.env = { ...originalEnv, TAKT_CONFIG_DIR: taktDir };
});
afterEach(() => {
process.env = originalEnv;
rmSync(testRoot, { recursive: true, force: true });
});
it('should backup existing config and replace with language-matched template', () => {
writeFileSync(configPath, ['language: ja', 'provider: mock'].join('\n'), 'utf-8');
const result = resetGlobalConfigToTemplate(new Date('2026-02-19T12:00:00Z'));
expect(result.language).toBe('ja');
expect(result.backupPath).toBeDefined();
expect(existsSync(result.backupPath!)).toBe(true);
expect(readFileSync(result.backupPath!, 'utf-8')).toContain('provider: mock');
const newConfig = readFileSync(configPath, 'utf-8');
expect(newConfig).toContain('# TAKT グローバル設定サンプル');
expect(newConfig).toContain('language: ja');
// Template should only have 'language' as an active (non-commented) setting
const activeLines = newConfig.split('\n').filter(line => !line.startsWith('#') && line.trim() !== '');
expect(activeLines.length).toBe(1);
expect(activeLines[0]).toMatch(/^language: ja/);
});
it('should create config from default language template when config does not exist', () => {
rmSync(configPath, { force: true });
const result = resetGlobalConfigToTemplate(new Date('2026-02-19T12:00:00Z'));
expect(result.backupPath).toBeUndefined();
expect(result.language).toBe('en');
expect(existsSync(configPath)).toBe(true);
const newConfig = readFileSync(configPath, 'utf-8');
expect(newConfig).toContain('# TAKT global configuration sample');
expect(newConfig).toContain('language: en');
const activeLines = newConfig.split('\n').filter(line => !line.startsWith('#') && line.trim() !== '');
expect(activeLines.length).toBe(1);
expect(activeLines[0]).toMatch(/^language: en/);
});
});