Skip to content

fix(server): reload kwelea.toml on change during serve#39

Merged
engineervix merged 1 commit into
mainfrom
fix/38-reload-config-on-change
Jun 26, 2026
Merged

fix(server): reload kwelea.toml on change during serve#39
engineervix merged 1 commit into
mainfrom
fix/38-reload-config-on-change

Conversation

@engineervix

Copy link
Copy Markdown
Owner

Summary

  • rebuildAndReload was reusing the in-memory *config.Config loaded at startup, so kwelea.toml edits (docs_dir, output_dir, base_url) were silently ignored until the server restarted
  • Extract isConfigFile and reloadConfig helpers (independently testable)
  • watch now detects config file events, reloads from disk, re-applies CLI overrides, then snapshots currentCfg into the debounce closure to avoid a data race
  • Bad TOML is logged; the previous config is retained — server keeps running
  • server.Start gains an applyOverrides func(*config.Config) error param; serve.go passes a closure over applyFlagOverrides so CLI flags always win after reload

Closes #38

Test plan

  • go test ./internal/server/... — 8 new tests all pass (isConfigFile × 3, reloadConfig × 5)
  • go test ./... — no regressions
  • go build ./... — clean
  • Manual: kwelea serve, edit kwelea.toml, confirm "→ config reloaded" in logs and rebuild uses new values
  • Manual: kwelea serve --source content/docs, edit docs_dir in toml, confirm CLI override still wins
  • Manual: write bad TOML, confirm error logged and server keeps running

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 juan-lorenzo-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Approved

Verified locally on pr-39 against Go 1.25.7:

  • go vet ./... — clean
  • go build ./... — clean
  • go test -race -count=1 ./... — all 8 new tests pass, no regressions in internal/builder, internal/nav, internal/parser
  • Manual smoke test of kwelea serve:
    • Edit docs_dir in kwelea.toml → log shows → config reloaded then → rebuilt
    • --source cli-docs continues to win over docs_dir set in toml after a reload ✅
    • Bad TOML → error logged, server keeps running, HTTP 200 retained
    • Reproduced the bug on main: touching kwelea.toml produced no reload at all

💡 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: isConfigFile and reloadConfig are independently testable
  • The currentCfg snapshot pattern in the time.AfterFunc closure is the right way to avoid the data race
  • applyOverrides func(*config.Config) error injection keeps the server package free of cmd-package dependencies
  • Test coverage of the failure paths (bad TOML, missing file, override error) is exactly what's needed
  • Doc comments on watch, isConfigFile, reloadConfig and the new Start parameter are clear

Reviewed by Hermes Agent (juan-lorenzo-bot)

@engineervix engineervix merged commit 15addbb into main Jun 26, 2026
5 checks passed
@engineervix engineervix deleted the fix/38-reload-config-on-change branch June 26, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: reload kwelea.toml on change during kwelea serve

2 participants