Repository navigation
Commit 49c8e0f
fix(driver-turso): remote aggregate group keys over a boolean answer true/false (#37152)
Fixes #37133
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:托管云(远程 libSQL 连接)上的报表、图表和问数按「是否完成」这类布尔字段分组时,分组值显示为
是/否(true/false),不再显示 1/0,和本地运行一致。
- 为什么做:托管云的驱动在分组统计时漏掉了普通读取已有的值转换,同一份数据在两种连接方式下答案不同。
- 出错会怎样:只影响分组统计返回的分组值写法,计数和合计不变;如有问题可直接撤回此改动,数据本身不受影响。
- 要你做什么:无。
## What changes
`TursoDriver.aggregate` on its remote face (`libsql://`, `https://`,
`http://` URLs, the hosted construction) returned the libSQL transport's
raw columns, so a group over a declared boolean answered `1` / `0` /
`null` where the local face answers `true` / `false` / `null`.
The remote branch now presents its group-key columns through the two
inherited members the local face uses, `readPresentationKind` and
`presentReadColumns` (driver-sql), keyed by the output column (`alias ??
field`), with the registries keyed by object name as remote `find()` and
remote `distinct()` already read them. Every kind the shared presenter
covers (boolean, date, time, datetime, audit timestamps, number) is
presented the same way. Measures are not touched: counts and totals are
numbers from libSQL already, and `min` / `max` over a boolean stay `0` /
`1` (the ruled numeric aggregation domain, `SqlDriver.aggregate`
[#11152]).
Other remote grouped or projected reads checked for the same gap:
- `distinct()` already presents its values (`readPresentationKind` +
`presentReadValue`), so no change; the new suite pins it on the real
engine.
- `find()` / `findOne()` / `bulkUpdate()` / `create()` / `update()` /
`upsert()` already go through `formatRemoteRow(s)`.
- Window reads and query plans are refused on the remote face; the
remaining raw `execute` calls are catalog and sequence reads, not object
rows.
First files to read, by risk:
1. `packages/drivers/driver-turso/src/turso-driver.ts`: the
`aggregate()` remote branch and the new `presentRemoteGroupKeys` (the
one behavioural hunk).
2.
`packages/drivers/driver-turso/src/remote-aggregate-group-key-presentation.test.ts`:
the acceptance suite on the real libSQL engine.
Two-minute verification: `pnpm --filter @objectstack/driver-turso exec
vitest run --maxWorkers=2
src/remote-aggregate-group-key-presentation.test.ts` answers 4/4 green;
on `origin/main` the same file answers 3 failed, with `done: 0` / `done:
1` where `false` / `true` are expected.
## Tests
New `remote-aggregate-group-key-presentation.test.ts`, every case on the
REAL libSQL engine (`@libsql/client` over `file::memory:`, behind the
remote face; not the better-sqlite3 stub):
- a boolean group key answers `true` / `false` / `null`;
- an aliased structured key (`{ field: 'done', alias: 'is_done' }`) is
presented under the name the row carries;
- the remote answer equals the local face's on the same data for five
queries: boolean key, aliased key with `sum`, boolean + date keys, a
number key, and `max` / `min` over the boolean (measures);
- `distinct('done')` answers JSON booleans on both faces.
<details><summary>Readings (final head d6e5f6c)</summary>
- Before the fix (`origin/main` source, new test file only): `Tests 3
failed | 1 passed (4)`; the diff reads `- "done": false` / `+ "done":
0`, `- "done": true` / `+ "done": 1`.
- After: `Tests 4 passed (4)`.
- Package at d6e5f6c: `pnpm --filter @objectstack/driver-turso
typecheck && test` (lock VERDICT command-exit 0): `Test Files 104 passed
| 1 skipped (105)`, `Tests 2652 passed | 36 skipped (2688)`. `tsc
--noEmit --listFiles` includes the new test file (count 1).
- Derived gate families at d6e5f6c (`dispatch-gates.mjs --commands`):
69 run, each exit captured before any pipe; `--ran` reconciliation: `69
derived, 69 run, 0 NOT-MEASURED, 0 UNRUN`. 68 exited 0 on the first
pass; `check-plugin-teardown-shape.mjs --self-test` exited 3 because its
pinned positive-control commit was absent from this shallow clone, and
exited 0 (`48 cases pass`) once that one commit was fetched.
`check-nul-bytes`: OK. The wider CI families are CI's.
- Ablation, one time, committed fix first:
`scripts/ablation-replace.mjs` replaced `return
this.presentReadColumns(rows, columns);` with `return rows;` (anchor 1
to 0, blob efbc1cc to c8375a638b14), the suite answered `Tests 3
failed | 1 passed (4)` (the three group-key cases red, the `distinct`
case green as expected), and the restore read blob == HEAD
(efbc1cc), `git diff HEAD` empty. The test imports
`./turso-driver.js` from source, so no build sits in that path.
</details>
## Acceptance notes
- The card names the HTTP door as `/api/v1/data/:object/aggregate`. That
path is not a route on this platform: on a booted server it falls into
`GET /data/:object/:id` and answers `405 METHOD_NOT_ALLOWED` for POST
(`Allowed: DELETE, GET, HEAD, PATCH`) and `400 VALIDATION_ERROR` for GET
with `groupBy` (`Supported parameters: expand, select`). The aggregate
door over HTTP is `POST /api/v1/data/:object/query` with `groupBy` /
`aggregations` in the body (`packages/rest/src/crud-routes.ts`), which
is what was checked below.
- Not measured: `min` / `max` over a temporal column whose stored value
is NOT canonical (a legacy epoch integer). The local face presents that
through the column's temporal kind and the remote face does not, so the
two could disagree there. On canonical storage they agree (measured:
`max(due)` and `min(at)` over a `date` and a `datetime` read the same on
both faces). Left as dispatched ("measures stay untouched").
- The hosted-shaped boot used a scratch Hrana v2 shim (below); its batch
handling made the boot log `Batch schema sync failed, falling back to
sequential` twice. That is the shim's, not the product's; the sequential
sync completed and the server served.
## Verification
HTTP door on a hosted-shaped boot. No `sqld` here (not installed, GitHub
release downloads refused by the proxy, no Docker daemon), so what ran
instead:
1. A scratch Hrana v2 JSON-pipeline server (about 100 lines, not
committed) over the native `libsql` 0.5.29 engine on a `file` database,
on 127.0.0.1.
2. `pnpm dev -- --fresh -p PORT --database
'libsql://127.0.0.1:SHIMPORT?tls=0'` (the CLI accepts `libsql://`, and
`@libsql/client` reads `tls=0` as plain HTTP). The boot printed `Driver:
TursoDriver(libsql) → libsql://127.0.0.1:SHIMPORT`, the remote face,
with the showcase seed in place (`showcase_task.done`: 8 false, 2 true
by `find()`).
3. Signed in as the seeded admin and sent `POST
/api/v1/data/showcase_task/query` with
`{"groupBy":["done"],"aggregations":[{"function":"count","alias":"c"}]}`.
<details><summary>HTTP readings, same database across all three
boots</summary>
- Fixed build: `200
{"records":[{"done":false,"c":8},{"done":true,"c":2}],"total":2}`;
aliased key `{"field":"done","alias":"is_done"}`: `200
{"records":[{"is_done":false,"c":8},{"is_done":true,"c":2}]}`.
- Before leg: the presenter call ablated in source, driver-turso
rebuilt, `ablation-dist-preflight` read the marker present in 2 built
files, server restarted on the same database: `200
{"records":[{"done":0,"c":8},{"done":1,"c":2}]}`. This proves the HTTP
door reaches this code with nothing upstream presenting the key.
- Restore leg: source restored (blob == HEAD, `git status --porcelain`
empty), rebuilt, preflight `--absent` read the marker absent from all 6
built files and the tree clean, server restarted: `200
{"records":[{"done":false,"c":8},{"done":true,"c":2}]}`.
</details>
Dispatched by: maintainer · os-bob · session_012dn2AecKpLaYkUtNRiqtby
---
_Generated by [Claude
Code](https://claude.ai/code/session_012dn2AecKpLaYkUtNRiqtby)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 0e792da commit 49c8e0f
3 files changed
Lines changed: 187 additions & 2 deletions
File tree
- .changeset
- packages/drivers/driver-turso/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3314 | 3314 | | |
3315 | 3315 | | |
3316 | 3316 | | |
3317 | | - | |
3318 | | - | |
| 3317 | + | |
| 3318 | + | |
| 3319 | + | |
| 3320 | + | |
| 3321 | + | |
| 3322 | + | |
3319 | 3323 | | |
3320 | 3324 | | |
3321 | 3325 | | |
3322 | 3326 | | |
3323 | 3327 | | |
| 3328 | + | |
| 3329 | + | |
| 3330 | + | |
| 3331 | + | |
| 3332 | + | |
| 3333 | + | |
| 3334 | + | |
| 3335 | + | |
| 3336 | + | |
| 3337 | + | |
| 3338 | + | |
| 3339 | + | |
| 3340 | + | |
| 3341 | + | |
| 3342 | + | |
| 3343 | + | |
| 3344 | + | |
| 3345 | + | |
| 3346 | + | |
| 3347 | + | |
| 3348 | + | |
| 3349 | + | |
| 3350 | + | |
| 3351 | + | |
| 3352 | + | |
| 3353 | + | |
| 3354 | + | |
| 3355 | + | |
| 3356 | + | |
| 3357 | + | |
| 3358 | + | |
| 3359 | + | |
| 3360 | + | |
| 3361 | + | |
| 3362 | + | |
3324 | 3363 | | |
3325 | 3364 | | |
3326 | 3365 | | |
| |||
0 commit comments