fix(org-import): aggregate defaults.RequiredEnv into preflight check (issue #232) #249

Closed
claude-ceo-assistant wants to merge 1 commits from fix/issue232-org-import-required-env-aggregation into main
Owner

Summary

Fixes issue #232: Org import must aggregate per-workspace + per-runtime RequiredEnv into a single pre-flight credential gather.

Root cause

POST /org/import via the dir path loads org.yaml from disk and calls collectOrgEnv to build the preflight key list. However, Defaults.RequiredEnv (carrying the runtime's own requirements, e.g. ANTHROPIC_API_KEY for claude-code) was not present in tmpl.RequiredEnv -- it lives in the Defaults struct. The canvas preflight modal passes a fully-populated tmpl via the template body field, so the bug only manifested in the dir (template-on-disk) import path.

Result: importing molecule-dev (38 workspaces, runtime=claude-code, no explicit org-level RequiredEnv) silently passed the preflight, then shipped 38 workspaces each NOT CONFIGURED because the container needed ANTHROPIC_API_KEY and nobody was prompted to provide it.

Fix

  1. Add RequiredEnv / RecommendedEnv fields to OrgDefaults (org.go): same []EnvRequirement shape as OrgTemplate.RequiredEnv. Templates on disk declare defaults.required_env at the defaults level.

  2. Inject in Import handler (org.go, before collectOrgEnv call): append tmpl.Defaults.RequiredEnv into tmpl.RequiredEnv and tmpl.Defaults.RecommendedEnv into tmpl.RecommendedEnv.

  3. 3 regression tests prove defaults.RequiredEnv flows into the union, duplicates dedupe correctly, and any-of groups from defaults survive.

Test plan

  • TestCollectOrgEnv_DefaultsRequiredEnv -- defaults.RequiredEnv in union
  • TestCollectOrgEnv_DefaultsRequiredEnv_DedupWithExplicitOrgLevel -- dedup with explicit org-level
  • TestCollectOrgEnv_DefaultsRequiredEnv_AnyOfFromDefaults -- any-of group preserved
  • Manual: import molecule-dev via dir path, verify MissingKeysModal appears with ANTHROPIC_API_KEY

Labels: tier:medium
Closes #232

[core-qa-agent]

## Summary Fixes **issue #232**: Org import must aggregate per-workspace + per-runtime RequiredEnv into a single pre-flight credential gather. ### Root cause `POST /org/import` via the `dir` path loads `org.yaml` from disk and calls `collectOrgEnv` to build the preflight key list. However, `Defaults.RequiredEnv` (carrying the runtime's own requirements, e.g. `ANTHROPIC_API_KEY` for `claude-code`) was not present in `tmpl.RequiredEnv` -- it lives in the `Defaults` struct. The canvas preflight modal passes a fully-populated `tmpl` via the `template` body field, so the bug only manifested in the `dir` (template-on-disk) import path. Result: importing molecule-dev (38 workspaces, runtime=claude-code, no explicit org-level RequiredEnv) silently passed the preflight, then shipped 38 workspaces each `NOT CONFIGURED` because the container needed ANTHROPIC_API_KEY and nobody was prompted to provide it. ### Fix 1. **Add `RequiredEnv` / `RecommendedEnv` fields to `OrgDefaults`** (`org.go`): same `[]EnvRequirement` shape as `OrgTemplate.RequiredEnv`. Templates on disk declare `defaults.required_env` at the defaults level. 2. **Inject in `Import` handler** (`org.go`, before `collectOrgEnv` call): append `tmpl.Defaults.RequiredEnv` into `tmpl.RequiredEnv` and `tmpl.Defaults.RecommendedEnv` into `tmpl.RecommendedEnv`. 3. **3 regression tests** prove defaults.RequiredEnv flows into the union, duplicates dedupe correctly, and any-of groups from defaults survive. ### Test plan - [x] `TestCollectOrgEnv_DefaultsRequiredEnv` -- defaults.RequiredEnv in union - [x] `TestCollectOrgEnv_DefaultsRequiredEnv_DedupWithExplicitOrgLevel` -- dedup with explicit org-level - [x] `TestCollectOrgEnv_DefaultsRequiredEnv_AnyOfFromDefaults` -- any-of group preserved - [ ] Manual: import molecule-dev via `dir` path, verify MissingKeysModal appears with ANTHROPIC_API_KEY **Labels:** tier:medium **Closes** #232 [core-qa-agent]
claude-ceo-assistant added 1 commit 2026-05-10 07:04:58 +00:00
fix(org-import): aggregate defaults.RequiredEnv into preflight check (issue #232)
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 14s
sop-tier-check / tier-check (pull_request) Failing after 10s
audit-force-merge / audit (pull_request) Has been skipped
e0178b04c6
When importing an org template via `dir` path, the Import handler read the
YAML and called collectOrgEnv — but Defaults.RequiredEnv (carrying the
runtime's own env requirements, e.g. ANTHROPIC_API_KEY for claude-code)
was not in tmpl.RequiredEnv, so collectOrgEnv silently skipped it.
The canvas preflight modal bypasses this by passing a fully-populated
tmpl via the `template` body field, so the bug only manifests in the
`dir` (template-on-disk) import path.

Fix:
- Add RequiredEnv / RecommendedEnv fields to OrgDefaults struct (same
  shape as OrgTemplate.RequiredEnv). Templates on disk declare
  defaults.required_env at the defaults level; the import handler now
  injects these into tmpl.RequiredEnv / tmpl.RecommendedEnv before
  calling collectOrgEnv, so the preflight sees the runtime's requirements.
- collectOrgEnv is unchanged — it already walks the tree correctly. The
  injection point is in Import, not collectOrgEnv, so the existing test
  coverage is preserved.
- 3 new regression tests prove: (1) defaults.RequiredEnv flows into
  the union, (2) duplicate key with explicit org-level RequiredEnv
  deduplicates correctly, (3) any-of groups from defaults survive.

Repro scenario fixed: importing molecule-dev (38 workspaces, runtime=claude-
code, no explicit org-level RequiredEnv) now correctly blocks on
ANTHROPIC_API_KEY and shows the MissingKeysModal instead of silently
creating 38 NOT CONFIGURED workspaces.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Some checks are pending
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 14s
sop-tier-check / tier-check (pull_request) Failing after 10s
audit-force-merge / audit (pull_request) Has been skipped
CI / all-required (pull_request)
Required

Pull request closed

Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: molecule-ai/molecule-core#249