Bugfix: spacetime init --template react-ts creates a broken .env.local - #5941
Open
krisajenkins wants to merge 1 commit into
Open
krisajenkins wants to merge 1 commit into
krisajenkins wants to merge 1 commit into
Conversation
Run `spacetime init --template react-ts myproject`, accept the defaults. You'll get a project path of `myproject/` and a database name like `myproject-30ctp`. The instructions that follow, and the contents of the `.env.local` file will use the wrong database name. They'll use the project name instead of the actual database. This will affect plenty of other templates, but `react-ts` is the one I found it on. In a lot of cases, it won't be noticed because `spacetime dev` overwrites the `.env.local` file, but out of the box it's broken. The database name prompt's answer only ever reached `spacetime.local.json`. It never made it into the template setup, so `init_builtin` wrote the env file from the project name instead: ```rust write_typescript_client_env_file(project_path, &config.project_name, config.use_local)?; ``` The chosen database name is now passed from `exec_init` through `init_from_template` to `init_builtin`, and into `print_next_steps`. It's passed as a parameter rather than stored on `TemplateConfig`, because that struct is built in six places before the database name is known. - Rename `write_typescript_client_env_file`'s `module_name` parameter to `db_name`. - Add a test that initialises the `react-ts` template offline with distinct project and database names and asserts every `*_SPACETIMEDB_DB_NAME` in `.env.local` is the database name. It fails against the old code.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description of Changes
Run
spacetime init --template react-ts myprojectand accept the defaults. You'll get a project path ofmyproject/and a database name likemyproject-30ctp. The "Next steps" instructions that follow, and the contents of the generated.env.local, use the wrong database name: they use the project name instead of the database you just confirmed. So out of the box, the client points at a database that doesn't exist.This affects every built-in template with a TypeScript client, since they all share the same
.env.localwriter, and thespacetime publishline in "Next steps" was wrong for the Rust and C# templates too. It often goes unnoticed becausespacetime devoverwrites.env.localon every build, but running the client directly shows it.The database name prompt's answer only ever reached
spacetime.local.json. It never made it into the template setup, soinit_builtinwrote the env file from the project name:The chosen database name is now passed from
exec_initthroughinit_from_templatetoinit_builtin, and intoprint_next_steps. It's passed as a parameter rather than stored onTemplateConfig, because that struct is built in six places before the database name is known.write_typescript_client_env_file'smodule_nameparameter todb_name.react-tstemplate offline with distinct project and database names, and asserts every*_SPACETIMEDB_DB_NAMEin.env.localis the database name.API and ABI breaking changes
None. Only private functions inside the CLI's
initsubcommand change signature.Rollback safety impact
n/a
Expected complexity level and risk
1
Testing
test_init_builtin_typescript_client_env_uses_database_namepasses, and fails when the old&config.project_nameargument is restored.cargo test -p spacetimedb-cli --lib subcommands::init::tests,cargo clippy -p spacetimedb-cli --testsandcargo fmt -p spacetimedb-cli -- --checkare clean.spacetime init --template react-ts myproject, accept the defaults, and check that.env.localand the "Next steps" output both use the suffixed database name.