Skip to content

fix: make application imports side-effect free - #5

Merged
adity982 merged 4 commits into
mainfrom
agent/testable-app-startup
Jul 27, 2026
Merged

adity982 merged 4 commits into
mainfrom
agent/testable-app-startup

Conversation

@adity982

@adity982 adity982 commented Jul 27, 2026 •

Copy link
Copy Markdown
Owner

What changed

  • guard application startup with require.main === module
  • export start() while preserving npm start behavior
  • add a subprocess regression test that fails if an import connects to MySQL or opens the server
  • document the testable startup boundary in the README

Why

Importing src/app.js currently connects to MySQL and starts an HTTP listener. That prevents isolated route tests and makes the Express application unsafe to embed in another process.

This replacement starts from current main and intentionally excludes the insight-engine work already shipped in #1.

User and developer impact

Consumers can import the configured Express app without process-level side effects. Direct execution still connects to MySQL and starts the server, and tests can invoke the exported startup function explicitly.

Validation

  • branch is three commits ahead of main with no divergence
  • functional diff is limited to src/app.js, test/app.test.js, and README guidance
  • the subprocess test requires no database credentials or network access
  • GitHub Actions run 30241272004 passed npm run lint and npm test on Node.js 18, 20, and 22
  • DAILY_LOG.md records the shipped scope, validation, metrics, and next move

Closes #2

@adity982
adity982 marked this pull request as ready for review July 27, 2026 05:59
@adity982
adity982 merged commit 68f4336 into main Jul 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Importing the Express app starts MySQL and the HTTP server

1 participant