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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user