fix(MULTIVERSION-0001): fix multi-version indexing — jobs never created or triggered for secondary versions

Two bugs prevented secondary versions from ever being indexed:

1. JobQueue.enqueue() and RepositoryService.createIndexingJob() deduplication
   only checked repository_id, so a queued default-branch job blocked all
   version-specific jobs for the same repo. Fix: include version_id in the
   WHERE clause so only exact (repository_id, version_id) pairs are deduped.

2. POST /api/v1/libs/:id/versions used repoService.createIndexingJob() which
   inserts a job record but never triggers queue processing. Fix: use
   queue.enqueue() (same fallback pattern as the libs endpoint) so setImmediate
   fires processNext() after the job is inserted.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Giancarmine Salucci
2026-03-28 09:32:27 +01:00
parent 781d224adc
commit 1c5b634ea4
5 changed files with 69 additions and 8 deletions

View File

@@ -348,6 +348,37 @@ describe('API contract integration', () => {
expect(getBody.versions[0]).not.toHaveProperty('total_snippets');
});
it('POST /api/v1/libs/:id/versions creates distinct jobs for different versions of the same repo', async () => {
const repoService = new RepositoryService(db);
repoService.add({ source: 'github', sourceUrl: 'https://github.com/facebook/react' });
const postV1 = await postVersions({
params: { id: encodeURIComponent('/facebook/react') },
request: new Request('http://test/api/v1/libs/%2Ffacebook%2Freact/versions', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ tag: 'v18.3.0', autoIndex: true })
})
} as never);
const bodyV1 = await postV1.json();
const postV2 = await postVersions({
params: { id: encodeURIComponent('/facebook/react') },
request: new Request('http://test/api/v1/libs/%2Ffacebook%2Freact/versions', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ tag: 'v17.0.2', autoIndex: true })
})
} as never);
const bodyV2 = await postV2.json();
expect(postV1.status).toBe(201);
expect(postV2.status).toBe(201);
expect(bodyV1.job.id).not.toBe(bodyV2.job.id);
expect(bodyV1.job.versionId).toBe('/facebook/react/v18.3.0');
expect(bodyV2.job.versionId).toBe('/facebook/react/v17.0.2');
});
it('GET /api/v1/context returns informative txt output for empty results', async () => {
const repositoryId = seedRepo(db);