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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added per-step token cost tracking and estimated tool call token usage to Ask Sourcebot chat history. [#1353](https://github.com/sourcebot-dev/sourcebot/pull/1353)

### Fixed
- Fixed a crash when searching with `context:` referencing a search context that does not exist; it now returns a graceful error. [#1362](https://github.com/sourcebot-dev/sourcebot/pull/1362)
- Send anonymous server-side PostHog events as personless so unauthenticated requests don't inflate person counts. [#1367](https://github.com/sourcebot-dev/sourcebot/pull/1367)

## [5.0.4] - 2026-06-18
Expand Down
45 changes: 45 additions & 0 deletions packages/web/src/features/search/parser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { describe, expect, it } from 'vitest';
import type { PrismaClient } from '@sourcebot/db';
import { parseQuerySyntaxIntoIR } from './parser';
import { ServiceErrorException } from '@/lib/serviceError';
import { ErrorCode } from '@/lib/errorCodes';

describe('parseQuerySyntaxIntoIR', () => {
it('throws a ServiceErrorException when a search context is not found', async () => {
const prisma = {
searchContext: {
findUnique: async () => null,
},
} as unknown as PrismaClient;

const promise = parseQuerySyntaxIntoIR({
query: 'Helpers context:0',
options: {},
prisma,
});

await expect(promise).rejects.toBeInstanceOf(ServiceErrorException);
await expect(promise).rejects.toMatchObject({
serviceError: { errorCode: ErrorCode.SEARCH_CONTEXT_NOT_FOUND },
});
});

it('expands a search context into its repo set when found', async () => {
const prisma = {
searchContext: {
findUnique: async () => ({
repos: [{ name: 'org/repo-a' }, { name: 'org/repo-b' }],
}),
},
} as unknown as PrismaClient;

const ir = await parseQuerySyntaxIntoIR({
query: 'context:my-context',
options: {},
prisma,
});

expect(JSON.stringify(ir)).toContain('org/repo-a');
expect(JSON.stringify(ir)).toContain('org/repo-b');
});
});
6 changes: 5 additions & 1 deletion packages/web/src/features/search/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ export const parseQuerySyntaxIntoIR = async ({
});

if (!context) {
throw new Error(`Search context "${contextName}" not found`);
throw new ServiceErrorException({
statusCode: StatusCodes.NOT_FOUND,
errorCode: ErrorCode.SEARCH_CONTEXT_NOT_FOUND,
message: `Search context "${contextName}" not found`,
});
}

return context.repos.map((repo) => repo.name);
Expand Down