-
Notifications
You must be signed in to change notification settings - Fork 0
engine: zero-config local mode on :7654 (HAL-186) #42
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
hallelx2
wants to merge
1
commit into
main
Choose a base branch
from
halleluyaholudele/hal-186-engine-zero-config-local-mode
base: main
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.
+178
−0
Open
Changes from all commits
Commits
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package config | ||
|
|
||
| import "testing" | ||
|
|
||
| // TestLocalModeDefaults: with VLE_LOCAL_MODE set, Load with no file and no | ||
| // other env boots a complete, valid config — :7654, a localhost Postgres | ||
| // URL, local storage, river queue — with nothing else required. | ||
| func TestLocalModeDefaults(t *testing.T) { | ||
| t.Setenv("VLE_LOCAL_MODE", "true") | ||
|
|
||
| cfg, err := Load("") | ||
| if err != nil { | ||
| t.Fatalf("local-mode Load() with no other config should succeed, got: %v", err) | ||
| } | ||
| if cfg.Server.Addr != ":7654" { | ||
| t.Errorf("local mode server.addr = %q, want :7654", cfg.Server.Addr) | ||
| } | ||
| if cfg.Database.URL != defaultLocalDatabaseURL { | ||
| t.Errorf("local mode database.url = %q, want %q", cfg.Database.URL, defaultLocalDatabaseURL) | ||
| } | ||
| if cfg.Storage.Driver != "local" { | ||
| t.Errorf("local mode storage.driver = %q, want local", cfg.Storage.Driver) | ||
| } | ||
| if cfg.Queue.Driver != "river" { | ||
| t.Errorf("local mode queue.driver = %q, want river", cfg.Queue.Driver) | ||
| } | ||
| if cfg.Storage.Local.Root == "" { | ||
| t.Error("local mode storage.local.root must be set") | ||
| } | ||
| } | ||
|
|
||
| // TestLocalModeTruthyForms: the env flag accepts the usual truthy spellings | ||
| // and ignores everything else. | ||
| func TestLocalModeTruthyForms(t *testing.T) { | ||
| for _, v := range []string{"1", "true", "TRUE", "yes", "on"} { | ||
| t.Setenv("VLE_LOCAL_MODE", v) | ||
| if !LocalModeEnabled() { | ||
| t.Errorf("VLE_LOCAL_MODE=%q should enable local mode", v) | ||
| } | ||
| } | ||
| for _, v := range []string{"", "0", "false", "no", "off", "nope"} { | ||
| t.Setenv("VLE_LOCAL_MODE", v) | ||
| if LocalModeEnabled() { | ||
| t.Errorf("VLE_LOCAL_MODE=%q should NOT enable local mode", v) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // TestLocalModeEnvOverridesWin: local mode only moves the starting point — | ||
| // explicit env values still override the local defaults. | ||
| func TestLocalModeEnvOverridesWin(t *testing.T) { | ||
| t.Setenv("VLE_LOCAL_MODE", "true") | ||
| t.Setenv("VLE_SERVER_ADDR", ":9999") | ||
| t.Setenv("VLE_DATABASE_URL", "postgres://custom:custom@db:5432/custom?sslmode=disable") | ||
| t.Setenv("VLE_STORAGE_LOCAL_ROOT", "/srv/docs") | ||
|
|
||
| cfg, err := Load("") | ||
| if err != nil { | ||
| t.Fatalf("Load() failed: %v", err) | ||
| } | ||
| if cfg.Server.Addr != ":9999" { | ||
| t.Errorf("env should override local addr: got %q, want :9999", cfg.Server.Addr) | ||
| } | ||
| if cfg.Database.URL != "postgres://custom:custom@db:5432/custom?sslmode=disable" { | ||
| t.Errorf("env should override local db url, got %q", cfg.Database.URL) | ||
| } | ||
| if cfg.Storage.Local.Root != "/srv/docs" { | ||
| t.Errorf("VLE_STORAGE_LOCAL_ROOT should set storage root, got %q", cfg.Storage.Local.Root) | ||
| } | ||
| } | ||
|
|
||
| // TestNonLocalModeUnchanged: without the flag the historical defaults hold | ||
| // (:8080), and the engine still requires a database URL for the river | ||
| // queue — i.e. local mode is the ONLY thing that injects one. | ||
| func TestNonLocalModeUnchanged(t *testing.T) { | ||
| t.Setenv("VLE_LOCAL_MODE", "") | ||
| // Provide a DB URL so validation passes for the river default. | ||
| t.Setenv("VLE_DATABASE_URL", "postgres://x:x@localhost:5432/x?sslmode=disable") | ||
|
|
||
| cfg, err := Load("") | ||
| if err != nil { | ||
| t.Fatalf("Load() failed: %v", err) | ||
| } | ||
| if cfg.Server.Addr != ":8080" { | ||
| t.Errorf("non-local addr = %q, want :8080", cfg.Server.Addr) | ||
| } | ||
| } | ||
|
|
||
| // TestNonLocalModeMissingDBURLFails proves the local-mode injection is what | ||
| // removes the "no required config" gap: without it and without a DB URL, | ||
| // the river queue fails validation. | ||
| func TestNonLocalModeMissingDBURLFails(t *testing.T) { | ||
| t.Setenv("VLE_LOCAL_MODE", "") | ||
| t.Setenv("VLE_DATABASE_URL", "") | ||
|
|
||
| if _, err := Load(""); err == nil { | ||
| t.Fatal("expected validation error for river queue with no database.url, got nil") | ||
| } | ||
| } |
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.
Align the documented local Postgres URL with the actual default.
The comment block shows
postgres://vectorless:vectorless@localhost:5432/vectorless, but local mode actually defaults to.../vectorless?sslmode=disableinpkg/config/config.go. Please update this string to match the real injected default to avoid copy/paste confusion.Proposed doc fix
📝 Committable suggestion
🤖 Prompt for AI Agents