-
Notifications
You must be signed in to change notification settings - Fork 230
feat(compass-collection): CLOUDP-347048 LLM Output Validation Followup - Mock Data Generator #7365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…p - Mock Data Generator
}, | ||
}; | ||
|
||
// @ts-expect-error // TODO: fix ts error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the mock data generator modal with comprehensive validation and rendering improvements for faker method arguments. The changes focus on improving argument validation, centralizing validation logic, and enabling UI display of faker arguments.
- Adds comprehensive validation for faker arguments including nested structures, type checking, and size limits
- Refactors validation logic from collection-tab.ts to a shared utility module for better maintainability
- Updates UI components to display faker arguments as read-only text inputs with proper type handling
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
collection-tab.ts | Refactors validation to use centralized utility function |
utils.ts | Introduces comprehensive faker argument and method validation utilities |
utils.spec.ts | Adds extensive unit tests for validation functions |
script-generation-utils.ts | Extends FakerArg type to support nested arrays |
mock-data-generator-modal.spec.tsx | Adds integration test for oversized argument handling |
faker-schema-editor-screen.tsx | Passes faker arguments to mapping selector |
faker-mapping-selector.tsx | Implements UI rendering for faker arguments |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
packages/compass-collection/src/components/mock-data-generator-modal/faker-mapping-selector.tsx
Outdated
Show resolved
Hide resolved
packages/compass-collection/src/components/mock-data-generator-modal/utils.ts
Outdated
Show resolved
Hide resolved
packages/compass-collection/src/components/mock-data-generator-modal/utils.ts
Outdated
Show resolved
Hide resolved
packages/compass-collection/src/components/mock-data-generator-modal/utils.ts
Outdated
Show resolved
Hide resolved
Assigned |
expect(result.fakerArgs).to.deep.equal([]); | ||
}); | ||
|
||
it('returns false for valid method with invalid arguments and fallback fails', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be invalid arguments with valid method falls back to true and strips args
? That's what's happening I think, which is why this test is failing right now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, forgot to update it.
expect(result.fakerArgs).to.deep.equal([]); | ||
}); | ||
|
||
it('returns false for method with invalid fakerArgs', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comment applies here too I believe. Both tests should expect isValid: true
and fakerArgs: []
try { | ||
if (areFakerArgsValid(args)) { | ||
callable(...args); | ||
return { isValid: true, fakerArgs: args }; | ||
} else { | ||
callable(); | ||
return { isValid: true, fakerArgs: [] }; | ||
} | ||
} catch { | ||
// Intentionally ignored: error may be due to invalid arguments, will retry without args. | ||
if (args.length > 0) { | ||
try { | ||
callable(); | ||
return { isValid: true, fakerArgs: [] }; | ||
} catch { | ||
// Intentionally ignored: method is invalid without arguments as well. | ||
return { isValid: false, fakerArgs: [] }; | ||
} | ||
} | ||
} | ||
return { isValid: false, fakerArgs: [] }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we refactored a bit for clarity:
try { | |
if (areFakerArgsValid(args)) { | |
callable(...args); | |
return { isValid: true, fakerArgs: args }; | |
} else { | |
callable(); | |
return { isValid: true, fakerArgs: [] }; | |
} | |
} catch { | |
// Intentionally ignored: error may be due to invalid arguments, will retry without args. | |
if (args.length > 0) { | |
try { | |
callable(); | |
return { isValid: true, fakerArgs: [] }; | |
} catch { | |
// Intentionally ignored: method is invalid without arguments as well. | |
return { isValid: false, fakerArgs: [] }; | |
} | |
} | |
} | |
return { isValid: false, fakerArgs: [] }; | |
// If args are present and safe, try calling with args | |
if (args.length > 0 && areFakerArgsValid(args)) { | |
try { | |
callable(...args); | |
return { isValid: true, fakerArgs: args }; | |
} catch { | |
// Call with args failed. Fall through to trying without args | |
} | |
} | |
// Try without args (either because args were invalid or args failed) | |
try { | |
callable(); | |
return { isValid: true, fakerArgs: [] }; | |
} catch { | |
// Method doesn't work even without args | |
return { isValid: false, fakerArgs: [] }; | |
} |
} else if (typeof arg === 'boolean') { | ||
// booleans are always valid, continue | ||
} else if (Array.isArray(arg)) { | ||
if (!areFakerArgsValid(arg)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we limit the depth of this to prevent potential infinite recursion? We could pass a depth param and limit to say, 3 levels
callable(); | ||
return { isValid: true, fakerArgs: [] }; | ||
} | ||
} catch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A warning when there's an exception or the args are invalid would be valuable for fine tuning the prompt
|
||
// advance to the schema editor step | ||
userEvent.click(screen.getByText('Confirm')); | ||
await waitFor(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems to be an assertion missing? I'm not connecting how "faker args that are too large" are not shown
/** | ||
* Renders read-only TextInput components for each key-value pair in a faker arguments object. | ||
*/ | ||
const getFakerArgsInputFromObject = (fakerArgsObject: Record<string, any>) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use render in name to clarify React Elements are returned, something like renderFakerArgsInput
<TextInput | ||
key={`faker-arg-${idx}`} | ||
type="text" | ||
label="Faker Arg" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
labels should be unique across the form's inputs
*/ | ||
const getFakerArgsInputFromObject = (fakerArgsObject: Record<string, any>) => { | ||
return Object.entries(fakerArgsObject).map(([key, item]: [string, any]) => { | ||
if (typeof item === 'string' || typeof item === 'boolean') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't boolean
use something like a radio option instead of arbitrary text?
The faker arg form experience itself is interesting, I wonder how well users can intuit that the args are positional. Could be a follow-up. Maybe the user can be shown an inline preview of the faker call (cc @jcobis), right now they'd need to make the connection by reading the Script output |
Yeah, good question. If we can't show a specific label for each faker argument, an inline preview of the faker call would be good UI to show. |
Description
This pull request introduces more validation and rendering improvements for handling faker method arguments in the mock data generator modal. The main changes include adding comprehensive validation logic for faker arguments and method names, updating UI components to display faker arguments, and refactoring validation logic out of the module to a shared utility.
Validation and Utility Enhancements:
areFakerArgsValid
and improvedisValidFakerMethod
utility functions inutils.ts
to thoroughly validate faker arguments (including nested and object types) and method names, enforcing limits on argument length, string size, and value types.collection-tab.ts
to use the newisValidFakerMethod
utility, ensuring faker method and argument validation is consistent and centralized. [1] [2] [3]Type and Interface Updates:
FakerArg
type to support nested arrays, enabling more flexible representation of faker arguments.UI and Rendering Improvements:
FakerMappingSelector
to renderTextInput
components for each faker argument, supporting various types (string, number, boolean, arrays, and objects) and displaying them in a read-only format. [1] [2] [3]FakerSchemaEditorContent
to pass the active faker arguments to the mapping selector for display. [1] [2]Testing:
areFakerArgsValid
andisValidFakerMethod
inutils.spec.ts
, covering edge cases such as deeply nested structures, invalid argument types, and method existence.Checklist
Motivation and Context
Open Questions
Dependents
Types of changes