codeant-ai-for-open-source[bot] commented on code in PR #44964:
URL: https://github.com/apache/superset/pull/44964#discussion_r4176911103


##########
superset-frontend/.storybook/setup-stories.ts:
##########
@@ -0,0 +1,143 @@
+/**
+ * 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.
+ */
+
+// Source: https://gist.github.com/AriPerkkio/99b9eedc7d8f71ff6e6770f9425a4be4
+import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
+import { dirname, resolve } from 'node:path';
+import { type test, type Page } from '@playwright/test';
+
+declare global {
+  var __storyResult: { status: string; errors: string[] };
+}
+
+interface Entry {
+  id: string;
+  title: string;
+  name: string;
+  type: 'story' | 'docs';
+  tags?: string[];
+}
+
+interface Report {
+  type: string;
+  status: string;
+  result?: { violations?: { id: string; help: string }[] };
+}
+
+const storybookURL = process.env.STORYBOOK_URL ?? 'http://localhost:6006';
+const indexFile = resolve(
+  '../node_modules/.cache/storybook-playwright/index.json',
+);
+
+export default async function globalSetup() {
+  const response = await fetch(`${storybookURL}/index.json`);
+
+  if (!response.ok) {
+    throw new Error(
+      `Failed to fetch ${storybookURL}/index.json: ${response.status}`,
+    );
+  }
+
+  mkdirSync(dirname(indexFile), { recursive: true });
+  writeFileSync(indexFile, await response.text());
+}
+
+function captureStoryResult() {
+  const errors: string[] = [];
+  const serialize = (error: Error) =>
+    error.stack ?? `${error.name}: ${error.message}`;
+
+  let channel: any;
+  Object.defineProperty(globalThis, '__STORYBOOK_ADDONS_CHANNEL__', {
+    configurable: true,
+    get: () => channel,
+    set: value => {
+      channel = value;
+      channel.on(
+        'storyErrored',
+        ({ title, description }: Record<string, string>) =>
+          errors.push(`${title}\n${description}`),
+      );
+      channel.on('storyThrewException', (error: Error) =>
+        errors.push(serialize(error)),
+      );
+      channel.on('playFunctionThrewException', (error: Error) =>
+        errors.push(serialize(error)),
+      );
+      channel.on('unhandledErrorsWhilePlaying', (unhandled: Error[]) =>
+        errors.push(...unhandled.map(serialize)),
+      );
+      channel.on('storyMissing', (id: string) => {
+        globalThis.__storyResult = {
+          status: 'missing',
+          errors: [`Story "${id}" not found`],
+        };
+      });
+      channel.on(
+        'storyFinished',
+        ({ status, reporters }: { status: string; reporters: Report[] }) => {
+          for (const report of reporters.filter(
+            report => report.status === 'failed',
+          )) {
+            const violations = report.result?.violations ?? [];
+            errors.push(
+              [
+                `${report.type} report failed`,
+                ...violations.map(v => `- ${v.id}: ${v.help}`),
+              ].join('\n'),
+            );
+          }
+          globalThis.__storyResult = { status, errors };
+        },
+      );
+    },
+  });
+}
+
+async function visitStory(page: Page, entry: Entry) {
+  await page.addInitScript(captureStoryResult);
+  await page.goto(`/iframe.html?id=${entry.id}&viewMode=story`);

Review Comment:
   **Suggestion:** Root-relative navigation discards any deployment subpath in 
`STORYBOOK_URL`, so externally hosted Storybook tests open the wrong iframe URL.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Sometimes` ยท ๐Ÿท๏ธ `Api mismatch`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=123589b1d6fd417882c0e0305d0b8abc&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=123589b1d6fd417882c0e0305d0b8abc&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/.storybook/setup-stories.ts
   **Line:** 115:115
   **Comment:**
        *Api Mismatch: Root-relative navigation discards any deployment subpath 
in `STORYBOOK_URL`, so externally hosted Storybook tests open the wrong iframe 
URL.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44964&comment_hash=146c8988c57a455dbe095b3b83fa069eb606784a28e9c7b7f302f1f1e00fdcb1&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44964&comment_hash=146c8988c57a455dbe095b3b83fa069eb606784a28e9c7b7f302f1f1e00fdcb1&reaction=dislike'>๐Ÿ‘Ž</a>



##########
superset-frontend/.storybook/setup-stories.ts:
##########
@@ -0,0 +1,143 @@
+/**
+ * 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.
+ */
+
+// Source: https://gist.github.com/AriPerkkio/99b9eedc7d8f71ff6e6770f9425a4be4
+import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
+import { dirname, resolve } from 'node:path';
+import { type test, type Page } from '@playwright/test';
+
+declare global {
+  var __storyResult: { status: string; errors: string[] };
+}
+
+interface Entry {
+  id: string;
+  title: string;
+  name: string;
+  type: 'story' | 'docs';
+  tags?: string[];
+}
+
+interface Report {
+  type: string;
+  status: string;
+  result?: { violations?: { id: string; help: string }[] };
+}
+
+const storybookURL = process.env.STORYBOOK_URL ?? 'http://localhost:6006';
+const indexFile = resolve(
+  '../node_modules/.cache/storybook-playwright/index.json',
+);
+
+export default async function globalSetup() {
+  const response = await fetch(`${storybookURL}/index.json`);
+
+  if (!response.ok) {
+    throw new Error(
+      `Failed to fetch ${storybookURL}/index.json: ${response.status}`,
+    );
+  }
+
+  mkdirSync(dirname(indexFile), { recursive: true });
+  writeFileSync(indexFile, await response.text());
+}
+
+function captureStoryResult() {
+  const errors: string[] = [];
+  const serialize = (error: Error) =>
+    error.stack ?? `${error.name}: ${error.message}`;
+
+  let channel: any;
+  Object.defineProperty(globalThis, '__STORYBOOK_ADDONS_CHANNEL__', {
+    configurable: true,
+    get: () => channel,
+    set: value => {
+      channel = value;
+      channel.on(
+        'storyErrored',
+        ({ title, description }: Record<string, string>) =>
+          errors.push(`${title}\n${description}`),
+      );
+      channel.on('storyThrewException', (error: Error) =>
+        errors.push(serialize(error)),
+      );
+      channel.on('playFunctionThrewException', (error: Error) =>
+        errors.push(serialize(error)),
+      );
+      channel.on('unhandledErrorsWhilePlaying', (unhandled: Error[]) =>
+        errors.push(...unhandled.map(serialize)),
+      );
+      channel.on('storyMissing', (id: string) => {
+        globalThis.__storyResult = {
+          status: 'missing',
+          errors: [`Story "${id}" not found`],
+        };
+      });
+      channel.on(
+        'storyFinished',
+        ({ status, reporters }: { status: string; reporters: Report[] }) => {
+          for (const report of reporters.filter(
+            report => report.status === 'failed',
+          )) {
+            const violations = report.result?.violations ?? [];
+            errors.push(
+              [
+                `${report.type} report failed`,
+                ...violations.map(v => `- ${v.id}: ${v.help}`),
+              ].join('\n'),
+            );
+          }
+          globalThis.__storyResult = { status, errors };
+        },
+      );
+    },
+  });
+}
+
+async function visitStory(page: Page, entry: Entry) {
+  await page.addInitScript(captureStoryResult);
+  await page.goto(`/iframe.html?id=${entry.id}&viewMode=story`);
+
+  const handle = await page.waitForFunction(() => globalThis.__storyResult);
+  const result = await handle.jsonValue();
+
+  if (result.status !== 'success' || result.errors.length > 0) {
+    throw new Error(
+      [
+        `Story "${entry.title} โ€บ ${entry.name}" ${result.status === 'missing' 
? 'is missing' : 'failed'}.`,
+        `Open it in Storybook: ${storybookURL}/?path=/story/${entry.id}`,
+        '',
+        ...result.errors,
+      ].join('\n'),
+    );
+  }
+}
+
+export function loadStories(): [string, Parameters<typeof test>[2]][] {
+  const index = JSON.parse(readFileSync(indexFile, 'utf8')) as {
+    entries: Record<string, Entry>;
+  };

Review Comment:
   **Suggestion:** `loadStories()` runs while Playwright collects tests, before 
`globalSetup` writes `indexFile`, so the first run fails with a missing-file 
error.
   
   **Assessment:** ๐Ÿ”ด `Critical` ยท ๐Ÿ” `Occurrence: Often` ยท ๐Ÿท๏ธ `State and 
lifecycle`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=3110a0dc9a9a4e12b4b9801551d1dbc3&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=3110a0dc9a9a4e12b4b9801551d1dbc3&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/.storybook/setup-stories.ts
   **Line:** 133:135
   **Comment:**
        *State And Lifecycle: `loadStories()` runs while Playwright collects 
tests, before `globalSetup` writes `indexFile`, so the first run fails with a 
missing-file error.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44964&comment_hash=4d7246b59ee353782d686fa57beb0c9a218486c760085b337d4693499e36a294&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44964&comment_hash=4d7246b59ee353782d686fa57beb0c9a218486c760085b337d4693499e36a294&reaction=dislike'>๐Ÿ‘Ž</a>



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to