No test fails when an online `rollback --dry-run` or `remove --dry-run` leaves the before-blob it downloaded in `.socket/blobs`: the one test that claims it runs `--offline`
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 76/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- rust
- Domínio
- cli, testing-qa
Direção de pesquisa
Leia crates/socket-patch-cli/tests/remove/remove_network.rs e seus helpers de blobs simulados; em seguida, adicione o teste de regressão online para remove --dry-run descrito na issue. Adicione o caso correspondente de rollback --dry-run na suíte de rollback e esclareça que remove_dry_run_with_rollback_does_not_create_blobs_dir cobre apenas o caso offline. O trabalho estará concluído quando os dois testes online confirmarem que a prévia busca o blob ausente, mas deixa .socket/ inalterado.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
[agent] Found by the architecture refactor routine. Test code only: main at 1b3f422 behaves as the contract says. What is missing is a test that fails when it stops.
Problem
--dry-run is "Preview, no mutations" (CLI_CONTRACT.md, line 115). An agent-mode rollback --dry-run or remove --dry-run that finds a before-blob missing still downloads it, because the preview verifies against real blob content. To keep that download out of the committable .socket/blobs, the rollback reads and downloads blobs through a throwaway directory for the length of the dry run (_dry_run_blob_stage, CLI commands/rollback.rs, lines 3670 to 3708).
One test claims that rule, and it runs --offline, where nothing is ever downloaded. With the stage removed, an online preview leaves the downloaded blob in .socket/blobs and every test passes.
Evidence
The test is remove_dry_run_with_rollback_does_not_create_blobs_dir (CLI tests/remove/remove_invariants.rs, line 1112). Its comment says the preview "must not create .socket/blobs either (nor, online, download before-blobs into it)" and that it "walks its full path, including the throwaway dry-run blob stage the litter check below covers". It passes --offline, so the run stops at the offline gate with rollback_failed before any download. The stage is created and dropped empty, and the assertions hold with or without it.
The unit test dry_run_tolerates_created_by_patch_sentinel_rows (CLI commands/rollback.rs, line 6545) asserts that the stage is cleaned up. Its blobs are all on disk, so it downloads nothing either.
The mutation, never committed:
--- a/crates/socket-patch-cli/src/commands/rollback.rs
+++ b/crates/socket-patch-cli/src/commands/rollback.rs
@@ -3676,7 +3676,7 @@ pub(crate) async fn rollback_patches_inner(
- let _dry_run_blob_stage: Option<tempfile::TempDir> = if common.dry_run {
+ let _dry_run_blob_stage: Option<tempfile::TempDir> = if false {
With it on, these all pass:
- core's
patch::andmanifest::unit tests (1,610); - the CLI's unit tests (1,083);
- 49 CLI suites:
rollback,remove,repair,apply,scan,get,vendor,cli, and every other suite I found that runs an agent-moderollbackorremove(the list is in the ledger entry of this run). Three of the 49 hold only opt-in tests and ran nothing (e2e_pypi,e2e_scan,e2e_npm). The only failures are the five that fail in this sandbox with no mutation either, because it runs as root (two inrepair, three inin_process_redirect).
What the mutation does to a user, with the binary from main and the mutated one, over an npm project whose one patch is applied and whose before-blob is not in .socket/blobs, against a stand-in patch API that serves the blob:
| Binary | rollback --dry-run --yes |
Files in .socket/blobs before |
After |
|---|---|---|---|
main |
exit 0, "Downloaded 1 blob", "1 package can be rolled back" | 2 | 2 |
| mutated | exit 0, the same lines | 2 | 3: the downloaded before-blob stays |
A test that makes the preview download is green on main and red on the mutation:
$ cargo test -p socket-patch-cli --test remove -- remove_dry_run_online
test remove_network::remove_dry_run_online_leaves_the_downloaded_blob_out_of_the_socket_dir ... ok
$ cargo test -p socket-patch-cli --test remove # with the mutation
test remove_network::remove_dry_run_online_leaves_the_downloaded_blob_out_of_the_socket_dir ... FAILED
assertion `left == right` failed: a dry run leaves .socket/ as it found it
left: ["blobs", "blobs/d5e4cf563fb67895f4ab12ebf6963c84390ac573d85babf8348acd9d06ffe10a", "manifest.json"]
right: ["manifest.json"]
test result: FAILED. 90 passed; 1 failed
The 90 that pass include remove_dry_run_with_rollback_does_not_create_blobs_dir.
Planned fix
Add the online test below to tests/remove/remove_network.rs, which already has the mock that serves a before-blob, and its rollback --dry-run twin to the rollback suite. Then say in the comment of the offline test that it covers the offline half only. No production change.
Two more gates of these commands that no test reaches
Neither has a test that claims it, so neither passes this routine's bar for an issue of its own. Both came out of the same mutation run, and both are one test each.
rollbackrefuses to delete a patch-added file that holds other bytes.verify_file_rollback(corepatch/rollback.rs, lines 173 to 196) returnsHashMismatchfor a file the patch added (emptybeforeHash) whose content is not the patch's. With that branch changed toReady, the same unit tests and 49 suites pass. The mutated binary, over a project where the added file was replaced with the user's own text: "Rolled back 1 package", "Removed 1 patch from manifest", exit 0, and the user's file is gone.mainrefuses ("File holds neither the patched nor the original content"), exit 1, file kept. The tests beside it cover an added file that is absent, a dangling symlink, a stat error and a hash error, andtest_verify_file_rollback_hash_mismatchcovers a rewritten file. None covers an added file with other content.repairleaves the blobs of a vendored patch alone when the manifest also records it. The scoping inrepair_inner(CLIcommands/repair.rs, lines 709 to 724) drops a manifest record whose patch the vendor ledger or a lockfile reference already carries, because "a fully-vendored project legitimately has no.socket/blobs" and "repair must not re-litter them". With the filter off, the same tests pass, andrepairover the shapeto_standalone_vendor_modebuilds (CLItests/repair/repair_vendor_failure_paths.rs, line 470) exits 0 and writes a blob into a.socket/blobsthat did not exist.assert_socket_dir_lean(CLItests/repair/repair_vendor_e2e.rs, line 620) checks this for a project with no manifest, where the filter never runs.
Not run
Windows and macOS. The Bazel suite (no Bazel here), and the hosted and vendored build suites, which run no agent-mode preview. manifest_write_failure_warns_and_exits_one (CLI tests/rollback/rollback_failure_paths.rs, line 1669) is compiled on macOS only, so the mutant it would catch (a failed manifest write after a rollback, swallowed) survived here and is not counted above.
The test
/// The online half of `remove_dry_run_with_rollback_does_not_create_blobs_dir`
/// (`remove_invariants.rs`), which runs `--offline` and so never downloads:
/// a `remove --dry-run` that needs a missing before-blob fetches it for the
/// preview and leaves `.socket/` exactly as it found it.
#[tokio::test]
async fn remove_dry_run_online_leaves_the_downloaded_blob_out_of_the_socket_dir() {
fn listing(dir: &Path) -> Vec<String> {
let mut out = Vec::new();
let mut stack = vec[dir.to_path_buf()];
while let Some(d) = stack.pop() {
for entry in std::fs::read_dir(&d).expect("read_dir").flatten() {
let p = entry.path();
out.push(p.strip_prefix(dir).unwrap().display().to_string());
if p.is_dir() {
stack.push(p);
}
}
}
out.sort();
out
}
let before = b"before\n";
let after = b"after\n";
let before_hash = git_sha256(before);
let after_hash = git_sha256(after);
let mock = MockServer::start().await;
mount_before_blob(&mock, before, &before_hash).await;
let tmp = tempfile::tempdir().expect("tempdir");
let socket = tmp.path().join(".socket");
write_manifest(&socket, &before_hash, &after_hash);
install_patched_package(tmp.path(), after);
let was = listing(&socket);
let (code, stdout) = run_remove(tmp.path(), &mock.uri(), &["--dry-run"]);
assert_eq!(code, 0, "the preview succeeds; stdout=\n{stdout}");
// The preview did download the blob, so the stage was in use...
let blob_path = format!("/v0/orgs/{ORG_SLUG}/patches/blob/{before_hash}");
let reqs = mock.received_requests().await.expect("request recording");
assert!(
reqs.iter().any(|r| r.url.path() == blob_path),
"the preview fetches the missing before-blob; paths={:?}",
reqs.iter().map(|r| r.url.path().to_string()).collect::<Vec<_>>()
);
// ...and nothing of it is left in the committable directory.
assert_eq!(
listing(&socket),
was,
"a dry run leaves .socket/ as it found it; stdout=\n{stdout}"
);
assert!(manifest_has_entry(&socket), "the entry stays; stdout=\n{stdout}");
assert_eq!(
std::fs::read(tmp.path().join("node_modules/remove-network-test/index.js")).unwrap(),
after,
"the installed file is untouched"
);
}
Generated by Claude Code
- Linguagem predominante
- Rust
- Estrelas
- 9
- Forks
- 2
- Merge médio
- 1d 2h
- PRs com merge (30d)
- 213
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de SocketDev/socket-patch
-
agent:triaged arch-audit bug priority:p1
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
SocketDev/socket-patch#2517 ·
Mantenedores costumam responder em até 1 dia
-
agent:triaged bug bughunt pm:bundler priority:p1 ux
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
SocketDev/socket-patch#2508 ·
Mantenedores costumam responder em até 1 dia
-
agent:triaged bug bughunt pm:npm priority:p1
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
SocketDev/socket-patch#2476 ·
Mantenedores costumam responder em até 1 dia
-
agent:triaged arch-audit priority:p3 refactor
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
SocketDev/socket-patch#2429 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
agent:triaged ci-janitor priority:p3
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
SocketDev/socket-patch#2424 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de SocketDev/socket-patch
Issues semelhantes
-
chat compiler P1
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
HerringtonDarkholme/hd-lang#2793 ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 1 dia
-
security-advisory
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
MinBZK/regelrecht#2173 ·
-
ci
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
jonathanong/no-mistakes#5804 ·
-
triage: failed
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
oxc-project/tsrs#1277 · 1 comentário ·
Mantenedores costumam responder em até 1 dia