// Spot-check specific invariants after migrate-v1-issues.mjs.
// Usage: bare scripts/migrate-spot-check.mjs <v3-storage-dir>
import path from 'bare-path'
import Corestore from 'corestore'
import { IssueRegistry } from '../lib/issue-registry.js'
const storage = Bare.argv[2]
if (!storage) throw new Error('usage: bare scripts/migrate-spot-check.mjs <v3-storage-dir>')
const store = new Corestore(path.join(storage, 'store'))
await store.ready()
const registry = new IssueRegistry(store, {})
// 1. id=0 preservation
const deploy = await registry.getForRepo('hyper-deploy')
const zero = await deploy.get(0)
console.log('hyper-deploy #0:', zero ? `"${zero.title}" status=${zero.status} createdAt=${zero.createdAt}` : 'MISSING')
// 2. closed status preservation (godot-keet has 11 closed)
const keet = await registry.getForRepo('godot-keet')
const keetClosed = await keet.list({ status: 'closed' })
console.log(`godot-keet closed issues: ${keetClosed.length} (expected 11)`)
// 3. pear-git gap at 0 and 64 preserved (no placeholder)
const pg = await registry.getForRepo('pear-git')
const pg64 = await pg.get(64)
const pg0 = await pg.get(0)
console.log(`pear-git #64: ${pg64 ? 'present (UNEXPECTED)' : 'absent (correct — gap preserved)'}`)
console.log(`pear-git #0: ${pg0 ? 'present (UNEXPECTED)' : 'absent (correct — gap preserved)'}`)
const pgAll = await pg.list({ status: 'all' })
console.log(`pear-git total: ${pgAll.length} (expected 82)`)
const pgClosed = await pg.list({ status: 'closed' })
console.log(`pear-git closed: ${pgClosed.length} (expected 57)`)
// 4. counter.next past highest id
await pg._room.base.update()
const counter = await pg._room.view.get('counter:issues')
console.log(`pear-git counter.next: ${counter ? counter.value.next : 'missing'} (expected 84 = max(83)+1)`)
// 5. a pear-git comment end-to-end
for (const issue of pgAll) {
const comments = await pg.getComments(issue.id)
if (comments.length > 0) {
const c = comments[0]
console.log(`pear-git #${issue.id} comment "${c.commentId}":`)
console.log(` author : ${c.author}`)
console.log(` createdAt: ${new Date(c.createdAt || 0).toISOString()}`)
console.log(` body : ${(c.body || '').slice(0, 80)}`)
break
}
}
try { await store.close() } catch {}