aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorblasty <blasty@local>2026-07-25 11:51:38 +0200
committerblasty <blasty@local>2026-07-25 11:51:38 +0200
commitf4cb6eba274c411c503cbc8b4ed10fdfc6b70dcb (patch)
treec9bd1e37b16725099e4d0351f91211443a5e2bf1 /tests
parentprojects: worker pool with memory-budgeted residency (phase 1b) (diff)
downloadida-tui-f4cb6eba274c411c503cbc8b4ed10fdfc6b70dcb.tar.gz
ida-tui-f4cb6eba274c411c503cbc8b4ed10fdfc6b70dcb.tar.xz
ida-tui-f4cb6eba274c411c503cbc8b4ed10fdfc6b70dcb.zip
projects: switch between a project's binaries in the TUI (phase 1c)
Wires the project model + worker pool into the app. Project mode is ADDITIVE — without --project the app is exactly the single-binary tool it was, which is what keeps the 167-check pilot meaningful. * IdaTui(project=...) builds a WorkerPool and opens the project's first binary; _open_worker_client asks the pool instead of spawning directly. * BinaryState snapshots what a switch leaves behind (program, func_index, nav, cur, view prefs, filter). Switching reuses the _after_reconnect shape: swap client+program, rebuild the index, reopen the entry. A still-resident binary restores instantly (Program + index are in memory); an evicted one gets a fresh worker but keeps its nav history, which is just addresses. * ProjectPalette (Ctrl+O, + a "Switch binary…" palette command): the project's binaries with resident/analysed/pinned/active state and memory, filterable. * launch.py --project FILE, creating the project when binaries are also given; stages everything up front so the source tree is never written to. Two bugs found while testing: * _did_auto_land is app-wide, but landing is per-binary: after the first binary landed, a cold switch never landed at all AND left the switch overlay up forever. Reset it per switch. * PRE-EXISTING: the status Static had Textual markup enabled, so a single-word bracket marker parses as a style tag and is silently eaten — [listing] and [pseudocode] have never actually rendered (only [split · listing] survived, because the · makes it an invalid tag). Status is plain text with brackets and symbol names, so markup=False. tests/test_project_ui.py: end-to-end pilot on two real binaries (18 checks) — boot, switcher contents, switch, per-binary index, both workers resident, switch back with state intact, return-to-where-you-were, and the promise that the source tree stays pristine while every artifact lands in the sidecar. Full single-binary suite unchanged at 167/2 (the standing flakes).
Diffstat (limited to 'tests')
-rw-r--r--tests/test_project_ui.py165
1 files changed, 165 insertions, 0 deletions
diff --git a/tests/test_project_ui.py b/tests/test_project_ui.py
new file mode 100644
index 0000000..025107d
--- /dev/null
+++ b/tests/test_project_ui.py
@@ -0,0 +1,165 @@
+#!/usr/bin/env python3
+"""End-to-end pilot for project mode: two binaries, switching between them.
+
+Needs idalib (it spawns real workers, one per binary) and textual:
+
+ ~/ida-venv/bin/python tests/test_project_ui.py [bin1 bin2]
+
+Defaults to targets/echo + targets/cat. The binaries are copied into a temp
+source dir first, so the "source tree stays pristine" promise is checkable.
+"""
+import asyncio
+import os
+import shutil
+import sys
+import tempfile
+
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from idatui._sync import wait_for # noqa: E402
+from idatui.app import IdaTui, ProjectPalette # noqa: E402
+from idatui.project import Project # noqa: E402
+from textual.widgets import Input, Static # noqa: E402
+
+PASS = FAIL = 0
+
+
+def check(name, cond, detail=""):
+ global PASS, FAIL
+ if cond:
+ PASS += 1
+ print(f" ok {name}")
+ else:
+ FAIL += 1
+ print(f" FAIL {name} {detail}")
+
+
+async def run(bins):
+ repo = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+ with tempfile.TemporaryDirectory() as tmp:
+ src = os.path.join(tmp, "src")
+ os.makedirs(src)
+ srcs = []
+ for b in bins:
+ dst = os.path.join(src, os.path.basename(b))
+ shutil.copy2(b, dst)
+ srcs.append(dst)
+ proj = Project.create(os.path.join(tmp, "proj.json"), srcs, name="proj")
+ proj.stage_all()
+ first, second = (r.label for r in proj.refs)
+
+ app = IdaTui(keepalive=False, project=proj)
+ async with app.run_test(size=(140, 44)) as pilot:
+ async def settle(pred, t=180.0):
+ return await wait_for(pred, pilot.pause, t, 0.05)
+
+ # -- boots on the project's first binary ----------------------- #
+ ok = await settle(lambda: app.program is not None
+ and app._func_index is not None
+ and app._func_index.complete)
+ check("project mode boots on the first binary", ok,
+ f"binary={app._binary}")
+ check("the active binary is the first one", app._binary == first,
+ f"{app._binary}")
+ n_first = len(app._func_index)
+ check("its functions loaded", n_first > 10, f"n={n_first}")
+ status = str(app.query_one("#status", Static).render())
+ check("the status line names the active binary",
+ f"[{first}]" in status, status[:60])
+
+ # -- the switcher lists the project ---------------------------- #
+ await pilot.press("ctrl+o")
+ opened = await settle(
+ lambda: isinstance(app.screen, ProjectPalette), 20)
+ check("Ctrl+O opens the binary switcher", opened,
+ f"screen={type(app.screen).__name__}")
+ if not opened:
+ return
+ pal = app.screen
+ check("the switcher lists every project binary",
+ len(pal._results) == 2, f"{[e['label'] for e in pal._results]}")
+ check("it marks which one is active",
+ any(e["active"] and e["label"] == first for e in pal._results))
+ check("it marks the other as not yet opened",
+ any(not e["resident"] and e["label"] == second
+ for e in pal._results))
+
+ # -- switch to the second binary -------------------------------- #
+ pal.query_one(Input).value = second
+ await pilot.pause(0.2)
+ await pilot.press("enter")
+ switched = await settle(
+ lambda: app._binary == second and app.program is not None
+ and app._func_index is not None and app._func_index.complete)
+ check("switching opens the other binary", switched,
+ f"binary={app._binary}")
+ check("the second binary has its own function index",
+ app._func_index is not None and len(app._func_index) > 5,
+ f"n={len(app._func_index) if app._func_index else 0}")
+ check("both binaries now have live workers",
+ sorted(app._pool.resident()) == sorted([first, second]),
+ f"{app._pool.resident()}")
+ landed = await settle(lambda: app._cur is not None, 60)
+ check("it lands somewhere in the new binary", landed,
+ f"cur={app._cur}")
+ where = app._cur.ea if app._cur else None
+
+ # -- switch back: resident, so state is restored ---------------- #
+ await pilot.press("ctrl+o")
+ reopened = await settle(
+ lambda: isinstance(app.screen, ProjectPalette), 20)
+ check("the switcher reopens after a switch", reopened,
+ f"screen={type(app.screen).__name__}")
+ if not reopened:
+ return
+ app.screen.query_one(Input).value = first
+ await pilot.pause(0.2)
+ await pilot.press("enter")
+ back = await settle(lambda: app._binary == first
+ and app._func_index is not None
+ and app._func_index.complete, 120)
+ check("switching back returns to the first binary", back,
+ f"binary={app._binary}")
+ check("its function index came back intact",
+ app._func_index is not None and len(app._func_index) == n_first,
+ f"n={len(app._func_index) if app._func_index else 0} want={n_first}")
+
+ # and forward again: the second binary's position was remembered
+ await pilot.press("ctrl+o")
+ if not await settle(lambda: isinstance(app.screen, ProjectPalette), 20):
+ check("returning to a binary restores where you were", False,
+ "switcher did not reopen")
+ return
+ app.screen.query_one(Input).value = second
+ await pilot.pause(0.2)
+ await pilot.press("enter")
+ again = await settle(lambda: app._binary == second
+ and app._cur is not None, 120)
+ check("returning to a binary restores where you were",
+ again and app._cur.ea == where,
+ f"cur={app._cur.ea if app._cur else None} want={where}")
+
+ # -- the promise: nothing was written next to the sources ---------- #
+ left = sorted(os.listdir(src))
+ check("the source tree stays pristine (no .i64/scratch beside it)",
+ left == sorted(os.path.basename(s) for s in srcs), f"{left}")
+ staged = sorted(os.listdir(proj.bin_dir))
+ check("IDA's artifacts all live in the project sidecar",
+ any(f.endswith(".i64") for f in staged), f"{staged}")
+
+ print(f"\n{PASS} passed, {FAIL} failed")
+ return 1 if FAIL else 0
+
+
+def main(argv):
+ repo = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+ bins = argv or [os.path.join(repo, "targets", "echo"),
+ os.path.join(repo, "targets", "cat")]
+ for b in bins:
+ if not os.path.isfile(b):
+ print(f"no such binary: {b}")
+ return 2
+ return asyncio.run(run(bins))
+
+
+if __name__ == "__main__":
+ raise SystemExit(main(sys.argv[1:]))