(projectRoot: string)
| 779 | * Check if the .codegraph directory has valid structure |
| 780 | */ |
| 781 | export function validateDirectory(projectRoot: string): { |
| 782 | valid: boolean; |
| 783 | errors: string[]; |
| 784 | } { |
| 785 | const errors: string[] = []; |
| 786 | const codegraphDir = getCodeGraphDir(projectRoot); |
| 787 | |
| 788 | if (!fs.existsSync(codegraphDir)) { |
| 789 | errors.push('CodeGraph directory does not exist'); |
| 790 | return { valid: false, errors }; |
| 791 | } |
| 792 | |
| 793 | if (!fs.statSync(codegraphDir).isDirectory()) { |
| 794 | errors.push('.codegraph exists but is not a directory'); |
| 795 | return { valid: false, errors }; |
| 796 | } |
| 797 | |
| 798 | // Auto-repair / upgrade .gitignore (non-critical file). A missing one is |
| 799 | // recreated; a stale pre-wildcard default that never ignored daemon.pid is |
| 800 | // regenerated in place (issue #788); a user-authored file is left alone. |
| 801 | const gitignorePath = path.join(codegraphDir, '.gitignore'); |
| 802 | const existedBefore = fs.existsSync(gitignorePath); |
| 803 | if (!ensureGitignore(gitignorePath) && !existedBefore) { |
| 804 | // Only a missing-and-uncreatable file is surfaced; a failed in-place |
| 805 | // upgrade of an existing file is non-fatal — the index still works. |
| 806 | errors.push('.gitignore missing in .codegraph directory and could not be created'); |
| 807 | } |
| 808 | |
| 809 | return { |
| 810 | valid: errors.length === 0, |
| 811 | errors, |
| 812 | }; |
| 813 | } |
no test coverage detected