Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/commands/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,33 @@ describe('runCreate', () => {
).rejects.toMatchObject({ exitCode: 5, code: 'VALIDATION_ERROR' });
expect(fetchImpl).not.toHaveBeenCalled();
});

it('rejects a whitespace-only --name with VALIDATION_ERROR (exit 5), no network', async () => {
const { credentialsPath } = makeCreds();
const fetchImpl = vi.fn(async () => {
throw new Error('should not hit network — validation must fire client-side');
});

await expect(
runCreate(
{
profile: 'default',
output: 'json',
debug: false,
type: 'frontend',
name: ' ',
targetUrl: 'https://example.com',
},
{
credentialsPath,
fetchImpl: fetchImpl as unknown as typeof fetch,
stdout: () => {},
stderr: () => {},
},
),
).rejects.toMatchObject({ exitCode: 5, code: 'VALIDATION_ERROR' });
expect(fetchImpl).not.toHaveBeenCalled();
});
});

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -641,6 +668,31 @@ describe('runUpdate', () => {
expect(fetchImpl).not.toHaveBeenCalled();
});

it('rejects a whitespace-only --name with VALIDATION_ERROR (exit 5), no network', async () => {
const { credentialsPath } = makeCreds();
const fetchImpl = vi.fn(async () => {
throw new Error('should not be called');
});
await expect(
runUpdate(
{
profile: 'default',
output: 'json',
debug: false,
projectId: 'proj_abc',
name: ' ',
},
{
credentialsPath,
fetchImpl: fetchImpl as unknown as typeof fetch,
stdout: () => {},
stderr: () => {},
},
),
).rejects.toMatchObject({ code: 'VALIDATION_ERROR', exitCode: 5 });
expect(fetchImpl).not.toHaveBeenCalled();
});

it('P7 — dry-run returns canned shape without network call', async () => {
const { credentialsPath } = makeCreds();
const fetchImpl = vi.fn(async () => {
Expand Down
12 changes: 12 additions & 0 deletions src/commands/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ export async function runCreate(
// (exit 10 UNAVAILABLE) — fail fast with a clear exit 5 instead.
assertIdempotencyKey(opts.idempotencyKey);

// Reject empty / whitespace-only names so a junk record never reaches the
// backend — matches the `requireString` whitespace guard `test create` uses
// (dogfood P1 fix #1). Without this, `--name " "` passes the action
// handler's `if (!name)` check (a non-empty string is truthy) and is sent
// verbatim, creating a blank-named project.
if (opts.name !== undefined && opts.name.trim().length === 0) {
throw localValidationError('--name must not be empty or whitespace-only');
}

// P1-3: client-side length checks matching server limits.
if (opts.name !== undefined && opts.name.length > 200) {
throw localValidationError('--name must be at most 200 characters');
Expand Down Expand Up @@ -247,6 +256,9 @@ export async function runUpdate(
assertIdempotencyKey(opts.idempotencyKey);

// P1-3: client-side length checks matching server limits.
if (opts.name !== undefined && opts.name.trim().length === 0) {
throw localValidationError('--name must not be empty or whitespace-only');
}
if (opts.name !== undefined && opts.name.length > 200) {
throw localValidationError('--name must be at most 200 characters');
}
Expand Down