Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(test-support): reject `..` lexically, and compile+run the gate in CI

M3gA-Mind3095bd3442d2
diff --git a/.github/workflows/ci-lite.yml b/.github/workflows/ci-lite.yml
index 1f352fcbec..bd66f9d113 100644
--- a/.github/workflows/ci-lite.yml
+++ b/.github/workflows/ci-lite.yml
@@ -507,17 +507,35 @@ jobs:
run: bash scripts/ci-cancel-aware.sh cargo check --manifest-path Cargo.toml --no-default-features
- name: Check the gates that are in NEITHER the contributor nor the product set
- # `tui` is the one gate that is default-OFF *and* deliberately not
- # forwarded to the desktop shell (it is a terminal front-end; the app
- # ships its own UI). That combination means nothing else in CI compiles
- # it: the product lanes do not select it, the contributor lanes no
- # longer default it on, and the gates-off check above turns it off.
+ # Two gates are default-OFF *and* absent from the product set, so
+ # nothing else in CI compiles them: the product lanes do not select
+ # them, the contributor lanes no longer default them on, and the
+ # gates-off check above turns them off.
#
- # Without this step the ratatui front-end would rot silently — which is
- # the same shape of failure as #4901, just pointed at a gate instead of
- # at the shipped app. If a future gate lands in this same
- # neither-set position, add it here.
- run: bash scripts/ci-cancel-aware.sh cargo check --manifest-path Cargo.toml --no-default-features --features tui
+ # tui — a terminal front-end; the app ships its own UI.
+ # e2e-test-support — the `test`/`test_support` RPC family, turned on
+ # only by app/scripts/e2e-build.sh for the packaged
+ # desktop E2E binary. It includes
+ # `openhuman.test_reset`, a destructive in-place
+ # wipe, which is exactly why it must stay out of
+ # every product lane — so a compile-only smoke
+ # check here is the right shape, not enabling it
+ # somewhere that ships.
+ #
+ # Without this step those families rot silently — the same shape of
+ # failure as #4901, pointed at a gate instead of at the shipped app.
+ # `e2e-test-support` sat in this position from the day it was added
+ # until #6086 and was never `cargo check`ed by CI in either state.
+ #
+ # Checked in SEPARATE invocations on purpose: `--features tui,e2e-test-support`
+ # would let one gate compile only because the other pulled a dependency
+ # in, which is the false pass this lane exists to prevent.
+ #
+ # If a future gate lands in this same neither-set position, add it here
+ # AND to the list in CLAUDE.md's "gate in neither set" note.
+ run: |
+ bash scripts/ci-cancel-aware.sh cargo check --manifest-path Cargo.toml --no-default-features --features tui
+ bash scripts/ci-cancel-aware.sh cargo check --manifest-path Cargo.toml --no-default-features --features e2e-test-support
- name: Run the gate-contract tests with the default domain gates disabled
# `cargo check` (even --all-targets) never RUNS tests, so a gated family that
@@ -545,6 +563,29 @@ jobs:
bash scripts/ci-cancel-aware.sh cargo test --manifest-path Cargo.toml \
--no-default-features --features mcp --lib -- \
mcp::server::resources::
+ # `test_support` is behind `e2e-test-support`, a gate in neither the
+ # contributor nor the product set, so no other lane RUNS these — the
+ # smoke check above only compiles them. That distinction is the whole
+ # point of this step: `resolve_workspace_relative`'s traversal guard
+ # (#6085) failed open for every path that did not exist, from the day
+ # it landed in #1892, and no `cargo check` anywhere could have caught
+ # it because the code compiled perfectly. These are the tests that
+ # would have.
+ #
+ # SCOPED TO `introspect::` ON PURPOSE, and this is a hole, not a
+ # tidy-up: the first run of the unscoped `test_support::` filter found
+ # `test_support::rpc::wipe_memory_tree_removes_content_dirs_and_reports_summary`
+ # already failing here —
+ # "test_reset: memory_tree wipe failed: wipe_all: driver
+ # 'tinymemory' does not serve Maintenance"
+ # `memory-engine-seams` (= dep:tinymemory-core) is in `default` but not
+ # in product-features.txt, so it is off in this profile. Widening the
+ # feature list to go green would hide exactly what this lane exists to
+ # expose, so the filter is narrowed and the gap is named instead.
+ # Re-widen to `test_support::` once that is resolved.
+ bash scripts/ci-cancel-aware.sh cargo test --manifest-path Cargo.toml \
+ --no-default-features --features e2e-test-support --lib -- \
+ test_support::introspect::
- name: Guard — the kernel dependency floor may not grow
# The `--no-default-features --features flows` profile is the surface a
diff --git a/AGENTS.md b/AGENTS.md
index 83f3dc1e3b..29fba69a21 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -703,7 +703,7 @@ What it *did* change: **a lane that relies on default features no longer covers
> **Adding a gate to either set? You must forward it to the desktop shell.**
> `app/src-tauri/Cargo.toml` declares `openhuman_core` with `default-features = false` (set in #1061, before gates existed), so the shipped app does **not** inherit the core's `default` list. A gate in the product set but not in the shell's `features` list is **compiled out of the shipped desktop app** — with no build error and no failing test. This is not hypothetical: `voice` shipped missing from v0.58.19 to v0.61.x (56 users, ~93k Sentry events, #4901), and `tokenjuice-treesitter` was never forwarded once since #4123 and failed *soft*, silently degrading AST compression (#4918).
> `scripts/ci/check-feature-forwarding.mjs` (the **Feature Forwarding Gate** lane) asserts three things: the shell forwards **exactly** `product-features.txt` (set equality, both directions), every name in that file is a real core gate, and every `default` gate is forwarded or allow-listed. The equality check is the load-bearing one — the old subset-of-`default` check would have passed **vacuously** once `default` stopped being the product set, silently re-arming #4901. If a gate genuinely must not ship, add it to `INTENTIONALLY_NOT_FORWARDED` **with a reason** — an explicit exclusion is the only way "deliberate" stays distinguishable from "forgotten".
-> A gate in **neither** set (today only `tui`) gets no compile coverage from the normal lanes at all, so the feature-gate-smoke lane checks it explicitly. Put new ones there too.
+> A gate in **neither** set (today `tui` and `e2e-test-support`) gets no compile coverage from the normal lanes at all, so the feature-gate-smoke lane checks it explicitly. Put new ones there too. `e2e-test-support` was in this position for its whole life without being listed here or checked anywhere (#6086) — it is the reason this sentence now names its members instead of claiming there is one.
**Slim-profile convention** (no `full` meta-feature): build slim variants with `cargo build --no-default-features --features "<explicit list of gates you want>"`. This mirrors the existing standalone-feature style (`sandbox-landlock`, `browser-native`, …). Example — everything except voice:
diff --git a/src/openhuman/test_support/introspect.rs b/src/openhuman/test_support/introspect.rs
index e9ea309eef..359ce8165f 100644
--- a/src/openhuman/test_support/introspect.rs
+++ b/src/openhuman/test_support/introspect.rs
@@ -28,7 +28,52 @@ const LIST_MAX_DEPTH: u32 = 6;
/// Reject any relative path containing a `..` component or that resolves
/// outside the workspace root. Returns the joined absolute path on success.
+///
+/// # Why the component walk has to come first
+///
+/// The prefix check below cannot enforce the `..` half of that promise on its
+/// own, and used to be the only check. `Path::join` does not normalise `..`,
+/// and `Path::starts_with` compares whole components — so
+/// `<root>/../../etc/passwd` *does* start with `<root>` and sails through. The
+/// only thing that ever caught a traversal was `canonicalize()` resolving it to
+/// somewhere outside the root, which means the guard was load-bearing exactly
+/// when the target **existed** and failed open when it did not:
+/// `canonicalize()` errors on a missing path, `unwrap_or_else` restores the
+/// un-normalised candidate, and the comparison passes. `../../nope` was
+/// answered with "No such file or directory" from the caller's own `stat`
+/// rather than a refusal.
+///
+/// So `..` is rejected lexically, before any filesystem access, which is what
+/// the doc line above has always promised and needs no `canonicalize()` to
+/// hold. The canonicalize + `starts_with` pair is kept underneath: a component
+/// walk cannot see a symlink that points out of the workspace, and that check
+/// can. See openhuman#6085.
fn resolve_workspace_relative(workspace: &Path, rel: &str) -> Result<PathBuf, String> {
+ let trimmed = rel.trim_start_matches('/');
+
+ // Lexical guard. Rejects `..` outright; also rejects a root/prefix
+ // component, which `trim_start_matches('/')` alone does not remove on
+ // Windows (`C:\…`, `\\?\…`) and which would otherwise make `join`
+ // discard the workspace root entirely. `CurDir` (`./`) is harmless and is
+ // allowed through so existing callers keep working.
+ for component in Path::new(trimmed).components() {
+ match component {
+ std::path::Component::Normal(_) | std::path::Component::CurDir => {}
+ std::path::Component::ParentDir => {
+ return Err(format!(
+ "rel_path {rel:?} escapes workspace root {}",
+ workspace.display()
+ ));
+ }
+ std::path::Component::RootDir | std::path::Component::Prefix(_) => {
+ return Err(format!(
+ "rel_path {rel:?} must be relative to the workspace root {}",
+ workspace.display()
+ ));
+ }
+ }
+ }
+
// Canonicalize the workspace root first so both sides of the prefix check
// share the same symlink-resolved base. On macOS `/var` is a symlink to
// `/private/var`; if we join `rel` onto the original (unresolved) workspace
@@ -39,7 +84,6 @@ fn resolve_workspace_relative(workspace: &Path, rel: &str) -> Result<PathBuf, St
let canonical_root = workspace
.canonicalize()
.unwrap_or_else(|_| workspace.to_path_buf());
- let trimmed = rel.trim_start_matches('/');
let candidate = canonical_root.join(trimmed);
let canonical_candidate = candidate
.canonicalize()
@@ -289,3 +333,7 @@ pub async fn wallet_prepared_quotes() -> Result<RpcOutcome<PreparedQuotesResult>
format!("wallet_prepared_quotes: {count} quotes"),
))
}
+
+#[cfg(test)]
+#[path = "introspect_tests.rs"]
+mod tests;
diff --git a/src/openhuman/test_support/introspect_tests.rs b/src/openhuman/test_support/introspect_tests.rs
new file mode 100644
index 0000000000..64c0dab80d
--- /dev/null
+++ b/src/openhuman/test_support/introspect_tests.rs
@@ -0,0 +1,158 @@
+use super::*;
+use tempfile::TempDir;
+
+/// A workspace root that exists on disk, so `canonicalize()` succeeds for the
+/// root itself and the tests below isolate the *candidate* path's behaviour.
+fn workspace() -> TempDir {
+ TempDir::new().expect("workspace tempdir")
+}
+
+// ── the regression this file exists for (openhuman#6085) ────────────────
+//
+// Before the lexical component walk, `resolve_workspace_relative` rejected a
+// traversal only when `canonicalize()` happened to resolve it somewhere
+// outside the root — which requires the target to EXIST. A traversal at a
+// path that does not exist failed open: `canonicalize()` errored,
+// `unwrap_or_else` restored the un-normalised candidate, and the
+// component-wise `starts_with(root)` passed because `<root>/../../x` really
+// does start with `<root>`. The caller then answered with its own `stat`
+// error ("No such file or directory") instead of a refusal, so the guard's
+// failure was invisible.
+
+#[test]
+fn parent_dir_traversal_to_a_missing_path_is_rejected() {
+ let ws = workspace();
+ // The distinguishing case: nothing exists at the far end, so
+ // `canonicalize()` cannot save the guard. This is the exact input from
+ // the issue's reproduction.
+ let err = resolve_workspace_relative(ws.path(), "../../nonexistent-e2e-probe")
+ .expect_err("a `..` traversal must be refused even when the target does not exist");
+ assert!(
+ err.contains("escapes workspace root"),
+ "the refusal must name the escape, not surface a filesystem error: {err}"
+ );
+}
+
+#[test]
+fn parent_dir_traversal_to_an_existing_path_is_rejected() {
+ let ws = workspace();
+ // The case that already worked, kept so a fix cannot trade one for the
+ // other: `/etc/passwd` exists on every POSIX host, so canonicalize()
+ // resolves it out of the root.
+ let err = resolve_workspace_relative(ws.path(), "../../../../../../etc/passwd")
+ .expect_err("a `..` traversal to an existing file must be refused");
+ assert!(
+ err.contains("escapes workspace root"),
+ "unexpected error: {err}"
+ );
+}
+
+#[test]
+fn a_single_parent_dir_component_anywhere_is_rejected() {
+ let ws = workspace();
+ std::fs::create_dir_all(ws.path().join("a/b")).expect("nested dirs");
+ // Lands back inside the root, so the prefix check alone would allow it.
+ // The doc contract is "any relative path containing a `..` component",
+ // not "any path that ends up outside", so this is refused too.
+ let err = resolve_workspace_relative(ws.path(), "a/../b")
+ .expect_err("a `..` component must be refused even when it resolves back inside");
+ assert!(
+ err.contains("escapes workspace root"),
+ "unexpected error: {err}"
+ );
+}
+
+#[test]
+fn a_leading_slash_is_trimmed_but_a_traversal_behind_it_is_not() {
+ let ws = workspace();
+ // `trim_start_matches('/')` strips the leading slash on POSIX, so this
+ // arrives as a normal relative path and is allowed — assert the POSIX
+ // behaviour we actually have rather than pretending otherwise.
+ let ok = resolve_workspace_relative(ws.path(), "/inside.txt")
+ .expect("a leading slash is trimmed and the remainder treated as relative");
+ assert!(
+ ok.starts_with(
+ ws.path()
+ .canonicalize()
+ .unwrap_or_else(|_| ws.path().to_path_buf())
+ ),
+ "the trimmed path must stay under the workspace root: {}",
+ ok.display()
+ );
+ // A traversal that survives the trim is still refused.
+ let err = resolve_workspace_relative(ws.path(), "/../escape.txt")
+ .expect_err("a traversal behind a leading slash must still be refused");
+ assert!(
+ err.contains("escapes workspace root"),
+ "unexpected error: {err}"
+ );
+}
+
+// ── paths that must keep working ────────────────────────────────────────
+
+#[test]
+fn an_ordinary_relative_path_still_resolves_under_the_root() {
+ let ws = workspace();
+ std::fs::create_dir_all(ws.path().join("state")).expect("state dir");
+ std::fs::write(ws.path().join("state/costs.jsonl"), b"{}").expect("seed file");
+
+ let resolved = resolve_workspace_relative(ws.path(), "state/costs.jsonl")
+ .expect("an ordinary relative path must resolve");
+ assert!(
+ resolved.ends_with("state/costs.jsonl"),
+ "got {}",
+ resolved.display()
+ );
+ assert!(resolved.exists(), "the resolved path must be the real file");
+}
+
+#[test]
+fn a_path_that_does_not_exist_yet_still_resolves() {
+ let ws = workspace();
+ // `list_workspace_files` / `read_workspace_file` stat after resolving, so
+ // resolution itself must not require existence — otherwise the callers
+ // lose their own "not found" error.
+ let resolved = resolve_workspace_relative(ws.path(), "not/created/yet.txt")
+ .expect("resolution must not depend on the target existing");
+ assert!(
+ resolved.ends_with("not/created/yet.txt"),
+ "got {}",
+ resolved.display()
+ );
+ assert!(!resolved.exists());
+}
+
+#[test]
+fn a_leading_current_dir_component_is_allowed() {
+ let ws = workspace();
+ // `./x` is harmless and some callers pass it; the walk lets `CurDir`
+ // through deliberately.
+ let resolved = resolve_workspace_relative(ws.path(), "./state.json")
+ .expect("`./` must not be treated as an escape");
+ assert!(
+ resolved.ends_with("state.json"),
+ "got {}",
+ resolved.display()
+ );
+}
+
+// ── the check the component walk cannot make ────────────────────────────
+
+#[cfg(unix)]
+#[test]
+fn a_symlink_pointing_out_of_the_workspace_is_still_rejected() {
+ let ws = workspace();
+ let outside = TempDir::new().expect("outside tempdir");
+ let secret = outside.path().join("secret.txt");
+ std::fs::write(&secret, b"not yours").expect("seed outside file");
+ std::os::unix::fs::symlink(&secret, ws.path().join("link.txt")).expect("symlink");
+
+ // No `..` anywhere, so the lexical walk sees nothing wrong. This is why
+ // the canonicalize + starts_with pair is kept underneath it.
+ let err = resolve_workspace_relative(ws.path(), "link.txt")
+ .expect_err("a symlink escaping the workspace must still be refused");
+ assert!(
+ err.contains("escapes workspace root"),
+ "unexpected error: {err}"
+ );
+}