Skip to content

Commit 755fec7

Browse files
committed
fix(search): require complete review and date evidence
1 parent e6916a8 commit 755fec7

1 file changed

Lines changed: 70 additions & 31 deletions

File tree

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

Lines changed: 70 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ import type { NativeClient, NativePage } from '@/lib/sim-search/live/types'
2727
* "query":"repo:example/project is:pr search in:title",
2828
* "oracleQueries":["repo:example/project is:pr search in:title"],"expectedId":"123"}].
2929
* Optional fields: filters (startDate, endDate, sortBy), commentFragment, reviewer, approved.
30+
* reviewer requires a submitted review by that login. approved independently checks whether a
31+
* submitted APPROVED review event exists, not current approval status or mergeability. Review
32+
* fixtures must have fewer than 100 records; a full oracle page is rejected as incomplete.
33+
* Oracle queries describe equivalent logical branches. Explicit updated: qualifiers take
34+
* precedence over filters; otherwise both paths use inclusive GitHub candidate bounds.
35+
* The application search layer applies the exclusive end-date filter and is not exercised here.
3036
* Keep real identities and source content in the external case file. Timings include gh process
3137
* and network costs, not model selection or the authorized application/UI boundary.
3238
*/
@@ -232,9 +238,25 @@ async function runQuery(test: QueryCase) {
232238
const firstRequest = requests.length
233239
try {
234240
const oracleRows: Record<string, unknown>[] = []
241+
const start = test.filters?.startDate
242+
? new Date(test.filters.startDate).toISOString()
243+
: undefined
244+
const end = test.filters?.endDate ? new Date(test.filters.endDate).toISOString() : undefined
235245
for (const query of test.oracleQueries) {
246+
const nativeDateRange = (query.match(/"[^"]*"|\S+/g) ?? []).some((token) =>
247+
/^updated:/i.test(token)
248+
)
249+
const dateRange = nativeDateRange
250+
? undefined
251+
: start && end
252+
? `updated:${start}..${end}`
253+
: start
254+
? `updated:>=${start}`
255+
: end
256+
? `updated:<=${end}`
257+
: undefined
236258
const params = new URLSearchParams({
237-
q: query,
259+
q: [query, dateRange].filter(Boolean).join(' '),
238260
per_page: '10',
239261
page: '1',
240262
...(test.filters?.sortBy === 'newest' || test.filters?.sortBy === 'oldest'
@@ -244,7 +266,19 @@ async function runQuery(test: QueryCase) {
244266
const data = object(await githubApi(`/search/issues?${params}`, 'oracle'))
245267
assert.equal(data.incomplete_results, false, 'GitHub oracle search was incomplete')
246268
report.oracleTotal += Number(data.total_count)
247-
oracleRows.push(...array(data.items))
269+
const rows = array(data.items)
270+
if (dateRange) {
271+
for (const row of rows) {
272+
const updated = Date.parse(string(row.updated_at))
273+
assert.ok(
274+
Number.isFinite(updated) &&
275+
(!start || updated >= Date.parse(start)) &&
276+
(!end || updated <= Date.parse(end)),
277+
'Oracle candidate is outside the inclusive provider date interval'
278+
)
279+
}
280+
}
281+
oracleRows.push(...rows)
248282
}
249283
report.oracleResultIds = [...new Set(oracleRows.map((row) => string(row.number)))].sort()
250284
let page: NativePage = { documents: [] }
@@ -321,41 +355,46 @@ async function runQuery(test: QueryCase) {
321355
'GitHub normalizes hyphenated query terms. A matched review/comment fragment may not contain the literal quoted phrase; read the original before claiming exact wording.',
322356
})
323357
}
324-
if (test.reviewer || test.approved) {
358+
if (test.reviewer || test.approved !== undefined) {
325359
const document = test.expectedId
326360
? page.documents.find((document) => document.id === test.expectedId)
327361
: page.documents[0]
328-
if (document) {
329-
const reviews = array(
330-
await githubApi(
331-
`/repos/${repository}/pulls/${document.id}/reviews?per_page=100`,
332-
'oracle'
333-
)
334-
)
362+
assert.ok(document, 'Review expectations require a matching PR result')
363+
const reviews = array(
364+
await githubApi(`/repos/${repository}/pulls/${document.id}/reviews?per_page=100`, 'oracle')
365+
)
366+
assert.ok(
367+
reviews.length < 100,
368+
'Review oracle coverage is incomplete; choose a fixture with fewer than 100 reviews'
369+
)
370+
const submitted = reviews.filter(
371+
(review) => review.state !== 'PENDING' && string(review.submitted_at)
372+
)
373+
if (test.reviewer)
335374
assert.ok(
336-
reviews.some((review) =>
337-
test.reviewer
338-
? object(review.user).login === test.reviewer && review.state !== 'PENDING'
339-
: review.state === 'APPROVED'
375+
submitted.some(
376+
(review) =>
377+
string(object(review.user).login).toLowerCase() === test.reviewer!.toLowerCase()
340378
),
341-
'Independent review events do not support review query result'
379+
'Independent review events do not contain the expected reviewer'
342380
)
343-
report.evidence.push({
344-
type: 'review-events',
345-
url: document.url,
346-
snippet: `${reviews.length} independent review events; ${test.reviewer ? `verified reviewer ${test.reviewer}` : 'verified APPROVED event'}.`,
347-
})
348-
}
349-
}
350-
if (test.filters?.startDate && test.filters.endDate) {
351-
for (const row of oracleRows) {
352-
const updated = Date.parse(string(row.updated_at))
353-
assert.ok(
354-
updated >= Date.parse(test.filters.startDate) &&
355-
updated < Date.parse(test.filters.endDate),
356-
'Date-filtered result is outside the requested interval'
381+
if (test.approved !== undefined)
382+
assert.equal(
383+
submitted.some((review) => review.state === 'APPROVED'),
384+
test.approved,
385+
'Independent review events do not match the expected APPROVED event presence'
357386
)
358-
}
387+
report.evidence.push({
388+
type: 'review-events',
389+
url: document.url,
390+
snippet: [
391+
`${submitted.length} submitted review events`,
392+
test.reviewer && `verified reviewer ${test.reviewer}`,
393+
test.approved !== undefined && `verified APPROVED event presence: ${test.approved}`,
394+
]
395+
.filter(Boolean)
396+
.join('; '),
397+
})
359398
}
360399
report.status = 'passed'
361400
} catch (error) {
@@ -467,7 +506,7 @@ try {
467506
repository,
468507
pullRequest: number,
469508
boundary:
470-
'Real searchGitHub/readGitHub adapters over gh-authenticated GitHub API; independent oracle GETs. Does not exercise model query selection, application authorization, or UI.',
509+
'Real searchGitHub/readGitHub adapters over gh-authenticated GitHub API; independent oracle GETs and inclusive native date candidates. Does not exercise application half-open date filtering, model query selection, application authorization, or UI.',
471510
checks,
472511
queries,
473512
requests,

0 commit comments

Comments
 (0)