fix: use proper YAML parsing for no-db mode detection (bd-r6k2)

Replace fragile strings.Contains("no-db: true") with proper YAML parsing
to avoid false matches in comments or nested keys.

Changes:
- Add NoDb field to localConfig struct
- Add isNoDbModeConfigured() helper function
- Update main.go and doctor.go to use the helper
- Add 8 test cases for isNoDbModeConfigured

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-07 21:09:32 +11:00
parent cc89ce4914
commit 49bfdc2523
4 changed files with 102 additions and 17 deletions

View File

@@ -143,10 +143,28 @@ func checkGitForIssues() (int, string, string) {
return 0, "", ""
}
// localConfig represents the subset of config.yaml we need for auto-import.
// localConfig represents the subset of config.yaml we need for auto-import and no-db detection.
// Using proper YAML parsing handles edge cases like comments, indentation, and special characters.
type localConfig struct {
SyncBranch string `yaml:"sync-branch"`
NoDb bool `yaml:"no-db"`
}
// isNoDbModeConfigured checks if no-db: true is set in config.yaml.
// Uses proper YAML parsing to avoid false matches in comments or nested keys.
func isNoDbModeConfigured(beadsDir string) bool {
configPath := filepath.Join(beadsDir, "config.yaml")
data, err := os.ReadFile(configPath) // #nosec G304 - config file path from beadsDir
if err != nil {
return false
}
var cfg localConfig
if err := yaml.Unmarshal(data, &cfg); err != nil {
return false
}
return cfg.NoDb
}
// getLocalSyncBranch reads sync-branch from the local config.yaml file.