codeant-ai-for-open-source[bot] commented on code in PR #37367:
URL: https://github.com/apache/superset/pull/37367#discussion_r3662327656
##########
superset-frontend/src/preamble.test.ts:
##########
@@ -111,3 +114,32 @@ test('falls back to en when passing locale to
setupFormatters', async () => {
expect(mockSetupFormatters).toHaveBeenCalledWith({}, {}, 'en');
});
+
+test('initializes feature flags before fetching non-English language pack',
async () => {
+ const featureFlags = { EMBEDDED_SUPERSET: true };
+ mockGetBootstrapData.mockReturnValue(bootstrapData('fr', featureFlags));
+
+ const originalFetch = global.fetch;
+ const fetchMock = jest
+ .fn<ReturnType<typeof fetch>, Parameters<typeof fetch>>()
+ .mockResolvedValue({
+ ok: true,
+ json: jest.fn().mockResolvedValue({}),
+ } as unknown as Response);
+ global.fetch = fetchMock;
+
+ try {
+ await runPreamble();
+
+ expect(mockInitFeatureFlags).toHaveBeenCalledWith(featureFlags);
+ expect(fetchMock).toHaveBeenCalledWith('/superset/language_pack/fr/', {
+ signal: expect.any(AbortSignal),
+ });
Review Comment:
**Suggestion:** The test replaces `initFeatureFlags` with a recording-only
mock, so it verifies only that the call receives the expected argument and
precedes the language-pack fetch. It never verifies that `window.featureFlags`
is actually populated, nor that pre-existing global flags are handled, allowing
a broken initialization implementation to pass. Use the real initializer or add
an integration assertion against `window.featureFlags`. [possible bug]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Preamble regression tests miss global flag-state failures.
- ⚠️ Embedded feature checks remain unverified by this test.
- ⚠️ Incorrect initialization can reach `isFeatureEnabled()` console errors.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Run the `initializes feature flags before fetching non-English language
pack` test at
`superset-frontend/src/preamble.test.ts:118-145`; the test replaces
`@superset-ui/core`'s
`initFeatureFlags` with the recording-only `mockInitFeatureFlags` declared
at line 21 and
configured at lines 40-43.
2. `runPreamble()` at `superset-frontend/src/preamble.test.ts:92-95` imports
`preamble.ts`, which calls the mocked initializer at
`superset-frontend/src/preamble.ts:70`.
3. The assertion at `superset-frontend/src/preamble.test.ts:134` verifies
only the mock
arguments, while the ordering assertions at lines 135-141 verify only the
language-pack
request and call order.
4. No assertion reads `window.featureFlags`, even though the production
implementation at
`superset-frontend/packages/superset-ui-core/src/utils/featureFlags.ts:100-103`
assigns
the state consumed by `isFeatureEnabled()` at lines 106-112; therefore an
implementation
that receives the correct flags but fails to assign `window.featureFlags`
would still pass
this test.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=84fbba398f604e22970795f27bc84e0c&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=84fbba398f604e22970795f27bc84e0c&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/src/preamble.test.ts
**Line:** 134:137
**Comment:**
*Possible Bug: The test replaces `initFeatureFlags` with a
recording-only mock, so it verifies only that the call receives the expected
argument and precedes the language-pack fetch. It never verifies that
`window.featureFlags` is actually populated, nor that pre-existing global flags
are handled, allowing a broken initialization implementation to pass. Use the
real initializer or add an integration assertion against `window.featureFlags`.
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%2F37367&comment_hash=1caed5912e3058efccbc9b0d2e9fbb6f01dc403c9a0b4ffa9fca0cbf6a3731c8&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37367&comment_hash=1caed5912e3058efccbc9b0d2e9fbb6f01dc403c9a0b4ffa9fca0cbf6a3731c8&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]