Skip to content

Commit e0ad3ae

Browse files
committed
Fmt
1 parent f39731c commit e0ad3ae

4 files changed

Lines changed: 114 additions & 6 deletions

File tree

src/commands/dart_symbol_map/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use anyhow::Result;
2-
use clap::{Args, ArgMatches, Command, Parser as _, Subcommand};
31
use crate::utils::args::ArgExt as _;
2+
use anyhow::Result;
3+
use clap::{ArgMatches, Args, Command, Parser as _, Subcommand};
44

55
pub mod upload;
66

src/commands/dart_symbol_map/upload.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::fmt::{Display, Formatter, Result as FmtResult};
44
use std::path::Path;
55

66
use anyhow::{bail, Context as _, Result};
7-
use clap::{Args, ArgMatches};
7+
use clap::{ArgMatches, Args};
88

99
use crate::api::{Api, ChunkUploadCapability};
1010
use crate::config::Config;
@@ -45,11 +45,15 @@ impl<'a> Assemblable for DartSymbolMapObject<'a> {
4545
#[derive(Args, Clone)]
4646
pub(crate) struct DartSymbolMapUploadArgs {
4747
#[arg(value_name = "MAPPING")]
48-
#[arg(help = "Path to the dartsymbolmap JSON file (e.g. dartsymbolmap.json). Must be a JSON array of strings with an even number of entries (pairs).")]
48+
#[arg(
49+
help = "Path to the dartsymbolmap JSON file (e.g. dartsymbolmap.json). Must be a JSON array of strings with an even number of entries (pairs)."
50+
)]
4951
pub(super) mapping: String,
5052

5153
#[arg(value_name = "DEBUG_FILE")]
52-
#[arg(help = "Path to the corresponding debug file to extract the Debug ID from. The file must contain exactly one Debug ID.")]
54+
#[arg(
55+
help = "Path to the corresponding debug file to extract the Debug ID from. The file must contain exactly one Debug ID."
56+
)]
5357
pub(super) debug_file: String,
5458
}
5559

src/commands/derive_parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use crate::utils::auth_token::AuthToken;
22
use crate::utils::value_parsers::{auth_token_parser, kv_parser};
33
use clap::{command, ArgAction::SetTrue, Parser, Subcommand};
44

5+
use super::dart_symbol_map::DartSymbolMapArgs;
56
use super::logs::LogsArgs;
67
use super::send_metric::SendMetricArgs;
7-
use super::dart_symbol_map::DartSymbolMapArgs;
88

99
#[derive(Parser)]
1010
pub(super) struct SentryCLI {
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
use std::sync::atomic::{AtomicU8, Ordering};
2+
3+
use crate::integration::test_utils::AssertCommand;
4+
use crate::integration::{MockEndpointBuilder, TestManager};
5+
6+
#[test]
7+
fn command_upload_dart_symbol_map_missing_capability() {
8+
// Server does not advertise `dartsymbolmap` capability → command should bail early.
9+
TestManager::new()
10+
.mock_endpoint(
11+
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/")
12+
.with_response_file("debug_files/get-chunk-upload.json"),
13+
)
14+
.assert_cmd([
15+
"dart-symbol-map",
16+
"upload",
17+
"tests/integration/_fixtures/dart_symbol_map/dartsymbolmap.json",
18+
// Use a fixture with a single Debug ID
19+
"tests/integration/_fixtures/Sentry.Samples.Console.Basic.pdb",
20+
])
21+
.with_default_token()
22+
.run_and_assert(AssertCommand::Failure);
23+
}
24+
25+
#[test]
26+
fn command_upload_dart_symbol_map_chunk_upload_flow() {
27+
// Happy path: server supports dartsymbolmap capability, file needs upload, then assembles to ok.
28+
let call_count = AtomicU8::new(0);
29+
30+
TestManager::new()
31+
// Server advertises capability including `dartsymbolmap`.
32+
.mock_endpoint(
33+
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/")
34+
.with_response_file("dart_symbol_map/get-chunk-upload.json"),
35+
)
36+
// Accept chunk upload requests for the missing chunks; no validation needed here.
37+
.mock_endpoint(MockEndpointBuilder::new(
38+
"POST",
39+
"/api/0/organizations/wat-org/chunk-upload/",
40+
))
41+
// Assemble flow: 1) not_found (missingChunks), 2) created, 3) ok
42+
.mock_endpoint(
43+
MockEndpointBuilder::new(
44+
"POST",
45+
"/api/0/projects/wat-org/wat-project/files/difs/assemble/",
46+
)
47+
.with_header_matcher("content-type", "application/json")
48+
.with_response_fn(move |request| {
49+
let body = request.body().expect("body should be readable");
50+
let body_json: serde_json::Value = serde_json::from_slice(body)
51+
.expect("request body should be valid JSON");
52+
53+
// The request map has a single entry keyed by checksum; reuse it in responses.
54+
let (checksum, _obj) = body_json
55+
.as_object()
56+
.and_then(|m| m.iter().next())
57+
.map(|(k, v)| (k.clone(), v.clone()))
58+
.expect("assemble request must contain at least one object");
59+
60+
match call_count.fetch_add(1, Ordering::Relaxed) {
61+
0 => format!(
62+
"{{\"{checksum}\":{{\"state\":\"not_found\",\"missingChunks\":[\"{checksum}\"]}}}}"
63+
)
64+
.into(),
65+
1 => format!(
66+
"{{\"{checksum}\":{{\"state\":\"created\",\"missingChunks\":[]}}}}"
67+
)
68+
.into(),
69+
2 => format!(
70+
"{{\"{checksum}\":{{\"state\":\"ok\",\"detail\":null,\"missingChunks\":[],\"dif\":{{\"id\":\"1\",\"uuid\":\"00000000-0000-0000-0000-000000000000\",\"debugId\":\"00000000-0000-0000-0000-000000000000\",\"objectName\":\"dartsymbolmap.json\",\"cpuName\":\"any\",\"headers\":{{\"Content-Type\":\"application/octet-stream\"}},\"size\":1,\"sha1\":\"{checksum}\",\"dateCreated\":\"1776-07-04T12:00:00.000Z\",\"data\":{{}}}}}}}}"
71+
)
72+
.into(),
73+
n => panic!(
74+
"Only 3 calls to the assemble endpoint expected, but there were {}.",
75+
n + 1
76+
),
77+
}
78+
})
79+
.expect(3),
80+
)
81+
.assert_cmd([
82+
"dart-symbol-map",
83+
"upload",
84+
"tests/integration/_fixtures/dart_symbol_map/dartsymbolmap.json",
85+
// Use a fixture with a single Debug ID (embedded PDB)
86+
"tests/integration/_fixtures/Sentry.Samples.Console.Basic.pdb",
87+
])
88+
.with_default_token()
89+
.run_and_assert(AssertCommand::Success);
90+
}
91+
92+
#[test]
93+
fn command_upload_dart_symbol_map_invalid_mapping() {
94+
// Invalid mapping (odd number of entries) should fail before any HTTP calls.
95+
TestManager::new()
96+
.assert_cmd([
97+
"dart-symbol-map",
98+
"upload",
99+
"tests/integration/_fixtures/dart_symbol_map/dartsymbolmap-invalid.json",
100+
"tests/integration/_fixtures/Sentry.Samples.Console.Basic.pdb",
101+
])
102+
.with_default_token()
103+
.run_and_assert(AssertCommand::Failure);
104+
}

0 commit comments

Comments
 (0)