Skip to content

Commit ed28116

Browse files
committed
format: Format
1 parent 5d8ad95 commit ed28116

2 files changed

Lines changed: 30 additions & 27 deletions

File tree

build_tools/sharpy_dogfood/orchestrator.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ async def _generate_and_validate_multifile_code(
15981598
)
15991599
last_error = (
16001600
"Malformed response: you have an unclosed <code> tag. "
1601-
"Make sure every <code> or <code file=\"name.spy\"> tag has a matching </code>."
1601+
'Make sure every <code> or <code file="name.spy"> tag has a matching </code>.'
16021602
)
16031603
if attempt < max_attempts:
16041604
print(
@@ -1641,7 +1641,7 @@ async def _generate_and_validate_multifile_code(
16411641
files = extract_multifile_code(gen_result.output)
16421642
if not files:
16431643
print(" Failed to parse multi-file response", file=sys.stderr)
1644-
last_error = "Failed to parse multi-file response. Use <code file=\"name.spy\">...</code> tags for each file, and include a main.spy file."
1644+
last_error = 'Failed to parse multi-file response. Use <code file="name.spy">...</code> tags for each file, and include a main.spy file.'
16451645
# Keep last_files from previous attempt if available
16461646
# Only retry if we have previous files to include in feedback
16471647
if attempt < max_attempts and last_files is not None:
@@ -1773,10 +1773,9 @@ async def _generate_and_validate_multifile_code(
17731773

17741774
# All validation passed
17751775
# Try XML <expected> tags from raw response first, fall back to comment-based
1776-
expected_output = (
1777-
extract_expected_output_from_response(gen_result.output)
1778-
or extract_expected_output_from_multifile(files)
1779-
)
1776+
expected_output = extract_expected_output_from_response(
1777+
gen_result.output
1778+
) or extract_expected_output_from_multifile(files)
17801779
print(" All files validated successfully (compiler)", file=sys.stderr)
17811780
return MultifileGenerationResult(
17821781
success=True,

build_tools/tests/test_prompts.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,14 @@ def test_basic_extraction(self):
9292
assert result == 'print("hello")'
9393

9494
def test_with_surrounding_text(self):
95-
response = 'Here is the code:\n<code>\ndef main():\n print(1)\n</code>\nDone.'
95+
response = (
96+
"Here is the code:\n<code>\ndef main():\n print(1)\n</code>\nDone."
97+
)
9698
result = extract_code_from_xml(response)
9799
assert result == "def main():\n print(1)"
98100

99101
def test_no_code_tag(self):
100-
response = 'Just some text without code tags'
102+
response = "Just some text without code tags"
101103
result = extract_code_from_xml(response)
102104
assert result is None
103105

@@ -109,7 +111,7 @@ def test_does_not_match_file_attr(self):
109111
assert result is None
110112

111113
def test_multiline_code(self):
112-
response = '<code>\nclass Foo:\n x: int\n def __init__(self):\n self.x = 0\n</code>'
114+
response = "<code>\nclass Foo:\n x: int\n def __init__(self):\n self.x = 0\n</code>"
113115
result = extract_code_from_xml(response)
114116
assert "class Foo:" in result
115117
assert "self.x = 0" in result
@@ -119,27 +121,27 @@ class TestExtractExpectedFromXml:
119121
"""Tests for extract_expected_from_xml()."""
120122

121123
def test_basic_extraction(self):
122-
response = '<expected>\n42\n</expected>'
124+
response = "<expected>\n42\n</expected>"
123125
result = extract_expected_from_xml(response)
124126
assert result == "42\n"
125127

126128
def test_multiline_expected(self):
127-
response = '<expected>\nhello\nworld\n</expected>'
129+
response = "<expected>\nhello\nworld\n</expected>"
128130
result = extract_expected_from_xml(response)
129131
assert result == "hello\nworld\n"
130132

131133
def test_no_expected_tag(self):
132-
response = 'No expected output here'
134+
response = "No expected output here"
133135
result = extract_expected_from_xml(response)
134136
assert result is None
135137

136138
def test_empty_expected(self):
137-
response = '<expected>\n</expected>'
139+
response = "<expected>\n</expected>"
138140
result = extract_expected_from_xml(response)
139141
assert result is None
140142

141143
def test_with_code_and_expected(self):
142-
response = '<code>\nprint(1)\n</code>\n<expected>\n1\n</expected>'
144+
response = "<code>\nprint(1)\n</code>\n<expected>\n1\n</expected>"
143145
result = extract_expected_from_xml(response)
144146
assert result == "1\n"
145147

@@ -199,41 +201,43 @@ class TestHasUnclosedCodeTags:
199201
"""Tests for has_unclosed_code_tags()."""
200202

201203
def test_balanced_tags(self):
202-
response = '<code>\nprint(1)\n</code>'
204+
response = "<code>\nprint(1)\n</code>"
203205
assert has_unclosed_code_tags(response) is False
204206

205207
def test_unclosed_tag(self):
206-
response = '<code>\nprint(1)\n'
208+
response = "<code>\nprint(1)\n"
207209
assert has_unclosed_code_tags(response) is True
208210

209211
def test_multiple_balanced(self):
210-
response = '<code file="a.spy">\nfoo\n</code>\n<code file="b.spy">\nbar\n</code>'
212+
response = (
213+
'<code file="a.spy">\nfoo\n</code>\n<code file="b.spy">\nbar\n</code>'
214+
)
211215
assert has_unclosed_code_tags(response) is False
212216

213217
def test_one_unclosed_of_two(self):
214218
response = '<code file="a.spy">\nfoo\n</code>\n<code file="b.spy">\nbar\n'
215219
assert has_unclosed_code_tags(response) is True
216220

217221
def test_no_tags(self):
218-
response = 'Just some text'
222+
response = "Just some text"
219223
assert has_unclosed_code_tags(response) is False
220224

221225

222226
class TestExtractCodeBlockXmlFallback:
223227
"""Tests that extract_code_block tries XML first, then markdown."""
224228

225229
def test_xml_preferred_over_markdown(self):
226-
response = '<code>\nxml_code()\n</code>\n```python\nmarkdown_code()\n```'
230+
response = "<code>\nxml_code()\n</code>\n```python\nmarkdown_code()\n```"
227231
result = extract_code_block(response)
228232
assert result == "xml_code()"
229233

230234
def test_falls_back_to_markdown(self):
231-
response = '```python\nmarkdown_code()\n```'
235+
response = "```python\nmarkdown_code()\n```"
232236
result = extract_code_block(response)
233237
assert result == "markdown_code()"
234238

235239
def test_falls_back_to_raw_code(self):
236-
response = 'def main():\n print(1)'
240+
response = "def main():\n print(1)"
237241
result = extract_code_block(response)
238242
assert "def main():" in result
239243

@@ -245,17 +249,17 @@ def test_xml_preferred_over_markers(self):
245249
response = (
246250
'<code file="utils.spy">\ndef xml_helper(): pass\n</code>\n'
247251
'<code file="main.spy">\ndef main(): pass\n</code>\n'
248-
'=== FILE: utils.spy ===\ndef marker_helper(): pass\n'
249-
'=== FILE: main.spy ===\ndef main(): pass\n'
252+
"=== FILE: utils.spy ===\ndef marker_helper(): pass\n"
253+
"=== FILE: main.spy ===\ndef main(): pass\n"
250254
)
251255
result = extract_multifile_code(response)
252256
assert result is not None
253257
assert "xml_helper" in result["utils.spy"]
254258

255259
def test_falls_back_to_markers(self):
256260
response = (
257-
'=== FILE: utils.spy ===\ndef marker_helper(): pass\n\n'
258-
'=== FILE: main.spy ===\ndef main(): pass\n'
261+
"=== FILE: utils.spy ===\ndef marker_helper(): pass\n\n"
262+
"=== FILE: main.spy ===\ndef main(): pass\n"
259263
)
260264
result = extract_multifile_code(response)
261265
assert result is not None
@@ -266,11 +270,11 @@ class TestExtractExpectedOutputFromResponseXml:
266270
"""Tests that extract_expected_output_from_response tries XML first."""
267271

268272
def test_xml_expected(self):
269-
response = '<code>\nprint(42)\n</code>\n<expected>\n42\n</expected>'
273+
response = "<code>\nprint(42)\n</code>\n<expected>\n42\n</expected>"
270274
result = extract_expected_output_from_response(response)
271275
assert result == "42\n"
272276

273277
def test_falls_back_to_comment(self):
274-
response = '```python\nprint(42)\n# EXPECTED OUTPUT:\n# 42\n```'
278+
response = "```python\nprint(42)\n# EXPECTED OUTPUT:\n# 42\n```"
275279
result = extract_expected_output_from_response(response)
276280
assert result == "42\n"

0 commit comments

Comments
 (0)