Add docs, tests and agent rules; fix demo paths and a lock-release race

- README.md: usage, keys, how a sanity run works, config, demo command
- CLAUDE.md: rules for agents, ported from verilogrustformatter with a
  single serial dev loop (lead plans, dev, QA, lead reviews)
- tests/test_runner.py: stdlib unittest suite running the runner end to
  end against the demo sandbox (pass, fail, cancel, stale, stamp hash)
- tools/guard.py: time limit plus leaked-process check for test runs
- TODO.md and docs/features/dsflow-tui/README.md: backlog and feature doc

Fixes found by the tests:
- the fake dssc resolved paths wrong under symlinked dirs, breaking the
  default --demo location on macOS (/var -> /private/var)
- the runner saved its terminal status before releasing locks, so the
  TUI could report a run finished while locks were still held

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
lucioandClaude Opus 5.5 committed 2026-09-23 11:09:35 -07:00
1 parent e58b768963
commit 275d42aeb4
7 files changed
+635 -13

No files matched your search

+132
View File
@@ -0,0 +1,132 @@
"""Runner and Flow tests against the --demo sandbox (fake dssc, no real vault).
python3 -m unittest discover -s tests -v
"""
import os
import shutil
import subprocess
import sys
import tempfile
import time
import unittest
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
import dsflow_tui as d # noqa: E402
RUN_TIMEOUT = 60
class DemoCase(unittest.TestCase):
"""Fresh demo workspace per test; sanity steps are shortened to keep runs fast."""
def setUp(self):
self.base = tempfile.mkdtemp(prefix="dsflow_tui_test-")
self.env = dict(os.environ)
os.environ.update(DEMO_STEP_SECS="0.05", DEMO_SANITY_TESTS="3")
os.environ.pop("DEMO_FAIL", None)
ws, conf = d.setup_demo(self.base, True)
self.flow = d.Flow(ws, conf)
self.flow.load_vars()
def tearDown(self):
os.environ.clear()
os.environ.update(self.env)
for root, dirs, files in os.walk(self.base):
for n in dirs + files:
os.chmod(os.path.join(root, n), 0o755)
shutil.rmtree(self.base)
def start(self, mods, news=(), mode="checkin", tag=""):
job = d.new_job(self.flow, list(mods), list(news), self.flow.configs, mode, "test", tag, True)
d.spawn_runner(self.flow, job)
def wait(self, until_state="done"):
deadline = time.time() + RUN_TIMEOUT
while time.time() < deadline:
job = d.read_json(self.flow.path(d.JOB_FILE))
if d.job_state(job) == until_state:
return job
time.sleep(0.2)
self.fail("runner did not reach '%s' within %ds" % (until_state, RUN_TIMEOUT))
def steps(self, job):
return dict((s["key"], s["status"]) for s in job["steps"])
class SnapshotTest(DemoCase):
def test_lists_changes_locks_and_checkouts(self):
snap = self.flow.snapshot()
self.assertIsNone(snap.err)
kinds = dict((r["path"], r["kind"]) for r in snap.changes)
self.assertEqual(kinds["rtl/rx/rx_agg.sv"], "A")
self.assertEqual(kinds["rtl/rx/rx_fsm.sv"], "M")
stale = [r["path"] for r in snap.changes if r["stale"]]
self.assertEqual(stale, ["rtl/tx/tx_ctrl.sv"])
holders = dict((r["path"], r["holder"]) for r in snap.locks)
self.assertEqual(holders["rtl/regs/mac_regs.sv"], "alice")
self.assertEqual(holders["rtl/top/wifi_mac_top.sv"], d.ME)
self.assertIn("rtl/tx/tx_crc.sv", [r["path"] for r in snap.checkout])
class RunnerTest(DemoCase):
def test_pass_checks_in_tags_and_releases_locks(self):
mods = ["rtl/rx/rx_fsm.sv", "rtl/tx/tx_fifo.sv"]
self.start(mods, ["rtl/rx/rx_agg.sv"], tag="wmac_working")
job = self.wait()
self.assertEqual(job["status"], "passed", job.get("summary"))
self.assertTrue(job["checked_in"])
self.assertEqual(set(self.steps(job).values()), {"done"})
self.assertEqual(self.flow.holders(mods), dict((f, "") for f in mods))
self.assertEqual(self.flow.new_files(), [])
with open(self.flow.vars["CHECKIN_LOG"]) as fh:
self.assertIn("rtl/rx/rx_agg.sv", fh.read())
def test_failure_releases_run_locks_but_keeps_preheld(self):
os.environ["DEMO_FAIL"] = "jaguar_1x1"
hot, plain = "rtl/top/wifi_mac_top.sv", "rtl/rx/rx_fsm.sv"
self.start([hot, plain])
job = self.wait()
self.assertEqual(job["status"], "failed")
self.assertEqual(job["locked_by_job"], [plain])
self.assertEqual(self.steps(job)["checkin"], "skipped")
self.assertEqual(self.flow.holders([hot, plain]), {hot: d.ME, plain: ""})
def test_cancel_stops_sanity_and_releases_locks(self):
os.environ.update(DEMO_STEP_SECS="2", DEMO_SANITY_TESTS="30")
mods = ["rtl/rx/rx_fsm.sv"]
self.start(mods, mode="unlock")
deadline = time.time() + RUN_TIMEOUT
while self.steps(d.read_json(self.flow.path(d.JOB_FILE))).get("sanity:kibo_2x2") != "running":
self.assertLess(time.time(), deadline)
time.sleep(0.2)
open(self.flow.path(d.JOB_CANCEL), "w").close()
job = self.wait()
self.assertEqual(job["status"], "cancelled")
self.assertEqual(self.flow.holders(mods), {mods[0]: ""})
self.assertNotIn("child_pid", job)
def test_stale_file_is_rejected_before_locking(self):
self.start(["rtl/tx/tx_ctrl.sv"])
job = self.wait()
self.assertEqual(job["status"], "failed")
self.assertEqual(self.steps(job)["validate"], "failed")
self.assertEqual(job["locked_by_job"], [])
def test_full_coverage_run_writes_stamp_dsflow_accepts(self):
self.assertEqual(self.flow.act("ds_rebase", "rtl/tx/tx_ctrl.sv")[0], 0)
snap = self.flow.snapshot()
mods = [r["path"] for r in snap.changes if r["kind"] == "M"]
news = [r["path"] for r in snap.changes if r["kind"] == "A"]
self.start(mods, news, mode="unlock")
self.assertEqual(self.wait()["status"], "passed")
with open(self.flow.path("sanity.stamp")) as fh:
stamp = dict(l.split("=", 1) for l in fh.read().splitlines())
# dsflow's content_hash, transcribed so it also runs on bash 3.2
bash_hash = subprocess.check_output(self.flow.argv(
'fs=$(%s); sha1sum $fs | sha1sum | cut -d" " -f1' % d.ALL_CHANGES_SH),
cwd=self.flow.ws, env=self.flow.env(), universal_newlines=True).strip()
self.assertEqual(stamp["stamp_hash"], bash_hash)
if __name__ == "__main__":
unittest.main()