diff --git a/__tests__/status-json.test.ts b/__tests__/status-json.test.ts index 292ca209f..a467f71db 100644 --- a/__tests__/status-json.test.ts +++ b/__tests__/status-json.test.ts @@ -13,6 +13,7 @@ import * as fs from 'fs'; import * as path from 'path'; import * as os from 'os'; import { CodeGraph } from '../src'; +import { EXTRACTION_VERSION } from '../src/extraction/extraction-version'; const BIN = path.resolve(__dirname, '../dist/bin/codegraph.js'); const PKG_VERSION = JSON.parse( @@ -32,6 +33,15 @@ function runStatusJson(cwd: string): Record { return JSON.parse(line); } +function runStatusText(cwd: string): string { + return execFileSync(process.execPath, [BIN, 'status'], { + cwd, + encoding: 'utf-8', + env: { ...process.env, CODEGRAPH_NO_DAEMON: '1', NO_COLOR: '1' }, + stdio: ['ignore', 'pipe', 'pipe'], + }); +} + describe('codegraph status --json — CI fields (#329)', () => { let tempDir: string; @@ -86,6 +96,29 @@ describe('codegraph status --json — CI fields (#329)', () => { expect(ms).toBeGreaterThanOrEqual(before - 1000); expect(ms).toBeLessThanOrEqual(after + 1000); }); + + it('status requires a full rebuild when the extraction version is stale', async () => { + fs.writeFileSync(path.join(tempDir, 'a.ts'), 'export const x = 1;\n'); + const cg = CodeGraph.initSync(tempDir); + await cg.indexAll(); + cg.close(); + + // Simulate an index built by an older extraction engine. Incremental sync + // cannot revisit every unchanged file, so it must not be offered here. + // eslint-disable-next-line @typescript-eslint/no-require-imports + const { DatabaseSync } = require('node:sqlite'); + const db = new DatabaseSync(path.join(tempDir, '.codegraph', 'codegraph.db')); + db.prepare( + "INSERT INTO project_metadata (key, value, updated_at) VALUES ('indexed_with_extraction_version', ?, 0) " + + "ON CONFLICT(key) DO UPDATE SET value = excluded.value" + ).run(String(EXTRACTION_VERSION - 1)); + db.close(); + + const out = runStatusText(tempDir); + expect(out).toContain('Run "codegraph index"'); + expect(out).toMatch(/full rebuild/i); + expect(out).not.toContain('codegraph sync'); + }); }); describe('index completeness marker (index_state)', () => { diff --git a/__tests__/upgrade.test.ts b/__tests__/upgrade.test.ts index 0a2f89da4..c41de051e 100644 --- a/__tests__/upgrade.test.ts +++ b/__tests__/upgrade.test.ts @@ -204,10 +204,12 @@ describe('version helpers', () => { expect(parseLatestTagFromLocation('https://github.com/o/r/releases')).toBeNull(); }); - it('reindexAdvisory mentions the refresh commands', () => { + it('reindexAdvisory requires a full rebuild for extraction improvements', () => { const a = reindexAdvisory(); - expect(a).toContain('codegraph sync'); - expect(a).toContain('codegraph index -f'); + expect(a).toContain('codegraph index'); + expect(a).toMatch(/full rebuild/i); + expect(a).not.toContain('codegraph sync'); + expect(a).not.toContain('codegraph index -f'); }); it('buildWindowsUpgradeScript targets the right asset per arch and renames-not-deletes the exe', () => { @@ -300,7 +302,8 @@ describe('runUpgrade', () => { expect(calls.runs[0].args[1]).toContain('curl -fsSL'); expect(calls.runs[0].args[1]).toContain('| sh'); expect(calls.runs[0].env?.CODEGRAPH_INSTALL_DIR).toBe('/h/.codegraph'); - expect(calls.logs.join('\n')).toMatch(/codegraph sync/); // re-index advisory printed + expect(calls.logs.join('\n')).toMatch(/codegraph index/); // re-index advisory printed + expect(calls.logs.join('\n')).not.toMatch(/codegraph sync/); }); it('unix bundle: falls back to wget, and errors when neither downloader exists', async () => { diff --git a/src/bin/codegraph.ts b/src/bin/codegraph.ts index 4d85e204f..84df8d0a0 100644 --- a/src/bin/codegraph.ts +++ b/src/bin/codegraph.ts @@ -1037,7 +1037,7 @@ program if (reindexRecommended) { const builtWith = buildInfo.version ? `v${buildInfo.version.replace(/^v/, '')}` : 'an earlier version'; warn(`Index was built by ${builtWith}; re-index to pick up this engine's improvements.`); - info('Run "codegraph index" (full rebuild) or "codegraph sync"'); + info('Run "codegraph index" (full rebuild required)'); console.log(); } diff --git a/src/upgrade/index.ts b/src/upgrade/index.ts index 1c76738c5..d41a15bcd 100644 --- a/src/upgrade/index.ts +++ b/src/upgrade/index.ts @@ -310,9 +310,8 @@ const c = { export function reindexAdvisory(): string { return [ c.dim('Your existing project indexes keep working, but were built by the previous version.'), - c.dim('To pick up this version’s extraction improvements, refresh each project:'), - ` ${c.cyan('codegraph sync')} ${c.dim('# incremental, fast')}`, - ` ${c.cyan('codegraph index -f')} ${c.dim('# full rebuild')}`, + c.dim('To pick up this version’s extraction improvements, fully rebuild each project index:'), + ` ${c.cyan('codegraph index')} ${c.dim('# full rebuild required')}`, c.dim('(`codegraph status` flags any index that predates the engine you’re running.)'), ].join('\n'); }