Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c0740e0

Browse files
committed
refactor(site/src): require every registry name in the badge story
The registry-wide story counted rendered cases, so the extra subagent and unknown-tool fixtures could offset a registered renderer that produced nothing and the count assertion still passed. It now records which registry names actually rendered and requires all of them. Folds the negative auth-required badge assertion into the story it duplicated, and makes the internal renderer prop required now that `Tool` normalizes the public one.
1 parent e201b4f commit c0740e0

3 files changed

Lines changed: 9 additions & 26 deletions

File tree

site/src/pages/AgentsPage/components/ChatConversation/ConversationTimeline.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ const ReadFileTimelineBlock = memo<{
229229
<ReadFileTool
230230
{...readFile}
231231
status={firstTool.status}
232-
hookRewritten={firstTool.hookRewritten ?? false}
232+
hookRewritten={firstTool.hookRewritten}
233233
expanded={expanded}
234234
onExpandedChange={setExpanded}
235235
/>

site/src/pages/AgentsPage/components/ChatElements/tools/Tool.stories.tsx

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ export const ExecuteAuthRequired: Story = {
715715
"width=900,height=600",
716716
);
717717
openSpy.mockRestore();
718+
expect(canvas.queryByText("Modified by policy")).not.toBeInTheDocument();
718719
},
719720
};
720721

@@ -739,25 +740,6 @@ export const ExecuteAuthRequiredRewrittenByHook: Story = {
739740
},
740741
};
741742

742-
export const ExecuteAuthRequiredNotRewrittenByHook: Story = {
743-
args: {
744-
result: {
745-
auth_required: true,
746-
provider_display_name: "GitHub",
747-
authenticate_url: "https://coder.example.com/external-auth/github",
748-
output: "fatal: could not read Username for 'https://github.com'",
749-
},
750-
},
751-
play: async ({ canvasElement }) => {
752-
const canvas = within(canvasElement);
753-
754-
expect(
755-
canvas.getByRole("button", { name: "Authenticate with GitHub" }),
756-
).toBeInTheDocument();
757-
expect(canvas.queryByText("Modified by policy")).not.toBeInTheDocument();
758-
},
759-
};
760-
761743
// ---------------------------------------------------------------------------
762744
// WaitForExternalAuth stories
763745
// ---------------------------------------------------------------------------
@@ -3425,7 +3407,6 @@ export const AllToolIconsTranscript: Story = {
34253407

34263408
// The badge reaches tools implicitly through the shared header, so a renderer
34273409
// that builds its own header rows drops it with no type or runtime error.
3428-
// Asserting over the whole registry also fails when a new tool ships uncovered.
34293410
export const PolicyBadgeCoversEveryRenderer: Story = {
34303411
render: () => (
34313412
<ChatWorkspaceContext value={{ workspaceId: "test-workspace-id" }}>
@@ -3481,7 +3462,7 @@ export const PolicyBadgeCoversEveryRenderer: Story = {
34813462
toolRendererNames.filter((name) => !covered.has(name)),
34823463
).toStrictEqual([]);
34833464

3484-
const rendered: string[] = [];
3465+
const rendered = new Set<string>();
34853466
const missingBadge: string[] = [];
34863467
for (const toolCase of canvasElement.querySelectorAll(
34873468
"[data-policy-case]",
@@ -3490,13 +3471,15 @@ export const PolicyBadgeCoversEveryRenderer: Story = {
34903471
if (toolCase.textContent?.trim() === "") {
34913472
continue;
34923473
}
3493-
rendered.push(name);
3474+
rendered.add(name);
34943475
if (!within(toolCase as HTMLElement).queryByText("Modified by policy")) {
34953476
missingBadge.push(name);
34963477
}
34973478
}
34983479

34993480
expect(missingBadge).toStrictEqual([]);
3500-
expect(rendered.length).toBeGreaterThanOrEqual(toolRendererNames.length);
3481+
expect(
3482+
toolRendererNames.filter((name) => !rendered.has(name)),
3483+
).toStrictEqual([]);
35013484
},
35023485
};

site/src/pages/AgentsPage/components/ChatElements/tools/Tool.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ type ToolRendererProps = {
122122
parsedCommands?: readonly string[][];
123123
shellToolDisplayMode?: TypesGen.AgentDisplayMode;
124124
codeDiffDisplayMode?: TypesGen.AgentDisplayMode;
125-
hookRewritten?: boolean;
125+
hookRewritten: boolean;
126126
};
127127

128128
// ---------------------------------------------------------------------------
@@ -1129,7 +1129,7 @@ const toolRenderers: Record<string, FC<ToolRendererProps>> = {
11291129
};
11301130

11311131
// Exported so tests can assert cross-cutting header affordances across every
1132-
// dispatch target instead of a hand-picked subset.
1132+
// registered renderer instead of a hand-picked subset.
11331133
export const toolRendererNames: readonly string[] = Object.keys(toolRenderers);
11341134

11351135
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)