-
Notifications
You must be signed in to change notification settings - Fork 16
feat(models): add generic artifact generation to enable caching #1023
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
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
abafe01
feat(nx-plugin): add generic configuration for plugins
5bfd3f5
feat(nx-plugin): add generic type for plugins options
7641e57
feat(nx-plugin): revert changes for coverage schema
3101c6e
feat(nx-plugin): fix tests and mr comments
e894482
feat(nx-plugin): fix naming
0511698
feat(nx-plugin): fix units, update model
338e88a
feat(nx-plugin): fix linter
591bf37
feat(nx-plugin): rename artefact to artifacts
e0a7f17
feat(models): extend artifcationGenerationCommand schema with single …
51d78ea
feat(models): fix mr comments and duplications, fix test
AndriiSiuta 3275edd
feat(models): update index and docs
AndriiSiuta 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,24 @@ | ||
import { z } from 'zod'; | ||
|
||
/** | ||
* Generic schema for a tool command configuration, reusable across plugins. | ||
*/ | ||
export const artifactGenerationCommand = z.object({ | ||
AndriiSiuta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
command: z.string({ description: 'Command to run the tool.' }).min(1), | ||
AndriiSiuta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
args: z | ||
.array(z.string(), { | ||
description: 'Arguments to be passed to the tool.', | ||
AndriiSiuta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
.optional(), | ||
}); | ||
|
||
export type ArtefactGenerationCommand = z.infer< | ||
typeof artifactGenerationCommand | ||
>; | ||
|
||
export const pluginArtefactOptionsSchema = z.object({ | ||
generateArtefacts: artifactGenerationCommand.optional(), | ||
artefactsPaths: z.union([z.string(), z.array(z.string())]), | ||
}); | ||
|
||
export type PluginArtefactOptions = z.infer<typeof pluginArtefactOptionsSchema>; |
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,95 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { | ||
artifactGenerationCommand, | ||
pluginArtefactOptionsSchema, | ||
} from './configuration.js'; | ||
|
||
describe('artifactGenerationCommand', () => { | ||
it('should validate a command with required fields', () => { | ||
const data = { command: 'npx' }; | ||
const result = artifactGenerationCommand.safeParse(data); | ||
expect(result.success).toBe(true); | ||
if (result.success) { | ||
expect(result.data.command).toBe('npx'); | ||
expect(result.data.args).toBeUndefined(); | ||
} | ||
AndriiSiuta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
it('should validate a command with args', () => { | ||
const data = { command: 'npx', args: ['eslint', 'src/'] }; | ||
const result = artifactGenerationCommand.safeParse(data); | ||
expect(result.success).toBe(true); | ||
if (result.success) { | ||
expect(result.data.command).toBe('npx'); | ||
expect(result.data.args).toEqual(['eslint', 'src/']); | ||
} | ||
}); | ||
|
||
it('should fail if command is missing', () => { | ||
const data = { args: ['eslint', 'src/'] }; | ||
const result = artifactGenerationCommand.safeParse(data); | ||
expect(result.success).toBe(false); | ||
}); | ||
|
||
it('should fail if command is empty', () => { | ||
const data = { command: '' }; | ||
const result = artifactGenerationCommand.safeParse(data); | ||
expect(result.success).toBe(false); | ||
}); | ||
|
||
it('should fail if args is not an array of strings', () => { | ||
const data = { command: 'npx', args: [123, true] }; | ||
const result = artifactGenerationCommand.safeParse(data); | ||
expect(result.success).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('pluginArtefactOptionsSchema', () => { | ||
it('should validate with only artefactsPaths as string', () => { | ||
const data = { artefactsPaths: 'dist/report.json' }; | ||
const { success } = pluginArtefactOptionsSchema.safeParse(data); | ||
expect(success).toBe(true); | ||
}); | ||
|
||
it('should validate with artefactsPaths as array of strings', () => { | ||
const data = { artefactsPaths: ['dist/report.json', 'dist/summary.json'] }; | ||
const { success } = pluginArtefactOptionsSchema.safeParse(data); | ||
expect(success).toBe(true); | ||
}); | ||
|
||
it('should fail if artefactsPaths is an empty array', () => { | ||
const data = { artefactsPaths: [] }; | ||
const { success } = pluginArtefactOptionsSchema.safeParse(data); | ||
expect(success).toBe(false); | ||
}); | ||
|
||
it('should validate with generateArtefacts and artefactsPaths', () => { | ||
const data = { | ||
generateArtefacts: { command: 'npm', args: ['run', 'build'] }, | ||
artefactsPaths: ['dist/report.json'], | ||
}; | ||
const { success } = pluginArtefactOptionsSchema.safeParse(data); | ||
expect(success).toBe(true); | ||
}); | ||
|
||
it('should fail if artefactsPaths is missing', () => { | ||
const data = { generateArtefacts: { command: 'npm' } }; | ||
const { success } = pluginArtefactOptionsSchema.safeParse(data); | ||
expect(success).toBe(false); | ||
}); | ||
|
||
it('should fail if artefactsPaths is not string or array of strings', () => { | ||
const data = { artefactsPaths: 123 }; | ||
const { success } = pluginArtefactOptionsSchema.safeParse(data); | ||
expect(success).toBe(false); | ||
}); | ||
|
||
it('should fail if generateArtefacts is invalid', () => { | ||
const data = { | ||
generateArtefacts: { command: '' }, | ||
artefactsPaths: 'dist/report.json', | ||
}; | ||
const { success } = pluginArtefactOptionsSchema.safeParse(data); | ||
expect(success).toBe(false); | ||
}); | ||
}); |
AndriiSiuta marked this conversation as resolved.
Show resolved
Hide resolved
|
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
Oops, something went wrong.
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.