Skip to content

Conversation

@sirtimid
Copy link
Contributor

@sirtimid sirtimid commented Feb 5, 2025

Closes: #343

This PR fixes the kvGet return as the issue was requesting, but also extracts the store initialization to a new package @ocap/store and now the two implementations for NodeJs and wasm use the shared statements.

@sirtimid sirtimid requested a review from a team as a code owner February 5, 2025 20:10
@sirtimid
Copy link
Contributor Author

sirtimid commented Feb 5, 2025

If you notice this change here I removed the ephemeral notion from the sqlite code, since we don't really want it to be ephemeral, even if it is currently, instead I assign the DB name of the Vats store to the vat id, which I am not so sure now since how do we know that the vats will retain their ids, anyhow, my change doesn't really change the outcome, that the DB will be ephemeral, but it is something to notice. I can revert to the previous functionality of course but I wanted to align both nodejs and wasm implementations. Perhaps if we require in memory DB somewhere explicitly we can add a new issue and this can be handled for both environments? @FUDCo @rekmarks

@grypez grypez self-requested a review February 5, 2025 20:31
@sirtimid sirtimid force-pushed the sirtimid/kvstore-kvget-improvement branch from 6f616bc to 4181a1d Compare February 5, 2025 21:00
grypez
grypez previously requested changes Feb 5, 2025
Copy link
Contributor

@grypez grypez left a comment

Choose a reason for hiding this comment

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

native.test.ts and wasm.test.ts still share a fair bit of code

Creating the KV table.
Retrieving a value by key.
Throwing an error when a key is not found.
Inserting or updating a value.
Deleting a key-value pair.
Clearing the table.
Executing arbitrary SQL queries.
Getting the next key in sequence.

The mocking differs, but the extent of overlap seems to justify injecting a shared test suite into both

@sirtimid
Copy link
Contributor Author

sirtimid commented Feb 5, 2025

native.test.ts and wasm.test.ts still share a fair bit of code

Creating the KV table. Retrieving a value by key. Throwing an error when a key is not found. Inserting or updating a value. Deleting a key-value pair. Clearing the table. Executing arbitrary SQL queries. Getting the next key in sequence.

The mocking differs, but the extent of overlap seems to justify injecting a shared test suite into both

Yeah ok, but these are tests not bundled code so imo there isn't much value in a shared test suite. As long as they actually test the functionality it's ok. I would like to keep the separation of concerns here.

@sirtimid sirtimid requested review from grypez and rekmarks February 5, 2025 23:09
@FUDCo
Copy link
Contributor

FUDCo commented Feb 5, 2025

If you notice this change here I removed the ephemeral notion from the sqlite code, since we don't really want it to be ephemeral, even if it is currently, instead I assign the DB name of the Vats store to the vat id, which I am not so sure now since how do we know that the vats will retain their ids, anyhow, my change doesn't really change the outcome, that the DB will be ephemeral, but it is something to notice. I can revert to the previous functionality of course but I wanted to align both nodejs and wasm implementations. Perhaps if we require in memory DB somewhere explicitly we can add a new issue and this can be handled for both environments? @FUDCo @rekmarks

If you deliberately want an ephemeral DB (not uncommon for unit tests, for example), I believe you can get this by specifying ':memory:' as the database file path (I know this is true with the better-sqlite3 package, anyway, and I think it's implemented that way by SQLite itself rather than the JS wrapper, so I suspect it should work regardless).

@sirtimid sirtimid force-pushed the sirtimid/kvstore-kvget-improvement branch from c1ae316 to bbf0a16 Compare February 6, 2025 14:56
@sirtimid sirtimid force-pushed the sirtimid/kvstore-kvget-improvement branch from 5878d14 to 7664c66 Compare February 6, 2025 15:37
@socket-security
Copy link

socket-security bot commented Feb 6, 2025

Updated and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@vitest/browser@3.0.5 🔁 npm/@vitest/browser@3.0.4 Transitive: filesystem, shell +40 11.1 MB vitestbot
npm/@vitest/coverage-istanbul@3.0.5 🔁 npm/@vitest/coverage-istanbul@3.0.4 None 0 13.9 kB vitestbot

View full report↗︎

Copy link
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

Looks good! Smol request: can we rename native to nodejs?

@grypez
Copy link
Contributor

grypez commented Feb 6, 2025

native.test.ts and wasm.test.ts still share a fair bit of code
Creating the KV table. Retrieving a value by key. Throwing an error when a key is not found. Inserting or updating a value. Deleting a key-value pair. Clearing the table. Executing arbitrary SQL queries. Getting the next key in sequence.
The mocking differs, but the extent of overlap seems to justify injecting a shared test suite into both

Yeah ok, but these are tests not bundled code so imo there isn't much value in a shared test suite. As long as they actually test the functionality it's ok. I would like to keep the separation of concerns here.

I think in these pieces we're testing that the implementations uphold the contract of the KVStore interface, and it makes sense to test that in a uniform way. But since we only have two implementations, I see the value of your preference here (mocking is complicated), so long as we can agree it's probably worth doing if ever (🤞 never) a third arises.

@grypez grypez removed their request for review February 6, 2025 18:32
@rekmarks rekmarks dismissed grypez’s stale review February 6, 2025 18:55

Ryan intended to remove his request for changes

@sirtimid sirtimid requested a review from rekmarks February 6, 2025 19:07
@sirtimid sirtimid enabled auto-merge (squash) February 6, 2025 19:07
@sirtimid sirtimid requested a review from rekmarks February 6, 2025 19:42
Copy link
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

LGTM!

@sirtimid sirtimid merged commit 7def4f3 into main Feb 6, 2025
17 checks passed
@sirtimid sirtimid deleted the sirtimid/kvstore-kvget-improvement branch February 6, 2025 19:47
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.

Reuse kvGet in KVStore init implementations

5 participants