fix: preserve cross-device evidence and render recorded reports

This commit is contained in:
chenmingxuan committed 2026-10-17 16:05:58 +08:00
1 parent a66803651a
commit 1440a1f508
28 files changed
+759 -128

No files matched your search

+41 -3
View File
@@ -49,9 +49,12 @@ class FakeRecorderProcess:
self.stdout.feed_eof()
self.stdin = SimpleNamespace(write=self._quit, drain=AsyncMock())
self.killed = False
self.commands = []
def _quit(self, _data):
self.returncode = 0
def _quit(self, data):
self.commands.append(data)
if data == b"q\n":
self.returncode = 0
async def wait(self):
return self.returncode
@@ -130,7 +133,10 @@ def test_small_window_is_not_upscaled_and_hwnd_capture_is_explicit(tmp_path):
tmp_path / "video.mp4",
"hevc_nvenc",
)
assert argument(command, "-i") == "hwnd=123"
assert argument(command, "--hwnd") == "123"
assert "artemis.plugins.window_capture" in command
assert argument(command, "-i") == "pipe:0"
assert "gdigrab" not in command and "desktop" not in command
assert argument(command, "-vf") == "scale=800:600"
assert argument(command, "-b:v") == "1000k"
assert argument(command, "-tag:v") == "hvc1"
@@ -362,6 +368,38 @@ async def test_resized_window_seals_old_geometry_before_new_capture(tmp_path, fa
assert all(track["status"] == "ready" for track in recorder.sources.values())
@pytest.mark.asyncio
async def test_window_worker_starts_only_after_process_ownership(
tmp_path, fake_capture, monkeypatch
):
def assign(_pid):
assert fake_capture.processes[-1].commands == []
monkeypatch.setattr(
recording, "CaptureProcessJob", lambda: SimpleNamespace(assign=assign, close=lambda: None)
)
recorder = PluginRecordings(context(tmp_path, computer_scope="window"))
try:
await recorder.observe("source", "visual-test", source())
assert fake_capture.processes[0].commands == [b"start\n"]
finally:
await recorder.stop()
assert fake_capture.processes[0].commands == [b"start\n", b"q\n"]
@pytest.mark.asyncio
async def test_capture_error_keeps_partial_clip_but_never_marks_ready(tmp_path, fake_capture):
recorder = PluginRecordings(context(tmp_path, computer_scope="window"))
await recorder.observe("source", "visual-test", source())
process, output, _, _ = next(iter(recorder.active.values()))
output.with_suffix(".log").write_text("capture stopped", encoding="utf-8")
process.returncode = 1
await recorder.stop()
track = next(iter(recorder.sources.values()))
assert track["status"] == "failed" and "capture stopped" in track["message"]
assert output.exists() and track["segments"][0]["duration_ms"] == 2500
@pytest.mark.asyncio
async def test_dead_worker_recovery_keeps_partial_clip_and_does_not_restart(
tmp_path, fake_capture, monkeypatch