mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-21 15:52:26 +01:00
gatelock: verify the 2026-11-21 lock order
Some checks are pending
file length / file-length (push) Waiting to run
gatelock pre-commit / pre-commit (push) Waiting to run
gatelock tests / test (push) Waiting to run
kuhy_credit drift / drift (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
palette drift / palette (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run
Some checks are pending
file length / file-length (push) Waiting to run
gatelock pre-commit / pre-commit (push) Waiting to run
gatelock tests / test (push) Waiting to run
kuhy_credit drift / drift (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
palette drift / palette (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run
verify_all_lockers now runs six lockers at kuhy's ranks (workout, book, tutor, diet, focus, LeetCode last), fails when they come up out of order, and checks each installed locker's rank constant. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b00455722d
commit
c439f54784
@ -122,8 +122,11 @@ simultaneous starters see each other. An armed lock also steps back (`_stepback`
|
||||
when a strictly higher-ranked, live claim that locks at least as firmly appears
|
||||
later: it hides, releases the grab and its holder lock (the claim stays, so
|
||||
lower ranks keep queueing), waits windowless, and re-arms fully once nothing
|
||||
outranks it. `scripts/verify_all_lockers.py` checks this with five real
|
||||
processes on a private Xvfb.
|
||||
outranks it. `scripts/verify_all_lockers.py` checks this with six real
|
||||
processes on a private Xvfb. It also fails unless the locks come up in
|
||||
kuhy's order (2026-11-21: workout 200, book 175, tutor 150, diet 130,
|
||||
focus 128, LeetCode 125 last) and every installed locker's own rank
|
||||
constant matches that table (`scripts/locker_ranks.py`, runnable alone).
|
||||
|
||||
## Error and slow-wait reporting
|
||||
|
||||
|
||||
93
gatelock/scripts/locker_ranks.py
Executable file
93
gatelock/scripts/locker_ranks.py
Executable file
@ -0,0 +1,93 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2026 Krzysztof Rudnicki
|
||||
"""The lock order kuhy fixed on 2026-11-21, and checks that the lockers keep it.
|
||||
|
||||
``verify_all_lockers.py`` starts one child per entry in :data:`LOCKERS` at the
|
||||
rank written here. That only proves this table, so :func:`rank_drift` also
|
||||
imports each locker's own rank constant (as ``/usr/bin/python3`` sees it, the
|
||||
deployment path) and reports any that differ. A locker that is not installed
|
||||
is skipped, not failed: this also runs on machines without the lockers.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
from itertools import pairwise
|
||||
import json
|
||||
import sys
|
||||
from typing import TYPE_CHECKING, Final
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pathlib import Path
|
||||
|
||||
LOCKERS: Final = { # gatelock app -> rank; see each repo's DOCS-lock-order.md
|
||||
"screen_locker": 200,
|
||||
"book_guard": 175,
|
||||
"tutor_gate": 150,
|
||||
"diet_guard": 130,
|
||||
"focus_guard": 128,
|
||||
"leetcode_guard": 125,
|
||||
}
|
||||
REQUIRED_ORDER: Final = ( # kuhy's order: workout, book, tutor, diet, leetcode
|
||||
"screen_locker",
|
||||
"book_guard",
|
||||
"tutor_gate",
|
||||
"diet_guard",
|
||||
"leetcode_guard",
|
||||
)
|
||||
SOURCES: Final = { # app -> (module, constant) holding its real rank
|
||||
"screen_locker": ("gatelock", "RANK_SCREEN_LOCKER"),
|
||||
"book_guard": ("book_guard._constants", "RANK_BOOK_GUARD"),
|
||||
"tutor_gate": ("tutor.gate_lock", "RANK_TUTOR_EVENING"),
|
||||
"diet_guard": ("diet_guard._constants", "RANK_DIET_GUARD"),
|
||||
"focus_guard": ("focus_guard._constants", "RANK_FOCUS_GUARD"),
|
||||
"leetcode_guard": ("leetcode_guard._constants", "RANK_LEETCODE_GUARD"),
|
||||
}
|
||||
|
||||
|
||||
def order_holds() -> bool:
|
||||
"""Whether :data:`LOCKERS` ranks kuhy's order strictly falling."""
|
||||
ranks = [LOCKERS[app] for app in REQUIRED_ORDER]
|
||||
return all(a > b for a, b in pairwise(ranks))
|
||||
|
||||
|
||||
def rank_drift() -> tuple[list[str], list[str]]:
|
||||
"""(mismatches, skipped): installed ranks that differ from the table."""
|
||||
bad: list[str] = []
|
||||
skipped: list[str] = []
|
||||
for app, (module, name) in SOURCES.items():
|
||||
try:
|
||||
real = getattr(importlib.import_module(module), name, None)
|
||||
except ImportError as exc:
|
||||
skipped.append(f"{app} ({exc})")
|
||||
continue
|
||||
if real != LOCKERS[app]:
|
||||
bad.append(f"{app}: installed {real}, table {LOCKERS[app]}")
|
||||
return bad, skipped
|
||||
|
||||
|
||||
def firmness_defeats(claims_dir: Path) -> list[str]:
|
||||
"""Pairs where a higher-ranked claim locks less firmly than a lower one.
|
||||
|
||||
gatelock lets such a lower lock arm anyway (rank never weakens a lock), so
|
||||
each pair listed here is a place the order does not hold.
|
||||
"""
|
||||
claims = [json.loads(p.read_text()) for p in sorted(claims_dir.glob("*.json"))]
|
||||
pairs: list[str] = []
|
||||
for hi in claims:
|
||||
for lo in claims:
|
||||
weaker = (hi["grab"] == "local" and lo["grab"] == "global") or (
|
||||
lo["disable_vt"] and not hi["disable_vt"]
|
||||
)
|
||||
if hi["rank"] > lo["rank"] and weaker:
|
||||
pairs.append(f"{hi['app']} ({hi['rank']}) > {lo['app']} ({lo['rank']})")
|
||||
return pairs
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Fast check without an X server: the table's order and the installed ranks.
|
||||
drifted, missing = rank_drift()
|
||||
sys.stdout.write(
|
||||
f"order holds: {order_holds()}\ndrift: {drifted}\nskipped: {missing}\n"
|
||||
)
|
||||
sys.exit(0 if order_holds() and not drifted else 1)
|
||||
@ -3,13 +3,14 @@
|
||||
# pylint: disable=missing-function-docstring,consider-using-with,import-error
|
||||
r"""All lockers at once, on a real X server: one lock at a time, each clickable.
|
||||
|
||||
Starts the five lockers that fire together at login (real app names and ranks,
|
||||
Starts the six lockers that can fire together (real app names and ranks,
|
||||
the real ``Arbiter`` + ``wait_for_turn`` startup, one process each, a private
|
||||
``GATELOCK_RUNTIME_DIR``) with a ``gcr-prompter`` grab helper started first, as
|
||||
on 2026-11-11. Asserts: never two locks on screen; once the prompt lets go the
|
||||
lone lock holds the grab; an XTEST click on its button fires its callback; when
|
||||
it closes the next one comes up the same way. The queue poll is 0.5 s (real:
|
||||
2 s) to fit the 60 s cap. Argument: launch order -- mixed, strong-first,
|
||||
it closes the next one comes up the same way; they come up in kuhy's order
|
||||
(``locker_ranks``) and every installed locker's rank matches it. The queue poll
|
||||
is 0.5 s (real: 2 s) to fit the 60 s cap. Argument: launch order -- mixed, strong-first,
|
||||
weak-first, or late-strong (screen_locker starts 3 s after the rest, once a
|
||||
weaker lock holds the grab). Xvfb only (XTEST); refuses ``:0``::
|
||||
|
||||
@ -29,6 +30,7 @@ import tempfile
|
||||
import time
|
||||
from typing import TYPE_CHECKING, Final
|
||||
|
||||
from locker_ranks import LOCKERS, firmness_defeats, order_holds, rank_drift
|
||||
from Xlib import X, display, error
|
||||
from Xlib.ext import xtest
|
||||
|
||||
@ -36,16 +38,9 @@ if TYPE_CHECKING:
|
||||
from collections.abc import Callable
|
||||
|
||||
HERE: Final = Path(__file__).parent
|
||||
LOCKERS: Final = { # app -> rank, as in each locker's own constants
|
||||
"screen_locker": 200,
|
||||
"leetcode_guard": 150,
|
||||
"book_guard": 125,
|
||||
"focus_guard": 120,
|
||||
"diet_guard": 100,
|
||||
}
|
||||
_RANKED: Final = tuple(sorted(LOCKERS, key=lambda a: -LOCKERS[a]))
|
||||
ORDERS: Final = { # launch order: how the five processes race to publish
|
||||
"mixed": tuple(_RANKED[i] for i in (4, 1, 3, 0, 2)),
|
||||
ORDERS: Final = { # launch order: how the six processes race to publish
|
||||
"mixed": tuple(_RANKED[i] for i in (5, 1, 4, 0, 3, 2)),
|
||||
"strong-first": _RANKED,
|
||||
"weak-first": _RANKED[::-1],
|
||||
"late-strong": tuple(sorted(set(LOCKERS) - {"screen_locker"})),
|
||||
@ -217,6 +212,9 @@ def main(mode: str) -> int:
|
||||
helper.stdout is not None and helper.stdout.readline().strip() == "READY",
|
||||
"prompt holds the grab",
|
||||
)
|
||||
check(order_holds(), "the table ranks workout > book > tutor > diet > leetcode")
|
||||
drift, skipped = rank_drift()
|
||||
check(not drift, f"installed ranks match the table {drift} (skipped: {skipped})")
|
||||
fleet = _Fleet(env, ORDERS[mode])
|
||||
run = _Run(fleet, _Screen())
|
||||
try:
|
||||
@ -228,14 +226,16 @@ def main(mode: str) -> int:
|
||||
if mode in LATE:
|
||||
late, at, hold = LATE[mode]
|
||||
run.pump(at - hold)
|
||||
check("leetcode_guard" in fleet.armed, "a weaker lock is armed first")
|
||||
check(_RANKED[1] in fleet.armed, "a weaker lock is armed first")
|
||||
fleet.launch(late)
|
||||
gone = run.pump(SHOW_S, lambda: "leetcode_guard" not in run.screen.shown())
|
||||
gone = run.pump(SHOW_S, lambda: _RANKED[1] not in run.screen.shown())
|
||||
check(gone, "the weaker lock stepped back")
|
||||
weak = firmness_defeats(Path(env["GATELOCK_RUNTIME_DIR"]) / "claims")
|
||||
check(not weak, f"no higher rank locks more weakly {weak}")
|
||||
order = _drive(run, check)
|
||||
check(not run.doubles, f"never two locks on screen (saw {run.doubles[:3]})")
|
||||
_say(f"order seen: {order}")
|
||||
_say("rank order" if order == list(_RANKED) else "NOT rank order")
|
||||
check(order == list(_RANKED), "the locks came up in rank order")
|
||||
finally:
|
||||
fleet.stop()
|
||||
if helper.stdin:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user