Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed May 17, 2024
1 parent 08682b1 commit e9acfb0
Show file tree
Hide file tree
Showing 53 changed files with 193 additions and 228 deletions.
17 changes: 16 additions & 1 deletion crates/turborepo-lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ pub struct ExecutionArgs {
/// Environment variable mode.
/// Use "loose" to pass the entire existing environment.
/// Use "strict" to use an allowlist specified in turbo.json.
#[clap(long = "env-mode", default_value = "strict", num_args = 0..=1, default_missing_value = "infer")]
#[clap(long = "env-mode", default_value = "strict", num_args = 0..=1, default_missing_value = "strict")]
pub env_mode: EnvMode,
/// Use the given selector to specify package(s) to act as
/// entry points. The syntax mirrors pnpm's syntax, and
Expand Down Expand Up @@ -1445,6 +1445,21 @@ mod test {
} ;
"framework_inference: flag set to false"
)]
#[test_case::test_case(
&["turbo", "run", "build", "--env-mode"],
Args {
command: Some(Command::Run {
execution_args: Box::new(ExecutionArgs {
tasks: vec!["build".to_string()],
env_mode: EnvMode::Strict,
..get_default_execution_args()
}),
run_args: Box::new(get_default_run_args())
}),
..Args::default()
} ;
"env_mode: not fully-specified"
)]
#[test_case::test_case(
&["turbo", "run", "build"],
Args {
Expand Down
4 changes: 2 additions & 2 deletions crates/turborepo-lib/src/hash/proto.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ struct GlobalHashable {


enum EnvMode {
loose @1;
strict @2;
loose @0;
strict @1;
}

struct Entry {
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/run/global_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{

static DEFAULT_ENV_VARS: [&str; 1] = ["VERCEL_ANALYTICS_ID"];

const GLOBAL_CACHE_KEY: &str = "HEY STELLLLLLLAAAAAAAAAAAAA";
const GLOBAL_CACHE_KEY: &str = "I can’t see ya, but I know you’re here";

#[derive(Debug, Error)]
pub enum Error {
Expand Down
10 changes: 4 additions & 6 deletions crates/turborepo-lib/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,13 @@ impl Run {
is_monorepo.then(|| get_external_deps_hash(&root_workspace.transitive_dependencies));

let global_hash_inputs = {
let (env_mode, pass_through_env) = match self.opts.run_opts.env_mode {
let env_mode = self.opts.run_opts.env_mode;
let pass_through_env = match env_mode {
EnvMode::Loose => {
// Remove the passthroughs from hash consideration if we're explicitly loose.
(EnvMode::Loose, None)
None
}
env_mode => (
env_mode,
self.root_turbo_json.global_pass_through_env.as_deref(),
),
EnvMode::Strict => self.root_turbo_json.global_pass_through_env.as_deref(),
};

get_global_hash_inputs(
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/run/summary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl RunTracker {
run_opts,
packages,
global_hash_summary,
global_env_mode.into(),
global_env_mode,
task_factory,
)
.await?;
Expand Down
7 changes: 1 addition & 6 deletions crates/turborepo-lib/src/run/summary/task_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,7 @@ impl<'a> TaskSummaryFactory<'a> {
framework,
dependencies,
dependents,
// TODO: this is some very messy code that appears in a few places
// we should attempt to calculate this once and reuse it
env_mode: match self.global_env_mode {
cli::EnvMode::Strict => EnvMode::Strict,
cli::EnvMode::Loose => EnvMode::Loose,
},
env_mode: self.global_env_mode.into(),

Check failure on line 178 in crates/turborepo-lib/src/run/summary/task_factory.rs

View workflow job for this annotation

GitHub Actions / Turborepo rust clippy

useless conversion to the same type: `cli::EnvMode`
environment_variables: TaskEnvVarSummary::new(
task_definition,
env_vars,
Expand Down
10 changes: 5 additions & 5 deletions turborepo-tests/integration/tests/dry-json/monorepo.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Setup

$ cat tmpjson.log | jq .globalCacheInputs
{
"rootKey": "HEY STELLLLLLLAAAAAAAAAAAAA",
"rootKey": "I can\xe2\x80\x99t see ya, but I know you\xe2\x80\x99re here", (esc)
"files": {
"foo.txt": "eebae5f3ca7b5831e429e947b7d61edd0de69236"
},
Expand Down Expand Up @@ -50,7 +50,7 @@ Setup
"taskId": "my-app#build",
"task": "build",
"package": "my-app",
"hash": "f5b905676d8a275c",
"hash": "dea27cc2fbbcfe2c",
"inputs": {
".env.local": "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
"package.json": "1746e0db2361085b5953a6a3beab08c24af5bc08"
Expand Down Expand Up @@ -92,7 +92,7 @@ Setup
},
"expandedOutputs": [],
"framework": "",
"envMode": "loose",
"envMode": "strict",
"environmentVariables": {
"specified": {
"env": [],
Expand All @@ -113,7 +113,7 @@ Setup
"taskId": "util#build",
"task": "build",
"package": "util",
"hash": "1ce33e04f265f95c",
"hash": "e09943c27ed0a75d",
"inputs": {
"package.json": "e755064fd7893809d10fc067bb409c7ae516327f"
},
Expand Down Expand Up @@ -148,7 +148,7 @@ Setup
},
"expandedOutputs": [],
"framework": "",
"envMode": "loose",
"envMode": "strict",
"environmentVariables": {
"specified": {
"env": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Setup
"turboVersion": "[a-z0-9\.-]+", (re)
"monorepo": false,
"globalCacheInputs": {
"rootKey": "HEY STELLLLLLLAAAAAAAAAAAAA",
"rootKey": "I can\xe2\x80\x99t see ya, but I know you\xe2\x80\x99re here", (esc)
"files": {
"package-lock.json": "1c117cce37347befafe3a9cba1b8a609b3600021",
"package.json": "8606ff4b95a5330740d8d9d0948faeada64f1f32"
Expand All @@ -27,13 +27,13 @@ Setup
"passthrough": null
}
},
"envMode": "infer",
"envMode": "strict",
"frameworkInference": true,
"tasks": [
{
"taskId": "build",
"task": "build",
"hash": "bfac661137d88079",
"hash": "64c6a531cb00bb47",
"inputs": {
".gitignore": "03b541460c1b836f96f9c0a941ceb48e91a9fd83",
"package-lock.json": "1c117cce37347befafe3a9cba1b8a609b3600021",
Expand Down Expand Up @@ -68,7 +68,7 @@ Setup
},
"expandedOutputs": [],
"framework": "",
"envMode": "loose",
"envMode": "strict",
"environmentVariables": {
"specified": {
"env": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Setup
"turboVersion": "[a-z0-9\.-]+", (re)
"monorepo": false,
"globalCacheInputs": {
"rootKey": "HEY STELLLLLLLAAAAAAAAAAAAA",
"rootKey": "I can\xe2\x80\x99t see ya, but I know you\xe2\x80\x99re here", (esc)
"files": {
"package-lock.json": "1c117cce37347befafe3a9cba1b8a609b3600021",
"package.json": "8606ff4b95a5330740d8d9d0948faeada64f1f32",
Expand All @@ -26,13 +26,13 @@ Setup
"passthrough": null
}
},
"envMode": "infer",
"envMode": "strict",
"frameworkInference": true,
"tasks": [
{
"taskId": "build",
"task": "build",
"hash": "45fcb56a23295f63",
"hash": "90cc7d5743fac83f",
"inputs": {
".gitignore": "03b541460c1b836f96f9c0a941ceb48e91a9fd83",
"package-lock.json": "1c117cce37347befafe3a9cba1b8a609b3600021",
Expand Down Expand Up @@ -74,7 +74,7 @@ Setup
},
"expandedOutputs": [],
"framework": "",
"envMode": "loose",
"envMode": "strict",
"environmentVariables": {
"specified": {
"env": [],
Expand All @@ -89,7 +89,7 @@ Setup
{
"taskId": "test",
"task": "test",
"hash": "314a0e5a10072ae2",
"hash": "a9ebf97b334e0690",
"inputs": {
".gitignore": "03b541460c1b836f96f9c0a941ceb48e91a9fd83",
"package-lock.json": "1c117cce37347befafe3a9cba1b8a609b3600021",
Expand Down Expand Up @@ -129,7 +129,7 @@ Setup
},
"expandedOutputs": [],
"framework": "",
"envMode": "loose",
"envMode": "strict",
"environmentVariables": {
"specified": {
"env": [],
Expand Down
8 changes: 4 additions & 4 deletions turborepo-tests/integration/tests/dry-json/single-package.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Setup
"turboVersion": "[a-z0-9\.-]+", (re)
"monorepo": false,
"globalCacheInputs": {
"rootKey": "HEY STELLLLLLLAAAAAAAAAAAAA",
"rootKey": "I can\xe2\x80\x99t see ya, but I know you\xe2\x80\x99re here", (esc)
"files": {
"package-lock.json": "1c117cce37347befafe3a9cba1b8a609b3600021",
"package.json": "8606ff4b95a5330740d8d9d0948faeada64f1f32",
Expand All @@ -26,13 +26,13 @@ Setup
"passthrough": null
}
},
"envMode": "infer",
"envMode": "strict",
"frameworkInference": true,
"tasks": [
{
"taskId": "build",
"task": "build",
"hash": "45fcb56a23295f63",
"hash": "90cc7d5743fac83f",
"inputs": {
".gitignore": "03b541460c1b836f96f9c0a941ceb48e91a9fd83",
"package-lock.json": "1c117cce37347befafe3a9cba1b8a609b3600021",
Expand Down Expand Up @@ -72,7 +72,7 @@ Setup
},
"expandedOutputs": [],
"framework": "",
"envMode": "loose",
"envMode": "strict",
"environmentVariables": {
"specified": {
"env": [],
Expand Down
6 changes: 3 additions & 3 deletions turborepo-tests/integration/tests/dry-run.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Setup
Global Hash Inputs
Global Files = 1
External Dependencies Hash = 459c029558afe716
Global Cache Key = HEY STELLLLLLLAAAAAAAAAAAAA
Global Cache Key = I can\xe2\x80\x99t see ya, but I know you\xe2\x80\x99re here (esc)
Global .env Files Considered = 0
Global Env Vars = SOME_ENV_VAR
Global Env Vars Values =
Expand All @@ -31,7 +31,7 @@ Setup
my-app#build
Task = build\s* (re)
Package = my-app\s* (re)
Hash = f5b905676d8a275c\s* (re)
Hash = dea27cc2fbbcfe2c
Cached \(Local\) = false\s* (re)
Cached \(Remote\) = false\s* (re)
Directory = apps(\/|\\)my-app\s* (re)
Expand All @@ -52,7 +52,7 @@ Setup
util#build
Task = build\s* (re)
Package = util\s* (re)
Hash = 1ce33e04f265f95c\s* (re)
Hash = e09943c27ed0a75d
Cached \(Local\) = false\s* (re)
Cached \(Remote\) = false\s* (re)
Directory = packages(\/|\\)util\s* (re)
Expand Down
30 changes: 15 additions & 15 deletions turborepo-tests/integration/tests/edit-turbo-json/task.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,63 @@ Baseline task hashes
$ ${TURBO} build --dry=json | jq -r '.tasks | sort_by(.taskId)[] | {taskId, hash}'
{
"taskId": "another#build",
"hash": "02f55362198a6c3d"
"hash": "39902e236d45b17a"
}
{
"taskId": "my-app#build",
"hash": "8a8944ef32696847"
"hash": "8f74c4a19d54432c"
}
{
"taskId": "util#build",
"hash": "1ce33e04f265f95c"
"hash": "e09943c27ed0a75d"
}

Change only my-app#build
$ cp "$TESTDIR/fixture-configs/b-change-only-my-app.json" "$(pwd)/turbo.json" && git commit -am "no comment" --quiet
$ ${TURBO} build --dry=json | jq -r '.tasks | sort_by(.taskId)[] | {taskId, hash}'
{
"taskId": "another#build",
"hash": "02f55362198a6c3d"
"hash": "39902e236d45b17a"
}
{
"taskId": "my-app#build",
"hash": "83bb5352c916557e"
"hash": "c741bcbd31d15d60"
}
{
"taskId": "util#build",
"hash": "1ce33e04f265f95c"
"hash": "e09943c27ed0a75d"
}

Change my-app#build dependsOn
$ cp "$TESTDIR/fixture-configs/c-my-app-depends-on.json" "$(pwd)/turbo.json" && git commit -am "no comment" --quiet
$ ${TURBO} build --dry=json | jq -r '.tasks | sort_by(.taskId)[] | {taskId, hash}'
{
"taskId": "another#build",
"hash": "02f55362198a6c3d"
"hash": "39902e236d45b17a"
}
{
"taskId": "my-app#build",
"hash": "346838a5f9d9a530"
"hash": "6553128bdbc1036d"
}
{
"taskId": "util#build",
"hash": "1ce33e04f265f95c"
"hash": "e09943c27ed0a75d"
}

Non-materially modifying the dep graph does nothing.
$ cp "$TESTDIR/fixture-configs/d-depends-on-util.json" "$(pwd)/turbo.json" && git commit -am "no comment" --quiet
$ ${TURBO} build --dry=json | jq -r '.tasks | sort_by(.taskId)[] | {taskId, hash}'
{
"taskId": "another#build",
"hash": "02f55362198a6c3d"
"hash": "39902e236d45b17a"
}
{
"taskId": "my-app#build",
"hash": "346838a5f9d9a530"
"hash": "6553128bdbc1036d"
}
{
"taskId": "util#build",
"hash": "1ce33e04f265f95c"
"hash": "e09943c27ed0a75d"
}


Expand All @@ -71,13 +71,13 @@ Change util#build impacts itself and my-app
$ ${TURBO} build --dry=json | jq -r '.tasks | sort_by(.taskId)[] | {taskId, hash}'
{
"taskId": "another#build",
"hash": "02f55362198a6c3d"
"hash": "39902e236d45b17a"
}
{
"taskId": "my-app#build",
"hash": "b15e1a917912cd09"
"hash": "fa0fd889b37b9c1b"
}
{
"taskId": "util#build",
"hash": "2ee29eb57d7f69b3"
"hash": "b781fbdbf3ba6a42"
}
4 changes: 2 additions & 2 deletions turborepo-tests/integration/tests/global-deps.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Run a build
\xe2\x80\xa2 Packages in scope: my-app (esc)
\xe2\x80\xa2 Running build in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
my-app:build: cache miss, executing 81165ceb4ed0e31f
my-app:build: cache miss, executing 4dd187491a8e9350

Tasks: 1 successful, 1 total
Cached: 0 cached, 1 total
Expand All @@ -18,7 +18,7 @@ Run a build
\xe2\x80\xa2 Packages in scope: my-app (esc)
\xe2\x80\xa2 Running build in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
my-app:build: cache miss, executing 7bc88ba3e84628fd
my-app:build: cache miss, executing 0ba77ba531e887b6

Tasks: 1 successful, 1 total
Cached: 0 cached, 1 total
Expand Down
Loading

0 comments on commit e9acfb0

Please sign in to comment.