fix: sessões abrem mesmo sem a origem; mensagens claras de erro (0.3.1)

Antes, abrir uma sessão cuja origem não estava acessível (ou cujo arquivo não podia
ser lido, como em /root) falhava por inteiro com erro vago. Agora a sessão abre,
permite navegar/exportar e a origem pode ser reconectada. Testes cobrem sessões
gravadas pela v0.1.0.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Sonnet 5.5 committed 2026-10-18 16:37:25 -03:00
1 parent 45d535bdb7
commit 682ba8b943
10 files changed
+213 -23

No files matched your search

@@ -0,0 +1 @@
{"version": 1, "target": "@@ALVO@@", "options": {"mode": "deep", "include_allocated": false, "categories": [], "max_carve_size": 8589934592}, "found": [{"id": 1, "name": "tese.docx", "dir": null, "ext": "docx", "category": "document", "size": 411277, "origin": "ntfs", "confidence": "high", "data": {"kind": "extents", "extents": [{"offset": 52428800, "len": 411277}]}, "modified": 1792346095, "note": null}, {"id": 2, "name": "notas.txt", "dir": null, "ext": "txt", "category": "document", "size": 945617, "origin": "ntfs", "confidence": "medium", "data": {"kind": "extents", "extents": [{"offset": 52842496, "len": 945617}]}, "modified": 1792346095, "note": null}, {"id": 3, "name": "relatorio.pdf", "dir": null, "ext": "pdf", "category": "document", "size": 646931, "origin": "ntfs", "confidence": "high", "data": {"kind": "extents", "extents": [{"offset": 53788672, "len": 646931}]}, "modified": 1792346095, "note": null}, {"id": 4, "name": "dados.bin", "dir": null, "ext": "bin", "category": "other", "size": 3000000, "origin": "ntfs", "confidence": "medium", "data": {"kind": "extents", "extents": [{"offset": 54435840, "len": 3000000}]}, "modified": 1792346095, "note": null}, {"id": 5, "name": "contatos.db", "dir": null, "ext": "db", "category": "database", "size": 573440, "origin": "ntfs", "confidence": "high", "data": {"kind": "extents", "extents": [{"offset": 57438208, "len": 573440}]}, "modified": 1792346095, "note": null}, {"id": 6, "name": "praia.jpg", "dir": null, "ext": "jpg", "category": "image", "size": 511391, "origin": "ntfs", "confidence": "high", "data": {"kind": "extents", "extents": [{"offset": 58011648, "len": 511391}]}, "modified": 1792346096, "note": null}, {"id": 7, "name": "montanha.png", "dir": null, "ext": "png", "category": "image", "size": 3337460, "origin": "ntfs", "confidence": "high", "data": {"kind": "extents", "extents": [{"offset": 58638336, "len": 3337460}]}, "modified": 1792346096, "note": null}], "checkpoint": null, "layout": {"size": 100663296, "table": "none", "partitions": [{"index": 0, "start": 0, "len": 100663296, "fs": "ntfs", "label": null, "lost": false, "encrypted": null, "table_type": "volume sem tabela de partições"}], "gaps": [], "warnings": []}, "warnings": [], "done": true}
+99
View File
@@ -302,3 +302,102 @@ fn configuracoes_de_tema_persistem() {
.unwrap();
assert_eq!(settings::load().theme, "dark");
}
fn wait_done(eng: &service::Engine, job: &str) {
for _ in 0..500 {
if eng.status(job).unwrap()["status"] != "running" {
return;
}
std::thread::sleep(std::time::Duration::from_millis(10));
}
panic!("job não terminou");
}
/// Uma sessão gravada pela v0.1.0 continua abrindo nas versões novas.
#[test]
fn sessao_da_v0_1_0_abre_e_funciona() {
let Some(dir) = fixtures() else { return };
let img = dir.join("ntfs.img");
let raw = include_str!("data/sessao-v0.1.0.json").replace("@@ALVO@@", img.to_str().unwrap());
let tmp = tempfile::NamedTempFile::new().unwrap();
std::fs::write(tmp.path(), raw).unwrap();
let eng = service::Engine::new();
let job = eng.load_session(tmp.path().to_str().unwrap()).unwrap();
wait_done(&eng, &job);
let st = eng.status(&job).unwrap();
assert_eq!(st["status"], "done");
assert_eq!(st["found"], 7);
assert_eq!(st["source"], true);
let res = eng.results(&job, &service::Query::default()).unwrap();
assert_eq!(res["total"], 7);
// recuperar a partir da sessão antiga continua dando o mesmo conteúdo
let out = tempfile::tempdir().unwrap();
let rj = eng
.start_recover(
&job,
None,
Some(service::Query::default()),
out.path().to_str().unwrap(),
)
.unwrap();
wait_done(&eng, &rj);
let got = hashes_in(out.path());
for (h, p) in expected(&dir, "ntfs") {
assert!(got.contains_key(&h), "faltou {p}");
}
}
/// Origem indisponível não impede abrir a sessão; reapontar a origem religa tudo.
#[test]
fn sessao_abre_sem_a_origem_e_pode_ser_reconectada() {
let Some(dir) = fixtures() else { return };
let img = dir.join("ntfs.img");
let raw =
include_str!("data/sessao-v0.1.0.json").replace("@@ALVO@@", "/dev/disco-que-nao-existe");
let tmp = tempfile::NamedTempFile::new().unwrap();
std::fs::write(tmp.path(), raw).unwrap();
let eng = service::Engine::new();
let job = eng.load_session(tmp.path().to_str().unwrap()).unwrap();
let st = eng.status(&job).unwrap();
assert_eq!(st["source"], false);
assert_eq!(st["found"], 7);
assert!(st["warnings"][0]
.as_str()
.unwrap()
.contains("não está disponível"));
// navegar e exportar funcionam
assert_eq!(
eng.results(&job, &service::Query::default()).unwrap()["total"],
7
);
let csv = tempfile::NamedTempFile::new().unwrap();
assert_eq!(
eng.export_csv(&job, csv.path().to_str().unwrap(), None)
.unwrap(),
7
);
// pré-visualização e recuperação avisam com clareza
assert_eq!(eng.thumb(&job, 1, 128).err(), Some(503));
let out = tempfile::tempdir().unwrap();
let e = eng
.start_recover(&job, None, None, out.path().to_str().unwrap())
.unwrap_err();
assert!(e.to_string().contains("não está disponível"), "{e}");
// reconecta
eng.relink(&job, img.to_str().unwrap()).unwrap();
let st = eng.status(&job).unwrap();
assert_eq!(st["source"], true);
assert!(st["warnings"].as_array().unwrap().is_empty());
let rj = eng
.start_recover(&job, None, None, out.path().to_str().unwrap())
.unwrap();
wait_done(&eng, &rj);
assert_eq!(hashes_in(out.path()).len(), 7);
// arquivo que não é sessão
std::fs::write(tmp.path(), b"nao e json").unwrap();
let e = eng.load_session(tmp.path().to_str().unwrap()).unwrap_err();
assert!(
e.to_string().contains("não é uma sessão do Guará válida"),
"{e}"
);
}