Skip to content

bug: report the selected environment consistently in ConfigSnapshot #408

Description

@codeforester

Goal

report the selected environment consistently in ConfigSnapshot.

Background and evidence

Release-preparation review of 7d8e7d7e902ace88495c5e0ff3b9db4f4a7bf5d2 on macOS arm64. Python 3.13.15, Click 8.5.0, Typer 0.27.2.

BatteriesIncludedConfigLoader.load(..., environment="prod") loads environments/prod.yaml but returns snapshot.framework.environment == "dev" and provenance from the default/user environment. The public loader therefore exposes a contradictory snapshot. The App wrapper separately overrides ctx.environment, which hides this bug from the existing App-based environment test.

from pathlib import Path
from tempfile import TemporaryDirectory
from base_cli.config import BatteriesIncludedConfigLoader
with TemporaryDirectory() as d:
    user = Path(d)
    (user / "environments").mkdir()
    (user / "config.yaml").write_text("environment: dev\n")
    (user / "environments" / "prod.yaml").write_text("endpoint: production\n")
    s = BatteriesIncludedConfigLoader(user_config_dir=user).load(None, None, environment="prod")
    print(s.framework.environment, s.config, dict(s.provenance))

Actual: dev, {'endpoint': 'production'}, with environment provenance user. Expected: environment identity and provenance describe the explicit prod selection. The selector is validated and used for paths but never committed into merged before FrameworkConfig is constructed.

Scope and acceptance criteria

  • Make an explicit environment selection authoritative in the returned framework snapshot and its provenance.
  • Define and test whether environment files may change the selected environment; prevent a snapshot from claiming a different environment than the layer selected.
  • Add direct public loader tests, including no base config, a conflicting user/project environment, and App parity.

Validation

Run tests/test_batteries_included_config.py, relevant lifecycle tests, and the full gate.

Source references:

Non-goals

No release publication or unrelated API redesign. Preserve documented compatibility except for the defective behavior identified above.

Project fields

  • Project: base-cli
  • Status: Ready
  • Priority: P2
  • Area: Runtime
  • Initiative: v1.0 Readiness
  • Size: S
  • Milestone: v1.0.0

Agent assignment

Assignee: @codeforester. Implementation may be handled through the normal issue-backed worktree and reviewed PR workflow.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething is not working

Type

No type

Projects

  • Status
    Ready

Relationships

None yet

Development

No branches or pull requests

Issue actions