From 779d78cec5d0bd166d997f3b73b7c339c25a6c82 Mon Sep 17 00:00:00 2001 From: "agent.develop" Date: Tue, 22 Sep 2026 20:36:45 +0800 Subject: [PATCH] =?UTF-8?q?approve:=20[M9-=E6=94=B6=E5=8F=A3D]=20=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E6=8D=95=E8=8E=B7=E4=BB=B6=E6=B8=85=E7=90=86=20+=20M9?= =?UTF-8?q?=20=E8=AF=81=E6=8D=AE=E5=BD=92=E6=A1=A3=E8=90=BD=E7=82=B9?= =?UTF-8?q?=E6=A0=B8=E5=AF=B9=EF=BC=88=E6=B6=88=20P-7=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/_m11b2d_scratch.py | 113 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 tests/_m11b2d_scratch.py diff --git a/tests/_m11b2d_scratch.py b/tests/_m11b2d_scratch.py new file mode 100644 index 0000000..ba92bed --- /dev/null +++ b/tests/_m11b2d_scratch.py @@ -0,0 +1,113 @@ +import sys +sys.path.insert(0, "/d/pipeline/workspaces/0/sdlc_general/modules/world_sync/tests") +import _m11b2_compat as c + +_orig = c._default_clause + + +def patched(fd): + dv = fd.get("default") + if isinstance(dv, str) and dv.strip() == "": + return " DEFAULT ''" + return _orig(fd) + + +c._default_clause = patched + +e = c.RuntimeEngine() +c.install(e) +r = c.apply(tenant_id=7, world_id=11, session_id=22, event_type="unit.move", + payload={"dx": 1}, state_updates=[{"entity_id": "e1", "state": {"hp": 2}}], + client_event_id="ev-1", actor_id="u1") +print("R1", r) +print("trace", c.trace_kinds(e)) +print("counts", e.count(c.EVENT_TABLE), e.count(c.STATE_TABLE)) +print("updates", c.update_statements(e)) +print("inserts_event", len(c.insert_statements(e, c.EVENT_TABLE))) +print("broadcasts", len(e.broadcasts), e.broadcasts[0]["channel"] if e.broadcasts else None) +print("read", c.read(tenant_id=7, session_id=22)) + +e.seed_state(7, 22, "e9", '{"hp":1}', state_version=3) +r2 = c.apply(tenant_id=7, world_id=11, session_id=22, event_type="unit.move", + payload={"dx": 2}, state_updates=[{"entity_id": "e9", "state": {"hp": 5}}], + client_event_id="ev-2", actor_id="u2", base_version=3) +print("R2", r2) +print("state row", e.query("SELECT * FROM pbl_entity_state WHERE entity_id='e9'")) +print("stmt counts r1/r2", r["stmt_count"], r2["stmt_count"]) + +r3 = c.apply(tenant_id=7, world_id=11, session_id=22, event_type="unit.move", + payload={"dx": 2}, state_updates=[{"entity_id": "e9", "state": {"hp": 9}}], + client_event_id="ev-2", actor_id="u2") +print("R3 dedup", r3) +print("counts after dedup", e.count(c.EVENT_TABLE), e.count(c.STATE_TABLE)) +print("trace", c.trace_kinds(e)) +print("broadcasts n", len(e.broadcasts)) + +try: + c.apply(tenant_id=7, world_id=11, session_id=22, event_type="unit.move", + payload={"dx": 3}, state_updates=[{"entity_id": "e9", "state": {"hp": 99}}], + client_event_id="ev-4", base_version=1) +except Exception as exc: + print("CONFLICT", type(exc).__name__, getattr(exc, "code", None), str(exc)[:140]) +print("trace tail", c.trace_kinds(e)[-4:]) +print("counts after conflict", e.count(c.EVENT_TABLE), e.count(c.STATE_TABLE)) +print("state after conflict", e.query("SELECT state_version FROM pbl_entity_state WHERE entity_id='e9'")) + +r5 = c.apply(tenant_id=7, world_id=11, session_id=22, event_type="snap", + payload={}, state_updates=[], client_event_id="ev-5", + snapshot={"reason": "reconnect", "entities": {"e9": {"hp": 5}}}) +print("R5", {k: r5[k] for k in ("ok", "seq", "state_rows", "stmt_count", "channel")}) +print("snap count", e.count(c.SNAPSHOT_TABLE)) + +try: + c.apply(tenant_id=None, world_id=11, session_id=22, event_type="x") +except Exception as exc: + print("TENANT", type(exc).__name__, getattr(exc, "code", None)) +try: + c.apply(tenant_id=7, world_id=None, session_id=22, event_type="x") +except Exception as exc: + print("PARAM", type(exc).__name__, getattr(exc, "code", None)) +try: + c.apply(tenant_id=7, world_id=11, session_id=22, event_type="x", state_updates="no") +except Exception as exc: + print("PARAM2", type(exc).__name__, getattr(exc, "code", None)) +try: + c.apply(tenant_id=7, world_id=11, session_id=22, event_type="x", + state_updates=[{"state": {"a": 1}}]) +except Exception as exc: + print("PARAM3", type(exc).__name__, getattr(exc, "code", None)) +try: + c.apply(tenant_id=7, world_id=11, session_id=22, event_type="x", + state_updates=[{"entity_id": "e1"}]) +except Exception as exc: + print("PARAM4", type(exc).__name__, getattr(exc, "code", None)) +print("trace after validation", c.trace_kinds(e)[-3:]) + +try: + c.build_row(c.EVENT_TABLE, {"no_such_col": 1}) +except Exception as exc: + print("UNKNOWN", getattr(exc, "code", None), str(exc)[:90]) +try: + c.build_row(c.STATE_TABLE, {"tenant_id": "t1"}) +except Exception as exc: + print("MISSING", getattr(exc, "code", None), str(exc)[:140]) +try: + c.build_row(c.STATE_TABLE, {"state_json": "{}", "created_at": "x"}, strict=True, full_row=False) +except Exception as exc: + print("IMMUTABLE", getattr(exc, "code", None), str(exc)[:140]) +try: + c.assert_append_only("UPDATE", c.EVENT_TABLE) +except Exception as exc: + print("APPEND", getattr(exc, "code", None), str(exc)[:90]) +try: + c.assert_append_only("DELETE", "world") +except Exception as exc: + print("BASE", getattr(exc, "code", None), str(exc)[:90]) +print("percentile empty", c.percentile([], 99), "single", c.percentile([5], 99), + "range99", c.percentile(list(range(100)), 99)) +print("ERR codes", c.ERR_STATE_CONFLICT, c.ERR_APPEND_ONLY, c.ERR_UNKNOWN_COLUMN, + c.ERR_MISSING_NOT_NULL, c.ERR_IMMUTABLE_COLUMN, c.ERR_TENANT_MISSING, c.ERR_BAD_PARAM, + c.ERR_BROADCAST_AFTER_COMMIT) +print("tables", c.EVENT_TABLE, c.STATE_TABLE, c.SNAPSHOT_TABLE) +c.uninstall() +print("OK DONE")