artifact presenter & global Agents updates & plan for nono profiles
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
MODULE_PATH = Path(__file__).parents[1] / "scripts" / "present.py"
|
||||
SPEC = importlib.util.spec_from_file_location("artifact_presenter_integration", MODULE_PATH)
|
||||
assert SPEC and SPEC.loader
|
||||
MODULE = importlib.util.module_from_spec(SPEC)
|
||||
sys.modules[SPEC.name] = MODULE
|
||||
SPEC.loader.exec_module(MODULE)
|
||||
|
||||
|
||||
@unittest.skipUnless(
|
||||
os.environ.get("HERDR_INTEGRATION_TESTS") == "1",
|
||||
"set HERDR_INTEGRATION_TESTS=1 inside a Herdr pane",
|
||||
)
|
||||
class ArtifactPresenterIntegrationTests(unittest.TestCase):
|
||||
def wait_for_mcat(self, herdr: str, pane_id: str, artifact: Path) -> None:
|
||||
for _attempt in range(100):
|
||||
state = MODULE.run_json(
|
||||
herdr,
|
||||
["pane", "process-info", "--pane", pane_id],
|
||||
subprocess.run,
|
||||
)
|
||||
processes = state["result"]["process_info"]["foreground_processes"]
|
||||
if any(
|
||||
process.get("name") == "mcat"
|
||||
and str(artifact) in process.get("argv", [])
|
||||
for process in processes
|
||||
):
|
||||
return
|
||||
time.sleep(0.05)
|
||||
self.fail(f"mcat did not open {artifact}")
|
||||
|
||||
def test_replaces_active_mcat_in_real_herdr_pane(self) -> None:
|
||||
herdr = shutil.which("herdr")
|
||||
mcat = shutil.which("mcat")
|
||||
source_pane = os.environ.get("HERDR_PANE_ID")
|
||||
if not all((herdr, mcat, source_pane)):
|
||||
self.skipTest("Herdr, mcat, and HERDR_PANE_ID are required")
|
||||
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
first = root / "first.md"
|
||||
second = root / "second.md"
|
||||
first.write_text(
|
||||
"# First artifact\n" + ("first viewer line " * 20 + "\n") * 1_000,
|
||||
encoding="utf-8",
|
||||
)
|
||||
second.write_text(
|
||||
"# Second artifact\n" + ("second viewer line " * 20 + "\n") * 1_000,
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
split = MODULE.run_json(
|
||||
herdr,
|
||||
[
|
||||
"pane",
|
||||
"split",
|
||||
"--pane",
|
||||
source_pane,
|
||||
"--direction",
|
||||
"right",
|
||||
"--cwd",
|
||||
directory,
|
||||
"--env",
|
||||
"PAGER=less",
|
||||
"--no-focus",
|
||||
],
|
||||
subprocess.run,
|
||||
)
|
||||
pane_id = MODULE.created_pane_id(split)
|
||||
try:
|
||||
MODULE.run_mcat(
|
||||
herdr,
|
||||
mcat,
|
||||
pane_id,
|
||||
first,
|
||||
subprocess.run,
|
||||
)
|
||||
self.wait_for_mcat(herdr, pane_id, first)
|
||||
|
||||
MODULE.run_mcat(
|
||||
herdr,
|
||||
mcat,
|
||||
pane_id,
|
||||
second,
|
||||
subprocess.run,
|
||||
reused=True,
|
||||
)
|
||||
self.wait_for_mcat(herdr, pane_id, second)
|
||||
finally:
|
||||
subprocess.run(
|
||||
[herdr, "pane", "send-keys", pane_id, "q"],
|
||||
check=False,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
subprocess.run(
|
||||
[herdr, "pane", "close", pane_id],
|
||||
check=False,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user