|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import ast |
3 | 4 | import json |
4 | 5 | import os |
5 | 6 | import subprocess |
| 7 | +import sys |
6 | 8 | from collections.abc import Iterator |
7 | 9 | from pathlib import Path |
8 | 10 |
|
@@ -65,10 +67,13 @@ def test_aliases_normalize_to_copilot_exec(alias: str) -> None: |
65 | 67 |
|
66 | 68 |
|
67 | 69 | @pytest.mark.parametrize("alias", ["copilot", "copilot_cli", "github_copilot"]) |
68 | | -def test_bare_copilot_aliases_normalize_to_the_fully_local_chat_backend( |
| 70 | +def test_bare_copilot_aliases_normalize_to_the_cli_authenticated_chat_backend( |
69 | 71 | alias: str, |
70 | 72 | ) -> None: |
71 | 73 | assert normalize_backend_name(alias) == "copilot_chat" |
| 74 | + assert model.set_backend(alias) == "copilot_chat" |
| 75 | + assert backend_config.get_optimizer_backend() == "copilot_chat" |
| 76 | + assert backend_config.get_target_backend() == "copilot_chat" |
72 | 77 |
|
73 | 78 |
|
74 | 79 | def test_set_backend_routes_target_to_copilot_and_keeps_chat_optimizer() -> None: |
@@ -119,16 +124,19 @@ def test_parse_jsonl_concatenates_assistant_messages_and_ignores_noise() -> None |
119 | 124 | json.dumps({"type": "tool.call", "data": {"content": "ignored"}}), |
120 | 125 | json.dumps({"type": "assistant.message", "data": {"content": "first"}}), |
121 | 126 | "{ broken json", |
| 127 | + "[]", |
| 128 | + "null", |
| 129 | + json.dumps({"type": "assistant.message", "data": "invalid"}), |
122 | 130 | json.dumps({"type": "assistant.message", "data": {"content": "second"}}), |
123 | 131 | json.dumps({"type": "assistant.message", "data": {}}), |
124 | 132 | ] |
125 | 133 | ) |
126 | | - assert harness._parse_copilot_jsonl(raw) == "first\nsecond" |
| 134 | + assert copilot_backend.parse_copilot_jsonl(raw) == "first\nsecond" |
127 | 135 |
|
128 | 136 |
|
129 | 137 | def test_parse_jsonl_returns_empty_for_no_assistant_messages() -> None: |
130 | | - assert harness._parse_copilot_jsonl('{"type":"tool.call","data":{}}') == "" |
131 | | - assert harness._parse_copilot_jsonl("") == "" |
| 138 | + assert copilot_backend.parse_copilot_jsonl('{"type":"tool.call","data":{}}') == "" |
| 139 | + assert copilot_backend.parse_copilot_jsonl("") == "" |
132 | 140 |
|
133 | 141 |
|
134 | 142 | def _fake_run(captured: dict, stdout: str, returncode: int = 0): |
@@ -216,7 +224,8 @@ def test_copilot_backends_keep_a_real_deployment_fallback() -> None: |
216 | 224 | assert default_model_for_backend("copilot_chat") == "gpt-4o" |
217 | 225 |
|
218 | 226 |
|
219 | | -def test_no_response_error_includes_cli_output(monkeypatch, tmp_path) -> None: # copilot_exec persists no artifacts, so a bare "returned no response" |
| 227 | +def test_no_response_error_includes_cli_output(monkeypatch, tmp_path) -> None: |
| 228 | + # copilot_exec persists no artifacts, so a bare "returned no response" |
220 | 229 | # would leave an empty/invalid JSONL stream undebuggable. |
221 | 230 | model.set_backend("copilot") |
222 | 231 | model.configure_copilot_exec(path="copilot", home="", allow_all_tools=False) |
@@ -459,19 +468,36 @@ def test_copilot_config_keys_survive_flattening() -> None: |
459 | 468 | @pytest.mark.parametrize("script", ["train", "eval_only"]) |
460 | 469 | def test_cli_exposes_copilot_backend_and_flags(script: str) -> None: |
461 | 470 | root = Path(__file__).resolve().parents[1] |
462 | | - text = (root / "scripts" / f"{script}.py").read_text(encoding="utf-8") |
463 | | - assert "copilot_chat" in text |
464 | | - assert "copilot_exec" in text |
| 471 | + script_path = root / "scripts" / f"{script}.py" |
| 472 | + result = subprocess.run( |
| 473 | + [sys.executable, str(script_path), "--help"], |
| 474 | + capture_output=True, |
| 475 | + text=True, |
| 476 | + timeout=30, |
| 477 | + ) |
| 478 | + assert result.returncode == 0, result.stderr |
| 479 | + assert "copilot_chat" in result.stdout |
| 480 | + assert "copilot_exec" in result.stdout |
465 | 481 | for flag in ( |
466 | 482 | "--copilot_exec_path", |
| 483 | + "--copilot_exec_home", |
| 484 | + "--copilot_exec_allow_all_tools", |
| 485 | + "--copilot_chat_optimizer_model", |
467 | 486 | "--copilot_chat_target_model", |
468 | 487 | "--copilot_chat_timeout", |
469 | 488 | ): |
470 | | - assert flag in text |
| 489 | + assert flag in result.stdout |
471 | 490 | # train.py delegates backend configuration to the trainer; eval_only wires |
472 | | - # it directly. Assert whichever applies so the wiring can't silently drop. |
473 | | - applier = ( |
474 | | - text if script == "eval_only" else (root / "skillopt" / "engine" / "trainer.py").read_text(encoding="utf-8") |
| 491 | + # it directly. Inspect call nodes rather than source spelling/formatting. |
| 492 | + applier_path = ( |
| 493 | + script_path |
| 494 | + if script == "eval_only" |
| 495 | + else root / "skillopt" / "engine" / "trainer.py" |
475 | 496 | ) |
476 | | - assert "configure_copilot_chat" in applier |
477 | | - assert "configure_copilot_exec" in applier |
| 497 | + tree = ast.parse(applier_path.read_text(encoding="utf-8")) |
| 498 | + calls = { |
| 499 | + node.func.id |
| 500 | + for node in ast.walk(tree) |
| 501 | + if isinstance(node, ast.Call) and isinstance(node.func, ast.Name) |
| 502 | + } |
| 503 | + assert {"configure_copilot_chat", "configure_copilot_exec"} <= calls |
0 commit comments