Skip to content

Commit 2f59b4b

Browse files
cdervclaude
andcommitted
Fail on ambiguous account selection in non-interactive mode
Other publish providers fail when --no-prompt is set and multiple accounts exist, via the shared resolveAccount logic. Connect Cloud bypasses that shared path for environment token account resolution, so it needs its own guard: throw an error when multiple publishable accounts exist without POSIT_CONNECT_CLOUD_ACCOUNT_ID in non-interactive mode, instead of silently picking the first. Also add Test 6b to the manual testing protocol covering this case. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bea3045 commit 2f59b4b

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/publish/posit-connect-cloud/posit-connect-cloud.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,12 @@ async function publish(
370370
accountName = match.name;
371371
accountId = match.id;
372372
} else {
373+
if (publishable.length > 1 && !options.prompt) {
374+
throw new Error(
375+
"Multiple publishable accounts found. " +
376+
`Set ${kPositConnectCloudAccountIdVar} to select a specific account.`,
377+
);
378+
}
373379
accountName = publishable[0].name;
374380
accountId = publishable[0].id;
375381
if (publishable.length > 1) {

tests/docs/manual/publish-connect-cloud/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,21 @@ Remove stored accounts via `quarto publish accounts` so only env var token is us
214214
- [ ] Publish succeeds
215215
- [ ] No ghost token persisted (run `quarto publish accounts` after — should show no posit-connect-cloud accounts)
216216

217+
### 6b: Multiple Accounts Without ACCOUNT_ID (--no-prompt)
218+
219+
If the access token has access to multiple publishable accounts:
220+
221+
```bash
222+
export POSIT_CONNECT_CLOUD_ACCESS_TOKEN="<accessToken>"
223+
# Intentionally do NOT set POSIT_CONNECT_CLOUD_ACCOUNT_ID
224+
./package/dist/bin/quarto.cmd publish posit-connect-cloud tests/docs/manual/publish-connect-cloud/single-doc/document.qmd --no-prompt
225+
```
226+
227+
- [ ] Publish fails with error: "Multiple publishable accounts found. Set POSIT_CONNECT_CLOUD_ACCOUNT_ID to select a specific account."
228+
- [ ] No content published
229+
230+
This matches other providers' behavior: ambiguous account selection fails in non-interactive mode.
231+
217232
**Cleanup:**
218233

219234
```bash
@@ -340,6 +355,7 @@ Access tokens expire after some time. To test proactive refresh:
340355
| 4 | Update existing content | | |
341356
| 5 | Account management | | |
342357
| 6 | CI/CD mode | | |
358+
| 6b | Multiple accounts without ACCOUNT_ID | | |
343359
| 7 | Provider selection | | |
344360
| 8 | posit-cloud deprecation | | |
345361
| 9a | Invalid token error | | |

0 commit comments

Comments
 (0)