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
51 changes: 51 additions & 0 deletions .github/workflows/wine11-trusted-gate-stop-hil.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Wine 11 Trusted Gate STOP HIL

on:
pull_request:
paths:
- 'rdte/protected-control/wine_gate_hil_test.go'
- '.github/workflows/wine11-trusted-gate-stop-hil.yml'

permissions:
contents: read

jobs:
wine11-gate-stop:
runs-on: ubuntu-24.04
timeout-minutes: 40
env:
GO111MODULE: 'off'
GOTOOLCHAIN: local
DOCKER_BUILD_RECORD_UPLOAD: 'false'
steps:
- name: Checkout exact candidate
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
persist-credentials: false
ref: ${{ github.event.pull_request.head.sha }}
path: gate
- name: Checkout separately qualified WineHQ 11.0 package build definition
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
repository: SemperSupra/WineBot
persist-credentials: false
ref: 8c5ed8019a3518cf534b158662755172bfce7c59
path: runtime
- name: Build ephemeral package-pinned Wine image without publishing or cache upload
working-directory: runtime
shell: bash
run: |
set -euo pipefail
if ! docker build --target base-system -f docker/base.Dockerfile -t winebot-r046:local . >"$RUNNER_TEMP/wine-r046-build.log" 2>&1; then
echo 'WINE_GATE_HIL stage=base_build_failed'
exit 1
fi
echo 'WINE_GATE_HIL stage=base_built'
- name: Build exact Go test
working-directory: gate
run: go test -c -o "$RUNNER_TEMP/wine-gate.test" ./rdte/protected-control
- name: Run real Wine GUI and persistent STOP against disposable scope
run: sudo -n env WINEBOT_REAL_WINE_GATE=1 "$RUNNER_TEMP/wine-gate.test" -test.run '^TestWine11GateStopHIL$' -test.timeout=10m -test.v
- name: Remove raw build diagnostics
if: always()
run: rm -f "$RUNNER_TEMP/wine-r046-build.log"
176 changes: 176 additions & 0 deletions rdte/protected-control/wine_gate_hil_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
//go:build linux

package main

import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"testing"
"time"
)

// Real Wine workload bridge on disposable hosted Linux ONLY. Docker is an
// external effect authority; a successful start acknowledgement is not a
// distributed fencing proof. Never release or retry this generation.
func TestWine11GateStopHIL(t *testing.T){
if os.Getenv("WINEBOT_REAL_WINE_GATE")!="1"{t.Skip("dedicated disposable public HIL only")}
if os.Geteuid()!=0{t.Fatal("fixture requires root")}
ctx,cancel:=context.WithTimeout(context.Background(),8*time.Minute)
defer cancel()
call:=func(args ...string)(string,error){
b,err:=exec.CommandContext(ctx,args[0],args[1:]...).Output()
return strings.TrimSpace(string(b)),err
}
must:=func(stage string,args ...string)string{
t.Helper()
out,err:=call(args...)
if err!=nil{t.Fatalf("WINE_GATE_HIL stage=%s failed",stage)}
return out
}
root:=lifecycleTestRoot(t)
if err:=lifecycleProvision(root,0);err!=nil{t.Fatal("journal provisioning failed")}
name:="winebotr046"+strconv.Itoa(os.Getpid())
driver:=must("engine_driver","docker","info","--format","{{.CgroupDriver}}")
var scope,parent string
switch driver{
case "systemd":
parent=name+".slice"
unit:=filepath.Join("/run/systemd/system",parent)
if err:=os.WriteFile(unit,[]byte("[Unit]\nDescription=Disposable WineBot RDTE scope\n[Slice]\n"),0600);err!=nil{t.Fatal("scope unit creation failed")}
defer func(){
_=exec.Command("systemctl","stop",parent).Run()
_=os.Remove(unit)
_=exec.Command("systemctl","daemon-reload").Run()
}()
must("reload","systemctl","daemon-reload")
must("scope_start","systemctl","start",parent)
cg:=must("scope_path","systemctl","show","-p","ControlGroup","--value",parent)
if cg!="/"+parent{t.Fatal("unexpected disposable slice identity")}
scope=filepath.Join("/sys/fs/cgroup",cg)
case "cgroupfs":
scope=filepath.Join("/sys/fs/cgroup",name)
if err:=os.Mkdir(scope,0700);err!=nil{t.Fatal("scope creation failed")}
defer os.Remove(scope)
parent="/"+name
default:t.Fatal("unsupported engine cgroup driver")
}
dir,err:=os.Open(scope)
if err!=nil{t.Fatal("scope open failed")}
defer dir.Close()
id,err:=cgroupID(dir)
if err!=nil{t.Fatal("scope identity failed")}
image:=must("image_identity","docker","image","inspect","winebot-r046:local","--format","{{.Id}}")
if !strings.HasPrefix(image,"sha256:") || len(image)!=71{t.Fatal("invalid local image identity")}
g,err:=newWriterGate(root,0,0,dir,id)
if err!=nil{t.Fatal("scope reservation failed",err)}
e,err:=newEmergencyDispatch(g)
if err!=nil{t.Fatal(err)}
script:=`set -eu
export HOME=/home/winebot WINEPREFIX=/tmp/winebot-r046-prefix DISPLAY=:93 WINEARCH=win64
fail() { printf "WINE_GATE_HIL=FAIL_%s\n" "$1"; exit 1; }
export WINEDLLOVERRIDES=mscoree,mshtml=
test "$(id -u)" = 1000 || fail IDENTITY
test "$(dpkg-query -W -f='${Version}' winehq-stable)" = '11.0.0.0~trixie-1' || fail PACKAGE
wine --version | grep -Eq '^wine-11[.]0([[:space:]]|$)' || fail VERSION
echo WINE_GATE_HIL=VERSION_OK
Xvfb "$DISPLAY" -screen 0 1024x768x24 -noreset >/dev/null 2>&1 &
ready=0
for i in $(seq 1 40); do
if xdpyinfo -display "$DISPLAY" >/dev/null 2>&1; then ready=1; break; fi
sleep .25
done
test "$ready" = 1 || fail X11
echo WINE_GATE_HIL=X11_OK
mkdir -p "$WINEPREFIX" || fail PREFIX_DIRECTORY
test -w "$WINEPREFIX" || fail PREFIX_WRITABLE
timeout -k 5s 90s wineboot -i >/dev/null 2>&1 || fail WINEBOOT
echo WINE_GATE_HIL=BOOT_OK
timeout -k 5s 30s wineserver -w >/dev/null 2>&1 || fail SERVER_WAIT
test -s "$WINEPREFIX/system.reg" || fail REGISTRY
timeout -k 5s 15s wine cmd /c exit 0 >/dev/null 2>&1 || fail COMMAND
echo WINE_GATE_HIL=PREFIX_OK
wine notepad >/dev/null 2>&1 &
app=$!
ready=0
for i in $(seq 1 80); do
if xdotool search --onlyvisible --class notepad >/dev/null 2>&1; then ready=1; break; fi
kill -0 "$app" 2>/dev/null || fail NOTEPAD_EXIT
sleep .5
done
test "$ready" = 1 || fail WINDOW
echo WINE_GATE_HIL=WINDOW_OK
wait "$app" || fail NOTEPAD_WAIT
`
container:=must("create_fixture","docker","create","--name",name,"--cgroup-parent",parent,
"--network","none","--user","1000:1000","--cap-drop","ALL","--security-opt","no-new-privileges",
"--pids-limit","256","--memory","2g","--init","--entrypoint","/bin/sh",image,"-c",script)
if len(container)!=64{t.Fatal("invalid container identity")}
defer exec.Command("docker","rm","-f",container).Run()
if err=e.run(func(context.Context)error{
_,err:=call("docker","start",container)
return err
});err!=nil{t.Fatal("start effect unknown; no retry")}
pid:=must("container_pid","docker","inspect","--format","{{.State.Pid}}",container)
pidn,err:=strconv.Atoi(pid)
if err!=nil || pidn<=0{t.Fatal("invalid fixture process")}
membership,err:=os.ReadFile(fmt.Sprintf("/proc/%d/cgroup",pidn))
if err!=nil{t.Fatal("membership unavailable")}
rel:=strings.TrimPrefix(scope,"/sys/fs/cgroup")
matched:=false
for _,line:=range strings.Split(string(membership),"\n"){
if line=="0::"+rel || strings.HasPrefix(line,"0::"+rel+"/"){matched=true}
}
if !matched{t.Fatal("engine process outside admitted scope")}
// Emit only exact allowlisted synthetic receipts; never print raw logs.
stages:=map[string]bool{}
allowed:=[]string{"VERSION_OK","X11_OK","BOOT_OK","PREFIX_OK","WINDOW_OK",
"FAIL_IDENTITY","FAIL_PACKAGE","FAIL_VERSION","FAIL_X11","FAIL_PREFIX_DIRECTORY",
"FAIL_PREFIX_WRITABLE","FAIL_WINEBOOT","FAIL_SERVER_WAIT","FAIL_REGISTRY",
"FAIL_COMMAND","FAIL_NOTEPAD_EXIT","FAIL_WINDOW","FAIL_NOTEPAD_WAIT"}
observeStages:=func(){
out,err:=call("docker","logs","--tail","100",container)
if err!=nil{return}
for _,line:=range strings.Split(out,"\n"){
for _,stage:=range allowed{
if line=="WINE_GATE_HIL="+stage && !stages[stage]{
stages[stage]=true
t.Log("WINE_GATE_HIL receipt="+stage)
}
}
}
}
deadline:=time.Now().Add(260*time.Second)
for {
observeStages()
if stages["VERSION_OK"] && stages["PREFIX_OK"] && stages["WINDOW_OK"]{break}
if time.Now().After(deadline){t.Fatal("Wine11 prefix/window qualification failed")}
if must("running","docker","inspect","--format","{{.State.Running}}",container)!="true"{
observeStages()
t.Fatal("fixture exited before readiness; see allowlisted stage receipts")
}
time.Sleep(time.Second)
}
if p,err:=cgroupPopulated(dir,id);err!=nil || !p{t.Fatal("live Wine scope not observed")}
t.Log("WINE_GATE_HIL stage=wine11_window_ready_in_admitted_scope")
if _,err=e.requestPersistentStop();err!=nil{t.Fatal("durable STOP failed",err)}
must("stop_fixture","docker","stop","--time","5",container)
if must("stopped","docker","inspect","--format","{{.State.Running}}",container)!="false"{t.Fatal("engine termination unconfirmed")}
deadline=time.Now().Add(10*time.Second)
for{
p,err:=cgroupPopulated(dir,id)
if err!=nil{t.Fatal("scope observation unavailable")}
if !p{break}
if time.Now().After(deadline){t.Fatal("scope still populated")}
time.Sleep(100*time.Millisecond)
}
if err=g.stopAndReconcile();err==nil{t.Fatal("STOP allowed automatic release")}
if _,err=reserveWriterGate(root,0,g.generation,func()(bool,error){return false,nil});err==nil{t.Fatal("replacement writer admitted")}
s,err:=lifecycleRead(root,0)
if err!=nil || s.Phase!="QUARANTINED"{t.Fatal("quarantine missing")}
t.Log("WINE_GATE_HIL stage=terminated_empty_but_quarantined")
}