Skip to content

Commit

Permalink
Fixing up tests and adding one for declaring a task interruptible wit…
Browse files Browse the repository at this point in the history
…hout it being persistent
  • Loading branch information
NicholasLYang committed Oct 7, 2024
1 parent b4e033d commit 4993179
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
7 changes: 7 additions & 0 deletions crates/turborepo-lib/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ pub enum Error {
#[label("package task found here")]
span: Option<SourceSpan>,
},
#[error("interruptible tasks must be persistent")]
InterruptibleButNotPersistent {
#[source_code]
text: NamedSource,
#[label("`interruptible` set here")]
span: Option<SourceSpan>,
},
#[error(transparent)]
#[diagnostic(transparent)]
InvalidEnvPrefix(Box<InvalidEnvPrefixError>),
Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-lib/src/run/summary/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ mod test {
"inputs": [],
"outputLogs": "full",
"persistent": false,
"interruptible": false,
"interactive": false,
"env": [],
"passThroughEnv": null,
Expand Down
21 changes: 17 additions & 4 deletions crates/turborepo-lib/src/turbo_json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,13 @@ impl TryFrom<RawTaskDefinition> for TaskDefinition {
}
}

let persistent = *raw_task.persistent.unwrap_or_default();
let interruptible = raw_task.interruptible.unwrap_or_default();
if *interruptible && !persistent {
let (span, text) = interruptible.span_and_text("turbo.json");
return Err(Error::InterruptibleButNotPersistent { span, text });
}

let mut env_var_dependencies = HashSet::new();
let mut topological_dependencies: Vec<Spanned<TaskName>> = Vec::new();
let mut task_dependencies: Vec<Spanned<TaskName>> = Vec::new();
Expand Down Expand Up @@ -410,8 +417,8 @@ impl TryFrom<RawTaskDefinition> for TaskDefinition {
inputs,
pass_through_env,
output_logs: *raw_task.output_logs.unwrap_or_default(),
persistent: *raw_task.persistent.unwrap_or_default(),
interruptible: *raw_task.interruptible.unwrap_or_default(),
persistent,
interruptible: *interruptible,
interactive,
env_mode: raw_task.env_mode,
})
Expand Down Expand Up @@ -724,7 +731,8 @@ mod tests {
"inputs": ["package/a/src/**"],
"outputLogs": "full",
"persistent": true,
"interactive": true
"interactive": true,
"interruptible": true
}"#,
RawTaskDefinition {
depends_on: Some(Spanned::new(vec![Spanned::<UnescapedString>::new("cli#build".into()).with_range(26..37)]).with_range(25..38)),
Expand All @@ -736,6 +744,7 @@ mod tests {
output_logs: Some(Spanned::new(OutputLogsMode::Full).with_range(246..252)),
persistent: Some(Spanned::new(true).with_range(278..282)),
interactive: Some(Spanned::new(true).with_range(309..313)),
interruptible: Some(Spanned::new(true).with_range(342..346)),
env_mode: None,
},
TaskDefinition {
Expand All @@ -752,6 +761,7 @@ mod tests {
topological_dependencies: vec![],
persistent: true,
interactive: true,
interruptible: true,
env_mode: None,
}
; "full"
Expand All @@ -765,7 +775,8 @@ mod tests {
"cache": false,
"inputs": ["package\\a\\src\\**"],
"outputLogs": "full",
"persistent": true
"persistent": true,
"interruptible": true
}"#,
RawTaskDefinition {
depends_on: Some(Spanned::new(vec![Spanned::<UnescapedString>::new("cli#build".into()).with_range(30..41)]).with_range(29..42)),
Expand All @@ -776,6 +787,7 @@ mod tests {
inputs: Some(vec![Spanned::<UnescapedString>::new("package\\a\\src\\**".into()).with_range(227..248)]),
output_logs: Some(Spanned::new(OutputLogsMode::Full).with_range(279..285)),
persistent: Some(Spanned::new(true).with_range(315..319)),
interruptible: Some(Spanned::new(true).with_range(352..356)),
interactive: None,
env_mode: None,
},
Expand All @@ -792,6 +804,7 @@ mod tests {
task_dependencies: vec![Spanned::<TaskName<'_>>::new("cli#build".into()).with_range(30..41)],
topological_dependencies: vec![],
persistent: true,
interruptible: true,
interactive: false,
env_mode: None,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "https://turbo.build/schema.json",
"globalDependencies": [
"foo.txt"
],
"globalEnv": [
"SOME_ENV_VAR"
],
"tasks": {
"build": {
"env": [
"NODE_ENV",
"$FOOBAR"
],
"interruptible": true,
"outputs": []
}
}
}
16 changes: 15 additions & 1 deletion turborepo-tests/integration/tests/bad-turbo-json.t
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,21 @@ Run in single package mode even though we have a task with package syntax
`----


Use our custom turbo config which has interruptible: true
$ . ${TESTDIR}/../../helpers/replace_turbo_json.sh $(pwd) "interruptible-but-not-persistent.json"

Build should fail
$ ${TURBO} run build
x interruptible tasks must be persistent
,-[turbo.json:14:1]
14 | ],
15 | "interruptible": true,
: ^^|^
: `-- `interruptible` set here
16 | "outputs": []
`----

[1]

Use our custom turbo config with syntax errors
$ . ${TESTDIR}/../../helpers/replace_turbo_json.sh $(pwd) "syntax-error.json"
Expand Down Expand Up @@ -101,4 +115,4 @@ Run build with syntax errors in turbo.json
15 |
`----

[1]
[1]

0 comments on commit 4993179

Please sign in to comment.