Repository navigation
fix(test): stop the SLM version-check tests reading the host code_source (#13162) - #13371
Merged
Merged
Conversation
…rce (#13162) The five TestVersionCheckTask cases never established the precondition the loop they exercise requires. version_check_task skips its whole body when the active CodeSource path has no .git directory (#9716), and the tests patched only get_git_tracker / db_service — never the path resolution. So the loop fell through to the module's DEFAULT_REPO_PATH and read whatever the host happened to have there: green on a developer box with a live install, red on a CI runner without one. That is the entire cause of the five CI failures; the production skip is deliberate and stays as is. Give the class an autouse fixture that points _get_active_code_source_config at a tmp_path tree containing a real .git directory, so the genuine _is_git_repo check runs and passes on any host, and reset the _missing_repo_warned module global between cases. This mirrors the pattern the sibling git_tracker_test.py already uses. Add test_task_skips_when_no_local_checkout to pin the gate itself. The loop's skip path had no coverage — only _run_git_command's did — which is why the gate could silently disable five tests. Verified by mutation: removing the gate makes the new test fail. Verification (SLM-only pytest invocation, per the pytest.ini note): - before, with no host checkout: 5 failed, 4 passed - after, with no host checkout: 10 passed - after, full scope, migrations + tests/services: 429 passed, 1 skipped autobot-slm-backend/migrations is already green in both environments; its 28 tests pass. The 18 reported failures there reproduce only when the two backends are collected in one pytest session, where whichever collects first binds the shared migrations dotted name. CI already runs the two backends as separate invocations, so no change is needed.
Contributor
✅ SSOT Configuration Compliance: Passing🎉 No hardcoded values detected that have SSOT config equivalents! |
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.
Thinking Path
Scope was
autobot-slm-backend/migrations/andautobot-slm-backend/tests/services/, reported as ~23 CI failures split 18 / 5.Baseline on the dev box (Python 3.10, SLM-only pytest invocation) was 428 passed, 1 skipped, 0 failed — nothing reproduced. Rather than guess at a Python 3.14 difference, I pulled the actual shard logs from the latest
Dev_new_guiCI run and grepped them. Only five failures exist in this scope, all inversion_checker_test.py::TestVersionCheckTask, and every one of them is an assertion thatcheck_for_updates/update_latest_version_setting/ the "Update available" log never happened.That pattern points at one shared precondition, not five bugs.
version_check_taskresolves the active CodeSource path, then gates its entire body on_is_git_repo(repo_path)— a deliberate skip added in #9716 for deployments with no local checkout. The tests patchget_git_trackeranddb_service, but never the path resolution, so the loop fell through to the module'sDEFAULT_REPO_PATHand read the host filesystem. The dev box has a live install at that location, so the gate opened and the tests passed. A CI runner does not, so the gate closed and all five assertions failed.Confirmed the diagnosis by reproducing the exact CI failure set locally with
SLM_REPO_PATH=/nonexistent/code_source: 5 failed, 4 passed — the same five test IDs. So this is not a Python 3.14 artifact; it is environment coupling that happens to be invisible on any machine with a deployed checkout at the default location.The reported 18 failures in
migrations/are not real. That directory is green in both environments and in CI. They reproduce only whenautobot-backendandautobot-slm-backendare collected in a single pytest session — both define a top-levelmigrationspackage, so whichever collects first binds the dotted name and the other's imports fail. This is the exact hazard the comment abovetestpathsinpytest.inidocuments, and CI already runs the two backends as separate invocations. Demonstrated below.What Changed
autobot-slm-backend/tests/services/version_checker_test.pyonly. No production code was modified — the_is_git_reposkip is intended behaviour and the tests were wrong to depend on the host for it.TestVersionCheckTaskthat points_get_active_code_source_configat atmp_pathtree containing a real.gitdirectory. The genuine_is_git_repocheck still runs (it is not stubbed out), it just now has a deterministic tree to look at. This also removes the incidental real-DB session two of the cases were attempting. Mirrors the isolation pattern the siblinggit_tracker_test.pyalready uses._missing_repo_warnedmodule global per test so the once-only log flag cannot leak between cases.test_task_skips_when_no_local_checkout, pinning the gate itself. The loop's skip path had no coverage — only_run_git_command's equivalent did — which is precisely why the gate could silently disable five tests without anyone noticing.No test was skipped, xfailed, or weakened, and no assertion was relaxed.
Verification
SLM-only pytest invocation throughout, per the
pytest.ininote (autobot-backendandautobot-slm-backendmust not share a session).Reproducing the CI environment,
SLM_REPO_PATHpointed at a path with no checkout — before:Same command, after:
Full scope on the dev box, after:
(428 before, plus the one new regression test.)
The new test is mutation-verified. Replacing the
if not _is_git_repo(repo_path):gate with a constant-false condition makes it fail:The mutation was reverted;
git statusshows the test file as the only modification.migrations/needs no change — 28 tests, all passing:And the collision that produced the phantom 18 is a single-session artifact. Collecting an
autobot-backendmigrations test alongside the SLM ones makes the backend side lose the name race here, with the SLM 28 still green:Reverse the collection order and the 18 SLM ones lose instead. CI does not run them together, so neither set is actually red there.
Lint on the changed file, all clean:
isort(line length 120),black(line length 120, unchanged),flake8(exit 0),bandit(no issues identified, no severity floor).Model Used
Claude Opus 5
Closes #13162