Split benchmark surface tests from monolith#220
Merged
ictechgy merged 5 commits intoJun 21, 2026
Conversation
Split the independent benchmark, statusline, cross-agent setup, and escrow test groups out of the monolithic context_guard_kit test module while reusing its shared fixtures through explicit aliases. This keeps unittest discovery stable and avoids duplicating imported TestCase classes. Constraint: G006 allows only safe behavior-preserving maintainability cleanup. Rejected: refactor experimental_registry.py internals | higher runtime risk than a test-module extraction for this story. Confidence: high Scope-risk: narrow Directive: Keep future large test groups in focused test modules and avoid wildcard imports from modules that define TestCase classes. Tested: python3 -m py_compile tests/test_context_guard_kit.py tests/test_context_guard_kit_benchmark_surfaces.py; PYTHONDONTWRITEBYTECODE=1 python3 -m unittest tests.test_context_guard_kit_benchmark_surfaces.BenchmarkRunnerTests tests.test_context_guard_kit_benchmark_surfaces.StatuslineMergedWrapperTests tests.test_context_guard_kit_benchmark_surfaces.CrossAgentAdapterTests tests.test_context_guard_kit_benchmark_surfaces.ContextEscrowCcrMetadataTests -q (126 tests); PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s tests -p 'test_*.py' (737 tests); python3 scripts/prepublish_check.py --skip-tests; python3 scripts/sync_plugin_copies.py --check; git diff --check. Not-tested: CI matrix before PR creation.
Keep the split benchmark-surface test module and the base test module canonical under both unittest discovery and package-qualified invocation names. Add lazy legacy dotted-path compatibility for moved TestCase classes without exposing them through dir() and duplicating discovery. Constraint: review-loop fix for G006 must preserve behavior and avoid duplicate TestCase discovery. Rejected: wildcard import from the base test module | would expose imported TestCase classes and duplicate discovery. Confidence: high Scope-risk: narrow Directive: When splitting tests, alias top-level and package-qualified module names before sharing mutable fixtures. Tested: python3 -m py_compile tests/test_context_guard_kit.py tests/test_context_guard_kit_benchmark_surfaces.py; PYTHONDONTWRITEBYTECODE=1 python3 -m unittest tests.test_context_guard_kit_benchmark_surfaces.SplitModuleCompatibilityTests tests.test_context_guard_kit_benchmark_surfaces.BenchmarkRunnerTests tests.test_context_guard_kit_benchmark_surfaces.StatuslineMergedWrapperTests tests.test_context_guard_kit_benchmark_surfaces.CrossAgentAdapterTests tests.test_context_guard_kit_benchmark_surfaces.ContextEscrowCcrMetadataTests -q (128 tests); legacy top-level dotted path load from tests/ returned 74 BenchmarkRunnerTests; PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s tests -p 'test_*.py' (739 tests); python3 scripts/prepublish_check.py --skip-tests; python3 scripts/sync_plugin_copies.py --check; git diff --check. Not-tested: CI matrix after this fix commit before push.
ed7390d to
c83a656
Compare
Canonicalize the new benchmark-surface test module under both top-level discovery and package-qualified import names, matching the base-module aliasing. This prevents duplicate moved TestCase class objects when tools mix unittest discovery names with dotted package invocations. Constraint: review-loop fix for G006 must preserve behavior and avoid duplicate TestCase discovery. Rejected: leaving split-module aliases implicit | package-qualified imports can reload the split module and duplicate moved TestCase classes. Confidence: high Scope-risk: narrow Directive: For split tests under tests/, canonicalize both top-level and package-qualified module names when supporting both invocation styles. Tested: python3 -m py_compile tests/test_context_guard_kit.py tests/test_context_guard_kit_benchmark_surfaces.py; SplitModuleCompatibilityTests (3 tests); explicit top-level-then-package and package-then-top import order checks; PYTHONDONTWRITEBYTECODE=1 python3 -m unittest tests.test_context_guard_kit_benchmark_surfaces.SplitModuleCompatibilityTests tests.test_context_guard_kit_benchmark_surfaces.BenchmarkRunnerTests tests.test_context_guard_kit_benchmark_surfaces.StatuslineMergedWrapperTests tests.test_context_guard_kit_benchmark_surfaces.CrossAgentAdapterTests tests.test_context_guard_kit_benchmark_surfaces.ContextEscrowCcrMetadataTests -q (129 tests); PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s tests -p 'test_*.py' (740 tests); python3 scripts/prepublish_check.py --skip-tests; python3 scripts/sync_plugin_copies.py --check; git diff --check. Not-tested: CI matrix after this fix commit before push.
Alias the base context_guard_kit test module under both top-level and package-qualified names at import time, then cover both import orders from fresh subprocesses. This keeps shared test fixtures single-instanced even when tools mix unittest discovery names with package dotted names before loading the split module. Constraint: review-loop fix for G006 must preserve behavior and avoid duplicate TestCase discovery. Rejected: relying on the split module to repair base aliases | direct base imports can happen before the split module is imported. Confidence: high Scope-risk: narrow Directive: Keep import-order subprocess tests when supporting both top-level and package-qualified test module names. Tested: python3 -m py_compile tests/test_context_guard_kit.py tests/test_context_guard_kit_benchmark_surfaces.py; SplitModuleCompatibilityTests (4 tests); PYTHONDONTWRITEBYTECODE=1 python3 -m unittest tests.test_context_guard_kit_benchmark_surfaces.SplitModuleCompatibilityTests tests.test_context_guard_kit_benchmark_surfaces.BenchmarkRunnerTests tests.test_context_guard_kit_benchmark_surfaces.StatuslineMergedWrapperTests tests.test_context_guard_kit_benchmark_surfaces.CrossAgentAdapterTests tests.test_context_guard_kit_benchmark_surfaces.ContextEscrowCcrMetadataTests -q (130 tests); PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s tests -p 'test_*.py' (741 tests); python3 scripts/prepublish_check.py --skip-tests; python3 scripts/sync_plugin_copies.py --check; git diff --check. Not-tested: CI matrix after this fix commit before push.
When canonicalizing top-level and package-qualified test module names, also attach the canonical module objects to the parent tests package. This preserves package-qualified unittest dotted paths after a top-level discovery import and prevents _FailedTest loader results in mixed invocation processes. Constraint: review-loop fix for G006 must preserve behavior and avoid duplicate TestCase discovery. Rejected: sys.modules-only aliasing | unittest dotted-name resolution also consults the parent package attribute chain. Confidence: high Scope-risk: narrow Directive: For test-module alias shims, update both sys.modules and the parent package attribute. Tested: python3 -m py_compile tests/test_context_guard_kit.py tests/test_context_guard_kit_benchmark_surfaces.py; SplitModuleCompatibilityTests (4 tests); PYTHONDONTWRITEBYTECODE=1 python3 -m unittest tests.test_context_guard_kit_benchmark_surfaces.SplitModuleCompatibilityTests tests.test_context_guard_kit_benchmark_surfaces.BenchmarkRunnerTests tests.test_context_guard_kit_benchmark_surfaces.StatuslineMergedWrapperTests tests.test_context_guard_kit_benchmark_surfaces.CrossAgentAdapterTests tests.test_context_guard_kit_benchmark_surfaces.ContextEscrowCcrMetadataTests -q (130 tests); PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s tests -p 'test_*.py' (741 tests); python3 scripts/prepublish_check.py --skip-tests; python3 scripts/sync_plugin_copies.py --check; git diff --check. Not-tested: CI matrix after this fix commit before push.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary\n- Split independent benchmark/statusline/cross-agent/escrow test groups from the monolithic context_guard_kit test module.\n- Reuse shared fixtures via explicit aliases to avoid duplicate unittest discovery from imported TestCase classes.\n- No product/runtime behavior change.\n\n## Validation\n- python3 -m py_compile tests/test_context_guard_kit.py tests/test_context_guard_kit_benchmark_surfaces.py\n- PYTHONDONTWRITEBYTECODE=1 python3 -m unittest tests.test_context_guard_kit_benchmark_surfaces.BenchmarkRunnerTests tests.test_context_guard_kit_benchmark_surfaces.StatuslineMergedWrapperTests tests.test_context_guard_kit_benchmark_surfaces.CrossAgentAdapterTests tests.test_context_guard_kit_benchmark_surfaces.ContextEscrowCcrMetadataTests -q (126 tests)\n- PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s tests -p 'test_*.py' (737 tests)\n- python3 scripts/prepublish_check.py --skip-tests\n- python3 scripts/sync_plugin_copies.py --check\n- git diff --check\n