Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/mvp-ic1-windows-workloads.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
basedir="$(dirname "$exe")/baseset"
mkdir -p "$basedir"
find "$work/gfx" -type f \( -iname '*.tar' -o -iname '*.obg' -o -iname '*.grf' \) \
-exec cp -n '{}' "$basedir" \;
-exec cp --update=none '{}' "$basedir" \;
test -n "$(find "$basedir" -type f -print -quit)" ||
{ echo 'MVP_WORKLOAD stage=gfx_missing'; exit 1; }
test -z "$(find apps/mvp-ic1 -type l -print -quit)" ||
Expand Down
9 changes: 9 additions & 0 deletions api/routers/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ async def _send_keys(
effective_backend = "xdotool" if _desktop_absent() else "ahk"

if effective_backend == "xdotool":
# A supplied but unresolved title must never silently become
# unscoped XTEST input to the currently focused application.
if window_title and not window_id:
return {
"ok": False,
"backend": "xdotool",
"error": "xdotool_target_unresolved",
"stderr": "",
}
cmd = ["xdotool"]
if window_id:
cmd.extend(["key", "--window", window_id, keys])
Expand Down
19 changes: 19 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,25 @@ Focus a specific window.
- **Body:** `{"window_id": "0x123456"}`
- **Response:** `{"status": "focused", "id": "..."}`

#### `POST /input/key`
Send keys through an authenticated, policy-admitted control session.

- Explicit `backend: "xdotool"` with a resolved `window_id` uses X11
directed synthetic events (XSendEvent); some applications ignore them.
A successful command/HTTP `status: "sent"` is dispatch acknowledgement,
**not** proof of application receipt or an application state change.
- Without a requested target, xdotool uses the active desktop focus (XTEST).
Use only when the caller intentionally controls the current focus, on an
isolated desktop with no concurrent human input. Verify the focus and an
application-level postcondition; do not automatically retry an ambiguous
dispatch or silently drop a requested target.
- A supplied title that cannot resolve to an X11 window on the xdotool path
fails with `xdotool_target_unresolved`; it must not send keys to the
current focus. The AHK title path remains distinct.
- The Wine 11 directed-key/save acceptance remains a release gate. An
alternate focused-mode result is a differential, not a waiver or proof
of atomic focus binding. Keep X11 window IDs distinct from native HWNDs.

#### `POST /input/mouse/click`
Click at specific coordinates.
- **Body:**
Expand Down
40 changes: 34 additions & 6 deletions scripts/ci/qualify-mvp-broker-real-keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def main() -> None:
if active.returncode:
fail("real_window_focus")

original_text = PROOF.read_text()

with ExitStack() as stack:
stack.enter_context(patch.dict(os.environ, {
"API_TOKEN": HEADER["X-API-Key"],
Expand All @@ -81,12 +83,33 @@ def main() -> None:
# Use the same in-process route harness as the proven HTTP unit tests.
# Entering TestClient lifespan would mutate unrelated real service state.
client = TestClient(app)
def key(keys: str):
return client.post(
"/input/key",
json={"keys": keys, "window_id": window, "backend": "xdotool"},
headers=HEADER,
)
def key(keys: str, *, targeted: bool = True):
payload = {"keys": keys, "backend": "xdotool"}
if targeted:
payload["window_id"] = window
return client.post("/input/key", json=payload, headers=HEADER)

def focused_differential() -> str:
# Diagnostic only: same real broker and editor, different X11
# delivery primitive. Never waive the original targeted failure.
# This is an isolated disposable desktop; focus checks are not an
# atomic target-binding guarantee for a shared production desktop.
for chord in ("ctrl+End", "y", "ctrl+s"):
observed = subprocess.run(
["xdotool", "getactivewindow"], capture_output=True,
text=True, timeout=5, check=False,
)
if observed.returncode or observed.stdout.strip() != window:
return "focused_xtest_focus_mismatch"
if key(chord, targeted=False).status_code != 200:
return "focused_xtest_dispatch_failed"
deadline = time.monotonic() + 15
while time.monotonic() < deadline:
# z may have been inserted but not saved by directed delivery.
if PROOF.read_text() in (original_text + "y", original_text + "zy"):
return "focused_xtest_pass"
time.sleep(0.25)
return "focused_xtest_save_failed"

if key("z").status_code != 423:
fail("unguarded_input")
Expand Down Expand Up @@ -115,6 +138,11 @@ def key(keys: str):
break
time.sleep(0.25)
else:
try:
outcome = focused_differential()
except Exception:
outcome = "focused_xtest_probe_error"
print("IC1_BROKER_DIFFERENTIAL=" + outcome, flush=True)
fail("real_wine_save_postcondition")
stopped = client.post(
"/sessions/ic1-broker-live/user_intent",
Expand Down
4 changes: 4 additions & 0 deletions scripts/ci/qualify-mvp-windows-workloads.sh
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ docker compose -f compose/layered.yml exec -T \
IC1_BROKER_CAUSE=*) printf '%s\n' "$cause" ;;
*) echo 'IC1_BROKER_CAUSE=unclassified' ;;
esac
differential="$(grep -Eo 'IC1_BROKER_DIFFERENTIAL=(focused_xtest_pass|focused_xtest_focus_mismatch|focused_xtest_dispatch_failed|focused_xtest_save_failed|focused_xtest_probe_error)' "$RUNNER_TEMP/ic1-broker-local.log" | tail -1 || true)"
case "$differential" in
IC1_BROKER_DIFFERENTIAL=*) printf '%s\n' "$differential" ;;
esac
fail broker_real_keyboard
}
grep -Fq 'IC1_BROKER=real_wine_keyboard_and_stop_pass' "$RUNNER_TEMP/ic1-broker-local.log" || fail broker_receipt_missing
Expand Down
35 changes: 35 additions & 0 deletions tests/test_input_keyboard_conformance.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,38 @@ def test_ahk_special_escaped(self):
assert "{^}" in _xdotool_to_ahk_keys("^")
assert "{!}" in _xdotool_to_ahk_keys("!")
assert "{#}" in _xdotool_to_ahk_keys("#")



@pytest.mark.parametrize("backend", ["xdotool", "auto"])
def test_unresolved_xdotool_title_never_dispatches_to_focus(backend):
"""A requested target that did not resolve is not permission for global input."""
import asyncio

from api.routers.input import _send_keys

with patch("api.routers.input._desktop_absent", return_value=True), patch(
"api.routers.input.run_async_command"
) as command:
result = asyncio.run(_send_keys("z", None, "missing", backend, "/tmp", 2))
assert result["ok"] is False
assert result["error"] == "xdotool_target_unresolved"
command.assert_not_called()


@pytest.mark.parametrize("window_id,expected", [
(None, ["xdotool", "key", "z"]),
("12345", ["xdotool", "key", "--window", "12345", "z"]),
])
def test_xdotool_delivery_mode_not_silently_changed(window_id, expected):
import asyncio

from api.routers.input import _send_keys

with patch("api.routers.input.run_async_command") as command:
command.return_value = {"ok": True}
result = asyncio.run(
_send_keys("z", window_id, None, "xdotool", "/tmp", 2)
)
assert result["ok"] is True
command.assert_awaited_once_with(expected, timeout=2)