Detach graph viewer from MCP transport
This commit is contained in:
parent
5e77cd2adb
commit
f6b9816ffd
10 changed files with 369 additions and 22 deletions
|
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
import json
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import unittest
|
||||
|
|
@ -270,6 +271,46 @@ if (nodePalette("child", 2).fill === nodePalette("child", 1).fill) fail("hop sha
|
|||
finally:
|
||||
runner.stop()
|
||||
|
||||
def test_detached_worker_survives_the_launching_transport_process(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = self.copy_fixture("alpha", Path(directory))
|
||||
ProjectIndex(Project.open(root)).build()
|
||||
script = """
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from docforge.index import ProjectIndex
|
||||
from docforge.project import Project
|
||||
from docforge.visualization import DetachedVisualizationRunner
|
||||
|
||||
runner = DetachedVisualizationRunner(
|
||||
ProjectIndex(Project.open(Path(sys.argv[1]))),
|
||||
initial_grace_seconds=1.0,
|
||||
lease_seconds=0.3,
|
||||
monitor_interval_seconds=0.02,
|
||||
)
|
||||
print(runner.start()["url"], flush=True)
|
||||
time.sleep(60)
|
||||
"""
|
||||
script = "import time\n" + script
|
||||
with subprocess.Popen(
|
||||
[sys.executable, "-c", script, str(root)],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
) as launcher:
|
||||
assert launcher.stdout is not None
|
||||
url = launcher.stdout.readline().strip()
|
||||
launcher.terminate()
|
||||
launcher.wait(timeout=2)
|
||||
self.assertLess(launcher.returncode, 0)
|
||||
self.assertTrue(url.startswith("http://127.0.0.1:"))
|
||||
with urllib.request.urlopen(url, timeout=2) as response:
|
||||
self.assertEqual(200, response.status)
|
||||
|
||||
time.sleep(0.6)
|
||||
with self.assertRaises(OSError):
|
||||
urllib.request.urlopen(url, timeout=0.2)
|
||||
|
||||
def test_runner_rejects_ambiguous_targets_and_changed_index_snapshot(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = self.copy_fixture("alpha", Path(directory))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue