Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
CI fails closed: a missing test precondition fails in CI instead of skipping (27a) (#779)
Oleksandr Ivanchenko6513c07805f5
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 800da315..a674f45c 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -143,12 +143,21 @@ jobs:if-no-files-found: ignoreretention-days: 30+ # Strict: GitHub sets CI=true, so a test whose precondition is missing (Chrome, ffmpeg, Xvfb, git)+ # fails instead of printing "skipped" and passing (tests/support/skip.rs). The Docker tests run in+ # docker-tests; what runs nowhere in CI is listed in tests/NOT_IN_CI.md.rust:name: rustruns-on: ubuntu-latestneeds: frontend+ env:+ KWNT_TEST_REQUIRE: "1"steps:- uses: actions/checkout@v4+ - name: Test skips go through skip_or_fail+ run: python3 scripts/check_test_skips.py+ - name: Test tools+ run: scripts/ci_docker_tests.sh tools# The binary embeds frontend/dist, so the Rust build needs it- uses: actions/download-artifact@v4with:@@ -165,7 +174,39 @@ jobs:- name: Mac lockfile in syncrun: cargo metadata --locked --format-version 1 --manifest-path apps/mac/Cargo.toml > /dev/null- name: Tests- run: cargo test --locked --no-fail-fast+ run: scripts/ci_docker_tests.sh rust-tests+ # Proves the rule itself: a browser test with Chrome hidden fails with CI=true and skips without+ - name: Strict fails, local skips+ run: scripts/ci_docker_tests.sh both-ways- name: Disk usageif: always()run: df -h / && du -sh target || true++ # The agents-in-VM security tests, the VM browser container and the parallel harness need Docker+ # and kwant's own images. This job builds them (timed, in the job summary) and runs those tests+ # strict, so a missing image fails here instead of skipping. In parallel with rust, so its disk+ # and time stay as they were.+ docker-tests:+ name: docker-tests+ runs-on: ubuntu-latest+ needs: frontend+ timeout-minutes: 60+ env:+ KWNT_TEST_REQUIRE: "1"+ steps:+ - uses: actions/checkout@v4+ - uses: actions/download-artifact@v4+ with:+ name: frontend-dist+ path: frontend/dist+ - uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable+ - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3+ with:+ key: docker-tests+ - name: Build the images+ run: scripts/ci_docker_tests.sh images+ - name: Docker tests (strict)+ run: scripts/ci_docker_tests.sh run+ - name: Disk usage+ if: always()+ run: df -h / && docker system df && du -sh target || truediff --git a/AGENTS.md b/AGENTS.mdnew file mode 100644index 00000000..7e6b98ca--- /dev/null+++ b/AGENTS.md@@ -0,0 +1,23 @@+# AGENTS.md++Rules for anyone, person or agent, who adds or changes kwant's tests. CONTRIBUTING.md covers the rest.++## Tests++- **A new test fails without the change.** Run it on the code before your change and see it fail;+ a test that passes either way checks nothing.+- **No fixed sleeps.** Wait for the condition (a file, a port, a message, a state) with a deadline,+ never `sleep(…)` and hope.+- **Run each new test 3 times before the PR**, e.g. `for i in 1 2 3; do cargo test --test x_test name || break; done`.+- **A missing precondition goes through `skip::skip_or_fail(what, fix)`** (`tests/support/skip.rs`).+ It skips on your computer and fails in CI (`CI=true` or `KWNT_TEST_REQUIRE=1`), naming what's+ missing and how to provide it. A live test that needs a real service uses `skip::opt_in(var, what)`.+ Never print "skipped" and return: `scripts/check_test_skips.py` fails CI on it.+- **An `#[ignore]`d test is listed in `tests/NOT_IN_CI.md`** with why it can't run in CI and the+ exact command that runs it.+- **Fail loudly, no silent fallback.** A test, or the code it checks, that can't do what it was+ asked says so and fails; it doesn't quietly do something else and pass.+- **Find the root cause before fixing a symptom.** A retry, a longer timeout or a skipped case is+ not a fix until you know why it failed.++Adapted from agent-substrate's AGENTS.md and docs/ci-fail-closed.md (Apache-2.0).diff --git a/scripts/check_test_skips.py b/scripts/check_test_skips.pynew file mode 100644index 00000000..c0586e79--- /dev/null+++ b/scripts/check_test_skips.py@@ -0,0 +1,92 @@+#!/usr/bin/env python3+"""Fails when a Rust test skips outside tests/support/skip.rs, or when an ignored test isn't listed.++A skip and a pass have the same exit code, and `cargo test` hides a passing test's output, so a+test that prints "skipped" and returns looks green in CI having run nothing. Every early return+for a missing precondition goes through `skip::skip_or_fail` (fails in CI) or `skip::opt_in`+(live tests, never in CI). This check finds, in test code:++ 1. a print!/println!/eprint!/eprintln! whose text says "skip";+ 2. a direct read of the CI variable or KWNT_AGENT_TEST_REQUIRE (use `skip::strict()`);+ 3. an #[ignore]d test whose name isn't in tests/NOT_IN_CI.md.++Test code is everything under tests/, and in src/ the part of a file from its first+`#[cfg(test)]` on (plus files named tests.rs or under a tests/ folder).++ python3 scripts/check_test_skips.py [repo root]+"""+import re+import sys+from pathlib import Path++HELPER = Path("tests/support/skip.rs")+HELPER_TEST = Path("tests/skip_helper_test.rs")+NOT_IN_CI = Path("tests/NOT_IN_CI.md")+PRINT = re.compile(r'\b(?:e?print(?:ln)?)!\s*\(\s*"((?:[^"\\]|\\.)*)"', re.S)+CI_READ = re.compile(r'\bvar(?:_os)?\s*\(\s*"CI"\s*\)|KWNT_AGENT_TEST_REQUIRE')+IGNORE = re.compile(r'^\s*#\[ignore\b')+FN = re.compile(r'\bfn\s+(\w+)')+++def test_code(root: Path):+ """(path, first test line index, lines) for every Rust file with test code."""+ for p in sorted((root / "tests").rglob("*.rs")):+ if p.relative_to(root) not in (HELPER, HELPER_TEST):+ yield p, 0, p.read_text(encoding="utf-8").split("\n")+ for p in sorted((root / "src").rglob("*.rs")):+ lines = p.read_text(encoding="utf-8").split("\n")+ if p.name == "tests.rs" or "tests" in p.relative_to(root).parts[:-1]:+ yield p, 0, lines+ continue+ start = next((i for i, l in enumerate(lines) if l.strip() == "#[cfg(test)]"), None)+ if start is not None:+ yield p, start, lines+++def ignored_names(lines, start):+ """(line number, test name) for each #[ignore] attribute from `start` on."""+ for i in range(start, len(lines)):+ if IGNORE.match(lines[i]):+ for nxt in lines[i + 1:i + 6]:+ m = FN.search(nxt)+ if m:+ yield i + 1, m.group(1)+ break+++def check(root: Path):+ problems = []+ listed = (root / NOT_IN_CI).read_text(encoding="utf-8") if (root / NOT_IN_CI).exists() else ""+ for path, start, lines in test_code(root):+ rel = path.relative_to(root)+ body = "\n".join(lines[start:])+ offset = start + 1+ for m in PRINT.finditer(body):+ if "skip" in m.group(1).lower():+ line = offset + body.count("\n", 0, m.start())+ problems.append(f"{rel}:{line}: a test prints a skip itself; call skip::skip_or_fail(what, fix) "+ f"(fails in CI) or skip::opt_in(var, what) for a live test (see {HELPER})")+ for m in CI_READ.finditer(body):+ line = offset + body.count("\n", 0, m.start())+ problems.append(f"{rel}:{line}: reads CI or KWNT_AGENT_TEST_REQUIRE directly; use skip::strict() ({HELPER})")+ for line, name in ignored_names(lines, start):+ if f"`{name}`" not in listed:+ problems.append(f"{rel}:{line}: #[ignore]d test `{name}` is not listed in {NOT_IN_CI}; "+ f"add it with why it can't run in CI and the command that runs it")+ return problems+++def main(argv):+ root = Path(argv[1]) if len(argv) > 1 else Path(__file__).resolve().parent.parent+ problems = check(root)+ for p in problems:+ print(p, file=sys.stderr)+ if problems:+ print(f"check_test_skips.py: {len(problems)} problem(s)", file=sys.stderr)+ return 1+ print("check_test_skips.py: every test skip goes through tests/support/skip.rs; every #[ignore] is listed")+ return 0+++if __name__ == "__main__":+ sys.exit(main(sys.argv))diff --git a/scripts/ci_docker_tests.sh b/scripts/ci_docker_tests.shnew file mode 100755index 00000000..bd9d0fd3--- /dev/null+++ b/scripts/ci_docker_tests.sh@@ -0,0 +1,139 @@+#!/usr/bin/env bash+# The tests that need Docker and kwant's own images: the agents-in-VM security tests, the VM+# browser container and the parallel harness. CI's docker-tests job builds the images and runs+# them strict (CI=true); the rust job skips them by name, because it has no images.+#+# scripts/ci_docker_tests.sh images build the executor, agent and browser images, pull oha+# scripts/ci_docker_tests.sh run run the Docker tests (strict: a missing image fails)+# scripts/ci_docker_tests.sh rust-tests the rust job's `cargo test`, without the Docker tests+# scripts/ci_docker_tests.sh tools install what the strict rust job's tests need (apt)+# scripts/ci_docker_tests.sh both-ways a browser test with Chrome hidden: fails with CI=true, skips without+#+# Run it from the repo root. Locally, `images` then `KWNT_TEST_REQUIRE=1 scripts/ci_docker_tests.sh run`.+set -euo pipefail++AGENT_VM_UNIT_TEST=sandbox::agent_vm::tests::in_a_real_container_a_hook_cant_be_written_but_git_commit_works+# Tests in the default run that skip (or fail, in CI) without Docker and the agent image.+DOCKER_TESTS=(+ the_three_attacks_fail_in_a_shell_and_in_the_agents_own_bash+ nothing_the_bot_started_outlives_the_containers_last_turn+ an_approval_goes_through_kwnt_and_both_answers_work+ every_failure_is_a_notice_and_nothing_runs_on_this_computer+ "$AGENT_VM_UNIT_TEST"+)++# Image tags come from the code, so a bump there needs no edit here.+const() { sed -n "s/.*pub const $1: &str = \"\\([^\"]*\\)\".*/\\1/p" "$2" | head -1; }+CLAUDE_VERSION=$(const CLAUDE_VERSION src/sandbox/agent_vm/mod.rs)+AGENT_IMAGE="kwnt-agent:v1-claude-$CLAUDE_VERSION"+BROWSER_IMAGE=$(const BROWSER_IMAGE src/sandbox/service.rs)+EXECUTOR_IMAGE=$(const EXECUTOR_IMAGE src/sandbox/manager.rs)+OHA_IMAGE=$(const OHA_IMAGE src/parallel/harness.rs)+for v in CLAUDE_VERSION BROWSER_IMAGE EXECUTOR_IMAGE OHA_IMAGE; do+ [ -n "${!v}" ] || { echo "ci_docker_tests.sh: could not read $v from the source" >&2; exit 1; }+done++# Runs a step and records how long it took, in the job summary too when there is one.+timed() {+ local name=$1 start end rc=0; shift+ start=$(date +%s)+ "$@" || rc=$?+ end=$(date +%s)+ echo "$name: $((end - start)) s (exit $rc)"+ [ -z "${GITHUB_STEP_SUMMARY:-}" ] || echo "| $name | $((end - start)) s | exit $rc |" >> "$GITHUB_STEP_SUMMARY"+ return "$rc"+}++images() {+ [ -z "${GITHUB_STEP_SUMMARY:-}" ] || printf '| step | time | result |\n|---|---|---|\n' >> "$GITHUB_STEP_SUMMARY"+ local all+ all=$(date +%s)+ timed "$EXECUTOR_IMAGE" docker build --progress plain -t "$EXECUTOR_IMAGE" -f docker/executor.Dockerfile docker+ timed "$AGENT_IMAGE" docker build --progress plain -t "$AGENT_IMAGE" --build-arg "CLAUDE_VERSION=$CLAUDE_VERSION" \+ -f docker/agent.Dockerfile docker+ timed "$BROWSER_IMAGE" docker build --progress plain -t "$BROWSER_IMAGE" -f docker/browser.Dockerfile docker+ timed "oha (pull)" docker pull --quiet "$OHA_IMAGE"+ echo "all images: $(( $(date +%s) - all )) s"+ [ -z "${GITHUB_STEP_SUMMARY:-}" ] || echo "| all images | $(( $(date +%s) - all )) s | |" >> "$GITHUB_STEP_SUMMARY"+}++run() {+ export KWNT_TEST_REQUIRE=1+ [ -z "${GITHUB_STEP_SUMMARY:-}" ] || printf '| tests | time | result |\n|---|---|---|\n' >> "$GITHUB_STEP_SUMMARY"+ local failed=()+ # Every group runs even when an earlier one fails; the script fails at the end+ each() { local name=$1; shift; timed "$name" "$@" || failed+=("$name"); }+ each "agents-in-VM tests" cargo test --locked --no-fail-fast --test agents_in_vm_adversarial_test \+ --test agents_in_vm_fail_closed_test+ each "agent_vm unit test" cargo test --locked --lib -- --exact "$AGENT_VM_UNIT_TEST"+ # Ignored in the default run because they start containers; here the images exist+ each "browser container tests" cargo test --locked --no-fail-fast --test browser_container_test \+ --test browser_container_download_test -- --ignored+ each "browser stream (live Chromium)" cargo test --locked --test browser_stream_test -- --ignored --exact \+ live_chromium_stream_and_isolated_sessions+ each "parallel harness" cargo test --locked --test parallel_test -- --ignored+ if [ ${#failed[@]} -gt 0 ]; then+ printf 'ci_docker_tests.sh: failed: %s\n' "${failed[@]}" >&2+ exit 1+ fi+}++# Chrome, git and python3 are on GitHub's Ubuntu image; ffmpeg and Xvfb may not be. Without them+# the video and window tests fail in a strict run, so install what's missing.+tools() {+ local need=()+ command -v ffmpeg >/dev/null || need+=(ffmpeg)+ command -v Xvfb >/dev/null || need+=(xvfb)+ if [ ${#need[@]} -gt 0 ]; then+ timed "apt install ${need[*]}" sudo sh -c "apt-get update -q && apt-get install -y -q --no-install-recommends ${need[*]}"+ fi+ for t in google-chrome git python3 ffmpeg Xvfb; do+ printf '%s: %s\n' "$t" "$(command -v "$t" || echo MISSING)"+ done+}++# Both branches of skip_or_fail on a real browser test, with Chrome hidden (empty PATH, empty HOME,+# no KWNT_CHROME_PATH): with CI=true it must fail and name the fix; without CI it must pass, saying+# it skipped. Runs the binary `rust-tests` already built.+PROOF_TEST=browser_keys_test+PROOF_NAME=a_bots_enter_submits_the_form_and_other_keys_still_type+both_ways() {+ local bin home out rc+ bin=$(cargo test --locked --no-run --message-format=json --test "$PROOF_TEST" 2>/dev/null | python3 -c '+import json, sys+for line in sys.stdin:+ m = json.loads(line)+ if m.get("reason") == "compiler-artifact" and m.get("executable") and m["target"]["name"] == sys.argv[1]:+ print(m["executable"])' "$PROOF_TEST")+ [ -x "$bin" ] || { echo "both-ways: no $PROOF_TEST binary" >&2; exit 1; }+ home=$(mktemp -d)+ echo "== CI=true, no Chrome: must FAIL"+ rc=0; out=$(env -i HOME="$home" PATH=/nonexistent CI=true "$bin" --exact "$PROOF_NAME" 2>&1) || rc=$?+ echo "$out"; echo "exit $rc"+ [ "$rc" -ne 0 ] || { echo "both-ways: the strict run passed without Chrome" >&2; exit 1; }+ grep -q "Chrome or Chromium is missing, and this run is strict" <<<"$out" \+ || { echo "both-ways: the strict run failed for another reason" >&2; exit 1; }+ echo "== no CI, no Chrome: must SKIP (pass, saying so)"+ rc=0; out=$(env -i HOME="$home" PATH=/nonexistent "$bin" --exact "$PROOF_NAME" --nocapture 2>&1) || rc=$?+ echo "$out"; echo "exit $rc"+ [ "$rc" -eq 0 ] && grep -q "skipped: Chrome or Chromium is missing" <<<"$out" \+ || { echo "both-ways: the local run didn't skip" >&2; exit 1; }+ rm -rf "$home"+ echo "both-ways: strict fails, local skips"+}++rust_tests() {+ local skip=()+ for t in "${DOCKER_TESTS[@]}"; do skip+=(--skip "$t"); done+ cargo test --locked --no-fail-fast -- "${skip[@]}"+}++case "${1:-}" in+ images) images ;;+ run) run ;;+ rust-tests) rust_tests ;;+ tools) tools ;;+ both-ways) both_ways ;;+ list) printf '%s\n' "${DOCKER_TESTS[@]}" ;;+ *) sed -n '2,12p' "$0" >&2; exit 2 ;;+esacdiff --git a/scripts/release_required_checks.txt b/scripts/release_required_checks.txtindex 84238e45..8132ce5d 100644--- a/scripts/release_required_checks.txt+++ b/scripts/release_required_checks.txt@@ -6,3 +6,4 @@ rustfrontendsitefresh-machine+docker-testsdiff --git a/scripts/test_check_test_skips.py b/scripts/test_check_test_skips.pynew file mode 100644index 00000000..ff07664e--- /dev/null+++ b/scripts/test_check_test_skips.py@@ -0,0 +1,113 @@+"""Tests for check_test_skips.py: python3 -m unittest discover -s scripts -p 'test_*.py'"""+import sys+import tempfile+import textwrap+import unittest+from pathlib import Path++sys.path.insert(0, str(Path(__file__).resolve().parent))+import check_test_skips # noqa: E402+++class CheckTestSkips(unittest.TestCase):+ def tree(self, files):+ d = tempfile.TemporaryDirectory()+ self.addCleanup(d.cleanup)+ root = Path(d.name)+ for rel in ("tests", "src"):+ (root / rel).mkdir()+ for rel, body in files.items():+ p = root / rel+ p.parent.mkdir(parents=True, exist_ok=True)+ p.write_text(textwrap.dedent(body))+ return root++ def problems(self, files):+ return check_test_skips.check(self.tree(files))++ def test_a_skip_printed_in_a_test_fails_on_its_line(self):+ found = self.problems({"tests/a_test.rs": """\+ #[test]+ fn t() {+ if chrome().is_none() {+ eprintln!("skipped: no Chrome or Chromium installed");+ return;+ }+ }+ """})+ self.assertEqual(len(found), 1, found)+ self.assertTrue(found[0].startswith("tests/a_test.rs:4: a test prints a skip itself"), found)++ def test_other_spellings_and_a_split_macro_are_caught(self):+ found = self.problems({"tests/b_test.rs": """\+ fn a() { println!("git isn't installed; skipped"); }+ fn b() { eprintln!("KWNT_X is not set: Skipping the live test"); }+ fn c() {+ eprintln!(+ "window part skipped: no Xvfb"+ );+ }+ fn d() { eprint!("no ffmpeg here: skipped\\n"); }+ """})+ self.assertEqual([p.split(": ")[0] for p in found],+ ["tests/b_test.rs:1", "tests/b_test.rs:2", "tests/b_test.rs:4", "tests/b_test.rs:8"], found)++ def test_the_helper_and_other_prints_pass(self):+ found = self.problems({+ "tests/support/skip.rs": 'pub fn skip_or_fail() { eprintln!("skipped: {what}"); std::env::var("CI"); }\n',+ "tests/c_test.rs": """\+ fn t() {+ if chrome().is_none() {+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);+ return;+ }+ eprintln!("took {ms} ms");+ }+ """,+ })+ self.assertEqual(found, [])++ def test_in_src_only_the_test_module_counts(self):+ found = self.problems({"src/setup.rs": """\+ fn install() {+ println!(" skipped: no terminal to ask in");+ }+ #[cfg(test)]+ mod tests {+ fn t() { eprintln!("skipped: no Chrome"); }+ }+ """})+ self.assertEqual([p.split(": ")[0] for p in found], ["src/setup.rs:6"], found)++ def test_reading_ci_directly_fails(self):+ found = self.problems({"tests/d_test.rs": """\+ fn t() {+ assert!(std::env::var_os("CI").is_none());+ assert!(std::env::var("KWNT_AGENT_TEST_REQUIRE").is_err());+ }+ """})+ self.assertEqual([p.split(": ")[0] for p in found], ["tests/d_test.rs:2", "tests/d_test.rs:3"], found)+ self.assertIn("skip::strict()", found[0])++ def test_an_ignored_test_must_be_listed(self):+ files = {"tests/e_test.rs": """\+ #[tokio::test]+ #[ignore = "needs the network"]+ async fn a_live_page_works() {}+ #[test]+ #[ignore]+ fn listed_one() {}+ fn f() { s.replace("#[test]\\n", "#[test]\\n#[ignore]\\n"); }+ """,+ "tests/NOT_IN_CI.md": "| `listed_one` | why | cmd |\n"}+ found = self.problems(files)+ self.assertEqual(len(found), 1, found)+ self.assertTrue(found[0].startswith("tests/e_test.rs:2: #[ignore]d test `a_live_page_works` is not listed"), found)++ def test_this_repo_passes(self):+ root = Path(__file__).resolve().parent.parent+ self.assertEqual(check_test_skips.check(root), [])+++if __name__ == "__main__":+ unittest.main()diff --git a/src/lib.rs b/src/lib.rsindex 0330c388..75ac2a91 100644--- a/src/lib.rs+++ b/src/lib.rs@@ -23,6 +23,11 @@ pub mod teams;pub mod tools;pub mod zombie;+/// tests/support/skip.rs, once for the whole lib: a missing test precondition skips locally and fails in CI.+#[cfg(test)]+#[path = "../tests/support/skip.rs"]+pub(crate) mod test_skip;+pub use broker::{ApprovalDecision, ApprovalRequest, PermissionBroker};pub use config::{Config, ConfigError};pub use db::{Database, DbError};diff --git a/src/sandbox/agent_vm/mod.rs b/src/sandbox/agent_vm/mod.rsindex d4fe9029..0d1d2a13 100644--- a/src/sandbox/agent_vm/mod.rs+++ b/src/sandbox/agent_vm/mod.rs@@ -1185,6 +1185,10 @@ impl Drop for IsolatedTurn {}}+// Only the Linux real-container test uses it; elsewhere the import would be unused (clippy -D warnings)+#[cfg(all(test, target_os = "linux"))]+use crate::test_skip as skip;+#[cfg(test)]mod tests {use super::*;@@ -1389,15 +1393,14 @@ mod tests {/// folder; a normal `git commit` inside still works, and nothing reached the hooks folder on/// this computer. Then the #462 review's race, made certain: `.git/hooks` is checked as a real/// folder, then swapped for a link to a "secret" folder before `docker run`, and the secret- /// must not be readable inside. Needs Docker and the agent image; skips without them unless- /// `KWNT_AGENT_TEST_REQUIRE=1`.+ /// must not be readable inside. Needs Docker and the agent image; skips without them, except in+ /// CI or with `KWNT_TEST_REQUIRE=1` (`skip_or_fail`).#[cfg(target_os = "linux")]#[test]fn in_a_real_container_a_hook_cant_be_written_but_git_commit_works() {use std::process::Command as Std;if !Std::new("docker").args(["image", "inspect", &image_tag()]).output().is_ok_and(|o| o.status.success()) {- assert!(std::env::var("KWNT_AGENT_TEST_REQUIRE").is_err(), "Docker or the agent image {} is missing", image_tag());- eprintln!("skipped: needs Docker and the agent image {}", image_tag());+ skip::skip_or_fail(&format!("Docker or the agent image {}", image_tag()), skip::AGENT_IMAGE_FIX);return;}let d = tempfile::tempdir().unwrap();diff --git a/src/sandbox/chrome_download.rs b/src/sandbox/chrome_download.rsindex 67fbbdc8..58189c9a 100644--- a/src/sandbox/chrome_download.rs+++ b/src/sandbox/chrome_download.rs@@ -526,6 +526,9 @@ async fn remove_profile(profile: &Path) {}}+#[cfg(test)]+use crate::test_skip as skip;+#[cfg(test)]mod tests {use super::*;@@ -603,7 +606,7 @@ mod tests {super::super::computer::local_chrome_path()};let Some(chrome) = chrome else {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;};let profile = tmp.path().join("p1");diff --git a/src/sandbox/identity.rs b/src/sandbox/identity.rsindex 7d0290bc..5c189170 100644--- a/src/sandbox/identity.rs+++ b/src/sandbox/identity.rs@@ -396,6 +396,9 @@ async fn run(browser_ws: String, ready: tokio::sync::oneshot::Sender<()>) {}}+#[cfg(test)]+use crate::test_skip as skip;+#[cfg(test)]mod tests {use super::*;@@ -495,7 +498,7 @@ mod tests {#[tokio::test]#[ignore]async fn real_chrome_keeps_its_identity() {- let Ok(driver) = std::env::var("KWNT_REAL_IDENTITY_DRIVER") else { return };+ let Some(driver) = skip::opt_in("KWNT_REAL_IDENTITY_DRIVER", "the real Chrome identity check") else { return };let headless = std::env::var("KWNT_REAL_HEADED").is_err();let profile = tempfile::tempdir().unwrap();let (endpoint, windowless) = super::super::computer::ensure_local_chrome(profile.path(), headless).await.unwrap();diff --git a/src/server/dev/scan/tests.rs b/src/server/dev/scan/tests.rsindex 9be9559f..2123b9d6 100644--- a/src/server/dev/scan/tests.rs+++ b/src/server/dev/scan/tests.rs@@ -11,6 +11,8 @@ use serde_json::json;use std::collections::{BTreeMap, BTreeSet};use std::time::Duration;+use crate::test_skip as skip;+fn diff(path: &str, status: &str, patch: Option<&str>) -> FileDiff {let adds = patch.map_or(0, |p| p.lines().filter(|l| l.starts_with('+')).count() as u64);let dels = patch.map_or(0, |p| p.lines().filter(|l| l.starts_with('-')).count() as u64);@@ -243,7 +245,7 @@ fn j_s2_hide_lines_replaces_whole_added_lines_and_keeps_numbers() {// Real gitleaks (local only): `KWANT_TEST_GITLEAKS=/path/to/gitleaks-8.30.1 cargo test j_s -- --ignored`fn real_bin() -> Option<std::path::PathBuf> {- let p = std::path::PathBuf::from(std::env::var("KWANT_TEST_GITLEAKS").ok()?);+ let p = std::path::PathBuf::from(skip::opt_in("KWANT_TEST_GITLEAKS", "the real gitleaks tests")?);p.is_file().then_some(p)}diff --git a/tests/NOT_IN_CI.md b/tests/NOT_IN_CI.mdnew file mode 100644index 00000000..7de593a1--- /dev/null+++ b/tests/NOT_IN_CI.md@@ -0,0 +1,66 @@+# Tests the rust job doesn't run++CI runs strict (`CI=true`, and the rust job also sets `KWNT_TEST_REQUIRE=1`): a test whose+precondition is missing fails through `skip::skip_or_fail` instead of passing having run nothing+(`tests/support/skip.rs`). What follows is every test the rust job's `cargo test` leaves out, why,+and the exact command that runs it. `scripts/check_test_skips.py` fails CI when an `#[ignore]`d test+isn't listed here.++## Run by CI's `docker-tests` job++The rust job has no kwant images, so it skips these by name (`scripts/ci_docker_tests.sh list`) or+they are `#[ignore]`d. The `docker-tests` job builds the executor, agent and browser images+(`scripts/ci_docker_tests.sh images`) and runs them all strict (`scripts/ci_docker_tests.sh run`).+Locally, with Docker: `scripts/ci_docker_tests.sh images && scripts/ci_docker_tests.sh run`.++| Test | Needs | Command |+|---|---|---|+| `the_three_attacks_fail_in_a_shell_and_in_the_agents_own_bash` | Docker, the agent image | `KWNT_TEST_REQUIRE=1 cargo test --test agents_in_vm_adversarial_test` |+| `nothing_the_bot_started_outlives_the_containers_last_turn` | Docker, the agent image | same |+| `an_approval_goes_through_kwnt_and_both_answers_work` | Docker, the agent image | same |+| `every_failure_is_a_notice_and_nothing_runs_on_this_computer` | Docker, the agent image (its broker-down case) | `KWNT_TEST_REQUIRE=1 cargo test --test agents_in_vm_fail_closed_test` |+| `in_a_real_container_a_hook_cant_be_written_but_git_commit_works` | Docker, the agent image | `KWNT_TEST_REQUIRE=1 cargo test --lib -- --exact sandbox::agent_vm::tests::in_a_real_container_a_hook_cant_be_written_but_git_commit_works` |+| `a_fresh_kwants_container_has_no_restart_and_labels_stops_at_shutdown_and_is_reaped_once_its_folder_is_gone` | Docker, the browser image; starts a container | `cargo test --test browser_container_test -- --ignored` |+| `a_vm_bots_download_from_the_browser_container_lands_in_its_own_folder` | Docker, the browser image; starts a container | `cargo test --test browser_container_download_test -- --ignored` |+| `live_chromium_stream_and_isolated_sessions` | Docker, the browser image | `cargo test --test browser_stream_test -- --ignored --exact live_chromium_stream_and_isolated_sessions` |+| `harness_measures_a_synthetic_app_and_leaves_nothing_behind` | Docker, `kwnt-executor:v1`, the oha image | `cargo test --test parallel_test -- --ignored` |+| `an_app_that_never_answers_is_cleaned_up_too` | same | same |+| `the_internal_network_reaches_neither_the_internet_nor_the_host` | same | same |+| `the_build_reaches_the_network_only_when_asked` | same | same |+| `a_real_run_through_the_routes_leaves_nothing_behind` | same | same |++## Not in CI: run by hand before a release++These need the open internet, a person, or something CI can't build. They are on the release+checklist (QA).++| Test | Why not in CI | Command |+|---|---|---|+| `a_public_page_quote_opens_at_it` | needs the network (gnu.org) and Chrome | `cargo test --test browser_cite_test -- --ignored a_public_page_quote_opens_at_it` |+| `saucedemo_checkout_asks_before_finish` | needs the network (saucedemo.com) and Chrome | `cargo test --test browser_pay_gate_test -- --ignored saucedemo_checkout_asks_before_finish` |+| `saucedemo_says_what_changed` | same | `cargo test --test browser_progress_test -- --ignored saucedemo_says_what_changed` |+| `saucedemo_reads_are_cheaper` | same | `cargo test --test browser_reads_test -- --ignored saucedemo_reads_are_cheaper` |+| `saucedemo_by_refs` | same | `cargo test --test browser_refs_test -- --ignored saucedemo_by_refs` |+| `a_browser_container_from_an_older_image_is_replaced` | needs two older browser images, `kwnt-browser:v1` and `:v2`, built by hand | build both from `docker/browser.Dockerfile`, then `cargo test --test browser_stream_test -- --ignored --exact a_browser_container_from_an_older_image_is_replaced` |+| `live_registry_smoke` | talks to registry.modelcontextprotocol.io | `cargo test --test mcp_suggest_test -- --ignored live_registry_smoke` |+| `captcha_handoff_ui_harness` | manual: a live UI for Playwright or a phone (see the file comment) | `cargo test --test captcha_ui_harness -- --ignored --nocapture` |+| `inbox_timing` | a measurement, not a check; prints the median for a report | `cargo test --test inbox_away_b_test inbox_timing -- --ignored --nocapture` |+| `router_eval` | expected concierge/ask routes fail until the router overhaul lands | `cargo test --test router_eval_test -- --ignored router_eval` |+| `write_settings_for_the_mac_ci_probe` | not a check: `.github/workflows/mac-local.yml` runs it on macOS to write settings for the Seatbelt probe | run by that workflow |++## Opt-in live tests++They need a real service or binary named by an environment variable. Without it they print+`skipped: … runs only with VAR set` (`skip::opt_in`) and pass, in CI too. They never fail for a+missing variable.++| Test | Variable | Command |+|---|---|---|+| `a_real_turn_and_a_resume_pass_through_kwnts_broker` | `KWNT_GATE0_KEY_FILE`: a file with a real Anthropic API key | `KWNT_GATE0_KEY_FILE=/path/to/key cargo test --test agents_in_vm_real_api_test -- --nocapture` |+| `bitwarden_end_to_end`, `wrong_master_passwords_lock_the_vault` | `KWNT_TEST_VAULTWARDEN`: a Vaultwarden URL with a test account | `KWNT_TEST_VAULTWARDEN=http://127.0.0.1:<port> cargo test --test bitwarden_test` |+| `the_imap_source_reads_without_changing_anything` | `KWNT_TEST_IMAP`: an IMAP test server address | `KWNT_TEST_IMAP=127.0.0.1:<port> cargo test --test zombie_imap_e2e` |+| `j_s2_real_gitleaks_finds_runtime_built_aws_github_stripe_and_private_keys` | `KWANT_TEST_GITLEAKS`: the gitleaks 8.30.1 binary (CI can't fetch it) | `KWANT_TEST_GITLEAKS=/path/to/gitleaks-8.30.1 cargo test --lib real_gitleaks -- --ignored` |+| `j_s3_real_gitleaks_ignores_checksums_integrity_uuids_shas_and_base64_images` | same | same |+| `f_a_real_gitleaks_finds_and_hides_keys_in_paths_its_allowlist_skips` | same | same |+| `real_chrome_keeps_its_identity` | `KWNT_REAL_IDENTITY_DRIVER`: the driver script that checks pages, popups and workers | `KWNT_REAL_IDENTITY_DRIVER=/path/to/driver cargo test --lib real_chrome_keeps_its_identity -- --ignored` |+| `real_capped_browser_keeps_the_driven_page_working` | `KWNT_REAL_CDP`: a kwnt-browser container started for this run, under a memory cap | `KWNT_REAL_CDP=http://127.0.0.1:<port> cargo test --test browser_recovery_test -- --ignored real_capped_browser_keeps_the_driven_page_working` |diff --git a/tests/agents_in_vm_adversarial_test.rs b/tests/agents_in_vm_adversarial_test.rsindex 3348c53e..c6a4c204 100644--- a/tests/agents_in_vm_adversarial_test.rs+++ b/tests/agents_in_vm_adversarial_test.rs@@ -14,10 +14,13 @@//! * I. (#17) the real key is in no log, no `docker inspect` and no process list.//!//! Needs Docker and the agent image (`docker build -f docker/agent.Dockerfile --build-arg-//! CLAUDE_VERSION=… -t kwnt-agent:v1-claude-…`). Without them it says so and passes, unless-//! `KWNT_AGENT_TEST_REQUIRE=1` (QA runs) makes that a failure.+//! CLAUDE_VERSION=… -t kwnt-agent:v1-claude-…`, or `scripts/ci_docker_tests.sh images`). Without+//! them it skips, except in CI or with `KWNT_TEST_REQUIRE=1`, where it fails (`skip_or_fail`).#![cfg(target_os = "linux")]+#[path = "support/skip.rs"]+mod skip;+use axum::{body::Bytes, http::HeaderMap, response::IntoResponse, Router};use kwnt::sandbox::agent_vm::{broker::{BrokerConfig, Credential, Secret},@@ -151,8 +154,7 @@ async fn probe(container: &str, script: &Path, host_paths: &str, extra: &[&str],#[tokio::test(flavor = "multi_thread", worker_threads = 4)]async fn the_three_attacks_fail_in_a_shell_and_in_the_agents_own_bash() {if !docker_ok() {- assert!(std::env::var("KWNT_AGENT_TEST_REQUIRE").is_err(), "Docker or the agent image {} is missing", image_tag());- eprintln!("skipped: needs Docker and the agent image {}", image_tag());+ skip::skip_or_fail(&format!("Docker or the agent image {}", image_tag()), skip::AGENT_IMAGE_FIX);return;}let data = tempfile::tempdir().unwrap();@@ -351,8 +353,7 @@ fn size(p: &Path) -> u64 {#[tokio::test(flavor = "multi_thread", worker_threads = 2)]async fn nothing_the_bot_started_outlives_the_containers_last_turn() {if !docker_ok() {- assert!(std::env::var("KWNT_AGENT_TEST_REQUIRE").is_err(), "Docker or the agent image {} is missing", image_tag());- eprintln!("skipped: needs Docker and the agent image {}", image_tag());+ skip::skip_or_fail(&format!("Docker or the agent image {}", image_tag()), skip::AGENT_IMAGE_FIX);return;}let data = tempfile::tempdir().unwrap();@@ -517,8 +518,7 @@ async fn approval_turn(name: &str, answer: bool) -> (Vec<String>, bool, usize, S#[tokio::test(flavor = "multi_thread", worker_threads = 4)]async fn an_approval_goes_through_kwnt_and_both_answers_work() {if !docker_ok() {- assert!(std::env::var("KWNT_AGENT_TEST_REQUIRE").is_err(), "Docker or the agent image {} is missing", image_tag());- eprintln!("skipped: needs Docker and the agent image {}", image_tag());+ skip::skip_or_fail(&format!("Docker or the agent image {}", image_tag()), skip::AGENT_IMAGE_FIX);return;}let (asked, ran, calls, said) = approval_turn("allow", true).await;diff --git a/tests/agents_in_vm_fail_closed_test.rs b/tests/agents_in_vm_fail_closed_test.rsindex 25e41d2d..d6492e74 100644--- a/tests/agents_in_vm_fail_closed_test.rs+++ b/tests/agents_in_vm_fail_closed_test.rs@@ -8,6 +8,8 @@#[path = "common/exe.rs"]mod exe;+#[path = "support/skip.rs"]+mod skip;use axum::Router;use kwnt::{@@ -204,7 +206,7 @@ async fn every_failure_is_a_notice_and_nothing_runs_on_this_computer() {case.refused(&case.run(&vm, Some(&profile), Some(&work)).await, "relay_down", "broker down");vm.remove_containers(|_| true).await;} else {- eprintln!("broker-down case skipped: needs Docker and {}", image_tag());+ skip::skip_or_fail(&format!("Docker or the agent image {} (for the broker-down case)", image_tag()), skip::AGENT_IMAGE_FIX);}// A missing folder is never swapped for one on this computer: the shim still never ranassert!(!case.marker().exists());diff --git a/tests/agents_in_vm_real_api_test.rs b/tests/agents_in_vm_real_api_test.rsindex f42b727e..483f48b9 100644--- a/tests/agents_in_vm_real_api_test.rs+++ b/tests/agents_in_vm_real_api_test.rs@@ -7,6 +7,9 @@//! and never printed.#![cfg(target_os = "linux")]+#[path = "support/skip.rs"]+mod skip;+use kwnt::config::AgentsInVmConfig;use kwnt::sandbox::agent_vm::{broker::{BrokerConfig, Credential, Secret},@@ -18,8 +21,7 @@ use tokio::process::Command;#[tokio::test(flavor = "multi_thread", worker_threads = 2)]async fn a_real_turn_and_a_resume_pass_through_kwnts_broker() {- let Some(key_file) = std::env::var_os("KWNT_GATE0_KEY_FILE") else {- eprintln!("skipped: set KWNT_GATE0_KEY_FILE to run against the real API");+ let Some(key_file) = skip::opt_in("KWNT_GATE0_KEY_FILE", "the real-API agents-in-VM turn") else {return;};let key = std::fs::read_to_string(&key_file).expect("the key file").trim().to_string();diff --git a/tests/bitwarden_test.rs b/tests/bitwarden_test.rsindex c85f494c..1d5d3e3d 100644--- a/tests/bitwarden_test.rs+++ b/tests/bitwarden_test.rs@@ -12,6 +12,9 @@//!//! Without it those tests pass without doing anything (and say so).+#[path = "support/skip.rs"]+mod skip;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -164,11 +167,7 @@ async fn vault_routes_are_the_persons_only() {}fn server() -> Option<String> {- let s = std::env::var("KWNT_TEST_VAULTWARDEN").ok().filter(|s| !s.is_empty());- if s.is_none() {- eprintln!("KWNT_TEST_VAULTWARDEN is not set: skipping the live Bitwarden test");- }- s+ skip::opt_in("KWNT_TEST_VAULTWARDEN", "the live Bitwarden test")}const MASTER: &str = "DUMMY-master-pw-kwnt-test";diff --git a/tests/browser_app_links_test.rs b/tests/browser_app_links_test.rsindex 2819d918..4f3f2fe1 100644--- a/tests/browser_app_links_test.rs+++ b/tests/browser_app_links_test.rs@@ -4,6 +4,10 @@//! guard's frame policy Chrome stops passing clicks and keys to the tab while it asks whether to//! open the app; with it, Chrome blocks the frame and the page keeps taking input. Skipped when no//! Chrome is installed.++#[path = "support/skip.rs"]+mod skip;+#[path = "support/chrome_guard.rs"]mod chrome_guard;use chrome_guard::ChromeGuard;@@ -120,7 +124,7 @@ async fn moves_reaching(ctrl: &BrowserController) -> i64 {#[tokio::test]async fn a_hidden_frame_opening_another_app_leaves_the_page_taking_input() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -142,7 +146,7 @@ async fn a_hidden_frame_opening_another_app_leaves_the_page_taking_input() {#[tokio::test]async fn frames_the_tab_opens_itself_still_load_under_the_guard() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;diff --git a/tests/browser_cite_test.rs b/tests/browser_cite_test.rsindex eda9a73b..be1cbd77 100644--- a/tests/browser_cite_test.rs+++ b/tests/browser_cite_test.rs@@ -3,6 +3,10 @@//! same-origin frame); the link, opened, scrolls the browser to the quote (Chrome highlights it).//! A quote that isn't there, or is there twice, is refused. Blocks: a read with ids, cited by id.//! Skipped when no Chrome is installed.++#[path = "support/skip.rs"]+mod skip;+#[path = "support/chrome_guard.rs"]mod chrome_guard;use axum::{@@ -195,7 +199,7 @@ async fn open_link(ctrl: &BrowserController, link: &str) -> f64 {#[tokio::test]async fn a_quote_on_the_page_gets_a_link_that_opens_at_it_and_a_made_up_one_is_refused() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -291,7 +295,7 @@ async fn a_quote_on_the_page_gets_a_link_that_opens_at_it_and_a_made_up_one_is_r#[ignore = "needs the network"]async fn a_public_page_quote_opens_at_it() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -323,7 +327,7 @@ async fn a_public_page_quote_opens_at_it() {#[tokio::test]async fn a_lookalike_earlier_on_the_page_never_gets_the_link() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;diff --git a/tests/browser_container_download_test.rs b/tests/browser_container_download_test.rsindex 53023b17..04de3e20 100644--- a/tests/browser_container_download_test.rs+++ b/tests/browser_container_download_test.rs@@ -1,5 +1,5 @@//! 20g: a vm-mode bot's download from kwant's own browser container lands in the bot's own-//! `downloads/`, against real Chromium in the `kwnt-browser:v3` image. Run with+//! `downloads/`, against real Chromium in the `kwnt-browser` image (`BROWSER_IMAGE`). Run with//! `cargo test --test browser_container_download_test -- --ignored` on a host with Docker and that//! image. Ignored by default so CI and ordinary test runs never start a container.//!@@ -157,7 +157,7 @@ fn app_state(data_dir: &std::path::Path, db: Database, cdp_url: Option<String>)}#[tokio::test]-#[ignore = "needs Docker and the kwnt-browser:v3 image; starts a real container"]+#[ignore = "needs Docker and the kwnt-browser image (BROWSER_IMAGE); starts a real container"]async fn a_vm_bots_download_from_the_browser_container_lands_in_its_own_folder() {std::env::set_var(kwnt::sandbox::computer::MODE_ENV, "vm");std::env::remove_var("KWNT_BROWSER_CDP_URL");diff --git a/tests/browser_container_test.rs b/tests/browser_container_test.rsindex 6f77448b..2fad9b4d 100644--- a/tests/browser_container_test.rs+++ b/tests/browser_container_test.rs@@ -1,6 +1,6 @@//! The VM browser container's lifecycle against real Docker: run with//! `cargo test --test browser_container_test -- --ignored` on a host with Docker and the-//! `kwnt-browser:v3` image. Ignored by default so CI and ordinary test runs never start a container.+//! `kwnt-browser` image (`BROWSER_IMAGE`). Ignored by default so CI and ordinary test runs never start a container.use kwnt::sandbox::service::{managed_container_name, BrowserService};use std::process::Command;use std::time::Duration;@@ -17,7 +17,7 @@ impl Drop for Cleanup {}#[tokio::test]-#[ignore = "needs Docker and the kwnt-browser:v3 image; starts a real container"]+#[ignore = "needs Docker and the kwnt-browser image (BROWSER_IMAGE); starts a real container"]async fn a_fresh_kwants_container_has_no_restart_and_labels_stops_at_shutdown_and_is_reaped_once_its_folder_is_gone() {std::env::set_var(kwnt::sandbox::computer::MODE_ENV, "vm");let tmp = tempfile::tempdir().unwrap();diff --git a/tests/browser_download_upload_test.rs b/tests/browser_download_upload_test.rsindex f61f4d8f..cae9a388 100644--- a/tests/browser_download_upload_test.rs+++ b/tests/browser_download_upload_test.rs@@ -2,6 +2,9 @@//! tool answering a page's own file picker with a file from that folder or a chat attachment.//! Runs a real windowless Chrome in Local mode and is skipped when none is installed.+#[path = "support/skip.rs"]+mod skip;+#[path = "support/chrome_guard.rs"]mod chrome_guard;use chrome_guard::ChromeGuard;@@ -188,7 +191,7 @@ async fn wait_for_download(app: &Router, token: &str) -> Value {#[tokio::test]async fn a_download_lands_in_the_bots_own_folder() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -221,7 +224,7 @@ async fn a_download_lands_in_the_bots_own_folder() {#[tokio::test]async fn a_second_download_with_the_same_name_never_overwrites_the_first() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -250,7 +253,7 @@ async fn a_second_download_with_the_same_name_never_overwrites_the_first() {#[tokio::test]async fn a_download_in_one_bots_session_never_reaches_another() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -292,7 +295,7 @@ async fn a_download_in_one_bots_session_never_reaches_another() {#[tokio::test]async fn browser_upload_answers_the_pages_own_picker_with_a_workspace_file() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -326,7 +329,7 @@ async fn browser_upload_answers_the_pages_own_picker_with_a_workspace_file() {#[tokio::test]async fn browser_upload_answers_the_pages_own_picker_with_a_chat_attachment() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -364,7 +367,7 @@ async fn browser_upload_answers_the_pages_own_picker_with_a_chat_attachment() {#[tokio::test]async fn browser_upload_refuses_an_attachment_from_another_chat() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -410,7 +413,7 @@ async fn browser_upload_refuses_an_attachment_from_another_chat() {#[tokio::test]async fn browser_upload_fills_a_multiple_file_input_in_one_call() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -444,7 +447,7 @@ async fn browser_upload_fills_a_multiple_file_input_in_one_call() {#[tokio::test]async fn browser_upload_is_refused_with_no_picker_open() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;diff --git a/tests/browser_file_chooser_test.rs b/tests/browser_file_chooser_test.rsindex 2d34e84e..73136ca7 100644--- a/tests/browser_file_chooser_test.rs+++ b/tests/browser_file_chooser_test.rs@@ -5,6 +5,10 @@//! attachment already uploaded through `/api/attachments`, cancelling, and a chooser cleared by//! navigation. Skipped when no Chrome is installed. Local delivery only — there's no remote Chrome//! in this environment to exercise the base64/DataTransfer path.++#[path = "support/skip.rs"]+mod skip;+#[path = "support/chrome_guard.rs"]mod chrome_guard;use axum::{@@ -150,7 +154,7 @@ async fn take_control(ws: &mut Ws) {#[tokio::test]async fn picking_a_visible_input_uploads_and_delivers_the_file() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -183,7 +187,7 @@ async fn picking_a_visible_input_uploads_and_delivers_the_file() {#[tokio::test]async fn a_tiktok_style_hidden_input_behind_a_button_is_intercepted_too() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -214,7 +218,7 @@ async fn a_tiktok_style_hidden_input_behind_a_button_is_intercepted_too() {#[tokio::test]async fn cancelling_the_sheet_gets_no_reply_and_leaves_the_page_untouched() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -249,7 +253,7 @@ async fn cancelling_the_sheet_gets_no_reply_and_leaves_the_page_untouched() {#[tokio::test]async fn retrying_the_same_chooser_after_a_failed_answer_still_delivers_the_file() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -288,7 +292,7 @@ async fn retrying_the_same_chooser_after_a_failed_answer_still_delivers_the_file#[tokio::test]async fn navigating_away_while_the_sheet_is_open_clears_it() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;diff --git a/tests/browser_hover_test.rs b/tests/browser_hover_test.rsindex 4bbcf2c0..e1b8f572 100644--- a/tests/browser_hover_test.rs+++ b/tests/browser_hover_test.rs@@ -6,6 +6,10 @@//! what appeared. Ordinary controls are listed before hover controls and cards, which are capped//! at 40 each, icon-only buttons are named by their icon word, and the payment check still judges//! the same element and label. Skipped when no Chrome is installed.++#[path = "support/skip.rs"]+mod skip;+#[path = "support/chrome_guard.rs"]mod chrome_guard;use axum::{@@ -200,7 +204,7 @@ fn lines(page: &Value) -> Vec<String> {#[tokio::test]async fn a_hover_only_menu_on_a_tile_opens_and_downloads_by_text_and_by_ref() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -269,7 +273,7 @@ async fn a_hover_only_menu_on_a_tile_opens_and_downloads_by_text_and_by_ref() {#[tokio::test]async fn a_hover_says_what_appeared_and_clicks_nothing() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -301,7 +305,7 @@ async fn a_hover_says_what_appeared_and_clicks_nothing() {#[tokio::test]async fn cards_are_capped_and_icon_buttons_are_named() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -342,7 +346,7 @@ async fn cards_are_capped_and_icon_buttons_are_named() {#[tokio::test]async fn the_payment_check_still_judges_the_same_control() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;diff --git a/tests/browser_keys_test.rs b/tests/browser_keys_test.rsindex ed89e189..3c307331 100644--- a/tests/browser_keys_test.rs+++ b/tests/browser_keys_test.rs@@ -2,6 +2,10 @@//! submits a form, and letters, Space, Backspace and Tab still do what they do on a keyboard.//! Before the fix the bot's Enter went out as a bare `rawKeyDown` with only `key` and `code`://! keydown fired, the form never submitted. Skipped when no Chrome is installed.++#[path = "support/skip.rs"]+mod skip;+#[path = "support/chrome_guard.rs"]mod chrome_guard;use axum::{@@ -120,7 +124,7 @@ async fn url_after(ctrl: &BrowserController, wait: Duration) -> String {#[tokio::test]async fn a_bots_enter_submits_the_form_and_other_keys_still_type() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;diff --git a/tests/browser_pages_test.rs b/tests/browser_pages_test.rsindex 20b9c9ff..f2d5ac99 100644--- a/tests/browser_pages_test.rs+++ b/tests/browser_pages_test.rs@@ -8,6 +8,9 @@//! DevTools endpoint, where a job page is a new page in the team's browser context) and in Local//! mode (a new window of the person's Chrome). Skipped when no Chrome is installed.+#[path = "support/skip.rs"]+mod skip;+#[path = "support/chrome_guard.rs"]mod chrome_guard;use axum::{@@ -64,7 +67,7 @@ async fn serve() -> String {async fn start_chrome(profile: &Path) -> Option<(String, ChromeGuard)> {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return None;}let (endpoint, _) = computer::ensure_local_chrome(profile, true).await.expect("Chrome starts");@@ -552,7 +555,7 @@ async fn closing_a_pages_connections_keeps_its_sign_in_and_reconnects_the_same_p#[tokio::test]async fn in_local_mode_a_job_page_is_a_window_of_the_same_chrome_with_its_sign_ins() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let tmp = tempdir().unwrap();diff --git a/tests/browser_pay_gate_test.rs b/tests/browser_pay_gate_test.rsindex 8efa77f0..2e3cdecc 100644--- a/tests/browser_pay_gate_test.rs+++ b/tests/browser_pay_gate_test.rs@@ -4,6 +4,10 @@//! The shell bots' `/act` API can't show a card, so it refuses those and does nothing.//! Skipped when no Chrome is installed. `saucedemo_checkout_asks_before_finish` (ignored, needs//! the network) walks a real demo shop to its last step.++#[path = "support/skip.rs"]+mod skip;+#[path = "support/chrome_guard.rs"]mod chrome_guard;use axum::{@@ -149,7 +153,7 @@ async fn post_act(app: &Router, bot: &str, body: Value) -> (StatusCode, Value) {#[tokio::test]async fn the_page_decides_whether_a_browser_click_pays() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -192,7 +196,7 @@ async fn the_page_decides_whether_a_browser_click_pays() {#[tokio::test]async fn space_on_a_focused_button_asks_like_enter() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -224,7 +228,7 @@ async fn space_on_a_focused_button_asks_like_enter() {#[tokio::test]async fn approvals_off_still_cards_a_card_form_click_and_the_shell_api_refuses_it() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -283,7 +287,7 @@ async fn approvals_off_still_cards_a_card_form_click_and_the_shell_api_refuses_i#[ignore]async fn saucedemo_checkout_asks_before_finish() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;diff --git a/tests/browser_popups_test.rs b/tests/browser_popups_test.rsindex 7a07f79b..be019a10 100644--- a/tests/browser_popups_test.rs+++ b/tests/browser_popups_test.rs@@ -2,6 +2,10 @@//! `window.open`, the popup posts its answer back to the page that opened it and closes. The bot's//! browser tools and the live view both move to the popup while it is open and come back to the//! opener when it closes. Skipped when no Chrome is installed.++#[path = "support/skip.rs"]+mod skip;+#[path = "support/chrome_guard.rs"]mod chrome_guard;use chrome_guard::ChromeGuard;@@ -96,7 +100,7 @@ async fn click(ctrl: &BrowserController) {#[tokio::test]async fn a_popup_the_page_opens_is_where_the_bots_tools_act_until_it_closes() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -134,7 +138,7 @@ async fn next_message(ws: &mut Ws, kind: &str, matches: impl Fn(&Value) -> bool)#[tokio::test]async fn the_live_view_shows_a_popup_the_page_opens_and_comes_back_when_it_closes() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;diff --git a/tests/browser_progress_test.rs b/tests/browser_progress_test.rsindex 38c2c94c..cdd81243 100644--- a/tests/browser_progress_test.rs+++ b/tests/browser_progress_test.rs@@ -3,6 +3,10 @@//! for a slow change, and stops a bot whose last 3 actions changed nothing or who asks a 3rd time//! in a row for the same action that changed nothing. Opening an address starts over. Skipped when no Chrome is//! installed.++#[path = "support/skip.rs"]+mod skip;+#[path = "support/chrome_guard.rs"]mod chrome_guard;use axum::{@@ -115,7 +119,7 @@ fn click(label: &str) -> Value {#[tokio::test]async fn each_action_says_what_changed_and_a_loop_is_stopped() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -187,6 +191,7 @@ async fn each_action_says_what_changed_and_a_loop_is_stopped() {#[ignore]async fn saucedemo_says_what_changed() {if computer::local_chrome_path().is_none() {+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;diff --git a/tests/browser_reads_test.rs b/tests/browser_reads_test.rsindex b1e94c0e..b7f0de81 100644--- a/tests/browser_reads_test.rs+++ b/tests/browser_reads_test.rs@@ -3,6 +3,10 @@//! the HTTP API, per turn for `browser_page`), and a page with many controls lists 40, the ones//! matching the bot's `find` words first, with their refs kept. Skipped when no Chrome is//! installed.++#[path = "support/skip.rs"]+mod skip;+#[path = "support/chrome_guard.rs"]mod chrome_guard;use axum::{@@ -123,7 +127,7 @@ async fn tool(e: &Env, token: &str, name: &str, args: Value) -> Value {#[tokio::test]async fn an_unchanged_page_is_not_sent_again_and_a_long_list_puts_matches_first() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -198,7 +202,7 @@ async fn an_unchanged_page_is_not_sent_again_and_a_long_list_puts_matches_first(#[ignore = "needs the network"]async fn saucedemo_reads_are_cheaper() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;diff --git a/tests/browser_recovery_test.rs b/tests/browser_recovery_test.rsindex 44459e5b..8bbdaf44 100644--- a/tests/browser_recovery_test.rs+++ b/tests/browser_recovery_test.rs@@ -9,6 +9,9 @@ use serde_json::{json, Value};use std::{sync::{atomic::{AtomicUsize, Ordering}, Arc}, time::{Duration, Instant}};use tokio::{net::TcpListener, sync::Mutex};+#[path = "support/skip.rs"]+mod skip;+/// A DevTools endpoint that can stop answering for a while, the way an overloaded Chrome does:/// its `/json` requests hang and its sockets take commands without replying.#[derive(Clone, Default)]@@ -259,7 +262,7 @@ async fn eval(ctrl: &kwnt::sandbox::BrowserController, expression: &str) -> Valu#[tokio::test]#[ignore]async fn real_capped_browser_keeps_the_driven_page_working() {- let Ok(endpoint) = std::env::var("KWNT_REAL_CDP") else { return };+ let Some(endpoint) = skip::opt_in("KWNT_REAL_CDP", "the real capped browser run") else { return };let tmp = tempfile::tempdir().unwrap();let (state, id, _port, app_task) = server(endpoint, &tmp).await;let steady = |key: String| { let state = state.clone(); async move {diff --git a/tests/browser_refs_test.rs b/tests/browser_refs_test.rsindex 8d3a96be..1582bf9a 100644--- a/tests/browser_refs_test.rs+++ b/tests/browser_refs_test.rs@@ -4,6 +4,10 @@//! covered clicks nothing and says why, with a fresh list. Payments are judged on the element//! the ref points to. Skipped when no Chrome is installed. `saucedemo_by_refs` (ignored, needs//! the network) shops a real demo store by refs.++#[path = "support/skip.rs"]+mod skip;+#[path = "support/chrome_guard.rs"]mod chrome_guard;use axum::{@@ -140,7 +144,7 @@ async fn eval(ctrl: &kwnt::sandbox::BrowserController, js: &str) {#[tokio::test]async fn a_click_by_ref_hits_that_control_or_nothing() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -209,7 +213,7 @@ async fn a_click_by_ref_hits_that_control_or_nothing() {#[tokio::test]async fn a_payment_is_judged_on_the_element_a_ref_points_to() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -235,6 +239,7 @@ async fn a_payment_is_judged_on_the_element_a_ref_points_to() {#[ignore]async fn saucedemo_by_refs() {if computer::local_chrome_path().is_none() {+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;@@ -263,7 +268,7 @@ fn marked(page: &Value) -> Vec<String> {#[tokio::test]async fn controls_that_just_appeared_are_marked_new_and_nothing_else() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;diff --git a/tests/browser_screenshot_test.rs b/tests/browser_screenshot_test.rsindex d35cfb29..322d86e9 100644--- a/tests/browser_screenshot_test.rs+++ b/tests/browser_screenshot_test.rs@@ -5,6 +5,9 @@//! Runs a real windowless Chrome as the "VM" browser (an external CDP endpoint) and is skipped//! when none is installed; tests/browser_test.rs covers the viewport steps on a fake browser.+#[path = "support/skip.rs"]+mod skip;+#[path = "support/chrome_guard.rs"]mod chrome_guard;use axum::{@@ -57,7 +60,7 @@ async fn serve_page() -> String {async fn start_chrome(profile: &Path) -> Option<(String, ChromeGuard)> {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return None;}let (endpoint, _) = computer::ensure_local_chrome(profile, true).await.expect("Chrome starts");diff --git a/tests/browser_site_rules_test.rs b/tests/browser_site_rules_test.rsindex 65f60adf..a6db051d 100644--- a/tests/browser_site_rules_test.rs+++ b/tests/browser_site_rules_test.rs@@ -3,6 +3,10 @@//! bot causes (opening an address, a link click, a redirect, a new tab), while the person's own//! clicks are never held to them. With no rules the guard doesn't run at all. Skipped when no//! Chrome is installed.++#[path = "support/skip.rs"]+mod skip;+#[path = "support/chrome_guard.rs"]mod chrome_guard;use axum::{@@ -135,7 +139,7 @@ async fn href(ctrl: &kwnt::sandbox::BrowserController) -> String {#[tokio::test]async fn a_bots_site_rules_hold_on_every_navigation_it_causes() {if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let e = setup().await;diff --git a/tests/browser_stream_test.rs b/tests/browser_stream_test.rsindex 96b98820..6f2bdc97 100644--- a/tests/browser_stream_test.rs+++ b/tests/browser_stream_test.rs@@ -1,3 +1,6 @@+#[path = "support/skip.rs"]+mod skip;+use axum::{extract::{State, Path, WebSocketUpgrade, ws::Message}, routing::get, Json, Router};use futures::{SinkExt, StreamExt};use kwnt::{config::Config, db::Database, tools::ToolRunner, broker::PermissionBroker, router::LayaRouter, server::{AppState, create_router}, sandbox::service::BrowserService};@@ -768,7 +771,7 @@ async fn a_link_to_another_app_is_stopped_or_its_prompt_closed_so_the_tab_keeps_/// Opt in after building docker/browser.Dockerfile. Uses disposable data and a local HTML page.#[tokio::test]-#[ignore = "requires Docker and the kwnt-browser:v3 image"]+#[ignore = "requires Docker and the kwnt-browser image (BROWSER_IMAGE)"]async fn live_chromium_stream_and_isolated_sessions() {let _ = tracing_subscriber::fmt().with_max_level(tracing::Level::WARN).try_init();let tmp = tempfile::tempdir().unwrap();@@ -1357,7 +1360,7 @@ impl Drop for LocalChrome {}/// Starts `KWNT_TEST_CHROME`, or Chrome or Chromium from PATH, and returns its DevTools address.-/// `None` when there is none, except on Linux CI, which has Chrome and must run these checks.+/// `None` when there is none (`skip_or_fail`: a failure in CI).fn local_chrome(profile: &std::path::Path) -> Option<(LocalChrome, String)> {let found = std::env::var("KWNT_TEST_CHROME").ok().or_else(|| {["google-chrome", "google-chrome-stable", "chromium", "chromium-browser"]@@ -1366,11 +1369,7 @@ fn local_chrome(profile: &std::path::Path) -> Option<(LocalChrome, String)> {.map(|p| p.to_string_lossy().into_owned())});let Some(bin) = found else {- assert!(- !(cfg!(target_os = "linux") && std::env::var_os("CI").is_some()),- "Linux CI has Chrome: set KWNT_TEST_CHROME or put it on PATH"- );- eprintln!("skipped: no Chrome or Chromium (set KWNT_TEST_CHROME)");+ skip::skip_or_fail("Chrome or Chromium", "put Chrome or Chromium on PATH, or set KWNT_TEST_CHROME to its binary");return None;};let child = std::process::Command::new(&bin)diff --git a/tests/browser_tools_test.rs b/tests/browser_tools_test.rsindex 2af7a29b..14be584b 100644--- a/tests/browser_tools_test.rs+++ b/tests/browser_tools_test.rs@@ -4,6 +4,9 @@//! only the turn's own sandbox. The browser part runs a real windowless Chrome in Local mode and//! is skipped when none is installed.+#[path = "support/skip.rs"]+mod skip;+#[path = "support/chrome_guard.rs"]mod chrome_guard;use chrome_guard::ChromeGuard;@@ -193,7 +196,7 @@ async fn claude_turn_gets_browser_tools_that_drive_its_own_panel() {}if computer::local_chrome_path().is_none() {- eprintln!("browser part skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);mcp_runtime::finish_turn(&state, &token).await;return;}diff --git a/tests/captcha_test.rs b/tests/captcha_test.rsindex 25332735..cddbdcbb 100644--- a/tests/captcha_test.rs+++ b/tests/captcha_test.rs@@ -6,6 +6,9 @@//! The browser parts run a real windowless Chrome as the "VM" browser (an external CDP endpoint)//! and are skipped when none is installed; the time-out part needs no browser.+#[path = "support/skip.rs"]+mod skip;+#[path = "support/chrome_guard.rs"]mod chrome_guard;use axum::{@@ -70,7 +73,7 @@ async fn serve_fixtures() -> String {/// A windowless Chrome on its own profile, standing in for the VM browser.async fn start_chrome(profile: &Path) -> Option<(String, ChromeGuard)> {if computer::local_chrome_path().is_none() {- eprintln!("browser part skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return None;}let (endpoint, _) = computer::ensure_local_chrome(profile, true).await.expect("Chrome starts");diff --git a/tests/captcha_turn_test.rs b/tests/captcha_turn_test.rsindex ff41434a..b3a09977 100644--- a/tests/captcha_turn_test.rs+++ b/tests/captcha_turn_test.rs@@ -6,6 +6,9 @@//! the browser API the prompt gives it. Its own test binary: it changes PATH. Skipped when no//! Chrome or Chromium is installed.+#[path = "support/skip.rs"]+mod skip;+#[path = "common/exe.rs"]mod exe;#[path = "support/chrome_guard.rs"]@@ -115,7 +118,7 @@ struct Env {async fn setup() -> Option<Env> {behave_dir();if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return None;}let tmp = tempfile::tempdir().unwrap();diff --git a/tests/local_chrome_exit_test.rs b/tests/local_chrome_exit_test.rsindex 7a1c6238..45b5ff4d 100644--- a/tests/local_chrome_exit_test.rs+++ b/tests/local_chrome_exit_test.rs@@ -3,6 +3,9 @@//! wait; one that is only slow to open its port still starts.#![cfg(unix)]+#[path = "support/skip.rs"]+mod skip;+use kwnt::sandbox::computer::{self, CHROME_PATH_ENV};use std::os::unix::fs::PermissionsExt;use std::path::Path;@@ -47,7 +50,7 @@ async fn a_chrome_that_exits_at_once_fails_fast_with_its_last_line() {async fn a_chrome_that_is_only_slow_still_starts() {let _env = ENV.lock().await;if std::process::Command::new("python3").arg("--version").output().is_err() {- eprintln!("skipped: no python3 for the slow fake Chrome");+ skip::skip_or_fail("python3 (for the slow fake Chrome)", "install python3");return;}let tmp = tempfile::tempdir().unwrap();diff --git a/tests/local_chrome_test.rs b/tests/local_chrome_test.rsindex 69fad284..a4170a38 100644--- a/tests/local_chrome_test.rs+++ b/tests/local_chrome_test.rs@@ -1,6 +1,10 @@//! Local mode against a real Chrome/Chromium: it runs without a window, pages render and take//! input at the viewer's 1280x800 size, and the window switch reopens the same page in a real-//! window and back. Skipped when no Chrome is installed; the window part needs Xvfb on Linux.+//! window and back. Without Chrome it skips (and fails in CI); the window part needs Xvfb on Linux.++#[path = "support/skip.rs"]+mod skip;+#[path = "support/chrome_guard.rs"]mod chrome_guard;use chrome_guard::ChromeGuard;@@ -60,7 +64,7 @@ async fn local_chrome_runs_windowless_and_can_open_as_a_window() {std::env::remove_var("DISPLAY");std::env::remove_var("WAYLAND_DISPLAY");if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let tmp = tempfile::tempdir().unwrap();@@ -140,7 +144,7 @@ async fn local_chrome_runs_windowless_and_can_open_as_a_window() {let _ = xvfb.kill();let _ = xvfb.wait();} else {- eprintln!("window part skipped: no Xvfb");+ skip::skip_or_fail("Xvfb (for the window part)", "install Xvfb, e.g. `apt install xvfb`");}// leaving local mode closes the windowless Chrome, since nothing would show itdiff --git a/tests/local_chrome_upgrade_test.rs b/tests/local_chrome_upgrade_test.rsindex 27a938e6..2b81a589 100644--- a/tests/local_chrome_upgrade_test.rs+++ b/tests/local_chrome_upgrade_test.rs@@ -1,6 +1,10 @@//! Upgrading kwant with its windowless Chrome still running: kwant 0.9.4 started it with a made-up//! `--user-agent` and marked automated (`navigator.webdriver`), which Google refuses to sign in,//! so kwant restarts it once as Chrome, and never again after. Skipped when no Chrome is installed.++#[path = "support/skip.rs"]+mod skip;+#[path = "support/chrome_guard.rs"]mod chrome_guard;use chrome_guard::ChromeGuard;@@ -15,7 +19,7 @@ async fn an_older_kwants_headless_chrome_is_restarted_once() {std::env::remove_var("DISPLAY");std::env::remove_var("WAYLAND_DISPLAY");let Some(chrome) = computer::local_chrome_path() else {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;};let tmp = tempfile::tempdir().unwrap();diff --git a/tests/mission_checkpoints_test.rs b/tests/mission_checkpoints_test.rsindex 651d155d..10f0836d 100644--- a/tests/mission_checkpoints_test.rs+++ b/tests/mission_checkpoints_test.rs@@ -5,6 +5,9 @@//! gaps: the retry `Idempotency-Key` and the drift scan's limits. Its own test binary: it changes//! PATH and listens on a real port the stand-in CLI calls back on.+#[path = "support/skip.rs"]+mod skip;+#[path = "common/exe.rs"]mod exe;@@ -613,7 +616,7 @@ async fn an_unreadable_folder_fails_the_checkpoint_but_not_the_turn() {if std::fs::read_dir(&dir).is_ok() {// Running as root: permissions don't stop reads, so there is nothing to teststd::fs::set_permissions(&dir, std::fs::Permissions::from_mode(0o755)).unwrap();- eprintln!("skipped: the folder stays readable (root?)");+ skip::skip_or_fail("a user that file modes apply to (the folder stays readable: root?)", "run the tests as a normal user");return;}let tid = &ids[0];diff --git a/tests/show_once_recorder_test.rs b/tests/show_once_recorder_test.rsindex 0065d393..3c0180dd 100644--- a/tests/show_once_recorder_test.rs+++ b/tests/show_once_recorder_test.rs@@ -3,6 +3,10 @@//! parser. Covers S-F2 (a field a script filled and the person then edited is masked) and S-F5//! (a field left by kwnt's own navigation, with no blur, is committed first, masked). Skipped//! when no Chrome is installed.++#[path = "support/skip.rs"]+mod skip;+#[path = "support/chrome_guard.rs"]mod chrome_guard;use chrome_guard::ChromeGuard;@@ -88,7 +92,7 @@ async fn the_recorder_masks_any_field_whose_text_is_not_all_the_persons_own_typistd::env::remove_var("DISPLAY");std::env::remove_var("WAYLAND_DISPLAY");if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let tmp = tempfile::tempdir().unwrap();@@ -191,7 +195,7 @@ async fn a_pick_in_the_drawn_list_is_a_select_step_and_a_wrapping_label_names_thstd::env::remove_var("DISPLAY");std::env::remove_var("WAYLAND_DISPLAY");if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let tmp = tempfile::tempdir().unwrap();@@ -273,7 +277,7 @@ async fn leaving_by_the_address_bar_with_no_blur_records_the_secret_fields_maskestd::env::remove_var("DISPLAY");std::env::remove_var("WAYLAND_DISPLAY");if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return;}let tmp = tempfile::tempdir().unwrap();diff --git a/tests/sign_in_wall_test.rs b/tests/sign_in_wall_test.rsindex e09fbb85..13cb9ef9 100644--- a/tests/sign_in_wall_test.rs+++ b/tests/sign_in_wall_test.rs@@ -7,6 +7,9 @@//! browser through the shell API (curl) like a bot without kwnt's tools. Its own test binary: it//! changes PATH. Skipped when no Chrome or Chromium is installed.+#[path = "support/skip.rs"]+mod skip;+#[path = "common/exe.rs"]mod exe;#[path = "support/chrome_guard.rs"]@@ -116,7 +119,7 @@ struct Env {async fn setup() -> Option<Env> {behave_dir();if computer::local_chrome_path().is_none() {- eprintln!("skipped: no Chrome or Chromium installed");+ skip::skip_or_fail("Chrome or Chromium", skip::CHROME_FIX);return None;}let tmp = tempfile::tempdir().unwrap();diff --git a/tests/skip_helper_test.rs b/tests/skip_helper_test.rsnew file mode 100644index 00000000..1ebca4b6--- /dev/null+++ b/tests/skip_helper_test.rs@@ -0,0 +1,48 @@+//! `skip_or_fail` and `strict()` (tests/support/skip.rs). Its own binary, because it changes CI and+//! KWNT_TEST_REQUIRE for the whole process.++#[path = "support/skip.rs"]+mod skip;++use skip::{opt_in, skip_or_fail, strict};++const KEYS: [&str; 3] = ["CI", "KWNT_TEST_REQUIRE", "KWNT_AGENT_TEST_REQUIRE"];++fn panic_text(f: impl FnOnce() + std::panic::UnwindSafe) -> Option<String> {+ std::panic::catch_unwind(f).err().map(|e| *e.downcast::<String>().unwrap())+}++// One test for every branch: env vars are process-wide, so separate tests would race.+#[test]+fn a_missing_precondition_skips_without_ci_and_fails_with_the_fix_in_ci() {+ let saved: Vec<_> = KEYS.iter().map(std::env::var_os).collect();+ for k in KEYS {+ std::env::remove_var(k);+ }+ assert!(!strict());+ assert_eq!(panic_text(|| skip_or_fail("a thing", "run `make thing`")), None, "skips without CI");++ for k in KEYS {+ for (v, want) in [("true", true), ("1", true), ("TRUE", true), ("0", false), ("false", false), ("", false)] {+ std::env::set_var(k, v);+ assert_eq!(strict(), want, "{k}={v}");+ }+ std::env::set_var(k, "1");+ let msg = panic_text(|| skip_or_fail("a thing", "run `make thing`")).unwrap_or_else(|| panic!("{k}=1 must fail"));+ assert!(msg.contains("a thing is missing") && msg.contains("run `make thing`") && msg.contains("CI=true"), "{msg}");+ std::env::remove_var(k);+ }++ // Opt-in live tests stay skipped in CI+ std::env::set_var("CI", "true");+ assert_eq!(opt_in("KWNT_TEST_SKIP_HELPER_NEVER_SET", "x"), None);+ std::env::set_var("KWNT_TEST_SKIP_HELPER_SET", "v");+ assert_eq!(opt_in("KWNT_TEST_SKIP_HELPER_SET", "x").as_deref(), Some("v"));++ for (k, v) in KEYS.iter().zip(saved) {+ match v {+ Some(v) => std::env::set_var(k, v),+ None => std::env::remove_var(k),+ }+ }+}diff --git a/tests/support/skip.rs b/tests/support/skip.rsnew file mode 100644index 00000000..e88e5090--- /dev/null+++ b/tests/support/skip.rs@@ -0,0 +1,52 @@+//! Missing test preconditions: a test skips on a dev machine and fails in CI.+//!+//! A skip and a pass have the same exit code, and `cargo test` hides the output of passing tests,+//! so a test that returns early in CI looks green having run nothing. Every early return for a+//! missing tool, image or service goes through [`skip_or_fail`]; `scripts/check_test_skips.py`+//! fails CI on a `skipped` line printed anywhere else.+//!+//! Integration tests include this file with `#[path = "support/skip.rs"] mod skip;`; the lib includes+//! it once as `crate::test_skip` (src/lib.rs) and unit tests `use crate::test_skip as skip;`.+#![allow(dead_code)]++/// True in CI (`CI=true`, which GitHub Actions sets) or with `KWNT_TEST_REQUIRE=1`.+/// `KWNT_AGENT_TEST_REQUIRE=1` is the older name and still works.+pub fn strict() -> bool {+ ["CI", "KWNT_TEST_REQUIRE", "KWNT_AGENT_TEST_REQUIRE"].iter().any(|k| on(k))+}++fn on(key: &str) -> bool {+ std::env::var(key).is_ok_and(|v| !matches!(v.trim().to_ascii_lowercase().as_str(), "" | "0" | "false" | "no"))+}++/// Call right before a test returns early because `what` is missing. `fix` says how to provide it+/// (a command to run or a variable to set). In a strict run this panics with both; otherwise it+/// prints `skipped: …` and the test returns.+#[track_caller]+pub fn skip_or_fail(what: &str, fix: &str) {+ if strict() {+ panic!(+ "{what} is missing, and this run is strict (CI=true or KWNT_TEST_REQUIRE=1), so the test fails instead of \+ skipping. To provide it: {fix}. To skip on your own computer, unset CI and KWNT_TEST_REQUIRE."+ );+ }+ eprintln!("skipped: {what} is missing. To run it: {fix}");+}++/// A live test that runs only when `var` is set (a real API key, a server address). Returns its+/// value, or prints `skipped: …` and returns `None`. Never fails, in CI either: these tests are+/// opt-in and listed in `tests/NOT_IN_CI.md`.+pub fn opt_in(var: &str, what: &str) -> Option<String> {+ let v = std::env::var(var).ok().filter(|v| !v.is_empty());+ if v.is_none() {+ eprintln!("skipped: {what} runs only with {var} set (opt-in, see tests/NOT_IN_CI.md)");+ }+ v+}++/// What to install for the browser tests; the fix text every Chrome skip uses.+pub const CHROME_FIX: &str =+ "install Google Chrome or Chromium on PATH, or set KWNT_CHROME_PATH to its binary";++/// Fix text for the tests that need Docker and the agent image.+pub const AGENT_IMAGE_FIX: &str = "start Docker and run `scripts/ci_docker_tests.sh images`";diff --git a/tests/team_discover_test.rs b/tests/team_discover_test.rsindex 4fa2faa9..74ecdf93 100644--- a/tests/team_discover_test.rs+++ b/tests/team_discover_test.rs@@ -3,6 +3,9 @@//! poisoned project gives the same team as its plain twin, and an existing team only gains the//! roles it lacks. All folders are temporary and all names are invented; nothing leaves the host.+#[path = "support/skip.rs"]+mod skip;+use axum::{body::{to_bytes, Body},http::{Request, StatusCode},@@ -433,7 +436,7 @@ async fn an_existing_team_only_gains_the_roles_it_lacks() {async fn a_git_folder_is_read_from_its_tracked_files() {let git_ok = std::process::Command::new("git").arg("--version").output().is_ok_and(|o| o.status.success());if !git_ok {- eprintln!("git isn't installed; skipped");+ skip::skip_or_fail("git", "install git");return;}let e = setup().await;@@ -479,7 +482,7 @@ async fn a_folder_kwant_cant_list_is_a_bad_path() {// root (or CAP_DAC_READ_SEARCH) still lists it: nothing to test thereif std::fs::read_dir(&shut).is_ok() {std::fs::set_permissions(&shut, std::fs::Permissions::from_mode(0o755)).unwrap();- eprintln!("skipped: this user can list a mode 000 folder (root)");+ skip::skip_or_fail("a user that file modes apply to (this one lists a mode 000 folder: root?)", "run the tests as a normal user");return;}let (s, v) = suggest(&e, json!({ "workspace_path": shut.to_str().unwrap() })).await;@@ -499,7 +502,7 @@ async fn a_folder_kwant_cant_list_is_a_bad_path() {async fn a_host_that_never_answers_is_read_failed_within_the_budget() {let git_ok = std::process::Command::new("git").arg("--version").output().is_ok_and(|o| o.status.success());if !git_ok {- eprintln!("git isn't installed; skipped");+ skip::skip_or_fail("git", "install git");return;}// Loopback is refused in every build, so the silent host listens on this machine's LAN address@@ -510,7 +513,7 @@ async fn a_host_that_never_answers_is_read_failed_within_the_budget() {let ip = match lan {Ok(ip) if !ip.is_loopback() && !ip.is_unspecified() => ip,_ => {- eprintln!("no LAN address; skipped");+ skip::skip_or_fail("a LAN address", "connect a network with a non-loopback IPv4 address");return;}};diff --git a/tests/video_attachments_test.rs b/tests/video_attachments_test.rsindex 0340b469..f3eac0f5 100644--- a/tests/video_attachments_test.rs+++ b/tests/video_attachments_test.rs@@ -3,6 +3,9 @@//! they can't be accepted, play inline, are shared by agents, and read as a few frames.//! Fixtures are 2–3 s ffmpeg `testsrc` clips (synthetic, no real footage).+#[path = "support/skip.rs"]+mod skip;+mod common;use axum::{@@ -208,7 +211,7 @@ async fn agents_share_videos_and_see_them_as_frames() {let r = self_call(&env, "tok-ws", "read_attachment", json!({"id": id})).await;if kwnt::server::video::tools().is_none() {- eprintln!("no ffmpeg here: checking the no-ffmpeg answer only");+ skip::skip_or_fail("ffmpeg and ffprobe (for the frames part)", "install ffmpeg, e.g. `apt install ffmpeg`");assert_eq!(r["isError"], false);assert!(text_of(&r).ends_with(kwnt::server::video::NO_FFMPEG), "{r}");return;@@ -236,7 +239,7 @@ async fn agents_share_videos_and_see_them_as_frames() {#[tokio::test]async fn a_damaged_video_reads_as_a_clear_error() {if kwnt::server::video::tools().is_none() {- eprintln!("no ffmpeg here: skipped");+ skip::skip_or_fail("ffmpeg and ffprobe", "install ffmpeg, e.g. `apt install ffmpeg`");return;}let env = setup().await;diff --git a/tests/zombie_imap_e2e.rs b/tests/zombie_imap_e2e.rsindex 5fc80f28..ffe200be 100644--- a/tests/zombie_imap_e2e.rs+++ b/tests/zombie_imap_e2e.rs@@ -12,6 +12,9 @@//!//! Without it the test passes without doing anything (and says so).+#[path = "support/skip.rs"]+mod skip;+use chrono::{Duration, Utc};use futures::StreamExt;use kwnt::zombie::{@@ -51,8 +54,7 @@ async fn flags(s: &mut Session, folder: &str) -> BTreeMap<u32, Vec<String>> {#[tokio::test]async fn the_imap_source_reads_without_changing_anything() {- let Ok(addr) = std::env::var("KWNT_TEST_IMAP") else {- eprintln!("KWNT_TEST_IMAP is not set: skipping the IMAP end-to-end test");+ let Some(addr) = skip::opt_in("KWNT_TEST_IMAP", "the IMAP end-to-end test") else {return;};let (host, port) = addr.rsplit_once(':').unwrap();