Skip to content

(SP: 1) [FIX] Add Netlify runtime env diagnostics to db/index.ts#424

Merged
ViktorSvertoka merged 5 commits intodevelopfrom
sl/feat/db-optimization
Mar 28, 2026
Merged

(SP: 1) [FIX] Add Netlify runtime env diagnostics to db/index.ts#424
ViktorSvertoka merged 5 commits intodevelopfrom
sl/feat/db-optimization

Conversation

@LesiaUKR
Copy link
Copy Markdown
Collaborator

@LesiaUKR LesiaUKR commented Mar 28, 2026

Diagnose why Netlify develop deploy runtime does not see APP_ENV and DATABASE_URL despite both being configured in Netlify dashboard (All scopes).

Summary by CodeRabbit

  • Bug Fixes

    • Improved category title formatting in the admin interface with proper trimming and fallback handling.
  • Tests

    • Updated test environment configuration for consistency across test suites.

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
devlovers-net Ignored Ignored Preview Mar 28, 2026 1:37pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 28, 2026

📝 Walkthrough

Walkthrough

The pull request relaxes mandatory APP_ENV validation in the database initialization module, allows APP_ENV to be undefined at runtime, extends runtime logging with diagnostic environment values, and configures test environments to explicitly set APP_ENV to 'local'. A string trimming fix is applied to category title handling.

Changes

Cohort / File(s) Summary
Test Environment Configuration
frontend/vitest.config.ts, frontend/vitest.shop.config.ts
Added test.env block injecting APP_ENV: 'local' into test runtime for both config files.
Database Module
frontend/db/index.ts
Removed mandatory APP_ENV validation; moved IS_LOCAL_ENV computation after logging; extended console diagnostics to include APP_ENV, NETLIFY, CONTEXT, NODE_ENV with '<undefined>' defaults; allows APP_ENV to be undefined at runtime.
Query Fix
frontend/db/queries/categories/admin-categories.ts
Updated getAdminCategoryList() to trim row.title and fallback to row.slug when title is null or empty string.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested labels

testing

Suggested reviewers

  • AM1007
  • ViktorSvertoka
  • liudmylasovetovs

Poem

🐰 The rabbit hops through test-time meadows bright,
Where APP_ENV now flows without a fight,
With trimmed-up titles and diagnostic glow,
The gardens grow where undefined can flow! 🌱

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the primary change: adding Netlify runtime environment diagnostics to db/index.ts, which is the main fix addressed in the PR to debug the APP_ENV visibility issue.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sl/feat/db-optimization

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
frontend/vitest.config.ts (1)

15-22: ⚠️ Potential issue | 🟡 Minor

Fix inconsistent indentation in the test block.

Same indentation issue as in vitest.shop.config.ts. The env: key and APP_ENV have inconsistent indentation compared to sibling properties.

🔧 Proposed fix
   test: {
-      env: {
-    APP_ENV: 'local',
-    },
+    env: {
+      APP_ENV: 'local',
+    },
     environment: 'node',
     include: [
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/vitest.config.ts` around lines 15 - 22, In the vitest.config.ts file
the test configuration block has inconsistent indentation for the env and
APP_ENV keys; update the block so that the env object and its APP_ENV property
align with the sibling properties (e.g., environment and include) inside the
test object—locate the test: { ... } block and re-indent the env: and APP_ENV
entries to the same column as environment and include so formatting is
consistent with vitest.shop.config.ts.
frontend/vitest.shop.config.ts (1)

15-22: ⚠️ Potential issue | 🟡 Minor

Fix inconsistent indentation in the test block.

The env block and its contents have inconsistent indentation compared to the rest of the test configuration. The env: key uses 6 spaces while APP_ENV uses 4 spaces, and sibling properties like environment use 4 spaces.

🔧 Proposed fix
   test: {
-      env: {
-    APP_ENV: 'local',
-    },
+    env: {
+      APP_ENV: 'local',
+    },
     environment: 'node',
     include: ['lib/tests/shop/**/*.test.ts'],
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/vitest.shop.config.ts` around lines 15 - 22, The test configuration
block has inconsistent indentation for the env map; normalize indentation so
keys align with other properties: adjust the "test" block's "env" key and its
"APP_ENV" entry to use the same 4-space indentation as "environment", "include",
and "setupFiles" — specifically update the "env", "APP_ENV" lines inside the
test config in vitest.shop.config.ts (referencing the test block, env, APP_ENV,
environment, include, setupFiles) so all sibling properties use consistent
4-space indentation.
🧹 Nitpick comments (1)
frontend/db/index.ts (1)

27-28: Consider logging a warning when APP_ENV is undefined.

When APP_ENV is undefined, IS_LOCAL_ENV becomes false, causing silent fallback to the production Neon path. While this aids Netlify debugging, it could mask misconfiguration in other environments. Consider adding a warning:

💡 Suggested improvement
 const IS_LOCAL_ENV = APP_ENV === 'local';
+
+if (!APP_ENV && process.env.NODE_ENV !== 'test') {
+  console.warn('[db] APP_ENV is undefined – defaulting to non-local mode');
+}

Also note that frontend/lib/env/auth.ts still throws when APP_ENV is undefined (see context snippet 3), so import order may cause different failure modes. You may want to reconcile these behaviors once debugging is complete.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/db/index.ts` around lines 27 - 28, APP_ENV may be undefined causing
silent fallback; update the initialization around IS_LOCAL_ENV to first check if
APP_ENV is undefined and emit a clear warning (e.g., console.warn or the project
logger) when it is, then compute const IS_LOCAL_ENV = APP_ENV === 'local';
locate the IS_LOCAL_ENV/APP_ENV usage in frontend/db/index.ts (and note related
behavior in frontend/lib/env/auth.ts which throws) and reconcile the behaviors
so configuration issues surface consistently across imports.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@frontend/vitest.config.ts`:
- Around line 15-22: In the vitest.config.ts file the test configuration block
has inconsistent indentation for the env and APP_ENV keys; update the block so
that the env object and its APP_ENV property align with the sibling properties
(e.g., environment and include) inside the test object—locate the test: { ... }
block and re-indent the env: and APP_ENV entries to the same column as
environment and include so formatting is consistent with vitest.shop.config.ts.

In `@frontend/vitest.shop.config.ts`:
- Around line 15-22: The test configuration block has inconsistent indentation
for the env map; normalize indentation so keys align with other properties:
adjust the "test" block's "env" key and its "APP_ENV" entry to use the same
4-space indentation as "environment", "include", and "setupFiles" — specifically
update the "env", "APP_ENV" lines inside the test config in
vitest.shop.config.ts (referencing the test block, env, APP_ENV, environment,
include, setupFiles) so all sibling properties use consistent 4-space
indentation.

---

Nitpick comments:
In `@frontend/db/index.ts`:
- Around line 27-28: APP_ENV may be undefined causing silent fallback; update
the initialization around IS_LOCAL_ENV to first check if APP_ENV is undefined
and emit a clear warning (e.g., console.warn or the project logger) when it is,
then compute const IS_LOCAL_ENV = APP_ENV === 'local'; locate the
IS_LOCAL_ENV/APP_ENV usage in frontend/db/index.ts (and note related behavior in
frontend/lib/env/auth.ts which throws) and reconcile the behaviors so
configuration issues surface consistently across imports.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e6248f22-7622-4d10-9440-42c17965ceef

📥 Commits

Reviewing files that changed from the base of the PR and between 97cdfa5 and 1f5cee8.

📒 Files selected for processing (4)
  • frontend/db/index.ts
  • frontend/db/queries/categories/admin-categories.ts
  • frontend/vitest.config.ts
  • frontend/vitest.shop.config.ts

@ViktorSvertoka ViktorSvertoka merged commit 04191f8 into develop Mar 28, 2026
7 checks passed
@ViktorSvertoka ViktorSvertoka deleted the sl/feat/db-optimization branch March 28, 2026 12:36
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.

2 participants