codeant-ai-for-open-source[bot] commented on code in PR #42033:
URL: https://github.com/apache/superset/pull/42033#discussion_r3600722018
##########
superset-frontend/packages/superset-ui-core/src/chart/components/StatefulChart.test.tsx:
##########
@@ -720,6 +720,435 @@ test('should refetch when mixing renderTrigger string
control with non-renderTri
});
});
+test('resolves async (202) responses via the injected handleAsyncChartData
hook', async () => {
+ const asyncJob = {
+ channel_id: 'c1',
+ job_id: 'j1',
+ status: 'running',
+ result_url: '/api/v1/chart/data/abc',
+ };
+ mockChartClient.client.post.mockResolvedValue({
+ response: { status: 202 } as Response,
+ json: asyncJob,
+ });
+ const handleAsyncChartData = jest
+ .fn()
+ .mockResolvedValue([{ data: 'async result' }]);
+
+ const { getByTestId } = render(
+ <StatefulChart
+ formData={mockFormData}
+ chartType="test_chart"
+ hooks={{ handleAsyncChartData }}
+ />,
+ );
+
+ await waitFor(() => {
+ expect(handleAsyncChartData).toHaveBeenCalledTimes(1);
+ });
+ // Delegates the raw response + job metadata (and useLegacyApi + abort
signal)
+ expect(handleAsyncChartData).toHaveBeenCalledWith(
+ { status: 202 },
+ asyncJob,
+ false,
+ expect.any(AbortSignal),
+ );
+ // Chart renders once the async data resolves
+ await waitFor(() => {
+ expect(getByTestId('super-chart')).toBeInTheDocument();
+ });
+});
+
+test('errors on async (202) response when no async handler is provided', async
() => {
+ mockChartClient.client.post.mockResolvedValue({
+ response: { status: 202 } as Response,
+ json: { job_id: 'j1', channel_id: 'c1', status: 'running' },
+ });
+ const onError = jest.fn();
+
+ const { findByText } = render(
+ <StatefulChart
+ formData={mockFormData}
+ chartType="test_chart"
+ onError={onError}
+ />,
+ );
+
+ // Fails loudly instead of rendering the job metadata as empty data
+ expect(await findByText(/async handler/i)).toBeInTheDocument();
+ await waitFor(() => {
+ expect(onError).toHaveBeenCalledTimes(1);
+ });
+});
+
+test('renders synchronous (200) responses that include a response object',
async () => {
+ mockChartClient.client.post.mockResolvedValue({
+ response: { status: 200 } as Response,
+ json: [{ result: [{ data: 'sync result' }] }],
+ });
+
+ const { getByTestId } = render(
+ <StatefulChart formData={mockFormData} chartType="test_chart" />,
+ );
+
+ await waitFor(() => {
+ expect(getByTestId('super-chart')).toBeInTheDocument();
+ });
+ // Synchronous path: no async handler needed, single request
+ expect(mockChartClient.client.post).toHaveBeenCalledTimes(1);
+});
+
+test('wraps the legacy async body as { result: [body] } for the async
handler', async () => {
+ const legacyBody = { job_id: 'j1', channel_id: 'c1', status: 'running' };
+ mockChartClient.client.post.mockResolvedValue({
+ response: { status: 202 } as Response,
+ json: legacyBody,
+ });
+ // Force the legacy API path for this viz type
+ (getChartMetadataRegistry as any).mockReturnValue({
Review Comment:
**Suggestion:** Replace the `any` cast with a concrete mock type (or
`unknown` with a safe narrowing) to preserve type checking in this test.
[custom_rule]
**Severity Level:** Minor ๐งน
<details>
<summary><b>Why it matters? โญ </b></summary>
The rule llmcfg-no-any-types forbids new or changed TypeScript code that
uses `any`. This line explicitly casts `getChartMetadataRegistry` to `any`, so
the violation is real and directly matches the rule.
</details>
<details>
<summary><b>Rule source ๐ </b></summary>
.cursor/rules/dev-standard.mdc (line 16)
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=6bf8284ef2f24619ab10ce29e5ef6b46&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=6bf8284ef2f24619ab10ce29e5ef6b46&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/packages/superset-ui-core/src/chart/components/StatefulChart.test.tsx
**Line:** 808:808
**Comment:**
*Custom Rule: Replace the `any` cast with a concrete mock type (or
`unknown` with a safe narrowing) to preserve type checking in this test.
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%2F42033&comment_hash=6a321650c85739dce7f042fc2688d128815670918a98f032644e8e859b62bdf7&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42033&comment_hash=6a321650c85739dce7f042fc2688d128815670918a98f032644e8e859b62bdf7&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]