Skip to content

Flutter tests fail without codegen: env.dart transitively requires build_runner #5935

@beastoin

Description

@beastoin

Problem

Running flutter test in a fresh checkout fails with 12 compilation errors:

lib/env/prod_env.dart:XX: Error: Undefined name '_ProdEnv'.
lib/env/dev_env.dart:XX: Error: Undefined name '_DevEnv'.

The envied-generated .g.dart files are gitignored (correctly — they contain obfuscated secrets). But env.dart imports dev_env.dart on line 1 to provide a default DevEnv() fallback in Env.init(). This creates a transitive dependency: any code that imports env.dart → needs dev_env.dart → needs dev_env.g.dart → needs build_runner.

Since most of the app imports env.dart, 12 of 18 test files fail to compile.

Impact

  • Agent-friendliness: Any AI agent running flutter test on a fresh checkout/worktree gets 12 false failures
  • CI gap: No GitHub Actions workflow runs Flutter tests, so this has gone unnoticed
  • test.sh works around it by detecting missing files and running build_runner, but bare flutter test should also work

Root Cause

lib/env/env.dart line 1:

import 'package:omi/env/dev_env.dart';

Line 10:

_instance = instance ?? DevEnv() as EnvFields;

The DevEnv() default is never used — main.dart always calls Env.init(DevEnv()) or Env.init(ProdEnv()) explicitly.

Fix

Remove the dev_env.dart import from env.dart and make Env.init() require an argument (no default fallback). This breaks the transitive codegen dependency. Tests can use Env.init(TestEnvFields()) without needing build_runner.

Also update test.sh to run all 18 test files instead of only the 9 currently listed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingp3Priority: Backlog (score <14)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions