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


##########
superset-websocket/src/config.ts:
##########
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-import { merge as _merge } from 'lodash';
+import { merge as _merge } from 'lodash-es';

Review Comment:
   **Suggestion:** This file is now explicitly ESM, but `configFromFile()` 
still uses CommonJS `require()`, which will throw `ReferenceError: require is 
not defined` at runtime when loading config. Replace the config file loading 
path with an ESM-compatible approach (for example 
`createRequire(import.meta.url)` or `fs` + `JSON.parse`) so startup does not 
fail. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Critical 🚨</summary>
   
   ```mdx
   ❌ Websocket service ignores config.json/config.test.json values.
   ⚠️ Vitest config tests fail, blocking CI success.
   ⚠️ JWT secret from file never applied to opts.
   ⚠️ Redis/statds tuning from file never applied.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Open `/workspace/superset/superset-websocket/package.json` where line 5 
sets `"type":
   "module"` and `/workspace/superset/superset-websocket/tsconfig.json` where 
line 6 sets
   `"module": "nodenext"`, confirming the compiled JS for this service runs as 
native ESM.
   
   2. Start the websocket service via `npm run start` (script defined at 
`package.json:7` as
   `node dist/index.js start`), which loads the compiled `dist/index.js` 
entrypoint from
   `/workspace/superset/superset-websocket/src/index.ts`.
   
   3. In `/workspace/superset/superset-websocket/src/index.ts` lines 18–23, 
`environment` and
   `startServer` are computed, then `export const opts = buildConfig();` is 
executed,
   importing `buildConfig` from 
`/workspace/superset/superset-websocket/src/config.ts:192`.
   
   4. In `/workspace/superset/superset-websocket/src/config.ts` lines 192–195,
   `buildConfig()` calls `defaultConfig()` and `configFromFile()`, then passes 
the result
   through `applyEnvOverrides()`, so `configFromFile()` runs on every startup 
and for every
   test that calls `buildConfig()`.
   
   5. In the same file, `configFromFile()` at lines 103–107 computes 
`configFile` as
   `'../config.json'` or `'../config.test.json'`, then executes `return 
require(configFile);`
   inside a `try` block; under ESM (package `"type": "module"`), `require` is 
not defined, so
   this line throws `ReferenceError: require is not defined`, which is caught 
by the `catch`
   at lines 108–111, causing a `console.warn('config.json file not found')` and 
returning
   `{}` instead of the JSON contents even when
   `/workspace/superset/superset-websocket/config.test.json` exists.
   
   6. When running tests via `npm test` (script at `package.json:9`), 
`spec/config.test.ts`
   line 22 calls `buildConfig()` and expects values sourced from 
`config.test.json` (e.g.,
   `jwtSecret`, redis `db`, statsd host/port). Because `configFromFile()` now 
always returns
   `{}` due to the ESM `require` failure, these expectations no longer match, 
causing the
   config tests to fail and CI to report red; similarly, in production the 
service will
   silently ignore `config.json` and run with defaults plus env vars only.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=5556c6d828ef4df3bd4ea35a5d3655b5&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=5556c6d828ef4df3bd4ea35a5d3655b5&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-websocket/src/config.ts
   **Line:** 20:20
   **Comment:**
        *Api Mismatch: This file is now explicitly ESM, but `configFromFile()` 
still uses CommonJS `require()`, which will throw `ReferenceError: require is 
not defined` at runtime when loading config. Replace the config file loading 
path with an ESM-compatible approach (for example 
`createRequire(import.meta.url)` or `fs` + `JSON.parse`) so startup does not 
fail.
   
   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%2F41680&comment_hash=f0a641675c115e916897884d5c12538af7e927c8caccab34b40e1e8ae2937e5c&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41680&comment_hash=f0a641675c115e916897884d5c12538af7e927c8caccab34b40e1e8ae2937e5c&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