Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions code/e2e-tests/addon-mcp.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/* eslint-disable local-rules/no-uncategorized-errors */
import path from 'node:path';

import type { APIRequestContext } from '@playwright/test';
import { expect, test } from '@playwright/test';
import process from 'process';

const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001';
const templateName = process.env.STORYBOOK_TEMPLATE_NAME || '';
const type = process.env.STORYBOOK_TYPE || 'dev';
const sandboxDir = process.env.STORYBOOK_SANDBOX_DIR;
const sandboxDir = process.env.STORYBOOK_SANDBOX_DIR!;
Comment on lines 8 to +11

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Avoid non‑null assertion for required env var; fail with a clear error.

process.env.STORYBOOK_SANDBOX_DIR! can throw later in path.join with a confusing error when the env var isn’t set. Prefer an explicit guard and a helpful message (including the default sandbox location) to make CI/local failures actionable.

✅ Suggested change
-const sandboxDir = process.env.STORYBOOK_SANDBOX_DIR!;
+const sandboxDir = process.env.STORYBOOK_SANDBOX_DIR;
+if (!sandboxDir) {
+  throw new Error(
+    'STORYBOOK_SANDBOX_DIR is required. Sandboxes are generated outside the repo at ../storybook-sandboxes/.'
+  );
+}

Based on learnings, sandboxes default to ../storybook-sandboxes/.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001';
const templateName = process.env.STORYBOOK_TEMPLATE_NAME || '';
const type = process.env.STORYBOOK_TYPE || 'dev';
const sandboxDir = process.env.STORYBOOK_SANDBOX_DIR;
const sandboxDir = process.env.STORYBOOK_SANDBOX_DIR!;
const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001';
const templateName = process.env.STORYBOOK_TEMPLATE_NAME || '';
const type = process.env.STORYBOOK_TYPE || 'dev';
const sandboxDir = process.env.STORYBOOK_SANDBOX_DIR;
if (!sandboxDir) {
throw new Error(
'STORYBOOK_SANDBOX_DIR is required. Sandboxes are generated outside the repo at ../storybook-sandboxes/.'
);
}
🤖 Prompt for AI Agents
In `@code/e2e-tests/addon-mcp.spec.ts` around lines 8 - 11, Replace the non‑null
asserted constant sandboxDir so it fails fast with a clear message and provides
the usual default; instead of using process.env.STORYBOOK_SANDBOX_DIR! in the
top‑level const, read the env var into a variable, and if it is missing throw a
descriptive Error (or set to the default sandbox path "../storybook-sandboxes/"
resolved to an absolute path) before any path.join usage; update references to
the existing sandboxDir constant so code uses the validated/defaulted value and
avoid later mysterious path.join failures.


const MCP_ENDPOINT = `${storybookUrl}/mcp`;

Expand Down Expand Up @@ -200,7 +202,7 @@ test.describe('addon-mcp', () => {
stories: [
{
exportName: storyName,
absoluteStoryPath: `${sandboxDir}/src/stories/Button.stories.ts`,
absoluteStoryPath: path.join(sandboxDir, 'src', 'stories', 'Button.stories.ts'),
},
],
},
Expand Down
Loading