Repository navigation
fix(service-analytics): draft preview answers $contains on a multi-value field as membership - #36675
Conversation
…lue field as membership The draft preview evaluated $contains as a case-folded substring of String(value) on every column, so on a declared multi-valued or JSON-stored field it searched the drafted list's string form. It now asks membership there (the members jsonMembershipCandidates names, compared by JSON text, as every SQL face binds them) and the case-exact substring of a stored string elsewhere (FILTER_TEXT_CASES, #4706 Q2 = A). $notContains joins the preview's table as the exact complement, measured against the shared text kit. Claude-Session: https://claude.ai/code/session_011y7As6FyXmJyGyHNKXUkV7 Co-authored-by: Claude <noreply@anthropic.com>
…embership fix Claude-Session: https://claude.ai/code/session_011y7As6FyXmJyGyHNKXUkV7 Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift Check6 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run. What this run could not see
Coarse fallback — 10 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 68ed732aeada2eb9058a69ca0c585156a82b29ad && git checkout 68ed732aeada2eb9058a69ca0c585156a82b29ad
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 6a731859def47e2c8cefcab4d635a1c45c60c2c1 6fec79120dd0271006ea88066dbfd366d6389caa && git checkout -B drift-repro 6a731859def47e2c8cefcab4d635a1c45c60c2c1 && git merge --no-ff 6fec79120dd0271006ea88066dbfd366d6389caa
node scripts/docs-audit/affected-docs.mjs --json 6a731859def47e2c8cefcab4d635a1c45c60c2c1 |
|
repo:objectstack#7 · os-alice · session_011y7As6YDLR8TJVDpdXzJyV 维护者速读
席位核对Verdict: ACCEPT · head Reviewed against GitHub at this head (diff, card body, Checklist
Clause-② reading (seat's point 1 and 2)
Accepted deviations and landing items
|
|
repo:objectstack#7 · os-alice · session_011y7As6FyXmJyGyHNKXUkV7 Landing · 2026-11-23T11:40Z · head
Landing item from the ACCEPT is done: the PR body's folded-item line now names #36677, the card the field-reference comparand was split to (body edit only, the head did not move). |
…olumn the driver stores as JSON, on the native dataset face and the draft preview (objectstack-ai#36771) Fixes objectstack-ai#36190 Clause-②: yes (narrowing) — widened: `SqlDriver.jsonColumnFieldClass` (`@objectstack/driver-sql`) is now public, and so on every class that extends it (`TursoDriver`, `SqliteWasmDriver`), and the exported `AnalyticsServiceConfig` (`@objectstack/service-analytics` root) gains the optional key `jsonColumnFieldClass`; narrowed: the native dataset face and the draft preview newly answer `400 INVALID_FILTER` for a scalar comparison on a single-value media column the driver stores as JSON, which they answered `200` with a wrong count before Metadata-protocol: none Skills-docs: none — no published skill documents the dataset door's filter vocabulary per storage class; the operator contract the skills describe (`$contains` is membership on a JSON column) is unchanged, and the prescription for this class lives in the refusal text itself (the media-column move) ## 维护者速读 - 用户能看到什么变化:在报表/看板里按附件字段(图片、文件)筛选时,数据集查询现在明确报错 400,不再静静给出错误的条数;其他字段的筛选照旧。 - 为什么做:属于「问数与报表口径一致」这条线,替数据门(`/api/v1/data` 查询)已有的拒绝把剩下两张面补齐,四张面同一句话。 - 出错会怎样:只会多出一条拒绝消息,不写任何数据;若判断过宽,受影响的只是这类筛选条件,回退该 PR 即可恢复。 - 要你做什么:确认「附件字段不能按值筛选,只能问有没有值」这个口径可以直接对外(消息里同时给出迁移命令);其余无。 ## What changes A single-value `image` / `file` / `avatar` / `video` / `audio` field is stored as a JSON column on every deployment still inside the ADR-0104 dual-encoding window, and no declaration says so — the declared shape is `image`, not JSON-stored. objectstack-ai#36168's dataset refusal reads the declared shape only (`isJsonStoredShape`, the `multiple` population), so the native dataset face compiled the comparison against the stored JSON string and answered `200` with a wrong count, and the draft preview answered its own. - `SqlDriver.jsonColumnFieldClass` becomes **public** (`packages/drivers/driver-sql/src/sql-driver.ts`, no body change): whether a media column is JSON is this deployment's storage state, which the analytics host cannot read from any declaration. This is the hook the card said the analytics host did not have; it is read-only, records nothing, and is the same question `driver-turso`'s remote transport already asks through it. - `DatasetScopedStrategyContext.jsonColumnFieldClass` is the analytics-side hook (`strategies/types.ts`), wired by `AnalyticsServicePlugin` from the driver that stores the object through the existing `getDriverForObject` seam, exactly as `sqlDialect` and `dateBucketSql` are. Only the two classes the refusal words are passed on; every tier that cannot answer stays `undefined`, which leaves the column unjudged. - `json-column-comparison-refusal.ts` (objectstack-ai#36168's module) grows one population function, `comparisonColumnClass`: the declared JSON shape is `'multi-value-or-json'` as before, else the storing driver's `'single-value-media'`, else not judged. Both faces of that module read it, so the refusal is worded by the column's class — the media-column move for this class, not the `$contains` membership repair, which finds no member in a single JSON string. - `NativeSQLStrategy`'s unknown-dialect decline reads the same population, so a datasource whose dialect the host cannot name keeps being handed to the ObjectQL strategy and its engine. - `driver-turso` records the now-public member in `REMOTE_FACE_ANSWERS` as `inherited` (that ledger is `Record<keyof SqlDriver, …>`, so a new public member reds its typecheck until its remote answer is decided): the remote face already answers from this registry through `setJsonColumnResolver`. **One conclusion per compile face**, as asked: | Face | Conclusion | |---|---| | Data door (`POST /api/v1/data/:object/query`, `driver-sql`'s `where`) | **Already compliant** — `sql-driver-filter-helpers.ts`'s `assertOperatorAppliesToColumn` asks `jsonColumnFieldClass` and refuses `400 INVALID_FILTER`; re-verified on current `main`, unchanged by this PR. | | ObjectQL face of the dataset door | **Already compliant** — it hands the leaf to the engine and `driver-sql`, which refuses; pinned here on all four filters, and its message is held equal to the native face's where both name one spelling. | | Native dataset face (`NativeSQLStrategy.buildFilterClause`) | **Changed** — refuses `400 INVALID_FILTER` before anything binds; previously `200` with a wrong count. | | Draft preview (`?preview=draft`, `preview-evaluator.ts`) | **Changed** — refuses once over the lowered `where`, before any row is read, so an empty seed draft is refused too; previously `200` with its own count. | Out of scope, deliberately: the card's "other dialects to be measured by the claimant" — the refusal is judged on the declared/stored class and never on the dialect, so it fires on every dialect; `NativeSQLStrategy` is pinned on `sqlite` / `postgres` / `mysql` / `mssql` by objectstack-ai#36168's own suite and nothing here is dialect-conditional. ## Tests First measured at `d07e6802` (the head this PR opened at, after merging `origin/main` once objectstack-ai#36675 landed). The dogfood battery is from that head. The rework round since then changed the changeset, comments, one import, one redundant check and the test file, and the package suite, typecheck and gate union were re-run at `fe18f109`. New: `packages/services/service-analytics/src/__tests__/dataset-single-value-media-refusal-36190.test.ts` — 17 tests (14 in the refusal suite, 3 in a moved-deployment control suite), driven through `queryDataset` on the production composition (a real `AnalyticsServicePlugin` over a real `ObjectQL` + `SqlDriver` on SQLite, media columns not moved), on all three faces of the door. - Pins on `pic: image` and `doc: file`, for `$eq`, implicit equality, `$in` and `$ne`: `code` `INVALID_FILTER` **and** `status` 400 on the native face, the ObjectQL face and the draft preview, the field named, and `$contains` NOT prescribed. One message across faces where they name one spelling (the equality pair is the known asymmetry: the ObjectQL leaf reaches `driver-sql` as the bare spelling). - The dataset's own `filter` likewise, in one sentence on all three faces. - The words are this class's: the message equals `jsonColumnOperatorRefusalText(…, 'single-value-media')`'s diagnostic and not the `multi-value-or-json` one. - Moved-deployment control (`fileColumnsMoved: true`): the driver reads neither media column as JSON, and `{ pic: 'file_1' }`, `$eq` and `$in` answer the one matching row on all three faces, for `image` and `file`. This pins that the refusal reads the storing driver's class, not the declared type. - Scalar control: the same four operators on a `text` column answer the right counts on every face. Presence control: `$null` on the media column still answers 2. Storage control: the driver reads both columns as `single-value-media`. ```text pnpm --filter @objectstack/service-analytics exec vitest run --maxWorkers=2 src/__tests__/dataset-single-value-media-refusal-36190.test.ts Test Files 1 passed (1) Tests 14 passed (14) pnpm --filter @objectstack/service-analytics test (at fe18f10) Test Files 226 passed (226) Tests 5777 passed | 345 skipped (6122) pnpm --filter @objectstack/service-analytics typecheck exit 0 pnpm --filter @objectstack/driver-sql typecheck exit 0 pnpm --filter @objectstack/driver-turso typecheck exit 0 pnpm --filter @objectstack/driver-turso exec vitest run src/turso-remote-inherited-members.test.ts src/turso-local-remote-single-value-media-refusal-parity.test.ts Test Files 2 passed (2) Tests 118 passed (118) pnpm --filter @objectstack/dogfood test (closure built first, under the verify lock; VERDICT command-exit 0) Test Files 487 passed | 3 skipped (490) Tests 4125 passed | 68 skipped (4193) ``` The gate families `node scripts/pm/dispatch-gates.mjs --commands` derives for this diff: 79, each run at `d07e6802` with its exit code recorded before any pipe; 78 exit 0, and `pnpm check:type-check-debt` exit 3 (PREREQUISITE NOT MET: its closure build did not get a turn on the shared verify lock while this branch's own battery held it), so it is NOT MEASURED locally and is read from CI's `Lint & Repo Gates`. `--ran` reconciliation: 79 accounted, 78 run, 1 NOT-MEASURED. **Ablation** (one-off, at `34268214`, not left in the tree; the population function it mutates is unchanged since), through `scripts/ablation-replace.mjs` so the mutation is proven on disk: dropping the single-value-media arm of `comparisonColumnClass` (anchor hit 1 → 0, blob `0e02e7239009` → `40f4ddee27aa`) turns **10 of the 14** tests red and leaves the 4 controls green — the expected direction, and the controls are what keeps the refusal from reading as "refuse everything". Restored and verified by the tool: blob equals HEAD's and `git diff HEAD` is empty. ## Acceptance notes - **Sibling PR objectstack-ai#36675 (draft preview `$contains` membership), now on `main`.** It reads `lowerPreviewRowFilters`' fifth parameter `declaredShape`. This branch first renamed and retyped that parameter; it now keeps `declaredShape` exactly as it was (name and type) and takes the storing driver's class as a sixth optional parameter, `storedJsonClass`, combined by `comparisonColumnClass`. The branch was merged with `origin/main` after objectstack-ai#36675 landed: the merge was clean, `lowerPreviewRowFilters` carries both changes, and the package's suite and typecheck above ran on the merged tree. No call site had to adapt. - `sql-driver.ts` is a registered facade file at a line ceiling of 10071 (raising it is maintainer-only), and it sat at 10069. The rationale for the visibility change therefore lives on the analytics-side hook's docblock, with a two-line pointer in the facade; the file now sits exactly at 10071. - **`$contains` on a single-value media column: three answers for one filter (measured, not changed here).** This is the one cross-face disagreement left on this class. I measured it at `fe18f109` on this PR's fixture (stored `pic` is the JSON string `"file_1"` / `"file_2"`, two rows null), through the same production composition the tests use: the data door's engine `find` (what `POST /api/v1/data/:object/query` calls) and the dataset door's `queryDataset` (what `POST /api/v1/analytics/dataset/query` calls), on each face. | `pic: { $contains: … }` | Data door (`find`) | Dataset, native | Dataset, ObjectQL | Draft preview | |---|---|---|---|---| | `'file_1'` | 0 rows | count 1 | count 0 | count 1 | | `'file'` | 0 rows | count 2 | count 0 | count 2 | | `'"file_1"'` | 0 rows | count 1 | count 0 | count 0 | The data door and the ObjectQL face run `driver-sql`'s JSON membership, which finds no member in a single JSON string. The native face falls to text-match over the stored JSON text (`whereContainsMembershipSql` reads only the declared shape), and the preview text-matches the bare drafted id. Every answer is `200`. Outside objectstack-ai#36190's Done-when; the seat holds the reading for filing. - Contract-review nits: N1 (changeset names `driver-turso`; the release text now says the member is public and what a subclass owes) and N3 (module prose for both classes, a repeated shape check dropped, the split import joined) are done on this head. N2 (a moved-deployment pin) is done too, as the control suite above. ## Verification Read first, in risk order (3 files): 1. `packages/services/service-analytics/src/json-column-comparison-refusal.ts` — the risk hunk is `comparisonColumnClass`: it must keep the declared-shape arm first, so the existing `multi-value-or-json` population is byte-identical in verdict and in words. 2. `packages/services/service-analytics/src/plugin.ts` — the risk hunk is `jsonColumnFieldClass`: it must pass on only the two known classes and swallow every tier that cannot answer, or a host without a SQL driver starts being judged. 3. `packages/drivers/driver-turso/src/turso-driver.ts` — the risk hunk is the new `REMOTE_FACE_ANSWERS` row: `inherited` must be true of the remote face (it is: the remote transport is handed this very method). Two-minute verification, one command: ```bash pnpm --filter @objectstack/service-analytics exec vitest run --maxWorkers=2 src/__tests__/dataset-single-value-media-refusal-36190.test.ts src/__tests__/dataset-json-column-refusal-36168.test.ts ``` Expect 17 + the objectstack-ai#36168 suite's tests all passing: the new class is refused and the old population's words did not move. --- _Generated by [Claude Code](https://claude.ai/code/session_011y7As5bdhV5T4N9vpjmZzH)_ <!-- signed: repo:objectstack#7 · os-alice · session_011y7As5bdhV5T4N9vpjmZzH --> --------- Co-authored-by: Claude <noreply@anthropic.com>
Fixes #36189
Clause-②: no
Metadata-protocol: none
repo:objectstack#7 · os-alice · session_011y7As6FyXmJyGyHNKXUkV7
维护者速读
What changes
The draft preview (
POST /api/v1/analytics/dataset/query?preview=draft, Studio's preview mode) evaluated$containsasString(value).toLowerCase().includes(…)on every column.packages/services/service-analytics/src/preview-evaluator.ts:previewContains(new) is the one test behind the$containspair.isJsonStoredShape, the population the nativewherecompile and the analytics: the dataset query door answers 200 / count 0 for = or $in on a JSON (multiple) column, where the data door refuses 400 #36168 JSON-column refusal read), the test is MEMBERSHIP. Some element of the drafted array must equal one of the members@objectstack/core'sjsonMembershipCandidatesnames, compared by JSON text, which is what the SQLite construct compares. So'1'names the string'1'or the number1, and a nested array, an object or a non-array value holds no member, as on every SQL face.$notContainsjoinsPREVIEW_FIELD_OPERATORSas the exact complement. It was refusedINVALID_FILTER/ 400 on every column. A row with no value reaches it inside the shared lowering's NULL escape and is answered by$nullthere. The table's docblock requires a new arm to be measured against the shared conformance kits. It is measured againstFILTER_TEXT_CASESin the new test file (below).matchesWheretakes an optionalshapeOf.lowerPreviewRowFilterspasses the declared shape it already receives, read through the member-to-column map, the same way the JSON-column refusal reads it. The call site inanalytics-service.tsis unchanged.The card's open question (scalar case fold): fixed here, because the live rule is written down. The rule is case-exact (#4706 Q2 = A). It is in
packages/spec/src/data/filter-text-conformance.ts:330-372(the$containsfamily rows),packages/services/service-analytics/src/text-match-sql.ts:84-87, andpackages/drivers/driver-memory/src/memory-driver.ts:1538. Measured before:label $contains 'A'answered native 1, ObjectQL 1, preview 3. The same kit rows also rule that a stored non-string never contains a substring (#14079). The preview searchedString(5), so the scalar arm now reads only a stored string. This takes the bounded-fix exemption: same predicate, same defect class (the preview disagreeing with the live faces on this operator), and the shape is pinned by the kit row.The folded item (a
{ $field }comparand on a multi-value field): not taken. It is a different mechanism. The preview resolves no field reference at all: it compares the row value against the reference object. So the scalar case is wrong too. Measured on the same composition:label $eq {$field: alias}answers native 2 and preview 0;$neanswers 2 and 4;$gtanswers 0 and 2. The multi-value case (label $eq {$field: tags}: live 400, preview 200 count 0) is one instance of that. It is not the JSON-column resolver, so the seat split it to card #36677.Tests
src/__tests__/preview-contains-membership-36189.test.ts, 30 cases.queryDataseton the production composition (realAnalyticsServicePlugin, engine and SQLiteSqlDriver, one pending seed draft). Ontagsand aselectdeclaredmultiple: true, it covers a substring-only value, a case-only difference and a comma-joined value under$contains,$notContains,$notand$or. Each asserts native = ObjectQL = preview = the declared count. The scalar text control asserts the case-exact substring, equal on every face.FILTER_TEXT_CASES: every kit row whose operators the preview evaluates. A pinned roster of six named rows makes sure the selection is not empty.preview-evaluator.test.ts: the'Hello World' $contains 'world'fold now assertsfalse, with a'World'hit beside it.preview-unevaluable-operator.test.ts:$notContainsmoves to the evaluated set, with a both-direction row in its matrix. The$notrefusal arm now uses$icontains.dataset-json-column-refusal-36168.test.ts:$notContainsleavesPREVIEW_UNEVALUATED, so its JSON-column control row is now also asserted on the preview.6fec79120:pnpm --filter @objectstack/service-analytics typecheckexit 0, andpnpm --filter @objectstack/service-analytics testgaveTest Files 225 passed (225),Tests 5760 passed | 345 skipped (6105). VERDICT command-exit 0.Before / after, three faces (counts over the 4-row fixture)
Ablation (one shot, not kept)
On committed
1c39ffab6,node scripts/ablation-replace.mjsplanted the old folded-substring line at the head ofpreviewContains. The anchorif (isJsonStoredShape(shape)) {went from 1 to 0 hits and the blob from6fca41f2e294to9a65dfcb0abe. The new test file then gaveTests 24 failed | 6 passed (30). The six that stayed green are the unfiltered control, the kit-roster pin, the_-literal kit row, the whole-member'ab'rows and the undeclared-field fallback, none of which tells the two readings apart. Restore: the blob matches HEAD6fca41f2e294andgit diff HEADis empty. The first attempt was a no-op: the replacement text contained its own anchor, so the tool refused it (anchor count moved 1 -> 1) and ran nothing.Acceptance notes
claude/issue-36190-analytics-single-media-json-refusal, no PR open).git merge-treeis clean, but the overlap is real in meaning. That branch renameslowerPreviewRowFilters's fifth parameter fromdeclaredShapetojsonColumnClass, which this PR reads forwhereShape. Whichever lands second adapts one line: membership is the'multi-value-or-json'class.$icontains,$startsWithand$endsWithstay refused on the preview, unchanged.$containson a declared temporal column whose drafted value is ISO text. The live faces type-gate it to FALSE (text operator over a temporal column: SQLite matches the stored ISO text, live Postgres refuses with SQLSTATE 42883, and the JS faces answer by stored representation — no face declares the cell #15683). The preview's scalar arm still reads any stored string.Verification
Two minutes:
pnpm --filter @objectstack/service-analytics exec vitest run --maxWorkers=2 src/__tests__/preview-contains-membership-36189.test.ts. ExpectTests 30 passed (30).Read first, by risk:
preview-evaluator.tspreviewContains: membership versus the case-exact substring, and the non-string guard.preview-evaluator.tslowerPreviewRowFilters:whereShapereads the member's column, as the refusal does.preview-unevaluable-operator.test.ts: the vocabulary change.Generated by Claude Code