#1878

fix(compose): import service env_file variables instead of dropping them

Opensanthiprakashwants to merge intofrom

Summary

Compose import now reads each service's env_file: — string, list, and long-form {path, required, format} entries — resolves the paths against the compose file's directory, and merges the referenced dotenv/raw contents into the service environment below environment:, matching Compose's own precedence. Files that cannot be read surface as a non-blocking unsupported warning instead of vanishing silently.

Motivation

#1854: a service's env_file: was dropped in silence. parseComposeFile never read svc.env_file, and UNSUPPORTED_SERVICE_KEYS had no entry for it, so collectUnsupported stayed quiet — the exact failure mode #533 set out to prevent. The app then starts without DATABASE_URL, SECRET_KEY_BASE, etc., and nothing points at env_file as the reason. The issue sketches two directions (a minimal UNSUPPORTED_SERVICE_KEYS warning vs. actually reading the files); this implements the fuller one — the values arrive, and unreadable files still get the honest warning, so both failure modes are covered.

Verified still present on current main (e94cbb99b): env_file is absent from the parser and from UNSUPPORTED_SERVICE_KEYS (only envFileContent interpolation of the compose-adjacent .env exists).

Related issue

Fixes #1854.

Changes

  • packages/platform compose-parser.ts:
    • parseServiceEnvFiles + resolveServiceEnvFiles — normalize env_file declarations, interpolate the path, resolve it against composeDirectory (the compose file's directory, like Compose itself), and parse contents as dotenv (default) or literal KEY=VALUE lines (format: raw).
    • Values merge below environment: — later files override earlier ones, explicit environment: values win.
    • A file that cannot be read lands on unsupported as a non-blocking warning naming the service and path; required: false entries stay silent, matching Compose. Absolute/~/..-above-root paths and malformed entries are reported rather than dropped.
    • composeEnvFilePaths — exported helper returning the resolved repo-relative paths a compose file names, so callers know exactly what to fetch.
    • ComposeParseOptions gains composeDirectory and envFileContents; hasEnvironmentDeclaration now also counts env_file so snapshot-safe sync paths treat the merged env correctly.
  • packages/platform prepare.service.ts:
    • readComposeEnvFileContents fetches each declared path through the same ProjectReader used for the compose file (local and Git-backed sources behave identically); resolveFromReader passes the map into toProjectInfo → parseComposeFile.
    • Callers that parse without a reader (migration, docker-inspect) still get the unsupported warning rather than silence.
  • Tests:
    • apps/api/test/lib/compose-parser.test.ts — 10 cases: merge order and environment: precedence, composeDirectory resolution, later-file override, required: false opt-out, unreadable-file warning (non-blocking), no-reader warning, out-of-repo paths, path interpolation, dotenv-vs-raw format, and literal-value handling.
    • apps/api/test/modules/deployments/prepare.service.test.ts — end-to-end through resolveProjectInfo on a real temp tree: deploy/api.env is read relative to deploy/docker-compose.yaml, environment: still wins, and the missing ./missing.env is reported.

Verification

$ cd apps/api && bunx vitest run test/lib/compose-parser.test.ts test/modules/deployments/prepare.service.test.ts
      Test Files  2 passed (2)
      Tests  236 passed (236)

$ cd packages/platform && bunx tsc --noEmit   # clean
$ cd apps/api && bunx tsc --noEmit            # clean (lint script)

$ cd packages/platform && bunx vitest run src/engine/modules/deployments/compose-review.test.ts src/engine/modules/deployments/compose/build-service-dns.test.ts
      Tests  22 passed (22)

Sabotage check (RED): with compose-parser.ts + prepare.service.ts reverted to upstream/main, all 10 new env_file parser tests fail (e.g. environment stays {}, no env_file warning); restoring the fix turns them green.

bunx prettier agrees with every line this PR adds. Several touched files already fail prettier --check on upstream main (pre-existing drift), so bun format was not run over them — the diff is kept byte-scoped with no unrelated reformatting.

Screenshots

N/A — parser/import-path change, no UI surface.

Checklist

  • One change per PR — one bug, or one agreed feature, with nothing unrelated bundled in
  • The diff is scoped — no reformatting or lint fixes on lines I wasn't otherwise changing
  • A test fails without this change and passes with it (or I explained above why there isn't one)
  • Relevant test suites, typechecks, and changed-line formatting pass locally
  • I understand every line of this diff and can explain it in review