fix: preserve exploration demonstration source and recording scope

This commit is contained in:
chenmingxuan committed 2026-10-18 23:20:50 +08:00
1 parent f4cb55c030
commit 973ccae679
22 files changed
+624 -55

No files matched your search

+79
View File
@@ -214,6 +214,85 @@ async def test_same_screen_reuses_recording_and_keeps_both_target_ids(tmp_path,
assert next(iter(recorder.sources.values()))["target_ids"] == ["window-1", "window-2"]
@pytest.mark.asyncio
async def test_manual_window_demo_follows_only_foreground_and_never_captures_two_screens(
tmp_path, fake_capture, monkeypatch
):
from artemis.exploration import demo_runtime
ctx = context(tmp_path, enabled=False, computer_scope="window")
ctx.plugins = SimpleNamespace(
packages={
"visual-test": (
SimpleNamespace(capabilities=SimpleNamespace(recording="windows")),
None,
None,
),
}
)
current = [source(screen={"left": -1920, "top": 0, "width": 4480, "height": 1440})]
scopes = []
def foreground(scope="screen"):
scopes.append(scope)
return current[0]
monkeypatch.setattr(demo_runtime, "desktop_source", foreground)
capture = demo_runtime.DemonstrationCapture(ctx, {"id": "demo", "source": "computer"})
try:
await capture.start()
assert capture.computer.config.computer_scope == "window"
assert argument(fake_capture.commands[0], "--hwnd") == "123"
await capture.refresh_computer()
assert len(fake_capture.commands) == 1
current[0] = source(window={"left": 1800, "top": 40, "width": 800, "height": 600})
await capture.refresh_computer()
assert len(fake_capture.commands) == 1
current[0] = source(target_id="456")
await capture.refresh_computer()
assert argument(fake_capture.commands[-1], "--hwnd") == "456"
assert fake_capture.processes[0].returncode == 0
assert len(capture.computer.active) == 1
# Desktop/no foreground window is a recording gap, never a reason to
# silently switch to capturing all monitors.
current[0] = None
await capture.refresh_computer()
assert not capture.computer.active
assert len(fake_capture.commands) == 2
current[0] = source(target_id="456")
await capture.refresh_computer()
assert len(capture.computer.active) == 1
assert len(fake_capture.commands) == 3
assert all(scope == "window" for scope in scopes)
assert all(
"gdigrab" not in command and "desktop" not in command
for command in fake_capture.commands
)
finally:
await capture.stop()
assert not capture.errors
assert len(capture.media) == 2
assert all(track["scope"] == "window" for track in capture.media)
assert all(process.returncode == 0 for process in fake_capture.processes)
assert ctx.agent_config.recording.computer_scope == "window"
@pytest.mark.asyncio
@pytest.mark.parametrize("exclusive", [False, True])
async def test_window_recording_exclusivity_does_not_change_normal_plugin_recordings(
tmp_path, fake_capture, exclusive
):
recorder = PluginRecordings(context(tmp_path, computer_scope="window"))
try:
await recorder.observe("first", "visual-test", source(), exclusive=exclusive)
await recorder.observe(
"second", "visual-test", source(target_id="456"), exclusive=exclusive
)
assert len(recorder.active) == (1 if exclusive else 2)
finally:
await recorder.stop()
@pytest.mark.asyncio
async def test_low_disk_space_records_failure_without_starting_capture(
tmp_path, fake_capture, monkeypatch