mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-29 17:03:33 +01:00
Compare commits
No commits in common. "206740889c4d23b3c216322156b72805a27218ac" and "7327c287f46d719392668afca076e8d80da515ab" have entirely different histories.
206740889c
...
7327c287f4
17
.gitignore
vendored
17
.gitignore
vendored
@ -1,17 +0,0 @@
|
|||||||
# Python build/test artifacts, across every subproject in this monorepo.
|
|
||||||
__pycache__/
|
|
||||||
*.py[cod]
|
|
||||||
*.egg-info/
|
|
||||||
build/
|
|
||||||
dist/
|
|
||||||
.venv/
|
|
||||||
.mypy_cache/
|
|
||||||
.ruff_cache/
|
|
||||||
.pytest_cache/
|
|
||||||
|
|
||||||
# Coverage output. Each subproject writes these next to its own pyproject.toml,
|
|
||||||
# and a run from the repo root drops a pair here too.
|
|
||||||
.coverage
|
|
||||||
.coverage.*
|
|
||||||
coverage.lcov
|
|
||||||
htmlcov/
|
|
||||||
19
crdt-sync/.github/workflows/pre-commit.yml
vendored
Normal file
19
crdt-sync/.github/workflows/pre-commit.yml
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
name: pre-commit
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
pre-commit:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: "3.12"
|
||||||
|
- name: Install dependencies
|
||||||
|
run: pip install -r requirements.txt
|
||||||
|
- uses: pre-commit/action@v3.0.1
|
||||||
28
crdt-sync/.github/workflows/python-tests.yml
vendored
Normal file
28
crdt-sync/.github/workflows/python-tests.yml
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
name: Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
python-version: ["3.10", "3.11", "3.12"]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: pip install -r requirements.txt
|
||||||
|
|
||||||
|
- name: Run tests with coverage
|
||||||
|
run: python -m pytest -v
|
||||||
12
crdt-sync/.gitignore
vendored
Normal file
12
crdt-sync/.gitignore
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
.venv/
|
||||||
|
.mypy_cache/
|
||||||
|
.ruff_cache/
|
||||||
|
.pytest_cache/
|
||||||
|
.coverage
|
||||||
|
coverage.lcov
|
||||||
|
htmlcov/
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
*.egg-info/
|
||||||
@ -3,14 +3,6 @@
|
|||||||
# Run: pre-commit run --all-files
|
# Run: pre-commit run --all-files
|
||||||
# Update: pre-commit autoupdate
|
# Update: pre-commit autoupdate
|
||||||
|
|
||||||
# NOTE: this subproject lives inside the ~/utils monorepo, whose git root is
|
|
||||||
# one level up. pre-commit always runs hooks from the git root, so every path
|
|
||||||
# below is written relative to THAT, not to this directory, and the top-level
|
|
||||||
# `files` key keeps these hooks off the sibling subprojects. CI invokes this
|
|
||||||
# config exactly the same way:
|
|
||||||
# pre-commit run --config crdt-sync/.pre-commit-config.yaml --all-files
|
|
||||||
files: ^crdt-sync/
|
|
||||||
|
|
||||||
default_language_version:
|
default_language_version:
|
||||||
python: python3
|
python: python3
|
||||||
default_stages: [pre-commit]
|
default_stages: [pre-commit]
|
||||||
@ -40,14 +32,6 @@ repos:
|
|||||||
|
|
||||||
- repo: local
|
- repo: local
|
||||||
hooks:
|
hooks:
|
||||||
- id: subproject-scope
|
|
||||||
name: subproject scope regex still matches
|
|
||||||
entry: scripts/check_subproject_scope.sh crdt-sync
|
|
||||||
language: script
|
|
||||||
# always_run so the top-level `files` filter cannot skip the one hook
|
|
||||||
# whose job is to notice that filter has stopped matching anything.
|
|
||||||
always_run: true
|
|
||||||
pass_filenames: false
|
|
||||||
- id: no-noqa
|
- id: no-noqa
|
||||||
name: Block noqa comments
|
name: Block noqa comments
|
||||||
entry: '(?i)#\s*(noqa|type:\s*ignore)'
|
entry: '(?i)#\s*(noqa|type:\s*ignore)'
|
||||||
@ -102,7 +86,7 @@ repos:
|
|||||||
hooks:
|
hooks:
|
||||||
- id: pylint
|
- id: pylint
|
||||||
args:
|
args:
|
||||||
- --rcfile=crdt-sync/pyproject.toml
|
- --rcfile=pyproject.toml
|
||||||
- --fail-under=8.0
|
- --fail-under=8.0
|
||||||
- --jobs=4
|
- --jobs=4
|
||||||
additional_dependencies:
|
additional_dependencies:
|
||||||
@ -110,24 +94,24 @@ repos:
|
|||||||
- requests
|
- requests
|
||||||
|
|
||||||
- repo: https://github.com/PyCQA/bandit
|
- repo: https://github.com/PyCQA/bandit
|
||||||
rev: 1.9.4
|
rev: 1.7.10
|
||||||
hooks:
|
hooks:
|
||||||
- id: bandit
|
- id: bandit
|
||||||
args:
|
args:
|
||||||
- -c
|
- -c
|
||||||
- crdt-sync/pyproject.toml
|
- pyproject.toml
|
||||||
- --severity-level=high
|
- --severity-level=high
|
||||||
- --confidence-level=medium
|
- --confidence-level=medium
|
||||||
- --skip=B113
|
- --skip=B113
|
||||||
additional_dependencies: ["bandit[toml]"]
|
additional_dependencies: ["bandit[toml]"]
|
||||||
exclude: ^(crdt-sync/crdt_sync/tests/|.*test.*\.py$)
|
exclude: ^(tests/|.*test.*\.py$)
|
||||||
|
|
||||||
- repo: local
|
- repo: local
|
||||||
hooks:
|
hooks:
|
||||||
- id: pytest-coverage
|
- id: pytest-coverage
|
||||||
name: pytest with coverage enforcement
|
name: pytest with coverage enforcement
|
||||||
entry: scripts/run_subproject_tests.sh crdt-sync
|
entry: python -m pytest
|
||||||
language: script
|
language: system
|
||||||
types: [python]
|
types: [python]
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
require_serial: true
|
require_serial: true
|
||||||
|
|||||||
19
gatelock/.github/workflows/pre-commit.yml
vendored
Normal file
19
gatelock/.github/workflows/pre-commit.yml
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
name: pre-commit
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
pre-commit:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: "3.12"
|
||||||
|
- name: Install dependencies
|
||||||
|
run: pip install -r requirements.txt
|
||||||
|
- uses: pre-commit/action@v3.0.1
|
||||||
28
gatelock/.github/workflows/python-tests.yml
vendored
Normal file
28
gatelock/.github/workflows/python-tests.yml
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
name: Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
python-version: ["3.10", "3.11", "3.12"]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: pip install -r requirements.txt
|
||||||
|
|
||||||
|
- name: Run tests with coverage
|
||||||
|
run: python -m pytest -v
|
||||||
12
gatelock/.gitignore
vendored
Normal file
12
gatelock/.gitignore
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
.venv/
|
||||||
|
.mypy_cache/
|
||||||
|
.ruff_cache/
|
||||||
|
.pytest_cache/
|
||||||
|
.coverage
|
||||||
|
coverage.lcov
|
||||||
|
htmlcov/
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
*.egg-info/
|
||||||
@ -3,14 +3,6 @@
|
|||||||
# Run: pre-commit run --all-files
|
# Run: pre-commit run --all-files
|
||||||
# Update: pre-commit autoupdate
|
# Update: pre-commit autoupdate
|
||||||
|
|
||||||
# NOTE: this subproject lives inside the ~/utils monorepo, whose git root is
|
|
||||||
# one level up. pre-commit always runs hooks from the git root, so every path
|
|
||||||
# below is written relative to THAT, not to this directory, and the top-level
|
|
||||||
# `files` key keeps these hooks off the sibling subprojects. CI invokes this
|
|
||||||
# config exactly the same way:
|
|
||||||
# pre-commit run --config gatelock/.pre-commit-config.yaml --all-files
|
|
||||||
files: ^gatelock/
|
|
||||||
|
|
||||||
default_language_version:
|
default_language_version:
|
||||||
python: python3
|
python: python3
|
||||||
default_stages: [pre-commit]
|
default_stages: [pre-commit]
|
||||||
@ -40,14 +32,6 @@ repos:
|
|||||||
|
|
||||||
- repo: local
|
- repo: local
|
||||||
hooks:
|
hooks:
|
||||||
- id: subproject-scope
|
|
||||||
name: subproject scope regex still matches
|
|
||||||
entry: scripts/check_subproject_scope.sh gatelock
|
|
||||||
language: script
|
|
||||||
# always_run so the top-level `files` filter cannot skip the one hook
|
|
||||||
# whose job is to notice that filter has stopped matching anything.
|
|
||||||
always_run: true
|
|
||||||
pass_filenames: false
|
|
||||||
- id: no-noqa
|
- id: no-noqa
|
||||||
name: Block noqa comments
|
name: Block noqa comments
|
||||||
entry: '(?i)#\s*(noqa|type:\s*ignore)'
|
entry: '(?i)#\s*(noqa|type:\s*ignore)'
|
||||||
@ -100,31 +84,31 @@ repos:
|
|||||||
hooks:
|
hooks:
|
||||||
- id: pylint
|
- id: pylint
|
||||||
args:
|
args:
|
||||||
- --rcfile=gatelock/pyproject.toml
|
- --rcfile=pyproject.toml
|
||||||
- --fail-under=8.0
|
- --fail-under=8.0
|
||||||
- --jobs=4
|
- --jobs=4
|
||||||
additional_dependencies:
|
additional_dependencies:
|
||||||
- pytest
|
- pytest
|
||||||
|
|
||||||
- repo: https://github.com/PyCQA/bandit
|
- repo: https://github.com/PyCQA/bandit
|
||||||
rev: 1.9.4
|
rev: 1.7.10
|
||||||
hooks:
|
hooks:
|
||||||
- id: bandit
|
- id: bandit
|
||||||
args:
|
args:
|
||||||
- -c
|
- -c
|
||||||
- gatelock/pyproject.toml
|
- pyproject.toml
|
||||||
- --severity-level=high
|
- --severity-level=high
|
||||||
- --confidence-level=medium
|
- --confidence-level=medium
|
||||||
- --skip=B113
|
- --skip=B113
|
||||||
additional_dependencies: ["bandit[toml]"]
|
additional_dependencies: ["bandit[toml]"]
|
||||||
exclude: ^(gatelock/gatelock/tests/|.*test.*\.py$)
|
exclude: ^(tests/|.*test.*\.py$)
|
||||||
|
|
||||||
- repo: local
|
- repo: local
|
||||||
hooks:
|
hooks:
|
||||||
- id: pytest-coverage
|
- id: pytest-coverage
|
||||||
name: pytest with coverage enforcement
|
name: pytest with coverage enforcement
|
||||||
entry: scripts/run_subproject_tests.sh gatelock
|
entry: python -m pytest
|
||||||
language: script
|
language: system
|
||||||
types: [python]
|
types: [python]
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
require_serial: true
|
require_serial: true
|
||||||
|
|||||||
@ -90,7 +90,6 @@ class RecoveryLoop:
|
|||||||
self._ticks = 0
|
self._ticks = 0
|
||||||
self._drain_job: str | None = None
|
self._drain_job: str | None = None
|
||||||
self._verify_job: str | None = None
|
self._verify_job: str | None = None
|
||||||
self._last_grab_warning: str | None = None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ticks(self) -> int:
|
def ticks(self) -> int:
|
||||||
@ -127,32 +126,15 @@ class RecoveryLoop:
|
|||||||
|
|
||||||
def _drain(self) -> None:
|
def _drain(self) -> None:
|
||||||
"""Run a full tick only if a push signal arrived. Cheap otherwise."""
|
"""Run a full tick only if a push signal arrived. Cheap otherwise."""
|
||||||
try:
|
if self._detector.take_pending():
|
||||||
if self._detector.take_pending():
|
_logger.debug("output-change signal received; re-asserting the lock")
|
||||||
_logger.debug("output-change signal received; re-asserting the lock")
|
self.tick()
|
||||||
self.tick()
|
self._schedule_drain()
|
||||||
# Same fail-open reasoning as _verify.
|
|
||||||
except Exception:
|
|
||||||
_logger.exception("drain tick raised; the lock loop keeps running")
|
|
||||||
finally:
|
|
||||||
self._schedule_drain()
|
|
||||||
|
|
||||||
def _verify(self) -> None:
|
def _verify(self) -> None:
|
||||||
"""Run a full tick unconditionally.
|
"""Run a full tick unconditionally."""
|
||||||
|
self.tick()
|
||||||
The reschedule is in ``finally`` because it is the only thing keeping
|
self._schedule_verify()
|
||||||
the loop alive: a Tk ``after`` callback that raises just logs and
|
|
||||||
returns, so scheduling *after* ``tick()`` meant one unexpected
|
|
||||||
exception silently ended all re-assertion of coverage, grab and VT for
|
|
||||||
the rest of the lock. Fail-open is the one outcome this module exists
|
|
||||||
to prevent, so a broken tick must still leave the next one queued.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
self.tick()
|
|
||||||
except Exception:
|
|
||||||
_logger.exception("verify tick raised; the lock loop keeps running")
|
|
||||||
finally:
|
|
||||||
self._schedule_verify()
|
|
||||||
|
|
||||||
def tick(self) -> RecoveryReport:
|
def tick(self) -> RecoveryReport:
|
||||||
"""Re-assert coverage, placement, grab and VT. Never weakens any of them.
|
"""Re-assert coverage, placement, grab and VT. Never weakens any of them.
|
||||||
@ -216,7 +198,7 @@ class RecoveryLoop:
|
|||||||
"""
|
"""
|
||||||
if self._config.resolved_grab() != "global":
|
if self._config.resolved_grab() != "global":
|
||||||
return False
|
return False
|
||||||
if self.holds_grab():
|
if self._holds_grab():
|
||||||
return False
|
return False
|
||||||
with contextlib.suppress(tk.TclError):
|
with contextlib.suppress(tk.TclError):
|
||||||
self._root.grab_set_global()
|
self._root.grab_set_global()
|
||||||
@ -224,59 +206,13 @@ class RecoveryLoop:
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def holds_grab(self) -> bool:
|
def _holds_grab(self) -> bool:
|
||||||
"""Whether the grab is held by a window this application owns.
|
"""Whether our root still owns the grab."""
|
||||||
|
|
||||||
Deliberately *not* ``grab_current() is self._root``. Our own transient
|
|
||||||
children take the grab for themselves: a posted Tk menu grabs the menu
|
|
||||||
window, and the old identity test read that as "the grab was lost" and
|
|
||||||
called ``grab_set_global()`` a second later, stealing it back off our
|
|
||||||
own widget mid-interaction. That is what made the screen-locker sport
|
|
||||||
selector unusable while locked on 2026-07-26. Any window we own still
|
|
||||||
means the lock has the pointer and keyboard.
|
|
||||||
|
|
||||||
``grab_current`` resolves the name Tcl gives it against our own widget
|
|
||||||
map, so anything that does not resolve -- a Tcl-created popdown such as
|
|
||||||
a ``ttk.Combobox``'s, or a stale name -- raises ``KeyError`` and is NOT
|
|
||||||
provably ours. That counts as lost and the grab is re-taken: fail
|
|
||||||
closed, because this module exists to keep the lock, and losing a
|
|
||||||
popdown beats believing we hold a grab we do not.
|
|
||||||
|
|
||||||
Known limitation: a second ``tk.Tk()`` in the same process reports its
|
|
||||||
root as ``"."`` too, which is indistinguishable from ours. The old
|
|
||||||
identity test had exactly the same blind spot. ``_heat_skip``'s
|
|
||||||
throwaway root is the only other one in screen-locker, and it is
|
|
||||||
destroyed before the lock window exists.
|
|
||||||
|
|
||||||
Public so an embedder (or a verification harness) can ask the same
|
|
||||||
question the loop asks, rather than re-implementing it and drifting.
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
held = self._root.grab_current() is not None
|
current = self._root.grab_current()
|
||||||
except KeyError as exc:
|
|
||||||
self._warn_once(
|
|
||||||
f"the grab is held by {exc.args[0]!r}, not one of our windows"
|
|
||||||
)
|
|
||||||
return False
|
|
||||||
except tk.TclError:
|
except tk.TclError:
|
||||||
self._warn_once("could not read the current grab")
|
|
||||||
return False
|
return False
|
||||||
if held:
|
return current is self._root
|
||||||
self._last_grab_warning = None
|
|
||||||
return held
|
|
||||||
|
|
||||||
def _warn_once(self, reason: str) -> None:
|
|
||||||
"""Warn about a lost grab, but only when the reason changes.
|
|
||||||
|
|
||||||
These states can persist for the whole lock (a dark display, a popdown
|
|
||||||
that keeps re-grabbing), and this runs once a second -- warning every
|
|
||||||
tick would push a line per second into the journal for as long as it
|
|
||||||
lasts. Silence is not the alternative: the first occurrence and every
|
|
||||||
change of cause are still logged at WARNING.
|
|
||||||
"""
|
|
||||||
if reason != self._last_grab_warning:
|
|
||||||
_logger.warning("%s; treating it as lost and re-taking it", reason)
|
|
||||||
self._last_grab_warning = reason
|
|
||||||
|
|
||||||
def _reassert_vt(self) -> bool:
|
def _reassert_vt(self) -> bool:
|
||||||
"""Periodically re-disable VT switching. Never re-enables it.
|
"""Periodically re-disable VT switching. Never re-enables it.
|
||||||
|
|||||||
@ -133,7 +133,7 @@ class TestParseXrandrQuery:
|
|||||||
assert output.rect is None
|
assert output.rect is None
|
||||||
|
|
||||||
def test_garbage_and_empty(self) -> None:
|
def test_garbage_and_empty(self) -> None:
|
||||||
"""Unparsable input yields no outputs rather than raising."""
|
"""Unparseable input yields no outputs rather than raising."""
|
||||||
assert parse_xrandr_query(XRANDR_GARBAGE) == ()
|
assert parse_xrandr_query(XRANDR_GARBAGE) == ()
|
||||||
assert parse_xrandr_query("") == ()
|
assert parse_xrandr_query("") == ()
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,6 @@ lock never weakens, and per-branch coverage.
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import ast
|
import ast
|
||||||
import logging
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
@ -191,57 +190,6 @@ class TestGrabReassertion:
|
|||||||
mock_root.grab_current.return_value = mock_root
|
mock_root.grab_current.return_value = mock_root
|
||||||
assert recovery.tick().grab_reasserted is False
|
assert recovery.tick().grab_reasserted is False
|
||||||
|
|
||||||
def test_noop_when_our_own_child_holds_the_grab(
|
|
||||||
self, loop: tuple[RecoveryLoop, MagicMock, SurfaceSet], mock_root: MagicMock
|
|
||||||
) -> None:
|
|
||||||
"""A posted menu owns the grab; we must not steal it back.
|
|
||||||
|
|
||||||
Regression: the old ``grab_current() is root`` test read a Tk menu's
|
|
||||||
own grab as "lost" and re-grabbed a second later, which made the
|
|
||||||
screen-locker sport selector unusable while locked.
|
|
||||||
"""
|
|
||||||
recovery, enumerator, _surfaces = loop
|
|
||||||
enumerator.scan.return_value = BOTH
|
|
||||||
mock_root.grab_current.return_value = MagicMock(name="posted menu")
|
|
||||||
assert recovery.tick().grab_reasserted is False
|
|
||||||
mock_root.grab_set_global.assert_not_called()
|
|
||||||
|
|
||||||
def test_reasserts_when_the_holder_is_not_one_of_our_windows(
|
|
||||||
self,
|
|
||||||
loop: tuple[RecoveryLoop, MagicMock, SurfaceSet],
|
|
||||||
mock_root: MagicMock,
|
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
|
||||||
"""Fail closed: a name we cannot resolve is not provably ours.
|
|
||||||
|
|
||||||
A ``ttk.Combobox`` popdown is a Tcl-created toplevel absent from
|
|
||||||
Tkinter's widget map, so ``nametowidget`` raises ``KeyError``. Keeping
|
|
||||||
the lock beats keeping a banned widget's popdown.
|
|
||||||
"""
|
|
||||||
recovery, enumerator, _surfaces = loop
|
|
||||||
enumerator.scan.return_value = BOTH
|
|
||||||
mock_root.grab_current.side_effect = KeyError("!popdown")
|
|
||||||
with caplog.at_level(logging.WARNING):
|
|
||||||
assert recovery.tick().grab_reasserted is True
|
|
||||||
mock_root.grab_set_global.assert_called()
|
|
||||||
assert "not one of our windows" in caplog.text
|
|
||||||
|
|
||||||
def test_a_persistent_lost_grab_warns_once_not_once_per_tick(
|
|
||||||
self,
|
|
||||||
loop: tuple[RecoveryLoop, MagicMock, SurfaceSet],
|
|
||||||
mock_root: MagicMock,
|
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
|
||||||
"""A state that lasts the whole lock must not stream to the journal."""
|
|
||||||
recovery, enumerator, _surfaces = loop
|
|
||||||
enumerator.scan.return_value = BOTH
|
|
||||||
mock_root.grab_current.side_effect = tk.TclError("gone")
|
|
||||||
with caplog.at_level(logging.WARNING):
|
|
||||||
for _ in range(5):
|
|
||||||
recovery.tick()
|
|
||||||
lost = [r for r in caplog.records if "current grab" in r.message]
|
|
||||||
assert len(lost) == 1, f"warned {len(lost)} times over 5 ticks"
|
|
||||||
|
|
||||||
def test_tclerror_while_regrabbing_is_swallowed(
|
def test_tclerror_while_regrabbing_is_swallowed(
|
||||||
self, loop: tuple[RecoveryLoop, MagicMock, SurfaceSet], mock_root: MagicMock
|
self, loop: tuple[RecoveryLoop, MagicMock, SurfaceSet], mock_root: MagicMock
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -252,7 +200,7 @@ class TestGrabReassertion:
|
|||||||
mock_root.grab_set_global.side_effect = tk.TclError("held")
|
mock_root.grab_set_global.side_effect = tk.TclError("held")
|
||||||
assert recovery.tick().grab_reasserted is False
|
assert recovery.tick().grab_reasserted is False
|
||||||
|
|
||||||
def test_grab_query_tclerror(
|
def test_grab_current_tclerror(
|
||||||
self, loop: tuple[RecoveryLoop, MagicMock, SurfaceSet], mock_root: MagicMock
|
self, loop: tuple[RecoveryLoop, MagicMock, SurfaceSet], mock_root: MagicMock
|
||||||
) -> None:
|
) -> None:
|
||||||
"""A TclError querying the grab counts as not holding it."""
|
"""A TclError querying the grab counts as not holding it."""
|
||||||
@ -338,37 +286,6 @@ class TestScheduling:
|
|||||||
recovery._verify()
|
recovery._verify()
|
||||||
assert recovery.ticks == 1
|
assert recovery.ticks == 1
|
||||||
|
|
||||||
def test_verify_reschedules_even_when_the_tick_raises(
|
|
||||||
self,
|
|
||||||
loop: tuple[RecoveryLoop, MagicMock, SurfaceSet],
|
|
||||||
mock_root: MagicMock,
|
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
|
||||||
"""A broken tick must not end the loop -- that would fail open."""
|
|
||||||
recovery, enumerator, _surfaces = loop
|
|
||||||
enumerator.scan.side_effect = RuntimeError("boom")
|
|
||||||
recovery._running = True
|
|
||||||
with caplog.at_level(logging.ERROR):
|
|
||||||
recovery._verify()
|
|
||||||
mock_root.after.assert_called_once()
|
|
||||||
assert "verify tick raised" in caplog.text
|
|
||||||
|
|
||||||
def test_drain_reschedules_even_when_the_tick_raises(
|
|
||||||
self,
|
|
||||||
loop: tuple[RecoveryLoop, MagicMock, SurfaceSet],
|
|
||||||
mock_root: MagicMock,
|
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
) -> None:
|
|
||||||
"""Same for the cheap cadence."""
|
|
||||||
recovery, enumerator, _surfaces = loop
|
|
||||||
enumerator.scan.side_effect = RuntimeError("boom")
|
|
||||||
recovery._detector.take_pending.return_value = True
|
|
||||||
recovery._running = True
|
|
||||||
with caplog.at_level(logging.ERROR):
|
|
||||||
recovery._drain()
|
|
||||||
mock_root.after.assert_called_once()
|
|
||||||
assert "drain tick raised" in caplog.text
|
|
||||||
|
|
||||||
def test_stop_cancels_and_halts(
|
def test_stop_cancels_and_halts(
|
||||||
self, loop: tuple[RecoveryLoop, MagicMock, SurfaceSet], mock_root: MagicMock
|
self, loop: tuple[RecoveryLoop, MagicMock, SurfaceSet], mock_root: MagicMock
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "gatelock"
|
name = "gatelock"
|
||||||
version = "0.2.1"
|
version = "0.2.0"
|
||||||
description = "Shared per-output lock-window + HMAC log-integrity backend for blocking-overlay apps"
|
description = "Shared per-output lock-window + HMAC log-integrity backend for blocking-overlay apps"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
dependencies = [] # pure stdlib — tkinter is bundled with Python
|
dependencies = [] # pure stdlib — tkinter is bundled with Python
|
||||||
|
|||||||
@ -1,40 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# ============================================================================
|
|
||||||
# Fail if a subproject's pre-commit config is scoped to a directory that has
|
|
||||||
# moved or vanished.
|
|
||||||
#
|
|
||||||
# Each subproject config carries `files: ^<subproject>/`. If the directory is
|
|
||||||
# renamed, that regex matches nothing and EVERY hook in the config reports
|
|
||||||
# "no files to check" -- green CI with no linting at all. This hook runs with
|
|
||||||
# always_run, so the top-level filter cannot skip it, and turns that silent
|
|
||||||
# pass into a loud failure.
|
|
||||||
#
|
|
||||||
# Usage: scripts/check_subproject_scope.sh <subproject>
|
|
||||||
# ============================================================================
|
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
readonly REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
||||||
|
|
||||||
main() {
|
|
||||||
if [[ $# -ne 1 ]]; then
|
|
||||||
echo "Usage: $(basename "$0") <subproject>" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
local subproject="$1"
|
|
||||||
local config="$REPO_ROOT/$subproject/.pre-commit-config.yaml"
|
|
||||||
|
|
||||||
if [[ ! -f "$config" ]]; then
|
|
||||||
echo "Error: $subproject/.pre-commit-config.yaml is missing." >&2
|
|
||||||
echo " Every hook scoped to '^$subproject/' would silently pass." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
if ! grep -qx "files: \^$subproject/" "$config"; then
|
|
||||||
echo "Error: $config does not scope itself to '^$subproject/'." >&2
|
|
||||||
echo " Hooks would run over the whole monorepo, or over nothing." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
main "$@"
|
|
||||||
@ -1,44 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# ============================================================================
|
|
||||||
# Run one subproject's test suite from that subproject's directory.
|
|
||||||
#
|
|
||||||
# Every subproject here keeps its own pyproject.toml, and its pytest config
|
|
||||||
# (testpaths, --cov=..., coverage source) is relative to that directory --
|
|
||||||
# but pre-commit always runs hooks from the monorepo's git root. This wrapper
|
|
||||||
# supplies the missing `cd`, and fails loudly if the subproject is gone,
|
|
||||||
# rather than silently testing nothing.
|
|
||||||
#
|
|
||||||
# Usage: scripts/run_subproject_tests.sh <subproject> [pytest args...]
|
|
||||||
# ============================================================================
|
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
readonly REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
||||||
readonly SCRIPT_NAME="$(basename "$0")"
|
|
||||||
|
|
||||||
usage() {
|
|
||||||
echo "Usage: $SCRIPT_NAME <subproject> [pytest args...]"
|
|
||||||
echo " <subproject> directory under $REPO_ROOT holding a pyproject.toml"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
|
||||||
if [[ $# -lt 1 ]]; then
|
|
||||||
usage
|
|
||||||
fi
|
|
||||||
local subproject="$1"
|
|
||||||
shift
|
|
||||||
local project_dir="$REPO_ROOT/$subproject"
|
|
||||||
|
|
||||||
if [[ ! -f "$project_dir/pyproject.toml" ]]; then
|
|
||||||
echo "Error: no $subproject/pyproject.toml under $REPO_ROOT" >&2
|
|
||||||
echo " (was the subproject renamed or removed?)" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cd "$project_dir"
|
|
||||||
exec python -m pytest "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
main "$@"
|
|
||||||
Loading…
Reference in New Issue
Block a user