(rootDir: string)
| 142 | } |
| 143 | |
| 144 | export async function readIndexMeta(rootDir: string): Promise<IndexMeta> { |
| 145 | const metaPath = path.join(rootDir, CODEBASE_CONTEXT_DIRNAME, INDEX_META_FILENAME); |
| 146 | |
| 147 | let parsed: unknown; |
| 148 | try { |
| 149 | const raw = await fs.readFile(metaPath, 'utf-8'); |
| 150 | parsed = JSON.parse(raw); |
| 151 | } catch (error) { |
| 152 | throw asIndexCorrupted('Index meta missing or unreadable (rebuild required)', error); |
| 153 | } |
| 154 | |
| 155 | const result = IndexMetaSchema.safeParse(parsed); |
| 156 | if (!result.success) { |
| 157 | throw new IndexCorruptedError( |
| 158 | `Index meta schema mismatch (rebuild required): ${result.error.message}` |
| 159 | ); |
| 160 | } |
| 161 | |
| 162 | const meta = result.data; |
| 163 | |
| 164 | if (meta.metaVersion !== INDEX_META_VERSION) { |
| 165 | throw new IndexCorruptedError( |
| 166 | `Index meta version mismatch (rebuild required): expected metaVersion=${INDEX_META_VERSION}, found metaVersion=${meta.metaVersion}` |
| 167 | ); |
| 168 | } |
| 169 | |
| 170 | if (meta.formatVersion !== INDEX_FORMAT_VERSION) { |
| 171 | throw new IndexCorruptedError( |
| 172 | `Index format version mismatch (rebuild required): expected formatVersion=${INDEX_FORMAT_VERSION}, found formatVersion=${meta.formatVersion}` |
| 173 | ); |
| 174 | } |
| 175 | |
| 176 | return meta; |
| 177 | } |
| 178 | |
| 179 | export async function validateIndexArtifacts(rootDir: string, meta: IndexMeta): Promise<void> { |
| 180 | const contextDir = path.join(rootDir, CODEBASE_CONTEXT_DIRNAME); |
no test coverage detected