Fix: backend fails to boot due to import.meta bug and missing audit controller exports - #1906
Open
webgo-oss wants to merge 2 commits into
Open
Fix: backend fails to boot due to import.meta bug and missing audit controller exports#1906webgo-oss wants to merge 2 commits into
webgo-oss wants to merge 2 commits into
Conversation
…ontroller exports Two compounding bugs: 1. src/utils/uploadPaths.utils.js used a bare 'typeof import.meta !== undefined' check. The babel plugin used under Jest only rewrites import.meta.url specifically, not a bare import.meta reference, so this line is a parse-time SyntaxError that no try/catch can guard against. This crashed every test suite that transitively imports this file. 2. Fixing souma9830#1 exposed a second, more severe bug underneath it: src/routes/audit.routes.js imports getAuditSummary and exportAuditLogs from the audit controller, but neither function existed (only getAuditStats did). Express throws at route-registration time when handed an undefined callback, which means app.js could not load at all — the entire backend server was dead on arrival, this was just being masked by bug souma9830#1 crashing first. Fix: - uploadPaths.utils.js: reference import.meta.url directly so the babel plugin can fully transform it away, and reject dotfiles in resolveUploadPath() (uncovered by uploadPaths.test.js once the syntax error was no longer masking it). - audit.controller.js: implement exportAuditLogs (CSV/NDJSON/JSON, wired up to the pre-existing but previously-unused auditFormatter.utils.js and auditQuery.validation.js) and alias getAuditSummary to the existing getAuditStats logic. Verified: 'npm run check:boot' passes, and the app now loads/boots cleanly under Jest. Remaining unrelated test failures (anomaly detection routes, two other pre-existing test bugs) are addressed in a follow-up PR.
|
@webgo-oss is attempting to deploy a commit to the souma9830's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The backend server crashes on startup and cannot boot at all.
Root cause (two compounding bugs)
src/utils/uploadPaths.utils.js used a bare "typeof import.meta !== undefined" check. The babel plugin used under Jest only rewrites import.meta.url specifically, not a bare import.meta reference, so this line is a parse-time SyntaxError that no try/catch can guard against. This crashed every test suite (and any CommonJS-transpiled context) that transitively imports this file.
Fixing Fixing navbar #1 exposed a second, more severe bug underneath it: src/routes/audit.routes.js imports getAuditSummary and exportAuditLogs from the audit controller, but neither function existed (only getAuditStats did). Express throws at route-registration time when handed an undefined callback:
Route.get() requires a callback function but got a [object Undefined]
This means app.js could not load at all — the entire backend server was dead on arrival. It was simply being masked by bug Fixing navbar #1 crashing first, so nobody saw it.
Fix
Testing
cd backend
npm install
npm run check:boot # passes — module syntax check
npm run dev # server now boots cleanly instead of crashing
npm test # 32/35 suites, 90/94 tests passing
The 3 remaining test failures (app.test.js, anomalyDetector.test.js, healthCheck.test.js) are pre-existing, unrelated bugs scoped to a follow-up PR — not regressions introduced here.
Changes