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


##########
superset-frontend/src/preamble.test.ts:
##########
@@ -0,0 +1,66 @@
+/**
+ * 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.
+ */
+
+import { initFeatureFlags } from '@superset-ui/core';
+import getBootstrapData from 'src/utils/getBootstrapData';
+
+jest.mock('@superset-ui/core', () => ({
+  ...jest.requireActual('@superset-ui/core'),
+  initFeatureFlags: jest.fn(),
+  makeApi: jest.fn(() => jest.fn(() => Promise.resolve({}))),
+}));
+
+jest.mock('@apache-superset/core/translation', () => ({
+  configure: jest.fn(),
+}));
+
+jest.mock('@apache-superset/core/utils', () => ({
+  logging: { warn: jest.fn(), error: jest.fn() },
+}));
+
+jest.mock('src/utils/getBootstrapData', () => ({
+  __esModule: true,
+  default: jest.fn(() => ({
+    common: {
+      feature_flags: { EMBEDDED_SUPERSET: true },
+      d3_format: {},
+      d3_time_format: {},
+      locale: 'en',
+    },
+    user: { isActive: false },
+  })),
+  applicationRoot: jest.fn(() => '/'),
+}));
+
+jest.mock('src/setup/setupClient', () => jest.fn());
+jest.mock('src/setup/setupColors', () => jest.fn());
+jest.mock('src/setup/setupFormatters', () => jest.fn());
+jest.mock('src/setup/setupDashboardComponents', () => jest.fn());
+jest.mock('src/hooks/useLocale', () => ({}));
+
+test('initPreamble calls initFeatureFlags synchronously before language pack 
fetch', async () => {
+  const initPreamble = (await import('./preamble')).default;
+
+  // initPreamble is called eagerly at module load, so initFeatureFlags
+  // should already have been called by the time the module finishes loading
+  await initPreamble();
+
+  expect(initFeatureFlags).toHaveBeenCalledWith({ EMBEDDED_SUPERSET: true });
+  expect(getBootstrapData).toHaveBeenCalled();

Review Comment:
   **Suggestion:** The test currently awaits initialization before asserting 
and uses an English locale, so it does not actually verify that feature flags 
are initialized before language pack fetch begins. Configure a non-English 
locale, mock `fetch`, and assert call order to validate the intended 
synchronous-before-fetch behavior. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ CI test misses ordering regressions in preamble initialization.
   - ⚠️ Language-pack path remains unverified by this unit test.
   ```
   </details>
   
   ```suggestion
     (getBootstrapData as jest.Mock).mockReturnValue({
       common: {
         feature_flags: { EMBEDDED_SUPERSET: true },
         d3_format: {},
         d3_time_format: {},
         locale: 'fr',
       },
       user: { isActive: false },
     });
   
     const originalFetch = global.fetch;
     const fetchMock = jest.fn().mockResolvedValue({
       ok: true,
       json: async () => ({}),
     });
     (global as any).fetch = fetchMock;
   
     const initPreamble = (await import('./preamble')).default;
   
     expect(initFeatureFlags).toHaveBeenCalledWith({ EMBEDDED_SUPERSET: true });
     expect(fetchMock).toHaveBeenCalled();
   
     const flagsOrder = (initFeatureFlags as 
jest.Mock).mock.invocationCallOrder[0];
     const fetchOrder = fetchMock.mock.invocationCallOrder[0];
     expect(flagsOrder).toBeLessThan(fetchOrder);
   
     await initPreamble();
     (global as any).fetch = originalFetch;
   ```
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Open `superset-frontend/src/preamble.test.ts:44`; mocked bootstrap locale 
is `'en'`.
   
   2. Open `superset-frontend/src/preamble.ts:73-74`; language-pack `fetch` 
runs only when
   locale is not `'en'`.
   
   3. Open `superset-frontend/src/preamble.test.ts:62-65`; test awaits full 
`initPreamble()`
   and only asserts `initFeatureFlags`/`getBootstrapData`, with no `fetch` 
assertion or
   call-order check.
   
   4. Therefore, the current test cannot verify "before language pack fetch" 
behavior; it can
   pass without exercising the fetch path at all.
   ```
   </details>
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/src/preamble.test.ts
   **Line:** 58:65
   **Comment:**
        *Logic Error: The test currently awaits initialization before asserting 
and uses an English locale, so it does not actually verify that feature flags 
are initialized before language pack fetch begins. Configure a non-English 
locale, mock `fetch`, and assert call order to validate the intended 
synchronous-before-fetch behavior.
   
   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.
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37367&comment_hash=76389b48b3614a0f174ced87e13455e2b7b18085c08ee3308bdced276f6b82ed&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37367&comment_hash=76389b48b3614a0f174ced87e13455e2b7b18085c08ee3308bdced276f6b82ed&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