test(unit): convert source-scrape tests to behavioral — batch F (#800)#930
Merged
Conversation
Five of the six batch-F files (test_salt_master_probe_517, test_salt_master_ssot_562, test_promote_topology_560, test_provision_master_557, test_provision_status_endpoint_558) were already fully behavioral: no inspect.getsource / ast source-scrape patterns found; all assertions drive live code paths with mocked deps. test_sre_hardening.py — one vacuous inline test hardened: - Removed test_login_route_checks_must_change_password_flag which manually raised HTTPException itself and caught it (tested nothing about the login route; docstring mentioned "inspecting the route source" as the original intent). - Replaced with test_login_route_returns_token_for_valid_credentials: drives the unwrapped login handler with a user whose must_change_password=False, mocks DB + audit, and asserts that access_token and refresh_token are returned. Complements the adjacent test_login_route_raises_403_for_must_change_password. 142 tests pass, 0 source-scrape patterns remain across all 6 files.
Coverage Report✅ ✅ Gate passed |
Coverage Report✅ ✅ Gate passed |
Coverage Report✅ ✅ Gate passed |
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
Closes / contributes to #800 (TST-4 — eliminate source-scrape unit tests).
Reviewed all six batch-F files against the triage rubric. Five files were already
fully behavioralized by batch B; one file had a remaining vacuous inline pattern
that is fixed here.
Per-file breakdown
test_salt_master_probe_517.py — no changes needed
All assertions were already behavioral (mocked socket/requests/DB, asserting
returned dicts). Zero
inspect.getsource/ source-string patterns found.test_salt_master_ssot_562.py — no changes needed
The AST source-scanning
TestGrepGuardSaltTasks(which usedast.parse/node.sto scansalt_tasks.pyforSALT_API_*literals) was converted inbatch B to behavioral tests that set SALT_API_* env vars, call
_run_salt_apiwith a DB-credential stub, and assert the actual URL/username/password used.
The
_get_bootstrap_settingsSALT_MASTER guard was converted to aninstrumented mock DB that records queried keys.
test_promote_topology_560.py — no changes needed
Route auth checks already use
inspect.signature+ FastAPIDependsintrospection (not source text). All topology/minion tests drive live async
route handlers against mock DB sessions.
test_provision_master_557.py — no changes needed
OS detection, SSH-unreachable, success, exception, and reaper tests all call
provision_master/reap_orphaned_master_provisionswith mockedansible_runner/run_probe. Route auth check uses signature introspection.test_provision_status_endpoint_558.py — no changes needed
Route registration, GET method, auth guard, and four endpoint behavior tests all
call
get_provision_statusdirectly via mocked async DB. The TypeScriptprovisionRefetchIntervalhelper is exercised vianode --experimental-strip-types.test_sre_hardening.py — converted 1 vacuous test
test_login_route_source_contains_must_change_password_gateinspect.getsource(login))test_login_route_checks_must_change_password_flagraised + caughtHTTPExceptionwithout ever calling the login route. Replaced withtest_login_route_returns_token_for_valid_credentialswhich drives the unwrapped login handler with a user havingmust_change_password=False, mocks DB + audit, and assertsaccess_token+refresh_tokenare returned. Complements the adjacenttest_login_route_raises_403_for_must_change_password.Test results
No source-scrape patterns (
inspect.getsource,ast.parse/node.s,"X" in source) remain in any of the six files.Made with Cursor