Skip to content

fix(api): error when --app is used outside a project - #845

Open
mwbrooks wants to merge 2 commits into
mainfrom
mwbrooks-api-app-requires-project
Open

mwbrooks wants to merge 2 commits into
mainfrom
mwbrooks-api-app-requires-project

Conversation

@mwbrooks

Copy link
Copy Markdown
Member

Changelog

slack api --app now errors when it's run outside a project, instead of ignoring the flag and sending the request with another token or none.

Summary

This pull request makes slack api --app <app> fail with a clear error for developers who run it outside a Slack project. Before, the flag was silently ignored, so the CLI used SLACK_BOT_TOKEN or SLACK_USER_TOKEN if set, or sent the request with no token and printed not_authed with exit code 0.

  • The error is invalid_slack_project_directory, with a suggestion to run the command in a project or pass --token.
  • The "Token resolution" help text now says --app requires a project.

Testing

  • Outside a project, run SLACK_BOT_TOKEN=xoxb-fake slack api auth.test --app A123 and confirm the invalid_slack_project_directory error and exit code 1.
  • In a project, run slack api auth.test --app <app-id> and confirm it still returns the bot's identity.
  • The new Test_resolveToken_AppFlag_NoProject fails on main and passes on this branch.

Notes

Requirements

Outside a project the --app flag was ignored and the request fell
through to SLACK_BOT_TOKEN, SLACK_USER_TOKEN, or no token at all.
@mwbrooks mwbrooks added this to the Next Release milestone Nov 24, 2026
@mwbrooks mwbrooks added bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented changelog Use on updates to be included in the release notes semver:patch Use on pull requests to describe the release version increment labels Nov 24, 2026
@mwbrooks mwbrooks self-assigned this Nov 24, 2026
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.67%. Comparing base (2f4c63c) to head (15079ca).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #845      +/-   ##
==========================================
+ Coverage   80.64%   80.67%   +0.02%     
==========================================
  Files         246      246              
  Lines       18837    18840       +3     
==========================================
+ Hits        15192    15200       +8     
+ Misses       3645     3640       -5     

☔ 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.

@mwbrooks
mwbrooks marked this pull request as ready for review November 24, 2026 17:16
@mwbrooks
mwbrooks requested review from a team as code owners November 24, 2026 17:16

@WilliamBergamin WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 Thanks @mwbrooks, failing loudly here beats quietly sending the request as a different identity, and --token still wins outside a project. Nothing from me on the code. The CircleCI build job is red on this head while make build-ci passes locally and sibling PRs build green, so it could use a re-run 🙏

Comment thread cmd/api/api_test.go
}

func Test_resolveToken_AppFlag_NoProject(t *testing.T) {
t.Setenv("SLACK_BOT_TOKEN", "xoxb-env-bot-token")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 praise: Setting SLACK_BOT_TOKEN and asserting the prompt never runs pins the exact fallback this fixes, so the test fails on main for the right reason.

@mwbrooks

Copy link
Copy Markdown
Member Author

Thanks @WilliamBergamin for the review and the CI catch! 🙇 The build failure was a proxy.golang.org network error while downloading GoReleaser modules, so it's being re-run.

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

Labels

bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented changelog Use on updates to be included in the release notes semver:patch Use on pull requests to describe the release version increment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants