Skip to content

test(unit): convert source-scrape tests to behavioral — batch F (#800)#930

Merged
hellodk merged 3 commits into
masterfrom
test/source-scrape-800-batchF
Jun 26, 2026
Merged

test(unit): convert source-scrape tests to behavioral — batch F (#800)#930
hellodk merged 3 commits into
masterfrom
test/source-scrape-800-batchF

Conversation

@hellodk

@hellodk hellodk commented Jun 26, 2026

Copy link
Copy Markdown
Owner

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 used ast.parse /
node.s to scan salt_tasks.py for SALT_API_* literals) was converted in
batch B to behavioral tests that set SALT_API_* env vars, call _run_salt_api
with a DB-credential stub, and assert the actual URL/username/password used.
The _get_bootstrap_settings SALT_MASTER guard was converted to an
instrumented mock DB that records queried keys.

test_promote_topology_560.py — no changes needed

Route auth checks already use inspect.signature + FastAPI Depends
introspection (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_provisions with mocked
ansible_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_status directly via mocked async DB. The TypeScript
provisionRefetchInterval helper is exercised via node --experimental-strip-types.

test_sre_hardening.py — converted 1 vacuous test

Test Action
test_login_route_source_contains_must_change_password_gate Removed in batch B (used inspect.getsource(login))
test_login_route_checks_must_change_password_flag Converted — was a self-referential inline that simply raised + caught HTTPException without ever calling the login route. Replaced with test_login_route_returns_token_for_valid_credentials which drives the unwrapped login handler with a user having must_change_password=False, mocks DB + audit, and asserts access_token + refresh_token are returned. Complements the adjacent test_login_route_raises_403_for_must_change_password.
All other tests Kept — already behavioral (middleware, metrics auth, rate-limiter key, seeding guards, User model, Settings fields)

Test results

142 passed, 4 warnings in 2.45s

No source-scrape patterns (inspect.getsource, ast.parse/node.s, "X" in source) remain in any of the six files.

Made with Cursor

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.
@github-actions github-actions Bot added test Test coverage improvement frontend Frontend / React changes labels Jun 26, 2026
@github-actions

Copy link
Copy Markdown

Coverage Report

fleet_platform/services/ 85.0% (gate: 80%)

fleet_platform/agent/ 94.8% (gate: 80%)

Gate passed

@github-actions

Copy link
Copy Markdown

Coverage Report

fleet_platform/services/ 85.0% (gate: 80%)

fleet_platform/agent/ 94.8% (gate: 80%)

Gate passed

@github-actions

Copy link
Copy Markdown

Coverage Report

fleet_platform/services/ 85.0% (gate: 80%)

fleet_platform/agent/ 94.8% (gate: 80%)

Gate passed

@hellodk
hellodk merged commit 902ea34 into master Jun 26, 2026
12 checks passed
@hellodk
hellodk deleted the test/source-scrape-800-batchF branch June 26, 2026 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend Frontend / React changes test Test coverage improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant