Skip to content
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

#8067: fix unresolved schemas in integration configuration validation #8212

Merged
merged 7 commits into from
Apr 10, 2024

Conversation

grahamlangford
Copy link
Collaborator

What does this PR do?

Reviewer Tips

  • Schema was not being resolved correctly
  • Reused/renamed validateBrickInputOutput
    • See IntegrationConfigEditorModal

Checklist

  • Add jest or playwright tests and/or storybook stories
  • Designate a primary reviewer @BLoe

@@ -67,4 +69,35 @@ describe("IntegrationConfigEditorModal", () => {
).toBeVisible();
}
});

test("displays user-friendly pattern validation message", async () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored this test because now we're resolving the schema correctly. This should've been a sign to me that something was wrong, but I didn't know how to replicate the problem in the UI.

);

const { errors } = validator.validate(values);
const { errors } = await resolveSchemaAndValidate(schema, values);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual fix

@@ -249,7 +249,7 @@ export async function dereference(
*
* To avoid secret leakage, does not validate the secret `$ref`s of properties accepting an integration configuration.
*/
export async function validateBrickInputOutput(
export async function resolveSchemaAndValidate(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open to other names, but this function can resolve and schema and validate the values passed in, not just bricks

Copy link
Contributor

@twschiller twschiller Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grahamlangford I don't think this is the correct method to use for validating configuration?

This method has very particular behavior around how integrations are resolved: https://github.com/pixiebrix/pixiebrix-extension/pull/8212/files#diff-59aee84744090336263733bc3d1d8f1da1945e4e3728dcf9052ae3e093112890R276

I would recommend we make a "validateIntegrationConfiguration" method that correctly passes passes sanitize: false. (We'll also want to use this method in the Admin Console for validation)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second look, I think you're right. I need to dig deeper into how the $RefParser works.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BLoe and I both have context on this -- I'd recommend pairing with one of us vs. starting the investigation from scratch

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@twschiller those failures were actually due to a change I made in the previous PR. Agree on wanting to be able to set sanitize: false. I would appreciate a quick sync later though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@grahamlangford grahamlangford marked this pull request as ready for review April 10, 2024 18:50
@@ -204,7 +204,7 @@ const builtInSchemaResolver: ResolverOptions = {
* Should generally be set to true when using for runtime validation, but false when using for UI entry validation.
* @see $RefParser.dereference
*/
export async function dereference(
export async function dereferenceForYup(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Comment on lines -169 to -174
const dereferenced = await dereference(
integrationWithOptionalField as Schema,
{
sanitizeIntegrationDefinitions: false,
},
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to actually dereference and ref resolution is now handled in the modal

Copy link

No loom links were found in the first post. Please add one there if you'd like to it to appear on Slack.

Do not edit this comment manually.

@@ -52,7 +52,7 @@ export class LocalIntegrationsPage {
.getByPlaceholder("Start typing to find results")
.fill(integrationName);

await this.page.getByText(integrationName).hover();
await this.page.getByText(integrationName).first().hover();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: why is first necessary? Seems like it appears 2x on the page?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on which integration, the text can appear several times. Ran into an issue with the Open AI test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarifying which screen affordance is being hovered in that case would be beneficial

@twschiller twschiller changed the title #8067: fix unresolved schemas #8067: fix unresolved schemas in integration configuration validation Apr 10, 2024
@grahamlangford grahamlangford enabled auto-merge (squash) April 10, 2024 18:54
Copy link

codecov bot commented Apr 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.42%. Comparing base (5a4565c) to head (e601767).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8212      +/-   ##
==========================================
- Coverage   73.42%   73.42%   -0.01%     
==========================================
  Files        1319     1319              
  Lines       40825    40832       +7     
  Branches     7578     7578              
==========================================
+ Hits        29976    29980       +4     
- Misses      10849    10852       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@grahamlangford grahamlangford merged commit 3ff63c5 into main Apr 10, 2024
43 checks passed
@grahamlangford grahamlangford deleted the 8067-fix-unresolved-schemas branch April 10, 2024 19:00
@twschiller twschiller added this to the 1.8.13 milestone Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regression
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blank numeric text integration configuration field not validated on save
2 participants