Skip to content

Commit 9c3f778

Browse files
committed
fix: review update
1 parent f1819de commit 9c3f778

12 files changed

Lines changed: 92 additions & 18 deletions

src/__tests__/__snapshots__/tool.searchPatternFlyDocs.test.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ exports[`searchPatternFlyDocsTool should have a consistent return structure: str
1010

1111
exports[`searchPatternFlyDocsTool, callback should parse parameters, default: search 1`] = `"# Search results for "Button". Showing 1 exact match."`;
1212

13+
exports[`searchPatternFlyDocsTool, callback should parse parameters, explicit valid version: search 1`] = `"# Search results for "Button". Showing 1 exact match."`;
14+
1315
exports[`searchPatternFlyDocsTool, callback should parse parameters, with "*" searchQuery all: search 1`] = `"# Search results for "all" resources. Only showing the first 10 results. There are 546 potential match variations. Try searching with a more specific query."`;
1416

1517
exports[`searchPatternFlyDocsTool, callback should parse parameters, with "all" searchQuery all: search 1`] = `"# Search results for "all" resources. Only showing the first 10 results. There are 546 potential match variations. Try searching with a more specific query."`;

src/__tests__/resource.patternFlyComponentsIndex.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ describe('resourceCallback', () => {
2525
variables: {},
2626
expected: '# PatternFly Component Names Index for "v6"'
2727
},
28+
{
29+
description: 'explicit valid version',
30+
variables: {
31+
version: 'v6'
32+
},
33+
expected: '# PatternFly Component Names Index for "v6"'
34+
},
2835
{
2936
description: 'category',
3037
variables: {

src/__tests__/resource.patternFlyDocsIndex.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ describe('resourceCallback', () => {
2525
variables: {},
2626
expected: '# PatternFly Documentation Index for "v6"'
2727
},
28+
{
29+
description: 'explicit valid version',
30+
variables: {
31+
version: 'v6'
32+
},
33+
expected: '# PatternFly Documentation Index for "v6"'
34+
},
2835
{
2936
description: 'category',
3037
variables: {

src/__tests__/resource.patternFlyDocsTemplate.test.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ describe('resourceCallback', () => {
4343
});
4444

4545
it.each([
46+
{
47+
description: 'no version',
48+
variables: {
49+
name: 'Button'
50+
}
51+
},
4652
{
4753
description: 'default',
4854
variables: {
@@ -84,25 +90,44 @@ describe('resourceCallback', () => {
8490
});
8591

8692
it.each([
93+
{
94+
description: 'invalid version',
95+
error: 'Invalid PatternFly version',
96+
variables: {
97+
name: 'Button',
98+
version: 'v5'
99+
}
100+
},
87101
{
88102
description: 'with missing or undefined name',
89103
error: 'must be a string',
90-
variables: { version: 'v6' }
104+
variables: {
105+
version: 'v6'
106+
}
91107
},
92108
{
93109
description: 'with null name',
94110
error: 'must be a string',
95-
variables: { name: null, version: 'v6' }
111+
variables: {
112+
name: null,
113+
version: 'v6'
114+
}
96115
},
97116
{
98117
description: 'with empty name',
99118
error: 'must be a string',
100-
variables: { name: '', version: 'v6' }
119+
variables: {
120+
name: '',
121+
version: 'v6'
122+
}
101123
},
102124
{
103125
description: 'with non-string name',
104126
error: 'must be a string',
105-
variables: { name: 123, version: 'v6' }
127+
variables: {
128+
name: 123,
129+
version: 'v6'
130+
}
106131
}
107132
])('should handle variable errors, $description', async ({ error, variables }) => {
108133
const mockContent = `Mock content for ${variables.name}`;

src/__tests__/resource.patternFlySchemasIndex.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ describe('resourceCallback', () => {
3232
description: 'default',
3333
variables: {},
3434
expected: '# PatternFly Component JSON Schemas Index for "v6"'
35+
},
36+
{
37+
description: 'explicit valid version',
38+
variables: {
39+
version: 'v6'
40+
},
41+
expected: '# PatternFly Component JSON Schemas Index for "v6"'
3542
}
3643
])('should return component schemas index, $description', async ({ variables, expected }) => {
3744
const result = await resourceCallback(undefined as any, variables);

src/__tests__/resource.patternFlySchemasTemplate.test.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe('resourceCallback', () => {
2525
});
2626

2727
it.each([
28+
{ description: 'no version', variables: { name: 'Button' } },
2829
{
2930
description: 'default',
3031
variables: {
@@ -53,6 +54,14 @@ describe('resourceCallback', () => {
5354
});
5455

5556
it.each([
57+
{
58+
description: 'invalid version',
59+
error: 'Invalid PatternFly version',
60+
variables: {
61+
name: 'Button',
62+
version: 'v5'
63+
}
64+
},
5665
{
5766
description: 'with missing or undefined name',
5867
error: 'must be a string',
@@ -61,27 +70,39 @@ describe('resourceCallback', () => {
6170
{
6271
description: 'with null name',
6372
error: 'must be a string',
64-
variables: { name: null }
73+
variables: {
74+
name: null
75+
}
6576
},
6677
{
6778
description: 'with empty name',
6879
error: 'must be a string',
69-
variables: { name: '' }
80+
variables: {
81+
name: ''
82+
}
7083
},
7184
{
7285
description: 'with non-string name',
7386
error: 'must be a string',
74-
variables: { name: 123 }
87+
variables: {
88+
name: 123
89+
}
7590
},
7691
{
7792
description: 'non-existent name',
7893
error: 'No component JSON schemas found',
79-
variables: { name: 'loremIpsum', version: 'v6' }
94+
variables: {
95+
name: 'loremIpsum',
96+
version: 'v6'
97+
}
8098
},
8199
{
82100
description: 'found but no schema',
83101
error: 'No component JSON schemas found',
84-
variables: { name: 'table', version: 'v6' }
102+
variables: {
103+
name: 'table',
104+
version: 'v6'
105+
}
85106
}
86107
])('should handle variable errors, $description', async ({ error, variables }) => {
87108
await expect(resourceCallback(undefined as any, variables as any)).rejects.toThrow(McpError);

src/__tests__/tool.searchPatternFlyDocs.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ describe('searchPatternFlyDocsTool, callback', () => {
2929
});
3030

3131
it.each([
32+
{
33+
description: 'explicit valid version',
34+
searchQuery: 'Button',
35+
version: 'v6'
36+
},
3237
{
3338
description: 'default',
3439
searchQuery: 'Button'

src/resource.patternFlyComponentsIndex.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const resourceCallback = async (passedUri: URL, variables: Record<string, string
5555
const normalizedVersion = await normalizeEnumeratedPatternFlyVersion.memo(version);
5656

5757
assertInput(
58-
!version && !normalizedVersion,
58+
!version || Boolean(normalizedVersion),
5959
`Invalid PatternFly version "${version?.trim()}". Available versions are: ${availableVersions.join(', ')}`
6060
);
6161

src/resource.patternFlyDocsIndex.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const resourceCallback = async (passedUri: URL, variables: Record<string, string
6262
const normalizedVersion = await normalizeEnumeratedPatternFlyVersion.memo(version);
6363

6464
assertInput(
65-
!version && !normalizedVersion,
65+
!version || Boolean(normalizedVersion),
6666
`Invalid PatternFly version "${version?.trim()}". Available versions are: ${availableVersions.join(', ')}`
6767
);
6868

src/resource.patternFlyDocsTemplate.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ const resourceCallback = async (passedUri: URL, variables: Record<string, string
6666
}
6767

6868
const { availableVersions, latestVersion } = await getPatternFlyMcpResources.memo();
69-
const normalizedVersion = (await normalizeEnumeratedPatternFlyVersion.memo(version)) || latestVersion;
69+
const normalizedVersion = await normalizeEnumeratedPatternFlyVersion.memo(version);
7070

7171
assertInput(
72-
normalizedVersion,
72+
!version || Boolean(normalizedVersion),
7373
`Invalid PatternFly version "${version?.trim()}". Available versions are: ${availableVersions.join(', ')}`
7474
);
7575

76-
const updatedVersion = normalizedVersion;
76+
const updatedVersion = normalizedVersion || latestVersion;
7777
const updatedName = name.trim();
7878

7979
const { byEntry } = await filterPatternFly.memo({

0 commit comments

Comments
 (0)