Skip to content

fix(tests): restore the run-image mock, tighten approx and the layout check - #252

Merged
RuibinCheung merged 3 commits into
mainfrom
fix/agentx-tests-review
Nov 18, 2026
Merged

RuibinCheung merged 3 commits into
mainfrom
fix/agentx-tests-review

Conversation

@zhenhuang12

@zhenhuang12 zhenhuang12 commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Why

Follow-up to #250, which merged before its review finished. The review found one test that lost a mock in the pytest conversion, and a few smaller gaps.

Scope

  • tests/benchmarks/test_agentx_plan.py: test_repository_recipes_match_agentx_yaml takes the case fixture again, so ci_image.run_image is patched as it was before test(agentx): pytest style, tests/AGENTS.md rules and the tdd skill #250 and the test no longer reads the real stack.json.
  • pytest.approx(..., abs=5e-8) in four modules: the bound assertAlmostEqual had. test(agentx): pytest style, tests/AGENTS.md rules and the tdd skill #250 left the default relative 1e-6.
  • tests/benchmarks/test_agentx_environment.py: use_environ is a mock.patch.dict(os.environ, clear=True) context again, scoped to the call as before test(agentx): pytest style, tests/AGENTS.md rules and the tdd skill #250. test(agentx): pytest style, tests/AGENTS.md rules and the tdd skill #250 held it to the end of the test through monkeypatch, which restores only the keys it set.
  • tests/check_layout.py: flags an import statement whose module is a test_* or conftest module, relative or bare as well as tests.<...> (from .test_b import x, from test_b import x, import conftest). A name imported with from counts as a module only if its file exists under the repository root or beside the importing file. It also flags a directory under tests/ that holds Python files, or lies above one that does, without __init__.py. tests/benchmarks/__init__.py is added: the eleven modules there are now imported as tests.benchmarks.<name> instead of top-level modules, and tests/benchmarks is no longer put on sys.path. The collected test ids are unchanged.
  • Still a partial check, as tests/AGENTS.md rule 8 says. Not seen: importlib.import_module("..."); a module reached through another sys.path entry; a directory with no Python file below it. Any imported module whose own name starts with test_ is flagged, a third-party one too (sglang.test.test_utils, aiter.test_common; no test imports these today), as is a helper module of that name; so is a helper package of that name when imported as from ..test_support import x (but not as from .. import test_support).
  • tests/AGENTS.md rule 4 names the AgentX tests as the exception to "tests mirror aklr/"; harness/README.md lists the tdd skill.

Nothing under aklr/ or benchmarks/agentx/ changes.

Verification

Environment: head e2e297a (rebased on main at b6dd38e, after #246), lmsysorg/sglang:v0.5.22-rocm10-mi30x, no GPU used
Gate overrides: none

Code

$ python -m pytest -q -p no:cacheprovider tests/benchmarks
331 passed
$ python3 tests/check_layout.py     # clean
$ ruff format --check / ruff check on tests/benchmarks, tests/check_layout.py   # clean

CI code-lint ran pre-commit on this head: ruff check, ruff format and tests-layout pass.

Not run

Risk

Affects: tests and agent documents only
AgentX: none (no AgentX run needed)
If wrong: a CI failure in tests/benchmarks or in the tests-layout hook
Undo: git revert

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The layout checker overlooks missing package markers in intermediate directories and incorrectly rejects valid imports of ordinary helper values.

3 open issues
What changed in this PR

Follow-up to #250 that strengthens the converted AgentX tests and test-layout checks. Changes are limited to tests and contributor documentation; runtime and AgentX production code are unchanged.

Changes:

  • Restore recipe-test isolation from the real stack.json.
  • Add explicit absolute tolerances to numerical assertions.
  • Expand layout checks, add the benchmark package initializer, and clarify testing guidance.
File Description
tests/​check_layout.py Expands forbidden-import detection and checks package initializers.
tests/​benchmarks/​test_agentx_plan.py Restores the fixture that mocks run-image lookup.
tests/​benchmarks/​test_agentx_metrics.py Sets absolute tolerances for metric ratios.
tests/​benchmarks/​test_agentx_comparisons.py Sets absolute tolerances for comparison results.
tests/​benchmarks/​test_agentx_baselines.py Sets absolute tolerances for baseline ratios.
tests/​benchmarks/​test_agentx_archives.py Sets an absolute tolerance for archived interactivity.
tests/​benchmarks/​__init__.py Makes benchmark tests a Python package.
tests/​AGENTS.md Documents the AgentX test-layout exception.
harness/​README.md Lists the tdd skill and its scope.

Review effort: Max

Comment thread tests/check_layout.py Outdated
Comment on lines +18 to +19
if not (path.parent / "__init__.py").is_file():
errors.append(f"{path}: no __init__.py in {path.parent}/")
Comment thread tests/check_layout.py
last = name.rpartition(".")[2]
if name.split(".")[0] == "tests" and (last.startswith("test_") or last == "conftest"):
# any spelling: `tests.x.test_y`, `.test_y`, bare `test_y`
if last.startswith("test_") or last == "conftest":
assert not validator.is_valid(run)


@pytest.mark.usefixtures("case") # build_run reads the run image: keep stack.json out of this test
@zhenhuang12
zhenhuang12 force-pushed the fix/agentx-tests-review branch from d55d2ee to e2e297a Compare November 18, 2026 03:33
… check

Follow-up to #250, from its review.

- test_repository_recipes_match_agentx_yaml lost the ci_image.run_image patch in the pytest
  conversion and read the real stack.json; it takes the case fixture again.
- pytest.approx gets abs=5e-8, the bound assertAlmostEqual had.
- tests/check_layout.py flags a test_*.py or conftest import in any spelling (relative, bare),
  not only tests.<...>, and a test directory without __init__.py; tests/benchmarks gets one.
- tests/AGENTS.md names the AgentX tests as the exception to the aklr/ mirror; harness/README.md
  lists the tdd skill.
…modules only

From the review of this PR.

- test_agentx_environment.py: use_environ is a mock.patch.dict(os.environ, clear=True) context
  again, as before #250, so the environment is restored before the assertions. Held to the end of
  the test through monkeypatch, a process-wide change by execution_env went unseen.
- tests/check_layout.py: a name imported with from is a module only if its file exists, so a helper
  function named test_* is allowed; every directory up to tests/ needs __init__.py, not only a
  test's own.
From the review of this PR: `from ....helpers import x` in tests/probe.py raised IndexError and
stopped the scan. Such an import resolves nowhere, so it is skipped. The lookup's limit (the
repository root and the file's own directory) is written down beside it.
@zhenhuang12
zhenhuang12 force-pushed the fix/agentx-tests-review branch from e2e297a to dbe7e22 Compare November 18, 2026 11:27

@RuibinCheung RuibinCheung left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@RuibinCheung
RuibinCheung merged commit 7e9cff8 into main Nov 18, 2026
11 checks passed
@RuibinCheung
RuibinCheung deleted the fix/agentx-tests-review branch November 18, 2026 11:31
irvineoy added a commit that referenced this pull request Nov 18, 2026
Main moved from a65066c to 7e9cff8, ten commits, among them #253
(sglang 0.5.23, which bcf2f95 already declares), #257 (the GPU jobs
run on the aklr-safe runner) and #252 (a tighter tests layout check).
Nothing conflicts. CI run 44255030975 on bcf2f95 started on the old
runner setup and its GPU prepare job is still queued, so this head's
run is the branch's first on aklr-safe.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants