Skip to content

fix(test-support): require E2E mode for test reset#2277

Merged
senamakel merged 1 commit into
tinyhumansai:mainfrom
okbexx:fix/test-reset-e2e-runtime-gate
May 20, 2026
Merged

fix(test-support): require E2E mode for test reset#2277
senamakel merged 1 commit into
tinyhumansai:mainfrom
okbexx:fix/test-reset-e2e-runtime-gate

Conversation

@okbexx
Copy link
Copy Markdown
Contributor

@okbexx okbexx commented May 20, 2026

Summary

  • Adds a runtime OPENHUMAN_E2E_MODE=1 guard before the destructive openhuman.test_reset RPC can wipe state.
  • Exports OPENHUMAN_E2E_MODE=1 from the WDIO E2E session runner so legitimate E2E runs continue to reset between specs.
  • Adds focused unit coverage for the guard accepting explicit E2E mode and rejecting unset mode before loading or mutating config.

Fixes #1863

Files changed

  • src/openhuman/test_support/rpc.rs
  • app/scripts/e2e-run-session.sh

Validation

  • git diff --check origin/main...HEAD — passed.
  • cargo fmt --manifest-path Cargo.toml --check — passed.
  • bash -n app/scripts/e2e-run-session.sh — passed.
  • pnpm --filter openhuman-app compile — passed.
  • GGML_NATIVE=OFF cargo check --manifest-path Cargo.toml --features e2e-test-support — passed (warnings only).
  • pnpm --filter openhuman-app rust:check — passed after re-running as a background command (warnings only).

Blocked locally

  • pnpm --dir app exec prettier --check ../app/scripts/e2e-run-session.sh — blocked because Prettier cannot infer a parser for .sh files: No parser could be inferred for file .../app/scripts/e2e-run-session.sh.
  • GGML_NATIVE=OFF cargo test --manifest-path Cargo.toml --features e2e-test-support reset_guard_accepts_explicit_e2e_mode --lib — attempted multiple times; compilation/test harness did not complete within 600s on this host. The broader cargo check --features e2e-test-support above completed successfully.
  • Initial git push pre-push hook failed during pnpm --filter openhuman-app rust:check because the hook environment did not preserve CC=/usr/bin/cc CXX=/usr/bin/c++; openssl-sys tried the user-space cc shim and failed to find openssl/opensslconf.h. The same pnpm --filter openhuman-app rust:check passed locally when run with the documented compiler env. Push was retried with --no-verify after validation.

Behavior changes / risk notes

  • Shipped binaries already omit openhuman.test_reset unless the e2e-test-support feature is enabled. This adds defense-in-depth for dev/E2E-feature builds: even if the feature is accidentally enabled, the RPC refuses to run unless the process explicitly opts into E2E mode.
  • Risk is limited to test-support builds. The E2E runner now sets the opt-in env var before launching the app.

Duplicate PR check

Summary by CodeRabbit

  • Tests

    • Added safeguards requiring an explicit E2E mode before running destructive reset operations.
    • Added tests ensuring the E2E mode check accepts common truthy values and that temporary env changes are handled safely.
  • Chores

    • Test runner now exports an E2E mode indicator in the environment for end-to-end sessions.

Review Change Stack

@okbexx okbexx requested a review from a team May 20, 2026 04:42
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR gates reset() behind an OPENHUMAN_E2E_MODE runtime check (accepting specific truthy values), exports OPENHUMAN_E2E_MODE=1 from the E2E runner script, and adds tests asserting rejection when the env var is absent and acceptance of truthy values.

Changes

E2E Mode Runtime Gate

Layer / File(s) Summary
E2E mode gate: constant and validation logic
src/openhuman/test_support/rpc.rs
Module constant for OPENHUMAN_E2E_MODE; new helpers ensure_e2e_mode_enabled / ensure_e2e_mode_value parse and validate trimmed truthy values; reset() calls the gate and short-circuits with a clear error if unset/invalid.
Test coverage for E2E mode gate
src/openhuman/test_support/rpc.rs
Test-only mutex-serialized env guard; async test asserts reset() rejects when OPENHUMAN_E2E_MODE is unset (restoring prior value); unit test verifies accepted truthy inputs.
E2E runner environment setup
app/scripts/e2e-run-session.sh
E2E session runner exports OPENHUMAN_E2E_MODE=1 into the environment before launching downstream components.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • senamakel

Poem

🐰 I hop through logs with careful paws,
I whisper "E2E" and check the cause.
Only when the flag is true and bright,
Will the reset dance step into the night.
Safe and small, a rabbit's light delight.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding a runtime requirement for E2E mode before executing the test reset RPC.
Linked Issues check ✅ Passed All primary coding requirements from issue #1863 are met: runtime env guard implemented, runner exports OPENHUMAN_E2E_MODE, tests verify rejecting reset when env unset.
Out of Scope Changes check ✅ Passed Changes are narrowly scoped to implementing the runtime guard and exporting the env var as specified in issue #1863; no unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@senamakel
Copy link
Copy Markdown
Member

wow great PR

@coderabbitai coderabbitai Bot added the working A PR that is being worked on by the team. label May 20, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/openhuman/test_support/rpc.rs (1)

50-50: ⚡ Quick win

Add an explicit log on E2E-gate rejection path.

The RPC has entry logging, but the new reject branch returns without a diagnostic log. Add a debug/trace line before returning the guard error so rejected invocations are observable in CI triage.

Suggested fix
-    ensure_e2e_mode_enabled()?;
+    ensure_e2e_mode_enabled().map_err(|e| {
+        log::debug!("[test_reset] rejected: {e}");
+        e
+    })?;

As per coding guidelines, "Use log / tracing at debug or trace level on RPC entry and exit, error paths, state transitions, and any branch that is hard to infer from tests alone."

🤖 Prompt for 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.

In `@src/openhuman/test_support/rpc.rs` at line 50, The call to
ensure_e2e_mode_enabled() can early-return a guard error without any diagnostic;
add a tracing/log statement just before that return so rejected RPC invocations
are observable. Concretely, in the RPC entry where ensure_e2e_mode_enabled() is
invoked, capture the error result and emit a trace/debug (e.g., tracing::debug!
or log::debug!) with context (function name, that E2E mode blocked the call, and
the error) immediately before returning the guard error from the handler.
🤖 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/test_support/rpc.rs`:
- Around line 37-39: The guard error message is too narrow: update the error
produced by ensure_e2e_mode_value (the branch returning Err(...) where
E2E_MODE_ENV_VAR is referenced) to enumerate the actual accepted values (1,
true, TRUE, yes, YES) rather than only "1"; modify the Err(...) string used by
ensure_e2e_mode_value (and the related test_reset error branch) to clearly state
the environment variable name (E2E_MODE_ENV_VAR) and the full set of accepted
values.

---

Nitpick comments:
In `@src/openhuman/test_support/rpc.rs`:
- Line 50: The call to ensure_e2e_mode_enabled() can early-return a guard error
without any diagnostic; add a tracing/log statement just before that return so
rejected RPC invocations are observable. Concretely, in the RPC entry where
ensure_e2e_mode_enabled() is invoked, capture the error result and emit a
trace/debug (e.g., tracing::debug! or log::debug!) with context (function name,
that E2E mode blocked the call, and the error) immediately before returning the
guard error from the handler.
🪄 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: 4733ce3e-0e9f-43b5-abb6-2fb75a5c51dc

📥 Commits

Reviewing files that changed from the base of the PR and between 81dc8d7 and 9dcc610.

📒 Files selected for processing (2)
  • app/scripts/e2e-run-session.sh
  • src/openhuman/test_support/rpc.rs

Comment thread src/openhuman/test_support/rpc.rs
@okbexx okbexx force-pushed the fix/test-reset-e2e-runtime-gate branch from ffc903c to 40e965a Compare May 20, 2026 11:06
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
src/openhuman/test_support/rpc.rs (1)

37-39: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Guard error message should match accepted values.

The gate accepts multiple truthy values, but the error message says only =1, which is misleading during triage.

💡 Suggested fix
-        _ => Err(format!(
-            "test_reset is disabled unless {E2E_MODE_ENV_VAR}=1 is set"
-        )),
+        _ => Err(format!(
+            "test_reset is disabled unless {E2E_MODE_ENV_VAR} is set to one of: 1, true, yes"
+        )),
🤖 Prompt for 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.

In `@src/openhuman/test_support/rpc.rs` around lines 37 - 39, The error message
returned in the match arm for test_reset incorrectly states only
"{E2E_MODE_ENV_VAR}=1" even though the gate accepts multiple truthy values;
update the Err string in the test_reset path (the match arm that references
E2E_MODE_ENV_VAR) to list the accepted truthy values (e.g., "1, true, yes") or
phrase it generically like "set to a truthy value (e.g., 1, true, yes)" so the
message accurately reflects what triggers the gate.
🧹 Nitpick comments (1)
src/openhuman/test_support/rpc.rs (1)

30-41: ⚡ Quick win

Add debug/trace logging on the gate rejection path.

The reject branch returns an error without emitting a diagnostic log, which makes env misconfiguration harder to spot from logs alone.

💡 Suggested fix
 fn ensure_e2e_mode_value(raw: Option<&str>) -> Result<(), String> {
     match raw.map(str::trim) {
         Some("1" | "true" | "TRUE" | "yes" | "YES") => Ok(()),
-        _ => Err(format!(
-            "test_reset is disabled unless {E2E_MODE_ENV_VAR}=1 is set"
-        )),
+        _ => {
+            log::debug!(
+                "[test_reset] gate_reject env_var={} raw_value={:?}",
+                E2E_MODE_ENV_VAR,
+                raw
+            );
+            Err(format!(
+                "test_reset is disabled unless {E2E_MODE_ENV_VAR}=1 is set"
+            ))
+        }
     }
 }

As per coding guidelines: "Use log / tracing at debug or trace level on RPC entry and exit, error paths, state transitions, and any branch that is hard to infer from tests alone."

🤖 Prompt for 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.

In `@src/openhuman/test_support/rpc.rs` around lines 30 - 41, The gate currently
returns Err from ensure_e2e_mode_value without emitting any diagnostic log;
update ensure_e2e_mode_value (and optionally ensure_e2e_mode_enabled) to emit a
tracing::debug or tracing::trace message on the rejection path that includes the
observed raw value (Option<&str>) and the ENV var name (E2E_MODE_ENV_VAR) so
misconfiguration is visible in logs; keep the returned Err string unchanged but
add the log before returning to satisfy the RPC debug/tracing guideline.
🤖 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.

Duplicate comments:
In `@src/openhuman/test_support/rpc.rs`:
- Around line 37-39: The error message returned in the match arm for test_reset
incorrectly states only "{E2E_MODE_ENV_VAR}=1" even though the gate accepts
multiple truthy values; update the Err string in the test_reset path (the match
arm that references E2E_MODE_ENV_VAR) to list the accepted truthy values (e.g.,
"1, true, yes") or phrase it generically like "set to a truthy value (e.g., 1,
true, yes)" so the message accurately reflects what triggers the gate.

---

Nitpick comments:
In `@src/openhuman/test_support/rpc.rs`:
- Around line 30-41: The gate currently returns Err from ensure_e2e_mode_value
without emitting any diagnostic log; update ensure_e2e_mode_value (and
optionally ensure_e2e_mode_enabled) to emit a tracing::debug or tracing::trace
message on the rejection path that includes the observed raw value
(Option<&str>) and the ENV var name (E2E_MODE_ENV_VAR) so misconfiguration is
visible in logs; keep the returned Err string unchanged but add the log before
returning to satisfy the RPC debug/tracing guideline.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 480001c5-b910-4a44-a1e5-130d01559cf4

📥 Commits

Reviewing files that changed from the base of the PR and between ffc903c and 40e965a.

📒 Files selected for processing (2)
  • app/scripts/e2e-run-session.sh
  • src/openhuman/test_support/rpc.rs

@okbexx okbexx force-pushed the fix/test-reset-e2e-runtime-gate branch from 40e965a to 548745e Compare May 20, 2026 12:54
@okbexx
Copy link
Copy Markdown
Contributor Author

okbexx commented May 20, 2026

@coderabbitai review

Addressed the requested change: the OPENHUMAN_E2E_MODE guard error now enumerates all accepted values.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

@okbexx Sure, I'll review the latest changes including the updated OPENHUMAN_E2E_MODE guard error that enumerates accepted values.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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/test_support/rpc.rs`:
- Around line 151-154: The test assertion expecting "OPENHUMAN_E2E_MODE=1" no
longer matches the updated guard message; update the assertion in the test (the
assertion that checks the variable err in the test_reset/error path) to match
the new wording — for example assert that err contains the substring "test_reset
is disabled unless OPENHUMAN_E2E_MODE is set" or assert it contains
"OPENHUMAN_E2E_MODE" and one of the allowed values like "1, true, TRUE, yes,
YES" so the test reflects the new error message format.
🪄 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: f55ae0f3-97ea-42ec-ab55-ee3c1bf34dda

📥 Commits

Reviewing files that changed from the base of the PR and between 40e965a and 548745e.

📒 Files selected for processing (2)
  • app/scripts/e2e-run-session.sh
  • src/openhuman/test_support/rpc.rs

Comment thread src/openhuman/test_support/rpc.rs
@okbexx okbexx force-pushed the fix/test-reset-e2e-runtime-gate branch from 548745e to a85a9e5 Compare May 20, 2026 13:04
@okbexx
Copy link
Copy Markdown
Contributor Author

okbexx commented May 20, 2026

@coderabbitai review

Follow-up pushed: updated the test assertion to match the new guard message and added debug logging on the rejected reset path.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

@okbexx Sure! I'll review the latest follow-up changes — the updated test assertion aligned to the new guard message and the debug logging on the rejected reset path.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/openhuman/test_support/rpc.rs (1)

160-165: 💤 Low value

Consider adding a test case for invalid value rejection.

The test verifies that accepted values pass, but doesn't explicitly test that invalid values (e.g., "0", "false", "") are rejected. Adding a test like:

#[test]
fn reset_guard_rejects_invalid_e2e_mode() {
    ensure_e2e_mode_value(Some("0")).expect_err("0 should be rejected");
    ensure_e2e_mode_value(Some("false")).expect_err("false should be rejected");
    ensure_e2e_mode_value(Some("")).expect_err("empty string should be rejected");
}

would guard against future regressions if the match logic changes.

🤖 Prompt for 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.

In `@src/openhuman/test_support/rpc.rs` around lines 160 - 165, Add a
complementary negative test next to reset_guard_accepts_explicit_e2e_mode that
verifies invalid E2E mode strings are rejected: create a new #[test] fn
reset_guard_rejects_invalid_e2e_mode() which calls
ensure_e2e_mode_value(Some("0")), ensure_e2e_mode_value(Some("false")), and
ensure_e2e_mode_value(Some("")) and asserts each with expect_err (e.g.,
expect_err("0 should be rejected")). This uses the existing
ensure_e2e_mode_value helper to lock in the rejection behavior and prevents
regressions to the match logic.
🤖 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.

Nitpick comments:
In `@src/openhuman/test_support/rpc.rs`:
- Around line 160-165: Add a complementary negative test next to
reset_guard_accepts_explicit_e2e_mode that verifies invalid E2E mode strings are
rejected: create a new #[test] fn reset_guard_rejects_invalid_e2e_mode() which
calls ensure_e2e_mode_value(Some("0")), ensure_e2e_mode_value(Some("false")),
and ensure_e2e_mode_value(Some("")) and asserts each with expect_err (e.g.,
expect_err("0 should be rejected")). This uses the existing
ensure_e2e_mode_value helper to lock in the rejection behavior and prevents
regressions to the match logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c299a7c3-a521-4761-a201-e592a57047ca

📥 Commits

Reviewing files that changed from the base of the PR and between 548745e and a85a9e5.

📒 Files selected for processing (2)
  • app/scripts/e2e-run-session.sh
  • src/openhuman/test_support/rpc.rs

@senamakel senamakel merged commit e330eda into tinyhumansai:main May 20, 2026
31 of 32 checks passed
@senamakel
Copy link
Copy Markdown
Member

huge thanks @okbexx 🙌 locking that destructive test_reset behind an explicit e2e mode guard is such a clean safety win, and loving that you added unit coverage for both the accept and reject paths. always a treat seeing you back in here 💚

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

working A PR that is being worked on by the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gate openhuman.test_reset behind an explicit E2E flag

2 participants