-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: prioritize raw task output over task_output setting #7286
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
Changes from 5 commits
057aea1
80ef4b3
d1803cf
03077e8
3664e6e
5cbf7d4
7802169
5f0cb85
a113ba2
2b768ba
8a69478
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Test that raw tasks get interleave output even when task_output=prefix is set | ||
| # This ensures raw=true takes priority over task_output setting | ||
|
|
||
| cat <<EOF >mise.toml | ||
| [settings] | ||
| task_output = "prefix" | ||
|
|
||
| [tasks.normal] | ||
| run = 'echo normal task' | ||
|
|
||
| [tasks.raw_task] | ||
| raw = true | ||
| run = 'echo raw task output' | ||
| EOF | ||
|
|
||
| # Normal task should use prefix output (from settings) | ||
| assert_contains "mise run normal" "[normal] normal task" | ||
|
|
||
| # Raw task should get interleave output mode, meaning stdout goes directly | ||
| # without the [task_name] prefix being applied to the actual output | ||
| assert "mise run raw_task" "raw task output" | ||
|
|
||
| # Verify stdout doesn't have the prefix (only check stdout, not stderr) | ||
| stdout_output=$(mise run raw_task 2>/dev/null) | ||
| if [[ $stdout_output == *"[raw_task]"* ]]; then | ||
| echo "FAIL: raw task stdout should not have prefix" | ||
| exit 1 | ||
| fi | ||
| echo "SUCCESS: raw task stdout has no prefix" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,9 +121,12 @@ impl OutputHandler { | |
| TaskOutput::Prefix | ||
| } else if self.interleave { | ||
| TaskOutput::Interleave | ||
| } else if self.raw(task) { | ||
| // raw tasks need interleave for stdin/stdout to work properly | ||
| TaskOutput::Interleave | ||
| } else if let Some(output) = Settings::get().task_output { | ||
| output | ||
| } else if self.raw(task) || self.jobs() == 1 || self.is_linear { | ||
| } else if self.jobs() == 1 || self.is_linear { | ||
| TaskOutput::Interleave | ||
| } else { | ||
| TaskOutput::Prefix | ||
|
|
@@ -171,3 +174,87 @@ impl OutputHandler { | |
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use crate::config::settings::SettingsPartial; | ||
| use confique::Partial; | ||
|
|
||
| // Mutex to ensure tests don't interfere with each other when modifying global settings | ||
| static TEST_SETTINGS_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(()); | ||
|
|
||
| // Helper to run test with specific task_output setting | ||
| fn with_task_output_setting<F, R>(task_output: TaskOutput, test_fn: F) -> R | ||
| where | ||
| F: FnOnce() -> R, | ||
| { | ||
| let _guard = TEST_SETTINGS_LOCK.lock().unwrap(); | ||
|
|
||
| let mut settings = SettingsPartial::empty(); | ||
| settings.task_output = Some(task_output); | ||
|
|
||
| crate::config::Settings::reset(Some(settings)); | ||
| let result = test_fn(); | ||
| crate::config::Settings::reset(None); | ||
|
|
||
| result | ||
| } | ||
|
|
||
| fn default_config() -> OutputHandlerConfig { | ||
| OutputHandlerConfig { | ||
| prefix: false, | ||
| interleave: false, | ||
| output: None, | ||
| silent: false, | ||
| quiet: false, | ||
| raw: false, | ||
| is_linear: false, | ||
| jobs: None, | ||
| } | ||
| } | ||
|
|
||
| fn raw_task() -> Task { | ||
| Task { | ||
| raw: true, | ||
| ..Default::default() | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_raw_task_gets_interleave_output() { | ||
| let handler = OutputHandler::new(default_config()); | ||
| let task = raw_task(); | ||
| assert_eq!(handler.output(Some(&task)), TaskOutput::Interleave); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Test race condition due to missing lock acquisitionThe |
||
|
|
||
| #[test] | ||
| fn test_prefix_flag_overrides_raw() { | ||
| let config = OutputHandlerConfig { | ||
| prefix: true, | ||
| ..default_config() | ||
| }; | ||
| let handler = OutputHandler::new(config); | ||
| let task = raw_task(); | ||
| assert_eq!(handler.output(Some(&task)), TaskOutput::Prefix); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_raw_task_overrides_task_output_setting() { | ||
| // Key test: raw=true must override task_output=prefix setting | ||
| with_task_output_setting(TaskOutput::Prefix, || { | ||
| let handler = OutputHandler::new(default_config()); | ||
| let task = raw_task(); | ||
| assert_eq!(handler.output(Some(&task)), TaskOutput::Interleave); | ||
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_task_output_setting_applies_to_normal_tasks() { | ||
| with_task_output_setting(TaskOutput::Prefix, || { | ||
| let handler = OutputHandler::new(default_config()); | ||
| let task = Task::default(); | ||
| assert_eq!(handler.output(Some(&task)), TaskOutput::Prefix); | ||
| }); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Unit tests depend on global SettingsThe new unit tests call |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just remove this and rely on the e2e test unless you think it's adding value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good to me 👍