Compare commits

...
7 changed files with 295 additions and 3 deletions

No files matched your search

+89
View File
@@ -0,0 +1,89 @@
# windows-flakes-hunt.yml - hunt scaffolding, never merged. Runs only on a push to a `hunt/windows-flakes**` branch.
# The networkidle round on /x0 left on its own page once (main e2e 43425218633, part 3): ours against stock Playwright Firefox, four at once, x5.
name: windows flakes hunt
on:
push:
branches: ['hunt/windows-flakes**']
permissions:
contents: read
concurrency:
group: windows-flakes-hunt-${{ github.ref }}
cancel-in-progress: true
env:
GITHUB_TOKEN: ${{ github.token }}
jobs:
hunt:
name: flakes hunt ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 120
strategy:
max-parallel: 1
fail-fast: false
matrix:
os: [windows-2022, ubuntu-24.04]
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with: { python-version: '3.11' }
- name: Install
run: |
set -e
python -m pip install --quiet --upgrade pip
python -m pip install --quiet ".[dev]"
python -m pip install --quiet "playwright==$(cat scripts/playwright_pin.txt)"
echo "FF=$(cd "$RUNNER_TEMP" && python -m invisible_playwright fetch | tail -1)" >> "$GITHUB_ENV"
python scripts/ci_lab_geoip.py build
if [ "$RUNNER_OS" = "Linux" ]; then python -m playwright install --with-deps firefox; else python -m playwright install firefox; fi
- name: Typing per key, ours and stock, alone x20 and four at once x20
env:
PYTHONUNBUFFERED: "1"
run: |
set +e
mkdir -p evidence
for engine in ours stock; do
for n in 1 2 3 4; do python -u scripts/hunt_typing.py $engine "$FF" >> "evidence/alone_$engine.log" 2>&1; done
for c in 1 2 3 4; do python -u scripts/hunt_typing.py $engine "$FF" > "evidence/loaded_${engine}_$c.log" 2>&1 & done
wait
done
{
echo "## typing slip per key ($RUNNER_OS): ms after the plan at the last key, and page minus sent per key"
echo '```'
for set in alone_ours alone_stock loaded_ours loaded_stock; do
cat evidence/${set}*.log | grep -a "^HUNT-TYPING" | sed 's/^HUNT-TYPING //' | python -c "
import json,sys,statistics as s
r=[json.loads(l) for l in sys.stdin]
end=sorted(x['page_ms'][-1]-x['planned_ms'][-1] for x in r if len(x['page_ms'])==len(x['planned_ms']))
snd=sorted(x['sent_ms'][-1]-x['planned_ms'][-1] for x in r if len(x['sent_ms'])==len(x['planned_ms']))
per=[]
[per.extend((p-q) for p,q in zip(x['page_ms'],x['sent_ms'])) for x in r]
per.sort()
q=lambda v,f: v[min(len(v)-1,int(len(v)*f))] if v else None
print(sys.argv[1], 'runs', len(r), '| page slip at last key p50', q(end,.5), 'p95', q(end,.95), 'max', end[-1] if end else None,
'| sent slip p50', q(snd,.5), 'max', snd[-1] if snd else None, '| page-sent per key p50', q(per,.5), 'p95', q(per,.95))
" $set
done
grep -ahE "Traceback|Error" evidence/*.log | sort | uniq -c | head
echo '```'
} | tee -a "$GITHUB_STEP_SUMMARY"
- name: Close every Firefox left
if: always()
shell: pwsh
run: |
Get-Process firefox -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
"left: " + @(Get-Process firefox -ErrorAction SilentlyContinue).Count
- name: Upload the evidence
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: windows-flakes-${{ github.run_id }}
path: evidence
if-no-files-found: warn
retention-days: 14
+76
View File
@@ -0,0 +1,76 @@
"""HUNT SCAFFOLDING, NEVER MERGED: goto(networkidle) on pages that replace themselves after load, ours against stock Playwright Firefox.
Usage: python scripts/hunt_netidle.py ours|stock [binary]. Prints one JSON line per round: the URL when goto returned, how long goto took, and
when the server saw the request of /landed relative to goto's return (negative = the replacement was already on the wire when goto said idle).
"""
import http.server
import json
import sys
import threading
import time
ENGINE = sys.argv[1]
REQS = []
def _page(ms, cross):
target = "location.origin.replace('127.0.0.1','localhost')+'/landed'" if cross else "'/landed'"
return ("<!doctype html><html><body><p id=p>first</p><script>addEventListener('load', () => setTimeout(() => "
"location.replace(%s), %d))</script></body></html>" % (target, ms)).encode()
PAGES = {"/landed": b"<!doctype html><html><body><p id=p>landed</p></body></html>"}
for ms in (0, 50):
PAGES["/r%d" % ms] = _page(ms, False)
PAGES["/x%d" % ms] = _page(ms, True)
class H(http.server.BaseHTTPRequestHandler):
def do_GET(self):
REQS.append((time.monotonic(), self.path))
body = PAGES.get(self.path.split("?")[0], PAGES["/landed"])
self.send_response(200)
self.send_header("Content-Type", "text/html; charset=utf-8")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, *a):
pass
srv = http.server.ThreadingHTTPServer(("127.0.0.1", 0), H)
srv.daemon_threads = True
threading.Thread(target=srv.serve_forever, daemon=True).start()
site = "http://127.0.0.1:%d" % srv.server_address[1]
def rounds(page, Error):
for path in ("/r0", "/r50", "/x0", "/x50"):
for i in range(5):
t0 = time.monotonic()
err = None
try:
page.goto("%s%s?n=%d" % (site, path, i), wait_until="networkidle", timeout=15000)
except Error as e:
err = str(e).splitlines()[0][:100]
t1 = time.monotonic()
url = page.url
landed = [t for t, p in REQS if p.startswith("/landed") and t >= t0]
print("HUNT-ROW " + json.dumps({
"engine": ENGINE, "path": path, "round": i, "landed_at_return": url.endswith("/landed"), "goto_ms": round((t1 - t0) * 1000),
"landed_request_ms_from_return": round((landed[0] - t1) * 1000) if landed else None, "error": err}), flush=True)
if ENGINE == "stock":
from playwright.sync_api import sync_playwright, Error
with sync_playwright() as p:
b = p.firefox.launch(headless=True)
rounds(b.new_page(), Error)
b.close()
else:
from invisible_playwright import InvisiblePlaywright
from invisible_playwright.sync_api import Error
with InvisiblePlaywright(seed=4321, binary_path=sys.argv[2], headless=True) as browser:
rounds(browser.new_page(), Error)
srv.shutdown()
+97
View File
@@ -0,0 +1,97 @@
"""HUNT SCAFFOLDING, NEVER MERGED: one typed address, three times per key: planned, sent (before the keydown command), seen by the page.
Usage: python scripts/hunt_typing.py ours|stock [binary]. Both type the same plan (persona of seed 2, typing nonce 1, the plan the core's
keyboard draws for a session's first field): ours through press_sequentially (the core keyboard), stock as down / sleep(dwell) / up /
sleep(gap) through stock Playwright's keyboard. One JSON line per run with the three series in wall-clock milliseconds.
"""
import http.server
import json
import sys
import threading
import time
from invisible_core.juggler._behaviour import TypingPersona, plan_typing
ENGINE = sys.argv[1]
TEXT = "someone@example.com"
PLAN = plan_typing(TEXT, TypingPersona.from_seed(2), nonce=1)
SENT = []
PAGE = (b"<!doctype html><html><body><input id=f><script>window.__k=[];document.addEventListener('keydown',"
b"e=>__k.push([e.key, performance.timeOrigin + performance.now()]),true);</script></body></html>")
class H(http.server.BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-Type", "text/html")
self.send_header("Content-Length", str(len(PAGE)))
self.end_headers()
self.wfile.write(PAGE)
def log_message(self, *a):
pass
srv = http.server.ThreadingHTTPServer(("127.0.0.1", 0), H)
srv.daemon_threads = True
threading.Thread(target=srv.serve_forever, daemon=True).start()
url = "http://127.0.0.1:%d/" % srv.server_address[1]
def report(page, t_start):
keys = page.evaluate("__k")
planned, t = [], 0.0
for dwell, gap in PLAN:
planned.append(round(t))
t += dwell + gap
print("HUNT-TYPING " + json.dumps({
"engine": ENGINE, "planned_ms": planned,
"sent_ms": [round(x * 1000 - SENT[0] * 1000) for x in SENT if True],
"page_ms": [round(v - keys[0][1]) for k, v in keys if k != "Shift"],
"page_keys": [k for k, v in keys], "send_offset_ms": round((SENT[0] - t_start) * 1000) if SENT else None,
}), flush=True)
if ENGINE == "stock":
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
b = p.firefox.launch(headless=True)
page = b.new_page()
for _ in range(5):
SENT.clear()
page.goto(url)
page.click("#f")
t_start = time.time()
for (dwell, gap), ch in zip(PLAN, TEXT):
SENT.append(time.time())
if ch == "@":
page.keyboard.down("Shift")
page.keyboard.down(ch)
time.sleep(dwell / 1000)
page.keyboard.up(ch)
if ch == "@":
page.keyboard.up("Shift")
time.sleep(gap / 1000)
report(page, t_start)
b.close()
else:
from invisible_core.juggler import keyboard as kb
real_down = kb.Keyboard.down
def down(self, key, *a, **k):
if key != "Shift":
SENT.append(time.time())
return real_down(self, key, *a, **k)
kb.Keyboard.down = down
from invisible_playwright import InvisiblePlaywright
for _ in range(5):
# a fresh browser per run: the plan is the one of the session's first field (typing nonce 1)
with InvisiblePlaywright(seed=2, binary_path=sys.argv[2], headless=True) as browser:
SENT.clear()
page = browser.new_page()
page.goto(url)
t_start = time.time()
page.locator("#f").press_sequentially(TEXT)
report(page, t_start)
srv.shutdown()
+16 -1
View File
@@ -348,6 +348,21 @@ def test_a_store_that_answers_the_focus_does_not_eat_the_text(firefox_binary, st
took = time.monotonic() - started
value = page.input_value("#store")
events = page.evaluate("__events")
_keys = [round(t) for k, t in events if k == "keydown"]
import json as _hj, os as _ho
if _ho.environ.get("HUNT_OUT"):
_plan = plan_typing(TEXT, TypingPersona.from_seed(seed), nonce=1)
_plan_span = sum(a + b for a, b in _plan[:-1])
_focus_all = [round(t) for k, t in events if k == "focus"]
with open(_ho.environ["HUNT_OUT"], "a") as _hf:
print(_hj.dumps({"how": how, "took": round(took, 3), "pause": round(pause, 3), "plan_span_ms": round(_plan_span),
"key_span_ms": (_keys[-1] - _keys[0]) if _keys else None, "keys": len(_keys),
"focus": _focus_all, "first_key": _keys[0] if _keys else None,
"last_focus_to_first_key_ms": (_keys[0] - _focus_all[-1]) if _keys and _focus_all else None}), file=_hf)
_focus = [round(t) for k, t in events if k == "focus"]
print("HUNT-TYPE how=%s took=%.2f pause=%.3f bound=%.2f focus=%r key_gaps=%r" % (
how, took, pause, 2 * pause + ANSWER_MS / 1000 + 0.4 * len(TEXT), _focus,
[b - a for a, b in zip(([_focus[0]] if _focus else []) + _keys, _keys)]), flush=True)
assert value == TEXT, "the field holds %r after %s" % (value, how)
focus = next(t for k, t in events if k == "focus")
first = next(t for k, t in events if k == "keydown")
@@ -357,4 +372,4 @@ def test_a_store_that_answers_the_focus_does_not_eat_the_text(firefox_binary, st
# The pause is a pause, not a stall: one hesitation (restarted once, by
# the store's write) on top of the typing itself.
assert took < 2 * pause + ANSWER_MS / 1000 + 0.4 * len(TEXT), (
"%s took %.1f s" % (how, took))
"%s took %.1f s HUNT pause=%.3f focus=%r keys=%r" % (how, took, pause, _focus, _keys))
+8
View File
@@ -161,6 +161,14 @@ def test_networkidle_is_reached_on_the_page_that_replaced_ours(page, site, path)
for i in range(ROUNDS):
_goto(page, "%s%s?n=%d" % (site, path, i), wait_until="networkidle",
timeout=15_000)
if not page.url.endswith("/landed"):
u1 = page.url
try:
href = page.evaluate("location.href")
except Exception as e:
href = "ERR " + str(e)[:120]
time.sleep(2)
print("HUNT-NETIDLE round=%d url=%s href=%s url_after_2s=%s" % (i, u1, href, page.url), flush=True)
assert page.url.endswith("/landed"), page.url
@@ -78,8 +78,11 @@ def page(firefox_binary):
def test_reads_after_the_isolated_page_answer(page, site):
for i in range(ROUNDS):
page.goto("%s/isolated?i=%d" % (site, i), wait_until="domcontentloaded")
assert page.evaluate("self.crossOriginIsolated") is True, (
"the engine did not isolate the page: this round tests nothing")
_h = page.evaluate("({coi: self.crossOriginIsolated, path: location.pathname, now: performance.now(), "
"load: performance.getEntriesByType('navigation')[0]?.loadEventEnd})")
print("HUNT-ISOLATED round=%d %r" % (i, _h), flush=True)
assert _h["coi"] is True, (
"the engine did not isolate the page: this round tests nothing HUNT %r" % (_h,))
# The read on the isolated page is what builds the script that went
# stale; without it the bug never showed.
assert page.locator("#p").inner_text(timeout=10_000) in ("isolated", "plain")
@@ -67,6 +67,10 @@ def test_the_first_datagram_does_not_wait_for_a_handshake(local_https_page, monk
t_pc = result["t_pc"] / 1000.0
granted = [a for a in gateway.associations if a[1] is not None]
first = next((t for host, port, _atyp, t in gateway.datagram_log if host == STUN_NUMBER), None)
print("HUNT-STUN t_pc=%.3f first=%s associations=%r srflx=%s" % (
t_pc - gateway.wall0, None if first is None else round(first, 3),
[(a[0] if len(a) > 0 else None, None if a[1] is None else round(a[1], 3)) for a in gateway.associations],
result.get("t_srflx") and round(result["t_srflx"] / 1000.0 - gateway.wall0, 3)), flush=True)
assert granted, "the proxy was never asked for an association"
# the first association of the gateway is the core's own UDP probe, made before the browser exists: it is no pool
# association of the engine, and counting it made this test pass with an engine that asked for none