Skip to content

fix(project): resolve -e/--env for all Admin-API commands#1257

Draft
Lena (moshimorschi) wants to merge 1 commit into
mainfrom
fix/project-env-flag-admin-api
Draft

fix(project): resolve -e/--env for all Admin-API commands#1257
Lena (moshimorschi) wants to merge 1 commit into
mainfrom
fix/project-env-flag-admin-api

Conversation

@moshimorschi

Copy link
Copy Markdown
Contributor

What changed?

All project commands that talk to a shop now resolve the target environment from -e/--env, matching the executor-based commands. Previously only executor commands (admin-build, ci, dev, ...) honored the flag; the Admin-API commands built their client from the base config and ignored it.

Behavior with the issue's config (base URL port 9, environments.staging port 29):

Command Before After
extension list -e staging contacts base (port 9) contacts staging (port 29)
extension uninstall -e staging Foo contacts base (port 9) contacts staging (port 29)
extension list -e nonexistent silently contacts base fails: environment "nonexistent" not found in config
extension list (no -e) contacts base contacts base (unchanged)

Why?

-e staging silently targeting the default environment means a mutating command such as extension uninstall -e staging MyPlugin could act on the wrong, possibly production, shop, and environment-name typos passed silently. See #1226 for the full analysis.

How was this tested?

  • New Config.WithEnvironment unit tests (override, base fallback, unknown-name error, no-op when no environments, no mutation of the original config).
  • list end-to-end tests asserting -e staging contacts the staging URL and -e nonexistent is rejected.
  • A table-driven test running all 12 Admin-API commands, each asserting it rejects an unknown environment and contacts the selected environment's URL. Verified failing against the pre-fix code and passing with the fix.
  • Full go test ./... passes; gofmt and go vet clean.

Related issue or discussion

Fixes #1226

@codecov-commenter

Codecov Comments Bot (codecov-commenter) commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.22%. Comparing base (3eaa8af) to head (0c89454).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1257      +/-   ##
==========================================
+ Coverage   53.46%   54.22%   +0.75%     
==========================================
  Files         303      303              
  Lines       23322    23342      +20     
==========================================
+ Hits        12470    12657     +187     
+ Misses      10848    10644     -204     
- Partials        4       41      +37     
Flag Coverage Δ
go-test 54.22% <100.00%> (+0.75%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Only the executor-based commands resolved the -e/--env flag. Every
Admin-API command (extension list/install/uninstall/activate/
deactivate/update/delete/outdated/upload, admin-api, clear-cache,
upgrade-check) built its client straight from the base config, so
-e staging silently targeted the default shop and an unknown
environment name was not rejected. A mutating command could act on
the wrong (possibly production) shop.

Add Config.WithEnvironment, which applies the selected environment's
URL and admin_api over the base config, and a readConfigWithEnvironment
helper that every Admin-API command now uses. Unknown environment
names fail with the same error the executor path already returns.
@moshimorschi
Lena (moshimorschi) force-pushed the fix/project-env-flag-admin-api branch from b992325 to 0c89454 Compare July 24, 2026 13:35
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.

-e/--env is silently ignored by all Admin-API project commands (wrong shop can be targeted)

3 participants