Skip to content

Commit e542b7b

Browse files
feat(service-analytics): a word that names the field a filtered measure candidate sums is answered from that field (ADR-0149 D3 note of 2026-12-01) (#38869)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBG4YD4RMAt72Ga5PdYYZDAQ)_ Fixes #38551 Clause-②: no Metadata-protocol: none PR #38848 (ADR note) merged; origin/main is merged in at cabeb27 and the ADR-0149 blob at HEAD equals main's (0d752a3). Claim for this branch: #38551 comment 7305144268 (PR 2 of claim 7301418387). ## 维护者速读 - 用户在问数时说的词正好是某个带筛选条件的指标所汇总的字段(例如「工时」对「计费工时」),AI 不再反问,而是直接按该字段回答并注明非指标口径,顺带提一句那个更窄的指标;两个 MCP 入口(HTTP 与 stdio)行为一致。 - 属于「AI 通过数据集语义层回答业务问题」的 ADR-0149 修订落地,替云端去掉它自己那份重复的下一步逻辑,解决正式基线里不必要的反问。 - 若判断出错,最坏是某个词本该反问却被按字段回答(或反之);不带筛选的指标、跨关联路径的字段、一个词同时指向两个字段,这三种情况都保持原来的反问;改动可整体撤回,不涉及数据或元数据格式。 - ADR 修订那个 PR(#38848,定义本改动所依据的规则)已合并,且三个子问题按默认答案落定;本 PR 已合入最新 main,按合并后的规则文本实现。 ## What changes Implements the ADR-0149 D3 amendment note of 2026-12-01 (PR #38848, ruling record 7301332152: "A measure candidate whose aggregated field is named by the term is not offered as a candidate to ask back about. The field answers the term under rule 4's labelled fallback, and the measure is mentioned as a narrower declared metric."), with the zone's two later narrowings: only a measure that carries a `filter` is taken out (L2 S2 on #38848), and the reading is per candidate (L1 N4 on #38848). - **Executor** (`packages/services/service-analytics/src/dataset-term-matcher.ts`, `readDatasetTerms`). For a term with no hit, the whole near set is built uncapped; a measure candidate that carries a `filter` and whose aggregated BASE field the term names (the term equals, or is inside, the field's label in any label handed in, or its name; both sides normalized as rule 1 normalizes) is taken out, and the field is reported (`namedFields`). Then the per-term cap applies to what is left. `findDatasetTermCandidates` keeps its signature and returns the candidates of the same reading. - **Sentence** (`dataset-next-step.ts`). No new decision value and no new key. A term left with nothing is `no_measure`, its note naming the field (object and field name) and mentioning the measure as a narrower declared metric, then the labelled fallback tail. A term left with only dimensions stays `candidates_only`: the field sentence, the dimensions offered as a possible grouping, and no outright question on its account; beside a grouping word the conditional sentence of the note of 2026-11-24 is still written (L2 S1). A term left with another measure candidate is asked about what is left, and one more sentence says the field answers only when that question settles nothing. Written in all four locales. - **Labels, route A** (`DatasetToolsDeps.readFieldLabel`, optional). Both hosts wire it from the object `describe_object` serves, as this caller is served it: the authored label, and the same object through the `/meta` object translation for the answer's locale (the bundle label). HTTP: `packages/runtime/src/domains/mcp.ts`, `datasetFieldLabelRead` (`readServedObject` → `servedToCaller` → `inCallerLocale`, each object read once per request), passed to `datasetToolMembers`. stdio: `packages/mcp/src/stdio-data-bridge.ts` (`servedView.getObject` → `inServedLocale` for the i18n default locale). The executor reads a label only for a base field that a measure near a sent term aggregates, once per field per answer; a host that omits the member, or a read that throws, tests the field's name only, and the `list_datasets` description says so. - **Texts.** `LIST_DATASETS_DESCRIPTION` and `DATASET_SELECTION_RULE` carry one sentence in the same words (pinned equal); the spec's `candidates` and `nextStep.note` descriptions and the `DatasetTermCandidateSchema` doc say it (descriptions only, no shape change; `content/docs/references/ai/dataset-tools.mdx` regenerated by `check:generated --fix`); `content/docs/data-modeling/analytics.mdx` gains one bullet. **Defaults named for the seat** (not decided by the ADR, set by the zone): a measure over a relationship path (`account.amount`), `*` or no field is never taken out and keeps today's ask (base fields only; no label is read for it). Not covered by the note and kept as today: a term naming different fields through different candidates (nothing is taken out; the field set is counted over every named measure, filtered or not), and a measure with no `filter` over the named field (it stays a candidate and is asked about). ## Tests - New `packages/services/service-analytics/src/__tests__/dataset-term-names-field-38551.test.ts`, every case reading `decision`, `note` and `candidates`: the card's 工时 case (bundle label over an English-authored field), the host-omission control, a throwing read, 销售 near 销售额 over 金额 still `candidates_only` with the ask note, the unfiltered measure kept, "Billable hours" taken out beside "Total hours" kept (per candidate), dimension-only candidates byte-identical with and without the label read, dimensions left, another measure left, two fields not covered, take-out before the cap, a relationship-path measure, a left-out field word beside a `one_measure` word, the grouping-word case (L2 S1), the description (15 cases). - `packages/runtime/src/mcp-dataset-tools-bridge.test.ts` and `packages/mcp/src/stdio-data-bridge.dataset-locale.test.ts`: each host's read answers `{ authored: 'Hours', translated: '工时' }` from the object `describe_object` serves; over the REAL executor 工时 is `no_measure` with no candidate; the control (no zh-CN field label / an `en` default) keeps `candidates_only` with the ask. - `packages/mcp/src/initialize-selection-rule-34686.test.ts`: both doors carry the field sentence in the same words. - The two 金额 pins in `dataset-tools.test.ts` keep their reading unchanged (fixture measures are unfiltered and `amount` is on two objects). <details><summary>Readings at 61388b8 (revision 1; round-1 readings below where unchanged)</summary> - At 61388b8, after the merge of origin/main 2af3d78: service-analytics full test 229 files, 5935 passed / 345 skipped; typecheck exit 0; `dataset-term-names-field-38551.test.ts` 15 passed; mcp tools-list-weight + initialize-selection-rule + stdio-data-bridge.dataset-locale + mcp-dataset-tools 4 files, 61 passed; runtime mcp-dataset-tools-bridge 16 passed; spec `check:generated` green after `--fix`; 117 of 120 derived gates run and exit 0 (3 left to CI on a missing prerequisite). - S1 ablation (`!numberNamed` re-inserted on each `noNumberTail` condition): 1 of 15 red in each branch; restored to the HEAD blob. - `vitest run src/__tests__/dataset-term-names-field-38551.test.ts src/__tests__/dataset-tools.test.ts` (service-analytics, at d33cb9b): 2 files passed, 110 passed / 10 skipped. - `pnpm --filter @objectstack/service-analytics test` (at 68254f1; only description text and one test case changed since): 229 files passed, 5933 passed / 345 skipped. `typecheck`: exit 0. - `vitest run src/tools-list-weight-34689.test.ts src/initialize-selection-rule-34686.test.ts` (mcp, at d33cb9b): 2 files, 18 passed. Full `@objectstack/mcp` suite at 68254f1: 88 files passed, 1 failed (`tools-list-weight-34689`, 39002 over the 39000 ceiling) — fixed at d33cb9b by a shorter host clause, re-run green. `pnpm --filter @objectstack/mcp typecheck`: exit 0. - `vitest run src/stdio-data-bridge.dataset-locale.test.ts` (mcp): 16 passed. `vitest run src/mcp-dataset-tools-bridge.test.ts` (runtime): 16 passed. `pnpm --filter @objectstack/runtime typecheck`: exit 0 (after building `@objectstack/driver-turso`, a devDependency the worktree had not built). - `pnpm --filter @objectstack/spec check:generated`: "All 14 generated artifacts are up to date" after `--fix` regenerated `content/docs/references/ai/dataset-tools.mdx`. - Ablation 1 (the take-out set emptied, `scripts/ablation-replace.mjs`, restored to the HEAD blob with `git diff HEAD` empty): 7 of 13 cases red. Ablation 2 (the `filter` condition removed, every named measure taken out): 1 red, the unfiltered-measure case. Both restored. - `tools/list` weight (open door, 18 tools): before 38569 bytes, `list_datasets` description 2567; after 38940 bytes, description 2938 (+371); ceiling 39000 unchanged. </details> ## Acceptance notes - H1 (route A): HTTP reads the authored label off `servedToCaller(readServedObject(object))` and the bundle label off the same object through `inCallerLocale` (`translateMetaList` over `object`, `metaTranslationSources`, the locale `loadDatasets` translates for). stdio reads them off `servedView.getObject(object)` and `inServedLocale` (the i18n service's default locale). - H2: the take-out runs before the cap; pinned by "the take-out runs over the uncapped near set". - Skill text this makes stale is left to a `domain:skills` card (no `skills/**` edit here): `skills/objectstack-ask/SKILL.md` step 1's candidates bullet and step 2's table rows, `skills/objectstack-ask/evals/metric-selection-fallback.json`, and the regenerated `packages/mcp/src/ask-skill.generated.ts`. ## Verification Read first, by risk: `packages/services/service-analytics/src/dataset-term-matcher.ts` (`readDatasetTerms`, the take-out set and the cap loop); `packages/services/service-analytics/src/dataset-next-step.ts` (`readTerm`, the `candidates_only` branch, `leftOutSentences`); `packages/runtime/src/domains/mcp.ts` (`datasetFieldLabelRead`). Two-minute check: `pnpm --filter @objectstack/service-analytics exec vitest run src/__tests__/dataset-term-names-field-38551.test.ts` — expect 15 passed. Signed: repo:objectstack@os-support-ai · os-support-ai · session_01WGufzeatqKfTRUzTJVa9jQ --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzeatqKfTRUzTJVa9jQ)_ <!-- signed: repo:objectstack@os-support-ai · os-support-ai · session_01WGufzeatqKfTRUzTJVa9jQ --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 475277b commit e542b7b

14 files changed

Lines changed: 1090 additions & 43 deletions
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@objectstack/service-analytics': patch
3+
'@objectstack/runtime': patch
4+
'@objectstack/mcp': patch
5+
'@objectstack/spec': patch
6+
---
7+
8+
feat(service-analytics): a word that names the field a filtered measure candidate sums is answered from that field, not asked about
9+
10+
Clause-②: no
11+
Metadata-protocol: none
12+
13+
`list_datasets` no longer offers, as a candidate to ask back about, a measure that carries a `filter` and whose aggregated base field the word names: the word equals, or is inside, that field's label or its name (ADR-0149 D3, the amendment note of 2026-12-01). "hours" beside a measure "Billable hours" that sums the field `hours` under a filter is now answered from the field: `nextStep.note` names the field (object and field name), says to answer it with the object query tools labelled as not from a governed metric, and mentions the measure as a narrower declared metric. The measure stays listed in its dataset's entry; it is only absent from `candidates` for that word.
14+
15+
The decision values are unchanged and read as declared: a word left with no candidate is `no_measure`; a word left with dimension candidates stays `candidates_only`, with the field named and no question; a word left with another measure candidate is still asked about, and the field answers only if that question settles nothing. Unchanged, and still asked about: a measure with no `filter` over the named field, a measure over a relationship path, and a word that names different fields through different measures. The take-out runs before the per-word cap of candidates, so a measure taken out uses no slot.
16+
17+
Field labels are read by a new optional `DatasetToolsDeps.readFieldLabel` (the authored label and the translation-bundle label for the answer's locale). Both MCP doors (HTTP and stdio) wire it from the object `describe_object` serves; a host that does not tests the field's name only, as the `list_datasets` description says. The `list_datasets` description and the MCP `initialize` selection rule carry the rule in the same sentence, and the `candidates` and `nextStep.note` descriptions in `@objectstack/spec` say it.

‎content/docs/data-modeling/analytics.mdx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ not certain:
197197
list is capped for each word.
198198
- A word whose candidates are all dimensions is read as a possible grouping,
199199
and is not asked about.
200+
- A word that names the field a filtered measure sums is not asked about for
201+
that measure. "Names" means the word equals, or is inside, the field's label
202+
or its name; where the deployment translates field labels, the label in the
203+
person's language counts too. The AI answers from the field itself, says the
204+
answer is not from a governed metric, and mentions the measure as a narrower
205+
declared metric: "hours" over a `hours` field labelled "Hours" is answered
206+
from that field, with "Billable hours" (`sum` of `hours` filtered to billable
207+
entries) mentioned. A measure with no `filter`, a measure over a relationship
208+
path, and a word that names two different fields through different measures
209+
keep the question.
200210

201211
The AI chooses which words of a question to look up. When it looks up a longer
202212
phrase ("overdue deliverables") or Chinese text without word breaks

‎content/docs/references/ai/dataset-tools.mdx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const result = DatasetNextStepSchema.parse(data);
6565
| :--- | :--- | :--- | :--- |
6666
| **decision** | `Enum<'one_measure' \| 'several_measures' \| 'candidates_only' \| 'no_measure'>` | ✅ | Which case of the ADR-0149 D3 selection rule each term in `terms` is in, computed by the platform from this answer's `matches` and `candidates`. `one_measure`: the term equals exactly one measure. `several_measures`: it equals more than one measure, in one dataset or in several. `candidates_only`: it matched no member and has entries in `candidates`. `no_measure`: it equals no measure and has no entry in `candidates`. A dimension the term equals is not counted |
6767
| **terms** | `string[]` | ✅ | The caller's terms the decision is about, each as sent in the tool's `terms` input. This is the reference to the members the decision rests on, which `nextStep` does not list: they are the entries carrying one of these terms in the same answer, in a dataset's `matches` (those whose `member` is a measure) for `one_measure` and `several_measures`, and in `candidates` for `candidates_only`. `no_measure` rests on no member |
68-
| **note** | `string` | ✅ | The decision in words: finished text in the caller's locale, composed by the tool from this answer and never typed by the model. The wording is the executor's; the schema declares the slot and fixes no text (ADR-0149 M1) |
68+
| **note** | `string` | ✅ | The decision in words: finished text in the caller's locale, composed by the tool from this answer and never typed by the model. Besides this answer's members it may name, for a term, the field that term names which a filtered measure listed here aggregates and which answers it (ADR-0149 D3, the note of 2026-12-01). The wording is the executor's; the schema declares the slot and fixes no text (ADR-0149 M1) |
6969

7070

7171
---
@@ -256,7 +256,7 @@ const result = DatasetNextStepSchema.parse(data);
256256
| **datasets** | `{ name: string; label: string; description?: string; object: string; … }[]` | ✅ | The datasets this caller may query. A dataset the caller may not query is absent, the same answer as one that does not exist |
257257
| **partial** | `true` | optional | Present, and `true`, when the dataset read was degraded and `datasets` may be incomplete; `warning` says why. Absent on a complete answer |
258258
| **warning** | `string` | optional | Why the answer is partial; present exactly when `partial` is |
259-
| **candidates** | `{ term: string; dataset: string; member: string }[]` | optional | Members offered as possible readings of a term that matched no member of any listed dataset: for a clarifying question when a measure is among the term's candidates. A term whose candidates are all dimensions is offered them as a possible grouping, not for a question, and does not stop a matched measure. A candidate is not a match: its term has no entry in any dataset's `matches`. The platform selects none: the list carries no score, and its order is the listing order stated here, not a ranking. Every candidate is a member this caller may read, listed in `datasets`. Terms in the order sent; for one term, datasets in the order listed, and each dataset's measures before its dimensions, as its entry lists them; at most 5 per term, the first in that order. Present only when `terms` were sent and a term that matched nothing has a candidate; absent otherwise, never an empty list. A term with a match has no candidate |
259+
| **candidates** | `{ term: string; dataset: string; member: string }[]` | optional | Members offered as possible readings of a term that matched no member of any listed dataset: for a clarifying question when a measure is among the term's candidates. A term whose candidates are all dimensions is offered them as a possible grouping, not for a question, and does not stop a matched measure. A measure that carries a filter and whose aggregated field the term names (the term equals, or is inside, that field's label or name) is not offered for that term: the field answers it, labelled as not from a governed metric, and `nextStep.note` names the field and mentions the measure as a narrower declared metric; its dataset's entry still lists it. Such a measure is still offered when the term names different fields through different candidates, and a measure with no filter is offered as before; with another measure candidate left for the term, that one is asked about first and the field answers only if the question settles nothing. A candidate is not a match: its term has no entry in any dataset's `matches`. The platform selects none: the list carries no score, and its order is the listing order stated here, not a ranking. Every candidate is a member this caller may read, listed in `datasets`. Terms in the order sent; for one term, datasets in the order listed, and each dataset's measures before its dimensions, as its entry lists them; at most 5 per term, the first in that order. Present only when `terms` were sent and a term that matched nothing has a candidate; absent otherwise, never an empty list. A term with a match has no candidate |
260260
| **nextStep** | `{ decision: Enum<'one_measure' \| 'several_measures' \| 'candidates_only' \| 'no_measure'>; terms: string[]; note: string }` | optional | Which case of the ADR-0149 D3 selection rule the caller's `terms` are in, as the platform computed it from this answer's own `matches` and `candidates`: the case, the terms it is about and the case in words. It adds no match and no candidate and lists no member: the members it rests on are read from `matches` and `candidates` under its `terms`. Present only when `terms` were sent |
261261

262262
### Nested Shape: `ListDatasetsOutput.datasets[number]`
@@ -286,7 +286,7 @@ const result = DatasetNextStepSchema.parse(data);
286286
| :--- | :--- | :--- | :--- |
287287
| **decision** | `Enum<'one_measure' \| 'several_measures' \| 'candidates_only' \| 'no_measure'>` | ✅ | Which case of the ADR-0149 D3 selection rule each term in `terms` is in, computed by the platform from this answer's `matches` and `candidates`. `one_measure`: the term equals exactly one measure. `several_measures`: it equals more than one measure, in one dataset or in several. `candidates_only`: it matched no member and has entries in `candidates`. `no_measure`: it equals no measure and has no entry in `candidates`. A dimension the term equals is not counted |
288288
| **terms** | `string[]` | ✅ | The caller's terms the decision is about, each as sent in the tool's `terms` input. This is the reference to the members the decision rests on, which `nextStep` does not list: they are the entries carrying one of these terms in the same answer, in a dataset's `matches` (those whose `member` is a measure) for `one_measure` and `several_measures`, and in `candidates` for `candidates_only`. `no_measure` rests on no member |
289-
| **note** | `string` | ✅ | The decision in words: finished text in the caller's locale, composed by the tool from this answer and never typed by the model. The wording is the executor's; the schema declares the slot and fixes no text (ADR-0149 M1) |
289+
| **note** | `string` | ✅ | The decision in words: finished text in the caller's locale, composed by the tool from this answer and never typed by the model. Besides this answer's members it may name, for a term, the field that term names which a filtered measure listed here aggregates and which answers it (ADR-0149 D3, the note of 2026-12-01). The wording is the executor's; the schema declares the slot and fixes no text (ADR-0149 M1) |
290290

291291

292292
---

‎packages/mcp/src/initialize-selection-rule-34686.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,26 @@ describe('[#34919] initialize instructions — follow nextStep, cite sourceLine'
254254
* description (the real one, read from the executor's package), so the two
255255
* doors cannot drift apart.
256256
*/
257+
/**
258+
* [ADR-0149 D3, amendment note of 2026-12-01] A word that names the field a
259+
* filtered measure candidate aggregates is answered from that field and not
260+
* asked about for that measure: both doors say it in the same words.
261+
*/
262+
describe('[ADR-0149 D3 note of 2026-12-01] initialize instructions — the field a word names, in the same words as list_datasets', () => {
263+
const FIELD_TERM =
264+
'A word that names the field a filtered candidate measure aggregates (it equals or is inside that field\'s '
265+
+ 'label or name) is not asked about for that measure: the field answers it through the object query tools, '
266+
+ 'labelled as not from a governed metric, and the measure is mentioned as a narrower declared metric.';
267+
268+
it('both doors carry the sentence', async () => {
269+
const runtime = new MCPServerRuntime({ name: 't', version: '1.0.0' });
270+
const text = await instructionsOf(runtime, makeBridge());
271+
const list = getDatasetToolDefinitions().find((d) => d.name === LIST_DATASETS_TOOL_NAME)!;
272+
expect(text).toContain(FIELD_TERM);
273+
expect(list.description).toContain(FIELD_TERM);
274+
});
275+
});
276+
257277
describe('[#35005] initialize instructions — the ask-back is scoped in the same words as list_datasets', () => {
258278
const SCOPED =
259279
'A word whose candidates are all dimensions is at most a possible grouping: never ask about it, and it never '

‎packages/mcp/src/mcp-server-runtime.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,10 @@ const AUTHORING_CONTRACT_LINE: string | undefined = (() => {
18931893
* [#35005] that question is owed only for a word with a measure among its
18941894
* candidates: a word whose candidates are all dimensions is at most a possible
18951895
* grouping, never asked about and never a stop for a matched measure, in the
1896-
* same words as `list_datasets`' description;
1896+
* same words as `list_datasets`' description; [ADR-0149 D3, note of
1897+
* 2026-12-01] a word that names the field a filtered measure candidate
1898+
* aggregates is answered from that field, labelled, the measure mentioned as a
1899+
* narrower declared metric, again in `list_datasets`' own words;
18971900
* only a word with no match and no candidate falls back to the object tools,
18981901
* with the answer labelled. [#34919] The answer itself then states the
18991902
* case (`list_datasets` `nextStep`, composed by the service-analytics
@@ -1912,7 +1915,10 @@ const DATASET_SELECTION_RULE =
19121915
+ 'Only the user\'s own word is asked about: one you cut out of a longer phrase of the question, or reworded, '
19131916
+ 'is sent to list_datasets once more as the user wrote it instead, never the whole question. '
19141917
+ 'A word whose candidates are all dimensions is at most a possible grouping: never ask about it, and it never '
1915-
+ 'stops a matched measure. No match '
1918+
+ 'stops a matched measure. '
1919+
+ 'A word that names the field a filtered candidate measure aggregates (it equals or is inside that field\'s '
1920+
+ 'label or name) is not asked about for that measure: the field answers it through the object query tools, '
1921+
+ 'labelled as not from a governed metric, and the measure is mentioned as a narrower declared metric. No match '
19161922
+ 'and no candidates: fall back to query_records / aggregate_records and say the answer is not from a governed '
19171923
+ 'metric. The list_datasets answer states which of these cases your words are in as nextStep: follow its note, '
19181924
+ 'which reports the first of several_measures, one_measure, candidates_only, no_measure when words differ. Cite '

‎packages/mcp/src/stdio-data-bridge.dataset-locale.test.ts‎

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,104 @@ describe('[ADR-0149 D2] stdio dataset tools when the i18n service resolves but i
300300
expect(en.query.sourceLine).not.toBe(zh.query.sourceLine);
301301
});
302302
});
303+
304+
/**
305+
* [ADR-0149 D3, amendment note of 2026-12-01] The stdio bridge hands the
306+
* executor a field-label read over the object `describe_object` serves on
307+
* this transport, localized for the i18n service's default locale: the
308+
* authored label and the bundle label. The card's case over the REAL executor:
309+
* 「工时」 is the zh-CN bundle label of the field `hours`, authored "Hours",
310+
* which a filtered measure 「计费工时」 sums, so the term is answered from the
311+
* field and not asked about; with an `en` default the bundle label is not the
312+
* answer's, and the term is still asked about.
313+
*/
314+
describe('[ADR-0149 D3] stdio dataset tools read a field\'s label for the term-names-field test', () => {
315+
const TIMESHEET = {
316+
name: 'timesheet',
317+
label: 'Timesheet',
318+
fields: { id: { type: 'text', label: 'Id' }, hours: { type: 'number', label: 'Hours' }, billable: { type: 'boolean', label: 'Billable' } },
319+
};
320+
const TIMESHEETS = {
321+
name: 'timesheets',
322+
label: 'Timesheets',
323+
object: 'timesheet',
324+
dimensions: [],
325+
measures: [{ name: 'billable_hours', label: '计费工时', aggregate: 'sum', field: 'hours', filter: { billable: true } }],
326+
};
327+
const ZH_FIELD = { objects: { timesheet: { fields: { hours: { label: '工时' } } } } };
328+
329+
async function wiredAnalytics(): Promise<AnalyticsService> {
330+
const engine = {
331+
execute: async () => ({ rows: [] }),
332+
hasObjectMiddleware: () => false,
333+
getObject: (name: string) => (name === 'timesheet' ? TIMESHEET : undefined),
334+
resolveEffectiveDatasource: () => undefined,
335+
};
336+
const security = {
337+
getReadFilter: async () => undefined,
338+
canReadObject: () => true,
339+
getReadableFields: async () => Object.keys(TIMESHEET.fields),
340+
getQueryableFields: async () => Object.keys(TIMESHEET.fields),
341+
};
342+
const registered: Record<string, unknown> = { data: engine, security };
343+
const ctx = {
344+
getService: (name: string) => registered[name],
345+
registerService: (name: string, svc: unknown) => { registered[name] = svc; },
346+
replaceService: (name: string, svc: unknown) => { registered[name] = svc; },
347+
logger: { info() {}, warn() {}, error() {}, debug() {} },
348+
};
349+
await new AnalyticsServicePlugin({ queryCapabilities: () => ({ nativeSql: true, objectqlAggregate: false, inMemory: false }) }).init(ctx as never);
350+
return registered.analytics as AnalyticsService;
351+
}
352+
353+
async function bridgeWithDefault(defaultLocale: string) {
354+
const analytics = await wiredAnalytics();
355+
const bound: Array<Parameters<StdioDatasetToolsService['datasetTools']>[0]> = [];
356+
const spy: StdioDatasetToolsService = {
357+
datasetTools: (deps) => {
358+
bound.push(deps);
359+
return analytics.datasetTools(deps as never);
360+
},
361+
};
362+
const bridge = createStdioDataBridge({
363+
engine: {} as any,
364+
metadataService: { list: async () => [] } as any,
365+
protocol: () => ({
366+
getMetaItems: async ({ type }: { type: string }) => ({ items: type === 'dataset' ? [TIMESHEETS] : type === 'object' ? [TIMESHEET] : [] }),
367+
}) as any,
368+
resolvePrincipal: async () => PRINCIPAL as any,
369+
datasetTools: spy,
370+
i18n: () => ({
371+
getLocales: () => ['zh-CN', 'en'],
372+
getTranslations: (locale: string) => (locale === 'zh-CN' ? ZH_FIELD : {}),
373+
getDefaultLocale: () => defaultLocale,
374+
}),
375+
});
376+
return { bridge, bound };
377+
}
378+
379+
it('the read answers the authored label and the bundle label for the default locale, from the object describe_object serves', async () => {
380+
const { bridge, bound } = await bridgeWithDefault('zh-CN');
381+
bridge.datasetToolDefinitions!();
382+
const read = bound[0].readFieldLabel!;
383+
expect(await read('timesheet', 'hours', undefined)).toEqual({ authored: 'Hours', translated: '工时' });
384+
expect(await read('timesheet', 'no_such_field', undefined)).toEqual({ authored: undefined, translated: undefined });
385+
expect(await read('no_such_object', 'hours', undefined)).toBeUndefined();
386+
});
387+
388+
it('工时, the bundle label of the field a filtered measure sums ⇒ no_measure, no candidate, the field named', async () => {
389+
const { bridge } = await bridgeWithDefault('zh-CN');
390+
const answer = (await bridge.listDatasets!({ terms: ['工时'] })) as ListDatasetsOutput;
391+
expect(answer.nextStep!.decision).toBe('no_measure');
392+
expect(answer.candidates).toBeUndefined();
393+
expect(answer.nextStep!.note).toContain('「工时」指的是字段 工时(对象 "timesheet"、字段 "hours")');
394+
});
395+
396+
it('control: an en default, so the bundle label is not the answer\'s, and 工时 is still a candidate and asked about', async () => {
397+
const { bridge } = await bridgeWithDefault('en');
398+
const answer = (await bridge.listDatasets!({ terms: ['工时'] })) as ListDatasetsOutput;
399+
expect(answer.nextStep!.decision).toBe('candidates_only');
400+
expect(answer.candidates).toEqual([{ term: '工时', dataset: 'timesheets', member: 'measures.billable_hours' }]);
401+
expect(answer.nextStep!.note).toContain('ask the user which one they mean');
402+
});
403+
});

0 commit comments

Comments
 (0)