Skip to content

Commit 619e507

Browse files
committed
Filter prior-branch runs by success before limiting
1 parent 51f5006 commit 619e507

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

‎ci/tools/lookup-run-id‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ if [[ "${MODE}" == "branch" ]]; then
104104
--repo "${REPOSITORY}" \
105105
--branch "${REF}" \
106106
--workflow "${WORKFLOW_NAME}" \
107-
--status completed \
107+
--status success \
108108
--json databaseId,workflowName,status,conclusion,headSha,headBranch,createdAt,url \
109109
--limit 100)
110110

‎ci/tools/tests/test_lookup_run_id.py‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,21 @@
2020
2121
args = sys.argv[1:]
2222
if args[:2] == ["run", "list"]:
23-
print(os.environ["FAKE_RUNS"])
23+
runs = json.loads(os.environ["FAKE_RUNS"])
24+
try:
25+
status = args[args.index("--status") + 1]
26+
limit = int(args[args.index("--limit") + 1])
27+
except (ValueError, IndexError):
28+
print("run list requires --status and --limit", file=sys.stderr)
29+
raise SystemExit(2)
30+
if status == "success":
31+
runs = [run for run in runs if run["conclusion"] == "success"]
32+
elif status == "completed":
33+
runs = [run for run in runs if run["status"] == "completed"]
34+
else:
35+
print(f"unsupported status filter: {status}", file=sys.stderr)
36+
raise SystemExit(2)
37+
print(json.dumps(runs[:limit]))
2438
raise SystemExit(0)
2539
2640
if args[:1] == ["api"]:
@@ -90,6 +104,28 @@ def _lookup(fake_gh, runs, artifacts, *args, workflow="CI"):
90104

91105
@pytest.mark.agent_authored(model="gpt-5.6")
92106
class TestBranchLookup:
107+
def test_filters_successful_runs_before_applying_limit(self, fake_gh):
108+
runs = [
109+
_run(
110+
run_id,
111+
"2026-08-13T12:00:00Z",
112+
conclusion="failure",
113+
)
114+
for run_id in range(200, 100, -1)
115+
]
116+
runs.append(_run(50, "2026-08-12T12:00:00Z"))
117+
118+
result = _lookup(
119+
fake_gh,
120+
runs,
121+
{},
122+
"--branch",
123+
"12.9.x",
124+
)
125+
126+
assert result.returncode == 0, result.stderr
127+
assert result.stdout.strip() == "50"
128+
93129
def test_selects_newest_run_with_filename_workflow_selector(self, fake_gh):
94130
runs = [
95131
_run(100, "2026-08-10T12:00:00Z"),

0 commit comments

Comments
 (0)