File size: 2,216 Bytes
39ff632
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
"""Regenerate tests/fixtures/factory_fixture.ts from the canned spec.

Used by the Docker build's fixture stage and by
``pytest tests/test_forge_bridge.py`` indirectly. Requires only the Python
standard library plus the vendored forge/ tree (via app/forge_bridge.py).

Usage: python3 scripts/build_fixture_factory.py [out.ts]
"""

from __future__ import annotations

import json
import sys
from pathlib import Path

REPO_ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO_ROOT))

from app import forge_bridge  # noqa: E402


def main() -> int:
    out = Path(sys.argv[1]) if len(sys.argv) > 1 else (
        REPO_ROOT / "tests" / "fixtures" / "factory_fixture.ts")
    spec = json.loads(
        (REPO_ROOT / "tests" / "fixtures" / "canned_spec.json").read_text(encoding="utf-8"))

    # Mirror the runtime adapter: strict-gate the original spec, then compile
    # a separate unreviewed hosted-preview manifest. No visual review evidence
    # or pass approval is invented.
    import tempfile

    with tempfile.TemporaryDirectory() as tmp:
        spec_path = Path(tmp) / "spec.json"
        spec_path.write_text(json.dumps(spec), encoding="utf-8")
        validation = forge_bridge.validate_spec(spec_path, strict=True)
        if not validation.get("ok"):
            print("canned spec failed strict-quality gate:", file=sys.stderr)
            for error in validation.get("errors", []):
                print(f"  - {error}", file=sys.stderr)
            return 1
        hosted_errors = forge_bridge.hosted_spec_errors(spec)
        if hosted_errors:
            print("canned spec is not supported by the hosted compiler:", file=sys.stderr)
            for error in hosted_errors:
                print(f"  - {error}", file=sys.stderr)
            return 1
        target = forge_bridge.HOSTED_PREVIEW_PASS
        preview = forge_bridge.prepare_hosted_preview(spec)
        spec_path.write_text(json.dumps(preview), encoding="utf-8")
        forge_bridge.generate_factory(spec_path, out, pass_id=target)
    print(f"fixture factory written: {out} ({out.stat().st_size} bytes, pass {target})")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())