-
Notifications
You must be signed in to change notification settings - Fork 231
Add app validate command
#6934
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
Merged
Merged
Add app validate command
#6934
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import {appFlags} from '../../flags.js' | ||
| import {validateApp} from '../../services/validate.js' | ||
| import AppLinkedCommand, {AppLinkedCommandOutput} from '../../utilities/app-linked-command.js' | ||
| import {linkedAppContext} from '../../services/app-context.js' | ||
| import {globalFlags} from '@shopify/cli-kit/node/cli' | ||
|
|
||
| export default class Validate extends AppLinkedCommand { | ||
| static summary = 'Validate your app configuration and extensions.' | ||
|
|
||
| static descriptionWithMarkdown = `Validates the selected app configuration file and all extension configurations against their schemas and reports any errors found.` | ||
|
|
||
| static description = this.descriptionWithoutMarkdown() | ||
|
|
||
| static flags = { | ||
| ...globalFlags, | ||
| ...appFlags, | ||
| } | ||
|
|
||
| public async run(): Promise<AppLinkedCommandOutput> { | ||
| const {flags} = await this.parse(Validate) | ||
|
|
||
| const {app} = await linkedAppContext({ | ||
dmerand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| directory: flags.path, | ||
| clientId: flags['client-id'], | ||
| forceRelink: flags.reset, | ||
| userProvidedConfigName: flags.config, | ||
| unsafeReportMode: true, | ||
| }) | ||
|
|
||
| await validateApp(app) | ||
|
|
||
| return {app} | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import {validateApp} from './validate.js' | ||
| import {testAppLinked} from '../models/app/app.test-data.js' | ||
| import {AppErrors} from '../models/app/loader.js' | ||
| import {describe, expect, test, vi} from 'vitest' | ||
| import {renderError, renderSuccess} from '@shopify/cli-kit/node/ui' | ||
| import {AbortSilentError} from '@shopify/cli-kit/node/error' | ||
|
|
||
| vi.mock('@shopify/cli-kit/node/ui') | ||
|
|
||
| describe('validateApp', () => { | ||
| test('renders success when there are no errors', async () => { | ||
| // Given | ||
| const app = testAppLinked() | ||
|
|
||
| // When | ||
| await validateApp(app) | ||
|
|
||
| // Then | ||
| expect(renderSuccess).toHaveBeenCalledWith({headline: 'App configuration is valid.'}) | ||
| expect(renderError).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| test('renders errors and throws when there are validation errors', async () => { | ||
| // Given | ||
| const errors = new AppErrors() | ||
| errors.addError('/path/to/shopify.app.toml', 'client_id is required') | ||
| errors.addError('/path/to/extensions/my-ext/shopify.extension.toml', 'invalid type "unknown"') | ||
| const app = testAppLinked() | ||
| app.errors = errors | ||
|
|
||
| // When / Then | ||
| await expect(validateApp(app)).rejects.toThrow(AbortSilentError) | ||
| expect(renderError).toHaveBeenCalledWith({ | ||
| headline: 'Validation errors found.', | ||
| body: expect.stringContaining('client_id is required'), | ||
| }) | ||
| expect(renderSuccess).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| test('renders success when errors object exists but is empty', async () => { | ||
| // Given | ||
| const errors = new AppErrors() | ||
| const app = testAppLinked() | ||
| app.errors = errors | ||
|
|
||
| // When | ||
| await validateApp(app) | ||
|
|
||
| // Then | ||
| expect(renderSuccess).toHaveBeenCalledWith({headline: 'App configuration is valid.'}) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import {AppLinkedInterface} from '../models/app/app.js' | ||
| import {stringifyMessage} from '@shopify/cli-kit/node/output' | ||
| import {renderError, renderSuccess} from '@shopify/cli-kit/node/ui' | ||
| import {AbortSilentError} from '@shopify/cli-kit/node/error' | ||
|
|
||
| export async function validateApp(app: AppLinkedInterface): Promise<void> { | ||
| const errors = app.errors | ||
|
|
||
| if (!errors || errors.isEmpty()) { | ||
| renderSuccess({headline: 'App configuration is valid.'}) | ||
| return | ||
| } | ||
|
|
||
| const errorMessages = errors.toJSON().map((error) => stringifyMessage(error).trim()) | ||
|
|
||
| renderError({ | ||
| headline: 'Validation errors found.', | ||
| body: errorMessages.join('\n\n'), | ||
| }) | ||
|
|
||
| throw new AbortSilentError() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |
| │ ├─ logs | ||
| │ │ └─ sources | ||
| │ ├─ release | ||
| │ ├─ validate | ||
| │ ├─ versions | ||
| │ │ └─ list | ||
| │ └─ webhook | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.