mirror of
https://github.com/morluto/rea.git
synced 2026-11-10 08:47:00 +00:00
* fix(desktop): preserve document URLs and value formats * fix(desktop): bound added checks and omit noisy text guards * fix(desktop): exclude unseeded locks from task checks * fix(desktop): preserve draft bounds and launch URLs * fix(desktop): render draft values using their source format * fix(desktop): preserve launch URLs and JSON draft values * fix(desktop): recognize captured file URL documents * fix(desktop): render captured file URLs for runtime home * fix(desktop): distinguish phone numbers from save metadata * fix(desktop): preserve launch URLs and user text * fix(desktop): preserve captured URLs and user text * fix(desktop): preserve local file URL authority * fix(desktop): preserve local file URL authority * fix(desktop): preserve local file URL authority * fix(desktop): render captured file URLs at launch * fix(desktop): classify numeric timestamps using field context * fix(desktop): classify numeric timestamps using field context * fix(desktop): classify numeric timestamps using field context * fix(desktop): retain context for generated draft values * fix(desktop): retain context for generated draft values * fix(desktop): retain context for generated draft values * test(desktop): cover generated IDs in text guards * test(desktop): cover generated IDs in text guards * test(desktop): cover generated IDs in text guards * fix(desktop): isolate launcher URL encoding * fix(desktop): isolate launcher URL encoding * fix(desktop): isolate launcher URL encoding * fix(desktop): isolate launcher URL encoding * fix(desktop): retain clean text in noisy record fields * fix(desktop): classify added line values in one pass * fix(desktop): apply XML quote rules to text drafts * fix(desktop): distinguish XML attributes from quoted text * fix(desktop): preserve parsed XML line context * Format appTaskChecks.ts with the pinned oxfmt Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(desktop): retain partial XML syntax facts * fix(desktop): recognize markdown autolinks in drafts * fix(desktop): reuse export exclusions in task drafts * fix(desktop): report unchecked client build paths * docs(desktop): clarify gzip scrub limits * fix(desktop): reuse export exclusions in task drafts * docs(desktop): keep the judge command on one line Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(desktop): clarify gzip scrub limits * fix(setup): own desktop build process cleanup * fix(doctor): compare desktop settings with resolved defaults * style(desktop): format the noisy-record draft files with the pinned oxfmt Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(desktop): give the root-array draft test its own describe The records describe grew past the 150-line lint limit with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(doctor): inspect client-recorded desktop runners * fix(doctor): reuse matching runner probes * fix(setup): propagate cancellation to desktop actions * fix(setup): stop Hopper on cancel, never report a cancelled setup ready, and keep a failed action's client setting - The Hopper install gets setup's signal: Linux already honoured it, and the macOS installer now stops its downloads and stops before mounting or copying. - runSetup checks the signal after the final doctor and close, so a cancellation there raises instead of returning ready. - A failed pack or agentenv install no longer writes its archive or runner to client configs, so the setting the client already had stays. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(setup): keep the completed setup result in a cancellation after cleanup A cancellation during the final doctor or host close carried only the applied actions, dropping each client's result and backup path and the doctor report. It now carries the whole result as setup_result, as doctor's cancellation carries its report. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(desktop): move launch execution to boundary suite * fix(desktop): redact build schema failure output * refactor(desktop): normalize schema failure once * fix(desktop): omit unsafe schema parser snippets * fix(desktop): preserve draft change and selected path evidence * test(desktop): group retained dconf note regressions * fix(desktop): respect archive entry format in draft checks * test(desktop): separate unowned-file draft note cases * fix(desktop): preserve explicitly selected journal documents * fix(xml): avoid scanning selected ancestors per tag * fix(desktop): exclude covered text runs from draft counts * fix: preserve text when drafting desktop checks * fix: restore nested desktop state aliases * refactor: share UUID recognition across draft checks * fix: retain multiline XML attribute context * fix: retain relationship identifiers in task drafts * docs: clarify desktop draft identifier handling * test(desktop): type formatting run cases as pairs * fix(desktop): carry document format into selector evaluation * test(desktop): separate markup boundary regression group * fix(desktop): propagate formats through draft selectors * fix(desktop): switch selector format within archive entries * test(desktop): remove duplicate seed filename case * fix(setup): retain diagnostics when cancellation overlaps failure * refactor(setup): keep command cancellation at its owner * test(setup): verify cancellation at the application boundary * test(desktop): pass JSON format in exported index parity * docs(desktop): clarify task checks before scratch export * fix(desktop): respell selected paths in file URLs * test(desktop): group captured document spelling cases * test(desktop): pin reader-free verifier to selector parent * fix(desktop): bound draft preview serialization * fix(desktop): restore selected state aliases * fix(desktop): respect entry format in draft noise * test(desktop): match exported alias evidence at its JSON boundary * fix(desktop): retain app state logs in exported seeds * fix: align desktop numeric seed comparisons * test(desktop): keep one draft exclusion fixture import * test(desktop): retain log eligibility across draft test groups * fix(doctor): resolve empty registered desktop runner * test(desktop): check retained log seed admission * style: fix desktop launch test formatting * style: format native command path schema * fix(desktop): map selected external launch paths * style(desktop): format seed document regressions * test(desktop): group launch URL regressions * fix(desktop): omit redundant nested state aliases * fix(desktop): compare added free text as a whole * fix(desktop): check recompressed seeds as shipped * docs(desktop): clarify recovered seed format * test(desktop): group shipped gzip seed checks * fix: retain quoted identifier text in task drafts * fix: recognize Unicode XML in desktop state readers * fix(desktop): bound nested draft checks * fix(desktop): explain missing arrays in truncated views * fix(desktop): find XML type references in archives * test(desktop): remove duplicated capture assertions * fix(desktop): retain nested omitted text boundaries * style(desktop): format draft value imports * test(desktop): group model and draft value checks * fix(desktop): map captured launch paths once * refactor: remove unused whole-text guard state * refactor: stop passing unused text children * test: align free-text checks with whole-note policy * fix: validate recompressed desktop archive seeds * style(desktop): format archive seed regression * fix(desktop): retain placed-item sibling guards * fix(desktop): preserve archive paths and bound doctor reads * fix(doctor): refuse non-files before descriptor admission * fix(setup): track remaining cleanup resources across retries * test(desktop): specify XML format in heap pairing fixture * fix(desktop): compare screen task views by value * fix(desktop): reject inexact reader numbers * fix(desktop): budget export for both reader passes * fix(desktop): bound reader runner argument size * test(desktop): verify chunked reader payloads and parent output * fix(doctor): query agentenv for model endpoint * style(desktop): format reader payload assertion * fix(doctor): preserve uncertainty for empty endpoint override * fix(desktop): redact runtime schema errors * fix(desktop): normalize captured file URLs * fix(desktop): report seeded files by capture path * fix(desktop): retain startup readiness failure stage * fix(desktop): retain JSON date checks * fix(desktop): preserve archive formatting checks * fix(desktop): preserve explicitly selected journal files * fix(desktop): report build command transport limits * docs(desktop): clarify unreadable dconf versions * test(desktop): remove duplicate history regression * fix(desktop): align XML names with exported reader * fix(desktop): create selected state alias targets * fix(desktop): inspect supported runtime archives * fix(desktop): retain record identity in draft checks * fix(desktop): align timestamp selector digits * fix(desktop): scrub XML independently of reader compatibility * fix(desktop): preserve file aliases and reader diagnostics * fix(desktop): retain remote reader cleanup ownership * style(desktop): format capture review fixes * fix(desktop): retain reader leases across verifier reloads * test(desktop): overlap reader cleanup retries * fix(desktop): run long exports within exec limits --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
233 lines
10 KiB
Python
233 lines
10 KiB
Python
"""Exercise the capture controller's filesystem inventory boundary."""
|
|
|
|
import json
|
|
import io
|
|
from contextlib import redirect_stdout
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from bridge.agentenv import capture
|
|
|
|
|
|
CONTROLLER = Path(__file__).with_name("capture.py")
|
|
|
|
|
|
class CaptureListingTest(unittest.TestCase):
|
|
def run_listing(self, root, output):
|
|
return subprocess.run(
|
|
[
|
|
sys.executable,
|
|
str(CONTROLLER),
|
|
"list",
|
|
json.dumps({"root": str(root), "output": str(output)}),
|
|
],
|
|
text=True,
|
|
capture_output=True,
|
|
check=False,
|
|
)
|
|
|
|
def test_directory_symlink_is_disclosed_without_following_it(self):
|
|
with tempfile.TemporaryDirectory() as parent:
|
|
parent = Path(parent)
|
|
root = parent / "root"
|
|
target = parent / "target"
|
|
output = parent / "listing.json"
|
|
root.mkdir()
|
|
target.mkdir()
|
|
(root / "present.txt").write_text("present")
|
|
(target / "outside.txt").write_text("outside")
|
|
try:
|
|
(root / "linked").symlink_to(target, target_is_directory=True)
|
|
except OSError as error:
|
|
self.skipTest(f"directory symlinks unavailable: {error}")
|
|
result = self.run_listing(root, output)
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
listing = json.loads(output.read_text())
|
|
self.assertEqual(
|
|
[item["path"] for item in listing["files"]],
|
|
[os.path.relpath(root / "present.txt", Path.home())],
|
|
)
|
|
self.assertEqual(
|
|
listing["skipped"], [os.path.relpath(root / "linked", Path.home())]
|
|
)
|
|
|
|
def test_missing_root_does_not_produce_an_empty_successful_inventory(self):
|
|
with tempfile.TemporaryDirectory() as parent:
|
|
parent = Path(parent)
|
|
output = parent / "listing.json"
|
|
result = self.run_listing(parent / "missing", output)
|
|
self.assertNotEqual(result.returncode, 0)
|
|
self.assertFalse(output.exists())
|
|
|
|
|
|
@unittest.skipIf(sys.platform == "win32", "desktop build computers use Linux")
|
|
class LongRunTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tmp = tempfile.TemporaryDirectory()
|
|
self.addCleanup(self.tmp.cleanup)
|
|
self.root = Path(self.tmp.name)
|
|
self.bin = self.root / "bin"
|
|
self.bin.mkdir()
|
|
rea = self.bin / "rea"
|
|
rea.write_text(
|
|
f"#!{sys.executable}\n"
|
|
"import os, signal, subprocess, sys, time\n"
|
|
"signal.signal(signal.SIGINT, lambda *_: sys.exit(130))\n"
|
|
"if len(sys.argv) > 1 and sys.argv[1] == 'wait':\n"
|
|
" open(sys.argv[2], 'w').close()\n"
|
|
" time.sleep(30)\n"
|
|
"if len(sys.argv) > 1 and sys.argv[1] == 'ignore':\n"
|
|
" signal.signal(signal.SIGINT, signal.SIG_IGN)\n"
|
|
" open(sys.argv[2], 'w').close()\n"
|
|
" while not os.path.exists(sys.argv[3]): time.sleep(0.02)\n"
|
|
"if len(sys.argv) > 1 and sys.argv[1] == 'stderr':\n"
|
|
" sys.stderr.write('x' * 100000 + 'TAIL')\n"
|
|
"if len(sys.argv) > 1 and sys.argv[1] == 'hold':\n"
|
|
" subprocess.Popen([sys.executable, '-c', 'import os,sys,time\\nwhile not os.path.exists(sys.argv[1]): time.sleep(0.02)', sys.argv[2]], stdout=subprocess.DEVNULL, stderr=sys.stderr, start_new_session=True)\n"
|
|
" sys.exit(0)\n"
|
|
"print(os.environ.get('AGENTENV_CONTROL_TOKEN', 'no token'))\n"
|
|
)
|
|
rea.chmod(0o755)
|
|
self.environment = {**os.environ, "HOME": str(self.root), "PATH": f"{self.bin}{os.pathsep}{os.environ.get('PATH', '')}",
|
|
"AGENTENV_CONTROL_TOKEN": "not-for-the-child"}
|
|
self.job = self.root / "job"
|
|
self.output = self.root / "out.json"
|
|
|
|
def command(self, name, **values):
|
|
result = subprocess.run([sys.executable, str(CONTROLLER), name, json.dumps(values)],
|
|
env=self.environment, text=True, capture_output=True, timeout=10, check=True)
|
|
return json.loads(result.stdout)
|
|
|
|
def begin(self, argv, timeout=60):
|
|
return self.command("run-begin", job=str(self.job), work=str(self.root), stdout=str(self.output),
|
|
token="owner-token", argv=argv, files={}, timeout_s=timeout)
|
|
|
|
def test_runs_and_reports_its_output(self):
|
|
self.assertEqual(self.begin([]), {"started": True})
|
|
result = self.command("run-poll", job=str(self.job), token="owner-token", timeout_s=5)
|
|
self.assertEqual(result["exit_code"], 0)
|
|
self.assertEqual(self.output.read_text().strip(), "no token")
|
|
|
|
def test_passes_large_command_without_persisting_its_arguments(self):
|
|
self.assertEqual(self.begin(["done", *("x" * 4000 for _ in range(20))]), {"started": True})
|
|
result = self.command("run-poll", job=str(self.job), token="owner-token", timeout_s=5)
|
|
self.assertEqual(result["exit_code"], 0)
|
|
self.assertFalse((self.job / "request.json").exists())
|
|
|
|
def test_keeps_only_a_bounded_stderr_tail(self):
|
|
self.assertEqual(self.begin(["stderr"]), {"started": True})
|
|
result = self.command("run-poll", job=str(self.job), token="owner-token", timeout_s=5)
|
|
self.assertEqual(len(result["stderr"]), 4096)
|
|
self.assertTrue(result["stderr"].endswith("TAIL"))
|
|
|
|
def test_cancels_a_running_child_and_confirms_exit(self):
|
|
ready = self.root / "ready"
|
|
self.assertEqual(self.begin(["wait", str(ready)]), {"started": True})
|
|
import time
|
|
deadline = time.monotonic() + 5
|
|
while not ready.exists() and time.monotonic() < deadline:
|
|
time.sleep(0.02)
|
|
self.assertTrue(ready.exists())
|
|
result = self.command("run-cancel", job=str(self.job), token="owner-token", timeout_s=5)
|
|
self.assertTrue(result["cancelled"])
|
|
self.assertEqual(result["exit_code"], 130)
|
|
|
|
def test_cancel_before_late_start_claims_the_job(self):
|
|
self.assertEqual(self.command("run-cancel", job=str(self.job), token="owner-token", timeout_s=1), {"absent": True})
|
|
self.assertIn("already used", self.begin([])["refused"])
|
|
self.assertFalse(self.output.exists())
|
|
|
|
def test_cancel_refuses_a_folder_without_the_matching_owner(self):
|
|
self.job.mkdir()
|
|
(self.job / "owner").write_text("someone-else")
|
|
result = self.command("run-cancel", job=str(self.job), token="owner-token", timeout_s=1)
|
|
self.assertIn("ownership is not confirmed", result["error"])
|
|
self.assertFalse((self.job / "cancel").exists())
|
|
|
|
def test_reports_supervisor_output_if_completion_is_unconfirmed(self):
|
|
self.job.mkdir()
|
|
(self.job / "owner").write_text("owner-token")
|
|
(self.job / "supervisor.log").write_text("supervisor failed")
|
|
result = self.command("run-poll", job=str(self.job), token="owner-token", timeout_s=0)
|
|
self.assertEqual(result["progress"], "supervisor failed")
|
|
self.assertTrue(result["pending"])
|
|
|
|
def test_reports_a_timed_out_child_that_has_not_stopped(self):
|
|
ready, release = self.root / "ready", self.root / "release"
|
|
self.assertEqual(self.begin(["ignore", str(ready), str(release)], timeout=3), {"started": True})
|
|
try:
|
|
result = self.command("run-poll", job=str(self.job), token="owner-token", timeout_s=4)
|
|
self.assertTrue(result["pending"])
|
|
self.assertTrue(result["timed_out"])
|
|
self.assertTrue(ready.exists())
|
|
finally:
|
|
release.touch()
|
|
self.command("run-poll", job=str(self.job), token="owner-token", timeout_s=5)
|
|
|
|
def test_waits_for_an_inherited_stderr_pipe_after_the_child_exits(self):
|
|
release = self.root / "release"
|
|
self.assertEqual(self.begin(["hold", str(release)], timeout=3), {"started": True})
|
|
try:
|
|
result = self.command("run-poll", job=str(self.job), token="owner-token", timeout_s=4)
|
|
self.assertTrue(result["pending"])
|
|
self.assertTrue(result["timed_out"])
|
|
finally:
|
|
release.touch()
|
|
result = self.command("run-poll", job=str(self.job), token="owner-token", timeout_s=5)
|
|
self.assertTrue(result["finished"])
|
|
|
|
def test_failure_closing_supervisor_log_after_launch_does_not_claim_exit(self):
|
|
ready = self.root / "ready"
|
|
original_open = open
|
|
original_popen = subprocess.Popen
|
|
supervisors = []
|
|
|
|
class FailingClose:
|
|
def __init__(self, file):
|
|
self.file = file
|
|
|
|
def __enter__(self):
|
|
return self.file
|
|
|
|
def __exit__(self, *args):
|
|
self.file.close()
|
|
raise OSError("log close failed")
|
|
|
|
def opening(path, *args, **kwargs):
|
|
file = original_open(path, *args, **kwargs)
|
|
return FailingClose(file) if str(path).endswith("supervisor.log") else file
|
|
|
|
def spawning(*args, **kwargs):
|
|
process = original_popen(*args, **kwargs)
|
|
supervisors.append(process)
|
|
def cleanup():
|
|
if process.poll() is None:
|
|
(self.job / "cancel").touch()
|
|
process.wait(timeout=5)
|
|
self.addCleanup(cleanup)
|
|
return process
|
|
|
|
arguments = {"job": str(self.job), "work": str(self.root), "stdout": str(self.output),
|
|
"token": "owner-token", "argv": ["wait", str(ready)], "files": {}, "timeout_s": 60}
|
|
with patch.dict(os.environ, self.environment, clear=True), patch("builtins.open", side_effect=opening), patch.object(capture.subprocess, "Popen", side_effect=spawning), redirect_stdout(io.StringIO()) as output:
|
|
capture.run_begin(arguments)
|
|
self.assertIn("started but its setup did not finish", json.loads(output.getvalue())["error"])
|
|
import time
|
|
deadline = time.monotonic() + 5
|
|
while not ready.exists() and time.monotonic() < deadline:
|
|
time.sleep(0.02)
|
|
self.assertTrue(ready.exists())
|
|
self.assertFalse((self.job / "result.json").exists())
|
|
result = self.command("run-cancel", job=str(self.job), token="owner-token", timeout_s=5)
|
|
self.assertTrue(result["cancelled"])
|
|
supervisors[0].wait(timeout=5)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|