|
20 | 20 |
|
21 | 21 | args = sys.argv[1:] |
22 | 22 | 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])) |
24 | 38 | raise SystemExit(0) |
25 | 39 |
|
26 | 40 | if args[:1] == ["api"]: |
@@ -90,6 +104,28 @@ def _lookup(fake_gh, runs, artifacts, *args, workflow="CI"): |
90 | 104 |
|
91 | 105 | @pytest.mark.agent_authored(model="gpt-5.6") |
92 | 106 | 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 | + |
93 | 129 | def test_selects_newest_run_with_filename_workflow_selector(self, fake_gh): |
94 | 130 | runs = [ |
95 | 131 | _run(100, "2026-08-10T12:00:00Z"), |
|
0 commit comments