|
| 1 | +# Task: Fix E2E test assertions for round-numbered findings and docs count |
| 2 | + |
| 3 | +## Background |
| 4 | + |
| 5 | +PR #172 introduced round-numbered findings files (`{file_id}_r{round_num}.json`) in Phase D. |
| 6 | +Phase E reads these files but no longer deletes them (by design — findings history is preserved). |
| 7 | +The E2E test `_assert_full_output` still asserts that `findings_dir` is empty after Phase E, which is now incorrect. |
| 8 | + |
| 9 | +Additionally, the docs count assertion was incorrectly changed from `M + 1` to `M` in this PR branch. |
| 10 | +Phase M generates M knowledge docs + 1 README.md = M + 1 files total. |
| 11 | + |
| 12 | +## File to edit |
| 13 | + |
| 14 | +`tools/knowledge-creator/tests/e2e/test_e2e.py` |
| 15 | + |
| 16 | +## Change 1: Update `_assert_full_output` signature and findings_dir assertion |
| 17 | + |
| 18 | +### Before (lines 126–155 on main): |
| 19 | + |
| 20 | +```python |
| 21 | +def _assert_full_output(ctx, expected, catalog_entries, U, M): |
| 22 | + """全kcコマンド共通の出力検証。 |
| 23 | +
|
| 24 | + Phase Mまで実行した後の全出力を検証する。 |
| 25 | + CC呼び出し回数は各テストで個別にアサートするため含まない。 |
| 26 | + """ |
| 27 | + # catalog.json entries |
| 28 | + catalog = _load_json(ctx.classified_list_path) |
| 29 | + catalog_ids = {f["id"] for f in catalog["files"]} |
| 30 | + expected_ids = {e["id"] for e in catalog_entries} |
| 31 | + assert catalog_ids == expected_ids, ( |
| 32 | + f"Catalog IDs mismatch: extra={catalog_ids - expected_ids}, " |
| 33 | + f"missing={expected_ids - catalog_ids}" |
| 34 | + ) |
| 35 | + assert len(catalog["files"]) == U |
| 36 | + |
| 37 | + # knowledge_cache_dir |
| 38 | + assert _count_json_files(ctx.knowledge_cache_dir) == U, ( |
| 39 | + f"Expected {U} files in knowledge_cache_dir, " |
| 40 | + f"got {_count_json_files(ctx.knowledge_cache_dir)}" |
| 41 | + ) |
| 42 | + for entry in catalog_entries: |
| 43 | + cache_path = f"{ctx.knowledge_cache_dir}/{entry['output_path']}" |
| 44 | + assert os.path.exists(cache_path), f"Missing cache file: {cache_path}" |
| 45 | + |
| 46 | + # findings_dir empty |
| 47 | + if os.path.isdir(ctx.findings_dir): |
| 48 | + assert _count_all_files(ctx.findings_dir, ".json") == 0, ( |
| 49 | + "findings_dir should be empty after Phase E" |
| 50 | + ) |
| 51 | +``` |
| 52 | + |
| 53 | +### After: |
| 54 | + |
| 55 | +```python |
| 56 | +def _assert_full_output(ctx, expected, catalog_entries, U, M, |
| 57 | + expected_findings_count=0): |
| 58 | + """全kcコマンド共通の出力検証。 |
| 59 | +
|
| 60 | + Phase Mまで実行した後の全出力を検証する。 |
| 61 | + CC呼び出し回数は各テストで個別にアサートするため含まない。 |
| 62 | +
|
| 63 | + expected_findings_count: Phase D が保存したラウンド番号付き findings ファイルの |
| 64 | + 期待数。Phase D/E ループはラウンドごとに findings を保持する設計のため、 |
| 65 | + findings_dir には processed_files × max_rounds 個のファイルが残る。 |
| 66 | + """ |
| 67 | + # catalog.json entries |
| 68 | + catalog = _load_json(ctx.classified_list_path) |
| 69 | + catalog_ids = {f["id"] for f in catalog["files"]} |
| 70 | + expected_ids = {e["id"] for e in catalog_entries} |
| 71 | + assert catalog_ids == expected_ids, ( |
| 72 | + f"Catalog IDs mismatch: extra={catalog_ids - expected_ids}, " |
| 73 | + f"missing={expected_ids - catalog_ids}" |
| 74 | + ) |
| 75 | + assert len(catalog["files"]) == U |
| 76 | + |
| 77 | + # knowledge_cache_dir |
| 78 | + assert _count_json_files(ctx.knowledge_cache_dir) == U, ( |
| 79 | + f"Expected {U} files in knowledge_cache_dir, " |
| 80 | + f"got {_count_json_files(ctx.knowledge_cache_dir)}" |
| 81 | + ) |
| 82 | + for entry in catalog_entries: |
| 83 | + cache_path = f"{ctx.knowledge_cache_dir}/{entry['output_path']}" |
| 84 | + assert os.path.exists(cache_path), f"Missing cache file: {cache_path}" |
| 85 | + |
| 86 | + # findings_dir: round-numbered findings files are preserved |
| 87 | + if os.path.isdir(ctx.findings_dir): |
| 88 | + actual_findings = _count_all_files(ctx.findings_dir, ".json") |
| 89 | + assert actual_findings == expected_findings_count, ( |
| 90 | + f"findings_dir should have {expected_findings_count} round-numbered files, " |
| 91 | + f"got {actual_findings}" |
| 92 | + ) |
| 93 | + # Verify all findings files follow _r{N}.json naming convention |
| 94 | + for root, _, files in os.walk(ctx.findings_dir): |
| 95 | + for f in files: |
| 96 | + if f.endswith(".json"): |
| 97 | + assert "_r" in f, ( |
| 98 | + f"Findings file {f} missing round number suffix (_rN.json)" |
| 99 | + ) |
| 100 | +``` |
| 101 | + |
| 102 | +## Change 2: Restore docs count assertion |
| 103 | + |
| 104 | +### Before (current branch): |
| 105 | + |
| 106 | +```python |
| 107 | + # docs |
| 108 | + docs_count = _count_all_files(ctx.docs_dir) |
| 109 | + assert docs_count == M, ( |
| 110 | + f"Expected {M} doc files, got {docs_count}" |
| 111 | + ) |
| 112 | +``` |
| 113 | + |
| 114 | +### After: |
| 115 | + |
| 116 | +```python |
| 117 | + # docs (M knowledge .md files + 1 README.md generated by Phase M) |
| 118 | + docs_count = _count_all_files(ctx.docs_dir) |
| 119 | + assert docs_count == M + 1, ( |
| 120 | + f"Expected {M + 1} doc files (M={M} knowledge docs + 1 README.md), got {docs_count}" |
| 121 | + ) |
| 122 | +``` |
| 123 | + |
| 124 | +## Change 3: Pass `expected_findings_count` at all 5 call sites |
| 125 | + |
| 126 | +Each call to `_assert_full_output` needs `expected_findings_count` added. |
| 127 | +The value depends on how many files Phase D processes and how many rounds run. |
| 128 | + |
| 129 | +### TestGen (around line 478): |
| 130 | + |
| 131 | +```python |
| 132 | + _assert_full_output(ctx, expected, catalog_entries, U, M, |
| 133 | + expected_findings_count=U * ctx.max_rounds) |
| 134 | +``` |
| 135 | + |
| 136 | +### TestGenResume (around line 538): |
| 137 | + |
| 138 | +```python |
| 139 | + _assert_full_output(ctx, expected, catalog_entries, U, M, |
| 140 | + expected_findings_count=U * ctx.max_rounds) |
| 141 | +``` |
| 142 | + |
| 143 | +### TestRegenTarget (around line 598): |
| 144 | + |
| 145 | +```python |
| 146 | + _assert_full_output(ctx, expected, catalog_entries, U, M, |
| 147 | + expected_findings_count=target_count * ctx.max_rounds) |
| 148 | +``` |
| 149 | + |
| 150 | +### TestFix (around line 665): |
| 151 | + |
| 152 | +```python |
| 153 | + _assert_full_output(ctx, expected, catalog_entries, U, M, |
| 154 | + expected_findings_count=U * ctx.max_rounds) |
| 155 | +``` |
| 156 | + |
| 157 | +### TestFixTarget (around line 722): |
| 158 | + |
| 159 | +```python |
| 160 | + _assert_full_output(ctx, expected, catalog_entries, U, M, |
| 161 | + expected_findings_count=target_count * ctx.max_rounds) |
| 162 | +``` |
| 163 | + |
| 164 | +## Why these values |
| 165 | + |
| 166 | +| Test | Phase D processes | Rounds | expected_findings_count | |
| 167 | +|------|------------------|--------|------------------------| |
| 168 | +| TestGen | All U files | max_rounds (2) | U × 2 | |
| 169 | +| TestGenResume | All U files (Phase B skips 1, but D checks all) | max_rounds (2) | U × 2 | |
| 170 | +| TestRegenTarget | target_count files only | max_rounds (2) | target_count × 2 | |
| 171 | +| TestFix | All U files | max_rounds (2) | U × 2 | |
| 172 | +| TestFixTarget | target_count files only | max_rounds (2) | target_count × 2 | |
| 173 | + |
| 174 | +`_copy_state` does NOT copy findings_dir, so target-based tests start with empty findings_dir. |
| 175 | + |
| 176 | +## Verification |
| 177 | + |
| 178 | +```bash |
| 179 | +cd tools/knowledge-creator |
| 180 | + |
| 181 | +# UT (should pass in ~20s) |
| 182 | +python3 -m pytest tests/ut/ --tb=short |
| 183 | + |
| 184 | +# E2E v6 (should pass in ~3min) |
| 185 | +python3 -m pytest tests/e2e/ -k "6" --tb=short |
| 186 | + |
| 187 | +# E2E v5 (should pass in ~4min) |
| 188 | +python3 -m pytest tests/e2e/ -k "5" --tb=short |
| 189 | +``` |
| 190 | + |
| 191 | +All 174 UT tests and 10 E2E tests (5 per version) must pass. |
0 commit comments