Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions scripts/process-fix-result-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
build_summary_body = mod.build_summary_body
main = mod.main

Comment thread
ggallen marked this conversation as resolved.
Resolved
_SCHEMA_PATH = os.path.join(
Comment thread
ggallen marked this conversation as resolved.
Resolved
os.path.dirname(os.path.abspath(__file__)),
"..",
"schemas",
"fix-result.schema.json",
)
_SCHEMA_ENV = {"FULLSEND_OUTPUT_SCHEMA": _SCHEMA_PATH}


class TestBuildSummaryBody(unittest.TestCase):
def test_basic_summary_with_fixes(self):
Expand Down Expand Up @@ -215,6 +223,7 @@ def test_short_body_not_truncated(self):
self.assertLess(len(body), MAX_COMMENT_LENGTH)


@patch.dict(os.environ, _SCHEMA_ENV)
class TestUnknownActionType(unittest.TestCase):
def test_unknown_type_rejected_by_schema(self):
"""Unknown action types are now caught by schema validation (exit 1)."""
Expand All @@ -241,6 +250,7 @@ def test_unknown_type_rejected_by_schema(self):
os.unlink(f.name)


@patch.dict(os.environ, _SCHEMA_ENV)
class TestPostSummaryFailure(unittest.TestCase):
def test_returns_2_when_comment_post_fails(self):
data = {
Expand All @@ -267,6 +277,7 @@ def test_returns_2_when_comment_post_fails(self):
os.unlink(f.name)


@patch.dict(os.environ, _SCHEMA_ENV)
class TestMain(unittest.TestCase):
def test_missing_args(self):
self.assertEqual(main([]), 1)
Expand Down Expand Up @@ -321,6 +332,7 @@ def test_empty_actions_fails_schema_validation(self):
os.unlink(f.name)


@patch.dict(os.environ, _SCHEMA_ENV)
class TestSchemaValidation(unittest.TestCase):
"""Tests for schema validation added in #412."""

Expand Down Expand Up @@ -446,5 +458,56 @@ def test_invalid_trigger_source_fails(self):
os.unlink(f.name)


@patch.dict(os.environ, _SCHEMA_ENV)
class TestSchemaEnvVar(unittest.TestCase):
"""Tests for FULLSEND_OUTPUT_SCHEMA env var requirement (#526)."""

def test_missing_env_var_fails(self):
"""Missing FULLSEND_OUTPUT_SCHEMA exits 1 with a clear error."""
data = {
"pr_number": 42,
"trigger_source": "bot",
"actions": [
{"type": "fix", "finding": "nil check", "description": "Fixed"},
],
"summary": "All good.",
"tests_passed": True,
"files_changed": ["foo.go"],
}
Comment thread
ggallen marked this conversation as resolved.
Resolved
Comment thread
ggallen marked this conversation as resolved.
Resolved
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as f:
json.dump(data, f)
f.flush()
try:
Comment thread
ggallen marked this conversation as resolved.
Resolved
os.environ.pop("FULLSEND_OUTPUT_SCHEMA", None)
with contextlib.redirect_stderr(io.StringIO()) as captured:
result = main([f.name, "org/repo", "42", "--dry-run"])
self.assertEqual(result, 1)
self.assertIn("FULLSEND_OUTPUT_SCHEMA", captured.getvalue())
finally:
os.unlink(f.name)

def test_env_var_used_for_schema_path(self):
"""When FULLSEND_OUTPUT_SCHEMA is set, it is used as the schema path."""
data = {
"pr_number": 42,
"trigger_source": "bot",
"actions": [
{"type": "fix", "finding": "nil check", "description": "Fixed"},
],
"summary": "All good.",
"tests_passed": True,
"files_changed": ["foo.go"],
}
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as f:
json.dump(data, f)
f.flush()
try:
# FULLSEND_OUTPUT_SCHEMA is set by the class-level @patch.dict
result = main([f.name, "org/repo", "42", "--dry-run"])
self.assertEqual(result, 0)
finally:
os.unlink(f.name)


if __name__ == "__main__":
unittest.main()
13 changes: 7 additions & 6 deletions scripts/process-fix-result.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,13 @@ def main(argv=None):
return 1

if jsonschema is not None:
Comment thread
ggallen marked this conversation as resolved.
Resolved
schema_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"..",
"schemas",
"fix-result.schema.json",
)
schema_path = os.environ.get("FULLSEND_OUTPUT_SCHEMA")
Comment thread
ggallen marked this conversation as resolved.
Resolved
Comment thread
ggallen marked this conversation as resolved.
Resolved
Comment thread
ggallen marked this conversation as resolved.
Resolved
Comment thread
ggallen marked this conversation as resolved.
Resolved
Comment thread
ggallen marked this conversation as resolved.
Resolved
if not schema_path:
print(
"::error::Cannot resolve schema path: FULLSEND_OUTPUT_SCHEMA environment variable is not set",
file=sys.stderr,
)
return 1
try:
with open(schema_path) as f:
schema = json.load(f)
Expand Down
Loading