arga-cli 0.1.1__tar.gz → 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: arga-cli
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: Command-line interface for Arga authentication, MCP installation, and browser validation
5
5
  Author: Arga Labs
6
6
  Project-URL: Homepage, https://github.com/ArgaLabs/arga-cli
@@ -115,6 +115,7 @@ List and inspect recent validation runs:
115
115
  ```bash
116
116
  arga runs list --repo arga-labs/validation-server --limit 20
117
117
  arga runs status <run_id>
118
+ arga runs logs <run_id>
118
119
  arga runs cancel <run_id>
119
120
  ```
120
121
 
@@ -186,6 +187,7 @@ arga scan report <run_id>
186
187
  ```bash
187
188
  arga runs list --repo arga-labs/validation-server --status running --limit 20
188
189
  arga runs status <run_id>
190
+ arga runs logs <run_id>
189
191
  arga runs cancel <run_id>
190
192
  ```
191
193
 
@@ -193,6 +195,10 @@ arga runs cancel <run_id>
193
195
  - `--repo` narrows the list to a single repository.
194
196
  - `--status` accepts `completed`, `failed`, or `running`. The `running` filter includes non-terminal states such as `queued`.
195
197
  - `arga runs status <run_id>` prints a detailed summary for a specific run.
198
+ - `arga runs logs <run_id>` prints worker logs plus recent runtime logs for a run you own.
199
+ - When you omit `<run_id>`, `arga runs logs` falls back to `./.arga-session.json` when present, which makes wizard-created twin sessions easy to inspect from the same directory.
200
+ - Add `--json` to `arga runs logs` for a machine-readable response.
201
+ - Add `--errors-only` to keep only failed worker logs plus warning/error runtime entries.
196
202
  - `arga runs cancel <run_id>` cancels the run through the validation API.
197
203
 
198
204
  ### Git Wrappers
@@ -95,6 +95,7 @@ List and inspect recent validation runs:
95
95
  ```bash
96
96
  arga runs list --repo arga-labs/validation-server --limit 20
97
97
  arga runs status <run_id>
98
+ arga runs logs <run_id>
98
99
  arga runs cancel <run_id>
99
100
  ```
100
101
 
@@ -166,6 +167,7 @@ arga scan report <run_id>
166
167
  ```bash
167
168
  arga runs list --repo arga-labs/validation-server --status running --limit 20
168
169
  arga runs status <run_id>
170
+ arga runs logs <run_id>
169
171
  arga runs cancel <run_id>
170
172
  ```
171
173
 
@@ -173,6 +175,10 @@ arga runs cancel <run_id>
173
175
  - `--repo` narrows the list to a single repository.
174
176
  - `--status` accepts `completed`, `failed`, or `running`. The `running` filter includes non-terminal states such as `queued`.
175
177
  - `arga runs status <run_id>` prints a detailed summary for a specific run.
178
+ - `arga runs logs <run_id>` prints worker logs plus recent runtime logs for a run you own.
179
+ - When you omit `<run_id>`, `arga runs logs` falls back to `./.arga-session.json` when present, which makes wizard-created twin sessions easy to inspect from the same directory.
180
+ - Add `--json` to `arga runs logs` for a machine-readable response.
181
+ - Add `--errors-only` to keep only failed worker logs plus warning/error runtime entries.
176
182
  - `arga runs cancel <run_id>` cancels the run through the validation API.
177
183
 
178
184
  ### Git Wrappers
@@ -20,6 +20,8 @@ from arga_cli.mcp import install_mcp_configuration
20
20
 
21
21
  DEFAULT_API_URL = os.environ.get("ARGA_API_URL", "https://api.argalabs.com")
22
22
  CONFIG_PATH = Path.home() / ".config" / "arga" / "config.json"
23
+ WIZARD_SESSION_FILE = ".arga-session.json"
24
+ WIZARD_SESSION_PATH = Path(WIZARD_SESSION_FILE)
23
25
  POLL_INTERVAL_SECONDS = 2.0
24
26
  POLL_TIMEOUT_SECONDS = 600.0
25
27
  SKIP_TRAILER = "[skip arga]"
@@ -128,6 +130,13 @@ class ApiClient:
128
130
  )
129
131
  return self._parse_json(response, "Failed to load run details")
130
132
 
133
+ def get_run_logs(self, run_id: str) -> dict[str, Any]:
134
+ response = self._client.get(
135
+ f"{self._api_url}/runs/{run_id}/logs",
136
+ headers=self._auth_headers(),
137
+ )
138
+ return self._parse_json(response, "Failed to load run logs")
139
+
131
140
  def get_redteam_report(self, run_id: str) -> dict[str, Any]:
132
141
  response = self._client.get(
133
142
  f"{self._api_url}/redteam/{run_id}/report",
@@ -251,6 +260,31 @@ def delete_api_key() -> bool:
251
260
  return True
252
261
 
253
262
 
263
+ def load_wizard_session(path: Path = WIZARD_SESSION_PATH) -> dict[str, Any] | None:
264
+ try:
265
+ data = json.loads(path.read_text())
266
+ except FileNotFoundError:
267
+ return None
268
+ except json.JSONDecodeError as exc:
269
+ raise CliError(f"Invalid wizard session file: {path}") from exc
270
+
271
+ if not isinstance(data, dict):
272
+ raise CliError(f"Invalid wizard session file: {path}")
273
+ return data
274
+
275
+
276
+ def resolve_logs_run_id(run_id: str | None, *, session_path: Path = WIZARD_SESSION_PATH) -> str:
277
+ if run_id:
278
+ return run_id
279
+ session = load_wizard_session(session_path)
280
+ session_run_id = str((session or {}).get("run_id") or "").strip()
281
+ if session_run_id:
282
+ return session_run_id
283
+ raise CliError(
284
+ f"Run ID is required. Pass one explicitly or run this command from a directory containing {WIZARD_SESSION_FILE}."
285
+ )
286
+
287
+
254
288
  def build_verification_url(start_payload: dict[str, str]) -> str:
255
289
  verification_url = start_payload["verification_url"]
256
290
  device_code = start_payload["device_code"]
@@ -375,6 +409,10 @@ def run_test_url(args: argparse.Namespace) -> int:
375
409
  finally:
376
410
  client.close()
377
411
 
412
+ if getattr(args, "json", False):
413
+ print(json.dumps({"run_id": payload.get("run_id"), "status": payload.get("status")}))
414
+ return 0
415
+
378
416
  print("Starting validation...\n")
379
417
  print(f"URL: {args.url}")
380
418
  print(f"Prompt: {args.prompt}\n")
@@ -391,6 +429,10 @@ def run_validate_pr(args: argparse.Namespace) -> int:
391
429
  finally:
392
430
  client.close()
393
431
 
432
+ if args.json:
433
+ print(json.dumps({"run_id": payload.get("run_id"), "status": payload.get("status")}))
434
+ return 0
435
+
394
436
  print("Starting PR validation...\n")
395
437
  print(f"Repository: {args.repo}")
396
438
  print(f"PR: #{args.pr}\n")
@@ -796,6 +838,139 @@ def _print_runs_table(runs: list[dict[str, Any]]) -> None:
796
838
  print(format_row(row))
797
839
 
798
840
 
841
+ def _print_worker_logs(worker_logs: list[dict[str, Any]]) -> None:
842
+ print("Worker Logs:")
843
+ if not worker_logs:
844
+ print("None")
845
+ return
846
+
847
+ for index, worker_log in enumerate(worker_logs):
848
+ job_id = str(worker_log.get("job_id") or "-")
849
+ metadata = [
850
+ str(worker_log.get("job_type") or "").strip(),
851
+ str(worker_log.get("target_role") or "").strip(),
852
+ str(worker_log.get("status") or "").strip(),
853
+ ]
854
+ metadata_label = " / ".join(value for value in metadata if value)
855
+ print(f"{job_id}: {metadata_label or 'worker log'}")
856
+
857
+ error = str(worker_log.get("error") or "").strip()
858
+ content = str(worker_log.get("content") or "").rstrip()
859
+ if error:
860
+ print(f"Error: {error}")
861
+ elif content:
862
+ print(content)
863
+ else:
864
+ print("No log content available.")
865
+
866
+ if index < len(worker_logs) - 1:
867
+ print()
868
+
869
+
870
+ def _print_runtime_logs(runtime_logs: list[dict[str, Any]]) -> None:
871
+ print("Runtime Logs:")
872
+ if not runtime_logs:
873
+ print("None")
874
+ return
875
+
876
+ for index, runtime_log in enumerate(runtime_logs):
877
+ header_parts = [
878
+ _format_timestamp(runtime_log.get("timestamp")),
879
+ str(runtime_log.get("severity") or "").strip(),
880
+ str(runtime_log.get("service_name") or "").strip(),
881
+ str(runtime_log.get("event") or "").strip(),
882
+ str(runtime_log.get("code") or "").strip(),
883
+ ]
884
+ header = " | ".join(part for part in header_parts if part and part != "-")
885
+ print(header or "Log entry")
886
+
887
+ message = str(runtime_log.get("message") or "").strip()
888
+ if message:
889
+ print(message)
890
+
891
+ metadata: list[str] = []
892
+ request_id = str(runtime_log.get("request_id") or "").strip()
893
+ if request_id:
894
+ metadata.append(f"request_id={request_id}")
895
+ job_id = str(runtime_log.get("job_id") or "").strip()
896
+ if job_id:
897
+ metadata.append(f"job_id={job_id}")
898
+ surface_name = str(runtime_log.get("surface_name") or "").strip()
899
+ if surface_name:
900
+ metadata.append(f"surface={surface_name}")
901
+ if metadata:
902
+ print(" ".join(metadata))
903
+
904
+ if index < len(runtime_logs) - 1:
905
+ print()
906
+
907
+
908
+ def _is_error_runtime_log(runtime_log: dict[str, Any]) -> bool:
909
+ severity = str(runtime_log.get("severity") or "").strip().upper()
910
+ return severity in {"WARNING", "ERROR", "CRITICAL", "ALERT", "EMERGENCY"}
911
+
912
+
913
+ def _is_error_worker_log(worker_log: dict[str, Any]) -> bool:
914
+ status = str(worker_log.get("status") or "").strip().lower()
915
+ error = str(worker_log.get("error") or "").strip()
916
+ return status in {"failed", "error", "cancelled"} or bool(error)
917
+
918
+
919
+ def _filter_run_logs_payload(payload: dict[str, Any], *, errors_only: bool) -> dict[str, Any]:
920
+ if not errors_only:
921
+ return payload
922
+
923
+ filtered_payload = dict(payload)
924
+ worker_logs = payload.get("worker_logs")
925
+ runtime_logs = payload.get("runtime_logs")
926
+ warnings = payload.get("warnings")
927
+
928
+ filtered_payload["worker_logs"] = (
929
+ [item for item in worker_logs if isinstance(item, dict) and _is_error_worker_log(item)]
930
+ if isinstance(worker_logs, list)
931
+ else []
932
+ )
933
+ filtered_payload["runtime_logs"] = (
934
+ [item for item in runtime_logs if isinstance(item, dict) and _is_error_runtime_log(item)]
935
+ if isinstance(runtime_logs, list)
936
+ else []
937
+ )
938
+ filtered_payload["warnings"] = warnings if isinstance(warnings, list) else []
939
+ return filtered_payload
940
+
941
+
942
+ def _print_run_logs(payload: dict[str, Any], fallback_run_id: str) -> None:
943
+ run = payload.get("run")
944
+ run_data = run if isinstance(run, dict) else {}
945
+ worker_logs = payload.get("worker_logs")
946
+ runtime_logs = payload.get("runtime_logs")
947
+ warnings = payload.get("warnings")
948
+ timeline_events = run_data.get("event_log_json")
949
+
950
+ print(f"Run ID: {run_data.get('id', fallback_run_id)}")
951
+ print(f"Status: {run_data.get('status', 'unknown')}")
952
+ print(f"Type: {run_data.get('run_type', 'unknown')}")
953
+ print(f"Mode: {run_data.get('mode', 'unknown')}")
954
+ print(f"Repository: {run_data.get('repo_full_name') or '-'}")
955
+ print(f"PR/Branch: {_run_ref_label(run_data)}")
956
+ print(f"Commit: {run_data.get('commit_sha') or '-'}")
957
+ print(f"Created: {_format_timestamp(run_data.get('created_at'))}")
958
+ print(f"Environment URL: {run_data.get('environment_url') or '-'}")
959
+ if isinstance(timeline_events, list):
960
+ print(f"Timeline Events: {len(timeline_events)}")
961
+
962
+ print()
963
+ _print_worker_logs(worker_logs if isinstance(worker_logs, list) else [])
964
+ print()
965
+ _print_runtime_logs(runtime_logs if isinstance(runtime_logs, list) else [])
966
+
967
+ if isinstance(warnings, list) and warnings:
968
+ print()
969
+ print("Warnings:")
970
+ for warning in warnings:
971
+ print(f"- {warning}")
972
+
973
+
799
974
  def run_runs_list(args: argparse.Namespace) -> int:
800
975
  api_key = load_api_key()
801
976
  client = ApiClient(args.api_url, api_key=api_key)
@@ -809,6 +984,10 @@ def run_runs_list(args: argparse.Namespace) -> int:
809
984
  finally:
810
985
  client.close()
811
986
 
987
+ if args.json:
988
+ print(json.dumps(runs))
989
+ return 0
990
+
812
991
  if not runs:
813
992
  print("No matching validation runs found.")
814
993
  return 0
@@ -825,6 +1004,10 @@ def run_runs_status(args: argparse.Namespace) -> int:
825
1004
  finally:
826
1005
  client.close()
827
1006
 
1007
+ if args.json:
1008
+ print(json.dumps(run))
1009
+ return 0
1010
+
828
1011
  print(f"Run ID: {run.get('id', args.run_id)}")
829
1012
  print(f"Status: {run.get('status', 'unknown')}")
830
1013
  print(f"Type: {run.get('run_type', 'unknown')}")
@@ -838,6 +1021,25 @@ def run_runs_status(args: argparse.Namespace) -> int:
838
1021
  return 0
839
1022
 
840
1023
 
1024
+ def run_runs_logs(args: argparse.Namespace) -> int:
1025
+ run_id = resolve_logs_run_id(args.run_id)
1026
+ api_key = load_api_key()
1027
+ client = ApiClient(args.api_url, api_key=api_key)
1028
+ try:
1029
+ payload = client.get_run_logs(run_id)
1030
+ finally:
1031
+ client.close()
1032
+
1033
+ payload = _filter_run_logs_payload(payload, errors_only=args.errors_only)
1034
+
1035
+ if args.json:
1036
+ print(json.dumps(payload, indent=2))
1037
+ return 0
1038
+
1039
+ _print_run_logs(payload, run_id)
1040
+ return 0
1041
+
1042
+
841
1043
  def run_runs_cancel(args: argparse.Namespace) -> int:
842
1044
  api_key = load_api_key()
843
1045
  client = ApiClient(args.api_url, api_key=api_key)
@@ -1061,6 +1263,7 @@ def build_parser() -> argparse.ArgumentParser:
1061
1263
  test_url_parser.add_argument("--prompt", required=True, help="Natural language instructions for the agent")
1062
1264
  test_url_parser.add_argument("--email", help="Optional login email")
1063
1265
  test_url_parser.add_argument("--password", help="Optional login password")
1266
+ test_url_parser.add_argument("--json", action="store_true", default=False, help="Output result as JSON")
1064
1267
  test_url_parser.set_defaults(func=run_test_url)
1065
1268
 
1066
1269
  validate_parser = subparsers.add_parser("validate", help="Start PR or URL validation runs")
@@ -1070,6 +1273,7 @@ def build_parser() -> argparse.ArgumentParser:
1070
1273
  validate_pr_parser.add_argument("--api-url", default=DEFAULT_API_URL, help="Arga API base URL")
1071
1274
  validate_pr_parser.add_argument("--repo", required=True, help="Repository in owner/repo format")
1072
1275
  validate_pr_parser.add_argument("--pr", required=True, type=int, help="Pull request number")
1276
+ validate_pr_parser.add_argument("--json", action="store_true", default=False, help="Output result as JSON")
1073
1277
  validate_pr_parser.set_defaults(func=run_validate_pr)
1074
1278
 
1075
1279
  validate_url_parser = validate_subparsers.add_parser(
@@ -1081,6 +1285,7 @@ def build_parser() -> argparse.ArgumentParser:
1081
1285
  validate_url_parser.add_argument("--prompt", required=True, help="Natural language instructions for the agent")
1082
1286
  validate_url_parser.add_argument("--email", help="Optional login email")
1083
1287
  validate_url_parser.add_argument("--password", help="Optional login password")
1288
+ validate_url_parser.add_argument("--json", action="store_true", default=False, help="Output result as JSON")
1084
1289
  validate_url_parser.set_defaults(func=run_test_url)
1085
1290
 
1086
1291
  mcp_parser = subparsers.add_parser("mcp", help="Manage MCP integrations")
@@ -1093,7 +1298,7 @@ def build_parser() -> argparse.ArgumentParser:
1093
1298
  mcp_install_parser.add_argument("--api-url", default=DEFAULT_API_URL, help="Arga API base URL")
1094
1299
  mcp_install_parser.set_defaults(func=run_mcp_install)
1095
1300
 
1096
- runs_parser = subparsers.add_parser("runs", help="List, inspect, or cancel validation runs")
1301
+ runs_parser = subparsers.add_parser("runs", help="List, inspect, cancel, or read validation run logs")
1097
1302
  runs_subparsers = runs_parser.add_subparsers(dest="runs_command", required=True)
1098
1303
 
1099
1304
  runs_list_parser = runs_subparsers.add_parser("list", help="List recent validation runs")
@@ -1105,13 +1310,30 @@ def build_parser() -> argparse.ArgumentParser:
1105
1310
  help="Filter by validation status",
1106
1311
  )
1107
1312
  runs_list_parser.add_argument("--limit", type=int, default=20, help="Maximum number of runs to show")
1313
+ runs_list_parser.add_argument("--json", action="store_true", default=False, help="Output result as JSON")
1108
1314
  runs_list_parser.set_defaults(func=run_runs_list)
1109
1315
 
1110
1316
  runs_status_parser = runs_subparsers.add_parser("status", help="Show detailed status for a validation run")
1111
1317
  runs_status_parser.add_argument("--api-url", default=DEFAULT_API_URL, help="Arga API base URL")
1112
1318
  runs_status_parser.add_argument("run_id", help="Validation run ID")
1319
+ runs_status_parser.add_argument("--json", action="store_true", default=False, help="Output result as JSON")
1113
1320
  runs_status_parser.set_defaults(func=run_runs_status)
1114
1321
 
1322
+ runs_logs_parser = runs_subparsers.add_parser("logs", help="Show worker and runtime logs for a validation run")
1323
+ runs_logs_parser.add_argument("--api-url", default=DEFAULT_API_URL, help="Arga API base URL")
1324
+ runs_logs_parser.add_argument(
1325
+ "run_id",
1326
+ nargs="?",
1327
+ help=f"Validation run ID. Defaults to {WIZARD_SESSION_FILE} in the current directory when available.",
1328
+ )
1329
+ runs_logs_parser.add_argument("--json", action="store_true", help="Print the raw JSON response")
1330
+ runs_logs_parser.add_argument(
1331
+ "--errors-only",
1332
+ action="store_true",
1333
+ help="Show only failed worker logs and warning/error runtime logs",
1334
+ )
1335
+ runs_logs_parser.set_defaults(func=run_runs_logs)
1336
+
1115
1337
  runs_cancel_parser = runs_subparsers.add_parser("cancel", help="Cancel a validation run")
1116
1338
  runs_cancel_parser.add_argument("--api-url", default=DEFAULT_API_URL, help="Arga API base URL")
1117
1339
  runs_cancel_parser.add_argument("run_id", help="Validation run ID")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: arga-cli
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: Command-line interface for Arga authentication, MCP installation, and browser validation
5
5
  Author: Arga Labs
6
6
  Project-URL: Homepage, https://github.com/ArgaLabs/arga-cli
@@ -115,6 +115,7 @@ List and inspect recent validation runs:
115
115
  ```bash
116
116
  arga runs list --repo arga-labs/validation-server --limit 20
117
117
  arga runs status <run_id>
118
+ arga runs logs <run_id>
118
119
  arga runs cancel <run_id>
119
120
  ```
120
121
 
@@ -186,6 +187,7 @@ arga scan report <run_id>
186
187
  ```bash
187
188
  arga runs list --repo arga-labs/validation-server --status running --limit 20
188
189
  arga runs status <run_id>
190
+ arga runs logs <run_id>
189
191
  arga runs cancel <run_id>
190
192
  ```
191
193
 
@@ -193,6 +195,10 @@ arga runs cancel <run_id>
193
195
  - `--repo` narrows the list to a single repository.
194
196
  - `--status` accepts `completed`, `failed`, or `running`. The `running` filter includes non-terminal states such as `queued`.
195
197
  - `arga runs status <run_id>` prints a detailed summary for a specific run.
198
+ - `arga runs logs <run_id>` prints worker logs plus recent runtime logs for a run you own.
199
+ - When you omit `<run_id>`, `arga runs logs` falls back to `./.arga-session.json` when present, which makes wizard-created twin sessions easy to inspect from the same directory.
200
+ - Add `--json` to `arga runs logs` for a machine-readable response.
201
+ - Add `--errors-only` to keep only failed worker logs plus warning/error runtime entries.
196
202
  - `arga runs cancel <run_id>` cancels the run through the validation API.
197
203
 
198
204
  ### Git Wrappers
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "arga-cli"
7
- version = "0.1.1"
7
+ version = "0.1.3"
8
8
  description = "Command-line interface for Arga authentication, MCP installation, and browser validation"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -0,0 +1,448 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+
5
+ from arga_cli import main
6
+
7
+
8
+ def test_runs_list_prints_filtered_table(monkeypatch, capsys) -> None:
9
+ monkeypatch.setattr(main, "load_api_key", lambda: "arga_api_key")
10
+ monkeypatch.setattr(main.ApiClient, "close", lambda self: None)
11
+
12
+ def fake_list(self, *, repo: str | None = None, limit: int = 20, offset: int = 0):
13
+ assert repo == "arga-labs/validation-server"
14
+ if offset == 0:
15
+ return {
16
+ "items": [
17
+ {
18
+ "run_id": "run_completed",
19
+ "status": "completed",
20
+ "repo": "arga-labs/validation-server",
21
+ "pr_number": 182,
22
+ "created_at": "2026-03-25T12:30:00Z",
23
+ },
24
+ {
25
+ "run_id": "run_failed",
26
+ "status": "failed",
27
+ "repo": "arga-labs/validation-server",
28
+ "branch": "main",
29
+ "created_at": "2026-03-25T12:00:00Z",
30
+ },
31
+ ],
32
+ "limit": limit,
33
+ "offset": offset,
34
+ "has_more": False,
35
+ "total": 2,
36
+ }
37
+ raise AssertionError("Unexpected extra page request")
38
+
39
+ monkeypatch.setattr(main.ApiClient, "list_pr_validation_runs", fake_list)
40
+
41
+ args = main.build_parser().parse_args(
42
+ ["runs", "list", "--repo", "arga-labs/validation-server", "--status", "failed", "--limit", "20"]
43
+ )
44
+ exit_code = args.func(args)
45
+ output = capsys.readouterr().out
46
+
47
+ assert exit_code == 0
48
+ assert "RUN_ID" in output
49
+ assert "run_failed" in output
50
+ assert "main" in output
51
+ assert "run_completed" not in output
52
+
53
+
54
+ def test_runs_list_running_filter_includes_non_terminal_statuses(monkeypatch, capsys) -> None:
55
+ monkeypatch.setattr(main, "load_api_key", lambda: "arga_api_key")
56
+ monkeypatch.setattr(main.ApiClient, "close", lambda self: None)
57
+
58
+ def fake_list(self, *, repo: str | None = None, limit: int = 20, offset: int = 0):
59
+ return {
60
+ "items": [
61
+ {
62
+ "run_id": "run_queued",
63
+ "status": "queued",
64
+ "repo": "arga-labs/validation-server",
65
+ "branch": "feature/arga",
66
+ "created_at": "2026-03-25T13:00:00Z",
67
+ },
68
+ {
69
+ "run_id": "run_completed",
70
+ "status": "completed",
71
+ "repo": "arga-labs/validation-server",
72
+ "branch": "main",
73
+ "created_at": "2026-03-25T12:00:00Z",
74
+ },
75
+ ],
76
+ "limit": limit,
77
+ "offset": offset,
78
+ "has_more": False,
79
+ "total": 2,
80
+ }
81
+
82
+ monkeypatch.setattr(main.ApiClient, "list_pr_validation_runs", fake_list)
83
+
84
+ args = main.build_parser().parse_args(["runs", "list", "--status", "running"])
85
+ exit_code = args.func(args)
86
+ output = capsys.readouterr().out
87
+
88
+ assert exit_code == 0
89
+ assert "run_queued" in output
90
+ assert "run_completed" not in output
91
+
92
+
93
+ def test_runs_status_prints_detail_summary(monkeypatch, capsys) -> None:
94
+ monkeypatch.setattr(main, "load_api_key", lambda: "arga_api_key")
95
+ monkeypatch.setattr(main.ApiClient, "close", lambda self: None)
96
+
97
+ def fake_get_run(self, run_id: str):
98
+ assert run_id == "run_123"
99
+ return {
100
+ "id": run_id,
101
+ "status": "running",
102
+ "run_type": "pr",
103
+ "mode": "auto_visual",
104
+ "repo_full_name": "arga-labs/validation-server",
105
+ "github_pr_number": 182,
106
+ "commit_sha": "abc123",
107
+ "created_at": "2026-03-25T12:30:00Z",
108
+ "environment_url": "https://preview.example.com",
109
+ "session_id": "session_1",
110
+ }
111
+
112
+ monkeypatch.setattr(main.ApiClient, "get_run", fake_get_run)
113
+
114
+ args = main.build_parser().parse_args(["runs", "status", "run_123"])
115
+ exit_code = args.func(args)
116
+ output = capsys.readouterr().out
117
+
118
+ assert exit_code == 0
119
+ assert "Run ID: run_123" in output
120
+ assert "Status: running" in output
121
+ assert "Repository: arga-labs/validation-server" in output
122
+ assert "PR/Branch: PR #182" in output
123
+
124
+
125
+ def test_runs_list_json_flag(monkeypatch, capsys) -> None:
126
+ monkeypatch.setattr(main, "load_api_key", lambda: "arga_api_key")
127
+ monkeypatch.setattr(main.ApiClient, "close", lambda self: None)
128
+
129
+ def fake_list(self, *, repo: str | None = None, limit: int = 20, offset: int = 0):
130
+ return {
131
+ "items": [
132
+ {
133
+ "run_id": "run_1",
134
+ "status": "completed",
135
+ "repo": "arga-labs/validation-server",
136
+ "pr_number": 182,
137
+ "created_at": "2026-03-25T12:30:00Z",
138
+ },
139
+ {
140
+ "run_id": "run_2",
141
+ "status": "failed",
142
+ "repo": "arga-labs/validation-server",
143
+ "branch": "main",
144
+ "created_at": "2026-03-25T12:00:00Z",
145
+ },
146
+ ],
147
+ "limit": limit,
148
+ "offset": offset,
149
+ "has_more": False,
150
+ "total": 2,
151
+ }
152
+
153
+ monkeypatch.setattr(main.ApiClient, "list_pr_validation_runs", fake_list)
154
+
155
+ args = main.build_parser().parse_args(["runs", "list", "--json"])
156
+ exit_code = args.func(args)
157
+ output = capsys.readouterr().out
158
+
159
+ assert exit_code == 0
160
+ parsed = json.loads(output)
161
+ assert isinstance(parsed, list)
162
+ assert len(parsed) == 2
163
+ assert parsed[0]["run_id"] == "run_1"
164
+ assert parsed[1]["run_id"] == "run_2"
165
+
166
+
167
+ def test_runs_list_json_flag_empty(monkeypatch, capsys) -> None:
168
+ monkeypatch.setattr(main, "load_api_key", lambda: "arga_api_key")
169
+ monkeypatch.setattr(main.ApiClient, "close", lambda self: None)
170
+
171
+ def fake_list(self, *, repo: str | None = None, limit: int = 20, offset: int = 0):
172
+ return {"items": [], "limit": limit, "offset": offset, "has_more": False, "total": 0}
173
+
174
+ monkeypatch.setattr(main.ApiClient, "list_pr_validation_runs", fake_list)
175
+
176
+ args = main.build_parser().parse_args(["runs", "list", "--json"])
177
+ exit_code = args.func(args)
178
+ output = capsys.readouterr().out
179
+
180
+ assert exit_code == 0
181
+ assert json.loads(output) == []
182
+
183
+
184
+ def test_runs_status_json_flag(monkeypatch, capsys) -> None:
185
+ monkeypatch.setattr(main, "load_api_key", lambda: "arga_api_key")
186
+ monkeypatch.setattr(main.ApiClient, "close", lambda self: None)
187
+
188
+ run_data = {
189
+ "id": "run_123",
190
+ "status": "running",
191
+ "run_type": "pr",
192
+ "mode": "auto_visual",
193
+ "repo_full_name": "arga-labs/validation-server",
194
+ "github_pr_number": 182,
195
+ "commit_sha": "abc123",
196
+ "created_at": "2026-03-25T12:30:00Z",
197
+ "environment_url": "https://preview.example.com",
198
+ "session_id": "session_1",
199
+ }
200
+
201
+ def fake_get_run(self, run_id: str):
202
+ return run_data
203
+
204
+ monkeypatch.setattr(main.ApiClient, "get_run", fake_get_run)
205
+
206
+ args = main.build_parser().parse_args(["runs", "status", "run_123", "--json"])
207
+ exit_code = args.func(args)
208
+ output = capsys.readouterr().out
209
+
210
+ assert exit_code == 0
211
+ parsed = json.loads(output)
212
+ assert parsed == run_data
213
+
214
+
215
+ def test_runs_logs_prints_worker_and_runtime_logs(monkeypatch, capsys) -> None:
216
+ monkeypatch.setattr(main, "load_api_key", lambda: "arga_api_key")
217
+ monkeypatch.setattr(main.ApiClient, "close", lambda self: None)
218
+
219
+ def fake_get_logs(self, run_id: str):
220
+ assert run_id == "run_123"
221
+ return {
222
+ "run": {
223
+ "id": run_id,
224
+ "status": "ready",
225
+ "run_type": "twin_quickstart",
226
+ "mode": "staging",
227
+ "repo_full_name": None,
228
+ "commit_sha": None,
229
+ "created_at": "2026-03-25T12:30:00Z",
230
+ "environment_url": "https://preview.example.com",
231
+ "event_log_json": [{"type": "environment_ready"}],
232
+ },
233
+ "worker_logs": [
234
+ {
235
+ "job_id": "job_1",
236
+ "job_type": "deploy",
237
+ "target_role": "warm-vm",
238
+ "status": "succeeded",
239
+ "content": "deploy output",
240
+ "truncated": False,
241
+ "error": None,
242
+ }
243
+ ],
244
+ "runtime_logs": [
245
+ {
246
+ "timestamp": "2026-03-25T12:31:00Z",
247
+ "service_name": "arga-api",
248
+ "severity": "INFO",
249
+ "event": "environment_ready",
250
+ "code": "ok",
251
+ "request_id": "req_1",
252
+ "job_id": "job_1",
253
+ "surface_name": "app",
254
+ "message": "Environment ready.",
255
+ }
256
+ ],
257
+ "warnings": ["Cloud Logging query was partially truncated."],
258
+ }
259
+
260
+ monkeypatch.setattr(main.ApiClient, "get_run_logs", fake_get_logs)
261
+
262
+ args = main.build_parser().parse_args(["runs", "logs", "run_123"])
263
+ exit_code = args.func(args)
264
+ output = capsys.readouterr().out
265
+
266
+ assert exit_code == 0
267
+ assert "Run ID: run_123" in output
268
+ assert "Worker Logs:" in output
269
+ assert "deploy output" in output
270
+ assert "Runtime Logs:" in output
271
+ assert "Environment ready." in output
272
+ assert "Warnings:" in output
273
+
274
+
275
+ def test_runs_logs_prints_json(monkeypatch, capsys) -> None:
276
+ monkeypatch.setattr(main, "load_api_key", lambda: "arga_api_key")
277
+ monkeypatch.setattr(main.ApiClient, "close", lambda self: None)
278
+
279
+ payload = {
280
+ "run": {"id": "run_123", "status": "ready"},
281
+ "worker_logs": [],
282
+ "runtime_logs": [],
283
+ "warnings": [],
284
+ }
285
+
286
+ monkeypatch.setattr(main.ApiClient, "get_run_logs", lambda self, run_id: payload)
287
+
288
+ args = main.build_parser().parse_args(["runs", "logs", "run_123", "--json"])
289
+ exit_code = args.func(args)
290
+ output = capsys.readouterr().out
291
+
292
+ assert exit_code == 0
293
+ assert json.loads(output) == payload
294
+
295
+
296
+ def test_runs_logs_errors_only_filters_plain_output(monkeypatch, capsys) -> None:
297
+ monkeypatch.setattr(main, "load_api_key", lambda: "arga_api_key")
298
+ monkeypatch.setattr(main.ApiClient, "close", lambda self: None)
299
+
300
+ def fake_get_logs(self, run_id: str):
301
+ assert run_id == "run_123"
302
+ return {
303
+ "run": {
304
+ "id": run_id,
305
+ "status": "ready",
306
+ "run_type": "twin_quickstart",
307
+ "mode": "staging",
308
+ "repo_full_name": None,
309
+ "commit_sha": None,
310
+ "created_at": "2026-03-25T12:30:00Z",
311
+ "environment_url": "https://preview.example.com",
312
+ "event_log_json": [],
313
+ },
314
+ "worker_logs": [
315
+ {
316
+ "job_id": "job_ok",
317
+ "job_type": "build",
318
+ "target_role": "builder",
319
+ "status": "succeeded",
320
+ "content": "all good",
321
+ "truncated": False,
322
+ "error": None,
323
+ },
324
+ {
325
+ "job_id": "job_bad",
326
+ "job_type": "deploy",
327
+ "target_role": "warm-vm",
328
+ "status": "failed",
329
+ "content": "deploy failed output",
330
+ "truncated": False,
331
+ "error": None,
332
+ },
333
+ ],
334
+ "runtime_logs": [
335
+ {
336
+ "timestamp": "2026-03-25T12:31:00Z",
337
+ "service_name": "arga-api",
338
+ "severity": "INFO",
339
+ "event": "environment_ready",
340
+ "code": None,
341
+ "request_id": "req_ok",
342
+ "job_id": None,
343
+ "surface_name": None,
344
+ "message": "Environment ready.",
345
+ },
346
+ {
347
+ "timestamp": "2026-03-25T12:32:00Z",
348
+ "service_name": "preview-proxy",
349
+ "severity": "WARNING",
350
+ "event": "preview.request.finish",
351
+ "code": None,
352
+ "request_id": "req_warn",
353
+ "job_id": None,
354
+ "surface_name": "slack",
355
+ "message": "Preview request completed.",
356
+ },
357
+ ],
358
+ "warnings": ["Cloud Logging query was partially truncated."],
359
+ }
360
+
361
+ monkeypatch.setattr(main.ApiClient, "get_run_logs", fake_get_logs)
362
+
363
+ args = main.build_parser().parse_args(["runs", "logs", "run_123", "--errors-only"])
364
+ exit_code = args.func(args)
365
+ output = capsys.readouterr().out
366
+
367
+ assert exit_code == 0
368
+ assert "job_bad" in output
369
+ assert "deploy failed output" in output
370
+ assert "job_ok" not in output
371
+ assert "all good" not in output
372
+ assert "Preview request completed." in output
373
+ assert "Environment ready." not in output
374
+ assert "Warnings:" in output
375
+
376
+
377
+ def test_runs_logs_errors_only_filters_json(monkeypatch, capsys) -> None:
378
+ monkeypatch.setattr(main, "load_api_key", lambda: "arga_api_key")
379
+ monkeypatch.setattr(main.ApiClient, "close", lambda self: None)
380
+
381
+ payload = {
382
+ "run": {"id": "run_123", "status": "ready"},
383
+ "worker_logs": [
384
+ {"job_id": "job_ok", "status": "succeeded", "error": None},
385
+ {"job_id": "job_bad", "status": "failed", "error": None},
386
+ ],
387
+ "runtime_logs": [
388
+ {"severity": "INFO", "message": "Environment ready."},
389
+ {"severity": "WARNING", "message": "Preview request completed."},
390
+ ],
391
+ "warnings": ["Cloud Logging query was partially truncated."],
392
+ }
393
+
394
+ monkeypatch.setattr(main.ApiClient, "get_run_logs", lambda self, run_id: payload)
395
+
396
+ args = main.build_parser().parse_args(["runs", "logs", "run_123", "--json", "--errors-only"])
397
+ exit_code = args.func(args)
398
+ output = capsys.readouterr().out
399
+
400
+ assert exit_code == 0
401
+ parsed = json.loads(output)
402
+ assert parsed["worker_logs"] == [{"job_id": "job_bad", "status": "failed", "error": None}]
403
+ assert parsed["runtime_logs"] == [{"severity": "WARNING", "message": "Preview request completed."}]
404
+ assert parsed["warnings"] == ["Cloud Logging query was partially truncated."]
405
+
406
+
407
+ def test_runs_logs_uses_wizard_session_file_when_run_id_missing(monkeypatch, capsys, tmp_path) -> None:
408
+ monkeypatch.chdir(tmp_path)
409
+ (tmp_path / main.WIZARD_SESSION_FILE).write_text(json.dumps({"run_id": "run_from_session"}) + "\n")
410
+ monkeypatch.setattr(main, "load_api_key", lambda: "arga_api_key")
411
+ monkeypatch.setattr(main.ApiClient, "close", lambda self: None)
412
+
413
+ def fake_get_logs(self, run_id: str):
414
+ assert run_id == "run_from_session"
415
+ return {
416
+ "run": {"id": run_id, "status": "ready"},
417
+ "worker_logs": [],
418
+ "runtime_logs": [],
419
+ "warnings": [],
420
+ }
421
+
422
+ monkeypatch.setattr(main.ApiClient, "get_run_logs", fake_get_logs)
423
+
424
+ args = main.build_parser().parse_args(["runs", "logs"])
425
+ exit_code = args.func(args)
426
+ output = capsys.readouterr().out
427
+
428
+ assert exit_code == 0
429
+ assert "Run ID: run_from_session" in output
430
+
431
+
432
+ def test_runs_cancel_prints_cancelled_status(monkeypatch, capsys) -> None:
433
+ monkeypatch.setattr(main, "load_api_key", lambda: "arga_api_key")
434
+ monkeypatch.setattr(main.ApiClient, "close", lambda self: None)
435
+
436
+ def fake_cancel(self, run_id: str):
437
+ assert run_id == "run_123"
438
+ return {"status": "cancelled"}
439
+
440
+ monkeypatch.setattr(main.ApiClient, "cancel_validation_run", fake_cancel)
441
+
442
+ args = main.build_parser().parse_args(["runs", "cancel", "run_123"])
443
+ exit_code = args.func(args)
444
+ output = capsys.readouterr().out
445
+
446
+ assert exit_code == 0
447
+ assert "Run ID: run_123" in output
448
+ assert "Status: cancelled" in output
@@ -1,5 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import json
4
+
3
5
  from arga_cli import main
4
6
 
5
7
 
@@ -26,3 +28,23 @@ def test_test_url_command_prints_run_id(monkeypatch, capsys) -> None:
26
28
  assert "Starting validation..." in output
27
29
  assert "Run ID: run_3421" in output
28
30
  assert "Status: queued" in output
31
+
32
+
33
+ def test_test_url_json_flag(monkeypatch, capsys) -> None:
34
+ monkeypatch.setattr(main, "load_api_key", lambda: "arga_api_key")
35
+
36
+ def fake_start(self, *, url: str, prompt: str, email: str | None = None, password: str | None = None):
37
+ return {"run_id": "run_3421", "status": "queued", "session_id": "session_1"}
38
+
39
+ monkeypatch.setattr(main.ApiClient, "start_url_validation", fake_start)
40
+ monkeypatch.setattr(main.ApiClient, "close", lambda self: None)
41
+
42
+ args = main.build_parser().parse_args(
43
+ ["test", "url", "--url", "https://demo-app.com", "--prompt", "test login flow", "--json"]
44
+ )
45
+ exit_code = args.func(args)
46
+ output = capsys.readouterr().out
47
+
48
+ assert exit_code == 0
49
+ parsed = json.loads(output)
50
+ assert parsed == {"run_id": "run_3421", "status": "queued"}
@@ -1,5 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import json
4
+
3
5
  from arga_cli import main
4
6
 
5
7
 
@@ -51,3 +53,23 @@ def test_validate_url_alias_reuses_url_validation(monkeypatch, capsys) -> None:
51
53
  assert exit_code == 0
52
54
  assert "Starting validation..." in output
53
55
  assert "Run ID: run_123" in output
56
+
57
+
58
+ def test_validate_pr_json_flag(monkeypatch, capsys) -> None:
59
+ monkeypatch.setattr(main, "load_api_key", lambda: "arga_api_key")
60
+
61
+ def fake_start(self, *, repo: str, pr_number: int):
62
+ return {"run_id": "run_83921", "status": "queued"}
63
+
64
+ monkeypatch.setattr(main.ApiClient, "start_pr_validation", fake_start)
65
+ monkeypatch.setattr(main.ApiClient, "close", lambda self: None)
66
+
67
+ args = main.build_parser().parse_args(
68
+ ["validate", "pr", "--repo", "arga-labs/validation-server", "--pr", "182", "--json"]
69
+ )
70
+ exit_code = args.func(args)
71
+ output = capsys.readouterr().out
72
+
73
+ assert exit_code == 0
74
+ parsed = json.loads(output)
75
+ assert parsed == {"run_id": "run_83921", "status": "queued"}
@@ -1,139 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from arga_cli import main
4
-
5
-
6
- def test_runs_list_prints_filtered_table(monkeypatch, capsys) -> None:
7
- monkeypatch.setattr(main, "load_api_key", lambda: "arga_api_key")
8
- monkeypatch.setattr(main.ApiClient, "close", lambda self: None)
9
-
10
- def fake_list(self, *, repo: str | None = None, limit: int = 20, offset: int = 0):
11
- assert repo == "arga-labs/validation-server"
12
- if offset == 0:
13
- return {
14
- "items": [
15
- {
16
- "run_id": "run_completed",
17
- "status": "completed",
18
- "repo": "arga-labs/validation-server",
19
- "pr_number": 182,
20
- "created_at": "2026-03-25T12:30:00Z",
21
- },
22
- {
23
- "run_id": "run_failed",
24
- "status": "failed",
25
- "repo": "arga-labs/validation-server",
26
- "branch": "main",
27
- "created_at": "2026-03-25T12:00:00Z",
28
- },
29
- ],
30
- "limit": limit,
31
- "offset": offset,
32
- "has_more": False,
33
- "total": 2,
34
- }
35
- raise AssertionError("Unexpected extra page request")
36
-
37
- monkeypatch.setattr(main.ApiClient, "list_pr_validation_runs", fake_list)
38
-
39
- args = main.build_parser().parse_args(
40
- ["runs", "list", "--repo", "arga-labs/validation-server", "--status", "failed", "--limit", "20"]
41
- )
42
- exit_code = args.func(args)
43
- output = capsys.readouterr().out
44
-
45
- assert exit_code == 0
46
- assert "RUN_ID" in output
47
- assert "run_failed" in output
48
- assert "main" in output
49
- assert "run_completed" not in output
50
-
51
-
52
- def test_runs_list_running_filter_includes_non_terminal_statuses(monkeypatch, capsys) -> None:
53
- monkeypatch.setattr(main, "load_api_key", lambda: "arga_api_key")
54
- monkeypatch.setattr(main.ApiClient, "close", lambda self: None)
55
-
56
- def fake_list(self, *, repo: str | None = None, limit: int = 20, offset: int = 0):
57
- return {
58
- "items": [
59
- {
60
- "run_id": "run_queued",
61
- "status": "queued",
62
- "repo": "arga-labs/validation-server",
63
- "branch": "feature/arga",
64
- "created_at": "2026-03-25T13:00:00Z",
65
- },
66
- {
67
- "run_id": "run_completed",
68
- "status": "completed",
69
- "repo": "arga-labs/validation-server",
70
- "branch": "main",
71
- "created_at": "2026-03-25T12:00:00Z",
72
- },
73
- ],
74
- "limit": limit,
75
- "offset": offset,
76
- "has_more": False,
77
- "total": 2,
78
- }
79
-
80
- monkeypatch.setattr(main.ApiClient, "list_pr_validation_runs", fake_list)
81
-
82
- args = main.build_parser().parse_args(["runs", "list", "--status", "running"])
83
- exit_code = args.func(args)
84
- output = capsys.readouterr().out
85
-
86
- assert exit_code == 0
87
- assert "run_queued" in output
88
- assert "run_completed" not in output
89
-
90
-
91
- def test_runs_status_prints_detail_summary(monkeypatch, capsys) -> None:
92
- monkeypatch.setattr(main, "load_api_key", lambda: "arga_api_key")
93
- monkeypatch.setattr(main.ApiClient, "close", lambda self: None)
94
-
95
- def fake_get_run(self, run_id: str):
96
- assert run_id == "run_123"
97
- return {
98
- "id": run_id,
99
- "status": "running",
100
- "run_type": "pr",
101
- "mode": "auto_visual",
102
- "repo_full_name": "arga-labs/validation-server",
103
- "github_pr_number": 182,
104
- "commit_sha": "abc123",
105
- "created_at": "2026-03-25T12:30:00Z",
106
- "environment_url": "https://preview.example.com",
107
- "session_id": "session_1",
108
- }
109
-
110
- monkeypatch.setattr(main.ApiClient, "get_run", fake_get_run)
111
-
112
- args = main.build_parser().parse_args(["runs", "status", "run_123"])
113
- exit_code = args.func(args)
114
- output = capsys.readouterr().out
115
-
116
- assert exit_code == 0
117
- assert "Run ID: run_123" in output
118
- assert "Status: running" in output
119
- assert "Repository: arga-labs/validation-server" in output
120
- assert "PR/Branch: PR #182" in output
121
-
122
-
123
- def test_runs_cancel_prints_cancelled_status(monkeypatch, capsys) -> None:
124
- monkeypatch.setattr(main, "load_api_key", lambda: "arga_api_key")
125
- monkeypatch.setattr(main.ApiClient, "close", lambda self: None)
126
-
127
- def fake_cancel(self, run_id: str):
128
- assert run_id == "run_123"
129
- return {"status": "cancelled"}
130
-
131
- monkeypatch.setattr(main.ApiClient, "cancel_validation_run", fake_cancel)
132
-
133
- args = main.build_parser().parse_args(["runs", "cancel", "run_123"])
134
- exit_code = args.func(args)
135
- output = capsys.readouterr().out
136
-
137
- assert exit_code == 0
138
- assert "Run ID: run_123" in output
139
- assert "Status: cancelled" in output
File without changes
File without changes
File without changes
File without changes
File without changes