diff --git a/.github/workflows/wine11-experiment-source-retry-rdte.yml b/.github/workflows/wine11-experiment-source-retry-rdte.yml new file mode 100644 index 00000000..d0de57e6 --- /dev/null +++ b/.github/workflows/wine11-experiment-source-retry-rdte.yml @@ -0,0 +1,44 @@ +name: Wine11 inherited trace-path startup recovery controls +on: + push: + branches: + - rdte/wine11-experiment-source-retry-r1-20261123 + paths: + - docker/entrypoint.sh + - scripts/init/30-start-services.sh + - scripts/init/winepath-with-retry.sh + - tests/test_winepath_startup_retry.py + - .github/workflows/wine11-experiment-source-retry-rdte.yml + workflow_dispatch: +permissions: + contents: read +concurrency: + group: wine11-experiment-source-retry-r1 + cancel-in-progress: false +jobs: + offline-accepted-main-retry-contract: + runs-on: ubuntu-24.04 + timeout-minutes: 10 + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd + with: + persist-credentials: false + - name: Validate shell syntax and known-stage retry wiring + run: | + set -euo pipefail + bash -n docker/entrypoint.sh scripts/init/30-start-services.sh scripts/init/winepath-with-retry.sh + grep -Fq 'WINEBOT_STARTUP_ERROR stage=' docker/entrypoint.sh + grep -Fq 'WINEBOT_STARTUP_STAGE="services/trace-log-path"' scripts/init/30-start-services.sh + grep -Fq 'WINEBOT_STARTUP_STAGE="services/trace-script-path"' scripts/init/30-start-services.sh + grep -Fq '/scripts/init/winepath-with-retry.sh' scripts/init/30-start-services.sh + echo 'PASS: wine11_experiment_startup_wiring' + - name: Execute original fail-closed bounded retry suite + run: | + set -euo pipefail + python3 -m venv "$RUNNER_TEMP/wine11-venv" + "$RUNNER_TEMP/wine11-venv/bin/pip" install --disable-pip-version-check 'pytest==9.0.3' + "$RUNNER_TEMP/wine11-venv/bin/python" -m pytest -q tests/test_winepath_startup_retry.py + echo 'PASS: synthetic_trace_path_retry_controls' + - name: Scope + if: always() + run: echo 'Accepted-main source retry borrowed byte-exact; isolated fixture, no private artifacts, raw logs, policy bypass, production release or private Actions spend.' diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 44c5e16c..f2ba690c 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -41,6 +41,9 @@ if [ "$(id -u)" = "0" ]; then fi # --- USER CONTEXT (winebot) --- +# Accepted-main-style fixed-code startup failure classification; no values/secrets. +WINEBOT_STARTUP_STAGE="configuration" +trap 'startup_rc=$?; if [ "$startup_rc" -ne 0 ]; then printf "WINEBOT_STARTUP_ERROR stage=%s rc=%s\\n" "$WINEBOT_STARTUP_STAGE" "$startup_rc" >&2; fi' EXIT write_instance_state() { local state="$1" local reason="${2:-}" diff --git a/scripts/init/30-start-services.sh b/scripts/init/30-start-services.sh index 3ba7665d..c487033e 100755 --- a/scripts/init/30-start-services.sh +++ b/scripts/init/30-start-services.sh @@ -3,14 +3,18 @@ echo "--> Pass 4: Service Startup (WINEBOT_INPUT_TRACE_WINDOWS=${WINEBOT_INPUT_TRACE_WINDOWS:-unset})" +WINEBOT_STARTUP_STAGE="services/input-trace" # Post-Init Tracing (Ensures wineserver is stable) if [ "${WINEBOT_INPUT_TRACE_WINDOWS:-0}" = "1" ]; then echo "--> Post-Init Tracing: AHK hook enabled." sleep 2 WIN_TRACE_MS="${WINEBOT_INPUT_TRACE_WINDOWS_SAMPLE_MS:-5}" mkdir -p "$SESSION_DIR/logs" - WINE_LOG_PATH=$(winepath -w "$SESSION_DIR/logs/input_events_windows.jsonl") - WINE_SCRIPT_PATH=$(winepath -w /automation/core/input_trace_windows.ahk) + WINEBOT_STARTUP_STAGE="services/trace-log-path" + WINE_LOG_PATH="$(/scripts/init/winepath-with-retry.sh "$SESSION_DIR/logs/input_events_windows.jsonl")" + WINEBOT_STARTUP_STAGE="services/trace-script-path" + WINE_SCRIPT_PATH="$(/scripts/init/winepath-with-retry.sh /automation/core/input_trace_windows.ahk)" + WINEBOT_STARTUP_STAGE="services/trace-launch" echo "--> Starting Windows Input Trace..." ( TRACE_RESTART_WINDOW="${WINEBOT_TRACE_RESTART_WINDOW_SECONDS:-120}" diff --git a/scripts/init/winepath-with-retry.sh b/scripts/init/winepath-with-retry.sh new file mode 100755 index 00000000..7c309e59 --- /dev/null +++ b/scripts/init/winepath-with-retry.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# Convert one Linux path for Wine input tracing, retrying transient Wine startup. +# No fallback path and no sensitive Wine stderr are admitted to caller logs. +set -euo pipefail +if [ "$#" -ne 1 ] || [ -z "$1" ]; then + exit 2 +fi +for attempt in 1 2 3 4; do + translated="" + if translated="$(timeout 8s winepath -w "$1" 2>/dev/null)" && + [ -n "$translated" ] && + [[ "$translated" != *$'\n'* ]] && + [[ "$translated" != *$'\r'* ]]; then + printf '%s\n' "$translated" + exit 0 + fi + if [ "$attempt" -lt 4 ]; then sleep 1; fi +done +exit 1 diff --git a/tests/test_winepath_startup_retry.py b/tests/test_winepath_startup_retry.py new file mode 100644 index 00000000..1bf3d6ab --- /dev/null +++ b/tests/test_winepath_startup_retry.py @@ -0,0 +1,75 @@ +"""Fail-closed Wine trace-path retries without native Wine or private fixtures.""" + +import os +import subprocess +from pathlib import Path + +import pytest + +SCRIPT = Path("scripts/init/winepath-with-retry.sh") + + +@pytest.mark.parametrize( + ("mode", "expected_rc", "expected_count"), + [("recover", 0, 3), ("fail", 1, 4), ("multiline", 1, 4)], +) +def test_bounded_trace_path_retry( + tmp_path: Path, mode: str, expected_rc: int, expected_count: int +) -> None: + tool = tmp_path / "winepath" + tool.write_text( + "#!/bin/sh\n" + "set -eu\n" + 'count="$(cat "$WINEPATH_COUNTER" 2>/dev/null || printf 0)"\n' + 'count=$((count + 1))\n' + 'printf "%s" "$count" > "$WINEPATH_COUNTER"\n' + 'if [ "$WINEPATH_MODE" = recover ] && [ "$count" -ge 3 ]; then\n' + " printf 'Z:\\\\trace.jsonl\\n'\n" + " exit 0\n" + "fi\n" + 'if [ "$WINEPATH_MODE" = multiline ]; then\n' + " printf 'Z:\\\\trace.jsonl\\nSYNTHETIC_PRIVATE_MARKER\\n'\n" + " exit 0\n" + "fi\n" + "echo SYNTHETIC_PRIVATE_MARKER >&2\n" + "exit 1\n", + encoding="utf-8", + ) + tool.chmod(0o755) + sleep = tmp_path / "sleep" + sleep.write_text("#!/bin/sh\nexit 0\n", encoding="utf-8") + sleep.chmod(0o755) + counter = tmp_path / "counter" + env = os.environ.copy() + env.update( + PATH=f"{tmp_path}:{env['PATH']}", + WINEPATH_COUNTER=str(counter), + WINEPATH_MODE=mode, + ) + result = subprocess.run( + ["bash", str(SCRIPT), "/synthetic/trace.jsonl"], + env=env, + capture_output=True, + text=True, + timeout=45, + check=False, + ) + assert result.returncode == expected_rc + assert int(counter.read_text(encoding="utf-8")) == expected_count + assert "SYNTHETIC_PRIVATE_MARKER" not in result.stdout + result.stderr + if expected_rc == 0: + assert result.stdout == "Z:\\trace.jsonl\n" + else: + assert not result.stdout + + +def test_no_input_rejected_without_wine_process() -> None: + result = subprocess.run( + ["bash", str(SCRIPT)], + capture_output=True, + text=True, + timeout=5, + check=False, + ) + assert result.returncode == 2 + assert result.stdout == ""