From 27a276c8ccb2a3cf79811b9c55b6b471bfe346ad Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 02:47:36 +0000 Subject: [PATCH 1/2] test(app-shell): pin the publish-all seed warning to the pack sentence (#35141) Claude-Session: https://claude.ai/code/session_01Utp6CbSphdunq2aJq7ktuY Co-authored-by: Claude --- ...sePublishAllDrafts.seedWarn-35141.test.tsx | 170 ++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 ui/packages/app-shell/src/preview/__tests__/usePublishAllDrafts.seedWarn-35141.test.tsx diff --git a/ui/packages/app-shell/src/preview/__tests__/usePublishAllDrafts.seedWarn-35141.test.tsx b/ui/packages/app-shell/src/preview/__tests__/usePublishAllDrafts.seedWarn-35141.test.tsx new file mode 100644 index 00000000000..511a611c644 --- /dev/null +++ b/ui/packages/app-shell/src/preview/__tests__/usePublishAllDrafts.seedWarn-35141.test.tsx @@ -0,0 +1,170 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#35141 — Home's *Publish all* and the draft-preview bar warn + * about a failed seed in the customer's words, never in the seed loader's. + * + * A failed seed answers `seedApplied.success === false`, and its `error` is + * the loader's own engine text (`seed apply stopped at the seed for object + * 'x': …`), written for whoever repairs the seed. The chat's publish-health + * line (objectstack#32984) says the pack sentence + * `chatbot.build.health.seedFailed` for it and folds the engine text away; + * the toast says the same sentence, on both of the hook's doors: the + * package batch (`publish-drafts`, read through `publishHealthFromResponse`) + * and the by-reference publish of a package-less seed. The engine text and + * the hard-coded English "NAME: sample data failed to load" never reach it. + * + * Real: the hook, `useMetadataClient` and its client, the publish-health + * reader, and `I18nProvider` with the shipped `en` and `zh-Hans` packs. + * Stubbed: `sonner` (the terminal sink) and `globalThis.fetch` (the server). + * + * Its own file: `I18nProvider` installs a module-level i18next global, which + * would leak into the key-echo `t` the other `usePublishAllDrafts` pins use. + */ + +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import type { ReactNode } from 'react'; +import { act, cleanup, renderHook, waitFor } from '@testing-library/react'; +import { I18nProvider, useObjectTranslation } from '@object-ui/i18n'; +import { en, zh } from '@object-ui/i18n/locales'; + +vi.mock('sonner', () => ({ + toast: { + warning: vi.fn(), + error: vi.fn(), + success: vi.fn(), + info: vi.fn(), + message: vi.fn(), + dismiss: vi.fn(), + }, +})); + +import { toast } from 'sonner'; +// The source under test reaches `@objectstack/lint` through a dynamic import; its +// first load is paid here, at collection, never inside a case's clock +// (`check:test-source-alias`). +import '@objectstack/lint'; +import { usePublishAllDrafts } from '../usePublishAllDrafts'; + +const PKG_ID = 'com.acme.crm'; +const SEED_NAME = 'crm_sample_rows'; +/** The seed loader's own text, as the runtime words a stopped seed apply. */ +const ENGINE_TEXT = "seed apply stopped at the seed for object 'crm_task': Reference not found: owner = \"ann\""; + +const PACK = { en, 'zh-Hans': zh } as const; +type Locale = keyof typeof PACK; +const LOCALES: Locale[] = ['en', 'zh-Hans']; + +/** What the server answers on each door; a test sets the ones it drives. */ +let drafts: Array>; +let batchBody: unknown; +let seedPublishBody: unknown; + +function json(body: unknown) { + return new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } }); +} + +/** A published batch carrying the given `seedApplied`, inside the dispatcher's envelope. */ +function batchWithSeed(seedApplied: Record) { + return { + success: true, + data: { + success: true, + outcome: 'published', + publishedCount: 1, + failedCount: 0, + published: [{ type: 'seed', name: SEED_NAME, version: 'sha256:0' }], + failed: [], + seedApplied, + }, + }; +} + +beforeEach(() => { + vi.clearAllMocks(); + drafts = []; + batchBody = undefined; + seedPublishBody = undefined; + vi.stubGlobal( + 'fetch', + vi.fn(async (input: unknown) => { + const url = String(input); + if (url.endsWith('/publish-drafts')) return json(batchBody); + if (/\/meta\/seed\/[^/]+\/publish$/.test(url)) return json(seedPublishBody); + if (url.includes('/meta/_drafts')) return json({ drafts }); + return json({ success: true, data: {} }); + }) as unknown as typeof fetch, + ); +}); + +afterEach(() => { + cleanup(); + vi.unstubAllGlobals(); +}); + +async function publishAllIn(locale: Locale) { + const wrapper = ({ children }: { children: ReactNode }) => ( + {children} + ); + const { result } = renderHook( + () => { + const { t, language } = useObjectTranslation(); + return { language, ...usePublishAllDrafts(t) }; + }, + { wrapper }, + ); + await waitFor(() => expect(result.current.language).toBe(locale)); + await act(async () => { + await result.current.publishAll(); + }); +} + +/** The one warning the publish raised: its title and its detail. */ +function seedWarning(): { title: string; description: string } { + const warnings = vi.mocked(toast.warning).mock.calls; + expect(warnings).toHaveLength(1); + const [title, opts] = warnings[0] as [string, { description: string }]; + return { title, description: opts.description }; +} + +describe('Publish all warns about a failed seed in the pack’s sentence (objectstack#35141)', () => { + it.each(LOCALES)('%s: a package batch whose seed failed with engine text shows the pack sentence', async (locale) => { + drafts = [{ type: 'seed', name: SEED_NAME, packageId: PKG_ID }]; + batchBody = batchWithSeed({ success: false, inserted: 0, updated: 0, error: ENGINE_TEXT }); + await publishAllIn(locale); + const { title, description } = seedWarning(); + expect(title).toBe(PACK[locale].home.pendingDrafts.seedWarn); + expect(description).toBe(PACK[locale].chatbot.build.health.seedFailed); + expect(description).not.toContain(ENGINE_TEXT); + expect(vi.mocked(toast.success).mock.calls).toEqual([]); + }); + + it.each(LOCALES)('%s: a package-less seed that failed with engine text shows the pack sentence', async (locale) => { + drafts = [{ type: 'seed', name: SEED_NAME, packageId: null }]; + seedPublishBody = { success: true, seedApplied: { success: false, inserted: 0, updated: 0, error: ENGINE_TEXT } }; + await publishAllIn(locale); + const { title, description } = seedWarning(); + expect(title).toBe(PACK[locale].home.pendingDrafts.seedWarn); + expect(description).toBe(PACK[locale].chatbot.build.health.seedFailed); + expect(description).not.toContain(ENGINE_TEXT); + }); + + it.each(LOCALES)('%s: a package-less seed that failed with no text shows the pack sentence, not English', async (locale) => { + drafts = [{ type: 'seed', name: SEED_NAME, packageId: null }]; + seedPublishBody = { success: true, seedApplied: { success: false, inserted: 0, updated: 0, errors: [] } }; + await publishAllIn(locale); + const { description } = seedWarning(); + expect(description).toBe(PACK[locale].chatbot.build.health.seedFailed); + expect(description).not.toContain('sample data failed to load'); + }); +}); + +describe('control: a seed that loaded reads as before (objectstack#35141)', () => { + it.each(LOCALES)('%s: a package-less seed that loaded raises no warning', async (locale) => { + drafts = [{ type: 'seed', name: SEED_NAME, packageId: null }]; + seedPublishBody = { success: true, seedApplied: { success: true, inserted: 2, updated: 0 } }; + await publishAllIn(locale); + expect(vi.mocked(toast.warning).mock.calls).toEqual([]); + expect(vi.mocked(toast.success).mock.calls).toHaveLength(1); + }); +}); From 3cf598ff98c8668acc56442e484c2e13d4ed3fc7 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 02:48:12 +0000 Subject: [PATCH 2/2] fix(app-shell): publish-all seed warning says the pack sentence, not engine text (#35141) Claude-Session: https://claude.ai/code/session_01Utp6CbSphdunq2aJq7ktuY Co-authored-by: Claude --- ...141-publish-all-seed-warn-pack-sentence.md | 12 +++++++++ .../src/preview/usePublishAllDrafts.ts | 26 +++++++------------ 2 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 .changeset/35141-publish-all-seed-warn-pack-sentence.md diff --git a/.changeset/35141-publish-all-seed-warn-pack-sentence.md b/.changeset/35141-publish-all-seed-warn-pack-sentence.md new file mode 100644 index 00000000000..8f422f4897b --- /dev/null +++ b/.changeset/35141-publish-all-seed-warn-pack-sentence.md @@ -0,0 +1,12 @@ +--- +'@object-ui/app-shell': patch +--- + +fix(console): the *Publish all* warning about failed sample data shows the pack's sentence, never the seed loader's text + +Clause-②: no +Metadata-protocol: none + +Home's *Publish all* and the draft-preview bar's *Publish* warn "Published, but some sample data failed to load." when a seed fails to load. The detail under that title printed the seed loader's own engine text (for example "seed apply stopped at the seed for object …"), and for a package-less seed with no text a hard-coded English "NAME: sample data failed to load" in every language. It now shows the sentence the AI chat's publish-health line already shows for the same failure (`chatbot.build.health.seedFailed`, from the locale pack), on both the package batch and the package-less publish. The loader's text never reaches the toast. + +No locale keys, props or exports change. diff --git a/ui/packages/app-shell/src/preview/usePublishAllDrafts.ts b/ui/packages/app-shell/src/preview/usePublishAllDrafts.ts index 6ab7b9cc5f2..76a3fe6ba11 100644 --- a/ui/packages/app-shell/src/preview/usePublishAllDrafts.ts +++ b/ui/packages/app-shell/src/preview/usePublishAllDrafts.ts @@ -97,21 +97,17 @@ export function usePublishAllDrafts(t: TranslateFn) { const packageIds = [...new Set(pending.map((d) => d.packageId).filter((p): p is string => p !== null))]; const orphans = pending.filter((d) => d.packageId === null); - const seedProblems: string[] = []; + // objectstack#35141 — whether any seed failed, on either door below. The + // toast says that in the pack's sentence, as the chat's publish-health + // line does (objectstack#32984): `seedFailed` is the failure, and the + // loader's own text (`seedError`, `seedApplied.error`) is engine text + // for whoever repairs the seed, never the customer's sentence. + let seedFailed = false; const probeProblems: NonNullable = []; let seededRows = 0; const recordHealth = (health: PublishHealth | undefined) => { if (!health) return; - // objectstack#32984 — `seedFailed` is the failure; `seedError` is only - // the producer's own text and is absent when it sent none. The rule - // the chat's publish-health line reads. With no producer text the - // toast says the line's own sentence, from the pack. - if (health.seedFailed === true || health.seedError) { - seedProblems.push( - health.seedError || - t('chatbot.build.health.seedFailed', { defaultValue: 'Sample data failed to load.' }), - ); - } + if (health.seedFailed === true || health.seedError) seedFailed = true; if (typeof health.seededRows === 'number') seededRows += health.seededRows; for (const issue of health.issues ?? []) { if (issue.severity === 'error') probeProblems.push(issue); @@ -165,9 +161,7 @@ export function usePublishAllDrafts(t: TranslateFn) { const res = await client.publishDraft(d.type, d.name, d.member ? { member: d.member } : {}); if (firstPublish) created.push({ type: d.type, name: d.name }); const seedApplied = (res as any)?.seedApplied; - if (seedApplied && seedApplied.success === false) { - seedProblems.push(seedApplied.error ?? `${d.name}: sample data failed to load`); - } + if (seedApplied && seedApplied.success === false) seedFailed = true; } if (probeProblems.length > 0) { @@ -188,10 +182,10 @@ export function usePublishAllDrafts(t: TranslateFn) { }), }, ); - } else if (seedProblems.length > 0) { + } else if (seedFailed) { toast.warning( t('home.pendingDrafts.seedWarn', { defaultValue: 'Published, but some sample data failed to load.' }), - { description: seedProblems[0] }, + { description: t('chatbot.build.health.seedFailed', { defaultValue: 'Sample data failed to load.' }) }, ); } else { toast.success(