diff --git a/src/profileCommands.service.ts b/src/profileCommands.service.ts index 5bdd45e..c16804e 100644 --- a/src/profileCommands.service.ts +++ b/src/profileCommands.service.ts @@ -110,7 +110,10 @@ const assertKeys = (input: JsonObject, allowed: readonly string[], label: string const text = (input: JsonObject, key: string, max: number, requiredField: boolean): void => { const value = input[key] - if (value === undefined && !requiredField) return + if (value === undefined) { + if (requiredField) throw new Error(`${key} is required`) + return + } if (typeof value !== 'string' || value.length > max) throw new Error(`${key} must be text of at most ${max} characters`) } diff --git a/test/profileCommands.service.test.ts b/test/profileCommands.service.test.ts index a05c2a0..8bff418 100644 --- a/test/profileCommands.service.test.ts +++ b/test/profileCommands.service.test.ts @@ -93,6 +93,15 @@ describe('profile commands', () => { expect(test.errors[1]).toContain('supported profile icon') }) + it('reports a missing required text field as required, not as too long', async () => { + const json: JsonMock = vi.fn(async () => ({ revision: 9 })) + const test = harness(json) + await expect(runCli(['profiles', 'actions', 'create', 'custom', 'profile1', '--name', 'n'], test.dependencies)).resolves.toBe(CliExitCode.USAGE) + await expect(runCli(['profiles', 'create', '--name', 'n', '--description', 'd'], test.dependencies)).resolves.toBe(CliExitCode.USAGE) + expect(test.errors).toEqual([expect.stringContaining('prompt is required'), expect.stringContaining('prompt is required')]) + expect(json).not.toHaveBeenCalled() + }) + it('rejects unknown, inapplicable, impossible, and trailing input before opening a profile request', async () => { const json: JsonMock = vi.fn(async () => ({ revision: 9 })) const test = harness(json)