65 lines
2.0 KiB
Python
65 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Confirms joe_wrapper.py's os.execv actually works, not just decide()'s
|
|
pure logic: point it at a plain, non-hd-managed file and verify real JOE
|
|
opens it, edits happen, and the save on disk is a normal, ordinary local
|
|
save -- no HedgeDoc connection attempted at all for this case.
|
|
"""
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import pexpect
|
|
|
|
JOE_BIN = os.environ.get("JOE_BIN", "/home/claude/work/repo/joe-patch/build/joe-4.8/joe/joe")
|
|
WRAPPER = str(Path(__file__).resolve().parent / "joe_wrapper.py")
|
|
|
|
|
|
def main():
|
|
tmpdir = Path(tempfile.mkdtemp(prefix="joe-wrapper-exec-test-"))
|
|
scratch = tmpdir / "scratch.txt"
|
|
scratch.write_text("original content\n")
|
|
|
|
ok = True
|
|
try:
|
|
# joe_wrapper.py's DEFAULT_REAL_JOE computes the same build path as
|
|
# JOE_BIN's default above; run the wrapper directly, exactly as the
|
|
# generated install.sh wrapper would exec it via the venv's python3.
|
|
env = {**os.environ, "TERM": "xterm"}
|
|
cmd = f"python3 {WRAPPER} {scratch}"
|
|
child = pexpect.spawn(cmd, cwd=str(tmpdir), env=env, dimensions=(24, 80), timeout=10)
|
|
time.sleep(0.8)
|
|
|
|
child.send("\x0bv") # Ctrl-K V: go to EOF
|
|
time.sleep(0.3)
|
|
child.send("added by real joe via the wrapper")
|
|
time.sleep(0.4)
|
|
|
|
child.send("\x0bx") # Ctrl-K X: save and exit
|
|
time.sleep(0.4)
|
|
child.send("\r")
|
|
try:
|
|
child.wait()
|
|
except pexpect.TIMEOUT:
|
|
pass
|
|
if child.isalive():
|
|
child.terminate(force=True)
|
|
time.sleep(0.3)
|
|
|
|
final = scratch.read_text()
|
|
print("final file content:", repr(final))
|
|
ok &= "original content" in final
|
|
ok &= "added by real joe via the wrapper" in final
|
|
|
|
finally:
|
|
import shutil
|
|
shutil.rmtree(tmpdir, ignore_errors=True)
|
|
|
|
print("\nPASS" if ok else "\nFAIL")
|
|
return 0 if ok else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|