Skip to content

Fix test-unit.c so the C unit tests compile and pass#305

Open
stumpylog wants to merge 2 commits into
asg017:mainfrom
stumpylog:fix/test-unit-compile
Open

Fix test-unit.c so the C unit tests compile and pass#305
stumpylog wants to merge 2 commits into
asg017:mainfrom
stumpylog:fix/test-unit-compile

Conversation

@stumpylog

Copy link
Copy Markdown

tests/test-unit.c hasn't compiled since the IVF/DiskANN commits, and no CI job builds it, so it rotted unnoticed. Three defects:

  • Structural: the IVF commit's hunks were anchored at the wrong offsets, splicing test functions into other functions' bodies, with mismatched #if/#endif and an unterminated #ifdef in main().
  • Link: the tests gate IVF on SQLITE_VEC_ENABLE_IVF but the implementation uses SQLITE_VEC_EXPERIMENTAL_IVF_ENABLE, so the ivf_* symbols don't link.
  • ABI drift: the struct mirror in sqlite-vec-internal.h was missing Vec0RescoreConfig.oversample_search, shifting ivf/diskann by 4 bytes so the DiskANN parse tests read the wrong fields.

Fix: regroup the tests into whole functions under correct guards, sync the struct mirror and default the flags to match sqlite-vec.c, align the IVF guard, rewrite the stale int8 quantizer assertions, and add the missing test-unit make prerequisites.

make test-unit passes, and the suite compiles, links, and passes across the flag matrix (defaults, RESCORE, RESCORE+DISKANN, RESCORE+DISKANN+IVF, all-off).

Feature functions were spliced into other functions' bodies by mis-anchored
IVF/DiskANN hunks, with mismatched #if/#endif guards and an unterminated
#ifdef in main(). Regroup each test back into a whole function under the
correct feature guard, restoring the rescore tests from their last-clean
revision and reassembling the IVF/DiskANN tests.

Also align the IVF test guard (SQLITE_VEC_ENABLE_IVF) with the implementation
flag (SQLITE_VEC_EXPERIMENTAL_IVF_ENABLE) so the binary links, and add the
sqlite-vec.h / $(prefix) prerequisites to the test-unit target.

Compiles and links across the flag matrix. The suite does not yet pass at
runtime: the rescore int8 assertions are stale (separate pre-existing bug).
…tions

The test's hand-maintained struct mirror in sqlite-vec-internal.h had drifted
from sqlite-vec.c: Vec0RescoreConfig was missing the oversample_search field
(8 vs 12 bytes), shifting ivf/diskann by 4 bytes so the diskann parse tests
read the wrong fields. The header also didn't default RESCORE/DISKANN on (the
extension does), so a no-flag build disagreed on struct sizes and smashed the
stack. Sync the mirror, default the flags to match sqlite-vec.c, drop a
duplicated rescore definition, and switch the feature guards from #ifdef to
#if so explicit -DFLAG=0 builds stay consistent.

Rewrite test_rescore_quantize_float_to_int8 against the actual quantizer (a
fixed [-1,1] -> [-128,127] mapping); the old assertions expected a
range-normalizing quantizer that no longer exists.

All unit tests pass across the flag matrix (defaults, RESCORE,
RESCORE+DISKANN, RESCORE+DISKANN+IVF, and explicit all-off).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant