Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
7325872
test(perf): count budgets for outdated and update (journey family 2)
danielmeppiel Nov 24, 2026
5df8a21
test(perf): count budgets for authenticated cold and warm installs (t…
danielmeppiel Nov 24, 2026
e05f4e0
test(perf): baseline budgets for outdated, update and the authenticat…
danielmeppiel Nov 24, 2026
152f409
test(perf): stamp the family 2 budget rows with their PR
danielmeppiel Nov 24, 2026
7f722f4
Merge branch 'ql/w2c-perf-count-budgets' into ql/w2c-perf-budgets-update
danielmeppiel Nov 24, 2026
4c9a8d8
test(perf): count hashlib.new and hashlib.file_digest in the hash cou…
danielmeppiel Nov 24, 2026
5d9bc93
test(perf): re-budget the hash counters now that hashlib.new and file…
danielmeppiel Nov 24, 2026
95480a7
test(perf): run the count-budget world at a fixed path depth
danielmeppiel Nov 24, 2026
56a9070
Merge commit 'refs/w2c/main' into ql/w2c-perf-budgets-update
danielmeppiel Nov 24, 2026
f907194
test(perf): re-budget every row measured at the fixed path depth
danielmeppiel Nov 24, 2026
b55eba9
Merge commit 'refs/w2c/main' into ql/w2c-perf-budgets-update
danielmeppiel Nov 24, 2026
2714cab
test(perf): re-budget on main with #5325/#5333 (interim; re-measured …
danielmeppiel Nov 24, 2026
baa516b
Merge #5340 (count budgets follow #5330) into ql/w2c-perf-budgets-upd…
danielmeppiel Nov 24, 2026
3f167d2
test(perf): budget rows for outdated, update and the authenticated jo…
danielmeppiel Nov 24, 2026
ccda562
Merge commit 'refs/w2c/main' into ql/w2c-perf-budgets-update
danielmeppiel Nov 24, 2026
0c60e29
test(perf): anonymous journeys pin auth-first off; outdated and auth …
danielmeppiel Nov 24, 2026
24dddd7
test(perf): outdated lstat/realpath budgets hold in the Integration job
danielmeppiel Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions tests/fixtures/perf/count_budgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@
from pathlib import Path

BUDGETS_PATH = Path(__file__).resolve().parents[2] / "perf" / "count_budgets.json"
# The journeys PR 1 of the engine budgets, all at tree-10, offline mirror, rtt 0.
JOURNEYS = ("install-cold", "install-warm", "install-noop")
# The budgeted journeys, all at tree-10, offline mirror, rtt 0.
JOURNEYS = (
"install-cold",
"install-warm",
"install-noop",
"outdated",
"update",
"install-cold-auth",
"install-warm-auth",
)
_FS_COUNTERS = (
"files_written",
"lockfile_reads",
Expand Down
102 changes: 90 additions & 12 deletions tests/integration/test_perf_count_budgets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Performance promise engine, layer 1: install count budgets (P-PERF-count-budgets).
"""Performance promise engine, layer 1: count budgets (P-PERF-count-budgets).

Counts, not time: git spawns by verb, HTTP requests and connects, files and
bytes hashed, files written, realpath/stat/lstat calls and lockfile reads are
Expand All @@ -7,7 +7,11 @@

- install-cold: an empty download cache and a fresh checkout;
- install-noop: the same project again, everything installed;
- install-warm: a fresh checkout with the cache the cold install filled.
- install-warm: a fresh checkout with the cache the cold install filled;
- outdated: that installed project asks which dependencies have newer refs;
- update: ``update -y`` on that project, with nothing newer to take;
- install-cold-auth / install-warm-auth: cold and warm again for an authenticated
user (a token, auth tried first: the token-first git path private hosts take).

Each journey's counters must stay within ``tests/perf/count_budgets.json``.
Over budget, or a counter with no row, fails with the diff; a counter well under
Expand All @@ -24,7 +28,10 @@
import os
import shutil
import sys
import tempfile
import warnings
from collections.abc import Iterator
from pathlib import Path

import pytest

Expand All @@ -42,6 +49,9 @@
]

_TREE = "tree-10"
_FIXED_ROOT = "/tmp"
# A fixed placeholder token the offline mirror accepts; auth is tried first.
_AUTH = {"GITHUB_APM_PAT": "ghp_" + "0" * 36, "APM_GITHUB_AUTH_FIRST": "1"}
_MEASURE = os.environ.get("APM_PERF_COUNT_BUDGETS_MEASURE") == "1"


Expand All @@ -50,11 +60,20 @@ class TightenNote(UserWarning):


@pytest.fixture(scope="module")
def journey_runs(tmp_path_factory, apm_engine_command) -> dict[str, tuple]:
"""Run install cold, no-op and warm once; each journey's flattened counters."""
work = tmp_path_factory.mktemp("perf-count-budgets")
def journey_runs(apm_engine_command) -> Iterator[dict[str, tuple]]:
"""Run every journey once, in order; each journey's result, lockfile and counters."""
# realpath lstat()s every path component, so the counts depend on how deep the world
# sits. pytest's basetemp depth differs between jobs (xdist adds popen-gwN/), so the
# world lives at a fixed depth instead: /tmp/apm-perf-<random>.
work = Path(tempfile.mkdtemp(prefix="apm-perf-", dir=_FIXED_ROOT))
try:
yield _run_journeys(work, list(apm_engine_command))
finally:
shutil.rmtree(work, ignore_errors=True)


def _run_journeys(work: Path, apm: list[str]) -> dict[str, tuple]:
tree = build_tree(TREE_RECIPES[_TREE], work / "tree")
apm = list(apm_engine_command)
runs: dict[str, tuple] = {}
with serve_offline(tree, work / "world") as world:
project = work / "project"
Expand All @@ -64,25 +83,37 @@ def checkout() -> None:
shutil.rmtree(project)
shutil.copytree(tree.project, project)

def install(journey: str) -> None:
def run(journey: str, *args: str, env: dict[str, str] | None = None) -> None:
world.reset_traffic()
result, counts = run_counted(
[*apm, "install"], cwd=project, env=world.env, log=work / f"{journey}.jsonl"
[*apm, *args],
cwd=project,
# An inherited APM_GITHUB_AUTH_FIRST=1 would move the anonymous
# journeys onto the token-first path; only _AUTH turns it on.
env={**world.env, "APM_GITHUB_AUTH_FIRST": "0", **(env or {})},
log=work / f"{journey}.jsonl",
)
locked = (project / "apm.lock.yaml").is_file()
runs[journey] = (result, locked, flatten(counts, world.traffic().as_dict()))

world.clear_cache()
checkout()
install("install-cold")
install("install-noop")
run("install-cold", "install")
run("install-noop", "install")
checkout()
install("install-warm")
run("install-warm", "install")
run("outdated", "outdated")
Comment thread
danielmeppiel marked this conversation as resolved.
Resolved
run("update", "update", "-y")
world.clear_cache()
checkout()
run("install-cold-auth", "install", env=_AUTH)
checkout()
run("install-warm-auth", "install", env=_AUTH)
Comment thread
danielmeppiel marked this conversation as resolved.
Resolved
return runs


@pytest.mark.parametrize("journey", JOURNEYS)
def test_install_stays_within_its_count_budget(journey: str, journey_runs) -> None:
def test_journey_stays_within_its_count_budget(journey: str, journey_runs) -> None:
result, locked, observed = journey_runs[journey]
output = f"{result.stdout[-3000:]}\n{result.stderr[-3000:]}"
assert result.returncode == 0, f"{journey} exited {result.returncode}:\n{output}"
Expand All @@ -97,6 +128,27 @@ def test_install_stays_within_its_count_budget(journey: str, journey_runs) -> No
assert not over, "count budget exceeded:\n" + "\n".join(over)


def test_the_hash_counters_see_hashlib_new_and_file_digest(tmp_path: Path) -> None:
"""hashlib.new (git object ids) and hashlib.file_digest (drift records) are counted."""
data = tmp_path / "data.bin"
data.write_bytes(b"x" * 1000)
script = (
"import hashlib, sys\n"
"hashlib.new('sha1', b'abc', usedforsecurity=False).hexdigest()\n"
"with open(sys.argv[1], 'rb') as handle:\n"
" hashlib.file_digest(handle, 'sha256').hexdigest()\n"
)
result, counts = run_counted(
[sys.executable, "-c", script, str(data)],
Comment thread
danielmeppiel marked this conversation as resolved.
Resolved
cwd=tmp_path,
env=dict(os.environ),
log=tmp_path / "counts.jsonl",
)
assert result.returncode == 0, result.stderr
assert counts["fs"]["hash_objects"] == 2, counts["fs"]
assert counts["fs"]["hashed_bytes"] == 3 + 1000, counts["fs"]


def test_cold_install_fetches_while_noop_fetches_nothing(journey_runs) -> None:
"""The counters see the work: a cold install fetches over HTTP, a no-op does not.

Expand All @@ -111,3 +163,29 @@ def test_cold_install_fetches_while_noop_fetches_nothing(journey_runs) -> None:
# Engagement oracle: if the in-process fetch stops engaging, clones come back.
assert cold.get("git.clone", 0) == 0 and cold["http.requests"] > 0, cold
assert noop.get("git.clone", 0) == 0 and noop["http.requests"] == 0, noop


def test_authenticated_cold_install_clones_with_git(journey_runs) -> None:
"""The fallback half of the engagement oracle: a token never takes the in-process fetch.

``inprocess_fetch._gate`` only admits a provably anonymous request, so an
authenticated cold install clones every package with git over HTTP.
"""
cold_run, _, cold = journey_runs["install-cold-auth"]
assert cold_run.returncode == 0, cold_run.stderr
assert cold.get("git.clone", 0) > 0 and cold["http.requests"] > 0, cold


def test_outdated_and_auth_journeys_took_the_path_they_budget(journey_runs) -> None:
"""Each journey measured the path it names, not a degraded one with lower counts.

``outdated`` reports a failed comparison as an ``unknown`` row and still exits 0,
and a lost token-first selection runs the auth journeys anonymously; both only
lower counts, which the budgets report as tighten notes, not failures.
"""
outdated_run, _, _ = journey_runs["outdated"]
assert "All dependencies are up-to-date" in outdated_run.stdout, outdated_run.stdout
for journey in ("install-cold-auth", "install-warm-auth"):
_, _, observed = journey_runs[journey]
# Token first: one ref probe per tree package before any fetch.
assert observed.get("git.ls-remote", 0) == 10, (journey, observed)
Loading
Loading