Skip to content

test(storage-boundary): add write-side WIT boundary test#1

Open
zacharywhitley wants to merge 1 commit into
mainfrom
feat/write-boundary-test
Open

test(storage-boundary): add write-side WIT boundary test#1
zacharywhitley wants to merge 1 commit into
mainfrom
feat/write-boundary-test

Conversation

@zacharywhitley

Copy link
Copy Markdown
Contributor

Summary

Adds crates/storage-boundary-test/tests/write_boundary.rs and the companion wit-write/ tree (256 + 242 LOC). This is the mirror-image counterpart to the read-side tests/boundary.rs: it loads the synthetic ducklink writer bridge and drives the exported duckdb:extension/storage-write-dispatch@2.0.0 interface end-to-end across the WIT component boundary via wasmtime, covering begin-transaction, create-table, insert-rows, update-rows, delete-rows, commit-transaction, and the rollback path.

The write world is duckdb:extension@2.0.0; the pre-existing wit/ tree uses the unversioned duckdb:extension package. Rather than version-mix, the write-side WIT lives in a sibling wit-write/ dir with its own duckdb:extension@2.0.0 dependency, keeping the two bindgen! invocations independent.

Cherry-picked as a single commit from feat/python-sdk-authoring-api (which carries unrelated Python-SDK authoring work) onto a fresh branch off main so the review scope is just the write-boundary test.

Related work

Motivating commits on the sqlink side (writer symmetry):

  • tegmentum/sqlink@5cfc37dc -- iVersion fix
  • tegmentum/sqlink@6ec38652 -- read/write unify

Companion smoke-fixture repos:

  • tegmentum/synthetic-mutating-vtab-bridge (sqlink side)
  • tegmentum/synthetic-mutating-vtab-ducklink-bridge (ducklink side; provides the writer wasm this test loads)

Companion PR:

  • tegmentum/ducklink-extension feat/storage-write-dispatch-2.1 -- adds the runtime trampolines + storage-write-dispatch@2.0.0 WIT on the extension-runtime side that this test exercises.

Test plan

  • Build the ducklink writer bridge from tegmentum/synthetic-mutating-vtab-ducklink-bridge and point DUCKLINK_WRITER_BRIDGE_WASM at the artifact (or stage it at ../../artifacts/extensions/synthetic_mutating_ducklink.wasm).
  • cargo test -p storage-boundary-test --test write_boundary -- confirm all boundary phases (begin, create-table, insert, update, delete, commit, rollback) pass.
  • Confirm the pre-existing read-side tests/boundary.rs still passes (no shared WIT/bindgen regressions).

Adds `tests/write_boundary.rs` -- the mirror-image counterpart to the
read-side `tests/boundary.rs`. Loads the synthetic ducklink writer
bridge (companion to sqlink's `synthetic-mutating-vtab-bridge`) and
drives its exported `duckdb:extension/storage-write-dispatch@2.0.0`
interface end-to-end across the WIT component boundary via wasmtime,
covering the full mutating path: begin-transaction, create-table,
insert-rows, update-rows, delete-rows, commit-transaction, and the
rollback path.

The write world is `duckdb:extension@2.0.0`; the pre-existing wit/
tree uses the unversioned `duckdb:extension` package. Rather than
version-mix, the write-side WIT lives in a sibling `wit-write/` dir
with its own duckdb:extension@2.0.0 dependency, keeping the two
bindgen! invocations independent.

Bridge wasm is located via (1) $DUCKLINK_WRITER_BRIDGE_WASM,
(2) `../../artifacts/extensions/synthetic_mutating_ducklink.wasm`
(the staged copy convention), or (3) the sibling checkout at
`~/git/synthetic-mutating-vtab-ducklink-bridge/target/wasm32-wasip2/
release/synthetic_mutating_ducklink_bridge_dynlink.wasm`. Test
panics with a clear build-me message if none of those exist.
zacharywhitley pushed a commit that referenced this pull request Jul 21, 2026
Adds `ducklink_load(name)` as a table function on the workspace CLI so the
extension's control-plane surface — committed in `ducklink-extension`'s
`STABILITY.md § 1.1` — is callable from SQL against the workspace host too.
Bumps the conformance suite's `01-entry-points-registered.out` from 2/6 to
3/6 (`ducklink_help`, `ducklink_load`, `ducklink_version`).

Design: host-synthesized table registration + native dispatch intercept.
The wasm DuckDB core hooks LOAD via `host-extension-loader.request-load`;
there is no SQL-callable route from a component into the extension load
orchestration without breaking the frozen `duckdb:extension@4.0.0`
contract, and macros can't have LOAD side effects. So the host takes the
same shape it already uses for the resolver observability scalars: a
sentinel `callback_handle` (`DUCKLINK_LOAD_HANDLE = 0xFFFF_FFFD`) that the
core knows nothing about, injected as a synthetic `reg::TableReg` in
`drain_pending_registrations`. `dispatch_table` short-circuits the sentinel
and runs `ensure_extension_loaded` natively.

The wasm core's runtime WIT registers every `funcarg` as a required
positional parameter (`duckdb_table_function_add_parameter`, no
named-parameter distinction) — so only the positional `name` argument is
surfaced today. `kind => 'wasm'|'native'` from STABILITY § 1.1 is parsed
if a second positional VARCHAR arrives (native currently errors clean —
the workspace has no native tier yet); a future contract bump that adds
named-parameter metadata to `runtime.table-registry.register` lets us
surface the named form without other changes.

Deferred drain: `dispatch_table` runs inside a `call_table` callback, so
the wasm store is mid-call — the same re-entrancy shape the live-query
import respects in `query`. Re-issuing `LOAD <name>;` from the handler
would self-deadlock. So the handler stashes what it loaded on the
manager and `HostState::execute` replays an idempotent `LOAD <name>;`
before the user's next statement; that second LOAD hits
`ensure_extension_loaded`'s already-loaded fast path and the core's
post-LOAD `get_pending_registrations` picks up the stashed
`deferred_registrations` — the extension's functions become visible on
the statement after `ducklink_load` returns (parity with the extension's
"NEXT statement's binder resolves them" contract).

Errors: `FROM ducklink_load('does-not-exist')` returns
`Duckerror::Invalidargument` with a legible message pointing at the
missing manifest entry / <extensions-dir>/*.wasm shortcut; no crash.
`FROM ducklink_load('jsonfns')` returns a single row
`(name, path, scalars, tables, aggregates)` matching the extension's
column shape (path is NULL until the workspace resolver's artifact path
is surfaced — parity follow-up).

Return columns are forward-compatible with `prefix__name` retirement
(task #1 in the fan-out) — no `prefix_*` machinery is added or removed.
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