Skip to content

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
souma9830:masterfrom
webgo-oss:fix/backend-boot-crash-audit-routes
Open

Fix: backend fails to boot due to import.meta bug and missing audit controller exports#1906
webgo-oss wants to merge 2 commits into
souma9830:masterfrom
webgo-oss:fix/backend-boot-crash-audit-routes

Conversation

@webgo-oss

Copy link
Copy Markdown

Problem

The backend server crashes on startup and cannot boot at all.

Root cause (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 (and any CommonJS-transpiled context) that transitively imports this file.

  2. 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

  • uploadPaths.utils.js: reference import.meta.url directly instead of a bare import.meta check, so the babel plugin can fully transform it away in non-ESM contexts. Also fixed resolveUploadPath() to reject dotfiles/hidden files, a gap uploadPaths.test.js already expected but wasn't catching because the syntax error was masking the whole suite.
  • audit.controller.js: implemented exportAuditLogs (supports CSV/NDJSON/JSON via the pre-existing but previously-unused auditFormatter.utils.js and auditQuery.validation.js) and aliased getAuditSummary to the existing getAuditStats logic.

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

  • 2 files changed
  • 52 insertions, 3 deletions
  • No breaking changes to existing working endpoints; only adds previously-missing functionality and fixes the boot crash.

…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.
@vercel

vercel Bot commented Aug 10, 2026

Copy link
Copy Markdown

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants