Skip to content

Commit f953281

Browse files
committed
fix(toolsets): reject an empty accountId instead of widening to every account
1 parent 64b3fe8 commit f953281

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎src/toolsets.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ describe('configuration', () => {
102102
await expect(async () => act()).rejects.toThrow(/must not contain an empty account id/);
103103
});
104104

105+
it('refuses an empty accountId rather than widening to every account', () => {
106+
expect(() => newToolSet({ accountId: '' })).toThrow(
107+
new ToolSetConfigError('accountId must not be an empty string'),
108+
);
109+
});
110+
105111
it('returns itself from setAccounts for chaining', () => {
106112
const toolset = newToolSet();
107113
expect(toolset.setAccounts(['acc1'])).toBe(toolset);

‎src/toolsets.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,19 @@ export class StackOneToolSet {
325325

326326
/**
327327
* @throws ToolSetConfigError If no API key is given or found in `STACKONE_API_KEY`, or both
328-
* `accountId` and `accountIds` are given.
328+
* `accountId` and `accountIds` are given, or `accountId` is an empty string.
329329
*/
330330
constructor(config: StackOneToolSetConfig = {}) {
331331
if (config.accountId != null && config.accountIds != null) {
332332
throw new ToolSetConfigError(
333333
'Cannot provide both accountId and accountIds. Use accountId for a single account or accountIds for multiple accounts.',
334334
);
335335
}
336+
// An empty accountId is usually an unset variable, and treating it as unset would silently
337+
// widen every call to all active accounts.
338+
if (config.accountId === '') {
339+
throw new ToolSetConfigError('accountId must not be an empty string');
340+
}
336341
assertAccountIdList(config.accountIds, 'accountIds');
337342
assertAccountIdList(config.execute?.accountIds, 'execute.accountIds');
338343

0 commit comments

Comments
 (0)