Skip to content
Open
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
12 changes: 10 additions & 2 deletions libs/hackbot-runtime/hackbot_runtime/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ def _finish(ctx: HackbotContext, outcome: object) -> int:
log.error(msg)
payload = _error_payload(ctx, msg)
exit_code = 1
payload["agent_version"] = ctx.config.agent_version

try:
_publish_log(ctx)
Expand All @@ -181,8 +180,17 @@ def _finish(ctx: HackbotContext, outcome: object) -> int:

try:
ctx.publish_changes()
except Exception:
except Exception as exc:
log.exception("Failed to publish source changes")
if exit_code == 0:
payload = _error_payload(
ctx,
f"Failed to publish source changes: {type(exc).__name__}: {exc}",
traceback_str=traceback.format_exc(),
)
exit_code = 1

payload["agent_version"] = ctx.config.agent_version

# Upload when a signed policy is configured, else write into the local
# artifacts dir (so local/compose/direct runs leave it on the host).
Expand Down
18 changes: 18 additions & 0 deletions libs/hackbot-runtime/tests/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ def test_summary_written_for_exception(tmp_path):
assert "boom" in summary["error"]


def test_run_fails_when_publishing_changes_raises(tmp_path, monkeypatch):
ctx = _ctx(tmp_path)

def _raise(self):
raise RuntimeError("git status failed")

monkeypatch.setattr(HackbotContext, "publish_changes", _raise)

code = _finish(ctx, HackbotAgentResult(num_turns=1))

assert code == 1
summary = json.loads(
(tmp_path / "artifacts" / "local-test" / "summary.json").read_text()
)
assert summary["status"] == "error"
assert "git status failed" in summary["error"]


def test_removed_action_is_absent_from_summary(tmp_path):
ctx = _ctx(tmp_path)
inaccurate = ctx.actions.record(
Expand Down