Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions crates/cli/src/subcommands/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,15 +567,17 @@ pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::E
}
}

if !module_bindings_dir.exists() {
let should_prepare_module_bindings_dir =

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am rather surprised that we addressed this issue, which is about spacetime generate working properly but not spacetime dev's generate, without re-using code from spacetime generate. shouldn't the fix be to share more of the codepaths so the behavior can't deviate?

should_prepare_default_module_bindings_dir(skip_generate, using_spacetime_config);
if should_prepare_module_bindings_dir && !module_bindings_dir.exists() {
// Create the module bindings directory if it doesn't exist
std::fs::create_dir_all(&module_bindings_dir).with_context(|| {
format!(
"Failed to create module bindings path {}",
module_bindings_dir.display()
)
})?;
} else if !module_bindings_dir.is_dir() {
} else if should_prepare_module_bindings_dir && !module_bindings_dir.is_dir() {
anyhow::bail!(
"Module bindings path {} exists but is not a directory.",
module_bindings_path.display()
Expand Down Expand Up @@ -1617,6 +1619,10 @@ fn create_default_spacetime_config_if_missing(project_dir: &Path) -> anyhow::Res
Ok(Some(config.save_to_dir(project_dir)?))
}

fn should_prepare_default_module_bindings_dir(skip_generate: bool, using_spacetime_config: bool) -> bool {
!skip_generate && !using_spacetime_config
}

fn create_local_spacetime_config_if_missing(
project_dir: &Path,
database_name: &str,
Expand Down Expand Up @@ -1985,6 +1991,14 @@ mod tests {
);
}

#[test]
fn test_default_module_bindings_dir_is_only_prepared_for_cli_generation() {
assert!(should_prepare_default_module_bindings_dir(false, false));
assert!(!should_prepare_default_module_bindings_dir(false, true));
assert!(!should_prepare_default_module_bindings_dir(true, false));
assert!(!should_prepare_default_module_bindings_dir(true, true));
}

#[test]
fn test_create_local_spacetime_config_if_missing_creates_database_override() {
let temp = TempDir::new().unwrap();
Expand All @@ -2010,25 +2024,6 @@ mod tests {
assert_eq!(obj.len(), 1, "local config should only contain database");
}

#[test]
fn test_create_local_spacetime_config_if_missing_upserts_missing_database() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this test removed?

let temp = TempDir::new().unwrap();
let project_path = temp.path();

std::fs::write(project_path.join("spacetime.json"), "{}").unwrap();
std::fs::write(project_path.join("spacetime.local.json"), r#"{ "server": "local" }"#).unwrap();

let updated = create_local_spacetime_config_if_missing(project_path, "my-cli-db")
.unwrap()
.expect("expected local config to be updated");
assert_eq!(updated, project_path.join("spacetime.local.json"));

let content = std::fs::read_to_string(project_path.join("spacetime.local.json")).unwrap();
let parsed: serde_json::Value = serde_json::from_str(&content).unwrap();
assert_eq!(parsed.get("server").and_then(|v| v.as_str()), Some("local"));
assert_eq!(parsed.get("database").and_then(|v| v.as_str()), Some("my-cli-db"));
}

#[test]
fn test_detect_and_save_merges_into_existing_file_when_no_existing_config_passed() {
let temp = TempDir::new().unwrap();
Expand Down
Loading