Skip to content

Commit

Permalink
fix: use correct enum values for task output mode (#5607)
Browse files Browse the repository at this point in the history
### Description

Fixes #5598

We weren't correctly (de)serializing the `outputMode` values to our enum
causing prune to fail when parsing an `outputMode` that contained an
`-only` suffix.

### Testing Instructions

Added new unit tests for making sure we can parse `outputMode`s that we
support.
Verify that unit tests match the supported values listed in [our
docs](https://turbo.build/repo/docs/reference/configuration#outputmode)

Co-authored-by: Chris Olszewski <Chris Olszewski>
  • Loading branch information
chris-olszewski committed Jul 25, 2023
1 parent eb719e0 commit b3d4145
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
24 changes: 24 additions & 0 deletions crates/turborepo-lib/src/config/turbo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,4 +790,28 @@ mod tests {

assert_eq!(pruned_json, expected);
}

#[test_case("full", Some(TaskOutputMode::Full) ; "full")]
#[test_case("hash-only", Some(TaskOutputMode::HashOnly) ; "hash-only")]
#[test_case("new-only", Some(TaskOutputMode::NewOnly) ; "new-only")]
#[test_case("errors-only", Some(TaskOutputMode::ErrorsOnly) ; "errors-only")]
#[test_case("none", Some(TaskOutputMode::None) ; "none")]
#[test_case("junk", None ; "invalid value")]
fn test_parsing_output_mode(output_mode: &str, expected: Option<TaskOutputMode>) {
let json: Result<RawTurboJSON, _> = serde_json::from_value(serde_json::json!({
"pipeline": {
"build": {
"outputMode": output_mode,
}
}
}));

let actual = json
.as_ref()
.ok()
.and_then(|j| j.pipeline.as_ref())
.and_then(|pipeline| pipeline.0.get("build"))
.and_then(|build| build.output_mode);
assert_eq!(actual, expected);
}
}
10 changes: 5 additions & 5 deletions crates/turborepo-lib/src/task_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ pub struct TaskOutputs {
}

// TaskOutputMode defines the ways turbo can display task output during a run
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
pub enum TaskOutputMode {
// FullTaskOutput will show all task output
#[default]
Full,
// None will hide all task output
None,
// Hash will display turbo-computed task hashes
Hash,
HashOnly,
// New will show all new task output and turbo-computed task hashes for cached
// output
New,
NewOnly,
// Error will show task output for failures only; no cache miss/hit messages are
// emitted
Error,
ErrorsOnly,
}

// taskDefinitionHashable exists as a definition for PristinePipeline, which is
Expand Down

0 comments on commit b3d4145

Please sign in to comment.