takt: desu-koremadee2etesuto-tesuto (#150)

This commit is contained in:
nrs 2026-02-09 00:25:53 +09:00 committed by GitHub
parent 4b14a58982
commit b5eef8d3fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 1070 additions and 5 deletions

View File

@ -17,6 +17,9 @@ piece_categories:
pieces: pieces:
- expert - expert
- expert-cqrs - expert-cqrs
Refactoring:
pieces:
- structural-reform
🔀 Hybrid (Codex Coding): 🔀 Hybrid (Codex Coding):
🚀 Quick Start: 🚀 Quick Start:
pieces: pieces:

View File

@ -0,0 +1,455 @@
name: structural-reform
description: Full project review and structural reform - iterative codebase restructuring with staged file splits
max_iterations: 50
policies:
coding: ../policies/coding.md
review: ../policies/review.md
testing: ../policies/testing.md
qa: ../policies/qa.md
knowledge:
backend: ../knowledge/backend.md
architecture: ../knowledge/architecture.md
personas:
planner: ../personas/planner.md
coder: ../personas/coder.md
architecture-reviewer: ../personas/architecture-reviewer.md
qa-reviewer: ../personas/qa-reviewer.md
supervisor: ../personas/supervisor.md
instructions:
implement: ../instructions/implement.md
review-arch: ../instructions/review-arch.md
review-qa: ../instructions/review-qa.md
fix: ../instructions/fix.md
initial_movement: review
loop_monitors:
- cycle:
- implement
- fix
threshold: 3
judge:
persona: supervisor
instruction_template: |
The implement -> reviewers -> fix loop has repeated {cycle_count} times for the current reform target.
Review the reports from each cycle and determine whether this loop
is making progress or repeating the same issues.
**Reports to reference:**
- Architect review: {report:04-architect-review.md}
- QA review: {report:05-qa-review.md}
**Judgment criteria:**
- Are review findings being addressed in each fix cycle?
- Are the same issues recurring without resolution?
- Is the implementation converging toward approval?
rules:
- condition: Healthy (making progress toward approval)
next: implement
- condition: Unproductive (same issues recurring, no convergence)
next: next_target
movements:
- name: review
edit: false
persona: architecture-reviewer
policy: review
knowledge:
- architecture
- backend
allowed_tools:
- Read
- Glob
- Grep
- WebSearch
- WebFetch
instruction_template: |
## Piece Status
- Iteration: {iteration}/{max_iterations} (piece-wide)
- Movement Iteration: {movement_iteration} (times this movement has run)
- Movement: review (full project review)
## User Request
{task}
## Instructions
Conduct a comprehensive structural review of the entire project codebase.
**Focus areas:**
1. **God Classes/Functions**: Files exceeding 300 lines, classes with multiple responsibilities
2. **Coupling**: Circular dependencies, tight coupling between modules
3. **Cohesion**: Low-cohesion modules mixing unrelated concerns
4. **Testability**: Untestable code due to tight coupling or side effects
5. **Layer violations**: Wrong dependency directions, domain logic in adapters
6. **DRY violations**: Duplicated logic across 3+ locations
**For each issue found, report:**
- File path and line count
- Problem category (God Class, Low Cohesion, etc.)
- Severity (Critical / High / Medium)
- Specific responsibilities that should be separated
- Dependencies that would be affected by splitting
**Output format:**
```markdown
# Full Project Structural Review
## Summary
- Total files reviewed: N
- Issues found: N (Critical: N, High: N, Medium: N)
## Critical Issues
### 1. {File path} ({line count} lines)
- **Problem**: {category}
- **Severity**: Critical
- **Responsibilities found**:
1. {responsibility 1}
2. {responsibility 2}
- **Proposed split**:
- `{new-file-1}.ts`: {responsibility}
- `{new-file-2}.ts`: {responsibility}
- **Affected dependents**: {files that import this module}
## High Priority Issues
...
## Medium Priority Issues
...
## Dependency Graph Concerns
- {circular dependencies, layering violations}
## Recommended Reform Order
1. {file} - {reason for priority}
2. {file} - {reason for priority}
```
rules:
- condition: Full review is complete with findings
next: plan_reform
- condition: No structural issues found
next: COMPLETE
output_contracts:
report:
- name: 00-full-review.md
- name: plan_reform
edit: false
persona: planner
knowledge: architecture
allowed_tools:
- Read
- Glob
- Grep
- Bash
- WebSearch
- WebFetch
instruction_template: |
## Piece Status
- Iteration: {iteration}/{max_iterations} (piece-wide)
- Movement Iteration: {movement_iteration} (times this movement has run)
- Movement: plan_reform (reform plan creation)
## User Request
{task}
## Full Review Results
{previous_response}
## Additional User Inputs
{user_inputs}
## Instructions
Based on the full review results, create a concrete reform execution plan.
**Planning principles:**
- One file split per iteration (keep changes manageable)
- Order by dependency: split leaf nodes first, then work inward
- Each split must leave tests and build passing
- No backward compatibility concerns (per user instruction)
**For each reform target, specify:**
1. Target file and current line count
2. Proposed new files with responsibilities
3. Expected changes to imports in dependent files
4. Test strategy (new tests needed, existing tests to update)
5. Risk assessment (what could break)
**Output format:**
```markdown
# Structural Reform Plan
## Reform Targets (ordered by execution priority)
### Target 1: {file path}
- **Current state**: {line count} lines, {N} responsibilities
- **Proposed split**:
| New file | Responsibility | Estimated lines |
|----------|---------------|-----------------|
| `{path}` | {responsibility} | ~{N} |
- **Dependent files**: {list of files that import this}
- **Test plan**: {what tests to add/update}
- **Risk**: {Low/Medium/High} - {description}
### Target 2: {file path}
...
## Execution Order Rationale
{Why this order minimizes risk and dependency conflicts}
## Success Criteria
- All tests pass after each split
- Build succeeds after each split
- No file exceeds 300 lines
- Each file has single responsibility
```
rules:
- condition: Reform plan is complete and ready to execute
next: implement
- condition: No actionable reforms identified
next: COMPLETE
- condition: Requirements unclear, need user input
next: ABORT
appendix: |
Clarifications needed:
- {Question 1}
- {Question 2}
output_contracts:
report:
- name: 01-reform-plan.md
format: plan
- name: implement
edit: true
persona: coder
policy:
- coding
- testing
session: refresh
knowledge:
- backend
- architecture
allowed_tools:
- Read
- Glob
- Grep
- Edit
- Write
- Bash
- WebSearch
- WebFetch
permission_mode: edit
instruction: implement
rules:
- condition: Implementation complete
next: reviewers
- condition: Cannot proceed, insufficient info
next: reviewers
- condition: User input required
next: implement
requires_user_input: true
interactive_only: true
output_contracts:
report:
- Scope: 02-coder-scope.md
- Decisions: 03-coder-decisions.md
- name: reviewers
parallel:
- name: arch-review
edit: false
persona: architecture-reviewer
policy: review
knowledge:
- architecture
- backend
allowed_tools:
- Read
- Glob
- Grep
- WebSearch
- WebFetch
rules:
- condition: approved
- condition: needs_fix
instruction: review-arch
output_contracts:
report:
- name: 04-architect-review.md
format: architecture-review
- name: qa-review
edit: false
persona: qa-reviewer
policy:
- review
- qa
allowed_tools:
- Read
- Glob
- Grep
- WebSearch
- WebFetch
rules:
- condition: approved
- condition: needs_fix
instruction: review-qa
output_contracts:
report:
- name: 05-qa-review.md
format: qa-review
rules:
- condition: all("approved")
next: verify
- condition: any("needs_fix")
next: fix
- name: fix
edit: true
persona: coder
policy:
- coding
- testing
knowledge:
- backend
- architecture
allowed_tools:
- Read
- Glob
- Grep
- Edit
- Write
- Bash
- WebSearch
- WebFetch
permission_mode: edit
rules:
- condition: Fix complete
next: reviewers
- condition: Cannot proceed, insufficient info
next: plan_reform
instruction: fix
- name: verify
edit: false
persona: supervisor
policy: review
allowed_tools:
- Read
- Glob
- Grep
- Bash
- WebSearch
- WebFetch
instruction_template: |
## Piece Status
- Iteration: {iteration}/{max_iterations} (piece-wide)
- Movement Iteration: {movement_iteration} (times this movement has run)
- Movement: verify (build and test verification)
## Instructions
Verify that the current reform step has been completed successfully.
**Verification checklist:**
1. **Build**: Run the build command and confirm it passes
2. **Tests**: Run the test suite and confirm all tests pass
3. **File sizes**: Confirm no new file exceeds 300 lines
4. **Single responsibility**: Confirm each new file has a clear, single purpose
5. **Import consistency**: Confirm all imports are updated correctly
**Report format:**
```markdown
# Verification Results
## Result: PASS / FAIL
| Check | Status | Details |
|-------|--------|---------|
| Build | PASS/FAIL | {output summary} |
| Tests | PASS/FAIL | {N passed, N failed} |
| File sizes | PASS/FAIL | {any file > 300 lines} |
| Single responsibility | PASS/FAIL | {assessment} |
| Import consistency | PASS/FAIL | {any broken imports} |
## Issues (if FAIL)
1. {issue description}
```
rules:
- condition: All verifications passed
next: next_target
- condition: Verification failed
next: fix
output_contracts:
report:
- name: 06-verification.md
format: validation
- name: next_target
edit: false
persona: planner
knowledge: architecture
allowed_tools:
- Read
- Glob
- Grep
- Bash
- WebSearch
- WebFetch
instruction_template: |
## Piece Status
- Iteration: {iteration}/{max_iterations} (piece-wide)
- Movement Iteration: {movement_iteration} (times this movement has run)
- Movement: next_target (progress check and next target selection)
## Original Reform Plan
{report:01-reform-plan.md}
## Latest Verification
{previous_response}
## Instructions
Assess the progress of the structural reform and determine the next action.
**Steps:**
1. Review the reform plan and identify which targets have been completed
2. Check the current codebase state against the plan
3. Determine if there are remaining reform targets
**Output format:**
```markdown
# Reform Progress
## Completed Targets
| # | Target | Status |
|---|--------|--------|
| 1 | {file} | Completed |
| 2 | {file} | Completed |
## Remaining Targets
| # | Target | Priority |
|---|--------|----------|
| 3 | {file} | Next |
| 4 | {file} | Pending |
## Next Action
- **Target**: {next file to reform}
- **Plan**: {brief description of the split}
## Overall Progress
{N}/{total} targets completed. Estimated remaining iterations: {N}
```
rules:
- condition: More reform targets remain
next: implement
- condition: All reform targets completed
next: COMPLETE
output_contracts:
report:
- name: 07-progress.md
report_formats:
plan: ../output-contracts/plan.md
architecture-review: ../output-contracts/architecture-review.md
qa-review: ../output-contracts/qa-review.md
validation: ../output-contracts/validation.md
summary: ../output-contracts/summary.md

View File

@ -12,10 +12,14 @@ piece_categories:
- review-only - review-only
🎨 フロントエンド: {} 🎨 フロントエンド: {}
⚙️ バックエンド: {} ⚙️ バックエンド: {}
🔧 フルスタック: 🔧 エキスパート:
pieces: フルスタック:
- expert pieces:
- expert-cqrs - expert
- expert-cqrs
リファクタリング:
pieces:
- structural-reform
🔀 ハイブリッド (Codex Coding): 🔀 ハイブリッド (Codex Coding):
🚀 クイックスタート: 🚀 クイックスタート:
pieces: pieces:

View File

@ -0,0 +1,455 @@
name: structural-reform
description: プロジェクト全体レビューと構造改革 - 段階的なファイル分割による反復的コードベース再構築
max_iterations: 50
policies:
coding: ../policies/coding.md
review: ../policies/review.md
testing: ../policies/testing.md
qa: ../policies/qa.md
knowledge:
backend: ../knowledge/backend.md
architecture: ../knowledge/architecture.md
personas:
planner: ../personas/planner.md
coder: ../personas/coder.md
architecture-reviewer: ../personas/architecture-reviewer.md
qa-reviewer: ../personas/qa-reviewer.md
supervisor: ../personas/supervisor.md
instructions:
implement: ../instructions/implement.md
review-arch: ../instructions/review-arch.md
review-qa: ../instructions/review-qa.md
fix: ../instructions/fix.md
initial_movement: review
loop_monitors:
- cycle:
- implement
- fix
threshold: 3
judge:
persona: supervisor
instruction_template: |
implement → reviewers → fix のループが現在の改革ターゲットに対して {cycle_count} 回繰り返されました。
各サイクルのレポートを確認し、このループが進捗しているか、
同じ問題を繰り返しているかを判断してください。
**参照するレポート:**
- アーキテクチャレビュー: {report:04-architect-review.md}
- QAレビュー: {report:05-qa-review.md}
**判断基準:**
- 各修正サイクルでレビュー指摘が解消されているか
- 同じ問題が解決されずに繰り返されていないか
- 実装が承認に向かって収束しているか
rules:
- condition: 健全(承認に向けて進捗あり)
next: implement
- condition: 非生産的(同じ問題が繰り返され、収束なし)
next: next_target
movements:
- name: review
edit: false
persona: architecture-reviewer
policy: review
knowledge:
- architecture
- backend
allowed_tools:
- Read
- Glob
- Grep
- WebSearch
- WebFetch
instruction_template: |
## ピースステータス
- イテレーション: {iteration}/{max_iterations}(ピース全体)
- ムーブメントイテレーション: {movement_iteration}(このムーブメントの実行回数)
- ムーブメント: reviewプロジェクト全体レビュー
## ユーザーリクエスト
{task}
## 指示
プロジェクトのコードベース全体に対して、包括的な構造レビューを実施してください。
**重点領域:**
1. **God Class/Function**: 300行を超えるファイル、複数の責務を持つクラス
2. **結合度**: 循環依存、モジュール間の密結合
3. **凝集度**: 無関係な関心事が混在した低凝集モジュール
4. **テスタビリティ**: 密結合や副作用によるテスト困難なコード
5. **レイヤー違反**: 依存方向の誤り、アダプター層にドメインロジック
6. **DRY違反**: 3箇所以上の重複ロジック
**発見した問題ごとに報告:**
- ファイルパスと行数
- 問題カテゴリGod Class、低凝集など
- 深刻度Critical / High / Medium
- 分離すべき具体的な責務
- 分割により影響を受ける依存先
**出力フォーマット:**
```markdown
# プロジェクト全体構造レビュー
## サマリー
- レビュー対象ファイル数: N
- 検出された問題: NCritical: N, High: N, Medium: N
## Critical Issues
### 1. {ファイルパス}{行数}行)
- **問題**: {カテゴリ}
- **深刻度**: Critical
- **検出された責務**:
1. {責務1}
2. {責務2}
- **分割提案**:
- `{新ファイル1}.ts`: {責務}
- `{新ファイル2}.ts`: {責務}
- **影響を受ける依存先**: {このモジュールをインポートしているファイル}
## High Priority Issues
...
## Medium Priority Issues
...
## 依存グラフの懸念事項
- {循環依存、レイヤー違反}
## 推奨改革順序
1. {ファイル} - {優先理由}
2. {ファイル} - {優先理由}
```
rules:
- condition: 全体レビューが完了し、問題が検出された
next: plan_reform
- condition: 構造的な問題は見つからなかった
next: COMPLETE
output_contracts:
report:
- name: 00-full-review.md
- name: plan_reform
edit: false
persona: planner
knowledge: architecture
allowed_tools:
- Read
- Glob
- Grep
- Bash
- WebSearch
- WebFetch
instruction_template: |
## ピースステータス
- イテレーション: {iteration}/{max_iterations}(ピース全体)
- ムーブメントイテレーション: {movement_iteration}(このムーブメントの実行回数)
- ムーブメント: plan_reform改革計画策定
## ユーザーリクエスト
{task}
## 全体レビュー結果
{previous_response}
## ユーザー追加入力
{user_inputs}
## 指示
全体レビュー結果を基に、具体的な改革実行計画を策定してください。
**計画の原則:**
- 1イテレーションにつき1ファイルの分割変更を管理可能に保つ
- 依存順に実行:まずリーフノードを分割し、内側に向かって進む
- 各分割後にテストとビルドが通ること
- 後方互換は不要(ユーザー指示通り)
**各改革ターゲットについて指定:**
1. 対象ファイルと現在の行数
2. 提案する新ファイルと責務
3. 依存先ファイルのインポート変更予定
4. テスト戦略(新規テスト、既存テストの更新)
5. リスク評価(何が壊れる可能性があるか)
**出力フォーマット:**
```markdown
# 構造改革計画
## 改革ターゲット(実行優先順)
### ターゲット1: {ファイルパス}
- **現状**: {行数}行、{N}個の責務
- **分割提案**:
| 新ファイル | 責務 | 推定行数 |
|----------|------|---------|
| `{パス}` | {責務} | ~{N} |
- **依存先ファイル**: {このモジュールをインポートしているファイル一覧}
- **テスト計画**: {追加・更新すべきテスト}
- **リスク**: {Low/Medium/High} - {説明}
### ターゲット2: {ファイルパス}
...
## 実行順序の根拠
{この順序がリスクと依存関係の競合を最小化する理由}
## 成功基準
- 各分割後に全テストが通る
- 各分割後にビルドが成功する
- 300行を超えるファイルがない
- 各ファイルが単一責務を持つ
```
rules:
- condition: 改革計画が完成し、実行可能な状態
next: implement
- condition: 実行可能な改革が特定されなかった
next: COMPLETE
- condition: 要件が不明確、ユーザー入力が必要
next: ABORT
appendix: |
確認事項:
- {質問1}
- {質問2}
output_contracts:
report:
- name: 01-reform-plan.md
format: plan
- name: implement
edit: true
persona: coder
policy:
- coding
- testing
session: refresh
knowledge:
- backend
- architecture
allowed_tools:
- Read
- Glob
- Grep
- Edit
- Write
- Bash
- WebSearch
- WebFetch
permission_mode: edit
instruction: implement
rules:
- condition: 実装完了
next: reviewers
- condition: 判断できない、情報不足
next: reviewers
- condition: ユーザー入力が必要
next: implement
requires_user_input: true
interactive_only: true
output_contracts:
report:
- Scope: 02-coder-scope.md
- Decisions: 03-coder-decisions.md
- name: reviewers
parallel:
- name: arch-review
edit: false
persona: architecture-reviewer
policy: review
knowledge:
- architecture
- backend
allowed_tools:
- Read
- Glob
- Grep
- WebSearch
- WebFetch
rules:
- condition: approved
- condition: needs_fix
instruction: review-arch
output_contracts:
report:
- name: 04-architect-review.md
format: architecture-review
- name: qa-review
edit: false
persona: qa-reviewer
policy:
- review
- qa
allowed_tools:
- Read
- Glob
- Grep
- WebSearch
- WebFetch
rules:
- condition: approved
- condition: needs_fix
instruction: review-qa
output_contracts:
report:
- name: 05-qa-review.md
format: qa-review
rules:
- condition: all("approved")
next: verify
- condition: any("needs_fix")
next: fix
- name: fix
edit: true
persona: coder
policy:
- coding
- testing
knowledge:
- backend
- architecture
allowed_tools:
- Read
- Glob
- Grep
- Edit
- Write
- Bash
- WebSearch
- WebFetch
permission_mode: edit
rules:
- condition: 修正完了
next: reviewers
- condition: 判断できない、情報不足
next: plan_reform
instruction: fix
- name: verify
edit: false
persona: supervisor
policy: review
allowed_tools:
- Read
- Glob
- Grep
- Bash
- WebSearch
- WebFetch
instruction_template: |
## ピースステータス
- イテレーション: {iteration}/{max_iterations}(ピース全体)
- ムーブメントイテレーション: {movement_iteration}(このムーブメントの実行回数)
- ムーブメント: verifyビルド・テスト検証
## 指示
現在の改革ステップが正常に完了したことを検証してください。
**検証チェックリスト:**
1. **ビルド**: ビルドコマンドを実行し、成功することを確認
2. **テスト**: テストスイートを実行し、全テストが通ることを確認
3. **ファイルサイズ**: 新しいファイルが300行を超えていないことを確認
4. **単一責務**: 各新ファイルが明確な単一の目的を持つことを確認
5. **インポート整合性**: すべてのインポートが正しく更新されていることを確認
**レポートフォーマット:**
```markdown
# 検証結果
## 結果: PASS / FAIL
| チェック項目 | 状態 | 詳細 |
|------------|------|------|
| ビルド | PASS/FAIL | {出力サマリー} |
| テスト | PASS/FAIL | {N passed, N failed} |
| ファイルサイズ | PASS/FAIL | {300行超のファイルの有無} |
| 単一責務 | PASS/FAIL | {評価} |
| インポート整合性 | PASS/FAIL | {壊れたインポートの有無} |
## 問題点FAILの場合
1. {問題の説明}
```
rules:
- condition: すべての検証に合格
next: next_target
- condition: 検証に失敗
next: fix
output_contracts:
report:
- name: 06-verification.md
format: validation
- name: next_target
edit: false
persona: planner
knowledge: architecture
allowed_tools:
- Read
- Glob
- Grep
- Bash
- WebSearch
- WebFetch
instruction_template: |
## ピースステータス
- イテレーション: {iteration}/{max_iterations}(ピース全体)
- ムーブメントイテレーション: {movement_iteration}(このムーブメントの実行回数)
- ムーブメント: next_target進捗確認と次ターゲット選択
## 改革計画
{report:01-reform-plan.md}
## 最新の検証結果
{previous_response}
## 指示
構造改革の進捗を評価し、次のアクションを決定してください。
**手順:**
1. 改革計画を確認し、完了したターゲットを特定
2. 現在のコードベースの状態を計画と照合
3. 残りの改革ターゲットがあるか判断
**出力フォーマット:**
```markdown
# 改革進捗
## 完了ターゲット
| # | ターゲット | 状態 |
|---|----------|------|
| 1 | {ファイル} | 完了 |
| 2 | {ファイル} | 完了 |
## 残りターゲット
| # | ターゲット | 優先度 |
|---|----------|-------|
| 3 | {ファイル} | 次 |
| 4 | {ファイル} | 保留 |
## 次のアクション
- **ターゲット**: {次に改革するファイル}
- **計画**: {分割の概要}
## 全体進捗
{N}/{合計}ターゲット完了。残りの推定イテレーション数: {N}
```
rules:
- condition: まだ改革ターゲットが残っている
next: implement
- condition: すべての改革ターゲットが完了
next: COMPLETE
output_contracts:
report:
- name: 07-progress.md
report_formats:
plan: ../output-contracts/plan.md
architecture-review: ../output-contracts/architecture-review.md
qa-review: ../output-contracts/qa-review.md
validation: ../output-contracts/validation.md
summary: ../output-contracts/summary.md

View File

@ -158,6 +158,21 @@ describe('resolveRefToContent with layer resolution', () => {
// No context, no file — returns the spec as-is (inline content behavior) // No context, no file — returns the spec as-is (inline content behavior)
expect(content).toBe('some-name'); expect(content).toBe('some-name');
}); });
it('should fall back to resolveResourceContent when facet not found with context', () => {
// Given: facetType and context provided, but no matching facet file exists
// When: resolveRefToContent is called with a name that has no facet file
const content = resolveRefToContent(
'nonexistent-facet-xyz',
undefined,
tempDir,
'policies',
context,
);
// Then: falls back to resolveResourceContent, which returns the ref as inline content
expect(content).toBe('nonexistent-facet-xyz');
});
}); });
describe('resolveRefList with layer resolution', () => { describe('resolveRefList with layer resolution', () => {

View File

@ -45,7 +45,7 @@ describe('Piece Loader IT: builtin piece loading', () => {
rmSync(testDir, { recursive: true, force: true }); rmSync(testDir, { recursive: true, force: true });
}); });
const builtinNames = ['default', 'minimal', 'expert', 'expert-cqrs', 'research', 'magi', 'review-only', 'review-fix-minimal']; const builtinNames = ['default', 'minimal', 'expert', 'expert-cqrs', 'coding', 'passthrough', 'compound-eye', 'research', 'magi', 'review-only', 'review-fix-minimal', 'structural-reform'];
for (const name of builtinNames) { for (const name of builtinNames) {
it(`should load builtin piece: ${name}`, () => { it(`should load builtin piece: ${name}`, () => {
@ -572,6 +572,139 @@ movements:
}); });
}); });
describe('Piece Loader IT: structural-reform piece', () => {
let testDir: string;
beforeEach(() => {
testDir = createTestDir();
});
afterEach(() => {
rmSync(testDir, { recursive: true, force: true });
});
it('should load structural-reform with 7 movements', () => {
const config = loadPiece('structural-reform', testDir);
expect(config).not.toBeNull();
expect(config!.name).toBe('structural-reform');
expect(config!.movements.length).toBe(7);
expect(config!.maxIterations).toBe(50);
expect(config!.initialMovement).toBe('review');
});
it('should have expected movement names in order', () => {
const config = loadPiece('structural-reform', testDir);
expect(config).not.toBeNull();
const movementNames = config!.movements.map((m) => m.name);
expect(movementNames).toEqual([
'review',
'plan_reform',
'implement',
'reviewers',
'fix',
'verify',
'next_target',
]);
});
it('should have review as read-only with instruction_template', () => {
const config = loadPiece('structural-reform', testDir);
expect(config).not.toBeNull();
const review = config!.movements.find((m) => m.name === 'review');
expect(review).toBeDefined();
expect(review!.edit).not.toBe(true);
expect(review!.instructionTemplate).toBeDefined();
expect(review!.instructionTemplate).toContain('{task}');
});
it('should have implement with edit: true and session: refresh', () => {
const config = loadPiece('structural-reform', testDir);
expect(config).not.toBeNull();
const implement = config!.movements.find((m) => m.name === 'implement');
expect(implement).toBeDefined();
expect(implement!.edit).toBe(true);
expect(implement!.session).toBe('refresh');
});
it('should have 2 parallel reviewers (arch-review and qa-review)', () => {
const config = loadPiece('structural-reform', testDir);
expect(config).not.toBeNull();
const reviewers = config!.movements.find(
(m) => m.parallel && m.parallel.length > 0,
);
expect(reviewers).toBeDefined();
expect(reviewers!.parallel!.length).toBe(2);
const subNames = reviewers!.parallel!.map((s) => s.name);
expect(subNames).toContain('arch-review');
expect(subNames).toContain('qa-review');
});
it('should have aggregate rules on reviewers movement', () => {
const config = loadPiece('structural-reform', testDir);
expect(config).not.toBeNull();
const reviewers = config!.movements.find(
(m) => m.parallel && m.parallel.length > 0,
);
expect(reviewers).toBeDefined();
const allRule = reviewers!.rules?.find(
(r) => r.isAggregateCondition && r.aggregateType === 'all',
);
expect(allRule).toBeDefined();
expect(allRule!.aggregateConditionText).toBe('approved');
expect(allRule!.next).toBe('verify');
const anyRule = reviewers!.rules?.find(
(r) => r.isAggregateCondition && r.aggregateType === 'any',
);
expect(anyRule).toBeDefined();
expect(anyRule!.aggregateConditionText).toBe('needs_fix');
expect(anyRule!.next).toBe('fix');
});
it('should have verify movement with instruction_template', () => {
const config = loadPiece('structural-reform', testDir);
expect(config).not.toBeNull();
const verify = config!.movements.find((m) => m.name === 'verify');
expect(verify).toBeDefined();
expect(verify!.edit).not.toBe(true);
expect(verify!.instructionTemplate).toBeDefined();
});
it('should have next_target movement routing to implement or COMPLETE', () => {
const config = loadPiece('structural-reform', testDir);
expect(config).not.toBeNull();
const nextTarget = config!.movements.find((m) => m.name === 'next_target');
expect(nextTarget).toBeDefined();
expect(nextTarget!.edit).not.toBe(true);
const nextValues = nextTarget!.rules?.map((r) => r.next);
expect(nextValues).toContain('implement');
expect(nextValues).toContain('COMPLETE');
});
it('should have loop_monitors for implement-fix cycle', () => {
const config = loadPiece('structural-reform', testDir);
expect(config).not.toBeNull();
expect(config!.loopMonitors).toBeDefined();
expect(config!.loopMonitors!.length).toBe(1);
const monitor = config!.loopMonitors![0]!;
expect(monitor.cycle).toEqual(['implement', 'fix']);
expect(monitor.threshold).toBe(3);
expect(monitor.judge).toBeDefined();
});
});
describe('Piece Loader IT: invalid YAML handling', () => { describe('Piece Loader IT: invalid YAML handling', () => {
let testDir: string; let testDir: string;