Skip to content

Commit e81eccc

Browse files
fix(console): the publish-all probe warning shows a finding's userMessage, never its agent message (#35139)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8AJJJRiYjshMUNgyMZSqBsr)_ Fixes #34553 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:首页「全部发布」和草稿预览条的「发布」在运行检查发现错误时,提示「已发布,但校验发现问题」下方的说明不再原样打印写给 AI 的英文 `message`。错误带有客户句(`userMessage`)时显示这句话;都没带时,显示 AI 对话发布健康行在同样情况下显示的通用句(`chatbot.build.issuesSummary`,来自语言包)。`message` 和 `fix` 不再进入提示。 - 为什么改:#32984 Q1 裁决:面向用户的文字显示 `userMessage`,永不显示开发者的 `message`。对话里的健康行已按此改好(#34539),这个提示还没改。 - 风险与回滚:只改提示说明的取值,标题、成功提示、示例数据提示和失败提示都不变;不新增语言包键、不改导出。回滚就是 revert 本 PR。卡片点名的第二处 `PendingDraftsBar` 在当前 main 上已经不再发布、也没有任何提示(见 Acceptance notes),本 PR 不改它。 - 先看:`ui/packages/app-shell/src/preview/usePublishAllDrafts.ts` 里 `probeProblems` 的取值和 `toast.warning` 的 `description`。 - 两分钟验证:`pnpm --dir ui exec vitest run packages/app-shell/src/preview/__tests__/usePublishAllDrafts.userMessage-34553.test.tsx`,预期 6 个用例全部通过(en 与 zh-Hans 各 3 个)。 - 需要你做的:无,席位落地。 ## What changes `usePublishAllDrafts` (shared by Home's *Publish all* and the draft-preview bar) collected the error-severity probe findings as their `message` strings and printed the first as the detail of the "Published, but verification found problems." warning. It now keeps the findings themselves and gives the toast: - the `userMessage` of the first error that carries one: the producer's sentence for the person who published, already in the request's language; else - `t('chatbot.build.issuesSummary')`, the generic sentence the chat's `PublishHealthLine` shows for an error set whose findings carry no `userMessage`. `message` and `fix` reach no user-facing text. The findings are read through the existing `publishHealthFromResponse` reader from `@object-ui/plugin-chatbot/core`, which already reads `userMessage`. No second reader is written, and no locale key is added. Changeset: `@object-ui/app-shell` patch. ## Tests New file `usePublishAllDrafts.userMessage-34553.test.tsx`: the real hook, the real client and health reader, and `I18nProvider` with the shipped packs. Three cases, each run in `en` and `zh-Hans`: 1. An error with a `userMessage`: the detail is that sentence, and contains neither `message` nor `fix`. 2. An error with no `userMessage`: the detail is the pack's `chatbot.build.issuesSummary`, read from the shipped `en` / `zh` pack objects, and not `message`. 3. An unvoiced error ahead of a voiced one: the voiced sentence is shown. It is its own file because `I18nProvider` installs a module-level i18next global, which would leak into the key-echo `t` the other `usePublishAllDrafts` pins use. ## Acceptance notes - **Premise, half held.** The hook's toast printed `issues[].message`, as the card says. `PendingDraftsBar` (`ui/packages/app-shell/src/console/ai/PendingDraftsBar.tsx`) no longer publishes on `origin/main`: since the one-Publish change of #34610 it only counts drafts and points to the shell's bar, and it imports no `toast` and reads no publish health. Its publish now goes through this hook, so this change covers it. - The toast holds one detail line. It shows the first voiced error, the first row the health line shows for the same set; it does not list several findings. - The generic sentence ends "Reply \"fix the problems\" and the assistant will repair them." In the chat that is an instruction the user can follow; on Home's *Publish all* there is no assistant thread next to the toast. The card's ruling says to use #34539's choice for an issue with no `userMessage`, so this PR uses it unchanged. Whether the Home toast should get its own sentence is a question for the seat. - Out of scope, unchanged: the seed-failure detail still prints the producer's `seedError` text when one is sent, and the package-less by-reference loop still builds `NAME: sample data failed to load` in English. The chat's health line shows only the localized sentence there. The issue is reported to the seat, not handled here. ## Verification <details><summary>Readings (head 386fb89, session_01JQwxbYRqkDAGuse5Wqbohi)</summary> - Build closure `pnpm --workspace-concurrency=2 --filter '@object-ui/app-shell^...' build` under os-verify-lock: VERDICT command-exit 0. - `vitest run` the new pin plus the four sibling `usePublishAllDrafts.*` test files: Test Files 5 passed (5), Tests 22 passed (22). VERDICT command-exit 0. - `pnpm --filter @object-ui/app-shell run type-check` (both tsc programs, the test layer included): VERDICT command-exit 0. - Ablation (`scripts/ablation-replace.mjs`): the description read changed back to `probeProblems[0]?.message`. Anchor 1 to 0, blob 6ab7b9c to c69f90a21991. The pin went red, Tests 6 failed (6): every case in both locales. Restored: blob equals HEAD (6ab7b9c) and `git diff HEAD` is empty. The test imports the hook by relative path from `src`, so no `dist` is in the resolution path. - Derived gates (`dispatch-gates --commands`, 38): 38 derived, 38 run, each exit 0 captured before any pipe; `--ran` reconciliation: 0 NOT-MEASURED, a derived zero. `check:type-check-debt` first answered exit 3 (PREREQUISITE NOT MET: its closure build timed out on the shared lock queue), and a rerun answered exit 0. `vitest run scripts/` (ui): Test Files 171 passed, 2 skipped (173); Tests 5092 passed, 2 skipped. - `overlap-check.mjs`: origin/main merges cleanly, 0 open PR heads share a file. VERDICT clean exit 0. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01JQwxbYRqkDAGuse5Wqbohi --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f796089 commit e81eccc

3 files changed

Lines changed: 191 additions & 3 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(console): the *Publish all* warning about a failed runtime check shows the customer's sentence, never the agent's text
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Home's *Publish all* and the draft-preview bar's *Publish* warn "Published, but verification found problems." when a publish's runtime checks (ADR-0038 L3 probes) find an error. The detail under that title printed the finding's `message`, which is English written for the AI agent that repairs the build. It now shows the finding's `userMessage`, the sentence the platform writes for the person who published, in the request's language. When no error carries one, the detail is the generic sentence the AI chat's publish-health line already shows for the same case (`chatbot.build.issuesSummary`, from the locale pack). A finding's `message` and `fix` never reach the toast.
11+
12+
No locale keys, props or exports change.
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#34553 — Home's *Publish all* and the draft-preview bar warn
5+
* about a publish whose runtime probes found an error in the customer's
6+
* words, never in the agent's.
7+
*
8+
* A probe finding carries two channels (objectstack#32984, ruling B: the
9+
* producer of a finding writes the customer sentence): `message` and `fix`
10+
* are written for the agent that repairs the build; `userMessage` is the
11+
* sentence for the person who published, already in the request's language.
12+
* The toast shows `userMessage`; for an error with none it shows the generic
13+
* sentence the chat's publish-health line shows (`chatbot.build.issuesSummary`),
14+
* from the locale pack. `message` and `fix` never reach it.
15+
*
16+
* Real: the hook, `useMetadataClient` and its client, the publish-health
17+
* reader, and `I18nProvider` with the shipped `en` and `zh-Hans` packs.
18+
* Stubbed: `sonner` (the terminal sink) and `globalThis.fetch` (the server).
19+
*
20+
* Its own file: `I18nProvider` installs a module-level i18next global, which
21+
* would leak into the key-echo `t` the other `usePublishAllDrafts` pins use.
22+
*/
23+
24+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
25+
import type { ReactNode } from 'react';
26+
import { act, cleanup, renderHook, waitFor } from '@testing-library/react';
27+
import { I18nProvider, useObjectTranslation } from '@object-ui/i18n';
28+
import { en, zh } from '@object-ui/i18n/locales';
29+
30+
vi.mock('sonner', () => ({
31+
toast: {
32+
warning: vi.fn(),
33+
error: vi.fn(),
34+
success: vi.fn(),
35+
info: vi.fn(),
36+
message: vi.fn(),
37+
dismiss: vi.fn(),
38+
},
39+
}));
40+
41+
import { toast } from 'sonner';
42+
// The source under test reaches `@objectstack/lint` through a dynamic import; its
43+
// first load is paid here, at collection, never inside a case's clock
44+
// (`check:test-source-alias`).
45+
import '@objectstack/lint';
46+
import { usePublishAllDrafts } from '../usePublishAllDrafts';
47+
48+
const PKG_ID = 'com.acme.crm';
49+
const AGENT_MESSAGE = "dashboard 'crm_board' widget 'open_tasks': query returned 0 rows although object 'crm_task' has 12";
50+
const AGENT_FIX = "check the dataset 'crm_task_totals' measures and dimensions";
51+
52+
/** The producer's sentence per locale, as `build-probes.user-text.ts` words an `empty_query`. */
53+
const USER_MESSAGE: Record<string, string> = {
54+
en: 'The widget "Open tasks" on dashboard "Task board" shows no data, although "Tasks" has records. Check the fields that its dataset "Task totals" measures and groups by, then publish again.',
55+
'zh-Hans': '仪表盘“团队看板”中的组件“未完成任务”没有显示任何数据,但“Tasks”中有记录。请检查其数据集“任务统计”所度量和分组的字段,然后重新发布。',
56+
};
57+
58+
/** The generic sentence each shipped pack holds for an error set with no customer sentence. */
59+
const PACK = { en, 'zh-Hans': zh } as const;
60+
type Locale = keyof typeof PACK;
61+
const LOCALES: Locale[] = ['en', 'zh-Hans'];
62+
const issuesSummaryIn = (locale: Locale): string =>
63+
PACK[locale].chatbot.build.issuesSummary;
64+
65+
let batchBody: unknown;
66+
67+
function json(body: unknown) {
68+
return new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
69+
}
70+
71+
/** A published batch whose probes found the given issues, inside the dispatcher's envelope. */
72+
function publishedWith(issues: Array<Record<string, unknown>>) {
73+
return {
74+
success: true,
75+
data: {
76+
success: true,
77+
outcome: 'published',
78+
publishedCount: 1,
79+
failedCount: 0,
80+
published: [{ type: 'view', name: 'lead_list', version: 'sha256:0' }],
81+
failed: [],
82+
probes: { checked: { seeds: 0, views: 1, widgets: 1, objects: 0 }, issues },
83+
},
84+
};
85+
}
86+
87+
beforeEach(() => {
88+
vi.clearAllMocks();
89+
vi.stubGlobal(
90+
'fetch',
91+
vi.fn(async (input: unknown) => {
92+
const url = String(input);
93+
if (url.endsWith('/publish-drafts')) return json(batchBody);
94+
if (url.includes('/meta/_drafts')) {
95+
return json({ drafts: [{ type: 'view', name: 'lead_list', packageId: PKG_ID }] });
96+
}
97+
return json({ success: true, data: {} });
98+
}) as unknown as typeof fetch,
99+
);
100+
});
101+
102+
afterEach(() => {
103+
cleanup();
104+
vi.unstubAllGlobals();
105+
});
106+
107+
async function publishAllIn(locale: Locale) {
108+
const wrapper = ({ children }: { children: ReactNode }) => (
109+
<I18nProvider config={{ defaultLanguage: locale, detectBrowserLanguage: false }}>{children}</I18nProvider>
110+
);
111+
const { result } = renderHook(
112+
() => {
113+
const { t, language } = useObjectTranslation();
114+
return { language, ...usePublishAllDrafts(t) };
115+
},
116+
{ wrapper },
117+
);
118+
await waitFor(() => expect(result.current.language).toBe(locale));
119+
await act(async () => {
120+
await result.current.publishAll();
121+
});
122+
}
123+
124+
/** The one probe warning the publish raised: its title and its detail. */
125+
function probeWarning(): { title: string; description: string } {
126+
const warnings = vi.mocked(toast.warning).mock.calls;
127+
expect(warnings).toHaveLength(1);
128+
const [title, opts] = warnings[0] as [string, { description: string }];
129+
return { title, description: opts.description };
130+
}
131+
132+
describe('Publish all warns about a probe error in the customer’s words (objectstack#34553)', () => {
133+
it.each(LOCALES)('%s: an error with a userMessage shows that sentence, not message or fix', async (locale) => {
134+
batchBody = publishedWith([
135+
{ layer: 'L3', severity: 'error', artifact: 'dashboard', code: 'empty_query', message: AGENT_MESSAGE, fix: AGENT_FIX, userMessage: USER_MESSAGE[locale] },
136+
]);
137+
await publishAllIn(locale);
138+
const { description } = probeWarning();
139+
expect(description).toBe(USER_MESSAGE[locale]);
140+
expect(description).not.toContain(AGENT_MESSAGE);
141+
expect(description).not.toContain(AGENT_FIX);
142+
expect(vi.mocked(toast.success).mock.calls).toEqual([]);
143+
});
144+
145+
it.each(LOCALES)('%s: an error with no userMessage shows the pack’s generic sentence, not message', async (locale) => {
146+
batchBody = publishedWith([
147+
{ layer: 'L3', severity: 'error', artifact: 'dashboard', code: 'empty_query', message: AGENT_MESSAGE, fix: AGENT_FIX },
148+
]);
149+
await publishAllIn(locale);
150+
const { description } = probeWarning();
151+
expect(description).toBe(issuesSummaryIn(locale));
152+
expect(description).not.toContain(AGENT_MESSAGE);
153+
});
154+
155+
it.each(LOCALES)('%s: the first error that carries a sentence speaks, ahead of an unvoiced one', async (locale) => {
156+
batchBody = publishedWith([
157+
{ layer: 'L3', severity: 'error', artifact: 'view', code: 'view_read_failed', message: 'view lead_list: read failed' },
158+
{ layer: 'L3', severity: 'error', artifact: 'dashboard', code: 'empty_query', message: AGENT_MESSAGE, userMessage: USER_MESSAGE[locale] },
159+
]);
160+
await publishAllIn(locale);
161+
expect(probeWarning().description).toBe(USER_MESSAGE[locale]);
162+
});
163+
});

‎ui/packages/app-shell/src/preview/usePublishAllDrafts.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function usePublishAllDrafts(t: TranslateFn) {
9898
const orphans = pending.filter((d) => d.packageId === null);
9999

100100
const seedProblems: string[] = [];
101-
const probeProblems: string[] = [];
101+
const probeProblems: NonNullable<PublishHealth['issues']> = [];
102102
let seededRows = 0;
103103
const recordHealth = (health: PublishHealth | undefined) => {
104104
if (!health) return;
@@ -114,7 +114,7 @@ export function usePublishAllDrafts(t: TranslateFn) {
114114
}
115115
if (typeof health.seededRows === 'number') seededRows += health.seededRows;
116116
for (const issue of health.issues ?? []) {
117-
if (issue.severity === 'error') probeProblems.push(issue.message);
117+
if (issue.severity === 'error') probeProblems.push(issue);
118118
}
119119
};
120120

@@ -171,9 +171,22 @@ export function usePublishAllDrafts(t: TranslateFn) {
171171
}
172172

173173
if (probeProblems.length > 0) {
174+
// objectstack#32984 ruling B, as the chat's publish-health line reads
175+
// it: a finding speaks only through its producer's customer sentence
176+
// (`userMessage`, already in the request's language). `message` and
177+
// `fix` are the agent's text and never reach the toast. With no
178+
// sentence on any error, the line's generic sentence for an error set.
179+
const voiced = probeProblems.find((issue) => issue.userMessage)?.userMessage;
174180
toast.warning(
175181
t('home.pendingDrafts.probeWarn', { defaultValue: 'Published, but verification found problems.' }),
176-
{ description: probeProblems[0] },
182+
{
183+
description:
184+
voiced ??
185+
t('chatbot.build.issuesSummary', {
186+
defaultValue:
187+
'Some parts of this build need fixing before it is ready. Reply "fix the problems" and the assistant will repair them.',
188+
}),
189+
},
177190
);
178191
} else if (seedProblems.length > 0) {
179192
toast.warning(

0 commit comments

Comments
 (0)