You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by "liuxiaocs7 (via GitHub)" <gi...@apache.org> on 2026/08/26 16:34:15 UTC

[PR] test(desktop): story-cover the renderer crash fallback (#3943) [maka]

liuxiaocs7 opened a new pull request, #3947:
URL: https://github.com/apache/maka/pull/3947

   ## What
   
   Closes #3943.
   
   The top-level renderer `ErrorBoundary` (`apps/desktop/src/renderer/error-boundary.tsx`) had no Storybook coverage — `grep -rl "ErrorBoundary" apps/desktop/stories packages/ui/stories` returned nothing. It is by construction the surface hardest to reach in normal use and the one whose correctness matters most when reached: a crash the user cannot read or copy is a crash we never hear about. Its four `copyState` values (`idle`/`pending`/`copied`/`failed`) and the repeat-error path could only be seen by actually crashing the app (and the failed-copy state only by additionally failing the clipboard bridge).
   
   ## Changes
   
   - **Extract `ErrorBoundaryFallback`** — a pure presentational component carved out of the class (which still owns all state and side effects, `getDerivedStateFromError`/`componentDidCatch`/copy/reset/reload). This lets the crash face render in isolation, mirroring the `ErrorBoundaryFallback.stories.tsx` prior art from Lody the issue cites. Also exports an `ErrorBoundaryCopyState` type. Behavior is unchanged.
   - **Add `apps/desktop/stories/error-boundary.stories.tsx`** — one story per state (default fallback, copy pending, copied, copy failed, repeat error), each with a falsifiable `// Real path:` annotation per `stories/FIDELITY.md`.
   
   Rendering the fallback directly (rather than triggering a real throw) is deliberate: it keeps the render smoke free of the `console.error` that `componentDidCatch` — and React's own caught-error logging — would otherwise emit and fail on, and it makes every state deterministic at mount without relying on `play`.
   
   ## Verification
   
   - `biome lint` — clean
   - `tsc` (`tsconfig.storybook.json` + `tsconfig.renderer.json`) — pass
   - `npm run build-storybook` — success; all five `product-shell-error-boundary--*` stories in the index
   - `npm run smoke:storybook` — **passed (200 stories)**, all five new stories render clean
   
   *AI use: Claude Code assisted with the refactor and story authoring; the design and verification are my own.*


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] test(desktop): story-cover the renderer crash fallback [maka]

Posted by "liuxiaocs7 (via GitHub)" <gi...@apache.org>.
liuxiaocs7 commented on code in PR #3947:
URL: https://github.com/apache/maka/pull/3947#discussion_r3886151031


##########
apps/desktop/stories/error-boundary.stories.tsx:
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import type { Meta, StoryObj } from '@storybook/react-vite';
+import { fn } from 'storybook/test';
+import type { ErrorInfo } from 'react';
+import {
+  ErrorBoundaryFallback,
+  type ErrorBoundaryCopyState,
+} from '../src/renderer/error-boundary';
+
+const meta = {
+  title: 'Product/Shell/Error Boundary',
+  parameters: { layout: 'fullscreen' },
+} satisfies Meta;
+
+export default meta;
+type Story = StoryObj<typeof meta>;
+
+// The class owns the copy/reset/reload side effects; the fallback only paints,
+// so these mocks stand in for the wired handlers without touching state.
+const onCopyReport = fn();
+const onReset = fn();
+const onReload = fn();
+
+// A representative renderer crash: a real Error carrying a synthetic renderer
+// stack + React component stack, the same shape componentDidCatch hands render().
+function buildRendererError(name: string, message: string, frames: string[]): Error {
+  const error = new Error(message);
+  error.name = name;
+  error.stack = [`${name}: ${message}`, ...frames.map((frame) => `    at ${frame}`)].join('\n');
+  return error;
+}
+
+const transcriptError = buildRendererError(
+  'TypeError',
+  "Cannot read properties of undefined (reading 'messages')",
+  [
+    'SessionTranscript (src/renderer/features/workbar/session-transcript.tsx:142:31)',

Review Comment:
   Addressed in `472ebae0f`. The diagnostic data is now explicitly labeled synthetic, the invented Maka symbols and paths have been replaced with generic `Synthetic*` fixture frames, and the Story comments describe these as visual snapshots rather than real execution paths. Story typecheck, Storybook build, and the full 199-story render/accessibility smoke all pass.



##########
apps/desktop/stories/error-boundary.stories.tsx:
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import type { Meta, StoryObj } from '@storybook/react-vite';
+import { fn } from 'storybook/test';
+import type { ErrorInfo } from 'react';
+import {
+  ErrorBoundaryFallback,
+  type ErrorBoundaryCopyState,
+} from '../src/renderer/error-boundary';
+
+const meta = {
+  title: 'Product/Shell/Error Boundary',
+  parameters: { layout: 'fullscreen' },
+} satisfies Meta;
+
+export default meta;
+type Story = StoryObj<typeof meta>;
+
+// The class owns the copy/reset/reload side effects; the fallback only paints,
+// so these mocks stand in for the wired handlers without touching state.
+const onCopyReport = fn();
+const onReset = fn();
+const onReload = fn();
+
+// A representative renderer crash: a real Error carrying a synthetic renderer
+// stack + React component stack, the same shape componentDidCatch hands render().
+function buildRendererError(name: string, message: string, frames: string[]): Error {
+  const error = new Error(message);
+  error.name = name;
+  error.stack = [`${name}: ${message}`, ...frames.map((frame) => `    at ${frame}`)].join('\n');
+  return error;
+}
+
+const transcriptError = buildRendererError(
+  'TypeError',
+  "Cannot read properties of undefined (reading 'messages')",
+  [
+    'SessionTranscript (src/renderer/features/workbar/session-transcript.tsx:142:31)',
+    'renderWithHooks (react-dom.development.js:15486:18)',
+    'mountIndeterminateComponent (react-dom.development.js:20103:13)',
+    'beginWork (react-dom.development.js:21626:16)',
+  ],
+);
+
+const transcriptComponentStack: ErrorInfo = {
+  componentStack: [
+    '',
+    '    at SessionTranscript (src/renderer/features/workbar/session-transcript.tsx:142:31)',
+    '    at WorkbarPanel',
+    '    at AppShell',
+    '    at ErrorBoundary (src/renderer/error-boundary.tsx:73:1)',
+  ].join('\n'),
+};
+
+// A second, different error — what the boundary catches when the still-broken
+// subtree throws again after 重试.
+const retryError = buildRendererError('RangeError', 'Maximum call stack size exceeded', [
+  'toTreeNode (src/renderer/features/workbar/plan-tree.tsx:88:12)',
+  'toTreeNode (src/renderer/features/workbar/plan-tree.tsx:91:20)',
+  'toTreeNode (src/renderer/features/workbar/plan-tree.tsx:91:20)',
+]);
+
+const retryComponentStack: ErrorInfo = {
+  componentStack: [
+    '',
+    '    at PlanTree (src/renderer/features/workbar/plan-tree.tsx:88:12)',
+    '    at WorkbarPanel',
+    '    at AppShell',
+    '    at ErrorBoundary (src/renderer/error-boundary.tsx:73:1)',
+  ].join('\n'),
+};
+
+const resolveLocale = (globals: Record<string, unknown>) => (globals.locale === 'en' ? 'en' : 'zh');
+
+function fallback(copyState: ErrorBoundaryCopyState, error: Error, errorInfo: ErrorInfo) {
+  return (_args: unknown, { globals }: { globals: Record<string, unknown> }) => (
+    <ErrorBoundaryFallback
+      error={error}
+      errorInfo={errorInfo}
+      copyState={copyState}
+      locale={resolveLocale(globals)}
+      onCopyReport={onCopyReport}
+      onReset={onReset}
+      onReload={onReload}
+    />
+  );
+}
+
+// Real path: the renderer throws during render; ErrorBoundary.getDerivedStateFromError
+// + componentDidCatch capture the error and React component stack, and render() paints
+// this fallback with copyState 'idle'.
+export const DefaultFallback: Story = {
+  render: fallback('idle', transcriptError, transcriptComponentStack),
+};
+
+// Real path: on the crash screen the user clicks 复制诊断信息; handleCopyReport sets
+// copyState 'pending' while window.maka.diagnostics.copyReport is in flight, disabling
+// the button (isDisabled + aria-busy).
+export const CopyPending: Story = {
+  render: fallback('pending', transcriptError, transcriptComponentStack),
+};
+
+// Real path: continues from copy pending — diagnostics.copyReport resolves, handleCopyReport
+// sets copyState 'copied' and the copy button swaps to the check glyph.
+export const Copied: Story = {
+  render: fallback('copied', transcriptError, transcriptComponentStack),
+};
+
+// Real path: continues from copy pending — the clipboard bridge (diagnostics.copyReport, or
+// the navigator.clipboard fallback) rejects, handleCopyReport sets copyState 'failed', and the
+// manual-select hint appears below the actions.
+export const CopyFailed: Story = {
+  render: fallback('failed', transcriptError, transcriptComponentStack),
+};
+
+// Real path: after 重试 (handleReset clears the error) the still-broken subtree throws a

Review Comment:
   Addressed in `472ebae0f`. I removed `RepeatError` and its second-error fixtures rather than claiming reset-and-rethrow coverage from a static fallback rendering. The production comment was updated accordingly. Story typecheck, Storybook build, and the full 199-story render/accessibility smoke all pass.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] test(desktop): story-cover the renderer crash fallback [maka]

Posted by "liuxiaocs7 (via GitHub)" <gi...@apache.org>.
liuxiaocs7 commented on code in PR #3947:
URL: https://github.com/apache/maka/pull/3947#discussion_r3886151020


##########
apps/desktop/stories/error-boundary.stories.tsx:
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import type { Meta, StoryObj } from '@storybook/react-vite';
+import { fn } from 'storybook/test';
+import type { ErrorInfo } from 'react';
+import {
+  ErrorBoundaryFallback,
+  type ErrorBoundaryCopyState,
+} from '../src/renderer/error-boundary';
+
+const meta = {
+  title: 'Product/Shell/Error Boundary',
+  parameters: { layout: 'fullscreen' },
+} satisfies Meta;
+
+export default meta;
+type Story = StoryObj<typeof meta>;
+
+// The class owns the copy/reset/reload side effects; the fallback only paints,
+// so these mocks stand in for the wired handlers without touching state.
+const onCopyReport = fn();
+const onReset = fn();
+const onReload = fn();
+
+// A representative renderer crash: a real Error carrying a synthetic renderer
+// stack + React component stack, the same shape componentDidCatch hands render().
+function buildRendererError(name: string, message: string, frames: string[]): Error {
+  const error = new Error(message);
+  error.name = name;
+  error.stack = [`${name}: ${message}`, ...frames.map((frame) => `    at ${frame}`)].join('\n');
+  return error;
+}
+
+const transcriptError = buildRendererError(
+  'TypeError',
+  "Cannot read properties of undefined (reading 'messages')",
+  [
+    'SessionTranscript (src/renderer/features/workbar/session-transcript.tsx:142:31)',
+    'renderWithHooks (react-dom.development.js:15486:18)',
+    'mountIndeterminateComponent (react-dom.development.js:20103:13)',
+    'beginWork (react-dom.development.js:21626:16)',
+  ],
+);
+
+const transcriptComponentStack: ErrorInfo = {
+  componentStack: [
+    '',
+    '    at SessionTranscript (src/renderer/features/workbar/session-transcript.tsx:142:31)',
+    '    at WorkbarPanel',
+    '    at AppShell',
+    '    at ErrorBoundary (src/renderer/error-boundary.tsx:73:1)',
+  ].join('\n'),
+};
+
+// A second, different error — what the boundary catches when the still-broken
+// subtree throws again after 重试.
+const retryError = buildRendererError('RangeError', 'Maximum call stack size exceeded', [
+  'toTreeNode (src/renderer/features/workbar/plan-tree.tsx:88:12)',
+  'toTreeNode (src/renderer/features/workbar/plan-tree.tsx:91:20)',
+  'toTreeNode (src/renderer/features/workbar/plan-tree.tsx:91:20)',
+]);
+
+const retryComponentStack: ErrorInfo = {
+  componentStack: [
+    '',
+    '    at PlanTree (src/renderer/features/workbar/plan-tree.tsx:88:12)',
+    '    at WorkbarPanel',
+    '    at AppShell',
+    '    at ErrorBoundary (src/renderer/error-boundary.tsx:73:1)',
+  ].join('\n'),
+};
+
+const resolveLocale = (globals: Record<string, unknown>) => (globals.locale === 'en' ? 'en' : 'zh');
+
+function fallback(copyState: ErrorBoundaryCopyState, error: Error, errorInfo: ErrorInfo) {
+  return (_args: unknown, { globals }: { globals: Record<string, unknown> }) => (
+    <ErrorBoundaryFallback
+      error={error}
+      errorInfo={errorInfo}
+      copyState={copyState}
+      locale={resolveLocale(globals)}
+      onCopyReport={onCopyReport}
+      onReset={onReset}
+      onReload={onReload}
+    />
+  );
+}
+
+// Real path: the renderer throws during render; ErrorBoundary.getDerivedStateFromError
+// + componentDidCatch capture the error and React component stack, and render() paints
+// this fallback with copyState 'idle'.
+export const DefaultFallback: Story = {
+  render: fallback('idle', transcriptError, transcriptComponentStack),
+};
+
+// Real path: on the crash screen the user clicks 复制诊断信息; handleCopyReport sets
+// copyState 'pending' while window.maka.diagnostics.copyReport is in flight, disabling
+// the button (isDisabled + aria-busy).
+export const CopyPending: Story = {
+  render: fallback('pending', transcriptError, transcriptComponentStack),
+};
+
+// Real path: continues from copy pending — diagnostics.copyReport resolves, handleCopyReport
+// sets copyState 'copied' and the copy button swaps to the check glyph.
+export const Copied: Story = {
+  render: fallback('copied', transcriptError, transcriptComponentStack),
+};
+
+// Real path: continues from copy pending — the clipboard bridge (diagnostics.copyReport, or
+// the navigator.clipboard fallback) rejects, handleCopyReport sets copyState 'failed', and the
+// manual-select hint appears below the actions.
+export const CopyFailed: Story = {
+  render: fallback('failed', transcriptError, transcriptComponentStack),
+};
+
+// Real path: after 重试 (handleReset clears the error) the still-broken subtree throws a

Review Comment:
   Addressed in . I removed  and its second-error fixtures rather than claiming reset-and-rethrow coverage from a static fallback rendering. The production comment was updated accordingly. Story typecheck, Storybook build, and the full 199-story render/accessibility smoke all pass.



##########
apps/desktop/stories/error-boundary.stories.tsx:
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import type { Meta, StoryObj } from '@storybook/react-vite';
+import { fn } from 'storybook/test';
+import type { ErrorInfo } from 'react';
+import {
+  ErrorBoundaryFallback,
+  type ErrorBoundaryCopyState,
+} from '../src/renderer/error-boundary';
+
+const meta = {
+  title: 'Product/Shell/Error Boundary',
+  parameters: { layout: 'fullscreen' },
+} satisfies Meta;
+
+export default meta;
+type Story = StoryObj<typeof meta>;
+
+// The class owns the copy/reset/reload side effects; the fallback only paints,
+// so these mocks stand in for the wired handlers without touching state.
+const onCopyReport = fn();
+const onReset = fn();
+const onReload = fn();
+
+// A representative renderer crash: a real Error carrying a synthetic renderer
+// stack + React component stack, the same shape componentDidCatch hands render().
+function buildRendererError(name: string, message: string, frames: string[]): Error {
+  const error = new Error(message);
+  error.name = name;
+  error.stack = [`${name}: ${message}`, ...frames.map((frame) => `    at ${frame}`)].join('\n');
+  return error;
+}
+
+const transcriptError = buildRendererError(
+  'TypeError',
+  "Cannot read properties of undefined (reading 'messages')",
+  [
+    'SessionTranscript (src/renderer/features/workbar/session-transcript.tsx:142:31)',

Review Comment:
   Addressed in . The diagnostic data is now explicitly labeled synthetic, the invented Maka symbols and paths have been replaced with generic  fixture frames, and the Story comments describe these as visual snapshots rather than real execution paths. Story typecheck, Storybook build, and the full 199-story render/accessibility smoke all pass.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] test(desktop): story-cover the renderer crash fallback [maka]

Posted by "liuxiaocs7 (via GitHub)" <gi...@apache.org>.
liuxiaocs7 commented on code in PR #3947:
URL: https://github.com/apache/maka/pull/3947#discussion_r3886154506


##########
apps/desktop/stories/error-boundary.stories.tsx:
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import type { Meta, StoryObj } from '@storybook/react-vite';
+import { fn } from 'storybook/test';
+import type { ErrorInfo } from 'react';
+import {
+  ErrorBoundaryFallback,
+  type ErrorBoundaryCopyState,
+} from '../src/renderer/error-boundary';
+
+const meta = {
+  title: 'Product/Shell/Error Boundary',
+  parameters: { layout: 'fullscreen' },
+} satisfies Meta;
+
+export default meta;
+type Story = StoryObj<typeof meta>;
+
+// The class owns the copy/reset/reload side effects; the fallback only paints,
+// so these mocks stand in for the wired handlers without touching state.
+const onCopyReport = fn();
+const onReset = fn();
+const onReload = fn();
+
+// A representative renderer crash: a real Error carrying a synthetic renderer
+// stack + React component stack, the same shape componentDidCatch hands render().
+function buildRendererError(name: string, message: string, frames: string[]): Error {
+  const error = new Error(message);
+  error.name = name;
+  error.stack = [`${name}: ${message}`, ...frames.map((frame) => `    at ${frame}`)].join('\n');
+  return error;
+}
+
+const transcriptError = buildRendererError(
+  'TypeError',
+  "Cannot read properties of undefined (reading 'messages')",
+  [
+    'SessionTranscript (src/renderer/features/workbar/session-transcript.tsx:142:31)',

Review Comment:
   Thanks — you're right, labeling invented symbols as a "Real path" made the fixture look like evidence for a call chain that cannot occur. Fixed in 472ebae0f:
   
   - Removed the invented `SessionTranscript` / `WorkbarPanel` / `PlanTree` / `features/workbar/...` symbols; the fixture now uses neutral placeholders (`SyntheticCrashFixture`, `<synthetic-storybook-fixture>`).
   - Dropped the `// Real path:` annotations in favor of neutral "Visual snapshot of the fallback's <state> state" descriptions.
   - Added a comment stating the diagnostics are explicitly synthetic and do not represent a Maka product call chain.
   
   Render smoke still passes (199 stories).



##########
apps/desktop/stories/error-boundary.stories.tsx:
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import type { Meta, StoryObj } from '@storybook/react-vite';
+import { fn } from 'storybook/test';
+import type { ErrorInfo } from 'react';
+import {
+  ErrorBoundaryFallback,
+  type ErrorBoundaryCopyState,
+} from '../src/renderer/error-boundary';
+
+const meta = {
+  title: 'Product/Shell/Error Boundary',
+  parameters: { layout: 'fullscreen' },
+} satisfies Meta;
+
+export default meta;
+type Story = StoryObj<typeof meta>;
+
+// The class owns the copy/reset/reload side effects; the fallback only paints,
+// so these mocks stand in for the wired handlers without touching state.
+const onCopyReport = fn();
+const onReset = fn();
+const onReload = fn();
+
+// A representative renderer crash: a real Error carrying a synthetic renderer
+// stack + React component stack, the same shape componentDidCatch hands render().
+function buildRendererError(name: string, message: string, frames: string[]): Error {
+  const error = new Error(message);
+  error.name = name;
+  error.stack = [`${name}: ${message}`, ...frames.map((frame) => `    at ${frame}`)].join('\n');
+  return error;
+}
+
+const transcriptError = buildRendererError(
+  'TypeError',
+  "Cannot read properties of undefined (reading 'messages')",
+  [
+    'SessionTranscript (src/renderer/features/workbar/session-transcript.tsx:142:31)',
+    'renderWithHooks (react-dom.development.js:15486:18)',
+    'mountIndeterminateComponent (react-dom.development.js:20103:13)',
+    'beginWork (react-dom.development.js:21626:16)',
+  ],
+);
+
+const transcriptComponentStack: ErrorInfo = {
+  componentStack: [
+    '',
+    '    at SessionTranscript (src/renderer/features/workbar/session-transcript.tsx:142:31)',
+    '    at WorkbarPanel',
+    '    at AppShell',
+    '    at ErrorBoundary (src/renderer/error-boundary.tsx:73:1)',
+  ].join('\n'),
+};
+
+// A second, different error — what the boundary catches when the still-broken
+// subtree throws again after 重试.
+const retryError = buildRendererError('RangeError', 'Maximum call stack size exceeded', [
+  'toTreeNode (src/renderer/features/workbar/plan-tree.tsx:88:12)',
+  'toTreeNode (src/renderer/features/workbar/plan-tree.tsx:91:20)',
+  'toTreeNode (src/renderer/features/workbar/plan-tree.tsx:91:20)',
+]);
+
+const retryComponentStack: ErrorInfo = {
+  componentStack: [
+    '',
+    '    at PlanTree (src/renderer/features/workbar/plan-tree.tsx:88:12)',
+    '    at WorkbarPanel',
+    '    at AppShell',
+    '    at ErrorBoundary (src/renderer/error-boundary.tsx:73:1)',
+  ].join('\n'),
+};
+
+const resolveLocale = (globals: Record<string, unknown>) => (globals.locale === 'en' ? 'en' : 'zh');
+
+function fallback(copyState: ErrorBoundaryCopyState, error: Error, errorInfo: ErrorInfo) {
+  return (_args: unknown, { globals }: { globals: Record<string, unknown> }) => (
+    <ErrorBoundaryFallback
+      error={error}
+      errorInfo={errorInfo}
+      copyState={copyState}
+      locale={resolveLocale(globals)}
+      onCopyReport={onCopyReport}
+      onReset={onReset}
+      onReload={onReload}
+    />
+  );
+}
+
+// Real path: the renderer throws during render; ErrorBoundary.getDerivedStateFromError
+// + componentDidCatch capture the error and React component stack, and render() paints
+// this fallback with copyState 'idle'.
+export const DefaultFallback: Story = {
+  render: fallback('idle', transcriptError, transcriptComponentStack),
+};
+
+// Real path: on the crash screen the user clicks 复制诊断信息; handleCopyReport sets
+// copyState 'pending' while window.maka.diagnostics.copyReport is in flight, disabling
+// the button (isDisabled + aria-busy).
+export const CopyPending: Story = {
+  render: fallback('pending', transcriptError, transcriptComponentStack),
+};
+
+// Real path: continues from copy pending — diagnostics.copyReport resolves, handleCopyReport
+// sets copyState 'copied' and the copy button swaps to the check glyph.
+export const Copied: Story = {
+  render: fallback('copied', transcriptError, transcriptComponentStack),
+};
+
+// Real path: continues from copy pending — the clipboard bridge (diagnostics.copyReport, or
+// the navigator.clipboard fallback) rejects, handleCopyReport sets copyState 'failed', and the
+// manual-select hint appears below the actions.
+export const CopyFailed: Story = {
+  render: fallback('failed', transcriptError, transcriptComponentStack),
+};
+
+// Real path: after 重试 (handleReset clears the error) the still-broken subtree throws a

Review Comment:
   Agreed — as written it was just another idle-state data variant, not a reset-and-rethrow test. Removed `RepeatError` in 472ebae0f; the PR now keeps only the four real visual states (idle / pending / copied / failed).
   
   Verifying that the boundary clears the first error and captures the second is a boundary-interaction concern rather than a fallback-render snapshot, so I've left it out of this Storybook-focused PR. Happy to add a focused interaction test at the real `ErrorBoundary` (mount → reset → child rethrows) as a follow-up if you'd like it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] test(desktop): story-cover the renderer crash fallback [maka]

Posted by "liuxiaocs7 (via GitHub)" <gi...@apache.org>.
liuxiaocs7 commented on PR #3947:
URL: https://github.com/apache/maka/pull/3947#issuecomment-5461550237

   Thanks for the careful review, @Astro-Han. Addressed both [P2] points in 472ebae0f:
   
   1. **Synthetic fixtures** — removed the invented Maka symbols and the `// Real path:` annotations; the stack/component-stack data is now explicitly labeled synthetic with neutral placeholders.
   2. **RepeatError** — removed it; the PR keeps only the four real visual states you called out as useful (idle / pending / copied / failed). A reset-and-rethrow interaction test belongs at the real `ErrorBoundary` and I'm glad to do it as a follow-up if wanted.
   
   Re-ran locally: biome lint, tsc (stories + renderer), build-storybook, and the render smoke (199 stories, all four error-boundary states pass). Ready for another look when you have a moment.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] test(desktop): story-cover the renderer crash fallback [maka]

Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han merged PR #3947:
URL: https://github.com/apache/maka/pull/3947


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org


Re: [PR] test(desktop): story-cover the renderer crash fallback [maka]

Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han commented on code in PR #3947:
URL: https://github.com/apache/maka/pull/3947#discussion_r3885906112


##########
apps/desktop/stories/error-boundary.stories.tsx:
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import type { Meta, StoryObj } from '@storybook/react-vite';
+import { fn } from 'storybook/test';
+import type { ErrorInfo } from 'react';
+import {
+  ErrorBoundaryFallback,
+  type ErrorBoundaryCopyState,
+} from '../src/renderer/error-boundary';
+
+const meta = {
+  title: 'Product/Shell/Error Boundary',
+  parameters: { layout: 'fullscreen' },
+} satisfies Meta;
+
+export default meta;
+type Story = StoryObj<typeof meta>;
+
+// The class owns the copy/reset/reload side effects; the fallback only paints,
+// so these mocks stand in for the wired handlers without touching state.
+const onCopyReport = fn();
+const onReset = fn();
+const onReload = fn();
+
+// A representative renderer crash: a real Error carrying a synthetic renderer
+// stack + React component stack, the same shape componentDidCatch hands render().
+function buildRendererError(name: string, message: string, frames: string[]): Error {
+  const error = new Error(message);
+  error.name = name;
+  error.stack = [`${name}: ${message}`, ...frames.map((frame) => `    at ${frame}`)].join('\n');
+  return error;
+}
+
+const transcriptError = buildRendererError(
+  'TypeError',
+  "Cannot read properties of undefined (reading 'messages')",
+  [
+    'SessionTranscript (src/renderer/features/workbar/session-transcript.tsx:142:31)',

Review Comment:
   **[P2] Do not present synthetic stack frames as a real product path**
   
   `SessionTranscript`, `WorkbarPanel`, `PlanTree`, and the referenced `features/workbar/...` files do not exist in this repository. The Story can still use synthetic diagnostic data, but calling these frames a “Real path” makes the fixture look like evidence for a product call chain that cannot occur.
   
   Please either use actual renderer components and paths or label the fixture explicitly as synthetic and avoid invented Maka symbols.



##########
apps/desktop/stories/error-boundary.stories.tsx:
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import type { Meta, StoryObj } from '@storybook/react-vite';
+import { fn } from 'storybook/test';
+import type { ErrorInfo } from 'react';
+import {
+  ErrorBoundaryFallback,
+  type ErrorBoundaryCopyState,
+} from '../src/renderer/error-boundary';
+
+const meta = {
+  title: 'Product/Shell/Error Boundary',
+  parameters: { layout: 'fullscreen' },
+} satisfies Meta;
+
+export default meta;
+type Story = StoryObj<typeof meta>;
+
+// The class owns the copy/reset/reload side effects; the fallback only paints,
+// so these mocks stand in for the wired handlers without touching state.
+const onCopyReport = fn();
+const onReset = fn();
+const onReload = fn();
+
+// A representative renderer crash: a real Error carrying a synthetic renderer
+// stack + React component stack, the same shape componentDidCatch hands render().
+function buildRendererError(name: string, message: string, frames: string[]): Error {
+  const error = new Error(message);
+  error.name = name;
+  error.stack = [`${name}: ${message}`, ...frames.map((frame) => `    at ${frame}`)].join('\n');
+  return error;
+}
+
+const transcriptError = buildRendererError(
+  'TypeError',
+  "Cannot read properties of undefined (reading 'messages')",
+  [
+    'SessionTranscript (src/renderer/features/workbar/session-transcript.tsx:142:31)',
+    'renderWithHooks (react-dom.development.js:15486:18)',
+    'mountIndeterminateComponent (react-dom.development.js:20103:13)',
+    'beginWork (react-dom.development.js:21626:16)',
+  ],
+);
+
+const transcriptComponentStack: ErrorInfo = {
+  componentStack: [
+    '',
+    '    at SessionTranscript (src/renderer/features/workbar/session-transcript.tsx:142:31)',
+    '    at WorkbarPanel',
+    '    at AppShell',
+    '    at ErrorBoundary (src/renderer/error-boundary.tsx:73:1)',
+  ].join('\n'),
+};
+
+// A second, different error — what the boundary catches when the still-broken
+// subtree throws again after 重试.
+const retryError = buildRendererError('RangeError', 'Maximum call stack size exceeded', [
+  'toTreeNode (src/renderer/features/workbar/plan-tree.tsx:88:12)',
+  'toTreeNode (src/renderer/features/workbar/plan-tree.tsx:91:20)',
+  'toTreeNode (src/renderer/features/workbar/plan-tree.tsx:91:20)',
+]);
+
+const retryComponentStack: ErrorInfo = {
+  componentStack: [
+    '',
+    '    at PlanTree (src/renderer/features/workbar/plan-tree.tsx:88:12)',
+    '    at WorkbarPanel',
+    '    at AppShell',
+    '    at ErrorBoundary (src/renderer/error-boundary.tsx:73:1)',
+  ].join('\n'),
+};
+
+const resolveLocale = (globals: Record<string, unknown>) => (globals.locale === 'en' ? 'en' : 'zh');
+
+function fallback(copyState: ErrorBoundaryCopyState, error: Error, errorInfo: ErrorInfo) {
+  return (_args: unknown, { globals }: { globals: Record<string, unknown> }) => (
+    <ErrorBoundaryFallback
+      error={error}
+      errorInfo={errorInfo}
+      copyState={copyState}
+      locale={resolveLocale(globals)}
+      onCopyReport={onCopyReport}
+      onReset={onReset}
+      onReload={onReload}
+    />
+  );
+}
+
+// Real path: the renderer throws during render; ErrorBoundary.getDerivedStateFromError
+// + componentDidCatch capture the error and React component stack, and render() paints
+// this fallback with copyState 'idle'.
+export const DefaultFallback: Story = {
+  render: fallback('idle', transcriptError, transcriptComponentStack),
+};
+
+// Real path: on the crash screen the user clicks 复制诊断信息; handleCopyReport sets
+// copyState 'pending' while window.maka.diagnostics.copyReport is in flight, disabling
+// the button (isDisabled + aria-busy).
+export const CopyPending: Story = {
+  render: fallback('pending', transcriptError, transcriptComponentStack),
+};
+
+// Real path: continues from copy pending — diagnostics.copyReport resolves, handleCopyReport
+// sets copyState 'copied' and the copy button swaps to the check glyph.
+export const Copied: Story = {
+  render: fallback('copied', transcriptError, transcriptComponentStack),
+};
+
+// Real path: continues from copy pending — the clipboard bridge (diagnostics.copyReport, or
+// the navigator.clipboard fallback) rejects, handleCopyReport sets copyState 'failed', and the
+// manual-select hint appears below the actions.
+export const CopyFailed: Story = {
+  render: fallback('failed', transcriptError, transcriptComponentStack),
+};
+
+// Real path: after 重试 (handleReset clears the error) the still-broken subtree throws a

Review Comment:
   **[P2] This Story does not exercise the repeat-error transition**
   
   `RepeatError` directly renders `ErrorBoundaryFallback` with another Error. It never mounts `ErrorBoundary`, invokes reset, or causes the child tree to throw again, so it does not verify that the boundary clears the first error and captures the second one.
   
   As written, this is another idle-state data variant. It can be removed, or the repeat-error behavior can be covered at the real boundary with a focused interaction test.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org