Setting the file. One moment.
Test Render Report · LLM To Bedrock · aws/agent-toolkit-for-aws · Skills Docs
ContentsBack to the top of the page 81
Creating Amazon Aurora Db Cluster With Instances
104
Routing Traffic With Route53 And CloudFront
Resilience Program Design
Creating API Gateway Stage
def _write_phase_results
— line 89
This file
Number 30.30
Position 30 of 35
Type Python
Size 6 KB
Lines 175 scripts/ test_render_report.py
Python · 175 lines · 6 KB
: [
"app.py"
,
"pyproject.toml"
],
13 "notes" : "5 tests generated, 5/5 passing in clean checkout." ,
14 },
15 "report" : "Report written to /repo/MIGRATION_REPORT_2026-06-10.md. Overall status: ready-to-merge." ,
16 "evalRes" : { "pass_rate" : 0.89 , "total_cases" : 9 , "failures" : 1 , "notes" : "" },
17 "repo" : "/nonexistent-repo" ,
18 "reportDateSuffix" : "2026-06-10" ,
19 }
20
21
22 def test_summarize_handles_prose_report ():
23 out = rr.summarize(real_payload())
24 assert "bedrock-migration" in out
25 assert "89%" in out
26 assert "2 files" in out
27 assert "5/5 passing" in out
28
29
30 def test_summarize_zero_golden_cases_not_rendered_as_100_percent ():
31 p = real_payload()
32 p[ "evalRes" ] = { "pass_rate" : 1.0 , "total_cases" : 0 , "failures" : 0 ,
33 "notes" : "no_golden_cases: true \n reason: empty dataset" }
34 out = rr.summarize(p)
35 assert "100%" not in out
36 assert "N/A" in out
37
38
39 def test_summarize_degenerate_payload_does_not_crash ():
40 out = rr.summarize({})
41 assert "AI Migration Complete!" in out
42 assert "(none)" in out
43
44
45 def test_summarize_report_as_string_does_not_crash ():
46 # regression: the original implementation called .get() on the prose string
47 p = real_payload()
48 p[ "report" ] = "just prose"
49 rr.summarize(p)
50
51
52 def test_summarize_omits_test_line_when_notes_unparseable ():
53 p = real_payload()
54 p[ "rewrite" ][ "notes" ] = "no test info here"
55 out = rr.summarize(p)
56 assert "Tests:" not in out
57
58
59 def test_find_report_path_prefers_suffix_match (tmp_path):
60 (tmp_path / "MIGRATION_REPORT_2026-06-10.md" ).write_text( "x" )
61 (tmp_path / "MIGRATION_REPORT_2026-01-01.md" ).write_text( "y" )
62 p = { "repo" : str (tmp_path), "reportDateSuffix" : "2026-06-10" }
63 assert rr.find_report_path(p).endswith( "MIGRATION_REPORT_2026-06-10.md" )
64
65
66 def test_find_report_path_falls_back_to_latest_glob (tmp_path):
67 (tmp_path / "MIGRATION_REPORT_2026-01-01.md" ).write_text( "y" )
68 p = { "repo" : str (tmp_path), "reportDateSuffix" : "2026-06-10" }
69 assert rr.find_report_path(p).endswith( "MIGRATION_REPORT_2026-01-01.md" )
70
71
72 def test_find_report_path_no_repo_returns_none ():
73 assert rr.find_report_path({}) is None
74
75
76 def test_main_rejects_malformed_json (tmp_path, capsys):
77 bad = tmp_path / "payload.json"
78 bad.write_text( "{not json" )
79 rc = rr.main([ str (bad)])
80 assert rc == 1
81 assert "cannot read payload" in capsys.readouterr().err
82
83
84 # ---------- --phase-results mode ----------
85
86 import json
87
88
89 def _write_phase_results (tmp_path, rewrite = None , eval_res = None , deltas = None ):
90 d = tmp_path / "phase-results"
91 d.mkdir()
92 if rewrite is not None :
93 (d / "rewrite.json" ).write_text(json.dumps(rewrite))
94 if eval_res is not None :
95 (d / "eval.json" ).write_text(json.dumps(eval_res))
96 if deltas is not None :
97 (d / "delta-decisions.json" ).write_text(json.dumps(deltas))
98 return str (d)
99
100
101 def test_phase_results_mode_happy_path (tmp_path, capsys):
102 d = _write_phase_results(
103 tmp_path,
104 rewrite = { "branch_name" : "bedrock-migration" , "files_changed" : [ "a.py" ],
105 "notes" : "3 tests generated, 3/3 passing" },
106 eval_res = { "pass_rate" : 0.9 , "total_cases" : 10 , "failures" : 1 , "notes" : "" },
107 deltas = [{ "delta_type" : "x" , "location" : "a.py:1" ,
108 "resolution_chosen" : "range_narrowed_1" , "source" : "user_question" }],
109 )
110 rc = rr.main([ "--phase-results" , d, "--repo" , str (tmp_path),
111 "--results-dir" , str (tmp_path / "out" )])
112 assert rc == 0
113 out = capsys.readouterr().out
114 assert "bedrock-migration" in out
115 assert "90%" in out
116 assert "3/3 passing" in out
117 assert "decisions applied: 1" in out
118
119
120 def test_phase_results_missing_eval_degrades (tmp_path, capsys):
121 d = _write_phase_results(tmp_path, rewrite = { "branch_name" : "b" , "files_changed" : []})
122 rc = rr.main([ "--phase-results" , d, "--repo" , str (tmp_path),
123 "--results-dir" , str (tmp_path / "out" )])
124 assert rc == 0
125 assert "(unavailable)" in capsys.readouterr().out
126
127
128 def test_phase_results_control_state_file_not_treated_as_payload (tmp_path, capsys):
129 d = _write_phase_results(
130 tmp_path,
131 rewrite = { "branch_name" : "b" , "files_changed" : []},
132 eval_res = { "partial" : { "completed" : 3 , "total" : 9 , "reason" : "throttled" }},
133 )
134 rc = rr.main([ "--phase-results" , d, "--repo" , str (tmp_path),
135 "--results-dir" , str (tmp_path / "out" )])
136 assert rc == 0
137 assert "(unavailable)" in capsys.readouterr().out # partial != payload
138
139
140 def test_partial_coverage_note_rendered (tmp_path, capsys):
141 d = _write_phase_results(
142 tmp_path,
143 rewrite = { "branch_name" : "b" , "files_changed" : []},
144 eval_res = { "pass_rate" : 0.8 , "total_cases" : 4 , "failures" : 1 ,
145 "notes" : "partial_coverage: 4/9 cases (throttled)" },
146 )
147 rr.main([ "--phase-results" , d, "--repo" , str (tmp_path),
148 "--results-dir" , str (tmp_path / "out" )])
149 assert "partial coverage 4/9" in capsys.readouterr().out
150
151
152 def test_both_modes_is_argparse_error (tmp_path):
153 import pytest
154 d = _write_phase_results(tmp_path, rewrite = {})
155 payload = tmp_path / "p.json"
156 payload.write_text( " {} " )
157 with pytest.raises( SystemExit ):
158 rr.main([ str (payload), "--phase-results" , d, "--repo" , str (tmp_path)])
159
160
161 def test_neither_mode_is_argparse_error ():
162 import pytest
163 with pytest.raises( SystemExit ):
164 rr.main([])
165
166
167 def test_results_dir_still_means_copy_destination (tmp_path, capsys):
168 (tmp_path / "MIGRATION_REPORT_2026-06-10.md" ).write_text( "report body" )
169 d = _write_phase_results(tmp_path, rewrite = { "branch_name" : "b" , "files_changed" : []},
170 eval_res = { "pass_rate" : 1.0 , "total_cases" : 1 , "failures" : 0 , "notes" : "" })
171 dest = tmp_path / "copies"
172 rc = rr.main([ "--phase-results" , d, "--repo" , str (tmp_path),
173 "--date-suffix" , "2026-06-10" , "--results-dir" , str (dest)])
174 assert rc == 0
175 assert (dest / "MIGRATION_REPORT_2026-06-10.md" ).exists()