fix: address network command review feedback

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
BB-fat
2026-07-18 22:52:53 +08:00
co-authored by Cursor
parent 259b4826b7
commit 9799b98937
16 changed files with 488 additions and 289 deletions
+31 -2
View File
@@ -89,17 +89,46 @@ fn render(reply: &NetworkResult, format: Format) -> Result<(), CliError> {
fn render_entry(entry: &NetworkEntry) -> String {
let method = entry.method.as_deref().unwrap_or("?");
let url = entry.url.as_deref().unwrap_or("(unknown)");
match entry.kind {
bsk_protocol::tools::NetworkEntryKind::Failure => {
let err = entry.error_text.as_deref().unwrap_or("failed");
format!("#{} FAILED {method} {} — {err}", entry.sequence, entry.url)
format!("#{} FAILED {method} {url} - {err}", entry.sequence)
}
bsk_protocol::tools::NetworkEntryKind::Response => {
let status = entry
.status
.map(|s| s.to_string())
.unwrap_or_else(|| "?".to_string());
format!("#{} {status} {method} {}", entry.sequence, entry.url)
format!("#{} {status} {method} {url}", entry.sequence)
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use bsk_protocol::tools::NetworkEntryKind;
#[test]
fn human_failure_output_uses_ascii_and_displays_unknown_url() {
let entry = NetworkEntry {
sequence: 7,
kind: NetworkEntryKind::Failure,
method: Some("GET".into()),
url: None,
status: None,
status_text: None,
mime_type: None,
resource_type: Some("Fetch".into()),
error_text: Some("net::ERR_FAILED".into()),
timestamp: None,
truncated: false,
};
assert_eq!(
render_entry(&entry),
"#7 FAILED GET (unknown) - net::ERR_FAILED"
);
}
}
+1 -1
View File
@@ -386,7 +386,7 @@ async fn network_returns_buffered_entries() {
sequence: 4,
kind: NetworkEntryKind::Response,
method: Some("GET".into()),
url: "https://example.test/api".into(),
url: Some("https://example.test/api".into()),
status: Some(404),
status_text: Some("Not Found".into()),
mime_type: Some("application/json".into()),
@@ -4,8 +4,7 @@
"type": "object",
"required": [
"kind",
"sequence",
"url"
"sequence"
],
"properties": {
"error_text": {
@@ -68,7 +67,10 @@
"type": "boolean"
},
"url": {
"type": "string"
"type": [
"string",
"null"
]
}
},
"definitions": {
@@ -32,8 +32,7 @@
"type": "object",
"required": [
"kind",
"sequence",
"url"
"sequence"
],
"properties": {
"error_text": {
@@ -96,7 +95,10 @@
"type": "boolean"
},
"url": {
"type": "string"
"type": [
"string",
"null"
]
}
}
},
+5 -12
View File
@@ -31,22 +31,14 @@ pub enum NetworkEntryKind {
Failure,
}
impl NetworkEntryKind {
pub fn as_str(self) -> &'static str {
match self {
Self::Response => "response",
Self::Failure => "failure",
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct NetworkEntry {
pub sequence: u64,
pub kind: NetworkEntryKind,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub method: Option<String>,
pub url: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
/// HTTP status code (`response` entries only).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub status: Option<u32>,
@@ -108,7 +100,7 @@ mod tests {
sequence: 3,
kind: NetworkEntryKind::Response,
method: Some("GET".into()),
url: "https://example.test/api".into(),
url: Some("https://example.test/api".into()),
status: Some(404),
status_text: Some("Not Found".into()),
mime_type: Some("application/json".into()),
@@ -121,7 +113,7 @@ mod tests {
sequence: 4,
kind: NetworkEntryKind::Failure,
method: Some("GET".into()),
url: "https://example.test/blocked".into(),
url: None,
status: None,
status_text: None,
mime_type: None,
@@ -138,6 +130,7 @@ mod tests {
assert_eq!(value["entries"][0]["kind"], json!("response"));
assert_eq!(value["entries"][0]["status"], json!(404));
assert_eq!(value["entries"][1]["kind"], json!("failure"));
assert!(value["entries"][1].get("url").is_none());
assert_eq!(
value["entries"][1]["error_text"],
json!("net::ERR_BLOCKED_BY_CLIENT")