syntheogenesis / tests /test_assembly_tool.py
github-actions[bot]
Deploy 6ee452f
70d3b6a
Raw
History Blame Contribute Delete
8.04 kB
"""Turing can BUILD now, not just describe building.
`dee/core/cloning.py` has done Gibson, Golden Gate and restriction cloning
since the plasmid work — with junction detection, overhang checking and primer
design — and until 2026-08-04 no agent tool imported it. So the "Build" step of
this product's own Design→Build→Edit→Learn loop had no agent path: asked to
clone three fragments into pET-28a, Turing could only write prose about how one
would. The capability was in the repo the whole time.
That is the fourth built-but-unreachable capability found in one day (the
vector catalogue, BLAST, pairwise alignment, and this), which is why the
capability audit leads with the category rather than with any one gap.
The tests here are weighted toward the ways an assembly can LIE:
* a design that does not close must be reported as a failure, not dressed up
as a product;
* a junction with no native overlap means primers someone has to buy, and a
summary that omits that makes a design look free;
* the engine's own warnings must survive to the model verbatim, not be
summarised into optimism.
"""
import pytest
from dee.core import agent_tools as t
from dee.core import cloning as cl
from dee.core import orchestrator as orch
# Three fragments with real, detectable overlaps between neighbours.
A = "ATGGCTAGCAAAGGAGAAGAACTTTTCACTGGAGTTGTCCCAATTCTTGTTGAATTAGATG"
B = A[-30:] + "GTGATGTTAATGGGCACAAATTTTCTGTCAGTGGAGAGGGTGAAGGTGATGCAACATACG"
C = B[-30:] + "GAAAACTTACCCTTAAATTTATTTGCACTACTGGAAAACTACCTGTTCCATGGCCAACAC"
def _frags():
return [{"name": "vector", "sequence": A},
{"name": "insert1", "sequence": B},
{"name": "insert2", "sequence": C}]
def _run(**kw):
args = {"fragments": _frags()}
args.update(kw)
return t.execute_tool("simulate_assembly", args, auth_anonymous=True)
# --------------------------------------------------------------------------- #
# it actually assembles
# --------------------------------------------------------------------------- #
def test_the_agent_can_reach_the_cloning_engine_at_all():
"""The whole point. Before this, cloning.py was not imported anywhere in
the tool layer."""
assert "simulate_assembly" in t._TOOLS
src = open("dee/core/agent_tools.py", encoding="utf-8").read()
assert "from dee.core import cloning" in src
def test_a_gibson_assembly_returns_a_real_product():
out = _run()
assert out["ok"] is True
assert out["_ui"]["sequence"]
assert out["length"] == len(out["_ui"]["sequence"])
assert len(out["junctions"]) >= 2
def test_native_overlaps_are_detected_rather_than_designed_over():
"""These fragments genuinely share 30 bp with their neighbours. If the
engine reports them as 'designed', it is inventing primer work that the
user does not need to pay for."""
out = _run()
kinds = [j["kind"] for j in out["junctions"]]
assert "native" in kinds, kinds
def test_the_assembled_product_matches_the_engine_directly():
"""The tool must not transform the sequence on its way through — it is a
wrapper, and a wrapper that alters its payload is a second implementation."""
direct = cl.gibson([{"name": f["name"], "seq": f["sequence"]} for f in _frags()])
assert _run()["_ui"]["sequence"] == direct["assembled"]
# --------------------------------------------------------------------------- #
# the ways it can lie
# --------------------------------------------------------------------------- #
def test_a_failed_assembly_is_reported_as_a_failure():
"""Golden Gate on fragments with no compatible overhangs does not close.
That is a real, useful answer — and the one an agent is most tempted to
round up into 'assembled successfully'."""
out = t.execute_tool("simulate_assembly",
{"fragments": _frags(), "method": "golden_gate"},
auth_anonymous=True)
assert out["ok"] is False
assert out["kind"] == "assembly_failed"
assert "do not describe the product as if it assembled" in out["next"].lower()
def test_primers_that_must_be_ordered_are_returned():
"""A designed junction is a purchase. Returning the product without the
primers makes the design look cheaper than it is."""
out = t.execute_tool("simulate_assembly",
{"fragments": [{"name": "x", "sequence": "ATGC" * 30},
{"name": "y", "sequence": "GGTT" * 30}]},
auth_anonymous=True)
if out["ok"]:
assert out["designed_junctions"] >= 1
assert "primers" in out
def test_engine_warnings_survive_verbatim():
"""Not summarised, not dropped. The warning is the honest part."""
out = t.execute_tool("simulate_assembly",
{"fragments": [{"name": "x", "sequence": "ATGC" * 30},
{"name": "y", "sequence": "GGTT" * 30}]},
auth_anonymous=True)
if out["ok"]:
direct = cl.gibson([{"name": "x", "seq": "ATGC" * 30},
{"name": "y", "seq": "GGTT" * 30}])
assert out["warnings"] == (direct.get("warnings") or [])
def test_the_summary_leads_with_the_primer_cost():
"""A one-line summary reading only "3,200 bp" hides the thing the user
has to act on."""
out = _run()
line = orch._summarize("simulate_assembly", out)
assert "junction" in line
if out.get("designed_junctions"):
assert "primer" in line
def test_the_result_asks_for_verification():
out = _run()
assert "map_plasmid" in out["next"]
assert "designed" in out["next"]
# --------------------------------------------------------------------------- #
# input handling
# --------------------------------------------------------------------------- #
def test_one_fragment_is_not_an_assembly():
out = t.execute_tool("simulate_assembly",
{"fragments": [{"name": "a", "sequence": A}]},
auth_anonymous=True)
assert out["ok"] is False
assert "two fragments" in out["error"]
def test_a_fragment_with_no_dna_is_refused_by_name():
"""Naming which fragment is empty is the difference between a fixable
error and a shrug."""
out = t.execute_tool("simulate_assembly",
{"fragments": [{"name": "vector", "sequence": A},
{"name": "bad insert", "sequence": "???"}]},
auth_anonymous=True)
assert out["ok"] is False
assert "bad insert" in out["error"]
def test_restriction_cloning_requires_its_enzyme():
out = t.execute_tool("simulate_assembly",
{"fragments": _frags(), "method": "restriction"},
auth_anonymous=True)
assert out["ok"] is False and "enzyme" in out["error"]
def test_an_unknown_method_is_refused_with_the_real_options():
out = t.execute_tool("simulate_assembly",
{"fragments": _frags(), "method": "magic"},
auth_anonymous=True)
assert out["ok"] is False
for m in ("gibson", "golden_gate", "restriction"):
assert m in out["error"]
# --------------------------------------------------------------------------- #
# wiring
# --------------------------------------------------------------------------- #
def test_the_bases_do_not_travel_through_the_model():
out = _run()
stripped = orch._strip_ui(out)
assert "_ui" not in stripped
assert not any(isinstance(v, str) and len(v) > 40 and set(v) <= set("ACGT")
for v in stripped.values())
def test_it_paints_the_plasmid_view():
assert orch._tool_view("simulate_assembly") == "plasmid"
assert "simulate_assembly" in open("dee/static/cockpit.js", encoding="utf-8").read()
def test_the_prompt_tells_it_to_build_rather_than_describe():
p = orch.build_system_prompt(False, {}, "")
assert "BUILD MEANS BUILD" in p
assert "simulate_assembly" in p