Files
dssc/tests/test_ui.py
T
lucioandClaude Opus 5.5 60532a4043 Rebuild the UI on vendored Textual; make the checkout self-contained
The internal servers have no access to outside package repositories and
run Python 3.8/3.9, so the UI moves from hand-drawn curses to Textual
6.2.1 (the last release supporting 3.8.1), vendored with its pure-Python
dependencies in vendor/. The launcher puts vendor/ first on sys.path, so a
plain checkout runs with no pip and no network.

- dsflow/: the single script split into a package (pure moves of the
  backend sections); action rules moved to ops.py, free of Textual
- dsflow/ui/: tabs, detail pane, live sanity-run panel, log viewer,
  modal dialogs, filter, themes, mouse support
- tests/test_ui.py: headless UI tests through Textual's pilot
- tools/vendor.py (refresh vendor/), tools/screenshots.py (README images)
- README, CLAUDE.md, TODO and the feature doc updated for the new layout,
  the Python 3.8.1 floor and the vendoring rules

Verified: 11 tests green on Python 3.12 and 3.8.20; the shipped file set
runs under `python -I -S` on both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-24 03:24:21 -07:00

124 lines
5.0 KiB
Python

"""UI tests: drive the Textual app headlessly (Textual's pilot) against the demo sandbox.
tools/guard.py -- python3 -m unittest discover -s tests -v
"""
import os
import shutil
import sys
import tempfile
import time
import unittest
ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
sys.path[:0] = [ROOT, os.path.join(ROOT, "vendor")]
from dsflow.demo import setup_demo # noqa: E402
from dsflow.flow import Flow # noqa: E402
from dsflow.ui.app import DsflowApp # noqa: E402
from dsflow.ui.dialogs import MessageDialog, SanityDialog # noqa: E402
SIZE = (130, 40)
class UICase(unittest.IsolatedAsyncioTestCase):
def setUp(self):
self.base = tempfile.mkdtemp(prefix="dsflow_ui_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 = setup_demo(self.base, True)
self.flow = 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)
async def until(self, pilot, cond, timeout=30):
deadline = time.time() + timeout
while not cond():
self.assertLess(time.time(), deadline, "condition not reached")
await pilot.pause(0.1)
async def ready(self, pilot, app):
await self.until(pilot, lambda: app.snap is not None)
await pilot.pause(0.2)
class MainScreenTest(UICase):
async def test_lists_changes_and_marks_with_space(self):
app = DsflowApp(self.flow)
async with app.run_test(size=SIZE) as pilot:
await self.ready(pilot, app)
table = app.table("changes")
self.assertIs(app.focused, table) # never the hidden filter input
self.assertEqual(table.row_count, 5)
await pilot.press("space", "space")
self.assertEqual(app.marks, {"rtl/rx/rx_fsm.sv", "rtl/top/wifi_mac_top.sv"})
await pilot.press("escape")
self.assertEqual(app.marks, set())
async def test_filter_narrows_the_table(self):
app = DsflowApp(self.flow)
async with app.run_test(size=SIZE) as pilot:
await self.ready(pilot, app)
await pilot.press("slash", *"tx_")
await pilot.pause(0.1)
self.assertEqual([r["path"] for r in app.table("changes").file_rows],
["rtl/tx/tx_ctrl.sv", "rtl/tx/tx_fifo.sv"])
await pilot.press("escape")
self.assertEqual(app.table("changes").row_count, 5)
async def test_stale_file_is_refused_with_a_dialog(self):
app = DsflowApp(self.flow)
async with app.run_test(size=SIZE) as pilot:
await self.ready(pilot, app)
await pilot.press("down", "down", "s") # rtl/tx/tx_ctrl.sv is stale in the demo
await pilot.pause(0.2)
self.assertIsInstance(app.screen, MessageDialog)
class SanityRunTest(UICase):
async def test_run_from_dialog_checks_in_and_releases_locks(self):
app = DsflowApp(self.flow)
async with app.run_test(size=SIZE) as pilot:
await self.ready(pilot, app)
await pilot.press("space", "s")
await pilot.pause(0.3)
self.assertIsInstance(app.screen, SanityDialog)
await pilot.press("enter") # empty comment: refused, dialog stays
await pilot.pause(0.1)
self.assertIsInstance(app.screen, SanityDialog)
await pilot.press(*"fix rx fsm", "enter")
await self.until(pilot, lambda: app.jstate == "active")
await pilot.pause(0.3)
self.assertEqual(app.tab(), "sanity")
await self.until(pilot, lambda: app.jstate == "done", 60)
self.assertEqual(app.job["status"], "passed", app.job.get("summary"))
self.assertTrue(app.job["checked_in"])
self.assertEqual(self.flow.holders(["rtl/rx/rx_fsm.sv"]), {"rtl/rx/rx_fsm.sv": ""})
async def test_cancel_from_the_ui(self):
os.environ.update(DEMO_STEP_SECS="2", DEMO_SANITY_TESTS="30")
app = DsflowApp(self.flow)
async with app.run_test(size=SIZE) as pilot:
await self.ready(pilot, app)
await pilot.press("space", "s")
await pilot.pause(0.3)
await pilot.press(*"wip", "enter")
await self.until(pilot, lambda: app.jstate == "active" and any(
s["status"] == "running" and s.get("kind") == "sanity" for s in app.job["steps"]))
await pilot.press("x")
await pilot.pause(0.3)
await pilot.press("enter") # confirm
await self.until(pilot, lambda: app.jstate == "done", 60)
self.assertEqual(app.job["status"], "cancelled")
self.assertEqual(self.flow.holders(["rtl/rx/rx_fsm.sv"]), {"rtl/rx/rx_fsm.sv": ""})
if __name__ == "__main__":
unittest.main()