tests: the tests that need the environment of their machine move to files of their own
Same bodies, same assertions; each file says in its name and docstring what it needs: the driver bundle tree (INVPW_DRIVER_TREE), the workbench next to the checkout, a stock Firefox bundled with Playwright, a clone with core.hooksPath armed, a clone with origin/main, and the two tests that run on Windows only (the hidden desktop's prefs, the job object of the reaper). The files that held them keep what runs everywhere.
This commit is contained in:
1 parent
06f9fd4b5e
commit
f76363b1dd
14 files changed
+348
-233
No files matched your search
@@ -0,0 +1,34 @@
|
||||
"""A test that needs a stock Firefox bundled with Playwright on the machine that runs it.
|
||||
|
||||
``test_real_stock_firefox_via_binary_path_is_refused`` looks for ``ms-playwright/firefox-*`` in the user's cache; a clean CI runner has none, so the test
|
||||
skips, and a skip is red in the whole unit suite of the candidate. It lives in its own file, out of ``tests/test_seal_binary_path.py`` (whose other
|
||||
cases build their own tree and run everywhere), and is a file of the environment of ``tests/test_the_unit_suite_is_accounted_for.py``.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from invisible_core.seal import EngineMismatch, read_engine_identity
|
||||
from invisible_playwright import _engine
|
||||
|
||||
from test_seal_binary_path import ENTRY_REL, active # noqa: F401 (``active`` is a fixture)
|
||||
|
||||
|
||||
def test_real_stock_firefox_via_binary_path_is_refused(active):
|
||||
"""The cell as it exists on this machine, not a synthetic stand-in. Read
|
||||
only; skips cleanly when no bundled Playwright Firefox is present."""
|
||||
local = os.environ.get("LOCALAPPDATA") or str(Path.home() / "AppData/Local")
|
||||
roots = [Path(local) / "ms-playwright", Path.home() / ".cache" / "ms-playwright"]
|
||||
entries = [d / "firefox" / ENTRY_REL for root in roots if root.is_dir()
|
||||
for d in sorted(root.glob("firefox-*"))]
|
||||
entries = [e for e in entries if e.exists()]
|
||||
if not entries:
|
||||
pytest.skip("no bundled stock Firefox on this machine")
|
||||
for entry in entries:
|
||||
ident = read_engine_identity(entry)
|
||||
with pytest.raises(EngineMismatch):
|
||||
_engine.resolve_executable(entry)
|
||||
assert ident.marked_entries == 0, f"{entry} unexpectedly carries our marker"
|
||||
@@ -15,8 +15,6 @@ The same checks also apply to the end user: a wheel missing
|
||||
import pathlib
|
||||
import re
|
||||
|
||||
import pytest
|
||||
|
||||
SRC = pathlib.Path(__file__).resolve().parents[1] / "src" / "invisible_playwright"
|
||||
TESTS = pathlib.Path(__file__).resolve().parent
|
||||
|
||||
@@ -142,39 +140,6 @@ def test_nothing_declares_a_node_version_any_more():
|
||||
"in this package downloads or runs node since 2026-08-28." % offenders)
|
||||
|
||||
|
||||
def _injected_sources():
|
||||
"""The strings the bundle injects into the page, one per physical line.
|
||||
|
||||
They are declared as ``sourceN = '...'`` with SINGLE quotes and with newlines
|
||||
written as two characters, so each one occupies a single line of the file.
|
||||
"""
|
||||
# ⛔ THE BUNDLE MAY NOT BE HERE ANY MORE, and that is not a broken tree:
|
||||
# the driver was removed on 2026-08-28. The defect this scans for lives in
|
||||
# a SINGLE-QUOTED JavaScript string inside that bundle, so with the bundle
|
||||
# gone the class is gone with it - our `injected.js` is a plain file, where
|
||||
# an apostrophe in a comment is just an apostrophe.
|
||||
#
|
||||
# It is kept reachable rather than deleted because the check still applies
|
||||
# to any bundle somebody points at: `INVPW_DRIVER_TREE` from a git worktree,
|
||||
# or a fresh upstream one being considered for extraction.
|
||||
import os
|
||||
|
||||
tree = os.environ.get("INVPW_DRIVER_TREE")
|
||||
root = (pathlib.Path(tree) if tree
|
||||
else pathlib.Path(__file__).resolve().parent.parent)
|
||||
bundle = (root / "src" / "invisible_playwright" / "_driver" / "package"
|
||||
/ "lib" / "coreBundle.js")
|
||||
if not bundle.is_file():
|
||||
return
|
||||
text = bundle.read_text(encoding="utf-8", errors="replace")
|
||||
for number, line in enumerate(text.splitlines(), 1):
|
||||
m = re.match(r"^\s*(source\d*) = '", line)
|
||||
if m:
|
||||
yield number, m.group(1), line
|
||||
|
||||
|
||||
|
||||
|
||||
def _unprotected_quote(line):
|
||||
"""Where the single-quoted string closes before the end, or None.
|
||||
|
||||
@@ -195,35 +160,6 @@ def _unprotected_quote(line):
|
||||
return "the string never closes at all"
|
||||
|
||||
|
||||
def test_the_injected_sources_have_balanced_quotes():
|
||||
"""An apostrophe in a comment closes the string and breaks the whole bundle.
|
||||
|
||||
Happened on 2026-08-24: an Italian comment added inside ``source4``
|
||||
contained ``piu'`` and ``cioe'``. The string closed right there, the file
|
||||
became invalid JavaScript and the driver stopped starting at all.
|
||||
|
||||
The defect is not visible to the eye - those lines are hundreds of
|
||||
thousands of characters long - and no test that only imports the Python
|
||||
package sees it. No Node required: it holds even where the runtime has not
|
||||
been downloaded yet.
|
||||
"""
|
||||
found = list(_injected_sources())
|
||||
if not found:
|
||||
# ⛔ NOT AN ASSERTION FAILURE. With no bundle reachable there is
|
||||
# nothing of this shape to check, and the defect class went with it -
|
||||
# see `_injected_sources`. Saying "no injected source found" as a
|
||||
# failure would turn a deliberate deletion into a permanent red.
|
||||
pytest.skip("no driver bundle reachable: nothing of this shape exists "
|
||||
"to check. Point INVPW_DRIVER_TREE at a worktree to run "
|
||||
"it against one.")
|
||||
for number, name, line in found:
|
||||
rest = _unprotected_quote(line)
|
||||
assert rest is None, (
|
||||
"coreBundle.js:%d, %s: the injected string closes too early, "
|
||||
"what remains after it is %r - almost always an apostrophe inside a "
|
||||
"comment" % (number, name, rest))
|
||||
|
||||
|
||||
def test_the_quote_check_sees_a_real_apostrophe():
|
||||
"""The known-bad mutation, on the exact form that broke the bundle.
|
||||
|
||||
|
||||
@@ -843,24 +843,6 @@ def test_every_courtesy_entry_says_WHO_calls_it():
|
||||
"%s does not say who calls it: %r" % (name, reason))
|
||||
|
||||
|
||||
def test_the_workbench_inventory_and_the_package_cannot_DRIFT():
|
||||
"""⛔ There is one perimeter and it lives in the shipped package. The
|
||||
workbench tool that counts remaining work reads it from there; if it kept
|
||||
its own copy the two would disagree the first time one was edited - and the
|
||||
one that matters, the one that REFUSES, would be the one nobody updated."""
|
||||
from invisible_playwright._juggler import perimeter
|
||||
tool = pathlib.Path(__file__).resolve().parents[3] / "scripts" \
|
||||
/ "inventario_voce6.py"
|
||||
if not tool.exists():
|
||||
pytest.skip("the workbench is not next to this checkout")
|
||||
source = tool.read_text(encoding="utf-8", errors="replace")
|
||||
assert "_fuori_dal_pacchetto" in source, (
|
||||
"the inventory no longer reads the package: it has grown its own copy "
|
||||
"of the perimeter")
|
||||
assert "perimeter.py" in source
|
||||
assert len(perimeter.OUTSIDE) > 50
|
||||
|
||||
|
||||
# ── the temporary profile ───────────────────────────────────────────────────
|
||||
|
||||
def test_a_profile_WE_made_is_removed_and_the_caller_s_is_not():
|
||||
|
||||
@@ -12,8 +12,6 @@ what the index has.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from invisible_core import generate_profile, get_default_stealth_prefs
|
||||
@@ -104,40 +102,3 @@ def test_a_zero_cap_with_the_binary_engine_means_the_default_not_off():
|
||||
cursor_engine=ENGINE_BINARY, humanize=0)
|
||||
assert prefs["stealthfox.humanize"] is True
|
||||
assert prefs["stealthfox.humanize.maxTime"] == "1.5"
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.platform != "win32",
|
||||
reason="the hidden desktop is a Windows path")
|
||||
def test_a_hidden_desktop_brings_its_two_sandbox_keys_and_nothing_hides_by_pref():
|
||||
"""The window is hidden by WHERE the browser is created, not by a pref.
|
||||
|
||||
⛔ `zoom.stealth.cloak_windows` must never come back: from 2026-06-11 to
|
||||
2026-09-20 it switched on a DWMWA_CLOAK inside the binary, and the owner
|
||||
chose a stock engine on that surface. The two keys that DO ride with a
|
||||
hidden desktop are the sandbox workarounds measured in 2026-05 (§P16,
|
||||
#18 Bug A), emitted only when the desktop was actually created, with
|
||||
setdefault so an explicit override still wins.
|
||||
"""
|
||||
without = build_prefs(profile=generate_profile(SEED), locale=LOCALE,
|
||||
timezone=TZ, extra_prefs=None,
|
||||
virtual_display=False,
|
||||
cursor_engine=ENGINE_PYTHON, humanize=True)
|
||||
hidden = build_prefs(profile=generate_profile(SEED), locale=LOCALE,
|
||||
timezone=TZ, extra_prefs=None,
|
||||
virtual_display=True,
|
||||
cursor_engine=ENGINE_PYTHON, humanize=True)
|
||||
overridden = build_prefs(profile=generate_profile(SEED), locale=LOCALE,
|
||||
timezone=TZ,
|
||||
extra_prefs={"security.sandbox.gpu.level": 1},
|
||||
virtual_display=True,
|
||||
cursor_engine=ENGINE_PYTHON, humanize=True)
|
||||
|
||||
for prefs in (without, hidden, overridden):
|
||||
assert "zoom.stealth.cloak_windows" not in prefs, (
|
||||
"the in-binary cloak pref is back")
|
||||
assert "security.sandbox.gpu.level" not in without
|
||||
assert "security.sandbox.content.level" not in without
|
||||
assert hidden["security.sandbox.gpu.level"] == 0
|
||||
assert hidden["security.sandbox.content.level"] == 4
|
||||
assert overridden["security.sandbox.gpu.level"] == 1, (
|
||||
"the desktop workaround overwrote an explicit override")
|
||||
@@ -0,0 +1,56 @@
|
||||
"""The arm of the prefs composition that exists on Windows only: the hidden desktop.
|
||||
|
||||
``test_a_hidden_desktop_brings_its_two_sandbox_keys_and_nothing_hides_by_pref`` is skipped on every other system (the hidden desktop is a Windows path),
|
||||
and a skip is red in the whole unit suite of the candidate, so it is a file of its own and only the row of Windows lists it (``tests/test_prefs_composition_arm.py``
|
||||
keeps what runs on both).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
from invisible_core import generate_profile
|
||||
from invisible_playwright._cursor import ENGINE_PYTHON
|
||||
from invisible_playwright._session import build_prefs
|
||||
|
||||
from test_prefs_composition_arm import LOCALE, SEED, TZ
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.platform != "win32",
|
||||
reason="the hidden desktop is a Windows path")
|
||||
def test_a_hidden_desktop_brings_its_two_sandbox_keys_and_nothing_hides_by_pref():
|
||||
"""The window is hidden by WHERE the browser is created, not by a pref.
|
||||
|
||||
⛔ `zoom.stealth.cloak_windows` must never come back: from 2026-06-11 to
|
||||
2026-09-20 it switched on a DWMWA_CLOAK inside the binary, and the owner
|
||||
chose a stock engine on that surface. The two keys that DO ride with a
|
||||
hidden desktop are the sandbox workarounds measured in 2026-05 (§P16,
|
||||
#18 Bug A), emitted only when the desktop was actually created, with
|
||||
setdefault so an explicit override still wins.
|
||||
"""
|
||||
without = build_prefs(profile=generate_profile(SEED), locale=LOCALE,
|
||||
timezone=TZ, extra_prefs=None,
|
||||
virtual_display=False,
|
||||
cursor_engine=ENGINE_PYTHON, humanize=True)
|
||||
hidden = build_prefs(profile=generate_profile(SEED), locale=LOCALE,
|
||||
timezone=TZ, extra_prefs=None,
|
||||
virtual_display=True,
|
||||
cursor_engine=ENGINE_PYTHON, humanize=True)
|
||||
overridden = build_prefs(profile=generate_profile(SEED), locale=LOCALE,
|
||||
timezone=TZ,
|
||||
extra_prefs={"security.sandbox.gpu.level": 1},
|
||||
virtual_display=True,
|
||||
cursor_engine=ENGINE_PYTHON, humanize=True)
|
||||
|
||||
for prefs in (without, hidden, overridden):
|
||||
assert "zoom.stealth.cloak_windows" not in prefs, (
|
||||
"the in-binary cloak pref is back")
|
||||
assert "security.sandbox.gpu.level" not in without
|
||||
assert "security.sandbox.content.level" not in without
|
||||
assert hidden["security.sandbox.gpu.level"] == 0
|
||||
assert hidden["security.sandbox.content.level"] == 4
|
||||
assert overridden["security.sandbox.gpu.level"] == 1, (
|
||||
"the desktop workaround overwrote an explicit override")
|
||||
@@ -113,16 +113,3 @@ def test_the_ledger_records_what_actually_shipped():
|
||||
|
||||
|
||||
# ------------------------------------------------------- the clone is armed
|
||||
|
||||
def test_the_hooks_are_armed_in_this_clone():
|
||||
"""A checked-in hook directory does nothing until core.hooksPath points at
|
||||
it, and git will not do that for you.
|
||||
|
||||
Until 2026-07-27 both the installer and this reminder lived in the core, so
|
||||
THIS repo shipped a hook that nothing armed and nothing checked was armed:
|
||||
a fresh clone pushed with the tests, the pin, the name scan and the publish
|
||||
gate all skipped, and said nothing about it.
|
||||
"""
|
||||
from invisible_core.testing import assert_hooks_are_armed
|
||||
|
||||
assert_hooks_are_armed(_REPO)
|
||||
@@ -245,56 +245,6 @@ def test_stamping_does_not_mutate_the_environment_it_was_given():
|
||||
assert original == {"PATH": "/usr"}
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.name != "nt", reason="job objects are a Windows mechanism")
|
||||
def test_the_tree_dies_when_this_process_is_KILLED_not_merely_closed():
|
||||
"""The path that in-process cleanup cannot reach, and the actual bug.
|
||||
|
||||
Measured first, and it corrected the diagnosis: an exception out of the
|
||||
`with` block does NOT leak - __exit__ runs, Playwright tears down, zero
|
||||
survivors over an interleaved A/B with the reaper disabled. The leak was
|
||||
the timeout path, where the runner is killed and __exit__ never executes.
|
||||
With a real browser: eight survivors on the first attempt, twelve on the
|
||||
second; zero after this.
|
||||
|
||||
Reproduced here without a browser, because the mechanism is the kernel's
|
||||
and not the browser's: a child binds a marked grandchild to its job, then
|
||||
is killed outright. The grandchild must not outlive it.
|
||||
"""
|
||||
holder = subprocess.Popen(
|
||||
[sys.executable, "-c",
|
||||
"import subprocess,sys,time;"
|
||||
"sys.path.insert(0, r'" + os.path.dirname(os.path.dirname(
|
||||
os.path.abspath(_reaper.__file__))) + "');"
|
||||
"from invisible_playwright._reaper import SessionToken, guard_for;"
|
||||
"tok=SessionToken.mint();"
|
||||
"env=tok.stamp(__import__('os').environ);"
|
||||
f"kid=subprocess.Popen([sys.executable,'-c','import time; time.sleep({_SLEEP})'],env=env);"
|
||||
"n=guard_for().bind(tok);"
|
||||
"print(kid.pid, n, flush=True);"
|
||||
f"time.sleep({_SLEEP})"],
|
||||
stdout=subprocess.PIPE, text=True,
|
||||
)
|
||||
try:
|
||||
line = holder.stdout.readline().split()
|
||||
assert len(line) == 2, f"the holder did not report: {line!r}"
|
||||
kid_pid, bound = int(line[0]), int(line[1])
|
||||
assert bound >= 1, "nothing was bound to the job, so nothing is guaranteed"
|
||||
assert psutil.pid_exists(kid_pid)
|
||||
|
||||
psutil.Process(holder.pid).kill() # no __exit__, no finally, no atexit
|
||||
holder.wait(timeout=10)
|
||||
|
||||
deadline = time.time() + 10
|
||||
while time.time() < deadline and psutil.pid_exists(kid_pid):
|
||||
time.sleep(0.2)
|
||||
assert not psutil.pid_exists(kid_pid), (
|
||||
f"pid {kid_pid} outlived the process that owned its job - this is "
|
||||
"exactly the leak"
|
||||
)
|
||||
finally:
|
||||
_reap_all(holder)
|
||||
|
||||
|
||||
def test_binding_reports_zero_rather_than_claiming_a_guarantee_it_lacks():
|
||||
"""0 means the guarantee is NOT in place, and callers can tell.
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
"""The reaper's guarantee that exists on Windows only: a job object takes the tree down when its owner is killed.
|
||||
|
||||
``test_the_tree_dies_when_this_process_is_KILLED_not_merely_closed`` is skipped on every other system (job objects are a Windows mechanism), and a skip is
|
||||
red in the whole unit suite of the candidate, so it is a file of its own and only the row of Windows lists it (``tests/test_reaper.py`` keeps what runs on both).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
from invisible_playwright import _reaper
|
||||
|
||||
from test_reaper import _SLEEP, _reap_all
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
psutil = pytest.importorskip("psutil")
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.name != "nt", reason="job objects are a Windows mechanism")
|
||||
def test_the_tree_dies_when_this_process_is_KILLED_not_merely_closed():
|
||||
"""The path that in-process cleanup cannot reach, and the actual bug.
|
||||
|
||||
Measured first, and it corrected the diagnosis: an exception out of the
|
||||
`with` block does NOT leak - __exit__ runs, Playwright tears down, zero
|
||||
survivors over an interleaved A/B with the reaper disabled. The leak was
|
||||
the timeout path, where the runner is killed and __exit__ never executes.
|
||||
With a real browser: eight survivors on the first attempt, twelve on the
|
||||
second; zero after this.
|
||||
|
||||
Reproduced here without a browser, because the mechanism is the kernel's
|
||||
and not the browser's: a child binds a marked grandchild to its job, then
|
||||
is killed outright. The grandchild must not outlive it.
|
||||
"""
|
||||
holder = subprocess.Popen(
|
||||
[sys.executable, "-c",
|
||||
"import subprocess,sys,time;"
|
||||
"sys.path.insert(0, r'" + os.path.dirname(os.path.dirname(
|
||||
os.path.abspath(_reaper.__file__))) + "');"
|
||||
"from invisible_playwright._reaper import SessionToken, guard_for;"
|
||||
"tok=SessionToken.mint();"
|
||||
"env=tok.stamp(__import__('os').environ);"
|
||||
f"kid=subprocess.Popen([sys.executable,'-c','import time; time.sleep({_SLEEP})'],env=env);"
|
||||
"n=guard_for().bind(tok);"
|
||||
"print(kid.pid, n, flush=True);"
|
||||
f"time.sleep({_SLEEP})"],
|
||||
stdout=subprocess.PIPE, text=True,
|
||||
)
|
||||
try:
|
||||
line = holder.stdout.readline().split()
|
||||
assert len(line) == 2, f"the holder did not report: {line!r}"
|
||||
kid_pid, bound = int(line[0]), int(line[1])
|
||||
assert bound >= 1, "nothing was bound to the job, so nothing is guaranteed"
|
||||
assert psutil.pid_exists(kid_pid)
|
||||
|
||||
psutil.Process(holder.pid).kill() # no __exit__, no finally, no atexit
|
||||
holder.wait(timeout=10)
|
||||
|
||||
deadline = time.time() + 10
|
||||
while time.time() < deadline and psutil.pid_exists(kid_pid):
|
||||
time.sleep(0.2)
|
||||
assert not psutil.pid_exists(kid_pid), (
|
||||
f"pid {kid_pid} outlived the process that owned its job - this is "
|
||||
"exactly the leak"
|
||||
)
|
||||
finally:
|
||||
_reap_all(holder)
|
||||
@@ -16,7 +16,6 @@ its whole job before a process exists.
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
@@ -28,7 +27,6 @@ from invisible_core.seal import (
|
||||
JUGGLER_ENTRIES,
|
||||
EngineMismatch,
|
||||
_reset_active_seal_for_tests,
|
||||
read_engine_identity,
|
||||
)
|
||||
from invisible_playwright import _engine
|
||||
|
||||
@@ -162,20 +160,3 @@ def test_no_binary_path_goes_through_ensure_binary(tmp_path, active, monkeypatch
|
||||
monkeypatch.setattr(_engine, "ensure_binary", fake_ensure)
|
||||
assert _engine.resolve_executable(None) == sentinel
|
||||
assert calls and calls[0] is not None, "the resolved seal must be passed down"
|
||||
|
||||
|
||||
def test_real_stock_firefox_via_binary_path_is_refused(active):
|
||||
"""The cell as it exists on this machine, not a synthetic stand-in. Read
|
||||
only; skips cleanly when no bundled Playwright Firefox is present."""
|
||||
local = os.environ.get("LOCALAPPDATA") or str(Path.home() / "AppData/Local")
|
||||
roots = [Path(local) / "ms-playwright", Path.home() / ".cache" / "ms-playwright"]
|
||||
entries = [d / "firefox" / ENTRY_REL for root in roots if root.is_dir()
|
||||
for d in sorted(root.glob("firefox-*"))]
|
||||
entries = [e for e in entries if e.exists()]
|
||||
if not entries:
|
||||
pytest.skip("no bundled stock Firefox on this machine")
|
||||
for entry in entries:
|
||||
ident = read_engine_identity(entry)
|
||||
with pytest.raises(EngineMismatch):
|
||||
_engine.resolve_executable(entry)
|
||||
assert ident.marked_entries == 0, f"{entry} unexpectedly carries our marker"
|
||||
@@ -0,0 +1,75 @@
|
||||
"""A test that needs a driver bundle tree, which only a machine that has one can give it.
|
||||
|
||||
``test_the_injected_sources_have_balanced_quotes`` reads ``coreBundle.js`` of the tree ``INVPW_DRIVER_TREE`` names (a git worktree, or a fresh
|
||||
upstream bundle being considered for extraction); the driver was removed from this checkout on 2026-08-28, so with no variable it skips. A skip is red
|
||||
in the whole unit suite of the candidate, so the test lives in its own file: ``tests/test_fork.py`` holds the checks of the fork that run on every
|
||||
machine, and this one is not in the rows of ``ci/required-suites.json``. It is a file of the environment of ``tests/test_the_unit_suite_is_accounted_for.py``.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import pathlib
|
||||
import re
|
||||
|
||||
import pytest
|
||||
|
||||
from test_fork import _unprotected_quote
|
||||
|
||||
|
||||
def _injected_sources():
|
||||
"""The strings the bundle injects into the page, one per physical line.
|
||||
|
||||
They are declared as ``sourceN = '...'`` with SINGLE quotes and with newlines
|
||||
written as two characters, so each one occupies a single line of the file.
|
||||
"""
|
||||
# ⛔ THE BUNDLE MAY NOT BE HERE ANY MORE, and that is not a broken tree:
|
||||
# the driver was removed on 2026-08-28. The defect this scans for lives in
|
||||
# a SINGLE-QUOTED JavaScript string inside that bundle, so with the bundle
|
||||
# gone the class is gone with it - our `injected.js` is a plain file, where
|
||||
# an apostrophe in a comment is just an apostrophe.
|
||||
#
|
||||
# It is kept reachable rather than deleted because the check still applies
|
||||
# to any bundle somebody points at: `INVPW_DRIVER_TREE` from a git worktree,
|
||||
# or a fresh upstream one being considered for extraction.
|
||||
import os
|
||||
|
||||
tree = os.environ.get("INVPW_DRIVER_TREE")
|
||||
root = (pathlib.Path(tree) if tree
|
||||
else pathlib.Path(__file__).resolve().parent.parent)
|
||||
bundle = (root / "src" / "invisible_playwright" / "_driver" / "package"
|
||||
/ "lib" / "coreBundle.js")
|
||||
if not bundle.is_file():
|
||||
return
|
||||
text = bundle.read_text(encoding="utf-8", errors="replace")
|
||||
for number, line in enumerate(text.splitlines(), 1):
|
||||
m = re.match(r"^\s*(source\d*) = '", line)
|
||||
if m:
|
||||
yield number, m.group(1), line
|
||||
|
||||
|
||||
def test_the_injected_sources_have_balanced_quotes():
|
||||
"""An apostrophe in a comment closes the string and breaks the whole bundle.
|
||||
|
||||
Happened on 2026-08-24: an Italian comment added inside ``source4``
|
||||
contained ``piu'`` and ``cioe'``. The string closed right there, the file
|
||||
became invalid JavaScript and the driver stopped starting at all.
|
||||
|
||||
The defect is not visible to the eye - those lines are hundreds of
|
||||
thousands of characters long - and no test that only imports the Python
|
||||
package sees it. No Node required: it holds even where the runtime has not
|
||||
been downloaded yet.
|
||||
"""
|
||||
found = list(_injected_sources())
|
||||
if not found:
|
||||
# ⛔ NOT AN ASSERTION FAILURE. With no bundle reachable there is
|
||||
# nothing of this shape to check, and the defect class went with it -
|
||||
# see `_injected_sources`. Saying "no injected source found" as a
|
||||
# failure would turn a deliberate deletion into a permanent red.
|
||||
pytest.skip("no driver bundle reachable: nothing of this shape exists "
|
||||
"to check. Point INVPW_DRIVER_TREE at a worktree to run "
|
||||
"it against one.")
|
||||
for number, name, line in found:
|
||||
rest = _unprotected_quote(line)
|
||||
assert rest is None, (
|
||||
"coreBundle.js:%d, %s: the injected string closes too early, "
|
||||
"what remains after it is %r - almost always an apostrophe inside a "
|
||||
"comment" % (number, name, rest))
|
||||
@@ -86,36 +86,6 @@ def test_an_entry_is_a_reviewed_sentence_of_a_closed_kind():
|
||||
assert item["rule"] in clocks.RULES and item["class"] == clocks.CLASS[item["rule"]], item
|
||||
|
||||
|
||||
def _main_document():
|
||||
"""The list of main, or None when it has none; the reason of the miss otherwise."""
|
||||
for ref in ("origin/main", "main"):
|
||||
shown = subprocess.run(["git", "show", "%s:%s" % (ref, GATE)], cwd=ROOT, capture_output=True, text=True)
|
||||
if shown.returncode == 0:
|
||||
return json.loads(shown.stdout), ref
|
||||
if subprocess.run(["git", "cat-file", "-e", ref], cwd=ROOT, capture_output=True).returncode == 0:
|
||||
return None, ref # the ref exists and the file does not: main has no list yet (the merge that brings this one)
|
||||
return "no ref", None
|
||||
|
||||
|
||||
def test_the_debt_does_not_grow_against_main():
|
||||
"""THE HONEST LIMIT OF A UNIT TEST: it can be changed together with the list. Reading the list from MAIN is what stops that, and main is only there when the
|
||||
checkout has it: the pull-request job fetches it (tests.yml); a developer without it skips, and a CI run without it is red (a comparison that compares nothing is
|
||||
not a green)."""
|
||||
document, ref = _main_document()
|
||||
if document == "no ref":
|
||||
if os.environ.get("GITHUB_ACTIONS"):
|
||||
pytest.fail("origin/main is not in this checkout, so the debt cannot be compared with it: fetch it (git fetch origin main) before the tests")
|
||||
pytest.skip("no origin/main in this checkout: the debt is not compared with main (CI does)")
|
||||
if document is None:
|
||||
return # main has no list: this is the change that brings it, there is nothing to grow from
|
||||
main_debt = {clocks.key_of(i) for i in document["debt"]}
|
||||
main_entries = {clocks.key_of(i) for i in document["entries"]}
|
||||
grown = sorted(k for k in (clocks.key_of(i) for i in clocks.load()["debt"]) if k not in main_debt and k not in main_entries)
|
||||
assert grown == [], (
|
||||
"the debt has occurrences that %s does not have: a test that was clean on main now waits on a clock, shares a port or reaches the world. Correct it; "
|
||||
"the debt only shrinks. %s" % (ref, grown))
|
||||
|
||||
|
||||
def test_the_conftest_declares_the_exit_of_the_lab():
|
||||
assert clocks.analyze_conftest((ROOT / "tests" / "conftest.py").read_text(encoding="utf-8")) == []
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
"""A test of the clone it runs in: ``core.hooksPath`` points at ``.githooks`` only in a clone somebody armed.
|
||||
|
||||
``git`` does not arm a checked-in hook directory; a developer does it once per clone (``invisible_core.testing.assert_hooks_are_armed`` says how). The
|
||||
checkout of the CI jobs is a fresh one and never has it, so the test is red there for a reason that is not the code. It lives in its own file, out of
|
||||
``tests/test_publish_gate_wiring.py`` (which holds the wiring of the gate, true in any checkout), and is a file of the environment of
|
||||
``tests/test_the_unit_suite_is_accounted_for.py``.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import pathlib
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
_REPO = pathlib.Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def test_the_hooks_are_armed_in_this_clone():
|
||||
"""A checked-in hook directory does nothing until core.hooksPath points at
|
||||
it, and git will not do that for you.
|
||||
|
||||
Until 2026-07-27 both the installer and this reminder lived in the core, so
|
||||
THIS repo shipped a hook that nothing armed and nothing checked was armed:
|
||||
a fresh clone pushed with the tests, the pin, the name scan and the publish
|
||||
gate all skipped, and said nothing about it.
|
||||
"""
|
||||
from invisible_core.testing import assert_hooks_are_armed
|
||||
|
||||
assert_hooks_are_armed(_REPO)
|
||||
@@ -0,0 +1,52 @@
|
||||
"""A test of the clone it runs in: ``origin/main`` is a ref only in a clone that fetched it.
|
||||
|
||||
``test_the_debt_does_not_grow_against_main`` reads the list of clock exceptions from ``origin/main``; the checkout of the candidate job has no such ref
|
||||
("origin/main is not in this checkout"), so it is red there for a reason that is not the code. The pull-request job fetches main and runs it
|
||||
(``tests.yml``). It lives in its own file, out of ``tests/test_the_e2e_tests_do_not_wait_on_clocks.py`` (the rules, true in any checkout), and is a file of the
|
||||
environment of ``tests/test_the_unit_suite_is_accounted_for.py``.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
import _e2e_clocks as clocks
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
GATE = "tests/gates/e2e_clock_exceptions.json"
|
||||
|
||||
|
||||
def _main_document():
|
||||
"""The list of main, or None when it has none; the reason of the miss otherwise."""
|
||||
for ref in ("origin/main", "main"):
|
||||
shown = subprocess.run(["git", "show", "%s:%s" % (ref, GATE)], cwd=ROOT, capture_output=True, text=True)
|
||||
if shown.returncode == 0:
|
||||
return json.loads(shown.stdout), ref
|
||||
if subprocess.run(["git", "cat-file", "-e", ref], cwd=ROOT, capture_output=True).returncode == 0:
|
||||
return None, ref # the ref exists and the file does not: main has no list yet (the merge that brings this one)
|
||||
return "no ref", None
|
||||
|
||||
|
||||
def test_the_debt_does_not_grow_against_main():
|
||||
"""THE HONEST LIMIT OF A UNIT TEST: it can be changed together with the list. Reading the list from MAIN is what stops that, and main is only there when the
|
||||
checkout has it: the pull-request job fetches it (tests.yml); a developer without it skips, and a CI run without it is red (a comparison that compares nothing is
|
||||
not a green)."""
|
||||
document, ref = _main_document()
|
||||
if document == "no ref":
|
||||
if os.environ.get("GITHUB_ACTIONS"):
|
||||
pytest.fail("origin/main is not in this checkout, so the debt cannot be compared with it: fetch it (git fetch origin main) before the tests")
|
||||
pytest.skip("no origin/main in this checkout: the debt is not compared with main (CI does)")
|
||||
if document is None:
|
||||
return # main has no list: this is the change that brings it, there is nothing to grow from
|
||||
main_debt = {clocks.key_of(i) for i in document["debt"]}
|
||||
main_entries = {clocks.key_of(i) for i in document["entries"]}
|
||||
grown = sorted(k for k in (clocks.key_of(i) for i in clocks.load()["debt"]) if k not in main_debt and k not in main_entries)
|
||||
assert grown == [], (
|
||||
"the debt has occurrences that %s does not have: a test that was clean on main now waits on a clock, shares a port or reaches the world. Correct it; "
|
||||
"the debt only shrinks. %s" % (ref, grown))
|
||||
@@ -0,0 +1,30 @@
|
||||
"""A test that needs the workbench of the person who runs it, next to the checkout.
|
||||
|
||||
``test_the_workbench_inventory_and_the_package_cannot_DRIFT`` reads ``scripts/inventario_voce6.py`` three directories above this file, where a
|
||||
developer's workbench is; a clean clone of the repository (the CI job) has no such folder, so the test skips, and a skip is red in the whole unit suite
|
||||
of the candidate. It lives in its own file, out of ``tests/test_juggler_transport.py`` (which holds what runs on every machine), and is a file of the
|
||||
environment of ``tests/test_the_unit_suite_is_accounted_for.py``.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import pathlib
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def test_the_workbench_inventory_and_the_package_cannot_DRIFT():
|
||||
"""⛔ There is one perimeter and it lives in the shipped package. The
|
||||
workbench tool that counts remaining work reads it from there; if it kept
|
||||
its own copy the two would disagree the first time one was edited - and the
|
||||
one that matters, the one that REFUSES, would be the one nobody updated."""
|
||||
from invisible_playwright._juggler import perimeter
|
||||
tool = pathlib.Path(__file__).resolve().parents[3] / "scripts" \
|
||||
/ "inventario_voce6.py"
|
||||
if not tool.exists():
|
||||
pytest.skip("the workbench is not next to this checkout")
|
||||
source = tool.read_text(encoding="utf-8", errors="replace")
|
||||
assert "_fuori_dal_pacchetto" in source, (
|
||||
"the inventory no longer reads the package: it has grown its own copy "
|
||||
"of the perimeter")
|
||||
assert "perimeter.py" in source
|
||||
assert len(perimeter.OUTSIDE) > 50
|
||||
Reference in new issue
Block a user