Repository navigation
fix: quieter tree-sitter notice, single readable errors, effective truncate mode (#21 B13/B17/B18) #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
fix: quieter tree-sitter notice, single readable errors, effective truncate mode (#21 B13/B17/B18) #49
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
691f6ff
fix: don't abort when stderr or stdout is closed early (#40)
igorls 7dc748b
test: don't depend on path separator in closed-pipe test
igorls 4e96ed0
fix: treat BrokenPipe on the truncation notice like other writes (rev…
igorls a83ffbe
fix: quieter tree-sitter notice, single readable errors, effective tr…
igorls e61208b
fix: path in write errors, tree-sitter notice for auto-diff, single c…
igorls 4572d97
test: in-process console/closed-pipe coverage; testable BrokenPipe he…
igorls 6c4024a
test: CountingWriter names the output file on failure (#21)
igorls c5b97cb
Merge fix/40-closed-stderr into fix/21-diagnostics
igorls 6e22561
refactor: console macros call functions so call sites keep coverage a…
igorls cfe785e
refactor: console helpers are functions, not macros, so call sites ke…
igorls 455cec2
test: cover debug tracing, diff-only warning and cache-write warning …
igorls 87470ef
test: make the command-line path runnable in-process (run_from) and c…
igorls b66edff
Merge branch 'test/run-in-process' into fix/40-closed-stderr
igorls bdbeebb
Merge fix/40-closed-stderr into fix/21-diagnostics
igorls f24786b
fix: single readable errors, quieter tree-sitter notice, path in writ…
igorls affcc9c
merge: supersede the stacked history with the master-based change
igorls File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,13 @@ | ||
| use std::io; | ||
| use std::io::{self, Write}; | ||
| use std::process::ExitCode; | ||
|
|
||
| fn main() -> io::Result<()> { | ||
| context_builder::finish(context_builder::run()) | ||
| fn main() -> ExitCode { | ||
| match context_builder::finish(context_builder::run()) { | ||
| Ok(()) => ExitCode::SUCCESS, | ||
| Err(e) => { | ||
| // Once, human-readable, and never a panic if stderr is closed. | ||
| let _ = writeln!(io::stderr(), "Error: {e}"); | ||
| ExitCode::FAILURE | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| //! Diagnostics of the built binary: warnings only when relevant, errors once | ||
| //! and readable (#21: B13, B17, B18). | ||
|
|
||
| use std::fs; | ||
| use std::path::Path; | ||
| use std::process::{Command, Output}; | ||
|
|
||
| fn run(dir: &Path, args: &[&str]) -> Output { | ||
| Command::new(env!("CARGO_BIN_EXE_context-builder")) | ||
| .args(args) | ||
| .current_dir(dir) | ||
| .output() | ||
| .unwrap() | ||
| } | ||
|
|
||
| fn text(bytes: &[u8]) -> String { | ||
| String::from_utf8_lossy(bytes).into_owned() | ||
| } | ||
|
|
||
| fn project() -> tempfile::TempDir { | ||
| let dir = tempfile::tempdir().unwrap(); | ||
| fs::write(dir.path().join("a.rs"), "fn a() {}\n").unwrap(); | ||
| dir | ||
| } | ||
|
|
||
| #[test] | ||
| fn plain_run_does_not_mention_tree_sitter() { | ||
| let dir = project(); | ||
| let out = run(dir.path(), &["-o", "-"]); | ||
| assert!(out.status.success()); | ||
| let stderr = text(&out.stderr); | ||
| assert!(!stderr.contains("tree-sitter"), "{stderr}"); | ||
| } | ||
|
|
||
| #[cfg(not(feature = "tree-sitter-base"))] | ||
| #[test] | ||
| fn tree_sitter_warning_only_for_flags_that_need_it_and_suggests_install() { | ||
| let dir = project(); | ||
| let signatures = text(&run(dir.path(), &["-o", "-", "--signatures"]).stderr); | ||
| assert!( | ||
| signatures.contains("require tree-sitter support"), | ||
| "{signatures}" | ||
| ); | ||
| assert!( | ||
| signatures.contains("cargo install context-builder --features tree-sitter-all"), | ||
| "{signatures}" | ||
| ); | ||
| assert!(!signatures.contains("cargo build"), "{signatures}"); | ||
|
|
||
| let budget = text(&run(dir.path(), &["-o", "-", "--max-tokens", "5000"]).stderr); | ||
| assert!(budget.contains("require tree-sitter support"), "{budget}"); | ||
| } | ||
|
|
||
| #[cfg(not(feature = "tree-sitter-base"))] | ||
| #[test] | ||
| fn truncation_notice_reports_the_effective_mode() { | ||
| let dir = tempfile::tempdir().unwrap(); | ||
| let body = "pub fn filler() { let _ = 1; }\n".repeat(2_000); | ||
| fs::write(dir.path().join("big.rs"), body).unwrap(); | ||
| let out = run(dir.path(), &["-o", "-", "--max-tokens", "2000"]); | ||
| let doc = text(&out.stdout); | ||
| assert!(doc.contains("File content truncated"), "{doc}"); | ||
| assert!(doc.contains("(mode: byte)"), "{doc}"); | ||
| assert!(!doc.contains("(mode: smart)"), "{doc}"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn missing_input_dir_error_is_printed_once_and_readable() { | ||
| let dir = tempfile::tempdir().unwrap(); | ||
| let out = run(dir.path(), &["-d", "no-such-dir"]); | ||
| assert_eq!(out.status.code(), Some(1)); | ||
| let stderr = text(&out.stderr); | ||
| assert_eq!(stderr.matches("Error:").count(), 1, "{stderr}"); | ||
| assert!(stderr.contains("no-such-dir"), "{stderr}"); | ||
| assert!(!stderr.contains("Custom {"), "{stderr}"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn unwritable_output_error_names_the_path_without_debug_formatting() { | ||
| let dir = project(); | ||
| // A regular file used as a directory component cannot be created under. | ||
| fs::write(dir.path().join("blocker"), "x").unwrap(); | ||
| let out = run(dir.path(), &["-o", "blocker/out.md"]); | ||
| assert_eq!(out.status.code(), Some(1)); | ||
| let stderr = text(&out.stderr); | ||
| assert_eq!(stderr.matches("Error:").count(), 1, "{stderr}"); | ||
| assert!(stderr.contains("blocker"), "{stderr}"); | ||
| assert!(!stderr.contains("Os {"), "{stderr}"); | ||
| assert!(!stderr.contains("Custom {"), "{stderr}"); | ||
| } | ||
|
|
||
| #[cfg(unix)] | ||
| #[test] | ||
| fn write_failure_after_open_names_the_output_path() { | ||
| let dir = project(); | ||
| // `/dev/full` opens fine and fails every write with ENOSPC. | ||
| if !Path::new("/dev/full").exists() { | ||
| return; | ||
| } | ||
| let out = run(dir.path(), &["-o", "/dev/full"]); | ||
| assert_eq!(out.status.code(), Some(1)); | ||
| let stderr = text(&out.stderr); | ||
| assert!(stderr.contains("/dev/full"), "{stderr}"); | ||
| } | ||
|
|
||
| #[cfg(not(feature = "tree-sitter-base"))] | ||
| #[test] | ||
| fn auto_diff_runs_also_get_the_tree_sitter_notice() { | ||
| let dir = project(); | ||
| fs::write( | ||
| dir.path().join("context-builder.toml"), | ||
| "output_folder = \"out\"\ntimestamped_output = true\nauto_diff = true\n", | ||
| ) | ||
| .unwrap(); | ||
| let stderr = text(&run(dir.path(), &["-y", "--signatures"]).stderr); | ||
| assert!(stderr.contains("require tree-sitter support"), "{stderr}"); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.