diff --git a/.gitignore b/.gitignore index d5969d29b7..e4b87d0541 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,7 @@ results/ !/.github/signature-fixtures/basic_jobs.json !perf/perf_baseline.json !src/trend_analysis/export/manifest_schema.json +!tests/fixtures/keepalive/*.json # Stop tracking noisy autofix history (now artifact-only) ci/autofix/history.json ci/autofix/diagnostics.json diff --git a/scripts/keepalive-runner.js b/scripts/keepalive-runner.js index 428394cfae..e435ed83df 100644 --- a/scripts/keepalive-runner.js +++ b/scripts/keepalive-runner.js @@ -189,8 +189,9 @@ async function runKeepalive({ core, github, context, env = process.env }) { } const latestCommandTs = new Date(commandComments[commandComments.length - 1].created_at).getTime(); - if (latestCommandTs > lastAgentTs) { - core.info(`#${prNumber}: skipped – waiting for Codex response to the latest command.`); + const minutesSinceCommand = (now - latestCommandTs) / 60000; + if (latestCommandTs > lastAgentTs && minutesSinceCommand < idleMinutes) { + core.info(`#${prNumber}: skipped – waiting for Codex response to the latest command (${minutesSinceCommand.toFixed(1)} minutes < ${idleMinutes}).`); continue; } diff --git a/tests/fixtures/keepalive/command_pending.json b/tests/fixtures/keepalive/command_pending.json new file mode 100644 index 0000000000..f2136b974a --- /dev/null +++ b/tests/fixtures/keepalive/command_pending.json @@ -0,0 +1,42 @@ +{ + "repo": {"owner": "stranske", "repo": "Trend_Model_Project"}, + "now": "2024-05-18T12:00:00Z", + "env": { + "OPTIONS_JSON": "{}", + "DRY_RUN": "false" + }, + "pulls": [ + { + "number": 606, + "labels": ["agent:codex"], + "comments": [ + { + "user": {"login": "triage-bot"}, + "body": "@codex plan-and-execute", + "created_at": "2024-05-18T11:55:00Z" + }, + { + "user": {"login": "chatgpt-codex-connector"}, + "body": "Daily update\n- [ ] Refresh datasets", + "created_at": "2024-05-18T11:40:00Z" + } + ] + }, + { + "number": 707, + "labels": ["agent:codex"], + "comments": [ + { + "user": {"login": "triage-bot"}, + "body": "@codex plan-and-execute", + "created_at": "2024-05-18T10:40:00Z" + }, + { + "user": {"login": "chatgpt-codex-connector"}, + "body": "Checklist\n- [ ] Extract scripts\n- [x] Prepare branch", + "created_at": "2024-05-18T10:30:00Z" + } + ] + } + ] +} diff --git a/tests/test_keepalive_workflow.py b/tests/test_keepalive_workflow.py index f8914044c0..37db2f4597 100644 --- a/tests/test_keepalive_workflow.py +++ b/tests/test_keepalive_workflow.py @@ -39,7 +39,9 @@ def _raw_entries(summary: dict) -> list[str]: def _details(summary: dict, title_prefix: str) -> dict | None: for entry in summary["entries"]: - if entry.get("type") == "details" and entry.get("title", "").startswith(title_prefix): + if entry.get("type") == "details" and entry.get("title", "").startswith( + title_prefix + ): return entry return None @@ -91,7 +93,10 @@ def test_keepalive_dedupes_configuration() -> None: labels_line = next(line for line in raw if line.startswith("Target labels:")) logins_line = next(line for line in raw if line.startswith("Agent logins:")) assert _extract_marked_values(labels_line) == ["agent:codex", "agent:triage"] - assert _extract_marked_values(logins_line) == ["chatgpt-codex-connector", "helper-bot"] + assert _extract_marked_values(logins_line) == [ + "chatgpt-codex-connector", + "helper-bot", + ] created = data["created_comments"] assert [item["issue_number"] for item in created] == [505] @@ -99,3 +104,22 @@ def test_keepalive_dedupes_configuration() -> None: details = _details(summary, "Triggered keepalive comments") assert details is not None and any("#505" in entry for entry in details["items"]) + + +def test_keepalive_waits_for_recent_command() -> None: + data = _run_scenario("command_pending") + summary = data["summary"] + + created = data["created_comments"] + assert [item["issue_number"] for item in created] == [707] + + info_logs = data["logs"]["info"] + assert any( + "#606: skipped – waiting for Codex response to the latest command (5.0 minutes < 10)." + == message + for message in info_logs + ) + + raw = _raw_entries(summary) + assert "Triggered keepalive count: 1" in raw + assert "Evaluated pull requests: 2" in raw