Skip to content

Commit 8a46ec2

Browse files
committed
test(data,llm): pin error-graceful behavior on real data
TestSearchDocumentsBadSyntaxGraceful previously ran against an empty store, so it only proved that malformed inputs do not error -- a regression that broadened them into matching real terms would still pass. Insert a document whose tokens share no prefix with any test query so the no-match assertion is meaningful. TestIsNetworkError gains an explicit case asserting that a bare error whose message contains "connection refused" is NOT classified as a network error, pinning the new contract that only wrapped syscall sentinels qualify.
1 parent 7e56b31 commit 8a46ec2

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

internal/data/fts_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,23 @@ func TestSearchDocumentsUpdateReflected(t *testing.T) {
172172
}
173173

174174
// TestSearchDocumentsBadSyntaxGraceful verifies that inputs which would
175-
// be malformed FTS5 expressions if passed verbatim do not error out --
176-
// the phrase-wrap escape in prepareFTSQuery turns each token into a
177-
// quoted phrase, neutralizing the special characters.
175+
// be malformed FTS5 expressions if passed verbatim do not error out and
176+
// also do not accidentally match real documents. A document is inserted
177+
// so the no-match assertion is meaningful (an empty store would pass
178+
// even if the query rewrite broadened matches).
178179
func TestSearchDocumentsBadSyntaxGraceful(t *testing.T) {
179180
t.Parallel()
180181
store := newTestStore(t)
181182

183+
// Document content uses tokens that don't share any prefix with
184+
// the test queries below, so any spurious match indicates a bug
185+
// in the rewrite (e.g., a query collapsing to a bare wildcard).
186+
require.NoError(t, store.CreateDocument(&Document{
187+
Title: "Zebra",
188+
FileName: "z.pdf",
189+
ExtractedText: "rhinoceros giraffe leopard",
190+
}))
191+
182192
bad := []string{
183193
`"unclosed`,
184194
`unclosed"`,
@@ -189,7 +199,7 @@ func TestSearchDocumentsBadSyntaxGraceful(t *testing.T) {
189199
`***`,
190200
`:::`,
191201
`+++---`,
192-
`(a AND)`,
202+
`(b AND)`,
193203
}
194204
for _, q := range bad {
195205
t.Run(q, func(t *testing.T) {

internal/llm/client_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,15 @@ func TestIsNetworkError(t *testing.T) {
528528
},
529529
{"unrelated error", errors.New("something else broke"), false},
530530
{"context.Canceled", context.Canceled, false},
531+
// Pin the new contract: errors that contain "connection refused"
532+
// in their message but do NOT wrap a syscall sentinel are not
533+
// classified as network errors. The previous string-fallback
534+
// implementation matched these by substring.
535+
{
536+
"bare string says connection refused",
537+
errors.New("dial tcp: connection refused"),
538+
false,
539+
},
531540
}
532541
for _, tt := range cases {
533542
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)