fix(server): reload kwelea.toml on change during serve#39
Merged
Conversation
rebuildAndReload reused the in-memory cfg pointer loaded at startup, so edits to kwelea.toml (docs_dir, output_dir, base_url) were silently ignored until the server restarted. - Extract isConfigFile and reloadConfig helpers (testable in isolation) - watch detects config file events, reloads from disk, re-applies CLI flag overrides, then snapshots the fresh cfg for the debounce closure to avoid a data race - Bad TOML logs the error and keeps the previous config - server.Start gains applyOverrides param; serve.go passes a closure that calls applyFlagOverrides so CLI flags still win after reload Closes #38
juan-lorenzo-bot
approved these changes
Jun 26, 2026
juan-lorenzo-bot
left a comment
Collaborator
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved ✅
Verified locally on pr-39 against Go 1.25.7:
go vet ./...— cleango build ./...— cleango test -race -count=1 ./...— all 8 new tests pass, no regressions ininternal/builder,internal/nav,internal/parser- Manual smoke test of
kwelea serve:- Edit
docs_dirinkwelea.toml→ log shows→ config reloadedthen→ rebuilt✅ --source cli-docscontinues to win overdocs_dirset in toml after a reload ✅- Bad TOML → error logged, server keeps running, HTTP 200 retained ✅
- Reproduced the bug on
main: touchingkwelea.tomlproduced no reload at all
- Edit
💡 Suggestion (non-blocking)
addDirRecursive is called once at startup with the original cfg.Build.DocsDir. If a user changes docs_dir in kwelea.toml to point at a different directory tree, the watcher still only watches the old tree — so edits in the new tree won't trigger rebuilds (only the toml-triggered rebuild will pick them up, and only the first time, since addDirRecursive isn't re-run). This is pre-existing behaviour, not introduced by this PR, but worth a follow-up issue. The current PR is correct in scope.
✅ Looks Good
- Clean separation:
isConfigFileandreloadConfigare independently testable - The
currentCfgsnapshot pattern in thetime.AfterFuncclosure is the right way to avoid the data race applyOverrides func(*config.Config) errorinjection keeps the server package free ofcmd-package dependencies- Test coverage of the failure paths (bad TOML, missing file, override error) is exactly what's needed
- Doc comments on
watch,isConfigFile,reloadConfigand the newStartparameter are clear
Reviewed by Hermes Agent (juan-lorenzo-bot)
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.
Summary
rebuildAndReloadwas reusing the in-memory*config.Configloaded at startup, sokwelea.tomledits (docs_dir,output_dir,base_url) were silently ignored until the server restartedisConfigFileandreloadConfighelpers (independently testable)watchnow detects config file events, reloads from disk, re-applies CLI overrides, then snapshotscurrentCfginto the debounce closure to avoid a data raceserver.Startgains anapplyOverrides func(*config.Config) errorparam;serve.gopasses a closure overapplyFlagOverridesso CLI flags always win after reloadCloses #38
Test plan
go test ./internal/server/...— 8 new tests all pass (isConfigFile× 3,reloadConfig× 5)go test ./...— no regressionsgo build ./...— cleankwelea serve, editkwelea.toml, confirm "→ config reloaded" in logs and rebuild uses new valueskwelea serve --source content/docs, editdocs_dirin toml, confirm CLI override still wins