ci: the host oracle lists what the idle launch left in the places of the shortcut code
On Windows the idle launch of each engine run is bracketed by two snapshots of the places the shortcut code reads and writes: the Start menu of the user and of ProgramData (Programs below them), the Desktop of the user and the Public one, the pinned taskbar shortcuts and ImplicitAppShortcuts, and every Mozilla-* folder of ProgramData (the shortcuts log is there). The files that are new, changed or gone (name, size, mtime) are kept in the footprint and summarized in one line of the report (SHORTCUTS ...): the direct proof of whether the engine leaves a shortcut or a log on the host. Evidence, not compared. The Create disposition stays.
This commit is contained in:
1 parent
b825a5542b
commit
39fd73116a
2 files changed
+139
-1
No files matched your search
+75
-1
@@ -79,6 +79,7 @@ from __future__ import annotations
|
||||
import argparse
|
||||
import codecs
|
||||
import contextlib
|
||||
import datetime
|
||||
import collections
|
||||
import ipaddress
|
||||
import json
|
||||
@@ -1513,6 +1514,7 @@ def judge(a: dict, b: dict, expected: list | None = None, a_a: bool = False, pla
|
||||
"differences": differences, "declared": declared, "ours": OURS, "tab": {"reason": TAB_REASON, "counts": tab},
|
||||
"outside_tree": outside, "warmup": dict(warm, both=both), "idle": {side: _idle_summary(fp.get("idle")) for side, fp in (("A", a), ("B", b))},
|
||||
"bare": {side: _bare_summary((fp.get("bare") or {}).get("bare")) for side, fp in (("A", a), ("B", b))},
|
||||
"shortcuts": {side: _shortcuts_summary(((fp.get("idle") or {}).get("idle") or {}).get("shortcut_changes")) for side, fp in (("A", a), ("B", b))},
|
||||
"stale": [e.get("id") for e in stale], "leaves": counts, "net": net}
|
||||
|
||||
|
||||
@@ -1532,6 +1534,11 @@ def print_report(report: dict, a_name: str, b_name: str) -> None:
|
||||
print("WARMUP-ONLY %s seed %s file.%s (touched by: %s)" % (name, warm["seed"], f["path"], ", ".join(f["touched_by"]) or "-"))
|
||||
for entry in warm.get("net", [])[:100]:
|
||||
print("WARMUP-ONLY %s seed %s net.%s" % (name, warm["seed"], entry))
|
||||
for side, name in (("A", a_name), ("B", b_name)):
|
||||
shortcuts = (report.get("shortcuts") or {}).get(side)
|
||||
if shortcuts:
|
||||
print("SHORTCUTS (the places of the shortcut code, before and after the idle launch; evidence) %s: %d new, %d changed, %d gone %s" % (
|
||||
name, shortcuts["new"], shortcuts["changed"], shortcuts["gone"], json.dumps(shortcuts["files"])))
|
||||
for side, name in (("A", a_name), ("B", b_name)):
|
||||
bare = (report.get("bare") or {}).get(side)
|
||||
if bare:
|
||||
@@ -1676,6 +1683,8 @@ def run_seed(binary: str, seed: int, work: Path, name: str | None = None, idle:
|
||||
geo_origin, stop_geo = start_geo_lab()
|
||||
server, steps, root_pid = None, [], None
|
||||
notified, watcher = None, None
|
||||
places = shortcut_places() if (windows and idle) else None
|
||||
shortcuts_before = snapshot_places(places) if places else None
|
||||
before = set(Path(tempfile.gettempdir()).glob("invisible_profile_*"))
|
||||
|
||||
def crash_dirs():
|
||||
@@ -1738,7 +1747,7 @@ def run_seed(binary: str, seed: int, work: Path, name: str | None = None, idle:
|
||||
problems.append("the tree did not exit within %d s of the close: the trace is cut short" % EXIT_LIMIT_S)
|
||||
result = _seed_result(binary, seed, seed_work, steps, log, trace, root_pid, windows, close)
|
||||
if idle:
|
||||
result["idle"] = {"notified": notified}
|
||||
result["idle"] = {"notified": notified, "shortcut_changes": diff_snapshots(shortcuts_before, snapshot_places(places)) if places else None}
|
||||
if bare:
|
||||
result["bare"] = {"notified": notified, "crash": crash_evidence(watcher.stop(), result, core_info(seed_work, binary) if not windows else None)}
|
||||
watcher = None
|
||||
@@ -1859,6 +1868,71 @@ def crash_evidence(watched: dict, fp: dict, core: dict | None = None) -> dict:
|
||||
"files": watched.get("files", []), "scans": watched.get("scans"), "core": core}
|
||||
|
||||
|
||||
def shortcut_places(env=None) -> list:
|
||||
"""`[(folder, recursive)]` of the places the shortcut code of Windows reads and writes (StartupOSIntegration.sys.mjs, nsWindowsShellService.cpp): the Start menu of the
|
||||
user and of ProgramData (its Programs below it), the Desktop of the user and the Public one, the pinned taskbar shortcuts of the user (and ImplicitAppShortcuts) and every
|
||||
`Mozilla-*` folder of ProgramData (the shortcuts log is there)."""
|
||||
env = os.environ if env is None else env
|
||||
appdata, programdata = env.get("APPDATA"), env.get("ProgramData") or env.get("PROGRAMDATA")
|
||||
profile, public = env.get("USERPROFILE"), env.get("PUBLIC")
|
||||
places = []
|
||||
for base in (appdata and Path(appdata) / "Microsoft" / "Windows" / "Start Menu", programdata and Path(programdata) / "Microsoft" / "Windows" / "Start Menu"):
|
||||
if base:
|
||||
places += [(base, False), (base / "Programs", True)]
|
||||
for desktop in (profile and Path(profile) / "Desktop", public and Path(public) / "Desktop"):
|
||||
if desktop:
|
||||
places.append((desktop, False))
|
||||
if appdata:
|
||||
pinned = Path(appdata) / "Microsoft" / "Internet Explorer" / "Quick Launch" / "User Pinned"
|
||||
places += [(pinned / "TaskBar", True), (pinned / "ImplicitAppShortcuts", True)]
|
||||
if programdata:
|
||||
try:
|
||||
places += [(p, True) for p in sorted(Path(programdata).glob("Mozilla-*")) if p.is_dir()]
|
||||
except OSError:
|
||||
pass
|
||||
return places
|
||||
|
||||
|
||||
def snapshot_places(places, limit: int = 20000) -> dict:
|
||||
"""`{path: {"size", "mtime_ns"}}` of the files in `places` (`shortcut_places`), a folder walked below itself when it says so."""
|
||||
out: dict = {}
|
||||
for folder, recursive in places:
|
||||
try:
|
||||
entries = Path(folder).rglob("*") if recursive else Path(folder).iterdir()
|
||||
for entry in entries:
|
||||
if len(out) >= limit:
|
||||
return out
|
||||
try:
|
||||
if entry.is_file():
|
||||
st = entry.stat()
|
||||
out[str(entry)] = {"size": st.st_size, "mtime_ns": st.st_mtime_ns}
|
||||
except OSError:
|
||||
continue
|
||||
except OSError:
|
||||
continue
|
||||
return out
|
||||
|
||||
|
||||
def diff_snapshots(before: dict, after: dict) -> dict:
|
||||
"""The files that are new, changed (another size or modification time) or gone between two snapshots, each `{"path", "size", "mtime"}` (the mtime as an ISO
|
||||
text, evidence): the direct proof of whether the engine left a shortcut or a log on the host."""
|
||||
def entry(path, info):
|
||||
stamp = datetime.datetime.fromtimestamp(info["mtime_ns"] / 1e9, datetime.timezone.utc).isoformat()
|
||||
return {"path": path, "size": info["size"], "mtime": stamp}
|
||||
|
||||
return {"new": [entry(p, after[p]) for p in sorted(set(after) - set(before))],
|
||||
"changed": [entry(p, after[p]) for p in sorted(set(after) & set(before)) if after[p] != before[p]],
|
||||
"gone": [entry(p, before[p]) for p in sorted(set(before) - set(after))]}
|
||||
|
||||
|
||||
def _shortcuts_summary(changes: dict | None) -> dict | None:
|
||||
"""A line's worth of `diff_snapshots`: how many files, and which ones by name."""
|
||||
if changes is None:
|
||||
return None
|
||||
return {"new": len(changes["new"]), "changed": len(changes["changed"]), "gone": len(changes["gone"]),
|
||||
"files": [(kind, Path(e["path"]).name, e["size"]) for kind in ("new", "changed", "gone") for e in changes[kind]][:20]}
|
||||
|
||||
|
||||
def wait_for_notification(read, period=NOTIFY_PERIOD_S, limit_s=NOTIFY_LIMIT_S, sleep=time.sleep, now=time.monotonic) -> dict:
|
||||
"""Reads the profile's prefs (`read()` returns the text of prefs.js, or None while there is none) until the notification of the data policy is recorded in it, or
|
||||
until `limit_s`: `{"observed": bool, "polls": n}`. The event is the verdict; the limit only ends the wait of a launch that never gets there."""
|
||||
|
||||
@@ -1757,3 +1757,67 @@ def test_the_report_carries_the_bare_launch_without_comparing_it(capsys):
|
||||
assert report["bare"]["A"]["crash_processes"] == [("crashreporter", "crashreporter --ping-cleanup /x /y")] and report["bare"]["B"]["crash_processes"] == []
|
||||
host.print_report(report, "firefox-68", "firefox-68 again")
|
||||
assert "BARE (no client, no page; not compared) firefox-68:" in capsys.readouterr().out
|
||||
|
||||
|
||||
# -
|
||||
# The places of the shortcut code, before and after the idle launch (Windows): the direct proof of whether the engine left a shortcut or a log on the host.
|
||||
|
||||
def a_windows_home(tmp_path):
|
||||
env = {"APPDATA": str(tmp_path / "Roaming"), "ProgramData": str(tmp_path / "ProgramData"), "USERPROFILE": str(tmp_path / "User"), "PUBLIC": str(tmp_path / "Public")}
|
||||
for rel in ("Roaming/Microsoft/Windows/Start Menu/Programs/Accessories", "ProgramData/Microsoft/Windows/Start Menu/Programs", "User/Desktop", "Public/Desktop",
|
||||
"Roaming/Microsoft/Internet Explorer/Quick Launch/User Pinned/TaskBar", "Roaming/Microsoft/Internet Explorer/Quick Launch/User Pinned/ImplicitAppShortcuts",
|
||||
"ProgramData/Mozilla-1de4eec8", "ProgramData/Mozilla-other", "ProgramData/NotMozilla"):
|
||||
(tmp_path / rel).mkdir(parents=True)
|
||||
return env
|
||||
|
||||
|
||||
def test_the_places_of_the_shortcut_code_are_the_start_menus_the_desktops_the_pinned_taskbar_and_every_mozilla_folder(tmp_path):
|
||||
env = a_windows_home(tmp_path)
|
||||
places = host.shortcut_places(env)
|
||||
names = [(str(p.relative_to(tmp_path)).replace("\\", "/"), r) for p, r in places]
|
||||
assert ("Roaming/Microsoft/Windows/Start Menu", False) in names and ("Roaming/Microsoft/Windows/Start Menu/Programs", True) in names
|
||||
assert ("ProgramData/Microsoft/Windows/Start Menu/Programs", True) in names and ("User/Desktop", False) in names and ("Public/Desktop", False) in names
|
||||
assert ("Roaming/Microsoft/Internet Explorer/Quick Launch/User Pinned/TaskBar", True) in names
|
||||
assert ("Roaming/Microsoft/Internet Explorer/Quick Launch/User Pinned/ImplicitAppShortcuts", True) in names
|
||||
assert ("ProgramData/Mozilla-1de4eec8", True) in names and ("ProgramData/Mozilla-other", True) in names and not any("NotMozilla" in n for n, _r in names)
|
||||
assert host.shortcut_places({}) == [], "a machine with none of these variables has none of these places"
|
||||
|
||||
|
||||
def test_what_the_launch_made_changed_or_removed_in_those_places_is_the_difference_of_two_snapshots(tmp_path):
|
||||
import os as _os
|
||||
|
||||
env = a_windows_home(tmp_path)
|
||||
places = host.shortcut_places(env)
|
||||
taskbar = tmp_path / "Roaming/Microsoft/Internet Explorer/Quick Launch/User Pinned/TaskBar"
|
||||
log = tmp_path / "ProgramData/Mozilla-1de4eec8/firefox_S-1-5-21-500_shortcuts.ini"
|
||||
log.write_text("[STARTMENU]\n", encoding="utf-8")
|
||||
(taskbar / "old.lnk").write_bytes(b"L")
|
||||
(tmp_path / "User/Desktop/stays.lnk").write_bytes(b"L")
|
||||
before = host.snapshot_places(places)
|
||||
log.write_text("[STARTMENU]\nShortcut0=Firefox.lnk\n", encoding="utf-8")
|
||||
_os.utime(log, (1_700_000_000, 1_700_000_000))
|
||||
(taskbar / "nightly.lnk").write_bytes(b"LNK" * 10)
|
||||
(tmp_path / "Roaming/Microsoft/Windows/Start Menu/Programs/Accessories/Private Browsing.lnk").write_bytes(b"LNK")
|
||||
(taskbar / "old.lnk").unlink()
|
||||
after = host.snapshot_places(places)
|
||||
got = host.diff_snapshots(before, after)
|
||||
assert [Path(e["path"]).name for e in got["new"]] == sorted(["Private Browsing.lnk", "nightly.lnk"], key=str.lower) or {Path(e["path"]).name for e in got["new"]} == {"Private Browsing.lnk", "nightly.lnk"}
|
||||
assert [Path(e["path"]).name for e in got["changed"]] == ["firefox_S-1-5-21-500_shortcuts.ini"] and got["changed"][0]["mtime"].startswith("2023-11-14")
|
||||
assert [Path(e["path"]).name for e in got["gone"]] == ["old.lnk"]
|
||||
assert [e["size"] for e in got["new"] if e["path"].endswith("nightly.lnk")] == [30]
|
||||
assert not any("stays.lnk" in e["path"] for kind in got.values() for e in kind), "a file the launch did not touch is not in it"
|
||||
assert host.diff_snapshots(after, host.snapshot_places(places)) == {"new": [], "changed": [], "gone": []}
|
||||
|
||||
|
||||
def test_a_launch_that_left_nothing_says_so_and_the_report_carries_the_summary_line_without_comparing_it(capsys):
|
||||
a = footprint(platform="win32")
|
||||
a["idle"] = {"seed": 11, "kinds": {}, "idle": {"notified": {"observed": True, "polls": 2}, "shortcut_changes": {
|
||||
"new": [{"path": "C:/ProgramData/Microsoft/Windows/Start Menu/Programs/Private Browsing.lnk", "size": 1650, "mtime": "2026-11-22T05:20:08+00:00"}], "changed": [], "gone": []}}}
|
||||
b = footprint("again", platform="win32")
|
||||
b["idle"] = {"seed": 11, "kinds": {}, "idle": {"notified": {"observed": True, "polls": 2}, "shortcut_changes": {"new": [], "changed": [], "gone": []}}}
|
||||
report = judge(a, b, a_a=True)
|
||||
assert report["shortcuts"] == {"A": {"new": 1, "changed": 0, "gone": 0, "files": [("new", "Private Browsing.lnk", 1650)]}, "B": {"new": 0, "changed": 0, "gone": 0, "files": []}}
|
||||
host.print_report(report, "firefox-68", "firefox-68 again")
|
||||
out = capsys.readouterr().out
|
||||
assert "SHORTCUTS (the places of the shortcut code, before and after the idle launch; evidence) firefox-68: 1 new, 0 changed, 0 gone" in out and "Private Browsing.lnk" in out
|
||||
assert judge(footprint(), footprint("again"), a_a=True)["shortcuts"] == {"A": None, "B": None}, "Linux has none of this"
|
||||
Reference in new issue
Block a user