From 3a6664e83d51ff09e5b2c891a5fdb0e65ac37db4 Mon Sep 17 00:00:00 2001 From: Nicholas Lawrence Date: Thu, 9 Jul 2026 10:07:36 -0700 Subject: [PATCH 1/4] loop: actually consume a runner's self-reported workload_id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #60 added run.workload_id = "vllm-decode" to _vllm_decode_factory's runner, but run_loop never read it: the only consumer, getattr(cfg.engine, "workload_id", None), (a) reads the wrong object (cfg.engine, the raw engine handle — the attribute is set on the runner, not on runner.engine) and (b) runs before cfg.engine is even populated from the runner (that assignment happens several lines later). So the attribute was dead code, and any workload_runner passed without an explicit cfg.workload silently fell back to the hardcoded "vllm-decode" label regardless of what it actually was. Re-check the runner's workload_id after it resolves (and only when the caller didn't pin one explicitly via cfg.workload, which still wins). Added regression tests for both the override and the explicit-wins precedence. Co-Authored-By: Claude Sonnet 5 --- gitm/scheduler/loop.py | 10 ++++++ tests/test_run_loop_workload.py | 64 +++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/gitm/scheduler/loop.py b/gitm/scheduler/loop.py index a3fed2e..b0c02a1 100644 --- a/gitm/scheduler/loop.py +++ b/gitm/scheduler/loop.py @@ -239,6 +239,16 @@ def run_loop(cfg: LoopConfig) -> dict[str, Any]: if cfg.engine is None and runner is not None: cfg.engine = getattr(runner, "engine", None) + # A factory-built runner may know its own workload id better than the + # guessed/default one above (e.g. a caller passed ``workload_runner`` + # directly with no ``cfg.workload``, so ``workload`` fell through to the + # "vllm-decode" default regardless of what the runner actually is). Only + # the runner's own object carries this — earlier ``cfg.engine`` is never + # populated yet — so it must be re-checked here, after resolution, not + # folded into the guess above. + if cfg.workload is None and runner is not None: + workload = getattr(runner, "workload_id", None) or workload + # Sample the engine scheduler (queue depth, batch occupancy, preemptions) # over the same window as the CUPTI capture — engine-level telemetry the GPU # trace can't see. A no-op when no engine is attached (empty series). diff --git a/tests/test_run_loop_workload.py b/tests/test_run_loop_workload.py index 5affde5..c421dae 100644 --- a/tests/test_run_loop_workload.py +++ b/tests/test_run_loop_workload.py @@ -32,6 +32,70 @@ def test_no_data_guard_does_not_fabricate_claims(tmp_path: Path): assert "NO DATA" in result["report_md"] +def test_runner_workload_id_relabels_trace_when_workload_unset(tmp_path: Path, monkeypatch): + """A factory-built runner's own ``workload_id`` (e.g. set by + ``_vllm_decode_factory``, see #60) must relabel the trace/capture call + instead of being silently discarded. + + Regression guard: ``run_loop`` computed its ``workload`` label from + ``cfg.engine.workload_id`` before the runner (and ``cfg.engine``) were even + resolved — the runner's own attribute was set on the wrong object at the + wrong time and was never actually read, so a runner passed via + ``workload_runner`` with no explicit ``cfg.workload`` always fell back to + the hardcoded "vllm-decode" default regardless of what it actually was. + """ + import gitm.scheduler.loop as loop + + captured: dict = {} + + @contextmanager + def fake_capture(out_path, *, workload_id="w", fingerprint="f", run_id=None): + captured["workload_id"] = workload_id + kernels = [make_kernel("k", start_ns=i * 100, end_ns=i * 100 + 90) for i in range(10)] + yield make_trace(events=kernels, vendor="nvidia", run_id=run_id or "r") + + monkeypatch.setattr(loop, "capture", fake_capture) + monkeypatch.setattr(loop, "sync_device", lambda: None) + + def runner(): + return {"events": 1} + + runner.workload_id = "custom-workload" + + from gitm import optimize + + optimize(budget="1s", scratch=str(tmp_path), workload_runner=runner) + + assert captured["workload_id"] == "custom-workload" + + +def test_runner_workload_id_does_not_override_explicit_workload(tmp_path: Path, monkeypatch): + """An explicit ``cfg.workload`` always wins over the runner's self-reported id.""" + import gitm.scheduler.loop as loop + + captured: dict = {} + + @contextmanager + def fake_capture(out_path, *, workload_id="w", fingerprint="f", run_id=None): + captured["workload_id"] = workload_id + kernels = [make_kernel("k", start_ns=i * 100, end_ns=i * 100 + 90) for i in range(10)] + yield make_trace(events=kernels, vendor="nvidia", run_id=run_id or "r") + + monkeypatch.setattr(loop, "capture", fake_capture) + monkeypatch.setattr(loop, "sync_device", lambda: None) + + def runner(): + return {"events": 1} + + runner.workload_id = "custom-workload" + + from gitm import optimize + + optimize(workload="hft", budget="1s", scratch=str(tmp_path), workload_runner=runner) + + assert captured["workload_id"] == "hft" + + def test_runner_runs_inside_capture_and_produces_real_trace(tmp_path: Path, monkeypatch): """An injected runner is invoked inside the capture window; with kernels in the trace the loop proceeds to real claims with a non-empty fingerprint.""" From e4ba57735d4a3fd229bff2454a10ecf812dc0648 Mon Sep 17 00:00:00 2001 From: Nicholas Lawrence Date: Thu, 9 Jul 2026 10:11:21 -0700 Subject: [PATCH 2/4] test: harden workload_id regression coverage per review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the function+monkeypatched-attribute runner double with an explicit _Runner class (a plain function's attribute is fragile if ever wrapped, e.g. functools.partial), de-duplicate the fake_capture setup shared by the workload_id tests, and add the two missing cases a reviewer flagged: an explicit workload_id=None (a real state a factory can leave unset) and a runner with no workload_id attribute at all (the getattr(..., None) default path) — both must fall back to the guessed/default label, not the previously-covered override case. Co-Authored-By: Claude Sonnet 5 --- tests/test_run_loop_workload.py | 95 ++++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 25 deletions(-) diff --git a/tests/test_run_loop_workload.py b/tests/test_run_loop_workload.py index c421dae..3f27a92 100644 --- a/tests/test_run_loop_workload.py +++ b/tests/test_run_loop_workload.py @@ -32,6 +32,35 @@ def test_no_data_guard_does_not_fabricate_claims(tmp_path: Path): assert "NO DATA" in result["report_md"] +class _Runner: + """A minimal workload_runner double — explicit about whether/what + ``workload_id`` it carries, instead of monkey-patching a plain function + (which silently loses the attribute if ever wrapped, e.g. functools.partial).""" + + def __init__(self, workload_id: object = "unset") -> None: + # "unset" (the sentinel) means: don't set the attribute at all, so + # getattr(..., "workload_id", None) exercises its own default path + # rather than reading an attribute that happens to be None. + if workload_id != "unset": + self.workload_id = workload_id + + def __call__(self) -> dict: + return {"events": 1} + + +def _capturing_fake_capture(captured: dict): + """A fake ``capture()`` that records the ``workload_id`` it was called + with, shared by the workload_id-relabeling tests below.""" + + @contextmanager + def fake_capture(out_path, *, workload_id="w", fingerprint="f", run_id=None): + captured["workload_id"] = workload_id + kernels = [make_kernel("k", start_ns=i * 100, end_ns=i * 100 + 90) for i in range(10)] + yield make_trace(events=kernels, vendor="nvidia", run_id=run_id or "r") + + return fake_capture + + def test_runner_workload_id_relabels_trace_when_workload_unset(tmp_path: Path, monkeypatch): """A factory-built runner's own ``workload_id`` (e.g. set by ``_vllm_decode_factory``, see #60) must relabel the trace/capture call @@ -47,24 +76,12 @@ def test_runner_workload_id_relabels_trace_when_workload_unset(tmp_path: Path, m import gitm.scheduler.loop as loop captured: dict = {} - - @contextmanager - def fake_capture(out_path, *, workload_id="w", fingerprint="f", run_id=None): - captured["workload_id"] = workload_id - kernels = [make_kernel("k", start_ns=i * 100, end_ns=i * 100 + 90) for i in range(10)] - yield make_trace(events=kernels, vendor="nvidia", run_id=run_id or "r") - - monkeypatch.setattr(loop, "capture", fake_capture) + monkeypatch.setattr(loop, "capture", _capturing_fake_capture(captured)) monkeypatch.setattr(loop, "sync_device", lambda: None) - def runner(): - return {"events": 1} - - runner.workload_id = "custom-workload" - from gitm import optimize - optimize(budget="1s", scratch=str(tmp_path), workload_runner=runner) + optimize(budget="1s", scratch=str(tmp_path), workload_runner=_Runner("custom-workload")) assert captured["workload_id"] == "custom-workload" @@ -74,26 +91,54 @@ def test_runner_workload_id_does_not_override_explicit_workload(tmp_path: Path, import gitm.scheduler.loop as loop captured: dict = {} + monkeypatch.setattr(loop, "capture", _capturing_fake_capture(captured)) + monkeypatch.setattr(loop, "sync_device", lambda: None) - @contextmanager - def fake_capture(out_path, *, workload_id="w", fingerprint="f", run_id=None): - captured["workload_id"] = workload_id - kernels = [make_kernel("k", start_ns=i * 100, end_ns=i * 100 + 90) for i in range(10)] - yield make_trace(events=kernels, vendor="nvidia", run_id=run_id or "r") + from gitm import optimize - monkeypatch.setattr(loop, "capture", fake_capture) + optimize( + workload="hft", budget="1s", scratch=str(tmp_path), + workload_runner=_Runner("custom-workload"), + ) + + assert captured["workload_id"] == "hft" + + +def test_runner_workload_id_none_falls_back_to_default(tmp_path: Path, monkeypatch): + """A factory that didn't populate ``workload_id`` (explicit ``None``, a + plausible real-world state) falls back to the guessed/default label + rather than relabeling to "None".""" + import gitm.scheduler.loop as loop + + captured: dict = {} + monkeypatch.setattr(loop, "capture", _capturing_fake_capture(captured)) monkeypatch.setattr(loop, "sync_device", lambda: None) - def runner(): - return {"events": 1} + from gitm import optimize + + optimize(budget="1s", scratch=str(tmp_path), workload_runner=_Runner(None)) + + assert captured["workload_id"] == "vllm-decode" - runner.workload_id = "custom-workload" + +def test_runner_without_workload_id_attribute_falls_back_to_default( + tmp_path: Path, monkeypatch +): + """A plain runner with no ``workload_id`` attribute at all (the common case + for a directly-passed callable, not a registry factory) exercises the + ``getattr(..., "workload_id", None)`` default path, not just the explicit + ``None`` case above.""" + import gitm.scheduler.loop as loop + + captured: dict = {} + monkeypatch.setattr(loop, "capture", _capturing_fake_capture(captured)) + monkeypatch.setattr(loop, "sync_device", lambda: None) from gitm import optimize - optimize(workload="hft", budget="1s", scratch=str(tmp_path), workload_runner=runner) + optimize(budget="1s", scratch=str(tmp_path), workload_runner=_Runner()) - assert captured["workload_id"] == "hft" + assert captured["workload_id"] == "vllm-decode" def test_runner_runs_inside_capture_and_produces_real_trace(tmp_path: Path, monkeypatch): From b5a03524711d89f736c0a46befc2a746cef1b78a Mon Sep 17 00:00:00 2001 From: Nicholas Lawrence Date: Thu, 9 Jul 2026 10:13:51 -0700 Subject: [PATCH 3/4] loop/test: identity sentinel, empty-string + no-runner coverage, clarifying comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _Runner's "unset" sentinel used string equality (workload_id != "unset"), so a caller passing the literal string "unset" as a real workload_id would be silently suppressed. Switched to an object() identity sentinel. Added two missing cases a reviewer flagged: workload_id="" (falls back to default like None, by design — getattr(...) or workload is falsy-any, not just None-specific) and no runner + no cfg.workload at all (the simplest path, confirming the relabeling guard doesn't require a runner to be present for the plain default to still apply). loop.py: added a one-line comment on the cfg.workload is None guard clarifying that cfg.workload (the field) is never reassigned anywhere in run_loop, unlike the local `workload` var it's compared against — this exact point had already been grep-verified false against a prior review round but was re-flagged, so documenting it inline directly. Co-Authored-By: Claude Sonnet 5 --- gitm/scheduler/loop.py | 6 ++++- tests/test_run_loop_workload.py | 47 ++++++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/gitm/scheduler/loop.py b/gitm/scheduler/loop.py index b0c02a1..08a97a2 100644 --- a/gitm/scheduler/loop.py +++ b/gitm/scheduler/loop.py @@ -245,7 +245,11 @@ def run_loop(cfg: LoopConfig) -> dict[str, Any]: # "vllm-decode" default regardless of what the runner actually is). Only # the runner's own object carries this — earlier ``cfg.engine`` is never # populated yet — so it must be re-checked here, after resolution, not - # folded into the guess above. + # folded into the guess above. NOTE: ``cfg.workload`` (the field) is never + # reassigned anywhere in this function — it stays the caller's original + # input for the whole call, unlike the local ``workload`` var below it, + # which this line progressively resolves. So this is an unambiguous + # "did the caller pin one explicitly" check, not a proxy for it. if cfg.workload is None and runner is not None: workload = getattr(runner, "workload_id", None) or workload diff --git a/tests/test_run_loop_workload.py b/tests/test_run_loop_workload.py index 3f27a92..7c80e40 100644 --- a/tests/test_run_loop_workload.py +++ b/tests/test_run_loop_workload.py @@ -32,16 +32,19 @@ def test_no_data_guard_does_not_fabricate_claims(tmp_path: Path): assert "NO DATA" in result["report_md"] +_UNSET = object() # identity sentinel — a real workload_id could legitimately be any string + + class _Runner: """A minimal workload_runner double — explicit about whether/what ``workload_id`` it carries, instead of monkey-patching a plain function (which silently loses the attribute if ever wrapped, e.g. functools.partial).""" - def __init__(self, workload_id: object = "unset") -> None: - # "unset" (the sentinel) means: don't set the attribute at all, so + def __init__(self, workload_id: object = _UNSET) -> None: + # _UNSET means: don't set the attribute at all, so # getattr(..., "workload_id", None) exercises its own default path # rather than reading an attribute that happens to be None. - if workload_id != "unset": + if workload_id is not _UNSET: self.workload_id = workload_id def __call__(self) -> dict: @@ -141,6 +144,44 @@ def test_runner_without_workload_id_attribute_falls_back_to_default( assert captured["workload_id"] == "vllm-decode" +def test_runner_workload_id_empty_string_falls_back_to_default(tmp_path: Path, monkeypatch): + """An empty-string ``workload_id`` is treated the same as unset/None, not + as a real (if unusual) label — ``getattr(...) or workload`` falls back on + any falsy value, by design, not just ``None``. Documented explicitly here + since it's a plausible footgun otherwise.""" + import gitm.scheduler.loop as loop + + captured: dict = {} + monkeypatch.setattr(loop, "capture", _capturing_fake_capture(captured)) + monkeypatch.setattr(loop, "sync_device", lambda: None) + + from gitm import optimize + + optimize(budget="1s", scratch=str(tmp_path), workload_runner=_Runner("")) + + assert captured["workload_id"] == "vllm-decode" + + +def test_no_runner_and_no_explicit_workload_uses_default(tmp_path: Path, monkeypatch): + """With nothing to read from at all (no runner, no cfg.workload, no + cfg.engine), the simplest path still resolves to the hardcoded default — + the relabeling guard must not require a runner to be present.""" + import gitm.scheduler.loop as loop + + captured: dict = {} + monkeypatch.setattr(loop, "capture", _capturing_fake_capture(captured)) + monkeypatch.setattr(loop, "sync_device", lambda: None) + # No registered factory for "vllm-decode" resolves a runner in this test + # environment (no vLLM installed), so runner stays None throughout. + monkeypatch.setattr(loop, "get_factory", lambda _workload: None) + + from gitm import optimize + + optimize(budget="1s", scratch=str(tmp_path)) + + assert captured["workload_id"] == "vllm-decode" + + def test_runner_runs_inside_capture_and_produces_real_trace(tmp_path: Path, monkeypatch): """An injected runner is invoked inside the capture window; with kernels in the trace the loop proceeds to real claims with a non-empty fingerprint.""" From d6a441935586cbd7f603d2ba7bc79051f10d7032 Mon Sep 17 00:00:00 2001 From: Nicholas Lawrence Date: Thu, 9 Jul 2026 10:17:51 -0700 Subject: [PATCH 4/4] test: dedupe workload_id capture setup into a fixture; drop get_factory patch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extracted the repeated 3-line monkeypatch(capture)/monkeypatch(sync_device) setup shared by 6 workload_id tests into a captured_workload_id fixture, per review feedback about copy-paste drift risk. test_no_runner_and_no_explicit_workload_uses_default no longer monkeypatches get_factory to force runner=None — it relies on the same "no vLLM installed in this test environment" fact test_no_data_guard_does_not_fabricate_claims already depends on, so a future refactor of the lookup site can't silently stop this test from exercising the intended path. loop.py: reworded the comment on the workload_id re-check to remove ambiguity about resolution order (cfg.engine populated the block directly above, not "not yet") and to state explicitly why cfg.engine.workload_id isn't consulted here too — no current runner sets both, so there's no real precedence question, just one preferred source when it exists. Co-Authored-By: Claude Sonnet 5 --- gitm/scheduler/loop.py | 22 +++++--- tests/test_run_loop_workload.py | 89 ++++++++++++--------------------- 2 files changed, 45 insertions(+), 66 deletions(-) diff --git a/gitm/scheduler/loop.py b/gitm/scheduler/loop.py index 08a97a2..fcdbbbe 100644 --- a/gitm/scheduler/loop.py +++ b/gitm/scheduler/loop.py @@ -242,14 +242,20 @@ def run_loop(cfg: LoopConfig) -> dict[str, Any]: # A factory-built runner may know its own workload id better than the # guessed/default one above (e.g. a caller passed ``workload_runner`` # directly with no ``cfg.workload``, so ``workload`` fell through to the - # "vllm-decode" default regardless of what the runner actually is). Only - # the runner's own object carries this — earlier ``cfg.engine`` is never - # populated yet — so it must be re-checked here, after resolution, not - # folded into the guess above. NOTE: ``cfg.workload`` (the field) is never - # reassigned anywhere in this function — it stays the caller's original - # input for the whole call, unlike the local ``workload`` var below it, - # which this line progressively resolves. So this is an unambiguous - # "did the caller pin one explicitly" check, not a proxy for it. + # "vllm-decode" default regardless of what the runner actually is). It + # must be re-checked here, after the runner is resolved, not folded into + # the initial guess a few lines up — at that point neither the runner nor + # ``cfg.engine`` (populated from it just above) exist yet. + # + # ``cfg.workload`` (the field) is never reassigned anywhere in this + # function — it stays exactly the caller's original input for the whole + # call, unlike the local ``workload`` var this line progressively + # resolves. So this is an unambiguous "did the caller pin one explicitly" + # check, not a proxy for it. Deliberately not falling back to + # ``cfg.engine.workload_id`` here too: no current runner sets both an + # engine and a top-level workload_id, so there's no real precedence + # question yet — the runner's own attribute is preferred as the most + # specific source when it exists. if cfg.workload is None and runner is not None: workload = getattr(runner, "workload_id", None) or workload diff --git a/tests/test_run_loop_workload.py b/tests/test_run_loop_workload.py index 7c80e40..bc1609f 100644 --- a/tests/test_run_loop_workload.py +++ b/tests/test_run_loop_workload.py @@ -10,6 +10,8 @@ from contextlib import contextmanager from pathlib import Path +import pytest + from .conftest import make_kernel, make_trace # Digest of an empty kernel list — sha256(repr([]))[:16]. A real trace must not @@ -51,9 +53,15 @@ def __call__(self) -> dict: return {"events": 1} -def _capturing_fake_capture(captured: dict): - """A fake ``capture()`` that records the ``workload_id`` it was called - with, shared by the workload_id-relabeling tests below.""" +@pytest.fixture +def captured_workload_id(monkeypatch): + """Patches ``capture``/``sync_device`` so ``run_loop`` runs without a real + GPU, and returns the dict that the ``workload_id`` it was called with + lands in. Shared by every workload_id-relabeling test below to avoid + repeating the same three-line monkeypatch setup six times.""" + import gitm.scheduler.loop as loop + + captured: dict = {} @contextmanager def fake_capture(out_path, *, workload_id="w", fingerprint="f", run_id=None): @@ -61,10 +69,12 @@ def fake_capture(out_path, *, workload_id="w", fingerprint="f", run_id=None): kernels = [make_kernel("k", start_ns=i * 100, end_ns=i * 100 + 90) for i in range(10)] yield make_trace(events=kernels, vendor="nvidia", run_id=run_id or "r") - return fake_capture + monkeypatch.setattr(loop, "capture", fake_capture) + monkeypatch.setattr(loop, "sync_device", lambda: None) + return captured -def test_runner_workload_id_relabels_trace_when_workload_unset(tmp_path: Path, monkeypatch): +def test_runner_workload_id_relabels_trace_when_workload_unset(tmp_path, captured_workload_id): """A factory-built runner's own ``workload_id`` (e.g. set by ``_vllm_decode_factory``, see #60) must relabel the trace/capture call instead of being silently discarded. @@ -76,27 +86,15 @@ def test_runner_workload_id_relabels_trace_when_workload_unset(tmp_path: Path, m ``workload_runner`` with no explicit ``cfg.workload`` always fell back to the hardcoded "vllm-decode" default regardless of what it actually was. """ - import gitm.scheduler.loop as loop - - captured: dict = {} - monkeypatch.setattr(loop, "capture", _capturing_fake_capture(captured)) - monkeypatch.setattr(loop, "sync_device", lambda: None) - from gitm import optimize optimize(budget="1s", scratch=str(tmp_path), workload_runner=_Runner("custom-workload")) - assert captured["workload_id"] == "custom-workload" + assert captured_workload_id["workload_id"] == "custom-workload" -def test_runner_workload_id_does_not_override_explicit_workload(tmp_path: Path, monkeypatch): +def test_runner_workload_id_does_not_override_explicit_workload(tmp_path, captured_workload_id): """An explicit ``cfg.workload`` always wins over the runner's self-reported id.""" - import gitm.scheduler.loop as loop - - captured: dict = {} - monkeypatch.setattr(loop, "capture", _capturing_fake_capture(captured)) - monkeypatch.setattr(loop, "sync_device", lambda: None) - from gitm import optimize optimize( @@ -104,82 +102,57 @@ def test_runner_workload_id_does_not_override_explicit_workload(tmp_path: Path, workload_runner=_Runner("custom-workload"), ) - assert captured["workload_id"] == "hft" + assert captured_workload_id["workload_id"] == "hft" -def test_runner_workload_id_none_falls_back_to_default(tmp_path: Path, monkeypatch): +def test_runner_workload_id_none_falls_back_to_default(tmp_path, captured_workload_id): """A factory that didn't populate ``workload_id`` (explicit ``None``, a plausible real-world state) falls back to the guessed/default label rather than relabeling to "None".""" - import gitm.scheduler.loop as loop - - captured: dict = {} - monkeypatch.setattr(loop, "capture", _capturing_fake_capture(captured)) - monkeypatch.setattr(loop, "sync_device", lambda: None) - from gitm import optimize optimize(budget="1s", scratch=str(tmp_path), workload_runner=_Runner(None)) - assert captured["workload_id"] == "vllm-decode" + assert captured_workload_id["workload_id"] == "vllm-decode" -def test_runner_without_workload_id_attribute_falls_back_to_default( - tmp_path: Path, monkeypatch -): +def test_runner_without_workload_id_attribute_falls_back_to_default(tmp_path, captured_workload_id): """A plain runner with no ``workload_id`` attribute at all (the common case for a directly-passed callable, not a registry factory) exercises the ``getattr(..., "workload_id", None)`` default path, not just the explicit ``None`` case above.""" - import gitm.scheduler.loop as loop - - captured: dict = {} - monkeypatch.setattr(loop, "capture", _capturing_fake_capture(captured)) - monkeypatch.setattr(loop, "sync_device", lambda: None) - from gitm import optimize optimize(budget="1s", scratch=str(tmp_path), workload_runner=_Runner()) - assert captured["workload_id"] == "vllm-decode" + assert captured_workload_id["workload_id"] == "vllm-decode" -def test_runner_workload_id_empty_string_falls_back_to_default(tmp_path: Path, monkeypatch): +def test_runner_workload_id_empty_string_falls_back_to_default(tmp_path, captured_workload_id): """An empty-string ``workload_id`` is treated the same as unset/None, not as a real (if unusual) label — ``getattr(...) or workload`` falls back on any falsy value, by design, not just ``None``. Documented explicitly here since it's a plausible footgun otherwise.""" - import gitm.scheduler.loop as loop - - captured: dict = {} - monkeypatch.setattr(loop, "capture", _capturing_fake_capture(captured)) - monkeypatch.setattr(loop, "sync_device", lambda: None) - from gitm import optimize optimize(budget="1s", scratch=str(tmp_path), workload_runner=_Runner("")) - assert captured["workload_id"] == "vllm-decode" + assert captured_workload_id["workload_id"] == "vllm-decode" -def test_no_runner_and_no_explicit_workload_uses_default(tmp_path: Path, monkeypatch): +def test_no_runner_and_no_explicit_workload_uses_default(tmp_path, captured_workload_id): """With nothing to read from at all (no runner, no cfg.workload, no cfg.engine), the simplest path still resolves to the hardcoded default — - the relabeling guard must not require a runner to be present.""" - import gitm.scheduler.loop as loop - - captured: dict = {} - monkeypatch.setattr(loop, "capture", _capturing_fake_capture(captured)) - monkeypatch.setattr(loop, "sync_device", lambda: None) - # No registered factory for "vllm-decode" resolves a runner in this test - # environment (no vLLM installed), so runner stays None throughout. - monkeypatch.setattr(loop, "get_factory", lambda _workload: None) - + the relabeling guard must not require a runner to be present. Relies on + the same "no vLLM installed" test-environment fact + ``test_no_data_guard_does_not_fabricate_claims`` already depends on + (rather than monkeypatching ``get_factory``, which would silently stop + exercising this path if the lookup ever moved or gained a second site).""" from gitm import optimize optimize(budget="1s", scratch=str(tmp_path)) - assert captured["workload_id"] == "vllm-decode" + assert captured_workload_id["workload_id"] == "vllm-decode" def test_runner_runs_inside_capture_and_produces_real_trace(tmp_path: Path, monkeypatch):