Skip to content

Commit 51d78ea

Browse files
committed
feat(models): fix mr comments and duplications, fix test
1 parent e0a7f17 commit 51d78ea

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed

packages/models/src/lib/configuration.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,16 @@ import { z } from 'zod';
33
/**
44
* Generic schema for a tool command configuration, reusable across plugins.
55
*/
6-
export const artifactGenerationCommand = z.object({
7-
command: z.string({ description: 'Generate artifact files' }).min(1),
8-
args: z
9-
.array(z.string(), {
10-
description: 'Arguments to be passed to the artifact generation command.',
11-
})
12-
.optional(),
13-
});
14-
156
export const artifactGenerationCommandSchema = z.union([
16-
z.string({ description: 'Command as a single string' }).min(1),
7+
z.string({ description: 'Generate artifact files' }).min(1),
178
z.object({
189
command: z.string({ description: 'Generate artifact files' }).min(1),
1910
args: z.array(z.string()).optional(),
2011
}),
2112
]);
2213

2314
export const pluginArtifactOptionsSchema = z.object({
24-
generateArtifacts: artifactGenerationCommandSchema.optional(),
15+
generateArtifactsCommand: artifactGenerationCommandSchema.optional(),
2516
artifactsPaths: z.union([z.string(), z.array(z.string()).min(1)]),
2617
});
2718

packages/models/src/lib/configuration.unit.test.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
import { describe, expect, it } from 'vitest';
22
import {
3-
artifactGenerationCommand,
3+
artifactGenerationCommandSchema,
44
pluginArtifactOptionsSchema,
55
} from './configuration.js';
66

7-
describe('artifactGenerationCommand', () => {
7+
describe('artifactGenerationCommandSchema', () => {
88
it('should validate a command with required fields', () => {
99
const data = { command: 'npx' };
10-
expect(artifactGenerationCommand.safeParse(data)).toStrictEqual({
10+
expect(artifactGenerationCommandSchema.safeParse(data)).toStrictEqual({
1111
success: true,
1212
data: { command: 'npx' },
1313
});
1414
});
1515

1616
it('should validate a command with args', () => {
1717
const data = { command: 'npx', args: ['eslint', 'src/'] };
18-
expect(artifactGenerationCommand.safeParse(data)).toStrictEqual({
18+
expect(artifactGenerationCommandSchema.safeParse(data)).toStrictEqual({
1919
success: true,
2020
data: { command: 'npx', args: ['eslint', 'src/'] },
2121
});
2222
});
2323

2424
it('should fail if command is missing', () => {
2525
const data = { args: ['eslint', 'src/'] };
26-
expect(artifactGenerationCommand.safeParse(data).success).toBe(false);
26+
expect(artifactGenerationCommandSchema.safeParse(data).success).toBe(false);
2727
});
2828

2929
it('should fail if command is empty', () => {
3030
const data = { command: '' };
31-
expect(artifactGenerationCommand.safeParse(data).success).toBe(false);
31+
expect(artifactGenerationCommandSchema.safeParse(data).success).toBe(false);
3232
});
3333

3434
it('should fail if args is not an array of strings', () => {
3535
const data = { command: 'npx', args: [123, true] };
36-
expect(artifactGenerationCommand.safeParse(data).success).toBe(false);
36+
expect(artifactGenerationCommandSchema.safeParse(data).success).toBe(false);
3737
});
3838
});
3939

@@ -63,22 +63,22 @@ describe('pluginArtifactOptionsSchema', () => {
6363
expect(pluginArtifactOptionsSchema.safeParse(data).success).toBe(false);
6464
});
6565

66-
it('should validate with generateArtifacts and artifactsPaths', () => {
66+
it('should validate with generateArtifactsCommand and artifactsPaths', () => {
6767
const data = {
68-
generateArtifacts: { command: 'npm', args: ['run', 'build'] },
68+
generateArtifactsCommand: { command: 'npm', args: ['run', 'build'] },
6969
artifactsPaths: ['dist/report.json'],
7070
};
7171
expect(pluginArtifactOptionsSchema.safeParse(data)).toStrictEqual({
7272
success: true,
7373
data: {
74-
generateArtifacts: { command: 'npm', args: ['run', 'build'] },
74+
generateArtifactsCommand: { command: 'npm', args: ['run', 'build'] },
7575
artifactsPaths: ['dist/report.json'],
7676
},
7777
});
7878
});
7979

8080
it('should fail if artifactsPaths is missing', () => {
81-
const data = { generateArtifacts: { command: 'npm' } };
81+
const data = { generateArtifactsCommand: { command: 'npm' } };
8282
expect(pluginArtifactOptionsSchema.safeParse(data).success).toBe(false);
8383
});
8484

@@ -87,39 +87,39 @@ describe('pluginArtifactOptionsSchema', () => {
8787
expect(pluginArtifactOptionsSchema.safeParse(data).success).toBe(false);
8888
});
8989

90-
it('should fail if generateArtifacts is invalid', () => {
90+
it('should fail if generateArtifactsCommand is invalid', () => {
9191
const data = {
92-
generateArtifacts: { command: '' },
92+
generateArtifactsCommand: { command: '' },
9393
artifactsPaths: 'dist/report.json',
9494
};
9595
expect(pluginArtifactOptionsSchema.safeParse(data).success).toBe(false);
9696
});
9797

98-
it('should validate with generateArtifacts as a string', () => {
98+
it('should validate with generateArtifactsCommand as a string', () => {
9999
const data = {
100-
generateArtifacts: 'yarn test --coverage',
100+
generateArtifactsCommand: 'yarn test --coverage',
101101
artifactsPaths: 'coverage/lcov.info',
102102
};
103103
expect(pluginArtifactOptionsSchema.safeParse(data)).toStrictEqual({
104104
success: true,
105105
data: {
106-
generateArtifacts: 'yarn test --coverage',
106+
generateArtifactsCommand: 'yarn test --coverage',
107107
artifactsPaths: 'coverage/lcov.info',
108108
},
109109
});
110110
});
111111

112-
it('should fail if generateArtifacts is an empty string', () => {
112+
it('should fail if generateArtifactsCommand is an empty string', () => {
113113
const data = {
114-
generateArtifacts: '',
114+
generateArtifactsCommand: '',
115115
artifactsPaths: 'coverage/lcov.info',
116116
};
117117
expect(pluginArtifactOptionsSchema.safeParse(data).success).toBe(false);
118118
});
119119

120-
it('should fail if generateArtifacts is a number', () => {
120+
it('should fail if generateArtifactsCommand is a number', () => {
121121
const data = {
122-
generateArtifacts: 123,
122+
generateArtifactsCommand: 123,
123123
artifactsPaths: 'coverage/lcov.info',
124124
};
125125
expect(pluginArtifactOptionsSchema.safeParse(data).success).toBe(false);

0 commit comments

Comments
 (0)