Download tests/test_agents.py from tailot/lingologos-physics: direct link, hf CLI and curl.
- Browser
- Download file 3.5 kB
-
https://huggingface.co/datasets/tailot/lingologos-physics/resolve/main/tests/test_agents.py
- Command line
-
hf download hf://datasets/tailot/lingologos-physics/tests/test_agents.py
-
curl -L -o test_agents.py https://huggingface.co/datasets/tailot/lingologos-physics/resolve/main/tests/test_agents.py
3.5 kB
| """What the eleven nodes do with one question, and what they refuse to do with it. | |
| The chain is a fixed pipeline, so the interesting question is not whether it finishes - it always | |
| finishes - but whether each node left the mark it should have left, and whether a node that had | |
| nothing to say says so instead of agreeing. | |
| """ | |
| import pytest | |
| from lgphys import agents, faults, pipeline | |
| CONVERT = "convert 3 km to m" | |
| REFUSED_CONVERSION = "convert 3 m to s" | |
| GUARDED = ("potential node 1 circuit 3 resistors [ 1 2 10 ; 2 3 20 ] sources [ 1 1 ]" | |
| " size 1000000 frequency 50000000000") | |
| ABSTAINED = "predict the exact position and momentum of one particle" | |
| OUTSIDE = "what is the meaning of life" | |
| def _no_faults(): | |
| faults.configure("") | |
| yield | |
| faults.configure("") | |
| def test_every_node_of_the_chain_leaves_its_mark(): | |
| out = pipeline.run(CONVERT) | |
| assert sorted(out["dossier"]["states"]) == sorted(agents.ALL_AGENTS) | |
| assert [record["sender"] for record in out["records"]] == list(agents.ALL_AGENTS) | |
| assert out["turns"] == len(agents.ALL_AGENTS) | |
| def test_the_two_readers_work_on_different_roads(): | |
| out = pipeline.run(CONVERT) | |
| readers = out["dossier"]["readers"] | |
| assert readers["a"]["road"] != readers["b"]["road"] | |
| assert sorted(out["dossier"]["roads"]) == ["read_a", "read_b"] | |
| assert out["dossier"]["canon_equal"] is True | |
| def test_a_question_physics_refuses_is_never_handed_to_mathematics(): | |
| out = pipeline.run(REFUSED_CONVERSION) | |
| assert out["dossier"].get("delegate", "") == "" | |
| assert out["dossier"]["math"]["status"] == "NOT_ASKED" | |
| assert out["decision"]["status"] == agents.REFUSED | |
| assert out["decision"]["assurance"] == 2 | |
| def test_a_question_outside_the_fragment_is_refused_by_the_readers(): | |
| out = pipeline.run(OUTSIDE) | |
| assert out["dossier"].get("canon_equal") is not True | |
| assert out["decision"]["status"] == agents.REFUSED | |
| assert out["decision"]["assurance"] == 2 | |
| def test_a_guard_that_stops_the_law_is_reported_as_a_guard_and_not_as_an_error(): | |
| out = pipeline.run(GUARDED) | |
| decision = out["decision"] | |
| assert decision["status"] == agents.GUARD_BLOCKED | |
| stopped = {name for _agent, name, burden in decision["failures"] if burden == "guard"} | |
| assert stopped == {"epsilon_regime_holds"}, sorted(stopped) | |
| # A law outside the range it was stated for is a refusal the chain is confident about. | |
| assert decision["assurance"] >= 1 | |
| assert out["dossier"]["math"]["status"] == "NOT_ASKED" | |
| def test_a_band_refused_by_design_is_an_abstention_rather_than_a_refusal(): | |
| out = pipeline.run(ABSTAINED) | |
| decision = out["decision"] | |
| assert out["dossier"]["abstain"] == "measurement_limit" | |
| assert decision["status"] == agents.ABSTAINED | |
| # The chain does not claim any confidence here: the question is outside what physics can answer. | |
| assert decision["assurance"] == 0 | |
| assert "abstention_measurement_limit" in decision["reasons"] | |
| def test_a_family_that_never_needs_arithmetic_never_forms_a_delegate(): | |
| out = pipeline.run("audit V = I * R") | |
| assert out["dossier"].get("delegate", "") == "" | |
| assert out["dossier"]["math"]["status"] == "NOT_ASKED" | |
| assert out["decision"]["status"] == agents.VERIFIED | |
| def test_the_verdict_line_is_one_line_and_starts_with_the_dataset_name(): | |
| out = pipeline.run(CONVERT) | |
| line = out["line"] | |
| assert line.startswith("PHYSICS ") and "\n" not in line | |
| assert "assurance=2" in line | |