Skip to content

fix(tests): override "test" sentinel in security conftest (#804) - #805

Merged
vybe merged 2 commits into
devfrom
AndriiPasternak31/issue-804
May 14, 2026
Merged

fix(tests): override "test" sentinel in security conftest (#804)#805
vybe merged 2 commits into
devfrom
AndriiPasternak31/issue-804

Conversation

@AndriiPasternak31

Copy link
Copy Markdown
Contributor

Summary

  • tests/security/conftest.py was using os.environ.setdefault(...) to overlay .env, which is a no-op once tests/conftest.py has set the "test" sentinel at global pytest import. The Redis ACL acceptance tests then ran redis-cli with -a test against a healthy stack and failed with NOAUTH — wrong-creds, not a real ACL regression.
  • Pop the sentinel for REDIS_PASSWORD / REDIS_BACKEND_PASSWORD before the .env overlay, then assign directly so real values win.
  • Add tests/security/test_redis_conftest_regression.py to lock this in: asserts the live env value isn't the sentinel, and (when .env defines the keys) matches .env exactly. Skips cleanly when neither .env nor real env vars provide creds.

Closes #804.

Test plan

  • pytest tests/security/test_redis_conftest_regression.py passes against a stack with real Redis creds in .env
  • tests/security/test_redis_network_isolation.py (the 3 ACL tests) pass against a freshly-started stack
  • With no creds anywhere (no .env, no env vars), the security suite still skips cleanly via the existing skip guard

🤖 Generated with Claude Code

AndriiPasternak31 and others added 2 commits May 11, 2026 23:42
…leanup_unreachable_orphan.py

#791 (which added the tests/lint_sys_modules.py lint and its baseline)
landed AFTER #783 (which added tests/unit/test_cleanup_unreachable_orphan.py).
The baseline was generated without including the orphan-test file's 3
top-level `sys.modules[...] = stub` assignments at lines 64, 76, 79
(docker, services.docker_service, database stubs installed before the
test module's services.cleanup_service import).

Result: every PR opened against dev fails the lint job on these 3 lines,
even when the PR's own changes are clean.

Fix: grandfather the file into the baseline at its current count (3).
This matches how the same shape is handled elsewhere — e.g.
test_watchdog_unit.py (3 violations, the precedent the orphan-test
file's own comment cites). The lint script's baseline path is the
intended mechanism for accepting pre-existing module-level stub
installs that cannot use monkeypatch.

Verified locally: python3 tests/lint_sys_modules.py emits zero
violations in the real test tree (only .venv site-packages remain,
which CI runners don't have).

Refs #762, #783, #791

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
`tests/conftest.py` setdefaults REDIS_PASSWORD/REDIS_BACKEND_PASSWORD to
the literal "test" at global pytest import so backend modules can be
imported without real Redis creds. `tests/security/conftest.py` was then
using `os.environ.setdefault(...)` to overlay real `.env` values — a
no-op because the sentinel was already set. Result: `redis-cli` ran with
`-a test` against a healthy stack and the ACL acceptance tests failed
for the wrong reason.

Pop the sentinel before the `.env` overlay and use direct assignment.
Add a regression test that asserts the live env value is not the
sentinel and (when `.env` defines the keys) matches the `.env` value.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@AndriiPasternak31
AndriiPasternak31 force-pushed the AndriiPasternak31/issue-804 branch from 018727c to 2296450 Compare May 12, 2026 01:52
@AndriiPasternak31
AndriiPasternak31 changed the base branch from dev to AndriiPasternak31/lint-baseline-orphan-test May 12, 2026 01:54
@AndriiPasternak31 AndriiPasternak31 self-assigned this May 12, 2026
@AndriiPasternak31
AndriiPasternak31 requested a review from vybe May 12, 2026 01:55

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR requires the following change before merge:

  • Retarget base branch to devAndriiPasternak31/lint-baseline-orphan-test was already squash-merged to dev as PR #796. Change via the GitHub UI: Edit → Base: dev.

Code is clean and the fix is correct. This is the only blocker.

@AndriiPasternak31
AndriiPasternak31 changed the base branch from AndriiPasternak31/lint-baseline-orphan-test to dev May 12, 2026 22:10
@AndriiPasternak31

Copy link
Copy Markdown
Contributor Author

Hi Eugene — base is already dev (auto-retargeted when #796 landed and the intermediate branch AndriiPasternak31/lint-baseline-orphan-test was deleted). Current state: base=dev, mergeable=MERGEABLE. Re-requesting review.

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Original blocker resolved. Fix is correct — sentinel pop + direct assignment is the right call. Regression test properly locks it in. LGTM.

@vybe
vybe merged commit d370216 into dev May 14, 2026
10 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.

2 participants