Files
hx/tests/tui_lspinstall.py
johannesandClaude Sonnet 5.5 a94632ea3d chore: delete code comments, add ratchet lint and ADRs
Classify every comment as tautology, stale, excuse or decision record.
Tautology/stale/excuse comments are deleted (excuses filed as issues
#196-#236), decisions moved to docs/adr/0001-0034.

- scripts/lint-comments.sh + .comment-baseline: per-file comment count
  may only go down; wired into tests/all.sh
- .claude/skills/delete-comment: repeatable audit workflow
- cargo fmt applied to touched crates

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-21 13:37:32 +01:00

73 lines
2.3 KiB
Python

"""lsp install prompt in the TUI: missing server -> [y/n] -> y runs the installer."""
import os, pty, sys, time, subprocess, select, re, json, tempfile, signal
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
port = 20000 + os.getpid() % 20000
srv = subprocess.Popen([sys.executable, f"{root}/tests/fake_lspinstall.py", str(port)])
tmp = tempfile.mkdtemp()
os.makedirs(f"{tmp}/home/.hx"); os.makedirs(f"{tmp}/repo")
open(f"{tmp}/home/.hx/auth.json", "w").write(json.dumps({"claude": {"access": "fake-token", "refresh": "r", "expires": 99999999999999}}))
open(f"{tmp}/repo/a.zz", "w").write("")
binp = f"{tmp}/bin/fake-ls"
open(f"{tmp}/home/.hx/config.toml", "w").write(f"""[lsp]
tests = "off"
[[lsp.servers]]
id = "fakels"
language = "zz"
extensions = ["zz"]
command = ["{binp}"]
roots = []
install = ["sh", "-c", "mkdir -p {tmp}/bin && touch {binp} && chmod +x {binp}"]
""")
time.sleep(0.5)
pid, fd = pty.fork()
if pid == 0:
os.chdir(f"{tmp}/repo")
os.environ.update(HOME=f"{tmp}/home", HX_BASE_URL=f"http://127.0.0.1:{port}", TERM="xterm-256color", COLUMNS="100", LINES="30")
os.execv(f"{root}/target/debug/hx", ["hx"])
import fcntl, termios, struct
fcntl.ioctl(fd, termios.TIOCSWINSZ, struct.pack("HHHH", 30, 100, 0, 0))
buf = b""
def pump(t):
global buf
end = time.time() + t
while time.time() < end:
r, _, _ = select.select([fd], [], [], 0.05)
if r:
try:
buf += os.read(fd, 65536)
except OSError:
return
def plain():
s = buf.decode(errors="replace")
s = re.sub(r"\x1b\[[0-9;?]*[A-Za-z]", " ", s)
return re.sub(r"\x1b[()][A-Z0-9]|\x1b[=>]", "", s)
def send(b, t=0.6):
os.write(fd, b); pump(t)
ok = True
def check(label, needle):
global ok
hit = needle in plain()
ok &= hit
print(f"{'PASS' if hit else 'FAIL'} {label}: {needle!r}")
pump(1.5)
send(b"go\r", 3)
check("question in footer", "[y/n] fakels is not")
check("installer shown", "Run `sh -c mkdir")
send(b"y", 3)
check("answer logged", " yes")
check("installed", "") if os.path.exists(binp) else (print("FAIL installer did not run"), globals().update(ok=False))
send(b"\x03", 1)
try:
_, st = os.waitpid(pid, 0)
print("exit status", st)
except ChildProcessError:
pass
check("exit summary", "session")
srv.kill()
sys.exit(0 if ok else 1)