Skip to content

fix: preserve tested_by edges for Python test files under tests/ - #690

Open
sihaoqiaouzi wants to merge 1 commit into
Egonex-AI:mainfrom
sihaoqiaouzi:fix/preserve-tested-by-edges-for-python-test-dirs
Open

sihaoqiaouzi wants to merge 1 commit into
Egonex-AI:mainfrom
sihaoqiaouzi:fix/preserve-tested-by-edges-for-python-test-dirs

Conversation

@sihaoqiaouzi

Copy link
Copy Markdown

Summary

is_test_path() treats tests/ as a test-source root for Swift, Rust, and PHP — but Python is missing from _TEST_DIRECTORY_EXTENSIONS. Python files under a tests/ directory are only recognized when the basename carries a test_ prefix or a _test suffix.

That leaves a common layout broken: a project whose suite lives in tests/ under names like run_tests.py or stage4_e2e.py gets every production-to-test tested_by edge dropped at merge time, because the pair is read as production-vs-production and discarded as semantically broken. The merge reports those edges as dropped, and the resulting graph shows zero test coverage for a repo that has a full test suite.

Reproduction

A 30-file Python project — tests/run_tests.py, tests/stage3_tests.py, tests/stage4_e2e.py, production under data_agent/:

  • The file-analyzers classified all three correctly and emitted 25 correct tested_by pairs.
  • merge-batch-graphs.py classified all three as production files and dropped every pair.
  • Resulting graph: 0 tested_by edges.

With this patch, on the same project:

before after
is_test_path on the 4 real tests/*.py files 4/4 wrong 12/12 correct
tested_by edges in graph 0 17
production files tagged tested 0 12
plugin unittest suite 91 passed 93 passed

Change

-_TEST_DIRECTORY_EXTENSIONS: frozenset[str] = frozenset({".swift", ".rs", ".php"})
+_TEST_DIRECTORY_EXTENSIONS: frozenset[str] = frozenset({".swift", ".rs", ".php", ".py"})

Plus the matching docstring/comment update and two new tests:

  • test_python_tests_directory — Python naming-convention false-negatives (run_tests.py, stage3_tests.py, stage4_e2e.py, gen_data.py, helpers.py).
  • test_python_non_test_paths — guards against a tests substring appearing elsewhere in the path (data_agent/core/sqlite_utils.py, mypkg/testing/helpers.py, src/latest.py).

The Swift/Rust/PHP cases added in #689 still pass.

Relation to the other tested_by reports

Both open issues below are about dropped tested_by edges, but each has a different root cause. This patch is not a duplicate of either.

Testing

cd <repo>
python -m unittest tests.skill.understand.test_merge_batch_graphs
# Ran 93 tests ... OK

`is_test_path` treats `tests/` as a test-source root only for Swift, Rust,
and PHP — Python is absent from `_TEST_DIRECTORY_EXTENSIONS`. A Python
project whose tests live under `tests/` without a `test_` prefix or `_test`
suffix therefore has every production->test `tested_by` edge dropped during
the merge: the pair is read as production-vs-production and discarded as
semantically broken.

Reproduced on a 30-file Python project with `tests/run_tests.py`,
`tests/stage3_tests.py`, and `tests/stage4_e2e.py`. All three were classified
as production files, so the merge reported 0 `tested_by` edges even though
the file-analyzers emitted correct pairs. After adding ".py":
- the files above (plus `tests/gen_data.py`) are recognized as tests;
- the graph gains 17 `tested_by` edges and 12 `tested` tags (was 0 and 0);
- the plugin's unittest suite passes: 93 tests (2 added here).

The two new tests cover the directory rule for Python naming-convention
false-negatives, and guard against a `tests` substring appearing elsewhere
in a path.

Related: Egonex-AI#586 and Egonex-AI#595 both report dropped `tested_by` edges, but for a
different reason (path candidates that never reach the source file, or a
suite outside any `tests/` root). This change only completes the extension
list for the existing `tests/` root rule.

This branch has not been deployed

No deployments
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.

1 participant