Spaces:
Running
Running
| #!/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()) | |