Resolve the default config path in the reset command (fixes #1404) - #1423
Resolve the default config path in the reset command (fixes #1404)#1423youdie006 wants to merge 3 commits into
Conversation
reset only loaded a config when -config was passed explicitly, so LITESTREAM_CONFIG and the default config path were ignored (benbjohnson#1404) -- unlike the other subcommands, which resolve DefaultConfigPath() when -config is empty. Without the config, reset operated on the default meta path instead of the one configured for the database. Resolve the default config path when -config is not given (matching the other subcommands) but tolerate a missing config file, since reset can run on a database that is not listed in any config. Adds a regression test that fails without the fix.
corylanou
left a comment
There was a problem hiding this comment.
Thanks for addressing #1404. This PR correctly makes reset honor LITESTREAM_CONFIG and the implicit default config path.
There is one behavior change that needs adjustment: ErrConfigFileNotFound is currently ignored regardless of how the path was selected. As a result, an explicitly missing -config file, which previously returned an error, now silently falls back to the default metadata path.
Please preserve an error for an explicitly supplied -config path. A missing path supplied through LITESTREAM_CONFIG should also return an error once we begin honoring that variable. Only a missing implicit platform default should be tolerated, preserving standalone litestream reset behavior.
Please add tests covering these cases:
- Missing explicit -config returns an error.
- Missing LITESTREAM_CONFIG path returns an error.
- Missing implicit platform default retains standalone reset behavior.
…ault An explicitly supplied -config path, or one from LITESTREAM_CONFIG, that does not exist now returns ErrConfigFileNotFound instead of falling back to the default metadata path. Only a missing implicit platform default is tolerated, preserving standalone litestream reset <db>. resolveConfigPath reports whether the path was explicitly selected, and DefaultConfigPath delegates to it so LITESTREAM_CONFIG is still read in one place and the other subcommands are unaffected.
|
Thanks for the review — you were right, and the consequence was worse than a silent fallback. I probed it before and after: With a mistyped What changedConfig resolution now distinguishes how the path was selected:
On your "use an existing helper if there is one" — there wasn't. Every other subcommand ( The other five subcommands are unaffected: same branch order, same values, and their tests pass. TestsThe three cases you listed:
The first two assert Verified red then green: with
Disclosure: I use AI assistance in my work, and I review and verify everything before it goes out. The probe and the red-green runs above are my own. |
Description
resetonly loaded a Litestream config when-configwas passed explicitly (cmd/litestream/reset.go:48), so it ignoredLITESTREAM_CONFIGand the default config path. Every other subcommand resolvesDefaultConfigPath()when-configis empty (databases.go,status.go,replicate.go,restore.go,ltx.go), andDefaultConfigPath()honorsLITESTREAM_CONFIGbefore falling back to/etc/litestream.yml. Becauseresetskipped that step,dbConfigstayedniland it operated on the default meta path vialitestream.NewDB(dbPath)instead of themeta-pathconfigured for the database (NewDBFromConfig).This resolves the default config path when
-configis not given, matching the other subcommands, but tolerates a missing config file (errors.Is(err, ErrConfigFileNotFound)) soresetstill works on a database that is not listed in any config.Scope: changes only the config-path resolution in
reset. Behavior with no config file present is unchanged, and the other subcommands are untouched.Motivation and Context
reseteven advertises the default config path in its own help text, but ignored it —LITESTREAM_CONFIG=cfg litestream reset <db>never saw the config.Fixes #1404
How Has This Been Tested?
Added
TestResetCommand_RunWithConfigEnv(cmd/litestream/reset_test.go): it places the Litestream state at a non-defaultmeta-pathdiscoverable only through a config file, setsLITESTREAM_CONFIG, runsresetwithout-config, and asserts the state at the configured meta path is removed.Verified red/green: the new test fails on
main(config ignored → default meta path used) and passes with this change.go build ./...,go vet ./cmd/litestream/, andgofmtare clean (go 1.25).Types of changes
Checklist
go fmt,go vet)go test ./cmd/litestream/)AI disclosure: prepared with AI assistance (Claude Code); the bug was traced against the code, the fix derived, and the red/green test verified before submitting.