Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore(web): enforce test story conventions (#16345)

Ben Bachem7322c56d5b5c
diff --git a/packages/eslint-plugin/src/index.ts b/packages/eslint-plugin/src/index.ts
index 103caa917c..d9b43c87c7 100644
--- a/packages/eslint-plugin/src/index.ts
+++ b/packages/eslint-plugin/src/index.ts
@@ -9,6 +9,7 @@ import { default as requireTitleWithTruncate } from "./rules/require-title-with-
import { default as noStyleProps } from "./rules/no-style-props.js";
import { default as noSwitchStatements } from "./rules/no-switch-statements.js";
import { default as noUnnecessaryCn } from "./rules/no-unnecessary-cn.js";
+import { default as storybookPlayRequiresTestName } from "./rules/storybook-play-requires-test-name.js";
const plugin = {
rules: {
@@ -23,6 +24,7 @@ const plugin = {
"no-tailwind-overflow-scroll": noTailwindOverflowScroll,
"no-unnecessary-cn": noUnnecessaryCn,
"require-title-with-truncate": requireTitleWithTruncate,
+ "storybook-play-requires-test-name": storybookPlayRequiresTestName,
},
};
diff --git a/packages/eslint-plugin/src/rules/storybook-play-requires-test-name.test.ts b/packages/eslint-plugin/src/rules/storybook-play-requires-test-name.test.ts
new file mode 100644
index 0000000000..6abdd9d3a7
--- /dev/null
+++ b/packages/eslint-plugin/src/rules/storybook-play-requires-test-name.test.ts
@@ -0,0 +1,68 @@
+import { RuleTester } from "@typescript-eslint/rule-tester";
+import * as typescriptEslintParser from "@typescript-eslint/parser";
+import rule from "./storybook-play-requires-test-name.js";
+
+const ruleTester = new RuleTester({
+ languageOptions: {
+ parser: typescriptEslintParser,
+ },
+});
+
+ruleTester.run("storybook-play-requires-test-name", rule, {
+ valid: [
+ `export const Default = meta.story({ args: {} });`,
+ `const helper = { play: async () => {} };`,
+ `export const Default = meta.story({ nested: { play: async () => {} } });`,
+ `export const Default = meta.story({ 1: "one" });`,
+ `export const Interaction = other.factory({ play: async () => {} });`,
+ `export const Interaction = meta.story({
+ name: "(Test) Opens menu",
+ play: async () => {},
+ });`,
+ `export const Interaction = meta.story({
+ "name": "(Test) Opens menu",
+ "play": async () => {},
+ });`,
+ `export const Interaction = meta.story({
+ ["play"]: async () => {},
+ });`,
+ `export const Interaction = {
+ name: "(Test) Opens menu",
+ play: async () => {},
+ };`,
+ ],
+ invalid: [
+ {
+ code: `export const OpensMenu = meta.story({ play: async () => {} });`,
+ errors: [{ messageId: "testNameRequired" }],
+ },
+ {
+ code: `export const OpensMenu = meta.story({
+ name: "Opens menu",
+ play: async () => {},
+ });`,
+ errors: [{ messageId: "testNameRequired" }],
+ },
+ {
+ code: `export const OpensMenu = {
+ name: "Test Opens menu",
+ play: async () => {},
+ };`,
+ errors: [{ messageId: "testNameRequired" }],
+ },
+ {
+ code: `export const OpensMenu = meta.story({
+ name: \`(Test) Opens menu\`,
+ play: async () => {},
+ });`,
+ errors: [{ messageId: "testNameRequired" }],
+ },
+ {
+ code: `export const OpensMenu = meta.story({
+ name: 42,
+ play: async () => {},
+ });`,
+ errors: [{ messageId: "testNameRequired" }],
+ },
+ ],
+});
diff --git a/packages/eslint-plugin/src/rules/storybook-play-requires-test-name.ts b/packages/eslint-plugin/src/rules/storybook-play-requires-test-name.ts
new file mode 100644
index 0000000000..8a8ab99e41
--- /dev/null
+++ b/packages/eslint-plugin/src/rules/storybook-play-requires-test-name.ts
@@ -0,0 +1,88 @@
+import { AST_NODE_TYPES, type TSESTree } from "@typescript-eslint/utils";
+import { createRule } from "../util.js";
+
+const TEST_STORY_PREFIX = "(Test)";
+
+function getPropertyName(property: TSESTree.Property): string | null {
+ if (property.computed) return null;
+ if (property.key.type === AST_NODE_TYPES.Identifier) return property.key.name;
+ if (
+ property.key.type === AST_NODE_TYPES.Literal &&
+ typeof property.key.value === "string"
+ ) {
+ return property.key.value;
+ }
+ return null;
+}
+
+function isStoryObject(node: TSESTree.ObjectExpression): boolean {
+ const parent = node.parent;
+
+ if (
+ parent.type === AST_NODE_TYPES.CallExpression &&
+ parent.arguments[0] === node &&
+ parent.callee.type === AST_NODE_TYPES.MemberExpression &&
+ !parent.callee.computed &&
+ parent.callee.property.type === AST_NODE_TYPES.Identifier &&
+ parent.callee.property.name === "story"
+ ) {
+ return true;
+ }
+
+ return (
+ parent.type === AST_NODE_TYPES.VariableDeclarator &&
+ parent.init === node &&
+ parent.parent.parent.type === AST_NODE_TYPES.ExportNamedDeclaration
+ );
+}
+
+const rule = createRule({
+ name: "storybook-play-requires-test-name",
+ meta: {
+ type: "problem",
+ docs: {
+ description:
+ "Require stories with play functions to have names prefixed with (Test).",
+ },
+ schema: [],
+ messages: {
+ testNameRequired:
+ 'Stories with play functions must set a display name prefixed with "(Test)".',
+ },
+ },
+ defaultOptions: [],
+ create(context) {
+ return {
+ ObjectExpression(node) {
+ if (!isStoryObject(node)) return;
+
+ const properties = node.properties.filter(
+ (property): property is TSESTree.Property =>
+ property.type === AST_NODE_TYPES.Property,
+ );
+ const playProperty = properties.find(
+ (property) => getPropertyName(property) === "play",
+ );
+ if (!playProperty) return;
+
+ const nameProperty = properties.find(
+ (property) => getPropertyName(property) === "name",
+ );
+ const name =
+ nameProperty?.value.type === AST_NODE_TYPES.Literal &&
+ typeof nameProperty.value.value === "string"
+ ? nameProperty.value.value
+ : null;
+
+ if (!name?.startsWith(TEST_STORY_PREFIX)) {
+ context.report({
+ node: playProperty.key,
+ messageId: "testNameRequired",
+ });
+ }
+ },
+ };
+ },
+});
+
+export default rule;
diff --git a/web/.storybook/preview.tsx b/web/.storybook/preview.tsx
index f0bfb4059a..6fe372dfb9 100644
--- a/web/.storybook/preview.tsx
+++ b/web/.storybook/preview.tsx
@@ -174,8 +174,24 @@ export default definePreview({
container: ThemedDocsContainer,
},
options: {
- storySort: {
- order: ["Design", "Playground"],
+ storySort: (a, b) => {
+ const sectionOrder = ["Design", "Playground"];
+ const aSectionIndex = sectionOrder.indexOf(a.title.split("/")[0] ?? "");
+ const bSectionIndex = sectionOrder.indexOf(b.title.split("/")[0] ?? "");
+ const sectionDifference =
+ (aSectionIndex === -1 ? sectionOrder.length : aSectionIndex) -
+ (bSectionIndex === -1 ? sectionOrder.length : bSectionIndex);
+ if (sectionDifference !== 0) return sectionDifference;
+
+ // Returning 0 preserves Storybook's existing stable order. Only
+ // partition test stories when both entries belong to the same component.
+ if (a.title !== b.title) return 0;
+
+ const aIsTest = a.name.startsWith("(Test)");
+ const bIsTest = b.name.startsWith("(Test)");
+ if (aIsTest !== bIsTest) return aIsTest ? 1 : -1;
+
+ return 0;
},
},
},
diff --git a/web/eslint.config.mjs b/web/eslint.config.mjs
index c5b604100f..34ce1a7c83 100644
--- a/web/eslint.config.mjs
+++ b/web/eslint.config.mjs
@@ -62,6 +62,13 @@ export default [
...nextConfig,
...storybook.configs["flat/recommended"],
+ {
+ name: "langfuse/web/storybook-test-story-names",
+ files: ["src/**/*.stories.{ts,tsx}"],
+ rules: {
+ "@repo/storybook-play-requires-test-name": "error",
+ },
+ },
{
...tailwindcssRecommendedConfig,
settings: {
diff --git a/web/src/components/nav/AppSidebar/AppSidebar.stories.tsx b/web/src/components/nav/AppSidebar/AppSidebar.stories.tsx
index b780f3e1dc..5cf7c32e23 100644
--- a/web/src/components/nav/AppSidebar/AppSidebar.stories.tsx
+++ b/web/src/components/nav/AppSidebar/AppSidebar.stories.tsx
@@ -164,6 +164,7 @@ export const LatestLaunchWeek = meta.story({
});
export const GitHubStar = meta.story({
+ name: "(Test) GitHub star",
args: {
v4UpgradeUiEnabled: false,
notificationState: {
diff --git a/web/src/features/in-app-agent/components/InAppAgentToolCallCard.stories.tsx b/web/src/features/in-app-agent/components/InAppAgentToolCallCard.stories.tsx
index ced65ebf0f..110e090a93 100644
--- a/web/src/features/in-app-agent/components/InAppAgentToolCallCard.stories.tsx
+++ b/web/src/features/in-app-agent/components/InAppAgentToolCallCard.stories.tsx
@@ -50,6 +50,7 @@ export const Error = meta.story({
});
export const SandboxBash = meta.story({
+ name: "(Test) Sandbox bash",
args: {
isCompact: true,
tool: {
@@ -78,6 +79,7 @@ export const SandboxBash = meta.story({
});
export const SandboxRead = meta.story({
+ name: "(Test) Sandbox read",
args: {
isCompact: true,
tool: {
@@ -100,6 +102,7 @@ export const SandboxRead = meta.story({
});
export const SandboxWrite = meta.story({
+ name: "(Test) Sandbox write",
args: {
isCompact: true,
tool: {
@@ -125,6 +128,7 @@ export const SandboxWrite = meta.story({
});
export const SandboxEdit = meta.story({
+ name: "(Test) Sandbox edit",
args: {
isCompact: true,
tool: {
@@ -203,6 +207,7 @@ export const ApprovalSubmitting = meta.story({
});
export const ApprovalDisabled = meta.story({
+ name: "(Test) Approval disabled",
args: {
isCompact: true,
isDisabled: true,
diff --git a/web/src/features/in-app-agent/components/InAppAgentWindow.stories.tsx b/web/src/features/in-app-agent/components/InAppAgentWindow.stories.tsx
index 28c88d5097..b636627d1d 100644
--- a/web/src/features/in-app-agent/components/InAppAgentWindow.stories.tsx
+++ b/web/src/features/in-app-agent/components/InAppAgentWindow.stories.tsx
@@ -727,6 +727,7 @@ const meta = preview.meta({
});
export const ToolApprovalRequired = meta.story({
+ name: "(Test) Tool approval required",
args: {
isAssistantTurnInProgress: true,
isAwaitingApproval: true,
@@ -1133,6 +1134,7 @@ export const ProgressLogWorking = meta.story({
});
export const ProgressLogOpened = meta.story({
+ name: "(Test) Progress log opened",
args: {
isAssistantTurnInProgress: true,
isExpanded: true,
@@ -1408,6 +1410,7 @@ export const LoadingAfterToolCall = meta.story({
});
export const Error = meta.story({
+ name: "(Test) Error",
args: {
error: {
type: "generic",
@@ -1447,6 +1450,7 @@ const stepLimitRun = {
};
export const StepLimit = meta.story({
+ name: "(Test) Step limit",
args: {
selectedConversationId: "conversation-1",
executionUi: {
@@ -1555,6 +1559,7 @@ const failedRun = {
};
export const Failed = meta.story({
+ name: "(Test) Failed",
args: {
selectedConversationId: "conversation-1",
executionUi: {
@@ -1616,6 +1621,7 @@ const failedBeforeFirstTokenRun = {
};
export const FailedBeforeFirstToken = meta.story({
+ name: "(Test) Failed before first token",
args: {
selectedConversationId: "conversation-1",
executionUi: {
@@ -1685,6 +1691,7 @@ export const FailedBeforeFirstToken = meta.story({
* running conversation has nothing for the user to act on yet.
*/
export const ConversationActivity = meta.story({
+ name: "(Test) Conversation activity",
args: {
conversations: activityConversations,
activityByConversationId,
@@ -1714,6 +1721,7 @@ const STORY_RUN_MS = 3_000;
* belongs to the first one only, and wait for the run to settle to see it go.
*/
export const BackgroundHint = meta.story({
+ name: "(Test) Background hint",
args: {
messages: [],
},
@@ -1830,6 +1838,7 @@ const backgroundStopReasoning = {
};
export const BackgroundRunStops = meta.story({
+ name: "(Test) Background run stops",
args: {
isAssistantTurnInProgress: true,
selectedConversationId: "conversation-1",