Skip to content

Add missing tests for KVIndex/randomts; fix three silent bugs#19

Merged
Hexagon merged 2 commits intomainfrom
copilot/add-missing-tests-and-fix-issues
Feb 20, 2026
Merged

Add missing tests for KVIndex/randomts; fix three silent bugs#19
Hexagon merged 2 commits intomainfrom
copilot/add-missing-tests-and-fix-issues

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 20, 2026

Two source modules (KVIndex, pseudoRandomTimestamp) had no dedicated tests. While adding coverage, three bugs were found and fixed.

Bug fixes

  • transaction.ts — SET validation never fired
    create() checked this.operation === KVOperation.SET but this.operation is undefined until after that line. The guard was effectively dead code.

    // before — always false, guard never triggered
    if (this.operation === KVOperation.SET && value === undefined) 
    // after
    if (operation === KVOperation.SET && value === undefined) 
  • ledger.ts vacuum — missing await on readHeader()
    The comment read "update the header to catch new transactions" but the call was fire-and-forget, so the updated offset was never applied within the loop.

  • ledger.ts lock — module-level LOCKED_BYTES constant mutated on every acquisition
    const lockBytes = LOCKED_BYTES + setBigUint64 wrote the lock-ID into the shared constant's underlying buffer. Replaced with new Uint8Array(LOCKED_BYTES_LENGTH) per call; removed the now-unused import.

New tests

  • test/index.test.ts (22 tests) — KVIndex: add/get with sorting, limit, reverse, numeric & string ranges, empty ranges; delete including empty-parent cleanup and sibling preservation; clear; setIndex; getChildKeys.
  • test/randomts.test.ts (6 tests) — pseudoRandomTimestamp: return type, proximity to original value, non-determinism, custom numBits, zero input, upper-bit preservation.
  • test/transaction.test.ts — one test confirming the fixed SET/undefined guard now throws.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com>
Copilot AI changed the title [WIP] Add tests where missing and fix found issues Add missing tests for KVIndex/randomts; fix three silent bugs Feb 20, 2026
Copilot AI requested a review from Hexagon February 20, 2026 22:32
@Hexagon Hexagon marked this pull request as ready for review February 20, 2026 22:35
@Hexagon Hexagon merged commit 4b58a73 into main Feb 20, 2026
5 checks passed
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.

2 participants