Skip to content

Commit

Permalink
fix: Final fixes and tests before release. (#1480)
Browse files Browse the repository at this point in the history
* Fix cache check.

* Use block in place.

* Add tests.

* Fix proto loading.

* Remove debug.

* Fix tests.

* Update proto.
  • Loading branch information
milesj committed May 27, 2024
1 parent 898d007 commit 99289d9
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
with:
auto-install: true
cache: ${{ runner.os == 'Linux' }}
proto-version: '0.35.3' # Keep in sync
proto-version: '0.35.4' # Keep in sync
- uses: mozilla-actions/[email protected]
if: ${{ vars.ENABLE_SCCACHE == 'true' }}
- name: Checking coverage status
Expand Down
11 changes: 10 additions & 1 deletion crates/core/moon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::path::Path;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use tokio::sync::RwLock;
use tokio::task::block_in_place;

static TELEMETRY: AtomicBool = AtomicBool::new(true);
static TELEMETRY_READY: AtomicBool = AtomicBool::new(false);
Expand All @@ -41,7 +42,15 @@ pub async fn load_workspace_from(
proto_env: Arc<ProtoEnvironment>,
console: Arc<Console>,
) -> miette::Result<Workspace> {
let mut workspace = match Workspace::load_from(&proto_env.cwd, &proto_env) {
let proto_env_clone = Arc::clone(&proto_env);

// We need to load the workspace in a blocking task, because config
// loading is synchronous, but uses `reqwest::blocking` under the hood,
// which triggers a panic when used in an async context...
let result =
block_in_place(move || Workspace::load_from(&proto_env_clone.cwd, &proto_env_clone));

let mut workspace = match result {
Ok(workspace) => {
set_telemetry(workspace.config.telemetry);
workspace
Expand Down
4 changes: 4 additions & 0 deletions crates/core/tool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ pub fn get_proto_paths(proto: &ProtoEnvironment) -> Vec<PathBuf> {
}

pub fn get_proto_version_env(tool: &ProtoTool) -> Option<String> {
if tool.version.is_none() {
return None;
}

let spec = tool.get_resolved_version();

// If we have a "latest" alias, use "*" as a version instead,
Expand Down
6 changes: 3 additions & 3 deletions crates/node/platform/tests/project_aliases_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async fn get_aliases_graph() -> (ProjectGraph, Sandbox) {
(graph, sandbox)
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn loads_node_aliases_name_scopes() {
let (graph, _sandbox) = get_aliases_graph().await;

Expand All @@ -43,7 +43,7 @@ async fn loads_node_aliases_name_scopes() {
);
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn returns_project_using_alias() {
let (graph, _sandbox) = get_aliases_graph().await;

Expand All @@ -53,7 +53,7 @@ async fn returns_project_using_alias() {
);
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn graph_uses_id_for_nodes() {
let (graph, _sandbox) = get_aliases_graph().await;

Expand Down
2 changes: 1 addition & 1 deletion nextgen/common/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ pub const CONFIG_PROJECT_FILENAME: &str = "moon.yml";

pub const CONFIG_TEMPLATE_FILENAME: &str = "template.yml";

pub const PROTO_CLI_VERSION: &str = "0.35.3";
pub const PROTO_CLI_VERSION: &str = "0.35.4";
10 changes: 9 additions & 1 deletion nextgen/config/src/config_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,15 @@ impl Cacher for ConfigCache {

fn write(&mut self, url: &str, contents: &str) -> Result<(), ConfigError> {
if !self.memory.contains_key(url) {
let _ = fs::write(self.get_temp_path(url), contents);
let file = self.get_temp_path(url);

if let Some(parent) = file.parent() {
if !parent.exists() {
let _ = fs::create_dir_all(parent);
}
}

let _ = fs::write(file, contents);

self.memory.insert(url.to_owned(), contents.to_owned());
}
Expand Down
28 changes: 28 additions & 0 deletions nextgen/config/tests/inherited_tasks_config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use moon_config::{
};
use moon_target::Target;
use rustc_hash::FxHashMap;
use schematic::Config;
use starbase_sandbox::{create_empty_sandbox, create_sandbox};
use std::collections::BTreeMap;
use utils::*;
Expand Down Expand Up @@ -238,6 +239,33 @@ fileGroups:

assert_eq!(config.tasks, create_merged_tasks());
}

#[test]
fn loads_from_url_and_saves_temp_file() {
let sandbox = create_empty_sandbox();
let server = MockServer::start();

server.mock(|when, then| {
when.method(GET).path("/config.yml");
then.status(200).body(SHARED_TASKS);
});

let temp_dir = sandbox.path().join(".moon/cache/temp");
let url = server.url("/config.yml");

sandbox.create_file("tasks.yml", format!(r"extends: '{url}'"));

assert!(!temp_dir.exists());

test_config(sandbox.path().join("tasks.yml"), |path| {
// Use load_partial instead of load since this caches!
let partial = InheritedTasksConfig::load_partial(sandbox.path(), path).unwrap();

Ok(InheritedTasksConfig::from_partial(partial))
});

assert!(temp_dir.exists());
}
}

mod file_groups {
Expand Down
63 changes: 62 additions & 1 deletion nextgen/config/tests/toolchain_config_test.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
mod utils;

use httpmock::prelude::*;
use moon_config::{BinConfig, BinEntry, NodePackageManager, NodeVersionFormat, ToolchainConfig};
use proto_core::{Id, PluginLocator, ProtoConfig, UnresolvedVersionSpec};
use starbase_sandbox::create_sandbox;
use starbase_sandbox::{create_empty_sandbox, create_sandbox};
use std::env;
use utils::*;

Expand Down Expand Up @@ -36,6 +37,10 @@ mod toolchain_config {
mod extends {
use super::*;

const SHARED_TOOLCHAIN: &str = r"
bun: {}
node: {}";

#[test]
fn recursive_merges() {
let sandbox = create_sandbox("extends/toolchain");
Expand Down Expand Up @@ -74,6 +79,62 @@ mod toolchain_config {
assert!(!typescript.create_missing_config);
assert!(typescript.sync_project_references);
}

#[test]
fn loads_from_url() {
let sandbox = create_empty_sandbox();
let server = MockServer::start();

server.mock(|when, then| {
when.method(GET).path("/config.yml");
then.status(200).body(SHARED_TOOLCHAIN);
});

let url = server.url("/config.yml");

sandbox.create_file(
"toolchain.yml",
format!(
r"
extends: '{url}'
deno: {{}}
"
),
);

let config = test_config(sandbox.path().join("toolchain.yml"), |path| {
ToolchainConfig::load(sandbox.path(), path, &ProtoConfig::default())
});

assert!(config.bun.is_some());
assert!(config.deno.is_some());
assert!(config.node.is_some());
}

#[test]
fn loads_from_url_and_saves_temp_file() {
let sandbox = create_empty_sandbox();
let server = MockServer::start();

server.mock(|when, then| {
when.method(GET).path("/config.yml");
then.status(200).body(SHARED_TOOLCHAIN);
});

let temp_dir = sandbox.path().join(".moon/cache/temp");
let url = server.url("/config.yml");

sandbox.create_file("toolchain.yml", format!(r"extends: '{url}'"));

assert!(!temp_dir.exists());

test_config(sandbox.path().join("toolchain.yml"), |path| {
ToolchainConfig::load(sandbox.path(), path, &ProtoConfig::default())
});

assert!(temp_dir.exists());
}
}

mod bun {
Expand Down
68 changes: 67 additions & 1 deletion nextgen/config/tests/workspace_config_test.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
mod utils;

use httpmock::prelude::*;
use moon_common::Id;
use moon_config::{
ExtensionConfig, FilePath, TemplateLocator, VcsProvider, WorkspaceConfig, WorkspaceProjects,
};
use rustc_hash::FxHashMap;
use semver::Version;
use starbase_sandbox::create_sandbox;
use starbase_sandbox::{create_empty_sandbox, create_sandbox};
use utils::*;

const FILENAME: &str = ".moon/workspace.yml";
Expand All @@ -33,6 +34,11 @@ mod workspace_config {
mod extends {
use super::*;

const SHARED_WORKSPACE: &str = r"
projects:
- packages/*
";

#[test]
fn recursive_merges() {
let sandbox = create_sandbox("extends/workspace");
Expand Down Expand Up @@ -80,6 +86,66 @@ mod workspace_config {
|path| WorkspaceConfig::load_from(path),
);
}

#[test]
fn loads_from_url() {
let sandbox = create_empty_sandbox();
let server = MockServer::start();

server.mock(|when, then| {
when.method(GET).path("/config.yml");
then.status(200).body(SHARED_WORKSPACE);
});

let url = server.url("/config.yml");

sandbox.create_file(
"workspace.yml",
format!(
r"
extends: '{url}'
telemetry: false
"
),
);

let config = test_config(sandbox.path().join("workspace.yml"), |path| {
WorkspaceConfig::load(sandbox.path(), path)
});

if let WorkspaceProjects::Globs(globs) = config.projects {
assert_eq!(globs, vec!["packages/*".to_owned()]);
} else {
assert!(false);
}

assert!(!config.telemetry);
}

#[test]
fn loads_from_url_and_saves_temp_file() {
let sandbox = create_empty_sandbox();
let server = MockServer::start();

server.mock(|when, then| {
when.method(GET).path("/config.yml");
then.status(200).body(SHARED_WORKSPACE);
});

let temp_dir = sandbox.path().join(".moon/cache/temp");
let url = server.url("/config.yml");

sandbox.create_file("workspace.yml", format!(r"extends: '{url}'"));

assert!(!temp_dir.exists());

test_config(sandbox.path().join("workspace.yml"), |path| {
WorkspaceConfig::load(sandbox.path(), path)
});

assert!(temp_dir.exists());
}
}

mod projects {
Expand Down
2 changes: 1 addition & 1 deletion nextgen/workspace/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl Workspace {
let proto_config = proto_env
.as_ref()
.load_config_manager()?
.get_local_config(working_dir)?;
.get_local_config(&root_dir)?;
let toolchain_config = load_toolchain_config(&root_dir, proto_config)?;
let tasks_config = load_tasks_config(&root_dir)?;

Expand Down
6 changes: 5 additions & 1 deletion packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@
last execution attempt.
- Fixed an issue where "have outputs been created" checks would fail if outputs only contained
negated globs, coupled with literal paths.
- Fixed an issue where `.prototools` in the workspace root was not being respected when running moon
commands in a sub-directory.
- Fixed `PROTO_*_VERSION` environment variables being set to `*`, resulting in unexpected versions
being resolved.

#### ⚙️ Internal

- Updated proto to v0.35.3 (from v0.34.4).
- Updated proto to v0.35.4 (from v0.34.4).
- Updated macOS binaries to be built on macos-12 instead of macos-11.

## 1.24.6
Expand Down

0 comments on commit 99289d9

Please sign in to comment.