111 lines
2.9 KiB
Bash
Executable File
111 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SMOKE_VALUE="${1:-EmmaTest}"
|
|
WORKDIR="$(mktemp -d)"
|
|
HTML_PATH="$WORKDIR/form-smoke.html"
|
|
JSON_PATH="$WORKDIR/result.json"
|
|
PORT="$(python3 - <<'PY'
|
|
import socket
|
|
s = socket.socket()
|
|
s.bind(('127.0.0.1', 0))
|
|
print(s.getsockname()[1])
|
|
s.close()
|
|
PY
|
|
)"
|
|
SERVER_PID=""
|
|
|
|
cleanup() {
|
|
if [[ -n "$SERVER_PID" ]]; then
|
|
kill "$SERVER_PID" >/dev/null 2>&1 || true
|
|
wait "$SERVER_PID" 2>/dev/null || true
|
|
fi
|
|
rm -rf "$WORKDIR"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
cat > "$HTML_PATH" <<'HTML'
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<title>Hermes Ego Browser Form Smoke</title>
|
|
<style>
|
|
body { font-family: system-ui, sans-serif; margin: 2rem; }
|
|
label, input { display: block; margin-bottom: 0.75rem; }
|
|
input { width: 20rem; padding: 0.4rem; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>Hermes Ego Browser Form Smoke</h1>
|
|
<label for="message">Message</label>
|
|
<input id="message" name="message" type="text" value="" />
|
|
<p id="status">ready</p>
|
|
<script>
|
|
const input = document.querySelector('#message');
|
|
const status = document.querySelector('#status');
|
|
input.addEventListener('input', () => {
|
|
status.textContent = `value:${input.value}`;
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|
|
HTML
|
|
|
|
python3 -m http.server "$PORT" --bind 127.0.0.1 --directory "$WORKDIR" >/dev/null 2>&1 &
|
|
SERVER_PID=$!
|
|
|
|
python3 - <<PY
|
|
import sys, urllib.request
|
|
url = "http://127.0.0.1:${PORT}/form-smoke.html"
|
|
for _ in range(50):
|
|
try:
|
|
with urllib.request.urlopen(url, timeout=0.5) as r:
|
|
if r.status == 200:
|
|
sys.exit(0)
|
|
except Exception:
|
|
pass
|
|
import time
|
|
time.sleep(0.1)
|
|
sys.exit(1)
|
|
PY
|
|
|
|
SMOKE_URL="http://127.0.0.1:${PORT}/form-smoke.html"
|
|
SMOKE_URL_JSON="$(python3 -c 'import json,sys; print(json.dumps(sys.argv[1]))' "$SMOKE_URL")"
|
|
SMOKE_VALUE_JSON="$(python3 -c 'import json,sys; print(json.dumps(sys.argv[1]))' "$SMOKE_VALUE")"
|
|
JSON_PATH_JSON="$(python3 -c 'import json,sys; print(json.dumps(sys.argv[1]))' "$JSON_PATH")"
|
|
|
|
ego-browser nodejs <<EOF
|
|
import fs from 'node:fs'
|
|
|
|
const task = await useOrCreateTaskSpace('hermes ego-browser form smoke')
|
|
const url = $SMOKE_URL_JSON
|
|
const expected = $SMOKE_VALUE_JSON
|
|
const outputPath = $JSON_PATH_JSON
|
|
|
|
await openOrReuseTab(url, { wait: true, timeout: 20 })
|
|
await fillInput('#message', expected)
|
|
const value = await js("document.querySelector('#message').value")
|
|
const status = await js("document.querySelector('#status').textContent")
|
|
const info = await pageInfo()
|
|
|
|
const result = {
|
|
taskId: task.id,
|
|
title: info.title,
|
|
url: info.url,
|
|
value,
|
|
status,
|
|
}
|
|
|
|
fs.writeFileSync(outputPath, JSON.stringify(result, null, 2))
|
|
cliLog(JSON.stringify(result, null, 2))
|
|
EOF
|
|
|
|
ego-browser nodejs <<'EOF'
|
|
const task = await useOrCreateTaskSpace('hermes ego-browser form smoke')
|
|
await completeTaskSpace(task.id, { keep: false })
|
|
cliLog('done')
|
|
EOF
|
|
|
|
cat "$JSON_PATH"
|