Skip to content

Conversation

@simone-stacks
Copy link
Contributor

Description

Add file and stdin input support to stacks-inspect commands, matching the pattern used in clarity-cli. Commands now accept:

  • - for stdin input
  • File paths
  • Direct values (backward compatible)

Applicable issues

Additional info (benefits, drawbacks, caveats)

  • Using shared helpers between clarity-cli and stacks-inspect (to avoid duplication)

Checklist

  • Test coverage for new or modified code paths
  • Changelog is updated
  • Required documentation changes (e.g., docs/rpc/openapi.yaml and rpc-endpoints.md for v2 endpoints, event-dispatcher.md for new events)
  • New clarity functions have corresponding PR in clarity-benchmarking repo

@codecov
Copy link

codecov bot commented Dec 22, 2025

Codecov Report

❌ Patch coverage is 0% with 60 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.49%. Comparing base (cf457b8) to head (37a8438).

Files with missing lines Patch % Lines
contrib/clarity-cli/src/lib.rs 0.00% 27 Missing ⚠️
contrib/stacks-inspect/src/main.rs 0.00% 27 Missing ⚠️
contrib/stacks-inspect/src/lib.rs 0.00% 6 Missing ⚠️

❌ Your project check has failed because the head coverage (77.49%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #6776      +/-   ##
===========================================
- Coverage    78.41%   77.49%   -0.92%     
===========================================
  Files          585      585              
  Lines       361849   361861      +12     
===========================================
- Hits        283740   280440    -3300     
- Misses       78109    81421    +3312     
Files with missing lines Coverage Δ
contrib/clarity-cli/src/main.rs 17.16% <ø> (+1.23%) ⬆️
contrib/stacks-inspect/src/lib.rs 4.19% <0.00%> (-0.01%) ⬇️
contrib/clarity-cli/src/lib.rs 80.01% <0.00%> (-1.30%) ⬇️
contrib/stacks-inspect/src/main.rs 0.00% <0.00%> (ø)

... and 88 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cf457b8...37a8438. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@simone-stacks simone-stacks marked this pull request as ready for review January 5, 2026 15:26
let block_hex = &argv[2];
let block_data = hex_bytes(block_hex).unwrap_or_else(|_| panic!("Failed to decode hex"));
let block_arg = &argv[2];
let block_hex = if block_arg == "-" || std::path::Path::new(block_arg).exists() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach of making the "value or filename" decision based on whether a file of said name exists feels off to me, I don't think I've ever seen that. Do you know of any precedent for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's a good point, you're right that this pattern is uncommon. My reasoning was:

  1. Backward compatibility: Commands like decode-tx previously only accepted hex strings directly. By checking file existence, existing scripts passing hex strings continue to work unchanged, while also enabling file/stdin input.
  2. Practical safety: For hex inputs (transaction hashes, block data), it's extremely unlikely a valid hex string would collide with an existing file path. These are typically 64+ character strings like 0a1b2c3d....
  3. Convenience: Users don't need to remember different flags (--file vs --hex) for a simple decode operation.

But I totally understand the concern and "extremely unlikely" is not something that I totally love either. Do you think I should add --file and --hex flags?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably wouldn't need both -- if the default (backwards-compatible) behavior is a direct value, then you just need --file (or something like it) to change the semantics. So this:

stacks-inspect foo c0ff33

would be the value 0xc0ff33, and this:

stacks-inspect foo --file c0ff33

would refer to a file named c0ff33.

This does feel cleaner to me, but you have more intuition on the practical uses of this.

Copy link
Contributor Author

@simone-stacks simone-stacks Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's definitely cleaner! Since I'm working on the refactoring of stacks-inspect using clap, and adding --file would require a dedicated extract_flag function or something like that, that would then be erased in favor of clap's parsing, I'd address both your comments in the clap refactoring PR

pub fn read_optional_file_or_stdin(path: Option<&PathBuf>) -> String {
match path {
Some(p) => read_file_or_stdin(p.to_str().expect("Invalid UTF-8 in path")),
None => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: None could defer to - handling instead of duplicating the logic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% agree!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants