Skip to content

Commit 6e7f2b3

Browse files
authored
fix(test): reject whitespace-only --name in test update (parity with test create) (#39)
* fix(test): reject whitespace-only --name in test update (parity with test create) * style: run prettier on src/commands/test.ts
1 parent e53257d commit 6e7f2b3

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/commands/test.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5777,6 +5777,31 @@ describe('runUpdate', () => {
57775777
expect(called).toBe(0);
57785778
});
57795779

5780+
it('rejects a whitespace-only --name before sending (parity with test create)', async () => {
5781+
const { credentialsPath } = makeCreds();
5782+
let called = 0;
5783+
const fetchImpl = makeFetch(() => {
5784+
called += 1;
5785+
return { body: SAMPLE_RESPONSE };
5786+
});
5787+
await expect(
5788+
runUpdate(
5789+
{
5790+
profile: 'default',
5791+
output: 'json',
5792+
debug: false,
5793+
testId: 'test_alpha',
5794+
name: ' ',
5795+
},
5796+
{ credentialsPath, fetchImpl, stdout: () => undefined },
5797+
),
5798+
).rejects.toMatchObject({
5799+
code: 'VALIDATION_ERROR',
5800+
details: expect.objectContaining({ field: 'name' }),
5801+
});
5802+
expect(called).toBe(0);
5803+
});
5804+
57805805
it('renders text mode with one line per updated field', async () => {
57815806
const { credentialsPath } = makeCreds();
57825807
const fetchImpl = makeFetch(() => ({ body: SAMPLE_RESPONSE }));

src/commands/test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,12 @@ export async function runUpdate(
12431243
assertIdempotencyKey(opts.idempotencyKey);
12441244
requireNonEmpty('test-id', opts.testId);
12451245
// P1-3: client-side length checks matching server limits.
1246+
if (opts.name !== undefined && opts.name.trim().length === 0) {
1247+
throw localValidationError(
1248+
'name',
1249+
'must be a non-empty string (whitespace-only is not allowed)',
1250+
);
1251+
}
12461252
if (opts.name !== undefined && opts.name.length > 200) {
12471253
throw localValidationError('name', 'must be at most 200 characters');
12481254
}

0 commit comments

Comments
 (0)