Repository navigation
Commit 702b0cf
fix(driver-sql)!: a boolean field is stored as a boolean whatever spelling the caller sends (#35718)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D1WDVL9JpCQhTUF97fpymtZ)_
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — the published skills teach no write of a boolean
field through a driver; the engine's door and authored metadata are
unchanged.
## 维护者速读
- 用户无感:经界面和接口写入的布尔与开关字段照旧;插件、钩子或脚本直接写这类字段时,真假的各种写法从此一律存成真正的布尔值。
- 替写插件、钩子和迁移脚本的开发者解决:同一个布尔字段不再因写法不同而存成两种形态,筛选、排序、分组读到的真假始终一致。
- 绕过引擎直接写库、又传了认不出真假的值(比如“yes”)的代码,会收到校验错误而不是悄悄存进去;本改动可整体撤回。
- 无。
## What changes
A boolean field is stored as a boolean whatever spelling the caller
sends.
- **The SQLite write door (`formatInput`,
`packages/drivers/driver-sql/src/sql-driver-sqlite-serialisation.ts`).**
For a declared scalar `Field.boolean` / `Field.toggle`, it used to bind
only a JS boolean and pass every other value through as sent, so a
string reached the column as text. It now reads the value through one
table, `SQLITE_BOOLEAN_TEXT_SPELLINGS`:
- accepted, and bound as the boolean they spell: `true` / `false`, the
numbers `1` / `0`, and the text `'1'` / `'0'`, `'true'` / `'false'` and
`'1.0'` / `'0.0'`;
- refused before any statement is built, with `VALIDATION_ERROR` / 400
(ADR-0112): every other value, for example `'yes'`, `'TRUE'`, `' true'`,
`''`, `2`, `NaN`, an array or an object. The error message names the
field and the object and describes the value's type without echoing it;
- `null` still writes NULL, and an absent key is left alone.
Every SQLite-family write door forms its row here: `SqlDriver` on
SQLite, both faces of `TursoDriver` (the remote face forms its rows
through the same `formatInput`), and `SqliteWasmDriver`. That covers
`create`, `update`, `upsert`, `bulkCreate`, `bulkUpdate` and
`updateMany`.
- **One rule for write and boot convergence
(`sql-driver-schema-sync.ts`).** The local boot convergence
(`SQLITE_LEGACY_BOOLEAN_TEXT` and the `UPDATE` in
`backfillCanonicalBooleans`) now builds its spelling lists from the same
table. The SQL it emits is byte-identical to before. The write door and
the convergence cannot drift apart: neither accepts a spelling the other
does not.
- **Remote `TursoDriver.bulkCreate`** checks every row's storage form
before it writes the first row. A refused row refuses the whole batch
with nothing written, as the local face's single INSERT already did.
- **The engine's door.** It already writes the boolean its validator
judged, and these tests pin that. A `beforeInsert` / `beforeUpdate` hook
that assigns a string runs after that rewrite, so the string reached the
driver as sent. It now lands as a boolean through the driver's door.
- **Not changed:** Postgres and MySQL; the engine's validation; any
schema or export shape. Rows already stored keep their stored form, and
nothing is rewritten at boot that was not rewritten before.
## Tests
-
`packages/drivers/driver-sql/src/sql-driver-boolean-write-spellings.test.ts`
(30 cases): every accepted spelling through all six doors lands
canonical, on a column the driver created (INTEGER) and on a `text`
column retyped to `boolean` (the text `'1'` / `'0'`). Every refused
value comes back as `{ code: 'VALIDATION_ERROR', status: 400 }` with
nothing written. Negative and positive filters (`$ne`, `$nin`, `$not`,
`=`) answer each row by the boolean it was written as.
-
`packages/drivers/driver-turso/src/turso-local-remote-boolean-write-parity.test.ts`
(28 cases): the same doors on both `TursoDriver` faces over an embedded
libSQL file, raw `typeof` read back through a separate client, plus a
remote `bulkCreate` batch with one refused row that writes nothing.
-
`packages/runtime/src/domains/boolean-written-spelling-row-scope.test.ts`
(6 cases): the engine, a permission set and REST, on both faces. Three
writers send the string `'true'`: the engine's door, the driver's door,
and a `beforeInsert` hook. A row-level rule written in negative form
(`restricted != true`, `!(record.restricted in [true])`, `record.locked
!= true`) answers each of those rows by the boolean it was written as,
on `find`, `count`, `findOne`, and the REST list, get and delete.
**Ablation of the new arm** (head `821e6832c09`). The mutant puts the
arm back as it stood at the base: only a JS boolean is bound, and every
other value passes through as sent. Each leg was rebuilt and proven to
reach `dist/` (`ablation-dist-preflight`: the marker present in 2 built
files, then absent from all 6).
| leg | driver-sql pin | driver-turso pin | runtime pin |
|---|---|---|---|
| mutant | 28 failed, 2 passed (30) | 28 failed (28) | 6 failed (6) |
| restored (`git diff HEAD` empty, whole tree clean) | 30 passed (full
suite below) | 28 passed (28) | 6 passed (6) |
Under the mutant, the runtime pin stores `driver_text_true` and
`hook_text_true` as `text` on both faces, while `engine_text_true` stays
`integer`: the engine's door already writes a boolean on its own.
<details><summary>Suites and typechecks at 821e683 (all under the
shared verify lock; VERDICT command-exit 0)</summary>
```text
pnpm --filter @objectstack/driver-sql typecheck EXIT=0
pnpm --filter @objectstack/driver-turso typecheck EXIT=0
pnpm --filter @objectstack/runtime typecheck EXIT=0
driver-sql vitest run --maxWorkers=2 Test Files 266 passed | 13 skipped (279) Tests 4438 passed | 257 skipped (4695)
driver-turso vitest run --maxWorkers=2 Test Files 102 passed | 1 skipped (103) Tests 2593 passed | 36 skipped (2629)
driver-sqlite-wasm vitest run Test Files 41 passed (41) Tests 768 passed (768)
runtime vitest run --project local src/domains/boolean-written-spelling-row-scope.test.ts Tests 6 passed (6)
```
The full runtime suite and the downstream consumers' suites are left to
CI (`Test Core`). This PR changes no runtime source; it adds one test
file there.
</details>
## Acceptance notes
- On the remote face of `TursoDriver`, a `toggle` column is created with
TEXT affinity, while the local face gives it boolean (NUMERIC) affinity.
Now that writes are canonical, the remote cell is the text `'1'` /
`'0'`, and every boolean filter reads it correctly. Noted, not filed.
- The engine's validator accepts fewer text spellings than the driver's
door: it does not accept `'1.0'` / `'0.0'`. The engine stays the
stricter of the two doors. Noted, not filed.
- No stored row is rewritten. A cell stored before this change keeps its
stored form, on either face.
- The runtime pin file takes about 11 s, almost all of it import time
(10.9 s of 11.5 s); its six cases take 0.43 s.
## Verification
**Read first, by risk:**
1. `packages/drivers/driver-sql/src/sql-driver-sqlite-serialisation.ts`,
the `formatInput` boolean arm: the one place a value a direct caller
could write before is now refused.
2. `packages/drivers/driver-turso/src/turso-driver.ts`, remote
`bulkCreate`: the per-row check before the first write.
3. `packages/drivers/driver-sql/src/sql-driver-schema-sync.ts`: the
convergence SQL is now built from the shared table; it should read
byte-identical.
**Two-minute verification:** with `@objectstack/driver-sql` built, run
`pnpm --filter @objectstack/driver-turso exec vitest run --maxWorkers=2
src/turso-local-remote-boolean-write-parity.test.ts`. Expect `Tests 28
passed (28)`.
**Dogfood battery, once, on the final head** (`821e6832c09`, the title
carries `!`): the `@objectstack/dogfood^...` closure was built, then
`pnpm --filter @objectstack/dogfood test` ran under the verify lock.
VERDICT command-exit 0: `Test Files 482 passed | 3 skipped (485)`,
`Tests 4093 passed | 68 skipped (4161)`. No line of the run's log
carries the new refusal's text.
<details><summary>Local gate families at 821e683: 70 derived, 69 run
green, 1 not measured</summary>
`node scripts/pm/dispatch-gates.mjs --commands` derived 70 families from
this diff. `--ran` reconciliation: `70 derived famil(ies) accounted for
— 69 run, 1 NOT-MEASURED`. `check:dual-build-cjs-loads` exits 3
(PREREQUISITE NOT MET) because it reads the built output of every
package, and this checkout built only the dogfood closure. CI's `Build
Core` job runs it.
```text
exit 0 node scripts/check-adr-0087-registration.mjs --base origin/main
exit 0 node scripts/check-adr-0087-registration.mjs --self-test
exit 0 node scripts/check-changeset-no-major.mjs --base origin/main
exit 0 node scripts/check-closing-keyword-parity.mjs
exit 0 node scripts/check-closing-keyword-parity.mjs --self-test
exit 0 node scripts/check-comment-mask-adoption.mjs
exit 0 node scripts/check-comment-mask-adoption.mjs --self-test
exit 0 node scripts/check-comment-mask-corpus.mjs
exit 0 node scripts/check-empty-changeset.mjs --base origin/main
exit 0 node scripts/check-empty-changeset.mjs --self-test
exit 0 node scripts/check-issue-citations.mjs
exit 0 node scripts/check-plugin-teardown-shape.mjs
exit 0 node scripts/check-plugin-teardown-shape.mjs --self-test
exit 0 node scripts/ci/assert-turbo-remote-cache.mjs --self-test
exit 0 node scripts/ci/plan-test-core-shards.mjs --self-test
exit 0 node scripts/ci/prune-turbo-cache.mjs --self-test
exit 0 node scripts/ci/snapshot-next.mjs --self-test
exit 0 node scripts/docs-audit/check-affected-docs.mjs
exit 0 node scripts/docs-audit/check-drift-comment.mjs
exit 0 node scripts/pm/check-governed-queue-guard.mjs --self-test
exit 0 node scripts/pm/release-rehearsal-clone.mjs --self-test
exit 0 node scripts/release-pending-publish.mjs --self-test
exit 0 pnpm --filter @objectstack/spec run check:duration-unit-keys
exit 0 pnpm check:adr-anchors
exit 0 pnpm check:adr-symbol-anchors
exit 0 pnpm check:changeset-gate-self-tests
exit 0 pnpm check:ci-filter-parity
exit 0 pnpm check:cli-command-ids
exit 0 pnpm check:closed-ceremony-text
exit 0 pnpm check:cross-package-test-inputs
exit 0 pnpm check:doc-authoring
exit 0 pnpm check:durability-log-level
exit 0 pnpm check:engine-double-contract
exit 0 pnpm check:error-status-conformance
exit 0 pnpm check:gitlink-declared
exit 0 pnpm check:issue-citations
exit 0 pnpm check:keyed-text-bounds
exit 0 pnpm check:logger-receiver-detach
exit 0 pnpm check:nul-bytes
exit 0 pnpm check:object-def-param-keys
exit 0 pnpm check:objectql-double-limit
exit 0 pnpm check:optional-error-sink
exit 0 pnpm check:org-identifier
exit 0 pnpm check:page-declaration-shape
exit 0 pnpm check:platform-object-tenancy-census
exit 0 pnpm check:query-options-erasure
exit 0 pnpm check:refd-timer-probe
exit 0 pnpm check:registry-log-declared
exit 0 pnpm check:rest-log-spy-declared
exit 0 pnpm check:route-envelope
exit 0 pnpm check:settings-bind-window
exit 0 pnpm check:slot-lookup
exit 0 pnpm check:system-context-census
exit 0 pnpm check:tenant-chokepoint
exit 0 pnpm check:test-source-alias
exit 0 pnpm check:tier-file-adoption
exit 0 pnpm check:undeclared-dep-imports
exit 0 pnpm check:vouch-for-reference-callers
exit 0 pnpm check:watch-hint-literal
exit 0 pnpm check:where-matcher
exit 0 node scripts/check-dts-emitted.mjs --self-test
exit 0 pnpm check:driver-conformance
exit 0 pnpm check:driver-memory-census
exit 0 pnpm check:dts-closure
exit 3 pnpm check:dual-build-cjs-loads
exit 0 pnpm check:lean-entry-closure
exit 0 pnpm check:published-files
exit 0 pnpm check:sourcemap-no-sources-content
exit 0 pnpm check:type-check-coverage
exit 0 pnpm check:type-check-debt (re-run under the verify lock: 0 ledger entries re-measured, 0 raw tsc errors)
```
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_016WV4czt69hUUaG5XcgFNYL)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent c321914 commit 702b0cf
7 files changed
Lines changed: 678 additions & 6 deletions
File tree
- .changeset
- packages
- drivers
- driver-sql/src
- driver-turso/src
- runtime/src/domains
| 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 | + | |
| 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 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| 180 | + | |
180 | 181 | | |
181 | 182 | | |
182 | 183 | | |
| |||
2058 | 2059 | | |
2059 | 2060 | | |
2060 | 2061 | | |
| 2062 | + | |
| 2063 | + | |
| 2064 | + | |
2061 | 2065 | | |
2062 | | - | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
2063 | 2078 | | |
2064 | 2079 | | |
2065 | 2080 | | |
| |||
2126 | 2141 | | |
2127 | 2142 | | |
2128 | 2143 | | |
2129 | | - | |
| 2144 | + | |
2130 | 2145 | | |
2131 | 2146 | | |
2132 | 2147 | | |
| |||
2139 | 2154 | | |
2140 | 2155 | | |
2141 | 2156 | | |
2142 | | - | |
| 2157 | + | |
2143 | 2158 | | |
2144 | 2159 | | |
2145 | 2160 | | |
| |||
0 commit comments