Skip to content

refactor: Migrate processes/services to devenv2#33

Merged
cschwartz merged 3 commits into
mainfrom
refactor/enter-test-native-devenv2
Mar 20, 2026
Merged

refactor: Migrate processes/services to devenv2#33
cschwartz merged 3 commits into
mainfrom
refactor/enter-test-native-devenv2

Conversation

@cschwartz
Copy link
Copy Markdown
Owner

@cschwartz cschwartz commented Mar 20, 2026

Summary by CodeRabbit

  • New Features

    • Environment-specific config files supported (development/test/production) and task to generate .env.{env} with service URLs.
    • Dynamic HTTP port allocation for backend and mock services.
  • Refactor

    • Replaced hard-coded service URLs/ports with configurable values; simplified local dev/test startup and readiness checks.
    • Tests now honor VERDICT_URL for endpoint discovery.
  • Chores

    • Updated .gitignore to ignore environment-specific .env files.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 20, 2026

📝 Walkthrough

Walkthrough

Refactors development environment to use environment-specific .env files, validate runtime ENVIRONMENT, allocate service HTTP ports dynamically via Nix, update readiness checks and tasks, remove legacy dev recipes, and make tests derive endpoints from configured VERDICT_URL/settings.

Changes

Cohort / File(s) Summary
Gitignore & DB env loading
\.gitignore, verdict-backend/app/database_config.py
Replaced .env.sample ignore with explicit ignores for .env.development, .env.test, .env.production, and .env.*.local. Added runtime ENVIRONMENT validation and conditional loading of ".env.{_environment}" and ".env.{_environment}.local" in database settings.
Mock services Nix module
mock-services/devenv.nix
Changed default env.MOCK_SERVICES_DIR path; replaced hardcoded mock ports with config.processes.<name>.ports.http.value; added ports.http.allocate and ready.http.get entries using configured ports and existing readiness paths.
App Nix/devenv tasks
verdict-backend/devenv.nix
Removed process-compose usage for verdict-app; made app port derive from config.processes.verdict-app.ports.http.value; replaced readiness_probe with ready.http.get; replaced single env.MOCK_SERVICES_DIR with conditional exported env set; added verdict-app:gen-env, db tasks, and simplified enterTest/enterShell behavior.
Removed manual recipes
verdict-backend/justfile
Removed dev, dev-test, db-info, and setup recipes that previously started the app or performed manual DB readiness/migrations.
Tests: endpoint/config changes
verdict-backend/tests/e2e/conftest.py, verdict-backend/tests/routes/test_ingestion.py
base_url fixture now reads VERDICT_URL env var (fallback http://localhost:8000). Ingestion tests now build mocked external endpoints from app.config.settings instead of hardcoded localhost URLs and ports.

Sequence Diagram(s)

sequenceDiagram
  participant Task as devenv task (gen-env / db tasks)
  participant Postgres as Postgres DB
  participant Mocks as Mock Services
  participant App as verdict-app (Uvicorn)
  Task->>Postgres: ensure DB name/port (DATABASE_NAME, DATABASE_PORT)
  Task->>Mocks: read allocated mock ports -> generate `.env.{env}`
  Task->>App: set VERDICT_URL from app allocated port
  Postgres-->>Task: DB ready
  Mocks-->>Task: Mocks ready (ready.http.get)
  Task->>App: start Uvicorn with port from config
  App->>App: readiness checked via ready.http.get on configured port
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibbled hardcodes, hopped on ports anew,
Env files sorted into named little crews,
Tasks now hum in order, services wake on cue,
Tests follow VERDICT_URL — neat and true,
A rabbit's tweak, a cleaner view!

🚥 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 summarizes the main change: migrating process and service management to devenv2 across multiple configuration files.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/enter-test-native-devenv2

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.

Tip

CodeRabbit can enforce grammar and style rules using `languagetool`.

Configure the reviews.tools.languagetool setting to enable/disable rules and categories. Refer to the LanguageTool Community to learn more.

Copy link
Copy Markdown

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.gitignore:
- Around line 55-58: Add a rule to .gitignore to also ignore production env
files so secrets can't be committed: update the .gitignore patterns (near the
existing .env.development, .env.test, and .env.*.local entries) to include
.env.production (and optionally .env.*.production or .env.production.local) so
the repository ignores production environment files referenced by
verdict-backend/app/database_config.py.

In `@verdict-backend/app/database_config.py`:
- Around line 7-21: The module currently computes _environment and validates it
at import time (using _VALID_ENVIRONMENTS and _environment) which freezes
ENVIRONMENT and can raise during import; change this so ENVIRONMENT is resolved
and validated lazily when settings are requested (e.g., inside
get_database_settings() or DatabaseSettings.__init__/a factory), remove the
module-level os.getenv and the import-time raise, and build
DatabaseSettings.model_config.env_file (or pass env_file into BaseSettings)
using the environment value obtained at call time; ensure
get_database_settings() performs the validation against _VALID_ENVIRONMENTS and
uses that runtime value to construct the env_file list.

In `@verdict-backend/devenv.nix`:
- Around line 132-148: The db-migrate and db-setup tasks
(tasks."verdict-app:db-migrate" and tasks."verdict-app:db-setup") need to wait
for Postgres to be ready; add "devenv:processes:postgres" to each task's after
array so the tasks depend on the Postgres process being up before running
migrations or db reset/setup.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d6f19a38-c2f1-472e-bcbd-9cfd8ae7f364

📥 Commits

Reviewing files that changed from the base of the PR and between efb3fce and ed72721.

📒 Files selected for processing (7)
  • .gitignore
  • mock-services/devenv.nix
  • verdict-backend/app/database_config.py
  • verdict-backend/devenv.nix
  • verdict-backend/justfile
  • verdict-backend/tests/e2e/conftest.py
  • verdict-backend/tests/routes/test_ingestion.py
💤 Files with no reviewable changes (1)
  • verdict-backend/justfile

Comment thread .gitignore
Comment thread verdict-backend/app/database_config.py
Comment thread verdict-backend/devenv.nix
Copy link
Copy Markdown

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

🧹 Nitpick comments (1)
verdict-backend/devenv.nix (1)

20-26: Consolidate duplicated env config into one source of truth.

ENVIRONMENT, DATABASE_NAME, DATABASE_PORT, and VERDICT_URL are defined twice (global env and .env.* generation). This can drift over time.

Refactor sketch
+  # Single source of truth for shared runtime values
+  # (declare in outer let/in scope)
+  runtimeEnv = {
+    ENVIRONMENT = if config.devenv.isTesting then "test" else "development";
+    DATABASE_NAME = if config.devenv.isTesting then "${database_name}_test" else database_name;
+    DATABASE_PORT = toString config.processes.postgres.ports.main.value;
+    VERDICT_URL = "http://localhost:${toString config.processes.verdict-app.ports.http.value}";
+  };
+
-  env = {
-    DATABASE_NAME = if config.devenv.isTesting then "${database_name}_test" else database_name;
-    DATABASE_PORT = toString config.processes.postgres.ports.main.value;
-    ENVIRONMENT = if config.devenv.isTesting then "test" else "development";
-    VERDICT_URL = "http://localhost:${toString config.processes.verdict-app.ports.http.value}";
-  };
+  env = runtimeEnv;

   tasks."verdict-app:gen-env" = {
     exec = ''
       cat > .env.${environment} <<EOF
-      ENVIRONMENT=${environment}
-      DATABASE_NAME=${db_name}
-      DATABASE_PORT=${db_port}
+      ENVIRONMENT=${runtimeEnv.ENVIRONMENT}
+      DATABASE_NAME=${runtimeEnv.DATABASE_NAME}
+      DATABASE_PORT=${runtimeEnv.DATABASE_PORT}
       ...
-      VERDICT_URL=http://localhost:${toString config.processes.verdict-app.ports.http.value}
+      VERDICT_URL=${runtimeEnv.VERDICT_URL}
       EOF
     '';
   };

Also applies to: 106-127

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

In `@verdict-backend/devenv.nix` around lines 20 - 26, Duplicate environment
definitions are present in the top-level env attribute and in the .env.*
generation logic (keys: ENVIRONMENT, DATABASE_NAME, DATABASE_PORT, VERDICT_URL);
consolidate them into a single source of truth by extracting those computed
values into one place (e.g., a shared let-bound record or function) and have
both the global env and the .env.* generators reference that single record
(update usages that currently compute values inline such as the conditional on
config.devenv.isTesting, toString config.processes.postgres.ports.main.value,
and toString config.processes.verdict-app.ports.http.value); remove the
duplicated inline computations so all changes flow from that one symbol and
ensure the .env.* writer uses the same symbols for key names and values.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@verdict-backend/devenv.nix`:
- Around line 20-26: Duplicate environment definitions are present in the
top-level env attribute and in the .env.* generation logic (keys: ENVIRONMENT,
DATABASE_NAME, DATABASE_PORT, VERDICT_URL); consolidate them into a single
source of truth by extracting those computed values into one place (e.g., a
shared let-bound record or function) and have both the global env and the .env.*
generators reference that single record (update usages that currently compute
values inline such as the conditional on config.devenv.isTesting, toString
config.processes.postgres.ports.main.value, and toString
config.processes.verdict-app.ports.http.value); remove the duplicated inline
computations so all changes flow from that one symbol and ensure the .env.*
writer uses the same symbols for key names and values.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3d08bcc2-05c1-49cb-96b5-aadbaa74f9b8

📥 Commits

Reviewing files that changed from the base of the PR and between ed72721 and 32ea4e6.

📒 Files selected for processing (2)
  • .gitignore
  • verdict-backend/devenv.nix
✅ Files skipped from review due to trivial changes (1)
  • .gitignore

@cschwartz cschwartz merged commit 43f2c5e into main Mar 20, 2026
1 of 3 checks passed
@cschwartz cschwartz deleted the refactor/enter-test-native-devenv2 branch March 20, 2026 16:34
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.

1 participant