fix(spiral-db): add test suite and fix critical bugs

Add comprehensive test suite (174 tests) covering encoding, schema,
image, database CRUD, and PNG round-trip. Fix critical bugs:

- PNG compression: replace non-functional zlibCompress with pako.deflate
- PNG import: add CRC validation, support all filter types (Sub/Up/Avg/Paeth)
- Input validation: validate records against schema before insert
- Index overflow: dynamic dataStartRing prevents index/data ring overlap
- Image expansion: expand before writes instead of after to prevent OOB
- update() read bug: search index from end to find latest entry, not deleted one
- String encoding: enforce 511-byte max length
- Index ring count: use 6 bits (2 pixels) instead of 3 bits for >7 ring support

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-03-23 09:52:18 +01:00
parent 3f5c17adbc
commit d4d08cc68b
9 changed files with 2227 additions and 163 deletions

View file

@ -185,6 +185,11 @@ export function decodeBool(stream: BitStream): boolean {
export function encodeString(stream: BitStream, value: string, compress = false): void {
const bytes = new TextEncoder().encode(value);
// 9-bit length field can hold max 511 bytes
if (bytes.length > 511) {
throw new Error(`String too long: ${bytes.length} bytes (max 511)`);
}
if (compress && bytes.length > 20) {
const compressed = pako.deflate(bytes);
if (compressed.length < bytes.length) {