|
| 1 | +"""Phase G11.0.2 (v0.11.3) F22 corrective pinning tests. |
| 2 | +
|
| 3 | +Pre-v0.11.3 the verifier's dispatch site |
| 4 | +(``verification.step2_3_check_version_and_language``) rejected |
| 5 | +any manifest whose ``language`` was not exactly ``"python"``, |
| 6 | +even though ``Manifest.from_dict`` accepted both |
| 7 | +``("python", "rust")`` from v0.11.0 onwards. The result was |
| 8 | +that the ``gate11-rust-smoke-test`` CI job had been red since |
| 9 | +PR #20 (v0.11.0): a rust manifest passed the schema validator |
| 10 | +but was rejected at the dispatch site with CASM-V-001. The |
| 11 | +dispatch surface contradicted the documented schema surface. |
| 12 | +
|
| 13 | +v0.11.3 aligns the dispatch whitelist with the schema |
| 14 | +whitelist. After this corrective, the rust smoke test goes |
| 15 | +green for the first time since v0.11.0. |
| 16 | +
|
| 17 | +These tests pin the corrective. They are intentionally |
| 18 | +narrow: only python and rust are exercised, because those are |
| 19 | +the two language substrates that have shipped verifiers as of |
| 20 | +v0.11.3. Go (Phase G11.2) and ONNX (Phase G11.3) are out of |
| 21 | +scope for this patch. |
| 22 | +""" |
| 23 | + |
| 24 | +# ruff: noqa: E402 |
| 25 | + |
| 26 | +from __future__ import annotations |
| 27 | + |
| 28 | +import pytest |
| 29 | + |
| 30 | +pytest.importorskip("rfc8785") |
| 31 | + |
| 32 | +from furqan_lint.gate11.manifest_schema import ( |
| 33 | + CasmSchemaError, |
| 34 | + Manifest, |
| 35 | +) |
| 36 | +from furqan_lint.gate11.verification import ( |
| 37 | + CasmVerificationError, |
| 38 | + TrustConfig, |
| 39 | + Verifier, |
| 40 | +) |
| 41 | + |
| 42 | + |
| 43 | +def _baseline_manifest_dict(language: str) -> dict: |
| 44 | + """Build a minimal Manifest dict in the requested language.""" |
| 45 | + return { |
| 46 | + "casm_version": "1.0", |
| 47 | + "module_identity": { |
| 48 | + "language": language, |
| 49 | + "module_path": "x", |
| 50 | + "module_root_hash": "sha256:" + "0" * 64, |
| 51 | + }, |
| 52 | + "public_surface": { |
| 53 | + "names": [], |
| 54 | + "extraction_method": (f"placeholder.{language}-public-surface@v1.0"), |
| 55 | + "extraction_substrate": "test", |
| 56 | + }, |
| 57 | + "chain": { |
| 58 | + "previous_manifest_hash": None, |
| 59 | + "chain_position": 1, |
| 60 | + }, |
| 61 | + "linter_substrate_attestation": { |
| 62 | + "linter_name": "furqan-lint", |
| 63 | + "linter_version": "0.11.3", |
| 64 | + "checker_set_hash": "sha256:" + "1" * 64, |
| 65 | + }, |
| 66 | + "trust_root": {"trust_root_id": "public-sigstore"}, |
| 67 | + "issued_at": "2026-05-09T00:00:00Z", |
| 68 | + } |
| 69 | + |
| 70 | + |
| 71 | +# --------------------------------------------------------------- |
| 72 | +# Schema-side: Manifest.from_dict accepts python and rust |
| 73 | +# (this was already true from v0.11.0; pin it as regression guard) |
| 74 | +# --------------------------------------------------------------- |
| 75 | + |
| 76 | + |
| 77 | +def test_schema_accepts_language_python() -> None: |
| 78 | + Manifest.from_dict(_baseline_manifest_dict("python")) |
| 79 | + |
| 80 | + |
| 81 | +def test_schema_accepts_language_rust() -> None: |
| 82 | + Manifest.from_dict(_baseline_manifest_dict("rust")) |
| 83 | + |
| 84 | + |
| 85 | +def test_schema_rejects_language_go() -> None: |
| 86 | + """Go support ships in Phase G11.2; until then schema rejects it. |
| 87 | +
|
| 88 | + This pin is removed when Phase G11.2 ships (v0.12.0+). |
| 89 | + """ |
| 90 | + bad = _baseline_manifest_dict("go") |
| 91 | + with pytest.raises(CasmSchemaError) as exc: |
| 92 | + Manifest.from_dict(bad) |
| 93 | + assert exc.value.code == "CASM-V-001" |
| 94 | + |
| 95 | + |
| 96 | +# --------------------------------------------------------------- |
| 97 | +# Dispatch-site: step2_3 accepts python and rust (THE F22 FIX) |
| 98 | +# --------------------------------------------------------------- |
| 99 | + |
| 100 | + |
| 101 | +def test_step2_3_accepts_python_manifest() -> None: |
| 102 | + verifier = Verifier(trust_config=TrustConfig()) |
| 103 | + manifest = Manifest.from_dict(_baseline_manifest_dict("python")) |
| 104 | + # No exception raised -> dispatch accepts. |
| 105 | + verifier.step2_3_check_version_and_language(manifest) |
| 106 | + |
| 107 | + |
| 108 | +def test_f22_step2_3_accepts_rust_manifest() -> None: |
| 109 | + """F22 CLOSURE: rust manifest no longer rejected at step 2_3. |
| 110 | +
|
| 111 | + Pre-v0.11.3 this raised CasmVerificationError(CASM-V-001, |
| 112 | + 'v1.0 supports only language=python; got rust'), causing |
| 113 | + gate11-rust-smoke-test CI to be red since v0.11.0. v0.11.3 |
| 114 | + aligns the dispatch whitelist with the schema whitelist |
| 115 | + (both accept python/rust). |
| 116 | + """ |
| 117 | + verifier = Verifier(trust_config=TrustConfig()) |
| 118 | + manifest = Manifest.from_dict(_baseline_manifest_dict("rust")) |
| 119 | + verifier.step2_3_check_version_and_language(manifest) |
| 120 | + |
| 121 | + |
| 122 | +def test_step2_3_rejects_unknown_language_with_supported_list() -> None: |
| 123 | + """Unsupported languages still fail-closed at the dispatch site |
| 124 | + with CasmVerificationError(CASM-V-001) and the supported list |
| 125 | + enumerated in the error message. Future Phase G11.2 (Go) and |
| 126 | + G11.3 (ONNX) will extend the whitelist when their verifiers |
| 127 | + ship. |
| 128 | + """ |
| 129 | + # We bypass schema (which would reject 'haskell') and forge |
| 130 | + # the language field directly to exercise the verifier-side |
| 131 | + # defense. |
| 132 | + valid = Manifest.from_dict(_baseline_manifest_dict("python")) |
| 133 | + valid.module_identity["language"] = "haskell" |
| 134 | + |
| 135 | + verifier = Verifier(trust_config=TrustConfig()) |
| 136 | + with pytest.raises(CasmVerificationError) as exc: |
| 137 | + verifier.step2_3_check_version_and_language(valid) |
| 138 | + assert exc.value.code == "CASM-V-001" |
| 139 | + # The error message must enumerate the supported list so an |
| 140 | + # operator hitting this knows how to adjust. |
| 141 | + msg = str(exc.value).lower() |
| 142 | + assert "python" in msg |
| 143 | + assert "rust" in msg |
| 144 | + |
| 145 | + |
| 146 | +def test_step2_3_rejects_go_pre_g11_2() -> None: |
| 147 | + """Go is not yet supported (Phase G11.2 / v0.12.0). The |
| 148 | + dispatch site fails-closed with CASM-V-001 + a clear error |
| 149 | + message naming the future phase. |
| 150 | + """ |
| 151 | + valid = Manifest.from_dict(_baseline_manifest_dict("python")) |
| 152 | + valid.module_identity["language"] = "go" |
| 153 | + |
| 154 | + verifier = Verifier(trust_config=TrustConfig()) |
| 155 | + with pytest.raises(CasmVerificationError) as exc: |
| 156 | + verifier.step2_3_check_version_and_language(valid) |
| 157 | + assert exc.value.code == "CASM-V-001" |
| 158 | + # Error message names the phase that will add Go. |
| 159 | + assert "G11.2" in str(exc.value) |
0 commit comments