Skip to content

fix: classify Android androidTest/ sources and *IT.java/*IT.kt as test files#766

Open
bittoby wants to merge 1 commit intoentrius:testfrom
bittoby:fix/is-test-file-android-source-set
Open

fix: classify Android androidTest/ sources and *IT.java/*IT.kt as test files#766
bittoby wants to merge 1 commit intoentrius:testfrom
bittoby:fix/is-test-file-android-source-set

Conversation

@bittoby
Copy link
Copy Markdown
Contributor

@bittoby bittoby commented Apr 24, 2026

Fixes #765

Summary

FileChange.is_test_file() missed three real-world test conventions, causing those files to be scored at full production weight (1.0) instead of TEST_FILE_CONTRIBUTION_WEIGHT (0.05) — a 20× over-score per token:

  • Gradle Android test source sets: androidTest/, androidTestGeneric/, androidTestGplay/, etc.
  • Gradle integration-test source sets: integrationTest/ — also covers Maven Failsafe *IT.java/.kt/.kts files, which by convention live under src/test/ or src/integrationTest/ and are caught by the directory rule rather than a filename-suffix rule.
  • Ruby RSpec: the spec/ directory and the *_spec.{rb,js,ts,…} filename suffix.

Impact is concrete: nextcloud/android keeps its integration tests under app/src/androidTest/... (16+ files like UploadIT.java, AbstractIT.java, ActivitiesFragmentIT.kt); Ruby projects keep specs under spec/models/account_spec.rb. Each was previously mis-scored at production weight.

Changes

  • gittensor/classes.py:
    • Added (^|/)androidtest[a-z]*/, (^|/)integrationtest/, and (^|/)spec/ to the directory pattern set.
    • Added _spec\.[^.]+$ to the basename pattern set.
    • Promoted both pattern sets to module-level re.compile-backed tuples (_TEST_DIR_PATTERNS, _TEST_BASENAME_PATTERNS) and extracted two small helpers (_matches_test_dir_pattern, _matches_test_basename_pattern) — avoids re-allocating and re-compiling the lists on every call to is_test_file().
  • tests/test_classes.py: 23 new parametrized assertions across 3 test functions, plus a regression check covering the pre-existing conventions — Gradle Android & integrationTest paths, Ruby RSpec spec/ paths and _spec.* suffixes, and lookalike negatives (Edit.java, build.gradle.kts, docs/androidtest.md, specification.rb, spectrum.rb, spec.rb).

Test Plan

  • pytest tests/test_classes.py — 25 passed
  • pytest tests/ — 676 passed, 0 regressions
  • pre-commit run --all-files --hook-stage pre-push — ruff, pyright, pytest all pass
  • Verified the issue reproducer (app/src/androidTest/java/...IT.java) now returns True
  • Verified false-positive candidates (Edit.java, Commit.java, Unit.kt, build.gradle.kts, docs/androidtest.md, specification.rb, spectrum.rb, spec.rb) still return False

@xiao-xiao-mao xiao-xiao-mao Bot added the bug Something isn't working label Apr 24, 2026
Copy link
Copy Markdown
Collaborator

@anderdc anderdc left a comment

Choose a reason for hiding this comment

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

Drop the IT-suffix regex — the new androidtest[a-z]*/ and integrationtest/ directory patterns cover every real-world case (Maven Failsafe puts *IT.java under src/test/, Gradle Android puts them under androidTest/). The IT-suffix branch only catches hypothetical files outside any test directory and risks false-positives on production classes named *IT.{java,kt,kts}.

@bittoby bittoby force-pushed the fix/is-test-file-android-source-set branch from 78844d5 to 8b38400 Compare April 28, 2026 23:31
@bittoby bittoby requested a review from anderdc April 29, 2026 14:35
@bittoby
Copy link
Copy Markdown
Contributor Author

bittoby commented Apr 29, 2026

Drop the IT-suffix regex — the new androidtest[a-z]*/ and integrationtest/ directory patterns cover every real-world case (Maven Failsafe puts *IT.java under src/test/, Gradle Android puts them under androidTest/). The IT-suffix branch only catches hypothetical files outside any test directory and risks false-positives on production classes named *IT.{java,kt,kts}.

Fixed all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] is_test_file misses the Android androidTest/ source set and the IT integration-test filename suffix

2 participants