Skip to content

Conversation

@findolor
Copy link
Collaborator

@findolor findolor commented Sep 18, 2025

fix #16

Summary

  • add a new FLOAT_ZERO_HEX SQLite scalar function that surfaces the canonical zero rain-math float hex string
  • register the function alongside other custom database functions and add a wasm test to ensure the default hex matches parsing zero
  • create Vitest coverage that exercises the new function end-to-end and update database cleanup helpers for the new table

Testing

  • cargo check -p sqlite-web-core --target wasm32-unknown-unknown (fails: local rain-math-float source path missing)
  • npm install (fails: repository requires Node.js >= 22 for @rainlanguage/float)

https://chatgpt.com/codex/tasks/task_e_68cbb532e16883338defbbf23f7c753b

Summary by CodeRabbit

  • New Features

    • Added FLOAT_ZERO_HEX() (arity 0) SQLite function returning the canonical zero value as a hex string; usable in queries, storage, aggregation, and as a column default.
  • Tests

    • Added tests for registration, repeated calls, canonical-zero retrieval, storage/aggregation with FLOAT_SUM, hex↔decimal conversions, and default-value usage.
  • Chores

    • Test DB cleanup now drops float_zero_usage and float_zero_defaults tables.
    • Updated test dependency to a new package snapshot.

@coderabbitai
Copy link

coderabbitai bot commented Sep 18, 2025

Walkthrough

Adds a new zero-value float scalar function FLOAT_ZERO_HEX (arity 0) in sqlite-web-core, registers it during function setup, includes tests verifying its hex and aggregation/default-behavior, and updates test cleanup and test dependency references.

Changes

Cohort / File(s) Summary
SQLite function implementation
packages/sqlite-web-core/src/database_functions/float_zero_hex.rs
Adds sqlite_transient() and pub(crate) unsafe extern "C" fn float_zero_hex(...) that validates zero args, computes Float::default().as_hex(), and returns the hex via sqlite3_result_text with a transient destructor; reports misuse via sqlite3_result_error/sqlite3_result_error_code.
Function registration
packages/sqlite-web-core/src/database_functions/mod.rs
Adds mod float_zero_hex; and use float_zero_hex::*; and registers FLOAT_ZERO_HEX (arity 0) in register_custom_functions via sqlite3_create_function_v2 (SQLITE_UTF8
Tests for FLOAT_ZERO_HEX
svelte-test/tests/database-functions/float-zero-hex.test.ts
New test suite exercising FLOAT_ZERO_HEX() and interaction with FLOAT_SUM, verifying canonical zero hex, hex→decimal round-trips, repeated invocations, and using FLOAT_ZERO_HEX() as a column default; uses per-test DB setup/teardown.
Test fixtures cleanup
svelte-test/tests/fixtures/test-helpers.ts
Adds float_zero_usage and float_zero_defaults to the list of tables dropped in cleanupDatabase.
Test dependency bump
svelte-test/package.json
Updates @rainlanguage/sqlite-web dependency from file:../pkg/rainlanguage-sqlite-web-0.0.1-alpha.1.tgz to file:../pkg/rainlanguage-sqlite-web-0.0.1-alpha.3.tgz.
Non-functional
pkg/package.json
Only EOF/newline status change; no content modification.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor TestRunner as Test Runner
  participant JS as Test JS
  participant Core as sqlite-web-core
  participant SQLite as SQLite Engine

  TestRunner->>JS: run test calling FLOAT_ZERO_HEX()
  JS->>Core: ensure custom functions registered
  Core->>SQLite: sqlite3_create_function_v2("FLOAT_ZERO_HEX", arity=0, cb=float_zero_hex)
  SQLite-->>Core: registration OK

  TestRunner->>SQLite: SELECT FLOAT_ZERO_HEX();
  SQLite->>Core: invoke float_zero_hex(context, argc=0, argv)
  Core->>Core: compute Float::default().as_hex()
  Core->>SQLite: sqlite3_result_text(hex_ptr, len, sqlite_transient())
  SQLite-->>TestRunner: returns hex string
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • hardyjosh
  • 0xgleb

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Add FLOAT_ZERO_HEX database function and tests" is a concise, single-sentence summary that directly reflects the primary change introduced by the PR. It names the new SQLite scalar function and explicitly notes the accompanying tests without extraneous detail. A reviewer scanning history will understand the main purpose from this title.
Linked Issues Check ✅ Passed The PR fulfills the linked issue's core coding objectives [#16] by adding a database-accessible function that returns the canonical zero Float hex (FLOAT_ZERO_HEX), registering that function with SQLite, and providing end-to-end tests that validate the canonical hex, its decoding to zero, aggregation behavior, and use as a default value. The implemented code (float_zero_hex.rs, registration in register_custom_functions, and the wasm/Vitest tests) directly prevents consumers from hard-coding hex values and exposes the runtime-derived canonical zero hex. The PR uses the explicit name FLOAT_ZERO_HEX (rather than FLOAT_ZERO) but this is a semantic naming choice and does not materially deviate from the issue intent.
Out of Scope Changes Check ✅ Passed The changes are scoped to implementing FLOAT_ZERO_HEX and its tests plus small test-helper updates; these map to the stated objectives. The remaining diffs are a test dependency tarball bump in svelte-test and an EOF newline change in pkg/package.json, which appear to be build/test housekeeping rather than unrelated feature work. I did not find modifications that add unrelated functionality or change public APIs outside the PR goals.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/add-database-function-for-zero-float

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c0ca462 and 18203be.

⛔ Files ignored due to path filters (1)
  • svelte-test/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • svelte-test/tests/fixtures/test-helpers.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: findolor
PR: rainlanguage/sqlite-web#14
File: svelte-test/tests/database-functions/float-is-zero.test.ts:60-90
Timestamp: 2025-09-19T07:06:37.278Z
Learning: For floating-point database functions in the rainlanguage/sqlite-web codebase, negative zero handling is not required and doesn't need to be tested.
Learnt from: CR
PR: rainlanguage/sqlite-web#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T06:55:20.178Z
Learning: Applies to packages/sqlite-web-core/src/database_functions.rs : Integrate and expose rain.math.float-backed custom database functions for SQLite queries
Learnt from: findolor
PR: rainlanguage/sqlite-web#5
File: packages/sqlite-web-core/src/database_functions/bigint_sum.rs:76-93
Timestamp: 2025-08-27T05:55:40.481Z
Learning: In the sqlite-web-core codebase, for SQLite aggregate function context initialization, the maintainer prefers using byte-scanning to detect zero-initialized memory rather than using explicit initialization flags or Option wrappers.
📚 Learning: 2025-09-17T08:04:44.062Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#6
File: svelte-test/tests/database-functions/float-sum.test.ts:78-86
Timestamp: 2025-09-17T08:04:44.062Z
Learning: In svelte-test/tests/database-functions/float-sum.test.ts, the schema defines `amount TEXT NOT NULL` but the NULL value handling tests attempt to insert NULL values, creating a constraint violation that prevents the tests from passing.

Applied to files:

  • svelte-test/tests/fixtures/test-helpers.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test
  • GitHub Check: test
🔇 Additional comments (1)
svelte-test/tests/fixtures/test-helpers.ts (1)

191-192: Tables verified — names match tests.

Both float_zero_usage and float_zero_defaults are created in svelte-test/tests/database-functions/float-zero-hex.test.ts (CREATE TABLE at lines 36 and 86) and are listed in svelte-test/tests/fixtures/test-helpers.ts:191 — no singular/plural mismatch found.


Comment @coderabbitai help to get the list of available commands and usage tips.

@findolor findolor marked this pull request as ready for review September 18, 2025 08:01
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cec3e27 and cfe4b3c.

⛔ Files ignored due to path filters (1)
  • svelte-test/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • packages/sqlite-web-core/src/database_functions/float_zero_hex.rs (1 hunks)
  • packages/sqlite-web-core/src/database_functions/mod.rs (2 hunks)
  • svelte-test/tests/database-functions/float-zero-hex.test.ts (1 hunks)
  • svelte-test/tests/fixtures/test-helpers.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (8)
📓 Common learnings
Learnt from: CR
PR: rainlanguage/sqlite-web#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T06:55:20.178Z
Learning: Applies to packages/sqlite-web-core/src/database_functions.rs : Integrate and expose rain.math.float-backed custom database functions for SQLite queries
Learnt from: findolor
PR: rainlanguage/sqlite-web#5
File: packages/sqlite-web-core/src/database_functions/bigint_sum.rs:76-93
Timestamp: 2025-08-27T05:55:40.481Z
Learning: In the sqlite-web-core codebase, for SQLite aggregate function context initialization, the maintainer prefers using byte-scanning to detect zero-initialized memory rather than using explicit initialization flags or Option wrappers.
Learnt from: findolor
PR: rainlanguage/sqlite-web#6
File: svelte-test/tests/database-functions/float-sum.test.ts:78-86
Timestamp: 2025-09-17T08:04:44.062Z
Learning: In svelte-test/tests/database-functions/float-sum.test.ts, the schema defines `amount TEXT NOT NULL` but the NULL value handling tests attempt to insert NULL values, creating a constraint violation that prevents the tests from passing.
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:64-72
Timestamp: 2025-09-17T17:09:58.740Z
Learning: FLOAT_SUM functionality is available and working in the codebase, so tests can rely on it without needing availability checks or gating logic.
📚 Learning: 2025-09-17T08:04:44.062Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#6
File: svelte-test/tests/database-functions/float-sum.test.ts:78-86
Timestamp: 2025-09-17T08:04:44.062Z
Learning: In svelte-test/tests/database-functions/float-sum.test.ts, the schema defines `amount TEXT NOT NULL` but the NULL value handling tests attempt to insert NULL values, creating a constraint violation that prevents the tests from passing.

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
  • svelte-test/tests/fixtures/test-helpers.ts
📚 Learning: 2025-09-17T17:17:41.827Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:105-119
Timestamp: 2025-09-17T17:17:41.827Z
Learning: The toMixedCase function in svelte-test/tests/fixtures/float-utils.ts only modifies [a-f] characters, preserving the 'x' in '0x' prefixes, so it won't create conflicts with tests that reject '0X' prefixes.

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
📚 Learning: 2025-09-17T17:17:41.827Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:105-119
Timestamp: 2025-09-17T17:17:41.827Z
Learning: The toMixedCase function in svelte-test/tests/fixtures/float-utils.ts only modifies characters matching /[a-f]/ (hex digits a-f), preserving the 'x' in '0x' prefixes and all other characters unchanged, so it won't create conflicts with tests that reject '0X' prefixes.

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
📚 Learning: 2025-09-17T06:55:20.178Z
Learnt from: CR
PR: rainlanguage/sqlite-web#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T06:55:20.178Z
Learning: Applies to packages/sqlite-web-core/src/database_functions.rs : Integrate and expose rain.math.float-backed custom database functions for SQLite queries

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
  • packages/sqlite-web-core/src/database_functions/mod.rs
  • packages/sqlite-web-core/src/database_functions/float_zero_hex.rs
📚 Learning: 2025-09-17T17:09:58.740Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:64-72
Timestamp: 2025-09-17T17:09:58.740Z
Learning: FLOAT_SUM functionality is available and working in the codebase, so tests can rely on it without needing availability checks or gating logic.

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
📚 Learning: 2025-08-27T05:55:40.481Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#5
File: packages/sqlite-web-core/src/database_functions/bigint_sum.rs:76-93
Timestamp: 2025-08-27T05:55:40.481Z
Learning: In the sqlite-web-core codebase, for SQLite aggregate function context initialization, the maintainer prefers using byte-scanning to detect zero-initialized memory rather than using explicit initialization flags or Option wrappers.

Applied to files:

  • packages/sqlite-web-core/src/database_functions/mod.rs
  • packages/sqlite-web-core/src/database_functions/float_zero_hex.rs
📚 Learning: 2025-09-17T18:08:06.145Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: packages/sqlite-web-core/src/database_functions/float_negate.rs:16-17
Timestamp: 2025-09-17T18:08:06.145Z
Learning: The rain-math-float Float type implements arithmetic operations (including unary negation with the - operator) to return Result types rather than direct values, requiring .map_err(...)? for error handling of potential mathematical errors like overflow or underflow.

Applied to files:

  • packages/sqlite-web-core/src/database_functions/mod.rs
🧬 Code graph analysis (2)
svelte-test/tests/database-functions/float-zero-hex.test.ts (1)
svelte-test/tests/fixtures/test-helpers.ts (2)
  • createTestDatabase (6-22)
  • cleanupDatabase (173-202)
packages/sqlite-web-core/src/database_functions/mod.rs (1)
packages/sqlite-web-core/src/database_functions/float_zero_hex.rs (2)
  • float_zero_hex (4-37)
  • std (32-35)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test
  • GitHub Check: test
🔇 Additional comments (4)
packages/sqlite-web-core/src/database_functions/float_zero_hex.rs (1)

9-16: Good arity guard and clear error.

The argc check with a static C string error is correct and consistent with other functions.

packages/sqlite-web-core/src/database_functions/mod.rs (2)

12-18: Module wiring looks correct.

mod float_zero_hex; and use float_zero_hex::*; integrate the new scalar into the existing registry cleanly.


83-101: Mark FLOAT_ZERO_HEX as SQLITE_DETERMINISTIC (and SQLITE_INNOCUOUS if available) — verify binding exposure

Repo search returned no matches for SQLITE_DETERMINISTIC/SQLITE_INNOCUOUS; confirm your SQLite bindings (or C headers) expose these constants. If available, register the scalar with those flags (file: packages/sqlite-web-core/src/database_functions/mod.rs, ~lines 83–101).

-            0, // 0 arguments
-            SQLITE_UTF8,
+            0, // 0 arguments
+            SQLITE_UTF8
+                | SQLITE_DETERMINISTIC
+                | SQLITE_INNOCUOUS,
             std::ptr::null_mut(),
             Some(float_zero_hex), // Scalar function

If SQLITE_INNOCUOUS isn't available, at minimum add SQLITE_DETERMINISTIC.

svelte-test/tests/database-functions/float-zero-hex.test.ts (1)

31-51: Solid end‑to‑end happy‑path coverage.

The canonical zero hex assertion and decoding back to "0" exercise both DB and library layers.

Comment on lines 28 to 36
sqlite3_result_text(
context,
zero_cstring.as_ptr(),
zero_cstring.as_bytes().len() as c_int,
Some(std::mem::transmute::<
isize,
unsafe extern "C" fn(*mut std::ffi::c_void),
>(-1isize)),
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick

🧩 Analysis chain

Use a safe/centralized SQLITE_TRANSIENT helper instead of transmute.

std::mem::transmute::<isize, extern "C" fn(*mut c_void)>(-1) works but is fragile across targets. If sqlite_wasm_rs::export exposes SQLITE_TRANSIENT (or you can add a small helper), prefer that for clarity and safety.

Proposed change (keeping the same behavior but clearer):

-        zero_cstring.as_ptr(),
-        zero_cstring.as_bytes().len() as c_int,
-        Some(std::mem::transmute::<
-            isize,
-            unsafe extern "C" fn(*mut std::ffi::c_void),
-        >(-1isize)),
+        zero_hex.as_ptr() as *const c_char,
+        zero_hex.len() as c_int,
+        SQLITE_TRANSIENT, // or a crate-local helper wrapping the -1 cast

To check availability of flags/helpers across the codebase:


🏁 Script executed:

#!/bin/bash
rg -n "SQLITE_TRANSIENT|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS|transmute::<\s*isize" -C2 --type=rust

Length of output: 1358


Centralize SQLITE_TRANSIENT and replace unsafe transmute(-1isize)

Add a crate-local SQLITE_TRANSIENT helper (an Option<unsafe extern "C" fn(*mut std::ffi::c_void)> wrapper for the SQLite transient destructor) and replace every occurrence of:
transmute::<isize, unsafe extern "C" fn(*mut std::ffi::c_void)>(-1isize)
with that helper for portability and clarity.

Files to update:

  • packages/sqlite-web-core/src/database_functions/float_zero_hex.rs:28-36
  • packages/sqlite-web-core/src/database_functions/bigint_sum.rs:149-151
  • packages/sqlite-web-core/src/database_functions/rain_math.rs:97-99
  • packages/sqlite-web-core/src/database_functions/float_sum.rs:143-145
🤖 Prompt for AI Agents
In packages/sqlite-web-core/src/database_functions/float_zero_hex.rs around
lines 28-36, create a crate-local SQLITE_TRANSIENT helper (type Option<unsafe
extern "C" fn(*mut std::ffi::c_void)>) and use it instead of the current unsafe
transmute::<isize, unsafe extern "C" fn(*mut std::ffi::c_void)>(-1isize); update
this file and likewise replace the transmute occurrence in
packages/sqlite-web-core/src/database_functions/bigint_sum.rs (around lines
149-151), packages/sqlite-web-core/src/database_functions/rain_math.rs (around
lines 97-99), and packages/sqlite-web-core/src/database_functions/float_sum.rs
(around lines 143-145) so each sqlite3_result_text/related call passes the new
SQLITE_TRANSIENT helper for clarity and portability.

Comment on lines +53 to +85
it("should integrate with queries storing and aggregating zero floats", async () => {
await db.query(`
CREATE TABLE float_zero_usage (
id INTEGER PRIMARY KEY AUTOINCREMENT,
amount TEXT NOT NULL
)
`);

await db.query(
"INSERT INTO float_zero_usage (amount) VALUES (FLOAT_ZERO_HEX())",
);
await db.query(
"INSERT INTO float_zero_usage (amount) VALUES (FLOAT_ZERO_HEX())",
);

const stored = await db.query(
"SELECT amount FROM float_zero_usage ORDER BY id",
);
const storedData = JSON.parse(stored.value || "[]");
expect(storedData).toHaveLength(2);
for (const row of storedData) {
expect(row.amount).toBe(canonicalZeroHex);
expect(decodeFloatHex(row.amount)).toBe("0");
}

const sumResult = await db.query(
"SELECT FLOAT_SUM(amount) as total FROM float_zero_usage",
);
const sumData = JSON.parse(sumResult.value || "[]");
expect(sumData).toHaveLength(1);
expect(sumData[0].total).toBe(canonicalZeroHex);
expect(decodeFloatHex(sumData[0].total)).toBe("0");
});
Copy link

@coderabbitai coderabbitai bot Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick

Add a negative test for arity enforcement.

Cover the error path by passing an argument to FLOAT_ZERO_HEX and asserting an error. This guards against accidental signature changes.

   it("should integrate with queries storing and aggregating zero floats", async () => {
     …
   });
+
+  it("should error when called with arguments", async () => {
+    const res = await db.query('SELECT FLOAT_ZERO_HEX(1) AS z');
+    const rows = JSON.parse(res.value || "[]");
+    // Expect no row or an error message depending on driver behavior; most wrappers return an error object.
+    // If your wrapper surfaces errors via result.error, assert that instead:
+    expect(res.error).toBeTruthy();
+  });

If the WASM wrapper surfaces SQL errors differently, adjust the assertion accordingly.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it("should integrate with queries storing and aggregating zero floats", async () => {
await db.query(`
CREATE TABLE float_zero_usage (
id INTEGER PRIMARY KEY AUTOINCREMENT,
amount TEXT NOT NULL
)
`);
await db.query(
"INSERT INTO float_zero_usage (amount) VALUES (FLOAT_ZERO_HEX())",
);
await db.query(
"INSERT INTO float_zero_usage (amount) VALUES (FLOAT_ZERO_HEX())",
);
const stored = await db.query(
"SELECT amount FROM float_zero_usage ORDER BY id",
);
const storedData = JSON.parse(stored.value || "[]");
expect(storedData).toHaveLength(2);
for (const row of storedData) {
expect(row.amount).toBe(canonicalZeroHex);
expect(decodeFloatHex(row.amount)).toBe("0");
}
const sumResult = await db.query(
"SELECT FLOAT_SUM(amount) as total FROM float_zero_usage",
);
const sumData = JSON.parse(sumResult.value || "[]");
expect(sumData).toHaveLength(1);
expect(sumData[0].total).toBe(canonicalZeroHex);
expect(decodeFloatHex(sumData[0].total)).toBe("0");
});
it("should integrate with queries storing and aggregating zero floats", async () => {
await db.query(`
CREATE TABLE float_zero_usage (
id INTEGER PRIMARY KEY AUTOINCREMENT,
amount TEXT NOT NULL
)
`);
await db.query(
"INSERT INTO float_zero_usage (amount) VALUES (FLOAT_ZERO_HEX())",
);
await db.query(
"INSERT INTO float_zero_usage (amount) VALUES (FLOAT_ZERO_HEX())",
);
const stored = await db.query(
"SELECT amount FROM float_zero_usage ORDER BY id",
);
const storedData = JSON.parse(stored.value || "[]");
expect(storedData).toHaveLength(2);
for (const row of storedData) {
expect(row.amount).toBe(canonicalZeroHex);
expect(decodeFloatHex(row.amount)).toBe("0");
}
const sumResult = await db.query(
"SELECT FLOAT_SUM(amount) as total FROM float_zero_usage",
);
const sumData = JSON.parse(sumResult.value || "[]");
expect(sumData).toHaveLength(1);
expect(sumData[0].total).toBe(canonicalZeroHex);
expect(decodeFloatHex(sumData[0].total)).toBe("0");
});
it("should error when called with arguments", async () => {
const res = await db.query('SELECT FLOAT_ZERO_HEX(1) AS z');
const rows = JSON.parse(res.value || "[]");
// Expect no row or an error message depending on driver behavior; most wrappers return an error object.
// If your wrapper surfaces errors via result.error, assert that instead:
expect(res.error).toBeTruthy();
});

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed. we don't have any arguments so it's a noop

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@findolor I understand your perspective. You're right that the function is designed to take zero arguments, so testing the error path isn't essential for the core functionality. I'll respect your decision to keep the test suite focused on the primary use cases.


🧠 Learnings used
Learnt from: findolor
PR: rainlanguage/sqlite-web#6
File: svelte-test/tests/database-functions/float-sum.test.ts:78-86
Timestamp: 2025-09-17T08:04:44.062Z
Learning: In svelte-test/tests/database-functions/float-sum.test.ts, the schema defines `amount TEXT NOT NULL` but the NULL value handling tests attempt to insert NULL values, creating a constraint violation that prevents the tests from passing.

Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:105-119
Timestamp: 2025-09-17T17:17:41.827Z
Learning: The toMixedCase function in svelte-test/tests/fixtures/float-utils.ts only modifies characters matching /[a-f]/ (hex digits a-f), preserving the 'x' in '0x' prefixes and all other characters unchanged, so it won't create conflicts with tests that reject '0X' prefixes.

Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:105-119
Timestamp: 2025-09-17T17:17:41.827Z
Learning: The toMixedCase function in svelte-test/tests/fixtures/float-utils.ts only modifies [a-f] characters, preserving the 'x' in '0x' prefixes, so it won't create conflicts with tests that reject '0X' prefixes.

Learnt from: CR
PR: rainlanguage/sqlite-web#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T06:55:20.178Z
Learning: Applies to packages/sqlite-web-core/src/database_functions.rs : Integrate and expose rain.math.float-backed custom database functions for SQLite queries

Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:64-72
Timestamp: 2025-09-17T17:09:58.740Z
Learning: FLOAT_SUM functionality is available and working in the codebase, so tests can rely on it without needing availability checks or gating logic.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have error coverage since we don't get this from the compiler

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

♻️ Duplicate comments (2)
packages/sqlite-web-core/src/database_functions/float_zero_hex.rs (2)

3-9: Centralized SQLITE_TRANSIENT helper — good; please apply repo‑wide.

This avoids fragile transmute usage at each call site. Recommend replacing remaining occurrences across the crate to use this helper.

Run to find remaining sites to update:

#!/bin/bash
rg -n --type=rust -C2 -e 'transmute::<\s*isize[^>]*>\s*\(-1isize\)' -e 'sqlite3_result_text\([^,]+,[^,]+,[^,]+,\s*None\)' -e 'SQLITE_TRANSIENT'

26-31: LGTM: no CString, correct TRANSIENT usage.

Passing ptr+len with SQLITE_TRANSIENT is the right pattern here and resolves earlier nitpicks.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cfe4b3c and ad05a44.

⛔ Files ignored due to path filters (1)
  • svelte-test/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • packages/sqlite-web-core/src/database_functions/float_zero_hex.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: CR
PR: rainlanguage/sqlite-web#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T06:55:20.178Z
Learning: Applies to packages/sqlite-web-core/src/database_functions.rs : Integrate and expose rain.math.float-backed custom database functions for SQLite queries
Learnt from: findolor
PR: rainlanguage/sqlite-web#5
File: packages/sqlite-web-core/src/database_functions/bigint_sum.rs:76-93
Timestamp: 2025-08-27T05:55:40.481Z
Learning: In the sqlite-web-core codebase, for SQLite aggregate function context initialization, the maintainer prefers using byte-scanning to detect zero-initialized memory rather than using explicit initialization flags or Option wrappers.
Learnt from: findolor
PR: rainlanguage/sqlite-web#6
File: svelte-test/tests/database-functions/float-sum.test.ts:78-86
Timestamp: 2025-09-17T08:04:44.062Z
Learning: In svelte-test/tests/database-functions/float-sum.test.ts, the schema defines `amount TEXT NOT NULL` but the NULL value handling tests attempt to insert NULL values, creating a constraint violation that prevents the tests from passing.
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:64-72
Timestamp: 2025-09-17T17:09:58.740Z
Learning: FLOAT_SUM functionality is available and working in the codebase, so tests can rely on it without needing availability checks or gating logic.
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:105-119
Timestamp: 2025-09-17T17:17:41.827Z
Learning: The toMixedCase function in svelte-test/tests/fixtures/float-utils.ts only modifies characters matching /[a-f]/ (hex digits a-f), preserving the 'x' in '0x' prefixes and all other characters unchanged, so it won't create conflicts with tests that reject '0X' prefixes.
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:105-119
Timestamp: 2025-09-17T17:17:41.827Z
Learning: The toMixedCase function in svelte-test/tests/fixtures/float-utils.ts only modifies [a-f] characters, preserving the 'x' in '0x' prefixes, so it won't create conflicts with tests that reject '0X' prefixes.
📚 Learning: 2025-09-17T06:55:20.178Z
Learnt from: CR
PR: rainlanguage/sqlite-web#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T06:55:20.178Z
Learning: Applies to packages/sqlite-web-core/src/database_functions.rs : Integrate and expose rain.math.float-backed custom database functions for SQLite queries

Applied to files:

  • packages/sqlite-web-core/src/database_functions/float_zero_hex.rs
📚 Learning: 2025-08-27T05:55:40.481Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#5
File: packages/sqlite-web-core/src/database_functions/bigint_sum.rs:76-93
Timestamp: 2025-08-27T05:55:40.481Z
Learning: In the sqlite-web-core codebase, for SQLite aggregate function context initialization, the maintainer prefers using byte-scanning to detect zero-initialized memory rather than using explicit initialization flags or Option wrappers.

Applied to files:

  • packages/sqlite-web-core/src/database_functions/float_zero_hex.rs
📚 Learning: 2025-09-17T06:55:20.178Z
Learnt from: CR
PR: rainlanguage/sqlite-web#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T06:55:20.178Z
Learning: Applies to packages/sqlite-web/worker_template.rs : Ensure the worker JavaScript generated by worker_template.rs embeds the WASM (base64) and does not fetch external WASM files

Applied to files:

  • packages/sqlite-web-core/src/database_functions/float_zero_hex.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test
  • GitHub Check: test

Comment on lines +11 to +16
/// Scalar SQLite function that returns the canonical zero Float as a hex string.
pub(crate) unsafe extern "C" fn float_zero_hex(
context: *mut sqlite3_context,
argc: c_int,
_argv: *mut *mut sqlite3_value,
) {
Copy link

@coderabbitai coderabbitai bot Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick

Document FFI safety invariants.

Brief “Safety” notes help maintainers keep this unsafe extern "C" sound when edited later.

-/// Scalar SQLite function that returns the canonical zero Float as a hex string.
+/// Scalar SQLite function that returns the canonical zero Float as a hex string.
+///
+/// Safety:
+/// - Called by SQLite with a valid `context`.
+/// - `argc` must be 0; `_argv` may be null and is ignored.
+/// - Result uses SQLITE_TRANSIENT so no lifetime ties to Rust memory.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/// Scalar SQLite function that returns the canonical zero Float as a hex string.
pub(crate) unsafe extern "C" fn float_zero_hex(
context: *mut sqlite3_context,
argc: c_int,
_argv: *mut *mut sqlite3_value,
) {
/// Scalar SQLite function that returns the canonical zero Float as a hex string.
///
/// Safety:
/// - Called by SQLite with a valid `context`.
/// - `argc` must be 0; `_argv` may be null and is ignored.
/// - Result uses SQLITE_TRANSIENT so no lifetime ties to Rust memory.
pub(crate) unsafe extern "C" fn float_zero_hex(
context: *mut sqlite3_context,
argc: c_int,
_argv: *mut *mut sqlite3_value,
) {
🤖 Prompt for AI Agents
In packages/sqlite-web-core/src/database_functions/float_zero_hex.rs around
lines 11 to 16, the unsafe extern "C" function is missing FFI safety
documentation; add a brief doc comment block labeled "Safety" immediately above
the function that enumerates the invariants callers and maintainers must uphold
(e.g., that context is non-null and points to a valid sqlite3_context, argc has
the expected value, _argv may be null and must not be dereferenced, the function
must not panic across the FFI boundary, must only call async-unsafe or
reentrant-safe code, and must preserve ABI and threading expectations of
SQLite), and include any notes about required casting, lifetime assumptions, and
expectations about error reporting so future edits keep the function sound.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@findolor Understood, I'll skip the FFI safety documentation suggestion. Thanks for the clarification!

  /|   /|   
 ( ._. )
o_(")(")

🧠 Learnings used
Learnt from: CR
PR: rainlanguage/sqlite-web#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T06:55:20.178Z
Learning: Applies to packages/sqlite-web-core/src/database_functions.rs : Integrate and expose rain.math.float-backed custom database functions for SQLite queries

Learnt from: findolor
PR: rainlanguage/sqlite-web#5
File: packages/sqlite-web-core/src/database_functions/bigint_sum.rs:76-93
Timestamp: 2025-08-27T05:55:40.481Z
Learning: In the sqlite-web-core codebase, for SQLite aggregate function context initialization, the maintainer prefers using byte-scanning to detect zero-initialized memory rather than using explicit initialization flags or Option wrappers.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (2)
packages/sqlite-web-core/src/database_functions/mod.rs (1)

83-101: Registration flags and arity are correct.

Deterministic + innocuous on a 0‑arity scalar is appropriate; error handling mirrors existing patterns.

packages/sqlite-web-core/src/database_functions/float_zero_hex.rs (1)

17-25: Good arity check with explicit errcode.

Clear message plus SQLITE_MISUSE tagging.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ad05a44 and e058502.

⛔ Files ignored due to path filters (1)
  • svelte-test/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • packages/sqlite-web-core/src/database_functions/float_zero_hex.rs (1 hunks)
  • packages/sqlite-web-core/src/database_functions/mod.rs (2 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: CR
PR: rainlanguage/sqlite-web#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T06:55:20.178Z
Learning: Applies to packages/sqlite-web-core/src/database_functions.rs : Integrate and expose rain.math.float-backed custom database functions for SQLite queries
Learnt from: findolor
PR: rainlanguage/sqlite-web#5
File: packages/sqlite-web-core/src/database_functions/bigint_sum.rs:76-93
Timestamp: 2025-08-27T05:55:40.481Z
Learning: In the sqlite-web-core codebase, for SQLite aggregate function context initialization, the maintainer prefers using byte-scanning to detect zero-initialized memory rather than using explicit initialization flags or Option wrappers.
Learnt from: findolor
PR: rainlanguage/sqlite-web#6
File: svelte-test/tests/database-functions/float-sum.test.ts:78-86
Timestamp: 2025-09-17T08:04:44.062Z
Learning: In svelte-test/tests/database-functions/float-sum.test.ts, the schema defines `amount TEXT NOT NULL` but the NULL value handling tests attempt to insert NULL values, creating a constraint violation that prevents the tests from passing.
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:64-72
Timestamp: 2025-09-17T17:09:58.740Z
Learning: FLOAT_SUM functionality is available and working in the codebase, so tests can rely on it without needing availability checks or gating logic.
📚 Learning: 2025-09-17T06:55:20.178Z
Learnt from: CR
PR: rainlanguage/sqlite-web#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T06:55:20.178Z
Learning: Applies to packages/sqlite-web-core/src/database_functions.rs : Integrate and expose rain.math.float-backed custom database functions for SQLite queries

Applied to files:

  • packages/sqlite-web-core/src/database_functions/mod.rs
  • packages/sqlite-web-core/src/database_functions/float_zero_hex.rs
📚 Learning: 2025-08-27T05:55:40.481Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#5
File: packages/sqlite-web-core/src/database_functions/bigint_sum.rs:76-93
Timestamp: 2025-08-27T05:55:40.481Z
Learning: In the sqlite-web-core codebase, for SQLite aggregate function context initialization, the maintainer prefers using byte-scanning to detect zero-initialized memory rather than using explicit initialization flags or Option wrappers.

Applied to files:

  • packages/sqlite-web-core/src/database_functions/mod.rs
  • packages/sqlite-web-core/src/database_functions/float_zero_hex.rs
📚 Learning: 2025-09-17T18:08:06.145Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: packages/sqlite-web-core/src/database_functions/float_negate.rs:16-17
Timestamp: 2025-09-17T18:08:06.145Z
Learning: The rain-math-float Float type implements arithmetic operations (including unary negation with the - operator) to return Result types rather than direct values, requiring .map_err(...)? for error handling of potential mathematical errors like overflow or underflow.

Applied to files:

  • packages/sqlite-web-core/src/database_functions/mod.rs
📚 Learning: 2025-09-17T06:55:20.178Z
Learnt from: CR
PR: rainlanguage/sqlite-web#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T06:55:20.178Z
Learning: Applies to packages/sqlite-web/worker_template.rs : Ensure the worker JavaScript generated by worker_template.rs embeds the WASM (base64) and does not fetch external WASM files

Applied to files:

  • packages/sqlite-web-core/src/database_functions/float_zero_hex.rs
🧬 Code graph analysis (1)
packages/sqlite-web-core/src/database_functions/mod.rs (1)
packages/sqlite-web-core/src/database_functions/float_zero_hex.rs (1)
  • float_zero_hex (12-32)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test
  • GitHub Check: test
🔇 Additional comments (2)
packages/sqlite-web-core/src/database_functions/mod.rs (1)

12-12: Module wiring LGTM.

New module and import are correct and scoped appropriately.

Also applies to: 17-17

packages/sqlite-web-core/src/database_functions/float_zero_hex.rs (1)

3-9: Centralize SQLITE_TRANSIENT helper

Move sqlite_transient() into a single shared helper (e.g. packages/sqlite-web-core/src/database_functions/mod.rs) and reuse to avoid duplication and drift.

Apply in this file:

- pub(crate) fn sqlite_transient() -> Option<unsafe extern "C" fn(*mut std::ffi::c_void)> {
-     // SQLite uses the value -1 cast to a function pointer as a sentinel meaning
-     // "make your own copy" for the result buffer (a.k.a. SQLITE_TRANSIENT).
-     Some(unsafe {
-         std::mem::transmute::<isize, unsafe extern "C" fn(*mut std::ffi::c_void)>(-1isize)
-     })
- }

Then add once in packages/sqlite-web-core/src/database_functions/mod.rs:

// Shared helper for SQLITE_TRANSIENT sentinel
pub(crate) fn sqlite_transient() -> Option<unsafe extern "C" fn(*mut std::ffi::c_void)> {
    Some(unsafe {
        std::mem::transmute::<isize, unsafe extern "C" fn(*mut std::ffi::c_void)>(-1isize)
    })
}

Run a repo search to find remaining occurrences (example):
rg -n --hidden -S '-1isize|sqlite_transient|transmute::<isize' || true

@0xgleb 0xgleb requested review from 0xgleb and hardyjosh September 18, 2025 16:31
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add some tests to this module?

Comment on lines +53 to +85
it("should integrate with queries storing and aggregating zero floats", async () => {
await db.query(`
CREATE TABLE float_zero_usage (
id INTEGER PRIMARY KEY AUTOINCREMENT,
amount TEXT NOT NULL
)
`);

await db.query(
"INSERT INTO float_zero_usage (amount) VALUES (FLOAT_ZERO_HEX())",
);
await db.query(
"INSERT INTO float_zero_usage (amount) VALUES (FLOAT_ZERO_HEX())",
);

const stored = await db.query(
"SELECT amount FROM float_zero_usage ORDER BY id",
);
const storedData = JSON.parse(stored.value || "[]");
expect(storedData).toHaveLength(2);
for (const row of storedData) {
expect(row.amount).toBe(canonicalZeroHex);
expect(decodeFloatHex(row.amount)).toBe("0");
}

const sumResult = await db.query(
"SELECT FLOAT_SUM(amount) as total FROM float_zero_usage",
);
const sumData = JSON.parse(sumResult.value || "[]");
expect(sumData).toHaveLength(1);
expect(sumData[0].total).toBe(canonicalZeroHex);
expect(decodeFloatHex(sumData[0].total)).toBe("0");
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have error coverage since we don't get this from the compiler

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
svelte-test/tests/fixtures/test-helpers.ts (1)

191-192: Table added for cleanup tracking.

Adding 'float_zero_usage' to the cleanup table list ensures proper test isolation for the new FLOAT_ZERO_HEX function tests.

Note: The indentation inconsistency was already flagged in past reviews and is being addressed in a separate PR.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e058502 and fb66731.

⛔ Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • svelte-test/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • packages/sqlite-web-core/src/database_functions/mod.rs (2 hunks)
  • pkg/package.json (1 hunks)
  • svelte-test/package.json (1 hunks)
  • svelte-test/tests/database-functions/float-zero-hex.test.ts (1 hunks)
  • svelte-test/tests/fixtures/test-helpers.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
svelte-test/package.json

📄 CodeRabbit inference engine (CLAUDE.md)

In the Svelte test app, depend on the sqlite-web package via the locally packed tarball produced by npm pack

Files:

  • svelte-test/package.json
🧠 Learnings (11)
📓 Common learnings
Learnt from: findolor
PR: rainlanguage/sqlite-web#14
File: svelte-test/tests/database-functions/float-is-zero.test.ts:60-90
Timestamp: 2025-09-19T07:06:37.278Z
Learning: For floating-point database functions in the rainlanguage/sqlite-web codebase, negative zero handling is not required and doesn't need to be tested.
Learnt from: CR
PR: rainlanguage/sqlite-web#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T06:55:20.178Z
Learning: Applies to packages/sqlite-web-core/src/database_functions.rs : Integrate and expose rain.math.float-backed custom database functions for SQLite queries
Learnt from: findolor
PR: rainlanguage/sqlite-web#5
File: packages/sqlite-web-core/src/database_functions/bigint_sum.rs:76-93
Timestamp: 2025-08-27T05:55:40.481Z
Learning: In the sqlite-web-core codebase, for SQLite aggregate function context initialization, the maintainer prefers using byte-scanning to detect zero-initialized memory rather than using explicit initialization flags or Option wrappers.
Learnt from: findolor
PR: rainlanguage/sqlite-web#6
File: svelte-test/tests/database-functions/float-sum.test.ts:78-86
Timestamp: 2025-09-17T08:04:44.062Z
Learning: In svelte-test/tests/database-functions/float-sum.test.ts, the schema defines `amount TEXT NOT NULL` but the NULL value handling tests attempt to insert NULL values, creating a constraint violation that prevents the tests from passing.
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:64-72
Timestamp: 2025-09-17T17:09:58.740Z
Learning: FLOAT_SUM functionality is available and working in the codebase, so tests can rely on it without needing availability checks or gating logic.
📚 Learning: 2025-09-17T08:04:44.062Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#6
File: svelte-test/tests/database-functions/float-sum.test.ts:78-86
Timestamp: 2025-09-17T08:04:44.062Z
Learning: In svelte-test/tests/database-functions/float-sum.test.ts, the schema defines `amount TEXT NOT NULL` but the NULL value handling tests attempt to insert NULL values, creating a constraint violation that prevents the tests from passing.

Applied to files:

  • svelte-test/tests/fixtures/test-helpers.ts
  • svelte-test/tests/database-functions/float-zero-hex.test.ts
📚 Learning: 2025-09-17T06:55:20.178Z
Learnt from: CR
PR: rainlanguage/sqlite-web#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T06:55:20.178Z
Learning: Applies to svelte-test/package.json : In the Svelte test app, depend on the sqlite-web package via the locally packed tarball produced by npm pack

Applied to files:

  • svelte-test/package.json
📚 Learning: 2025-09-17T17:17:41.827Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:105-119
Timestamp: 2025-09-17T17:17:41.827Z
Learning: The toMixedCase function in svelte-test/tests/fixtures/float-utils.ts only modifies characters matching /[a-f]/ (hex digits a-f), preserving the 'x' in '0x' prefixes and all other characters unchanged, so it won't create conflicts with tests that reject '0X' prefixes.

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
📚 Learning: 2025-09-17T17:17:41.827Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:105-119
Timestamp: 2025-09-17T17:17:41.827Z
Learning: The toMixedCase function in svelte-test/tests/fixtures/float-utils.ts only modifies [a-f] characters, preserving the 'x' in '0x' prefixes, so it won't create conflicts with tests that reject '0X' prefixes.

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
📚 Learning: 2025-09-19T07:06:37.278Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#14
File: svelte-test/tests/database-functions/float-is-zero.test.ts:60-90
Timestamp: 2025-09-19T07:06:37.278Z
Learning: For floating-point database functions in the rainlanguage/sqlite-web codebase, negative zero handling is not required and doesn't need to be tested.

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
📚 Learning: 2025-09-17T06:55:20.178Z
Learnt from: CR
PR: rainlanguage/sqlite-web#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T06:55:20.178Z
Learning: Applies to packages/sqlite-web-core/src/database_functions.rs : Integrate and expose rain.math.float-backed custom database functions for SQLite queries

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
  • packages/sqlite-web-core/src/database_functions/mod.rs
📚 Learning: 2025-09-17T17:09:58.740Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:64-72
Timestamp: 2025-09-17T17:09:58.740Z
Learning: FLOAT_SUM functionality is available and working in the codebase, so tests can rely on it without needing availability checks or gating logic.

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
📚 Learning: 2025-09-19T07:06:20.147Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#14
File: svelte-test/tests/database-functions/float-is-zero.test.ts:39-57
Timestamp: 2025-09-19T07:06:20.147Z
Learning: PRAGMA function_list is not available in the WASM SQLite test environment used by svelte-test, so availability testing should rely on direct function calls rather than PRAGMA queries.

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
📚 Learning: 2025-08-27T05:55:40.481Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#5
File: packages/sqlite-web-core/src/database_functions/bigint_sum.rs:76-93
Timestamp: 2025-08-27T05:55:40.481Z
Learning: In the sqlite-web-core codebase, for SQLite aggregate function context initialization, the maintainer prefers using byte-scanning to detect zero-initialized memory rather than using explicit initialization flags or Option wrappers.

Applied to files:

  • packages/sqlite-web-core/src/database_functions/mod.rs
📚 Learning: 2025-09-17T18:08:06.145Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: packages/sqlite-web-core/src/database_functions/float_negate.rs:16-17
Timestamp: 2025-09-17T18:08:06.145Z
Learning: The rain-math-float Float type implements arithmetic operations (including unary negation with the - operator) to return Result types rather than direct values, requiring .map_err(...)? for error handling of potential mathematical errors like overflow or underflow.

Applied to files:

  • packages/sqlite-web-core/src/database_functions/mod.rs
🧬 Code graph analysis (2)
svelte-test/tests/database-functions/float-zero-hex.test.ts (2)
svelte-test/tests/fixtures/float-utils.ts (2)
  • decodeFloatHex (20-31)
  • encodeFloatHex (5-11)
svelte-test/tests/fixtures/test-helpers.ts (2)
  • createTestDatabase (6-22)
  • cleanupDatabase (173-203)
packages/sqlite-web-core/src/database_functions/mod.rs (1)
packages/sqlite-web-core/src/database_functions/float_zero_hex.rs (2)
  • float_zero_hex (12-32)
  • std (7-7)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test
  • GitHub Check: test
🔇 Additional comments (6)
pkg/package.json (1)

15-15: LGTM!

No functional changes to this package manifest. The version and dependencies remain unchanged.

svelte-test/package.json (1)

44-44: Dependency update aligns with PR changes.

The update from alpha.1 to alpha.3 tarball correctly reflects the new version containing the FLOAT_ZERO_HEX functionality. This follows the coding guideline for using locally packed tarballs.

svelte-test/tests/database-functions/float-zero-hex.test.ts (2)

43-51: LGTM!

The test correctly validates that FLOAT_ZERO_HEX() returns the canonical zero hex value and that it decodes to "0". The approach is thorough and follows existing test patterns in the codebase.


53-85: Comprehensive integration test.

This test effectively validates the complete workflow: function registration, data insertion, storage verification, and aggregation with FLOAT_SUM. The test properly ensures that multiple zero values sum to zero, confirming both individual function behavior and interaction with existing aggregate functions.

packages/sqlite-web-core/src/database_functions/mod.rs (2)

13-13: Module integration follows established patterns.

The addition of the float_zero_hex module and its imports follows the same pattern as existing function modules in the codebase.

Also applies to: 19-19


85-103: Function registration is correctly configured.

The SQLITE_DETERMINISTIC flag is appropriate since FLOAT_ZERO_HEX() always returns the same canonical zero hex value regardless of when called. The SQLITE_INNOCUOUS flag is correctly applied since the function has no side effects and only returns a deterministic constant value. The zero-argument arity and scalar function configuration match the intended functionality.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
svelte-test/tests/database-functions/float-zero-hex.test.ts (1)

7-8: Deduplicate helpers: import from fixtures and drop local encode/decode + Float import

Reuse the shared utilities to avoid divergence and to benefit from ensurePrefixedHex and consistent error handling.

-import { Float } from "@rainlanguage/float";
+import { encodeFloatHex, decodeFloatHex } from "../fixtures/float-utils.js";
-function decodeFloatHex(hex: string): string {
-  const floatRes = Float.fromHex(hex as `0x${string}`);
-  if (floatRes.error) {
-    throw new Error(`fromHex failed: ${String(floatRes.error)}`);
-  }
-  const fmtRes = floatRes.value.format();
-  if (fmtRes.error) {
-    throw new Error(`format failed: ${String(fmtRes.error)}`);
-  }
-  return fmtRes.value as string;
-}
-
-function encodeFloatHex(decimal: string): `0x${string}` {
-  const parseRes = Float.parse(decimal);
-  if (parseRes.error) {
-    throw new Error(
-      `Float.parse failed: ${String(parseRes.error.msg ?? parseRes.error)}`,
-    );
-  }
-  return parseRes.value.asHex();
-}
+// Use encodeFloatHex/decodeFloatHex from fixtures instead of redefining locally.

Also applies to: 9-29

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb66731 and b7e2259.

📒 Files selected for processing (1)
  • svelte-test/tests/database-functions/float-zero-hex.test.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: findolor
PR: rainlanguage/sqlite-web#14
File: svelte-test/tests/database-functions/float-is-zero.test.ts:60-90
Timestamp: 2025-09-19T07:06:37.278Z
Learning: For floating-point database functions in the rainlanguage/sqlite-web codebase, negative zero handling is not required and doesn't need to be tested.
Learnt from: CR
PR: rainlanguage/sqlite-web#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T06:55:20.178Z
Learning: Applies to packages/sqlite-web-core/src/database_functions.rs : Integrate and expose rain.math.float-backed custom database functions for SQLite queries
Learnt from: findolor
PR: rainlanguage/sqlite-web#5
File: packages/sqlite-web-core/src/database_functions/bigint_sum.rs:76-93
Timestamp: 2025-08-27T05:55:40.481Z
Learning: In the sqlite-web-core codebase, for SQLite aggregate function context initialization, the maintainer prefers using byte-scanning to detect zero-initialized memory rather than using explicit initialization flags or Option wrappers.
Learnt from: findolor
PR: rainlanguage/sqlite-web#6
File: svelte-test/tests/database-functions/float-sum.test.ts:78-86
Timestamp: 2025-09-17T08:04:44.062Z
Learning: In svelte-test/tests/database-functions/float-sum.test.ts, the schema defines `amount TEXT NOT NULL` but the NULL value handling tests attempt to insert NULL values, creating a constraint violation that prevents the tests from passing.
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:64-72
Timestamp: 2025-09-17T17:09:58.740Z
Learning: FLOAT_SUM functionality is available and working in the codebase, so tests can rely on it without needing availability checks or gating logic.
📚 Learning: 2025-09-17T08:04:44.062Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#6
File: svelte-test/tests/database-functions/float-sum.test.ts:78-86
Timestamp: 2025-09-17T08:04:44.062Z
Learning: In svelte-test/tests/database-functions/float-sum.test.ts, the schema defines `amount TEXT NOT NULL` but the NULL value handling tests attempt to insert NULL values, creating a constraint violation that prevents the tests from passing.

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
📚 Learning: 2025-09-17T17:17:41.827Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:105-119
Timestamp: 2025-09-17T17:17:41.827Z
Learning: The toMixedCase function in svelte-test/tests/fixtures/float-utils.ts only modifies characters matching /[a-f]/ (hex digits a-f), preserving the 'x' in '0x' prefixes and all other characters unchanged, so it won't create conflicts with tests that reject '0X' prefixes.

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
📚 Learning: 2025-09-17T17:17:41.827Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:105-119
Timestamp: 2025-09-17T17:17:41.827Z
Learning: The toMixedCase function in svelte-test/tests/fixtures/float-utils.ts only modifies [a-f] characters, preserving the 'x' in '0x' prefixes, so it won't create conflicts with tests that reject '0X' prefixes.

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
📚 Learning: 2025-09-19T07:06:37.278Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#14
File: svelte-test/tests/database-functions/float-is-zero.test.ts:60-90
Timestamp: 2025-09-19T07:06:37.278Z
Learning: For floating-point database functions in the rainlanguage/sqlite-web codebase, negative zero handling is not required and doesn't need to be tested.

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
📚 Learning: 2025-09-17T06:55:20.178Z
Learnt from: CR
PR: rainlanguage/sqlite-web#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T06:55:20.178Z
Learning: Applies to packages/sqlite-web-core/src/database_functions.rs : Integrate and expose rain.math.float-backed custom database functions for SQLite queries

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
📚 Learning: 2025-09-17T17:09:58.740Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:64-72
Timestamp: 2025-09-17T17:09:58.740Z
Learning: FLOAT_SUM functionality is available and working in the codebase, so tests can rely on it without needing availability checks or gating logic.

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
🧬 Code graph analysis (1)
svelte-test/tests/database-functions/float-zero-hex.test.ts (2)
svelte-test/tests/fixtures/float-utils.ts (2)
  • decodeFloatHex (20-31)
  • encodeFloatHex (5-11)
svelte-test/tests/fixtures/test-helpers.ts (2)
  • createTestDatabase (6-22)
  • cleanupDatabase (173-203)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test
  • GitHub Check: test
🔇 Additional comments (3)
svelte-test/tests/database-functions/float-zero-hex.test.ts (3)

31-35: LGTM: canonical reference derived via encodeFloatHex("0")

Good invariant: comparing FLOAT_ZERO_HEX() to the canonical zero hex computed via the same Float lib.


53-85: LGTM: integration tests (storage, aggregation, defaults) are solid

Covers storage, FLOAT_SUM aggregation, and DEFAULT usage paths for the new scalar function.

Also applies to: 103-126


1-8: CI/runtime: confirm Node ≥ 22 and declare engines.node

Current Node: v24.3.0 (satisfies ≥22). pkg/package.json and svelte-test/package.json have no engines.node — add "engines": { "node": ">=22" } or align your CI matrix to that minimum to avoid install/runtime failures for @rainlanguage/float.

Comment on lines +44 to +51
const result = await db.query("SELECT FLOAT_ZERO_HEX() as zero_hex");
const data = JSON.parse(result.value || "[]");
expect(data).toHaveLength(1);
expect(data[0].zero_hex).toBe(canonicalZeroHex);

const decimal = decodeFloatHex(data[0].zero_hex);
expect(decimal).toBe("0");
});
Copy link

@coderabbitai coderabbitai bot Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick

Assert query success before parsing JSON

Guard against silent failures by asserting no error prior to JSON.parse; replicate for other queries in this file.

-    const result = await db.query("SELECT FLOAT_ZERO_HEX() as zero_hex");
-    const data = JSON.parse(result.value || "[]");
+    const result = await db.query("SELECT FLOAT_ZERO_HEX() as zero_hex");
+    expect(result.error).toBeFalsy();
+    const data = JSON.parse(result.value || "[]");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const result = await db.query("SELECT FLOAT_ZERO_HEX() as zero_hex");
const data = JSON.parse(result.value || "[]");
expect(data).toHaveLength(1);
expect(data[0].zero_hex).toBe(canonicalZeroHex);
const decimal = decodeFloatHex(data[0].zero_hex);
expect(decimal).toBe("0");
});
const result = await db.query("SELECT FLOAT_ZERO_HEX() as zero_hex");
expect(result.error).toBeFalsy();
const data = JSON.parse(result.value || "[]");
expect(data).toHaveLength(1);
expect(data[0].zero_hex).toBe(canonicalZeroHex);
const decimal = decodeFloatHex(data[0].zero_hex);
expect(decimal).toBe("0");
});
🤖 Prompt for AI Agents
In svelte-test/tests/database-functions/float-zero-hex.test.ts around lines 44
to 51, the test parses result.value without first asserting the query succeeded;
update the test to assert the query succeeded before JSON.parse (e.g.,
expect(result.error).toBeFalsy() or expect(result.ok).toBeTrue() or at minimum
expect(result.value).toBeDefined()), then parse result.value and continue
existing assertions; apply the same guard (assert no error / value defined) to
all other query usages in this file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to do this

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@findolor Understood, I'll skip that suggestion. Thanks for the clarification!


🧠 Learnings used
Learnt from: findolor
PR: rainlanguage/sqlite-web#14
File: svelte-test/tests/database-functions/float-is-zero.test.ts:60-90
Timestamp: 2025-09-19T07:06:37.278Z
Learning: For floating-point database functions in the rainlanguage/sqlite-web codebase, negative zero handling is not required and doesn't need to be tested.

Learnt from: findolor
PR: rainlanguage/sqlite-web#6
File: svelte-test/tests/database-functions/float-sum.test.ts:78-86
Timestamp: 2025-09-17T08:04:44.062Z
Learning: In svelte-test/tests/database-functions/float-sum.test.ts, the schema defines `amount TEXT NOT NULL` but the NULL value handling tests attempt to insert NULL values, creating a constraint violation that prevents the tests from passing.

Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:105-119
Timestamp: 2025-09-17T17:17:41.827Z
Learning: The toMixedCase function in svelte-test/tests/fixtures/float-utils.ts only modifies characters matching /[a-f]/ (hex digits a-f), preserving the 'x' in '0x' prefixes and all other characters unchanged, so it won't create conflicts with tests that reject '0X' prefixes.

Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:105-119
Timestamp: 2025-09-17T17:17:41.827Z
Learning: The toMixedCase function in svelte-test/tests/fixtures/float-utils.ts only modifies [a-f] characters, preserving the 'x' in '0x' prefixes, so it won't create conflicts with tests that reject '0X' prefixes.

Learnt from: CR
PR: rainlanguage/sqlite-web#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T06:55:20.178Z
Learning: Applies to packages/sqlite-web-core/src/database_functions.rs : Integrate and expose rain.math.float-backed custom database functions for SQLite queries

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (2)
svelte-test/tests/database-functions/float-zero-hex.test.ts (2)

20-22: Ensure cleanup drops float_zero_defaults to prevent cross-test leaks.

cleanupDatabase currently doesn’t drop the float_zero_defaults table created in this file. This can cause CREATE TABLE failures in subsequent tests if DBs are reused.

Apply in svelte-test/tests/fixtures/test-helpers.ts:

-      'bigint_test', 'categories', 'float_test', 'float_categories', 'float_zero_usage'
+      'bigint_test', 'categories', 'float_test', 'float_categories', 'float_zero_usage', 'float_zero_defaults'

35-41: Check DDL/INSERT results to surface unexpected failures early.

Assert no error on CREATE TABLE and INSERT statements.

Examples:

-    await db.query(`
+    const createUsageRes = await db.query(`
       CREATE TABLE float_zero_usage (
         id INTEGER PRIMARY KEY AUTOINCREMENT,
         amount TEXT NOT NULL
       )
     `);
+    expect(createUsageRes.error).toBeFalsy();
-    await db.query(
-      "INSERT INTO float_zero_usage (amount) VALUES (FLOAT_ZERO_HEX())",
-    );
+    const ins1 = await db.query(
+      "INSERT INTO float_zero_usage (amount) VALUES (FLOAT_ZERO_HEX())",
+    );
+    expect(ins1.error).toBeFalsy();
-    await db.query(`
+    const createDefaultsRes = await db.query(`
       CREATE TABLE float_zero_defaults (
         id INTEGER PRIMARY KEY AUTOINCREMENT,
         amount TEXT NOT NULL DEFAULT (FLOAT_ZERO_HEX())
       )
     `);
+    expect(createDefaultsRes.error).toBeFalsy();
-    await db.query("INSERT INTO float_zero_defaults DEFAULT VALUES");
+    const insDefault = await db.query("INSERT INTO float_zero_defaults DEFAULT VALUES");
+    expect(insDefault.error).toBeFalsy();

Also applies to: 42-47, 85-91, 92-95

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b7e2259 and c0ca462.

📒 Files selected for processing (1)
  • svelte-test/tests/database-functions/float-zero-hex.test.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (8)
📓 Common learnings
Learnt from: findolor
PR: rainlanguage/sqlite-web#14
File: svelte-test/tests/database-functions/float-is-zero.test.ts:60-90
Timestamp: 2025-09-19T07:06:37.278Z
Learning: For floating-point database functions in the rainlanguage/sqlite-web codebase, negative zero handling is not required and doesn't need to be tested.
Learnt from: CR
PR: rainlanguage/sqlite-web#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T06:55:20.178Z
Learning: Applies to packages/sqlite-web-core/src/database_functions.rs : Integrate and expose rain.math.float-backed custom database functions for SQLite queries
Learnt from: findolor
PR: rainlanguage/sqlite-web#5
File: packages/sqlite-web-core/src/database_functions/bigint_sum.rs:76-93
Timestamp: 2025-08-27T05:55:40.481Z
Learning: In the sqlite-web-core codebase, for SQLite aggregate function context initialization, the maintainer prefers using byte-scanning to detect zero-initialized memory rather than using explicit initialization flags or Option wrappers.
📚 Learning: 2025-09-17T08:04:44.062Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#6
File: svelte-test/tests/database-functions/float-sum.test.ts:78-86
Timestamp: 2025-09-17T08:04:44.062Z
Learning: In svelte-test/tests/database-functions/float-sum.test.ts, the schema defines `amount TEXT NOT NULL` but the NULL value handling tests attempt to insert NULL values, creating a constraint violation that prevents the tests from passing.

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
📚 Learning: 2025-09-17T17:17:41.827Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:105-119
Timestamp: 2025-09-17T17:17:41.827Z
Learning: The toMixedCase function in svelte-test/tests/fixtures/float-utils.ts only modifies characters matching /[a-f]/ (hex digits a-f), preserving the 'x' in '0x' prefixes and all other characters unchanged, so it won't create conflicts with tests that reject '0X' prefixes.

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
📚 Learning: 2025-09-17T17:17:41.827Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:105-119
Timestamp: 2025-09-17T17:17:41.827Z
Learning: The toMixedCase function in svelte-test/tests/fixtures/float-utils.ts only modifies [a-f] characters, preserving the 'x' in '0x' prefixes, so it won't create conflicts with tests that reject '0X' prefixes.

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
📚 Learning: 2025-09-19T07:06:37.278Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#14
File: svelte-test/tests/database-functions/float-is-zero.test.ts:60-90
Timestamp: 2025-09-19T07:06:37.278Z
Learning: For floating-point database functions in the rainlanguage/sqlite-web codebase, negative zero handling is not required and doesn't need to be tested.

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
📚 Learning: 2025-09-17T06:55:20.178Z
Learnt from: CR
PR: rainlanguage/sqlite-web#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T06:55:20.178Z
Learning: Applies to packages/sqlite-web-core/src/database_functions.rs : Integrate and expose rain.math.float-backed custom database functions for SQLite queries

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
📚 Learning: 2025-09-17T17:09:58.740Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:64-72
Timestamp: 2025-09-17T17:09:58.740Z
Learning: FLOAT_SUM functionality is available and working in the codebase, so tests can rely on it without needing availability checks or gating logic.

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
📚 Learning: 2025-09-19T07:06:20.147Z
Learnt from: findolor
PR: rainlanguage/sqlite-web#14
File: svelte-test/tests/database-functions/float-is-zero.test.ts:39-57
Timestamp: 2025-09-19T07:06:20.147Z
Learning: PRAGMA function_list is not available in the WASM SQLite test environment used by svelte-test, so availability testing should rely on direct function calls rather than PRAGMA queries.

Applied to files:

  • svelte-test/tests/database-functions/float-zero-hex.test.ts
🧬 Code graph analysis (1)
svelte-test/tests/database-functions/float-zero-hex.test.ts (2)
svelte-test/tests/fixtures/float-utils.ts (2)
  • encodeFloatHex (5-11)
  • decodeFloatHex (20-31)
svelte-test/tests/fixtures/test-helpers.ts (2)
  • createTestDatabase (6-22)
  • cleanupDatabase (173-203)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test
  • GitHub Check: test
🔇 Additional comments (1)
svelte-test/tests/database-functions/float-zero-hex.test.ts (1)

8-10: Good reuse of shared float utilities.

Importing decodeFloatHex/encodeFloatHex from fixtures avoids duplication and keeps behavior consistent across tests.

Comment on lines +25 to +31
const result = await db.query("SELECT FLOAT_ZERO_HEX() as zero_hex");
const data = JSON.parse(result.value || "[]");
expect(data).toHaveLength(1);
expect(data[0].zero_hex).toBe(canonicalZeroHex);

const decimal = decodeFloatHex(data[0].zero_hex);
expect(decimal).toBe("0");
Copy link

@coderabbitai coderabbitai bot Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick

Assert query success before JSON.parse to avoid masking failures.

Parse only after confirming no error and that value is present.

Example for the first query (replicate for the other SELECTs in this file):

-    const result = await db.query("SELECT FLOAT_ZERO_HEX() as zero_hex");
-    const data = JSON.parse(result.value || "[]");
+    const result = await db.query("SELECT FLOAT_ZERO_HEX() as zero_hex");
+    expect(result.error).toBeFalsy();
+    expect(result.value).toBeTruthy();
+    const data = JSON.parse(result.value!);

And for a later SELECT:

-    const stored = await db.query(
-      "SELECT amount FROM float_zero_usage ORDER BY id",
-    );
-    const storedData = JSON.parse(stored.value || "[]");
+    const stored = await db.query(
+      "SELECT amount FROM float_zero_usage ORDER BY id",
+    );
+    expect(stored.error).toBeFalsy();
+    const storedData = JSON.parse(stored.value!);

Also applies to: 49-53, 59-65, 68-73, 97-101

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@findolor Understood, I'll skip this suggestion. Your current approach with result.value || "[]" works fine for your testing needs.


🧠 Learnings used
Learnt from: findolor
PR: rainlanguage/sqlite-web#14
File: svelte-test/tests/database-functions/float-is-zero.test.ts:60-90
Timestamp: 2025-09-19T07:06:37.278Z
Learning: For floating-point database functions in the rainlanguage/sqlite-web codebase, negative zero handling is not required and doesn't need to be tested.

Learnt from: findolor
PR: rainlanguage/sqlite-web#6
File: svelte-test/tests/database-functions/float-sum.test.ts:78-86
Timestamp: 2025-09-17T08:04:44.062Z
Learning: In svelte-test/tests/database-functions/float-sum.test.ts, the schema defines `amount TEXT NOT NULL` but the NULL value handling tests attempt to insert NULL values, creating a constraint violation that prevents the tests from passing.

Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:105-119
Timestamp: 2025-09-17T17:17:41.827Z
Learning: The toMixedCase function in svelte-test/tests/fixtures/float-utils.ts only modifies characters matching /[a-f]/ (hex digits a-f), preserving the 'x' in '0x' prefixes and all other characters unchanged, so it won't create conflicts with tests that reject '0X' prefixes.

Learnt from: findolor
PR: rainlanguage/sqlite-web#11
File: svelte-test/tests/database-functions/float-negate.test.ts:105-119
Timestamp: 2025-09-17T17:17:41.827Z
Learning: The toMixedCase function in svelte-test/tests/fixtures/float-utils.ts only modifies [a-f] characters, preserving the 'x' in '0x' prefixes, so it won't create conflicts with tests that reject '0X' prefixes.

Learnt from: CR
PR: rainlanguage/sqlite-web#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-17T06:55:20.178Z
Learning: Applies to packages/sqlite-web-core/src/database_functions.rs : Integrate and expose rain.math.float-backed custom database functions for SQLite queries

Learnt from: findolor
PR: rainlanguage/sqlite-web#14
File: svelte-test/tests/database-functions/float-is-zero.test.ts:39-57
Timestamp: 2025-09-19T07:06:20.147Z
Learning: PRAGMA function_list is not available in the WASM SQLite test environment used by svelte-test, so availability testing should rely on direct function calls rather than PRAGMA queries.

@findolor findolor merged commit 967d6af into main Sep 22, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add FLOAT_ZERO database function to return a zero hex value

4 participants