test(security): add integration tests for load_and_get_security_policy_info (#2688)#2805
Conversation
…y_info Covers the env-overlay path identified in issue tinyhumansai#2688 — previously only exercised by the full JSON-RPC smoke test. Two new async integration tests: - `load_and_get_security_policy_info_reflects_env_overlay`: sets OPENHUMAN_MAX_ACTIONS_PER_HOUR=42 and asserts the RPC payload reflects it. - `load_and_get_security_policy_info_ignores_zero_budget`: sets the var to 0 (invalid) and asserts the default value is preserved. Both use TEST_ENV_LOCK for process-wide env serialisation, matching the pattern in other integration tests across the test suite. Closes tinyhumansai#2688
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds config validation rejecting ChangesSecurity policy environment configuration tests
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/openhuman/security/ops.rs`:
- Around line 62-65: Introduce an RAII guard (e.g., RestoreEnvGuard) that
captures the previous values (Option<String>) of
"OPENHUMAN_MAX_ACTIONS_PER_HOUR" and "OPENHUMAN_WORKSPACE" when created and
restores them in its Drop impl, then use this guard at the start of both test
blocks (the places that currently call std::env::remove_var inside unsafe) so
cleanup always runs even if assertions panic; replace the direct
std::env::remove_var calls with instantiation of RestoreEnvGuard and let Drop
handle restoration.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1667608b-016e-4647-8629-518693ba6c49
📒 Files selected for processing (1)
src/openhuman/security/ops.rs
Two issues addressed together: 1. RAII env restoration in both test blocks (CodeRabbit review comment #3315371695): introduce EnvRestore drop guard so vars are restored even if an assertion panics before the explicit remove_var calls. 2. Align env overlay zero-check with RPC update path: `apply_env_overlay` now ignores OPENHUMAN_MAX_ACTIONS_PER_HOUR=0 (logs a warning instead of clamping the live limit to zero), consistent with the RPC update handler that already rejects 0 with "must be at least 1". The integration test assumption was correct; the env overlay had the gap. Unit test in load_tests.rs pins the new behaviour.
|
Hi @graycyrus, thanks for the review! You're right that the Windows secrets ACL job fails on external contributor PRs because org secrets aren't injected for fork branches ("Secret source: None" in the runner log). I confirmed this is a fork limitation, not caused by our changes — the only files this PR touches are I pushed a re-trigger commit to get a fresh CI run. The job is currently pending and should finish clean shortly. |
graycyrus
left a comment
There was a problem hiding this comment.
Clean integration test coverage for load_and_get_security_policy_info. The full env → config → RPC payload chain is now exercised directly via cargo test, not just the JSON-RPC smoke.
A few things worth noting:
load.rs zero-guard — the added Ok(0) arm in apply_env_overlay is a correct fix and matches how the RPC update path already handles zero. The warning log is the right call here.
Issue acceptance criteria drift — issue #2688 said the zero case should "surface as zero in the RPC payload", but the actual correct behavior (and what the PR implements) is to ignore the invalid value and preserve the default. The PR description explains the rationale clearly; the issue criteria were slightly off. The implementation is right.
RAII EnvRestore guard — properly restores both vars on drop regardless of panic path. The unsafe usage is justified: TEST_ENV_LOCK serialises the mutation, which is the correct pattern across the test suite. No issues.
Approved.
|
Closing as superseded by #2695 for issue #2688. Both PRs add env-overlay coverage for Thanks for the contribution! The |
Summary
load_and_get_security_policy_infoinsrc/openhuman/security/ops.rs, covering the full env-var → config load → RPC payload chain that was previously only exercised by the JSON-RPC smoke test (follow-up from issue Add direct integration test for load_and_get_security_policy_info #2688)load_and_get_security_policy_info_reflects_env_overlay— setsOPENHUMAN_MAX_ACTIONS_PER_HOUR=42and asserts the RPC payload contains42load_and_get_security_policy_info_ignores_zero_budget— sets the var to0(invalid value, must be ≥ 1) and asserts the config default is preserved insteadBoth tests use
TEST_ENV_LOCKfor process-wide env serialisation, matching the pattern used across the test suite. Env vars are now restored via an RAIIEnvRestoredrop guard so cleanup is panic-safe (CodeRabbit review). Also aligned the env overlay zero-check with the RPC update path:apply_env_overlaynow ignoresOPENHUMAN_MAX_ACTIONS_PER_HOUR=0with a warning, consistent with the RPC handler that already rejects zero.Test plan
cargo test -p openhuman security::opspassesload_and_get_security_policy_info_reflects_env_overlayassertsmax_actions_per_hour == 42load_and_get_security_policy_info_ignores_zero_budgetassertsmax_actions_per_hour == <default>when env var is0security_policy_info_*unit testsCloses #2688
Summary by CodeRabbit
Tests
Bug Fixes