approve: [M9-收口D] 临时捕获件清理 + M9 证据归档落点核对(消 P-7)
This commit is contained in:
parent
eb7c242bb0
commit
779d78cec5
113
tests/_m11b2d_scratch.py
Normal file
113
tests/_m11b2d_scratch.py
Normal file
@ -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")
|
||||||
Loading…
x
Reference in New Issue
Block a user