Skip to content

fix(tests): collect tests/, and correct the two assertions that never ran - #314

Merged
antosubash merged 1 commit into
mainfrom
fix/order-dependent-tests
Sep 5, 2026
Merged

fix(tests): collect tests/, and correct the two assertions that never ran#314
antosubash merged 1 commit into
mainfrom
fix/order-dependent-tests

Conversation

@antosubash

Copy link
Copy Markdown
Owner

Partially addresses #295 — the order-dependence half. See "Still open" below.

The diagnosis in the issue is wrong, and the truth is worse

The issue describes two tests as order-dependent: green under pytest, red under pytest <file>. They are not order-dependent. testpaths listed

"tests/integration", "tests/e2e", "tests/benchmarks", "tests/perf"

but never tests/ itself, so the four modules sitting directly under it were never collected by a bare pytest. They "passed" by not running. 26 tests were in that gap, including test_hydration_lifespan.py and all fifteen of tests/test_audit_log.py.

Replacing the four entries with "tests" collects them. The marker filter already in addopts (-m 'not e2e and not perf') still holds e2e and perf out, so nothing new runs in CI that shouldn't. Collection goes 2787 → 2813, and that leaves exactly the two failures the issue names.

Both are the test being wrong, not the code

test_host_settings_ignores_env asserted "HostSettings must NOT read env — env-sprawl is what we're removing." That is not this codebase's contract. CLAUDE.md § Conventions: "Precedence is always env → DB → default; env must keep winning or existing deployments change behaviour silently on upgrade." And HostSettings declares env_prefix="SM_" with a comment explaining that a bare HostSettings() would otherwise read unprefixed names. Rewritten as three tests covering what the prefix actually guarantees: prefixed env wins, an unprefixed name is ignored, the default applies when neither is set.

test_session_wins_over_bad_bearer asserted a valid session cookie rescues a bad Authorization: Bearer. UsersAuthProvider.resolve_user does the opposite — the header is checked first and a bad token returns None.

⚠️ This one is an auth-semantics decision, and it needs your eye

I kept the code and corrected the test. The reasoning: falling through would make an invalid token indistinguishable from no token, so a client whose credential has expired or been revoked silently keeps working on whatever other identity it happens to carry, and its 401s become dependent on what else is in the request. The fall-through also gains nothing — it can only ever resolve the session's own identity, which the caller already had. The narrow cost is a browser attaching a stale Authorization header to a page request; nothing in this app does that, since pages authenticate with the session cookie.

The opposite call is defensible, and the original test did assert it with a rationale. But it had never executed, so it encoded an intention nobody had verified. If you want the fall-through instead, say so and I'll invert it — it's a three-line change in resolve_user plus the test.

The precedence is now stated where it's implemented, with a sibling test proving the session alone still returns 200 so the 401 is demonstrably the header's doing and not a broken fixture.

Verification

  • uv run pytest -q2814 passed, 2 skipped, 60 deselected (was 2787 collected; +27)
  • ruff format --check . / ruff check . / ty check framework modules host / check_file_size.py — all pass

Still open on #295

The issue's second half — the missing tests list (gen_i18n.py, PasswordInput, Error.tsx's 403 branch, useLeaveGuard, deriveState/user_state parity, file_storage pages, _clamp's out-of-range branch, and the soft if reissued is not None: guard in test_remember_me.py) — is not in this PR. Several of those files are touched by #312 and #313, which are in flight; doing them here would have collided. They should follow once those land, and I'd keep #295 open until then.

… ran

The issue calls these order-dependent — passing under `pytest`, failing under
`pytest <file>`. They are not. `testpaths` listed `tests/integration`,
`tests/e2e`, `tests/benchmarks` and `tests/perf` but never `tests/` itself, so
the four modules directly under it were not collected by a bare `pytest` at all.
The tests "passed" by not running. 26 tests were in that gap, including a
lifespan hydration test and fifteen audit-log tests.

Replacing the four entries with `"tests"` collects them; the marker filter in
`addopts` still holds e2e and perf out, so nothing new runs in CI that should
not. That leaves exactly the two failures the issue describes, and both are the
test being wrong rather than the code.

`test_host_settings_ignores_env` asserted "HostSettings must NOT read env".
That is not this codebase's contract: precedence is env → DB → default and env
has to keep winning, or an upgrade silently changes a deployment's behaviour.
`HostSettings` declares `env_prefix="SM_"` for that reason. Rewritten as three
tests covering what the prefix actually guarantees — prefixed env wins, an
unprefixed name is ignored, the default applies when neither is set.

`test_session_wins_over_bad_bearer` asserted a valid session rescues a bad
`Authorization: Bearer`. `resolve_user` does the opposite. Keeping the code is
the deliberate call: falling through would make an invalid token
indistinguishable from no token, so a client whose credential expired keeps
working on whatever other identity it carries and its 401s depend on what else
is in the request — while gaining nothing, since the fall-through can only
resolve the session's own identity, which the caller already had. The precedence
is now stated where it is implemented, with a sibling test proving the session
alone still succeeds so the 401 is the header's doing.

Closes #295
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review Completed 2026-09-04T22:38:20.734851Z dad8de2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying simple-module-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: dad8de2
Status: ✅  Deploy successful!
Preview URL: https://12541d38.simple-module-python.pages.dev
Branch Preview URL: https://fix-order-dependent-tests.simple-module-python.pages.dev

View logs

@antosubash
antosubash merged commit 82bcbd8 into main Sep 5, 2026
13 checks passed
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