From 8df02c683760bdb2dc5a588e0f24631dfb9f0cf3 Mon Sep 17 00:00:00 2001 From: Chris Olszewski Date: Wed, 5 Jun 2024 14:40:29 -0700 Subject: [PATCH] fix: correctly serialize ui values (#8338) ### Description Solves the issue reported here: https://github.com/vercel/turbo/issues/8311#issuecomment-2148968155 The `biome` deserialization defaults to camel case, whereas the `serde` serialization implementation doesn't. ### Testing Instructions Added unit tests as well as updated the `prune` test fixture to include `"ui": "stream"` --- crates/turborepo-lib/src/turbo_json/mod.rs | 9 +++++++++ .../fixtures/monorepo_with_root_dep/turbo.json | 3 ++- .../integration/tests/prune/produces-valid-turbo-json.t | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/turborepo-lib/src/turbo_json/mod.rs b/crates/turborepo-lib/src/turbo_json/mod.rs index bd4c441ec68ab..18025cd6117f6 100644 --- a/crates/turborepo-lib/src/turbo_json/mod.rs +++ b/crates/turborepo-lib/src/turbo_json/mod.rs @@ -160,6 +160,7 @@ impl DerefMut for Pipeline { } #[derive(Serialize, Debug, Copy, Clone, Deserializable, PartialEq, Eq)] +#[serde(rename_all = "camelCase")] pub enum UI { Tui, Stream, @@ -1073,4 +1074,12 @@ mod tests { let json = RawTurboJson::parse(json, AnchoredSystemPath::new("").unwrap()).unwrap(); assert_eq!(json.ui, expected); } + + #[test_case(r#"{ "ui": "tui" }"#, r#"{"ui":"tui"}"# ; "tui")] + #[test_case(r#"{ "ui": "stream" }"#, r#"{"ui":"stream"}"# ; "stream")] + fn test_ui_serialization(input: &str, expected: &str) { + let parsed = RawTurboJson::parse(input, AnchoredSystemPath::new("").unwrap()).unwrap(); + let actual = serde_json::to_string(&parsed).unwrap(); + assert_eq!(actual, expected); + } } diff --git a/turborepo-tests/integration/fixtures/monorepo_with_root_dep/turbo.json b/turborepo-tests/integration/fixtures/monorepo_with_root_dep/turbo.json index b8ef3df99416b..542fe4b5c2892 100644 --- a/turborepo-tests/integration/fixtures/monorepo_with_root_dep/turbo.json +++ b/turborepo-tests/integration/fixtures/monorepo_with_root_dep/turbo.json @@ -11,5 +11,6 @@ "web#build": { "dependsOn": ["web#gen"] } - } + }, + "ui": "stream" } diff --git a/turborepo-tests/integration/tests/prune/produces-valid-turbo-json.t b/turborepo-tests/integration/tests/prune/produces-valid-turbo-json.t index 8614ec80376de..1087a8195b670 100644 --- a/turborepo-tests/integration/tests/prune/produces-valid-turbo-json.t +++ b/turborepo-tests/integration/tests/prune/produces-valid-turbo-json.t @@ -16,7 +16,8 @@ Make sure we prune tasks that reference a pruned workspace "build": { "outputs": [] } - } + }, + "ui": "stream" } Verify turbo can read the produced turbo.json