Skip to content

Commit ed6f665

Browse files
committed
test(knowledge): accept either ordered index in the scale window check and bound discussion case text
1 parent 5c446f1 commit ed6f665

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

‎apps/sim/lib/knowledge/__integration__/scale.integration.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,14 @@ describe.skipIf(!enabled)('knowledge scale: isolated real PostgreSQL, no provide
368368
)
369369
report['reconciliation.window.scan.plan'] = scanned['QUERY PLAN']
370370
saveReport()
371-
expect(planIndexNames('reconciliation.window.scan')).toContain(
372-
'doc_connector_reconciliation_v2_idx'
373-
)
371+
/**
372+
* Every keyset step is an ordered index probe: through the v2 index, or the primary key when
373+
* this fixture's single connector is nearly the whole table. Either is a valid plan.
374+
*/
375+
const walkIndexes = new Set(planIndexNames('reconciliation.window.scan'))
376+
expect(walkIndexes.size).toBeGreaterThan(0)
377+
for (const name of walkIndexes)
378+
expect(['doc_connector_reconciliation_v2_idx', 'document_pkey']).toContain(name)
374379
const [removed] = await db.execute(
375380
sql`SELECT count(*)::int AS count FROM document WHERE connector_id = ${ids.connectorId} AND external_id::integer > ${rows - absentCount} AND deleted_at IS NOT NULL AND cardinality(acl) = 0`
376381
)

‎apps/sim/lib/sim-search/live/github.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ function groupGitHubText(query: string): string {
175175

176176
/** GitHub rejects more than 256 characters of search text; qualifiers do not count toward it. */
177177
const GITHUB_TEXT_CHARACTERS = 256
178-
const githubTextLength = (query: string) =>
178+
export const exceedsGitHubTextLimit = (query: string) =>
179179
githubTokens(query)
180180
.filter((token) => !GITHUB_QUALIFIER.test(token))
181-
.join(' ').length
181+
.join(' ').length > GITHUB_TEXT_CHARACTERS
182182

183183
export async function searchGitHub(
184184
client: NativeClient,
@@ -318,7 +318,7 @@ export async function searchGitHub(
318318
? `${dateField}:<=${dates.end}`
319319
: ''
320320
const datedQuery = dateRange ? [groupGitHubText(text), dateRange].filter(Boolean).join(' ') : text
321-
if (githubTextLength(text) > GITHUB_TEXT_CHARACTERS)
321+
if (exceedsGitHubTextLimit(text))
322322
throw new NativeSearchError(
323323
'unavailable',
324324
'GitHub search text is limited to 256 characters. Shorten the query.'

‎apps/sim/scripts/test-search-discussions-live.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
type WorkspaceSearchFilters,
1212
workspaceSearchFiltersSchema,
1313
} from '@/lib/api/contracts/knowledge'
14-
import { readGitHub, searchGitHub } from '@/lib/sim-search/live/github'
14+
import { exceedsGitHubTextLimit, readGitHub, searchGitHub } from '@/lib/sim-search/live/github'
1515
import { array, object, string } from '@/lib/sim-search/live/http'
1616
import { defaultLiveSearchPolicy } from '@/lib/sim-search/live/policy-schema'
1717
import type { NativeClient, NativePage } from '@/lib/sim-search/live/types'
@@ -478,7 +478,13 @@ try {
478478
const payload: unknown = JSON.parse(buffer.toString('utf8', 0, length))
479479
cases = queryCasesSchema.parse(payload)
480480
for (const test of cases)
481-
for (const query of [test.query, ...test.oracleQueries]) assertRepositoryScope(query)
481+
for (const query of [test.query, ...test.oracleQueries]) {
482+
assertRepositoryScope(query)
483+
assert.ok(
484+
!exceedsGitHubTextLimit(query),
485+
`Case "${test.name}" exceeds GitHub's 256-character search text limit`
486+
)
487+
}
482488
} finally {
483489
await file.close()
484490
}

0 commit comments

Comments
 (0)