From 988e725ea79f1ebd4c9b9f37ad057ea6217698d9 Mon Sep 17 00:00:00 2001 From: Dylan Frankland Date: Fri, 22 Aug 2025 17:15:25 -0700 Subject: [PATCH 1/3] add cli for decoding protos --- Cargo.lock | 2 ++ proto/Cargo.toml | 10 ++++++++++ proto/src/main.rs | 27 +++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 proto/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 99703fdc..8916a12c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3902,6 +3902,8 @@ dependencies = [ name = "proto" version = "0.0.0" dependencies = [ + "anyhow", + "clap", "prost", "prost-build", "prost-types", diff --git a/proto/Cargo.toml b/proto/Cargo.toml index 4362f599..034e02da 100644 --- a/proto/Cargo.toml +++ b/proto/Cargo.toml @@ -4,11 +4,21 @@ edition = "2021" version = "0.0.0" build = "src/build.rs" +[[bin]] +name = "proto-bin-parser" +path = "src/main.rs" +required-features = ["build-binary"] + [lib] name = "proto" path = "src/lib.rs" +[features] +build-binary = ["anyhow", "clap"] + [dependencies] +anyhow = { version = "1.0.44", optional = true } +clap = { version = "4.4.18", features = ["derive", "env"], optional = true } prost = "0.12.6" prost-types = "0.12.6" prost-wkt-types = { version = "0.5.1", features = ["vendored-protox"] } diff --git a/proto/src/main.rs b/proto/src/main.rs new file mode 100644 index 00000000..3a9c01bf --- /dev/null +++ b/proto/src/main.rs @@ -0,0 +1,27 @@ +use std::{fs, path::PathBuf}; + +use clap::Parser; +use prost::Message; +use proto::test_context::test_run::{TestReport, TestResult}; + +#[derive(Debug, Parser)] +pub struct Cli { + /// Protobuf bin file to parse + #[arg(required = true)] + pub proto_bin_file: PathBuf, +} + +fn main() -> anyhow::Result<()> { + let Cli { + proto_bin_file: path, + } = Cli::parse(); + let bin = fs::read(&path)?; + if let Ok(test_report) = TestReport::decode(bin.as_slice()) { + println!("{:#?}", test_report); + } else { + let test_result = TestResult::decode(bin.as_slice()) + .map_err(|err| anyhow::anyhow!("Failed to decode {:#?}: {}", &path, err))?; + println!("{:#?}", test_result); + } + Ok(()) +} From dc7056b1def14ade0edbbfe1b5ae8239477a29dd Mon Sep 17 00:00:00 2001 From: Dylan Frankland Date: Sun, 24 Aug 2025 15:25:22 -0700 Subject: [PATCH 2/3] move tool to `bundle` and reuse `bin_parse` --- Cargo.lock | 3 +-- bundle/Cargo.toml | 7 +++++++ bundle/src/main.rs | 26 ++++++++++++++++++++++++++ proto/Cargo.toml | 10 ---------- proto/src/main.rs | 27 --------------------------- 5 files changed, 34 insertions(+), 39 deletions(-) create mode 100644 bundle/src/main.rs delete mode 100644 proto/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 8916a12c..4e607ec3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -678,6 +678,7 @@ dependencies = [ "async-std", "async-tar-wasm", "chrono", + "clap", "codeowners", "constants", "context", @@ -3902,8 +3903,6 @@ dependencies = [ name = "proto" version = "0.0.0" dependencies = [ - "anyhow", - "clap", "prost", "prost-build", "prost-types", diff --git a/bundle/Cargo.toml b/bundle/Cargo.toml index 8baa4954..d9876ee1 100644 --- a/bundle/Cargo.toml +++ b/bundle/Cargo.toml @@ -3,8 +3,14 @@ name = "bundle" version = "0.0.0" edition = "2021" +[[bin]] +name = "proto-bin-to-json" +path = "src/main.rs" +required-features = ["build-binary"] + [dependencies] anyhow = "1.0.44" +clap = { version = "4.4.18", features = ["derive", "env"], optional = true } codeowners = { path = "../codeowners" } chrono = { version = "0.4.38", features = ["serde"] } proto = { path = "../proto" } @@ -65,3 +71,4 @@ pyo3 = [ "codeowners/pyo3", "context/pyo3", ] +build-binary = ["clap"] diff --git a/bundle/src/main.rs b/bundle/src/main.rs new file mode 100644 index 00000000..1c2492d2 --- /dev/null +++ b/bundle/src/main.rs @@ -0,0 +1,26 @@ +use std::{fs, path::PathBuf}; + +use bundle::bin_parse; +use clap::Parser; + +#[derive(Debug, Parser)] +#[command( + version, + about = "A tool to convert bundle proto bins into JSON for debugging." +)] +pub struct Cli { + /// Protobuf bin file to convert into JSON + #[arg(required = true)] + pub proto_bin_file: PathBuf, +} + +fn main() -> anyhow::Result<()> { + let Cli { + proto_bin_file: path, + } = Cli::parse(); + let bin = fs::read(&path)?; + let test_report = bin_parse(&bin)?; + let json = serde_json::to_string_pretty(&test_report)?; + println!("{}", json); + Ok(()) +} diff --git a/proto/Cargo.toml b/proto/Cargo.toml index 034e02da..4362f599 100644 --- a/proto/Cargo.toml +++ b/proto/Cargo.toml @@ -4,21 +4,11 @@ edition = "2021" version = "0.0.0" build = "src/build.rs" -[[bin]] -name = "proto-bin-parser" -path = "src/main.rs" -required-features = ["build-binary"] - [lib] name = "proto" path = "src/lib.rs" -[features] -build-binary = ["anyhow", "clap"] - [dependencies] -anyhow = { version = "1.0.44", optional = true } -clap = { version = "4.4.18", features = ["derive", "env"], optional = true } prost = "0.12.6" prost-types = "0.12.6" prost-wkt-types = { version = "0.5.1", features = ["vendored-protox"] } diff --git a/proto/src/main.rs b/proto/src/main.rs deleted file mode 100644 index 3a9c01bf..00000000 --- a/proto/src/main.rs +++ /dev/null @@ -1,27 +0,0 @@ -use std::{fs, path::PathBuf}; - -use clap::Parser; -use prost::Message; -use proto::test_context::test_run::{TestReport, TestResult}; - -#[derive(Debug, Parser)] -pub struct Cli { - /// Protobuf bin file to parse - #[arg(required = true)] - pub proto_bin_file: PathBuf, -} - -fn main() -> anyhow::Result<()> { - let Cli { - proto_bin_file: path, - } = Cli::parse(); - let bin = fs::read(&path)?; - if let Ok(test_report) = TestReport::decode(bin.as_slice()) { - println!("{:#?}", test_report); - } else { - let test_result = TestResult::decode(bin.as_slice()) - .map_err(|err| anyhow::anyhow!("Failed to decode {:#?}: {}", &path, err))?; - println!("{:#?}", test_result); - } - Ok(()) -} From d3a2534f03fd943cfcdde75b662f9d83aa6a87c0 Mon Sep 17 00:00:00 2001 From: Dylan Frankland Date: Sun, 24 Aug 2025 17:03:48 -0700 Subject: [PATCH 3/3] fix lint --- bundle/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/src/main.rs b/bundle/src/main.rs index 1c2492d2..ec5c90d5 100644 --- a/bundle/src/main.rs +++ b/bundle/src/main.rs @@ -18,7 +18,7 @@ fn main() -> anyhow::Result<()> { let Cli { proto_bin_file: path, } = Cli::parse(); - let bin = fs::read(&path)?; + let bin = fs::read(path)?; let test_report = bin_parse(&bin)?; let json = serde_json::to_string_pretty(&test_report)?; println!("{}", json);