diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-08 10:39:51 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-08 10:39:51 +0200 |
| commit | d5b13224737a9f66c3d5113a885603b32867d740 (patch) | |
| tree | d482cc965a65be22604800fe6772279c52961b99 /internal/appconfig/config_test.go | |
| parent | bd698b257a548d835fbc2675ff5be5e1a69ff229 (diff) | |
add gitignore-aware file filtering for LSP completions and code actionsv0.18.0
Files matching .gitignore patterns or user-configured extra patterns are
now skipped for completions and code actions. Configurable via [ignore]
section in config.toml with gitignore, extra_patterns, and
lsp_notify_ignored options. Includes hot-reload support and env var
overrides (HEXAI_IGNORE_*).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/appconfig/config_test.go')
| -rw-r--r-- | internal/appconfig/config_test.go | 117 |
1 files changed, 113 insertions, 4 deletions
diff --git a/internal/appconfig/config_test.go b/internal/appconfig/config_test.go index 75cc7ee..b9dfe3a 100644 --- a/internal/appconfig/config_test.go +++ b/internal/appconfig/config_test.go @@ -625,9 +625,9 @@ func TestFindGitRoot(t *testing.T) { if err := os.Chdir(nested); err != nil { t.Fatalf("chdir: %v", err) } - root := findGitRoot() + root := FindGitRoot() if root != dir { - t.Fatalf("findGitRoot() = %q, want %q", root, dir) + t.Fatalf("FindGitRoot() = %q, want %q", root, dir) } // Test from a dir with no .git ancestor @@ -635,9 +635,9 @@ func TestFindGitRoot(t *testing.T) { if err := os.Chdir(noGit); err != nil { t.Fatalf("chdir: %v", err) } - root = findGitRoot() + root = FindGitRoot() if root != "" { - t.Fatalf("findGitRoot() = %q, want empty", root) + t.Fatalf("FindGitRoot() = %q, want empty", root) } } @@ -784,3 +784,112 @@ func TestProjectConfigPath(t *testing.T) { t.Fatalf("ProjectConfigPath() = %q, want empty", path) } } + +func TestIgnoreConfig_Defaults(t *testing.T) { + clearHexaiEnv(t) + cfg := Load(nil) + if cfg.IgnoreGitignore == nil || !*cfg.IgnoreGitignore { + t.Error("expected IgnoreGitignore default true") + } + if cfg.IgnoreLSPNotify == nil || !*cfg.IgnoreLSPNotify { + t.Error("expected IgnoreLSPNotify default true") + } + if len(cfg.IgnoreExtraPatterns) != 0 { + t.Errorf("expected empty IgnoreExtraPatterns, got %v", cfg.IgnoreExtraPatterns) + } +} + +func TestIgnoreConfig_FromFile(t *testing.T) { + clearHexaiEnv(t) + dir := t.TempDir() + cfgPath := filepath.Join(dir, "config.toml") + writeFile(t, cfgPath, ` +[ignore] +gitignore = false +extra_patterns = ["*.min.js", "dist/**"] +lsp_notify_ignored = false +`) + cfg := LoadWithOptions(newLogger(), LoadOptions{ConfigPath: cfgPath}) + if cfg.IgnoreGitignore == nil || *cfg.IgnoreGitignore { + t.Error("expected IgnoreGitignore false from file") + } + if cfg.IgnoreLSPNotify == nil || *cfg.IgnoreLSPNotify { + t.Error("expected IgnoreLSPNotify false from file") + } + want := []string{"*.min.js", "dist/**"} + if !reflect.DeepEqual(cfg.IgnoreExtraPatterns, want) { + t.Errorf("IgnoreExtraPatterns = %v, want %v", cfg.IgnoreExtraPatterns, want) + } +} + +func TestIgnoreConfig_EnvOverrides(t *testing.T) { + clearHexaiEnv(t) + dir := t.TempDir() + cfgPath := filepath.Join(dir, "config.toml") + writeFile(t, cfgPath, ` +[ignore] +gitignore = true +lsp_notify_ignored = true +`) + withEnv(t, "HEXAI_IGNORE_GITIGNORE", "false") + withEnv(t, "HEXAI_IGNORE_LSP_NOTIFY", "0") + withEnv(t, "HEXAI_IGNORE_EXTRA_PATTERNS", "*.bak,*.tmp") + cfg := LoadWithOptions(newLogger(), LoadOptions{ConfigPath: cfgPath}) + if cfg.IgnoreGitignore == nil || *cfg.IgnoreGitignore { + t.Error("expected IgnoreGitignore false from env override") + } + if cfg.IgnoreLSPNotify == nil || *cfg.IgnoreLSPNotify { + t.Error("expected IgnoreLSPNotify false from env override") + } + want := []string{"*.bak", "*.tmp"} + if !reflect.DeepEqual(cfg.IgnoreExtraPatterns, want) { + t.Errorf("IgnoreExtraPatterns = %v, want %v", cfg.IgnoreExtraPatterns, want) + } +} + +func TestIgnoreConfig_ProjectOverride(t *testing.T) { + clearHexaiEnv(t) + dir := t.TempDir() + cfgPath := filepath.Join(dir, "config.toml") + writeFile(t, cfgPath, ` +[ignore] +gitignore = true +`) + // Set up a fake git repo with project override + projectDir := t.TempDir() + if err := os.Mkdir(filepath.Join(projectDir, ".git"), 0o755); err != nil { + t.Fatalf("mkdir .git: %v", err) + } + projectCfg := filepath.Join(projectDir, ProjectConfigFilename) + writeFile(t, projectCfg, ` +[ignore] +gitignore = false +extra_patterns = ["build/**"] +`) + cfg := LoadWithOptions(newLogger(), LoadOptions{ConfigPath: cfgPath, ProjectRoot: projectDir}) + if cfg.IgnoreGitignore == nil || *cfg.IgnoreGitignore { + t.Error("expected project override to set IgnoreGitignore false") + } + want := []string{"build/**"} + if !reflect.DeepEqual(cfg.IgnoreExtraPatterns, want) { + t.Errorf("IgnoreExtraPatterns = %v, want %v", cfg.IgnoreExtraPatterns, want) + } +} + +func TestIgnoreConfig_DisableGitignore(t *testing.T) { + clearHexaiEnv(t) + dir := t.TempDir() + cfgPath := filepath.Join(dir, "config.toml") + writeFile(t, cfgPath, ` +[ignore] +gitignore = false +`) + cfg := LoadWithOptions(newLogger(), LoadOptions{ConfigPath: cfgPath}) + if cfg.IgnoreGitignore == nil || *cfg.IgnoreGitignore { + t.Error("expected IgnoreGitignore false") + } + // LSP notify should still be true (default, not overridden) + if cfg.IgnoreLSPNotify == nil || !*cfg.IgnoreLSPNotify { + t.Error("expected IgnoreLSPNotify to remain true (default)") + } +} |
