-
Notifications
You must be signed in to change notification settings - Fork 1k
Stop dev from creating unused default bindings dir #5460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
clockwork-labs-bot
wants to merge
3
commits into
master
Choose a base branch
from
bot/dev-config-local-fixes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+16
−21
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 = | ||
| 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() | ||
|
|
@@ -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, | ||
|
|
@@ -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(); | ||
|
|
@@ -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() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 generateworking properly but notspacetime dev's generate, without re-using code fromspacetime generate. shouldn't the fix be to share more of the codepaths so the behavior can't deviate?