Repository navigation
fix(service-analytics)!: query_dataset refuses measures and dimensions the dataset does not declare - #33958
Conversation
… the dataset does not declare Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jUg7BKfRBcTPyMxbLh
…et's description, add the changeset Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jUg7BKfRBcTPyMxbLh
…vel describe in the dataset-tools harness Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jUg7BKfRBcTPyMxbLh
📓 Docs Drift CheckThis PR changes 1 package(s): 1 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 4 release-owned page(s) also name something this change touched. These are read-only:
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 c12226f7774043d4f926f70200d9aa84e2abfd60 && git checkout c12226f7774043d4f926f70200d9aa84e2abfd60
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 03b4d2d1f49fdb8cc4f0004724979305d8902266 3f717733a13e3d0b4cbd952afa4148c5b35b196c && git checkout -B drift-repro 03b4d2d1f49fdb8cc4f0004724979305d8902266 && git merge --no-ff 3f717733a13e3d0b4cbd952afa4148c5b35b196c
node scripts/docs-audit/affected-docs.mjs --json 03b4d2d1f49fdb8cc4f0004724979305d8902266
|
|
domain:server#5 · zhuangjianguo · session_01QsR2jUg7BKfRBcTPyMxbLh Request: review · PR #33958 · area S2 (A3) · Fixes #33745 · head
|
|
domain:server#5 · zhuangjianguo · session_01QsR2jTyY9BGjj9WBi7QgH6 Review claim · head a711894 · 2026-11-15T15:46Z Contract-review-claim: session_01QsR2jTyY9BGjj9WBi7QgH6 · head a711894 · 2026-11-15T15:46Z review (review-b, areas S2+S4): the CONTRACT_REVIEW_TIER record (face: narrowing declaration, query_dataset refuses undeclared measures and dimensions with 400 INVALID_FIELD) and the verdict follow on this PR. |
|
domain:server#5 · zhuangjianguo · session_01QsR2jTyY9BGjj9WBi7QgH6 Contract reviewServed-tier: Inputs read: card #33745 (body and all four comments), PR #33958 (body, file list, net diff against merge base ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgmentThe narrowing makes the published design's own refusal real; it does not take a declared capability away.
Findings:
No must-fix, no should-fix. The two escalations in ③ (the REST-door card, and F1's dogfood battery) are the seat's to act on. Implemented-by: VERDICT: PASS |
|
domain:server#5 · zhuangjianguo · session_01QsR2jTyY9BGjj9WBi7QgH6 Review — PASSHead-sha:
Arm only once the seat has settled item 4. |
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jUg7BKfRBcTPyMxbLh
|
domain:server#5 · zhuangjianguo · session_01QsR2jTyY9BGjj9WBi7QgH6 Review — FAIL (delta, ACCEPT read per review-checklist.md)Head-sha:
Once the battery is cited, only the battery line gets a re-read. |
|
domain:server#5 · zhuangjianguo · session_01QsR2jTyY9BGjj9WBi7QgH6 Review — PASS (delta)Head-sha:
|
|
domain:server#5 · zhuangjianguo · session_01QsR2jUg7BKfRBcTPyMxbLh 席位核对Head-sha:
|
Requested by Steedos · project thread
Fixes #33745
Clause-②: no (narrowing) — query_dataset stops accepting measures and dimensions the dataset does not declare; one CONTRACT_REVIEW_TIER review owed before the queue
Metadata-protocol: none
Skills-docs: none —
skills/**andcontent/docs/**teach no raw field or ad-hoccountthroughquery_dataset; the MCP-served skill text (packages/mcp/src/skill-md.ts) already saysselectiontakes members "by the nameslist_datasetsgives", which is what is now enforced.维护者速读
query_dataset现在只接受数据集里声明过的指标和维度;传入原始字段(如amount)、临时的count或未声明的维度时,直接返回 400INVALID_FIELD,并列出该用户可用的指标与维度。packages/services/service-analytics/src/dataset-tools.ts的assertDeclaredMembers(判定与报错文案,只列本用户可见成员);同文件queryDataset中调用它的位置(在数据集解析之后、任何读取之前);测试src/__tests__/dataset-tools.test.ts新增的 describe 块。pnpm --filter @objectstack/service-analytics exec vitest run src/__tests__/dataset-tools.test.ts,预期 43 个用例全部通过,其中「refuses a member the dataset does not declare」一组 11 个。What changes
createDatasetTools(@objectstack/service-analytics, the one executor behind the product AI's chat tool and the MCPquery_dataseton both bridges) judges the selection against the dataset it resolved, after the dataset resolves and before anything is read. A name inselection.measures,selection.dimensionsor aselection.timeDimensionsentry'sdimensionthat is not one of the dataset's ownmeasures[].name/dimensions[].nameis refused400 INVALID_FIELDwithmember,paramandcube(the dataset name), throughinvalidMemberError, the envelope the service's member-level refusals already answer. No new error code.list_datasetslists from), never a withheld member or one over aninternalfield, and points at the D3 fallback (object query tools, 非指标口径).403 PERMISSION_DENIED), unchanged. A missing or hidden dataset is still404 NOT_FOUNDfirst.totals.groupingsandorderkeys are already judged downstream against the selected members.query_dataset's tool description now states the rule..changeset/33745-query-dataset-declared-members.md: patch (Metadata-protocol: none), BREAKING banner, ADR-0087 dispositionnot-required (no-migration-prescription).Tests
describe('query_dataset refuses a member the dataset does not declare')inpackages/services/service-analytics/src/__tests__/dataset-tools.test.ts: a raw field as a measure, the ad-hoccount, a suffix spellingamount_sum, a dataset-qualifiedpipeline.revenue, an undeclared measure beside a declared one, a raw field as a dimension and as a time dimension — eachINVALID_FIELD/ 400 withmember/param/cube, on both faces (queryDatasetandexecute), the service never called, no read. Plus: the message names only caller-usable members; a missing or hidden dataset staysNOT_FOUND; two CONTROLs (every declared measure, a derived one included, and dimensions are served; a declared time dimension reaches the service).origin/mainexecutor: 7 failed / 35 passed (before the qualified-spelling case was added).assertDeclaredMembersremoved, viascripts/ablation-replace.mjs, anchor 1 -> 0): 8 failed / 35 passed; restored, blob equal to HEAD,git diff HEADempty.expected ... not to contain 'margin_total'); restored the same way.Acceptance notes
origin/mainthe executor servedmeasures: ['amount'],['count'],dimensions: ['amount'],pipeline.revenueandpipeline.stage, each with provenance citing the raw name as a member). H2: the MCP tool (HTTP and stdio bridges,packages/runtime/src/domains/mcp.ts) and the chat registry face share this executor, so one refusal covers them; the REST doorPOST /analytics/dataset/querydoes NOT go through it (it callsAnalyticsService.queryDatasetdirectly) and is not changed: it serves dashboards, reports and ad-hoc selections, and the card's ruling names the tool's executor. H3: a dataset declares no implicitcount;countis minted by the service'sinferMeasure, so it is refused here. H4:INVALID_FIELD/ 400 (ADR-0149 D2 lists it among the codes the tool may answer; the tool invents no code).dataset.memberqualified spelling of a DECLARED member is refused too: it is not a namelist_datasetslists, and its provenance used to cite the raw spelling with no label. Called out in case a consumer relies on it.Dogfood battery (head
3f717733a13e3d0b4cbd952afa4148c5b35b196c)Dogfood Regression Gate, accepted as such by the seat (15:54Z condition, reading accepted 15:57Z). Its selector runs the full dogfood suite for this diff: inci.ymlthe job'sif:needsfilter.outputs.core != 'false', and thefilterjob forcescoreto'true'onmerge_group;OS_SEED_ONLYisqueue-verdict.outputs.covered == 'true', andqueue-verdictruns onpushonly, so onmerge_groupall three shards runturbo run test --filter=@objectstack/dogfoodin full.@objectstack/dogfooddepends on@objectstack/service-analytics, so its test hash moves with this diff (no cache hit).query_datasetcallers selectrow_count/task_count), so the battery guards against regressions rather than exercising the refusal.Verification
Session: https://claude.ai/code/session_01QsR2jUg7BKfRBcTPyMxbLh — readings at the final head are in the os-dev report comment on the card. Head
3f717733isa711894fwithorigin/mainmerged (net diff byte-identical, same patch-id).🤖 Generated with Claude Code