Plan 006 step 1-2. registry.apply_schema honors PG_SKIP_SCHEMA; register()
validates required keys incl. fidelity floors and refuses to overwrite an
existing id (pre-registration is immutable). CLI: python -m research.experiments
{register|run|adjudicate} with deferred imports. 6 registry tests green.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
"""CLI: ``python -m research.experiments {register|run|adjudicate} [args]``.
|
|
|
|
Thin wrapper. Builds ONE EventStore (its Postgres connection is shared for the
|
|
experiment tables) and dispatches. Deferred imports so each subcommand only
|
|
pulls what it needs. NEVER run against the production DB from a test — the
|
|
harness's real verdict lands when the owner first schedules it.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
|
|
|
|
def _store():
|
|
from storage.event_store import EventStore
|
|
return EventStore(os.environ.get("WATCHER_EVENT_DB_PATH", "momentum"))
|
|
|
|
|
|
def main(argv=None) -> int:
|
|
argv = list(sys.argv[1:] if argv is None else argv)
|
|
if not argv:
|
|
print("usage: python -m research.experiments {register <json>|run|adjudicate}")
|
|
return 2
|
|
cmd, rest = argv[0], argv[1:]
|
|
|
|
if cmd == "register":
|
|
if not rest:
|
|
print("usage: python -m research.experiments register <json_path>")
|
|
return 2
|
|
from research.experiments import registry
|
|
store = _store()
|
|
try:
|
|
registry.apply_schema(store.con)
|
|
exp_id = registry.register(store.con, rest[0])
|
|
print(f"registered {exp_id}")
|
|
finally:
|
|
store.close()
|
|
return 0
|
|
|
|
if cmd == "run":
|
|
from research.experiments import replay
|
|
store = _store()
|
|
try:
|
|
n = replay.run(store)
|
|
print(f"experiments run: {n} new run rows")
|
|
finally:
|
|
store.close()
|
|
return 0
|
|
|
|
if cmd == "adjudicate":
|
|
from research.experiments import adjudicate
|
|
store = _store()
|
|
try:
|
|
verdicts = adjudicate.adjudicate(store)
|
|
for v in verdicts:
|
|
print(f"{v['experiment_id']}: {v['verdict']} (n={v['n']})")
|
|
finally:
|
|
store.close()
|
|
return 0
|
|
|
|
print(f"unknown command: {cmd}")
|
|
return 2
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|