Skip to content

Add tests for WasmDatabaseEngine.updateCellBatch#48

Closed
zknpr wants to merge 1 commit intomainfrom
wasm-db-engine-tests-16518766468019068459
Closed

Add tests for WasmDatabaseEngine.updateCellBatch#48
zknpr wants to merge 1 commit intomainfrom
wasm-db-engine-tests-16518766468019068459

Conversation

@zknpr
Copy link
Copy Markdown
Owner

@zknpr zknpr commented Feb 7, 2026

Added unit tests for WasmDatabaseEngine.updateCellBatch to verify batch update logic, including JSON patching and transaction atomicity. The tests ensure that multiple updates are applied correctly and that failures result in a clean rollback.


PR created automatically by Jules for task 16518766468019068459 started by @zknpr

Added comprehensive unit tests for `WasmDatabaseEngine.updateCellBatch` in `src/core/sqlite-db.ts`.
The tests cover:
- Standard batch updates for multiple rows and columns.
- JSON patch updates using RFC 7396 merge patch logic.
- Mixed updates combining standard value updates and JSON patches.
- Graceful handling of empty update arrays.
- Transaction atomicity ensuring that errors during a batch update trigger a rollback.

This improves test coverage for critical data modification logic and ensures reliability of batch operations.

Co-authored-by: zknpr <96851588+zknpr@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Feb 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sq-lite-explorer Ready Ready Preview, Comment Feb 7, 2026 1:52pm

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @zknpr, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new set of unit tests for the WasmDatabaseEngine's updateCellBatch method. The tests are designed to thoroughly verify the method's behavior across various update scenarios, including standard value changes, JSON patching, and combinations thereof. A key focus is on ensuring the transactional integrity of batch operations, particularly the correct rollback of changes when an error occurs during the update process.

Highlights

  • New Test Suite: A new unit test file tests/unit/sqlite_db.test.ts has been added to test the WasmDatabaseEngine.
  • Batch Update Verification: Comprehensive tests for WasmDatabaseEngine.updateCellBatch ensure correct handling of multiple cell updates in a single operation.
  • JSON Patching: Specific test cases validate the functionality of JSON patch updates within the batch update mechanism.
  • Transaction Atomicity: Tests confirm that updateCellBatch operations are atomic, with a focus on proper transaction rollback in case of errors.
  • Mixed Update Scenarios: The test suite includes scenarios for mixed standard and JSON patch updates, as well as graceful handling of empty update arrays.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • tests/unit/sqlite_db.test.ts
    • Added a new test file to house unit tests for the WasmDatabaseEngine.
    • Implemented tests for updateCellBatch covering batch updates for multiple cells, JSON patch updates for data columns, mixed standard and JSON patch updates, graceful handling of empty update arrays, and transaction rollback upon encountering an invalid update.
Activity
  • The pull request was automatically generated by Jules for a task initiated by @zknpr.
  • This is the initial submission, and no further review comments or discussions have occurred yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a good set of unit tests for WasmDatabaseEngine.updateCellBatch, covering important scenarios like batch updates, JSON patching, and transactional integrity. The tests are well-structured and improve coverage for the database engine. I've provided a few suggestions to enhance the tests by making them more robust, readable, and aligned with modern testing practices.

@@ -0,0 +1,121 @@

import { describe, it, before, after } from 'node:test';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The after function is imported but not used within this test suite. To maintain code cleanliness and avoid confusion, it's best to remove unused imports.

Suggested change
import { describe, it, before, after } from 'node:test';
import { describe, it, before } from 'node:test';


await engine.updateCellBatch('users', updates);

const result = await engine.executeQuery("SELECT * FROM users ORDER BY id");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using SELECT * can lead to brittle tests because the order of columns is not guaranteed. If the table schema changes, tests that rely on column indices can fail in non-obvious ways. It's better to explicitly select the columns you need for your assertions. This makes the test more robust and self-documenting.

Suggested change
const result = await engine.executeQuery("SELECT * FROM users ORDER BY id");
const result = await engine.executeQuery("SELECT id, name, age FROM users ORDER BY id");

Comment on lines +96 to +97
await engine.updateCellBatch('users', []);
assert.ok(true);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The assertion assert.ok(true) only confirms that the function didn't throw an error, which is a weak test. A more robust test would verify that the database state remains unchanged after calling updateCellBatch with an empty array. You could insert a known row, call the function, and then query that row to ensure its data has not been modified.

Suggested change
await engine.updateCellBatch('users', []);
assert.ok(true);
await engine.executeQuery("DELETE FROM users");
await engine.insertRow('users', { id: 1, name: 'NoOp', age: 99, data: '{}' });
await engine.updateCellBatch('users', []);
const result = await engine.executeQuery("SELECT name, age FROM users WHERE id = 1");
const row = result[0].rows[0];
assert.strictEqual(row[0], 'NoOp');
assert.strictEqual(row[1], 99);

Comment on lines +110 to +115
try {
await engine.updateCellBatch('users', updates);
assert.fail('Should have thrown an error');
} catch (e) {
assert.ok(e);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Instead of a try/catch block with assert.fail, you can use assert.rejects for a more concise and readable way to test for expected promise rejections. This is the modern standard for testing async errors in node:test and allows for more specific error validation, such as matching the error message.

        await assert.rejects(
            engine.updateCellBatch('users', updates),
            /no such column: non_existent_column/i,
            'Should have thrown an error for invalid column'
        );

@zknpr
Copy link
Copy Markdown
Owner Author

zknpr commented Feb 7, 2026

Merged as part of v1.3.0 release in PR #65

@zknpr zknpr closed this Feb 7, 2026
@google-labs-jules
Copy link
Copy Markdown
Contributor

Merged as part of v1.3.0 release in PR #65

Acknowledged. I am glad to hear that this has been merged as part of release v1.3.0.

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