fix: make heartbeat reporting and Prisma init build-safe#371
Open
itsmiso-ai wants to merge 2 commits into
Open
fix: make heartbeat reporting and Prisma init build-safe#371itsmiso-ai wants to merge 2 commits into
itsmiso-ai wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
AI Automated Review
Full PR review.
Analysis engine: dsv4f@https://litellm.jory.dev/v1 (openai) — fallback (primary failed)
Recommendation: Approve
This PR fixes the build-time Prisma initialization to be lazy, resolving the crash during next build when DATABASE_URL is not set. It also corrects the heartbeat orchestration to report actual sync/reconcile counts instead of hardcoded zeros. Both changes include comprehensive regression tests.
Change-by-Change Findings
src/lib/prisma.ts
- Replaces eager
PrismaPg/PrismaClientconstruction (which threw at module load whenDATABASE_URLwas absent) with a lazy Proxy that defers initialization until first property access. - The
initClient()function checksDATABASE_URLthenDISPATCH_DATABASE_URL(alias) and throws a clear error if neither is set. - Exports
__resetPrismaClientForTests()for test isolation. - Conforms to the AGENTS.md contract: "Next.js static generation runs at build time; Prisma initializes lazily."
src/lib/prisma.test.ts
- Verifies that importing the module does not throw when
DATABASE_URLis unset. - Verifies that accessing a property on the lazy proxy throws a clear error (
/DATABASE_URL is not set/). - Verifies that after setting the env var and resetting the client, access succeeds.
- Verifies that
DISPATCH_DATABASE_URLis accepted as an alias.
src/lib/heartbeat.ts
runSyncBestEffortnow returns the actualreposProcessedfrom the underlyingsyncIssuesForReposresult (was hardcoded0).runReconcileBestEffortnow returnsissuesReconciled,issuesChecked, andreposProcessedfrom thereconcileClosedIssuesresponse (was only returning after catch block; the success path was returning nothing).
src/lib/heartbeat.test.ts
- Mocks the external dependencies (
issue-sync,config,github,prisma). - Tests that
runReconcileBestEffortpropagates the actual counts from the mock. - Tests that
runSyncBestEffortpropagates the actualreposProcessedfrom the mock.
Standards Compliance
- The lazy Prisma pattern exactly matches the guidance in AGENTS.md under "DATABASE_URL not found at build time."
- Environment variable resolution order (
DATABASE_URL>DISPATCH_DATABASE_URL) matches the documented convention. - Error messages are clear and reference both env var names.
- No secrets or build artifacts are committed.
Tool Harness Findings
- The tool harness confirmed the contents of the changed files align with the diff.
- No unexpected modifications were found.
Linked Issue Fit
- No linked issue was provided; the PR body describes the problem and fix clearly.
Unknowns / Needs Verification
- None. The CI checks (Docker Build, Validate) all passed.
Verdict: Approve
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.
Summary
Validation