|
1 | 1 | from pathlib import Path |
| 2 | +from shutil import copytree |
2 | 3 |
|
3 | 4 | import pytest |
4 | 5 |
|
5 | 6 | from acp.schema import ReadTextFileRequest |
6 | | -from scripts.gen_all import resolve_ref, schema_source_paths |
| 7 | +from scripts.gen_all import ROOT, resolve_ref, schema_source_paths |
7 | 8 | from scripts.gen_meta import generate_meta |
8 | 9 | from scripts.gen_schema import generate_schema |
| 10 | +from scripts.gen_signature import gen_signature |
9 | 11 |
|
10 | 12 |
|
11 | 13 | def test_generated_field_descriptions_are_introspectable() -> None: |
@@ -74,6 +76,20 @@ def test_codegen_check_is_clean_and_read_only() -> None: |
74 | 76 | assert {output: output.read_bytes() for output in outputs} == before |
75 | 77 |
|
76 | 78 |
|
| 79 | +@pytest.mark.parametrize("protocol_version", [1, 2]) |
| 80 | +def test_generated_signatures_are_in_sync(tmp_path: Path, protocol_version: int) -> None: |
| 81 | + source = ROOT / "src" / "acp" |
| 82 | + if protocol_version == 2: |
| 83 | + source = source / "experimental" / "v2" |
| 84 | + generated = copytree(source, tmp_path / source.name) |
| 85 | + |
| 86 | + gen_signature(generated, protocol_version=protocol_version) |
| 87 | + |
| 88 | + for output in generated.rglob("*.py"): |
| 89 | + relative_path = output.relative_to(generated) |
| 90 | + assert output.read_bytes() == (source / relative_path).read_bytes(), relative_path |
| 91 | + |
| 92 | + |
77 | 93 | def test_signature_generation_preserves_inline_literal_values() -> None: |
78 | 94 | import ast |
79 | 95 | from typing import Literal, get_type_hints |
@@ -232,8 +248,6 @@ def test_v2_signature_generation_uses_v2_schema_and_qualified_types() -> None: |
232 | 248 |
|
233 | 249 |
|
234 | 250 | def test_v1_signature_generation_does_not_rewrite_experimental_files(tmp_path) -> None: |
235 | | - from scripts.gen_signature import gen_signature |
236 | | - |
237 | 251 | experimental = tmp_path / "experimental" / "v2" |
238 | 252 | experimental.mkdir(parents=True) |
239 | 253 | target = experimental / "interfaces.py" |
|
0 commit comments