Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions __tests__/status-json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -32,6 +33,15 @@ function runStatusJson(cwd: string): Record<string, unknown> {
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;

Expand Down Expand Up @@ -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)', () => {
Expand Down
11 changes: 7 additions & 4 deletions __tests__/upgrade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/codegraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
5 changes: 2 additions & 3 deletions src/upgrade/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down