Plan §6A, report-only per DIVISION-OF-WORK §4. Both halves ran. The cargo half
is real evidence; the LANE half is vacuous, and saying so is most of the point.
cargo test (PYO3_PYTHON=/opt/homebrew/bin/python3.12, --offline): 43 passed,
0 failed across 7 suites including test_crdt_hash_parity.rs. The plan's read
was right — cargo 1.97.1 and the registry cache are present locally and the
cloud session was blocked only by sandbox network policy.
Lane parity: 11/11 pinned SHAs match under both backends. That number means
nothing. Sabotaging EVERY core_rs callable to raise and re-running under
CORE_BACKEND=rust still gives `lanes: 11/11 match pinned SHAs`, exit 0. Three
sufficient reasons:
- The hot path bypasses the dispatch. algebra.cga.cga_inner is NOT
algebra.backend.cga_inner; 69 call sites import the hot functions from
algebra.cga/algebra.cl41 directly vs 24 through algebra.backend. The ~34k
cga_inner->geometric_product calls/turn that plan §6C calls ~73% of turn
time never reach the dispatch.
- The dtype gates reject the runtime workload. versor_condition IS imported
from algebra.backend by pipeline.py:24, and still falls through: the Rust
arm requires f32 and the wave-field workload is f64.
- Every dispatch arm ends in `except (..., Exception): pass`, so a broken,
garbage-returning, or absent kernel falls back to Python SILENTLY. That is
what makes the first two unfalsifiable by lane hashes.
Instrumented under CORE_BACKEND=rust: zero Rust calls in the whole
deductive_logic lane (pure ROBDD, no CGA), and exactly ONE
(versor_apply_with_closure_f64) in a full pipeline turn. CORE_BACKEND=rust is
today a one-call switch.
So §6B ("if parity holds, consider Rust default") rests on a measurement that
cannot fail, and §6C is the real blocker and is upstream of the backend. NOT
acted on — §6.4 says a parity/determinism finding is escalated, not fixed.
Recorded three follow-ups in dependency order: make the dispatch fail loudly,
add a parity test that fails when the Rust path is not TAKEN, only then route
the hot path.
The one thing fixed here is a plain defect blocking the measurement.
`core rust build` — the activation path print_rust_status() itself recommends —
raised `TypeError: _run() got an unexpected keyword argument 'env'` on every
invocation. core/cli.py::_run is injected into cli_rust.cmd_rust_build, which
passes env=rust_build_env() to carry PYO3_USE_ABI3_FORWARD_COMPATIBILITY, and
_run lacked the keyword the CommandRunner Protocol declares. One keyword, plus
tests/test_cli_runner_contract.py deriving the expected keywords FROM the
Protocol so the two cannot drift apart again. Verified end-to-end: `core rust
build` now builds and installs.
[Verification]: in-worktree on canonical CPython 3.12.13 with `uv sync
--locked`: smoke 575 (569 + 6), deductive 291 (unchanged). New tests fail
under mutation (revert the env keyword -> 3 red). Registered in `fast` AND
`smoke`. Installing core_rs does not activate it (_ALLOW_RUST requires
CORE_BACKEND), verified: extension present + no env var -> "rust backend:
inactive", so no default behaviour moves.
87 lines
3.3 KiB
Python
87 lines
3.3 KiB
Python
"""The injected `CommandRunner` must accept everything its call sites pass.
|
|
|
|
`core/cli.py::_run` is injected into `cli_rust.cmd_rust_build` and
|
|
`cli_test`'s runner. Both are typed against a `CommandRunner` Protocol carrying
|
|
`check`, `cwd` and `env`. `_run` was missing `env`, so `core rust build` raised
|
|
`TypeError: _run() got an unexpected keyword argument 'env'` on every
|
|
invocation — the documented Rust activation path had never worked.
|
|
|
|
Nothing caught it because the runner is only exercised through subprocess-y
|
|
commands that tests avoid calling for real. So the pin is on the SIGNATURE,
|
|
checked against the Protocol rather than against a hand-written list, so a
|
|
future keyword added to one side cannot drift from the other.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import inspect
|
|
|
|
import pytest
|
|
|
|
from core.cli import _run
|
|
from core.cli_test import CommandRunner, run_command
|
|
|
|
|
|
def _keywords(fn: object) -> set[str]:
|
|
sig = inspect.signature(fn) # type: ignore[arg-type]
|
|
return {
|
|
name
|
|
for name, p in sig.parameters.items()
|
|
if p.kind in (p.KEYWORD_ONLY, p.POSITIONAL_OR_KEYWORD)
|
|
and name not in ("args", "self")
|
|
}
|
|
|
|
|
|
def test_injected_runner_satisfies_the_command_runner_protocol() -> None:
|
|
"""Derived from the Protocol, so it cannot fall behind it."""
|
|
protocol_kwargs = _keywords(CommandRunner.__call__)
|
|
assert protocol_kwargs, "CommandRunner.__call__ has no keywords — protocol changed?"
|
|
missing = protocol_kwargs - _keywords(_run)
|
|
assert not missing, (
|
|
f"core.cli._run is missing {sorted(missing)} — it is injected into "
|
|
"cli_rust.cmd_rust_build, which passes env=rust_build_env(). A runner "
|
|
"that cannot accept what its call sites pass raises TypeError at runtime."
|
|
)
|
|
|
|
|
|
def test_default_runner_and_injected_runner_agree() -> None:
|
|
"""Both runners are used interchangeably; their keywords must match."""
|
|
assert _keywords(_run) == _keywords(run_command)
|
|
|
|
|
|
@pytest.mark.parametrize("keyword", ["check", "cwd", "env"])
|
|
def test_runner_accepts_each_documented_keyword(keyword: str) -> None:
|
|
assert keyword in _keywords(_run)
|
|
|
|
|
|
def test_rust_build_passes_env_so_the_runner_must_accept_it() -> None:
|
|
"""Pins the actual call site that broke, not just the signature.
|
|
|
|
Runs `cmd_rust_build` with a recording fake runner: it must reach the
|
|
maturin invocation and carry an env, rather than raising TypeError.
|
|
"""
|
|
import argparse
|
|
|
|
from core import cli_rust
|
|
|
|
seen: list[dict[str, object]] = []
|
|
|
|
def fake_run(*args: str, check: bool = False, cwd: object = None,
|
|
env: dict[str, str] | None = None) -> int:
|
|
seen.append({"args": args, "env": env})
|
|
return 0
|
|
|
|
args = argparse.Namespace(skip_auditwheel=False)
|
|
rc = cli_rust.cmd_rust_build(
|
|
args, run=fake_run, fail=lambda m, code=2: (_ for _ in ()).throw(SystemExit(code)),
|
|
python_executable="python3",
|
|
)
|
|
assert rc == 0
|
|
maturin = [c for c in seen if "maturin" in c["args"]]
|
|
assert maturin, f"maturin was never invoked; calls={seen}"
|
|
env = maturin[-1]["env"]
|
|
assert isinstance(env, dict)
|
|
assert env.get("PYO3_USE_ABI3_FORWARD_COMPATIBILITY") == "1", (
|
|
"the env is the whole reason the keyword exists — PyO3 0.21 supports "
|
|
"Python through 3.12 and needs the forward-compatibility escape hatch"
|
|
)
|