(projectRoot: string)
| 838 | * Check if the .codegraph directory has valid structure |
| 839 | */ |
| 840 | export function validateDirectory(projectRoot: string): { |
| 841 | valid: boolean; |
| 842 | errors: string[]; |
| 843 | } { |
| 844 | const errors: string[] = []; |
| 845 | const codegraphDir = getCodeGraphDir(projectRoot); |
| 846 | |
| 847 | if (!fs.existsSync(codegraphDir)) { |
| 848 | errors.push('CodeGraph directory does not exist'); |
| 849 | return { valid: false, errors }; |
| 850 | } |
| 851 | |
| 852 | if (!fs.statSync(codegraphDir).isDirectory()) { |
| 853 | errors.push('.codegraph exists but is not a directory'); |
| 854 | return { valid: false, errors }; |
| 855 | } |
| 856 | |
| 857 | // Auto-repair / upgrade .gitignore (non-critical file). A missing one is |
| 858 | // recreated; a stale pre-wildcard default that never ignored daemon.pid is |
| 859 | // regenerated in place (issue #788); a user-authored file is left alone. |
| 860 | const gitignorePath = path.join(codegraphDir, '.gitignore'); |
| 861 | const existedBefore = fs.existsSync(gitignorePath); |
| 862 | if (!ensureGitignore(gitignorePath) && !existedBefore) { |
| 863 | // Only a missing-and-uncreatable file is surfaced; a failed in-place |
| 864 | // upgrade of an existing file is non-fatal — the index still works. |
| 865 | errors.push('.gitignore missing in .codegraph directory and could not be created'); |
| 866 | } |
| 867 | |
| 868 | return { |
| 869 | valid: errors.length === 0, |
| 870 | errors, |
| 871 | }; |
| 872 | } |
no test coverage detected