codeant-ai-for-open-source[bot] commented on code in PR #41680:
URL: https://github.com/apache/superset/pull/41680#discussion_r3545850670
##########
superset-websocket/src/config.ts:
##########
@@ -104,7 +105,7 @@ function configFromFile(): Partial<ConfigType> {
const isTest = process.env.NODE_ENV === 'test';
const configFile = isTest ? '../config.test.json' : '../config.json';
try {
- return require(configFile);
+ return JSON.parse(readFileSync(configFile, 'utf8')) as ConfigType;
Review Comment:
**Suggestion:** Using `readFileSync` with `configFile` as a bare relative
path resolves against `process.cwd()`, not against
`config.ts`/`dist/config.js`. This changes behavior from module-relative
loading and will miss `superset-websocket/config.test.json` (and production
`config.json`) when the process is started from the package root, causing
file-based config to be silently skipped. Resolve the path from
`import.meta.url` (or equivalent module directory logic) before reading. [api
mismatch]
<details>
<summary><b>Severity Level:</b> Critical π¨</summary>
```mdx
- β WebSocket sidecar container fails startup despite config.json present.
- β JWT secret from config.json never applied to server options.
- β οΈ Test config.test.json ignored; tests use default connection settings.
```
</details>
<details>
<summary><b>Steps of Reproduction β
</b></summary>
```mdx
1. Start the `superset-websocket` service using Docker Compose, which
defines the
`superset-websocket` container at `docker-compose.yml:18-47` and mounts a
config file to
`/home/superset-websocket/config.json` via the volume at
`docker-compose.yml:41-43`. The
Dockerfile at `superset-websocket/Dockerfile:40-51` sets `WORKDIR
/home/superset-websocket` and runs `CMD ["npm", "start"]`, which uses the
`start` script
in `superset-websocket/package.json:7-8` (`"start": "node dist/index.js
start"`), so
Nodeβs `process.cwd()` is `/home/superset-websocket`.
2. When `dist/index.js` runs, it imports `./config.js` and immediately calls
`buildConfig()` via `export const opts = buildConfig();` at
`superset-websocket/src/index.ts:29-31,81`. `buildConfig()` in
`superset-websocket/src/config.ts:193-195` merges `defaultConfig()` with
`configFromFile()`.
3. Inside `configFromFile()` at `superset-websocket/src/config.ts:104-109`,
`NODE_ENV` is
`production`, so `isTest` is false and `configFile` is set to
`'../config.json'` at line
106. The call `readFileSync(configFile, 'utf8')` at line 108 resolves
`'../config.json'`
relative to `process.cwd()` (`/home/superset-websocket`), so Node attempts
to read
`/home/config.json`, but the actual file is at
`/home/superset-websocket/config.json`.
This causes `readFileSync` to throw `ENOENT`, the `catch` block at lines
109-111 logs
`config.json file not found`, and `configFromFile()` returns `{}`, silently
discarding the
mounted configuration.
4. Because file configuration is ignored, `buildConfig()` returns only
`defaultConfig()`
and `opts.jwtSecret` remains the empty string from `defaultConfig()`
(`superset-websocket/src/config.ts:70-72`). With `startServer` true
(`process.argv[2] ===
'start'` at `superset-websocket/src/index.ts:79`), the startup check at
`superset-websocket/src/index.ts:98-102` detects `opts.jwtSecret.length <
32`, logs
`Please provide a JWT secret at least 32 bytes long`, and calls
`process.exit(1)`, causing
the `superset-websocket` container to fail to start even though a valid
`config.json` (or
`config.example.json`) is present and mounted.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=592884349a7c4b83ae30226fa6fb9cb7&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=592884349a7c4b83ae30226fa6fb9cb7&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:** 108:108
**Comment:**
*Api Mismatch: Using `readFileSync` with `configFile` as a bare
relative path resolves against `process.cwd()`, not against
`config.ts`/`dist/config.js`. This changes behavior from module-relative
loading and will miss `superset-websocket/config.test.json` (and production
`config.json`) when the process is started from the package root, causing
file-based config to be silently skipped. Resolve the path from
`import.meta.url` (or equivalent module directory logic) before reading.
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=484f9a83b0969d2062d2a4faee41258f054dc1190c2422e5a70c6c9d19000802&reaction=like'>π</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41680&comment_hash=484f9a83b0969d2062d2a4faee41258f054dc1190c2422e5a70c6c9d19000802&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]