Skip to content

Three --offline gates pass every test switched off: a hosted Cargo unwind, a Gradle rollback with no backup and a gem unwind then send registry requests #2429

Backlog

Description

[agent] Found by the architecture refactor routine. The 56 mutants ran on main at 1bc104a; the three below ran again at 9f2bc04, against the suites that reach them. Test code only: main behaves as the contract says in every case run.

The problem

The contract's --offline is a strict airgap: "never contact the network". Nothing enforces it in one place. The CLI mirrors the flag into SOCKET_OFFLINE for telemetry and the org lookup, and every other request is refused where it is made: 58 places in the CLI and core test the flag or hand it down. A new request path that forgets its test, or a refactor that drops one, sends requests from an airgapped run, and only a test can say so.

For three of those places no test can. With the gate switched off, every test passes and an offline run sends a request:

Gate With it off, an --offline run Tests
the hosted unwind's crates.io lookup (core patch/redirect/upstream/client.rs, line 502, cargo_cksum) rollback, remove and a vendored takeover of a hosted Cargo pin ask the crates.io index for the checksum none reaches the line with offline on
a Gradle jar with no backup (core patch/jvm_jar.rs, line 1073) rollback --offline downloads the jar from Maven Central one unit test reaches it and passes
the gem unwind's checksum lookup (CLI commands/gem_refresh.rs, line 1624, the flag handed to gem_upstream) rollback, remove and vendor --revert ask the gem registry's compact index, on a lock without CHECKSUMS e2e_redirect_gem_stale_install reaches it five times and passes

Why they pass: no test runs a hosted Cargo unwind offline at all (the golden suite does for gem, Composer, PyPI and uv, and other suites for npm, Go and NuGet). The Gradle and gem tests that run offline point no registry at a server that counts, so "asked and was refused" reads the same as "did not ask". #2421 has the gem refresh's sibling gate (line 1758, on a lock with CHECKSUMS).

Evidence

One build carried 56 mutants (each reads its gate as online), behind a switch read from the environment that also logged every time its gate was reached with offline on. One traced run of the 238 test binaries that run without Docker or a live API said which suites reach which gate; each mutant then ran against those suites.

Result Mutants
caught 37: every command's own refusal, the telemetry and org-lookup switches, the update check, the hosted unwind for npm, PyPI, Go, gem, Composer and NuGet, the Maven vendoring lookups
survive or unreached, and a request is sent 3: the table above
survive or unreached, no test written yet 9: the stale-cache check after a vendored gem revert, the native rebuild of a gem refresh and of a rollback, vex fetching a patched package.json blob, vendor over hosted pins (three places), a Maven sidecar lookup, a gem build dependency
equivalent, message only or unreachable 7

Three new tests, each green on main and red on its mutant alone:

# main at 9f2bc04; SPMUT unset
test cargo_offline_restore_asks_no_index ... ok
test patch::jvm_jar::tests::gradle_offline_rollback_without_backup_asks_no_registry ... ok
test an_offline_vendored_unwind_sends_no_request ... ok

SPMUT=52  test cargo_offline_restore_asks_no_index ... FAILED
          tests/fixtures/redirect/cargo/cargo/basic: an offline restore sent ["/se/rd/serde"]
SPMUT=41  test patch::jvm_jar::tests::gradle_offline_rollback_without_backup_asks_no_registry ... FAILED
          an offline rollback sent ["/com/example/lib/1.0/lib-1.0.jar"]
SPMUT=27  test an_offline_vendored_unwind_sends_no_request ... FAILED
          ["rollback", "--yes"]: an offline unwind sent ["/upstream/info/stale-probe-gem"]

# the suites that reach each gate, at 9f2bc04, with the mutant on
SPMUT=52  upstream_restore_golden: 65 passed
SPMUT=41  core patch::jvm_jar unit tests: 16 passed; gradle_agent_cli: 39 passed
SPMUT=27  e2e_redirect_gem_stale_install: 76 passed
The three tests

For core tests/upstream_restore_golden.rs:

/// An offline restore of a hosted Cargo pin asks the crates.io index
/// nothing: each pin is restored from the lock's own twin entry or
/// refused as offline.
#[tokio::test]
#[serial]
async fn cargo_offline_restore_asks_no_index() {
    let mut refused = 0;
    for case in load("cargo/cargo") {
        if !case.input.contains_key("Cargo.lock") {
            continue;
        }
        let server = MockServer::start().await;
        let _env = EnvGuard::set("SOCKET_CRATES_INDEX", server.uri());
        let (after, statuses) = run_case_with(&case, None, &offline()).await;
        let sent: Vec<String> = server
            .received_requests()
            .await
            .unwrap()
            .iter()
            .map(|r| r.url.path().to_string())
            .collect();
        assert!(sent.is_empty(), "{}: an offline restore sent {sent:?}", case.dir.display());
        for (purl, status) in &statuses {
            if let PinStatus::Refused(why) = status {
                assert!(why.contains("offline"), "{}: {purl}: {why}", case.dir.display());
                refused += 1;
            }
        }
        if statuses.iter().all(|(_, s)| matches!(s, PinStatus::Refused(_))) {
            assert_eq!(after, case.expected, "{}: a refused pin must change nothing", case.dir.display());
        }
    }
    assert!(refused > 0, "no case was refused offline");
}

For the tests of core patch/jvm_jar.rs:

/// A Gradle copy that holds the patch and has no backup is left as it is
/// by an offline rollback, which asks the registry nothing.
#[tokio::test]
#[serial_test::serial]
async fn gradle_offline_rollback_without_backup_asks_no_registry() {
    let original = pristine_jar();
    let files = record();
    let server = wiremock::MockServer::start().await;
    let _registry = EnvGuard::set("SOCKET_MAVEN_REGISTRY", server.uri());
    let d = tempfile::tempdir().unwrap();
    let socket = d.path().join(".socket");
    let hash_dir = d
        .path()
        .join(".gradle/caches/modules-2/files-2.1/com.example/lib/1.0")
        .join(sha1_hex(&original));
    std::fs::create_dir_all(&hash_dir).unwrap();
    std::fs::write(hash_dir.join("lib-1.0.jar"), patched_jar()).unwrap();
    let back = rollback_jar_swap(&restore(&files, &socket, true), &[hash_dir.clone()]).await;
    let sent: Vec<String> = server
        .received_requests()
        .await
        .unwrap()
        .iter()
        .map(|r| r.url.path().to_string())
        .collect();
    assert!(sent.is_empty(), "an offline rollback sent {sent:?}");
    assert!(!back[0].success);
    let error = back[0].error.as_deref().unwrap();
    assert!(error.contains("--offline prevents downloading it again"), "{error}");
    assert!(std::fs::read(hash_dir.join("lib-1.0.jar")).unwrap() == patched_jar());
}

For CLI tests/e2e_redirect_gem_stale_install.rs:

/// An offline vendored unwind sends no request: not to the patch
/// service, and not to the gem registry for the checksum of a gem the
/// lock pins none for.
#[tokio::test(flavor = "multi_thread")]
async fn an_offline_vendored_unwind_sends_no_request() {
    for unwind in VENDORED_UNWINDS {
        let server = MockServer::start().await;
        let tmp = tempfile::tempdir().unwrap();
        let proj = tmp.path().join("proj");
        let (_gem_dir, archive) = agent_then_vendored(&server, &proj).await;
        std::fs::remove_dir_all(archive.parent().unwrap()).unwrap();
        let before = server.received_requests().await.unwrap().len();
        let mut args = unwind.to_vec();
        args.push("--json");
        args.push("--offline");
        let (code, stdout, stderr) = unwind_run(&proj, &server.uri(), &args);
        assert_eq!(code, 0, "{unwind:?}: {stdout}\nstderr:\n{stderr}");
        let after = server.received_requests().await.unwrap();
        let sent: Vec<String> = after[before..].iter().map(|r| r.url.path().to_string()).collect();
        assert!(sent.is_empty(), "{unwind:?}: an offline unwind sent {sent:?}");
    }
}

The mutant is one line at each gate, for example if self.offline && !crate::spmut(52) {, with spmut(n) reading SPMUT from the environment. The production diff was never committed.

Not run: Windows and macOS, the Docker suites, the tests that need a live API, and the two in-memory hosted suites, whose harness clears the environment the switch is read from. The nine gates of the third row were not probed: each needs a scenario where the mutant sends a request.

Planned fix

Add the three tests. No production change.

A wider fix would be structural: refuse an offline request in the two functions every registry request of the unwind goes through, and in the one client the vendored and JVM paths share, so that a new lookup cannot forget its test. That is a refactor with no defect behind it today, so it is not planned here.


Generated by Claude Code

Activity

  1. added
    arch-audit
    refactor
    on Dec 1, 2026
  2. added a commit that references this issue on Dec 1, 2026
  3. mikolalysenko commented on Dec 2, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] The nine gates this issue left unprobed, run on main at d718b07. Three more pass every test switched off and send a request; six are not findings. Test code only: main sends nothing in every case run.

    Three more gates no test fails without

    Gate With it off, an --offline run Tests
    vex reading a patched package.json (CLI commands/vex.rs, line 833, patched_blob) vex --offline over a hosted yarn classic pin whose patch changes package.json downloads the blob from the patch API, then attests the pin none reaches the line with offline on
    the stale-cache check after a vendored gem is unwound (CLI commands/vendored_backend/mod.rs, line 227, the flag handed to push_gem_stale_cache) rollback, remove and vendor --revert ask the gem registry's compact index, when Bundler's cache dir holds an archive of the gem and the lock has no CHECKSUMS 21 suites reach the line and pass
    the rebuild of a gem's native extension on rollback (CLI commands/rollback.rs, line 4064, the RubyEnv of restore_original_build; core patch/gem_ext.rs, line 6619, where it is read) rollback --offline asks the gem registry for the source gem, when the backup of the original build is gone and the gem home holds no archive five suites reach line 4064 and pass; two real-toolchain tests reach line 6619 and pass

    Why they pass. No test runs vex --offline over a pin whose patch changes package.json. No vendored unwind test that runs offline both keeps an archive of the gem in vendor/cache and counts what the registry is asked; for every other ecosystem the flag is not read. The two rollback tests that lose the backup keep the gem's archive in the gem home, and the suite's registry is http://127.0.0.1:9, where nothing listens: "asked and was refused" reads the same as "did not ask".

    Three new tests, each green on main and red on its mutant alone:

    # main at d718b07: the binary built from it, and the build that carries the switches with none on
    test yarn::offline_vex_fetches_no_patched_manifest_blob ... ok
    test an_offline_vendored_unwind_asks_nothing_about_bundlers_cache ... ok
    test an_offline_rollback_without_backup_or_archive_asks_no_registry ... ok
    
    vex.rs:833            test yarn::offline_vex_fetches_no_patched_manifest_blob ... FAILED
                          an offline vex sent 1 request(s)   ("status": "success", the pin "verified")
    vendored_backend:227  test an_offline_vendored_unwind_asks_nothing_about_bundlers_cache ... FAILED
                          ["rollback", "--yes"]: an offline unwind sent ["/upstream/info/stale-probe-gem"]
    rollback.rs:4064      test an_offline_rollback_without_backup_or_archive_asks_no_registry ... FAILED
    gem_ext.rs:6619       test an_offline_rollback_without_backup_or_archive_asks_no_registry ... FAILED
                          an offline rollback sent ["/info/sp_wrap"]
    
    # the suites that reach each gate with offline on, with its mutant on (the new test aside)
    vex.rs:833            e2e_vex_lockfile: 359 passed
    vendored_backend:227  21 suites, 817 tests passed: e2e_redirect_gem_stale_install, e2e_bun_lockb,
                          e2e_composer_version_identity, e2e_golang_workspace_build, e2e_vendor_bun_build,
                          e2e_vendor_cargo_build, e2e_vendor_composer_crlf, e2e_vendor_golang_build,
                          e2e_vendor_npm_build, e2e_vendor_pnpm_build, e2e_vendor_yarn_classic_build,
                          e2e_vendor_yarn_classic_dev_flow, in_process_remove_repair_lifecycle,
                          in_process_rollback_vendored, in_process_vendor,
                          in_process_vendor_pnpm_parent_child, manifest_path_ledger_root,
                          mode_migration_pypi, remove, rollback, vendor_group_commit_e2e
    rollback.rs:4064      apply: 225 passed; e2e_gem_native_ext_build: 43 passed, and its 11 real-toolchain
                          tests with --ignored; ecosystem_dispatch_e2e: 25; in_process_gem_multi_platform: 9;
                          in_process_rollback_all_ecosystems: 8
    gem_ext.rs:6619       e2e_gem_native_ext_build --ignored: 11 passed
    

    The third test compiles a C extension with the real ruby, gem and gcc, so it is #[ignore]d like its neighbours and runs on the pinned-Ruby leg.

    Six that are not findings

    Gate Verdict
    vendor over hosted pins, three places (CLI commands/vendor.rs, lines 1906, 4416 and 6253) not reachable with offline on. Lines 1906 and 6253 are reached only through scan and get, which exit 1 with offline_unsupported before either (ran: scan --offline --prune, scan --offline --mode vendored --dry-run, get <name> --offline --mode vendored). Line 4416 is the takeover inside the vendoring loop: vendor refuses any hosted pin in scope first (offline_eject_unavailable, line 1240, which mode_migration_cargo, vendor_eject_bun_lockb, in_process_vendor and e2e_bun_lockb assert), and scan and get as above. No test reaches any of the three with offline on
    the native rebuild of a gem refresh (CLI commands/gem_refresh.rs, line 133) the flag is read by nothing. The refresh installs the archive it holds (install_staged, core patch/gem_ext.rs, line 2559, with ignore_dependencies) and builds no gem source. env.offline has two readers in core, lines 6015 and 6619, and neither is on the refresh's path. e2e_redirect_gem_stale_install passes with it off (83 tests), as it must
    a gem build dependency (core patch/gem_ext.rs, line 4532) equivalent. With it off the download is refused one call later (withheld, core patch/gem_source.rs, lines 357 and 202); only the sentence changes. The real-toolchain tests reach it once and pass with it off
    a Maven lookup beside the jar (core vendor/maven_repo.rs) caught or not reachable at d718b07. The checksum lookup (line 2277), the pom and module lookup (line 2365) and the online switch (line 1742) each fail a unit test when switched off (jvm_upstream_checksums_are_independent_of_cache_sidecars, a_parent_naming_the_poms_version_is_vendored_at_the_base_version, jvm_rerun_is_in_sync_without_any_jar_source). The classifier jar's lookup (line 2163) runs only for a tree that is not committed yet, where the patch service's own offline refusal comes first (vendor_service_offline_conflict), or online (line 1810)

    Also caught here, for the record: the flag apply hands to its native rebuild (CLI commands/apply.rs, line 4220, and core patch/gem_ext.rs, line 6015) fails a_precompiled_copy_without_its_source_gem_is_refused.

    How it ran

    One build of main at d718b07 carried 15 switches (each reads its gate as online), read from a file, with a log of every time a gate was reached with offline on. One traced run of 241 test binaries (the 256 that cargo test --workspace --no-run builds, less the 15 Docker suites) gave the suites that reach each gate; each mutant then ran against those suites. Unmutated, everything passes but the five tests that fail as root here (in_process_redirect 3, repair 2). The production diff was never committed.

    Not run: Windows and macOS, the Docker suites, the tests that need a live API, and the second caller of patched_blob (the Go vendor-tree check of vex, line 1427), which no test reaches offline either.

    Planned fix, now six tests

    The three tests in the issue and the three below. No production change.

    The three tests

    For CLI tests/e2e_vex_lockfile/yarn.rs:

    /// `vex --offline` asks the patch API for nothing, the patched
    /// `package.json` of a hosted yarn classic pin included: with the record
    /// in the ledger and the blob in no local store the pin is
    /// `dependency_manifest_unverifiable`, though the API would serve the blob.
    #[test]
    fn offline_vex_fetches_no_patched_manifest_blob() {
        use wiremock::matchers::{method, path};
        use wiremock::{Mock, ResponseTemplate};
        const MANIFEST: &str = "package/package.json";
        let pristine = format!(
            r#"{{"name":"{NAME}","version":"{VERSION}","dependencies":{{"is-odd":"^2.0.0"}}}}"#
        );
        let patched = format!(
            r#"{{"name":"{NAME}","version":"{VERSION}","dependencies":{{"is-odd":"^3.0.0"}}}}"#
        );
        let after_hash = compute_git_sha256_from_bytes(patched.as_bytes());
        let before_hash = compute_git_sha256_from_bytes(pristine.as_bytes());
        let mut view = patch_view(UUID, PURL);
        view["files"][MANIFEST] = serde_json::json!({
            "beforeHash": before_hash,
            "afterHash": after_hash,
        });
        let (rt, server) = serve_patch_views(vec[(UUID, view)]);
        rt.block_on(
            Mock::given(method("GET"))
                .and(path(format!("/patch/blob/{after_hash}")))
                .respond_with(ResponseTemplate::new(200).set_body_bytes(patched.clone().into_bytes()))
                .mount(&server),
        );
    
        let tmp = tempfile::tempdir().unwrap();
        let cwd = tmp.path();
        hosted_checkout(cwd, Flavor::Classic);
        let lock = format!(
            "{}  dependencies:\n    is-odd \"^3.0.0\"\n\nis-odd@^3.0.0:\n  version \"3.0.1\"\n  \
             resolved \"https://registry.yarnpkg.com/is-odd/-/is-odd-3.0.1.tgz#\
             0123456789abcdef0123456789abcdef01234567\"\n  integrity \
             sha512-aXNvZGRpc29kZGlzb2RkaXNvZGQ=\n",
            hosted_lock(Flavor::Classic, "https://patch.socket.dev", UUID)
        );
        put(cwd, "yarn.lock", lock.as_bytes());
        let mut rec = record(UUID);
        rec.files.insert(
            MANIFEST.to_string(),
            PatchFileInfo {
                before_hash,
                after_hash: after_hash.clone(),
            },
        );
        write_redirect_ledger(cwd, Flavor::Classic, rec);
    
        // Online, the same checkout attests: the blob is what stands between.
        let (code, env) = vex_json(cwd, &["--proxy-url", &server.uri()]);
        assert_attested(cwd, code, &env, UUID, "redirected", "online");
        let online = request_count(&rt, &server);
        assert!(online > 0, "the online run fetched the blob");
    
        let (code, env) = vex_json(cwd, &["--offline", "--proxy-url", &server.uri()]);
        let sent = request_count(&rt, &server) - online;
        assert_eq!(sent, 0, "an offline vex sent {sent} request(s): {env:#}");
        assert_omitted(
            cwd,
            code,
            &env,
            "dependency_manifest_unverifiable",
            "offline",
        );
        drop(rt);
    }

    For CLI tests/e2e_redirect_gem_stale_install.rs (the fixture of this issue's third test, with a patched archive in vendor/cache):

    /// An offline vendored unwind sends no request, with a patched archive of
    /// the gem in Bundler's cache dir too: on a lock without `CHECKSUMS` the
    /// stale-cache check has no upstream sha256 and asks the registry for
    /// none.
    #[tokio::test(flavor = "multi_thread")]
    async fn an_offline_vendored_unwind_asks_nothing_about_bundlers_cache() {
        for unwind in VENDORED_UNWINDS {
            let server = MockServer::start().await;
            let tmp = tempfile::tempdir().unwrap();
            let proj = tmp.path().join("proj");
            let (_gem_dir, archive) = agent_then_vendored(&server, &proj).await;
            std::fs::remove_dir_all(archive.parent().unwrap()).unwrap();
            let cached = proj
                .join("vendor/cache")
                .join(format!("{DEP}-{DEP_VERSION}.gem"));
            std::fs::create_dir_all(cached.parent().unwrap()).unwrap();
            std::fs::write(&cached, real_gem(PATCHED_LIB)).unwrap();
            let before = server.received_requests().await.unwrap().len();
            let mut args = unwind.to_vec();
            args.push("--json");
            args.push("--offline");
            let (code, stdout, stderr) = unwind_run(&proj, &server.uri(), &args);
            assert_eq!(code, 0, "{unwind:?}: {stdout}\nstderr:\n{stderr}");
            let after = server.received_requests().await.unwrap();
            let sent: Vec<String> = after[before..]
                .iter()
                .map(|r| r.url.path().to_string())
                .collect();
            assert!(
                sent.is_empty(),
                "{unwind:?}: an offline unwind sent {sent:?}"
            );
            assert!(
                stdout.contains("upstream_gem_stale_cache"),
                "{unwind:?}: the archive is still named:\n{stdout}"
            );
        }
    }

    For CLI tests/e2e_gem_native_ext_build.rs:

    /// An offline rollback that has lost the backup of the original build, in
    /// a gem home that holds no archive of the gem, asks the registry for
    /// none: it rebuilds from the restored source in place.
    #[tokio::test(flavor = "multi_thread")]
    #[ignore = "host capstone: compiles a C extension with the real ruby/gem toolchain; \
                the unpinned `test` job skips it, the pinned-Ruby e2e leg runs it via --ignored"]
    async fn an_offline_rollback_without_backup_or_archive_asks_no_registry() {
        let Some(abi) = toolchain() else {
            return;
        };
        let fx = WrapGem::new(&abi, WRAP_EXTCONF);
        let (code, stdout, stderr) = fx.run(&["apply", "--json", "--offline"]);
        assert_eq!(code, 0, "apply failed:\n{stdout}\n{stderr}");
        assert_eq!(fx.value(), "2");
        std::fs::remove_dir_all(fx.gem_dir.join(".socket-patch-native-orig")).unwrap();
        std::fs::remove_file(fx.home.join("cache/sp_wrap-1.0.0.gem")).unwrap();
    
        let registry = wiremock::MockServer::start().await;
        let (code, stdout, stderr) = common::run_with_env(
            &fx.proj,
            &["rollback", "--json", "--offline"],
            &[("SOCKET_RUBYGEMS_URL", registry.uri().as_str())],
        );
        let sent: Vec<String> = registry
            .received_requests()
            .await
            .unwrap()
            .iter()
            .map(|r| r.url.path().to_string())
            .collect();
        assert!(sent.is_empty(), "an offline rollback sent {sent:?}");
        assert_eq!(code, 0, "rollback failed:\n{stdout}\n{stderr}");
        assert_eq!(
            fx.value(),
            "1",
            "the library is rebuilt from the restored source:\n{stdout}"
        );
        assert_eq!(fx.c_file(), wrap_c(1));
    }

    Generated by Claude Code

  4. added a commit that references this issue on Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:triagedarch-auditpriority:p3refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions