@hubspot/cli 7.7.31-experimental.0 → 7.7.33-experimental.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/commands/app.js +1 -6
  2. package/commands/getStarted.js +5 -4
  3. package/commands/project/__tests__/add.test.js +3 -5
  4. package/commands/project/__tests__/deploy.test.js +3 -2
  5. package/commands/project/add.js +2 -4
  6. package/commands/project/deploy.js +9 -61
  7. package/commands/project/dev/index.js +1 -1
  8. package/commands/project/dev/unifiedFlow.js +3 -0
  9. package/commands/project/upload.d.ts +2 -2
  10. package/commands/project/upload.js +3 -3
  11. package/commands/project/validate.js +1 -1
  12. package/commands/project/watch.js +2 -2
  13. package/commands/testAccount/create.js +0 -3
  14. package/lang/en.d.ts +8 -26
  15. package/lang/en.js +9 -27
  16. package/lib/__tests__/hasFeature.test.js +145 -7
  17. package/lib/__tests__/importData.test.js +1 -1
  18. package/lib/app/migrate.js +9 -2
  19. package/lib/constants.d.ts +2 -0
  20. package/lib/constants.js +2 -0
  21. package/lib/errorHandlers/index.d.ts +4 -0
  22. package/lib/errorHandlers/index.js +1 -1
  23. package/lib/hasFeature.js +6 -0
  24. package/lib/importData.js +1 -1
  25. package/lib/mcp/setup.js +1 -1
  26. package/lib/projectProfiles.d.ts +1 -1
  27. package/lib/projectProfiles.js +2 -10
  28. package/lib/projects/__tests__/AppDevModeInterface.test.js +61 -44
  29. package/lib/projects/__tests__/LocalDevProcess.test.js +1 -0
  30. package/lib/projects/__tests__/deploy.test.js +164 -0
  31. package/lib/projects/__tests__/{buildAndDeploy.test.js → platformVersion.test.js} +2 -2
  32. package/lib/projects/add/__tests__/legacyAddComponent.test.js +49 -6
  33. package/lib/projects/add/__tests__/v3AddComponent.test.js +71 -1
  34. package/lib/projects/add/legacyAddComponent.d.ts +1 -1
  35. package/lib/projects/add/legacyAddComponent.js +5 -1
  36. package/lib/projects/add/v3AddComponent.d.ts +1 -0
  37. package/lib/projects/add/v3AddComponent.js +2 -2
  38. package/lib/projects/create/__tests__/v3.test.js +97 -9
  39. package/lib/projects/create/index.js +2 -2
  40. package/lib/projects/create/legacy.js +1 -1
  41. package/lib/projects/create/v3.d.ts +2 -2
  42. package/lib/projects/create/v3.js +35 -12
  43. package/lib/projects/deploy.d.ts +13 -0
  44. package/lib/projects/deploy.js +63 -0
  45. package/lib/projects/localDev/AppDevModeInterface.d.ts +0 -2
  46. package/lib/projects/localDev/AppDevModeInterface.js +65 -36
  47. package/lib/projects/localDev/DevServerManagerV2.js +1 -0
  48. package/lib/projects/localDev/LocalDevProcess.js +3 -1
  49. package/lib/projects/localDev/LocalDevState.d.ts +5 -2
  50. package/lib/projects/localDev/LocalDevState.js +9 -1
  51. package/lib/projects/localDev/helpers/project.js +1 -1
  52. package/lib/projects/platformVersion.d.ts +1 -0
  53. package/lib/projects/platformVersion.js +10 -0
  54. package/lib/projects/{buildAndDeploy.d.ts → pollProjectBuildAndDeploy.d.ts} +0 -1
  55. package/lib/projects/{buildAndDeploy.js → pollProjectBuildAndDeploy.js} +0 -10
  56. package/lib/projects/structure.d.ts +2 -2
  57. package/lib/projects/upload.d.ts +1 -2
  58. package/lib/projects/upload.js +1 -2
  59. package/lib/projects/urls.d.ts +1 -0
  60. package/lib/projects/urls.js +3 -0
  61. package/lib/prompts/__tests__/projectAddPrompt.test.d.ts +1 -0
  62. package/lib/prompts/__tests__/projectAddPrompt.test.js +143 -0
  63. package/lib/prompts/__tests__/selectProjectTemplatePrompt.test.d.ts +1 -0
  64. package/lib/prompts/__tests__/selectProjectTemplatePrompt.test.js +160 -0
  65. package/lib/prompts/createDeveloperTestAccountConfigPrompt.js +1 -0
  66. package/lib/prompts/importDataFilePathPrompt.js +4 -2
  67. package/lib/prompts/installAppPrompt.d.ts +6 -1
  68. package/lib/prompts/installAppPrompt.js +6 -1
  69. package/lib/prompts/projectAddPrompt.js +1 -1
  70. package/lib/prompts/selectProjectTemplatePrompt.js +1 -1
  71. package/mcp-server/tools/cms/HsCreateFunctionTool.d.ts +32 -0
  72. package/mcp-server/tools/cms/HsCreateFunctionTool.js +96 -0
  73. package/mcp-server/tools/cms/HsCreateTemplateTool.d.ts +26 -0
  74. package/mcp-server/tools/cms/HsCreateTemplateTool.js +75 -0
  75. package/mcp-server/tools/cms/HsFunctionLogsTool.d.ts +32 -0
  76. package/mcp-server/tools/cms/HsFunctionLogsTool.js +76 -0
  77. package/mcp-server/tools/cms/HsListFunctionsTool.d.ts +23 -0
  78. package/mcp-server/tools/cms/HsListFunctionsTool.js +58 -0
  79. package/mcp-server/tools/cms/__tests__/HsCreateFunctionTool.test.d.ts +1 -0
  80. package/mcp-server/tools/cms/__tests__/HsCreateFunctionTool.test.js +251 -0
  81. package/mcp-server/tools/cms/__tests__/HsCreateTemplateTool.test.d.ts +1 -0
  82. package/mcp-server/tools/cms/__tests__/HsCreateTemplateTool.test.js +206 -0
  83. package/mcp-server/tools/cms/__tests__/HsFunctionLogsTool.test.d.ts +1 -0
  84. package/mcp-server/tools/cms/__tests__/HsFunctionLogsTool.test.js +183 -0
  85. package/mcp-server/tools/cms/__tests__/HsListFunctionsTool.test.d.ts +1 -0
  86. package/mcp-server/tools/cms/__tests__/HsListFunctionsTool.test.js +120 -0
  87. package/mcp-server/tools/index.js +8 -0
  88. package/mcp-server/tools/project/AddFeatureToProjectTool.d.ts +3 -3
  89. package/mcp-server/tools/project/CreateProjectTool.d.ts +3 -3
  90. package/mcp-server/tools/project/GetConfigValuesTool.js +3 -3
  91. package/mcp-server/tools/project/constants.d.ts +1 -1
  92. package/mcp-server/tools/project/constants.js +6 -4
  93. package/package.json +4 -3
  94. package/types/LocalDev.d.ts +2 -1
  95. package/types/Projects.d.ts +1 -0
  96. package/types/Yargs.d.ts +1 -1
  97. package/ui/components/BoxWithTitle.d.ts +8 -0
  98. package/ui/components/BoxWithTitle.js +9 -0
  99. package/ui/components/HorizontalSelectPrompt.d.ts +8 -0
  100. package/ui/components/HorizontalSelectPrompt.js +30 -0
  101. package/ui/components/StatusMessageBoxes.d.ts +12 -0
  102. package/ui/components/StatusMessageBoxes.js +31 -0
  103. package/ui/lib/ui-testing-utils.d.ts +9 -0
  104. package/ui/lib/ui-testing-utils.js +47 -0
  105. package/ui/lib/useTerminalSize.d.ts +13 -0
  106. package/ui/lib/useTerminalSize.js +31 -0
  107. package/ui/styles.d.ts +18 -0
  108. package/ui/styles.js +18 -0
  109. package/ui/views/UiSandbox.d.ts +5 -0
  110. package/ui/views/UiSandbox.js +25 -0
  111. package/commands/app/__tests__/install.test.js +0 -47
  112. package/commands/app/install.d.ts +0 -8
  113. package/commands/app/install.js +0 -122
  114. /package/{commands/app/__tests__/install.test.d.ts → lib/projects/__tests__/deploy.test.d.ts} +0 -0
  115. /package/lib/projects/__tests__/{buildAndDeploy.test.d.ts → platformVersion.test.d.ts} +0 -0
@@ -0,0 +1,251 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { HsCreateFunctionTool } from '../HsCreateFunctionTool.js';
3
+ import { runCommandInDir } from '../../../utils/project.js';
4
+ import { addFlag } from '../../../utils/command.js';
5
+ import { HTTP_METHODS } from '../../../../types/Cms.js';
6
+ vi.mock('@modelcontextprotocol/sdk/server/mcp.js');
7
+ vi.mock('../../../utils/project');
8
+ vi.mock('../../../utils/command');
9
+ vi.mock('../../../utils/toolUsageTracking', () => ({
10
+ trackToolUsage: vi.fn(),
11
+ }));
12
+ const mockRunCommandInDir = runCommandInDir;
13
+ const mockAddFlag = addFlag;
14
+ describe('HsCreateFunctionTool', () => {
15
+ let mockMcpServer;
16
+ let tool;
17
+ let mockRegisteredTool;
18
+ beforeEach(() => {
19
+ vi.clearAllMocks();
20
+ // @ts-expect-error Not mocking the whole server
21
+ mockMcpServer = {
22
+ registerTool: vi.fn(),
23
+ };
24
+ mockRegisteredTool = {};
25
+ mockMcpServer.registerTool.mockReturnValue(mockRegisteredTool);
26
+ tool = new HsCreateFunctionTool(mockMcpServer);
27
+ });
28
+ describe('register', () => {
29
+ it('should register the tool with the MCP server', () => {
30
+ const result = tool.register();
31
+ expect(mockMcpServer.registerTool).toHaveBeenCalledWith('create-hubspot-cms-function', {
32
+ title: 'Create HubSpot CMS Serverless Function',
33
+ description: `Creates a new HubSpot CMS serverless function using the hs create function command. Functions can be created non-interactively by specifying functionsFolder, filename, and endpointPath. Supports all HTTP methods (${HTTP_METHODS.join(', ')}).`,
34
+ inputSchema: expect.any(Object),
35
+ }, expect.any(Function));
36
+ expect(result).toBe(mockRegisteredTool);
37
+ });
38
+ });
39
+ describe('handler', () => {
40
+ it('should prompt for all missing required parameters', async () => {
41
+ const result = await tool.handler({
42
+ absoluteCurrentWorkingDirectory: '/test/dir',
43
+ });
44
+ expect(result.content).toHaveLength(3);
45
+ expect(result.content[0].text).toContain('Ask the user to provide the folder name for the function');
46
+ expect(result.content[1].text).toContain('Ask the user to provide the filename for the function');
47
+ expect(result.content[2].text).toContain('Ask the user to provide the API endpoint path for the function');
48
+ });
49
+ it('should not prompt when all required params provided', async () => {
50
+ mockAddFlag
51
+ .mockReturnValueOnce('hs create function --functions-folder api')
52
+ .mockReturnValueOnce('hs create function --functions-folder api --filename test-function')
53
+ .mockReturnValueOnce('hs create function --functions-folder api --filename test-function --endpoint-method GET')
54
+ .mockReturnValueOnce('hs create function --functions-folder api --filename test-function --endpoint-method GET --endpoint-path /api/test');
55
+ mockRunCommandInDir.mockResolvedValue({
56
+ stdout: 'Function created successfully',
57
+ stderr: '',
58
+ });
59
+ const result = await tool.handler({
60
+ absoluteCurrentWorkingDirectory: '/test/dir',
61
+ functionsFolder: 'api',
62
+ filename: 'test-function',
63
+ endpointPath: '/api/test',
64
+ });
65
+ expect(result.content).toHaveLength(2);
66
+ expect(result.content[0].text).toContain('Function created successfully');
67
+ });
68
+ it('should prompt for missing functionsFolder when other required params provided', async () => {
69
+ const result = await tool.handler({
70
+ absoluteCurrentWorkingDirectory: '/test/dir',
71
+ filename: 'test-function',
72
+ endpointPath: '/api/test',
73
+ });
74
+ expect(result.content).toHaveLength(1);
75
+ expect(result.content[0].text).toContain('Ask the user to provide the folder name for the function');
76
+ });
77
+ it('should prompt for missing filename when other required params provided', async () => {
78
+ const result = await tool.handler({
79
+ absoluteCurrentWorkingDirectory: '/test/dir',
80
+ functionsFolder: 'api',
81
+ endpointPath: '/api/test',
82
+ });
83
+ expect(result.content).toHaveLength(1);
84
+ expect(result.content[0].text).toContain('Ask the user to provide the filename for the function');
85
+ });
86
+ it('should prompt for missing endpointPath when other required params provided', async () => {
87
+ const result = await tool.handler({
88
+ absoluteCurrentWorkingDirectory: '/test/dir',
89
+ functionsFolder: 'api',
90
+ filename: 'test-function',
91
+ });
92
+ expect(result.content).toHaveLength(1);
93
+ expect(result.content[0].text).toContain('Ask the user to provide the API endpoint path for the function');
94
+ });
95
+ it('should execute command with all required parameters (default GET method)', async () => {
96
+ mockAddFlag
97
+ .mockReturnValueOnce('hs create function --functions-folder api')
98
+ .mockReturnValueOnce('hs create function --functions-folder api --filename test-function')
99
+ .mockReturnValueOnce('hs create function --functions-folder api --filename test-function --endpoint-method GET')
100
+ .mockReturnValueOnce('hs create function --functions-folder api --filename test-function --endpoint-method GET --endpoint-path /api/test');
101
+ mockRunCommandInDir.mockResolvedValue({
102
+ stdout: 'Function created successfully',
103
+ stderr: '',
104
+ });
105
+ const result = await tool.handler({
106
+ absoluteCurrentWorkingDirectory: '/test/dir',
107
+ functionsFolder: 'api',
108
+ filename: 'test-function',
109
+ endpointPath: '/api/test',
110
+ });
111
+ expect(mockAddFlag).toHaveBeenCalledWith('hs create function', 'functions-folder', 'api');
112
+ expect(mockAddFlag).toHaveBeenCalledWith(expect.stringContaining('functions-folder'), 'filename', 'test-function');
113
+ expect(mockAddFlag).toHaveBeenCalledWith(expect.stringContaining('filename'), 'endpoint-method', 'GET');
114
+ expect(mockAddFlag).toHaveBeenCalledWith(expect.stringContaining('endpoint-method'), 'endpoint-path', '/api/test');
115
+ expect(mockRunCommandInDir).toHaveBeenCalledWith('/test/dir', expect.stringContaining('hs create function'));
116
+ expect(result.content).toHaveLength(2);
117
+ expect(result.content[0].text).toContain('Function created successfully');
118
+ });
119
+ it('should execute command with POST method', async () => {
120
+ mockAddFlag
121
+ .mockReturnValueOnce('hs create function --functions-folder api')
122
+ .mockReturnValueOnce('hs create function --functions-folder api --filename post-function')
123
+ .mockReturnValueOnce('hs create function "POST Function" --functions-folder api --filename post-function --endpoint-method POST')
124
+ .mockReturnValueOnce('hs create function "POST Function" --functions-folder api --filename post-function --endpoint-method POST --endpoint-path /api/create');
125
+ mockRunCommandInDir.mockResolvedValue({
126
+ stdout: 'POST function created successfully',
127
+ stderr: '',
128
+ });
129
+ const result = await tool.handler({
130
+ absoluteCurrentWorkingDirectory: '/test/dir',
131
+ functionsFolder: 'api',
132
+ filename: 'post-function',
133
+ endpointMethod: 'POST',
134
+ endpointPath: '/api/create',
135
+ });
136
+ expect(mockAddFlag).toHaveBeenCalledWith(expect.stringContaining('filename'), 'endpoint-method', 'POST');
137
+ expect(result.content[0].text).toContain('POST function created successfully');
138
+ });
139
+ it('should execute command with PUT method', async () => {
140
+ mockAddFlag
141
+ .mockReturnValueOnce('hs create function --functions-folder api')
142
+ .mockReturnValueOnce('hs create function "PUT Function" --functions-folder api --filename put-function')
143
+ .mockReturnValueOnce('hs create function "PUT Function" --functions-folder api --filename put-function --endpoint-method PUT')
144
+ .mockReturnValueOnce('hs create function "PUT Function" --functions-folder api --filename put-function --endpoint-method PUT --endpoint-path /api/update');
145
+ mockRunCommandInDir.mockResolvedValue({
146
+ stdout: 'PUT function created successfully',
147
+ stderr: '',
148
+ });
149
+ const result = await tool.handler({
150
+ absoluteCurrentWorkingDirectory: '/test/dir',
151
+ functionsFolder: 'api',
152
+ filename: 'put-function',
153
+ endpointMethod: 'PUT',
154
+ endpointPath: '/api/update',
155
+ });
156
+ expect(mockAddFlag).toHaveBeenCalledWith(expect.stringContaining('filename'), 'endpoint-method', 'PUT');
157
+ expect(result.content[0].text).toContain('PUT function created successfully');
158
+ });
159
+ it('should execute command with DELETE method', async () => {
160
+ mockAddFlag
161
+ .mockReturnValueOnce('hs create function --functions-folder api')
162
+ .mockReturnValueOnce('hs create function "DELETE Function" --functions-folder api --filename delete-function')
163
+ .mockReturnValueOnce('hs create function "DELETE Function" --functions-folder api --filename delete-function --endpoint-method DELETE')
164
+ .mockReturnValueOnce('hs create function "DELETE Function" --functions-folder api --filename delete-function --endpoint-method DELETE --endpoint-path /api/delete');
165
+ mockRunCommandInDir.mockResolvedValue({
166
+ stdout: 'DELETE function created successfully',
167
+ stderr: '',
168
+ });
169
+ const result = await tool.handler({
170
+ absoluteCurrentWorkingDirectory: '/test/dir',
171
+ functionsFolder: 'api',
172
+ filename: 'delete-function',
173
+ endpointMethod: 'DELETE',
174
+ endpointPath: '/api/delete',
175
+ });
176
+ expect(mockAddFlag).toHaveBeenCalledWith(expect.stringContaining('filename'), 'endpoint-method', 'DELETE');
177
+ expect(result.content[0].text).toContain('DELETE function created successfully');
178
+ });
179
+ it('should execute command with PATCH method', async () => {
180
+ mockAddFlag
181
+ .mockReturnValueOnce('hs create function --functions-folder api')
182
+ .mockReturnValueOnce('hs create function "PATCH Function" --functions-folder api --filename patch-function')
183
+ .mockReturnValueOnce('hs create function "PATCH Function" --functions-folder api --filename patch-function --endpoint-method PATCH')
184
+ .mockReturnValueOnce('hs create function "PATCH Function" --functions-folder api --filename patch-function --endpoint-method PATCH --endpoint-path /api/patch');
185
+ mockRunCommandInDir.mockResolvedValue({
186
+ stdout: 'PATCH function created successfully',
187
+ stderr: '',
188
+ });
189
+ const result = await tool.handler({
190
+ absoluteCurrentWorkingDirectory: '/test/dir',
191
+ functionsFolder: 'api',
192
+ filename: 'patch-function',
193
+ endpointMethod: 'PATCH',
194
+ endpointPath: '/api/patch',
195
+ });
196
+ expect(mockAddFlag).toHaveBeenCalledWith(expect.stringContaining('filename'), 'endpoint-method', 'PATCH');
197
+ expect(result.content[0].text).toContain('PATCH function created successfully');
198
+ });
199
+ it('should handle command execution errors', async () => {
200
+ mockRunCommandInDir.mockRejectedValue(new Error('Function creation failed'));
201
+ const result = await tool.handler({
202
+ absoluteCurrentWorkingDirectory: '/test/dir',
203
+ functionsFolder: 'api',
204
+ filename: 'test-function',
205
+ endpointPath: '/api/test',
206
+ });
207
+ expect(result.content).toHaveLength(1);
208
+ expect(result.content[0].text).toContain('Function creation failed');
209
+ });
210
+ it('should handle stderr output', async () => {
211
+ mockAddFlag
212
+ .mockReturnValueOnce('hs create function "Test Function" --functions-folder api')
213
+ .mockReturnValueOnce('hs create function "Test Function" --functions-folder api --filename test-function')
214
+ .mockReturnValueOnce('hs create function "Test Function" --functions-folder api --filename test-function --endpoint-method GET')
215
+ .mockReturnValueOnce('hs create function "Test Function" --functions-folder api --filename test-function --endpoint-method GET --endpoint-path /api/test');
216
+ mockRunCommandInDir.mockResolvedValue({
217
+ stdout: 'Function created successfully',
218
+ stderr: 'Warning: Using deprecated function syntax',
219
+ });
220
+ const result = await tool.handler({
221
+ absoluteCurrentWorkingDirectory: '/test/dir',
222
+ functionsFolder: 'api',
223
+ filename: 'test-function',
224
+ endpointPath: '/api/test',
225
+ });
226
+ expect(result.content).toHaveLength(2);
227
+ expect(result.content[0].text).toContain('Function created successfully');
228
+ expect(result.content[1].text).toContain('Warning: Using deprecated function syntax');
229
+ });
230
+ it('should execute command with destination path', async () => {
231
+ mockAddFlag
232
+ .mockReturnValueOnce('hs create function "functions/custom" --functions-folder api')
233
+ .mockReturnValueOnce('hs create function "functions/custom" --functions-folder api --filename test-function')
234
+ .mockReturnValueOnce('hs create function "functions/custom" --functions-folder api --filename test-function --endpoint-method GET')
235
+ .mockReturnValueOnce('hs create function "functions/custom" --functions-folder api --filename test-function --endpoint-method GET --endpoint-path /api/test');
236
+ mockRunCommandInDir.mockResolvedValue({
237
+ stdout: 'Function created at custom path',
238
+ stderr: '',
239
+ });
240
+ const result = await tool.handler({
241
+ absoluteCurrentWorkingDirectory: '/test/dir',
242
+ dest: 'functions/custom',
243
+ functionsFolder: 'api',
244
+ filename: 'test-function',
245
+ endpointPath: '/api/test',
246
+ });
247
+ expect(mockRunCommandInDir).toHaveBeenCalledWith('/test/dir', expect.stringContaining('"functions/custom"'));
248
+ expect(result.content[0].text).toContain('Function created at custom path');
249
+ });
250
+ });
251
+ });
@@ -0,0 +1,206 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { HsCreateTemplateTool } from '../HsCreateTemplateTool.js';
3
+ import { runCommandInDir } from '../../../utils/project.js';
4
+ import { addFlag } from '../../../utils/command.js';
5
+ import { TEMPLATE_TYPES } from '../../../../types/Cms.js';
6
+ vi.mock('@modelcontextprotocol/sdk/server/mcp.js');
7
+ vi.mock('../../../utils/project');
8
+ vi.mock('../../../utils/command');
9
+ vi.mock('../../../utils/toolUsageTracking', () => ({
10
+ trackToolUsage: vi.fn(),
11
+ }));
12
+ const mockRunCommandInDir = runCommandInDir;
13
+ const mockAddFlag = addFlag;
14
+ describe('HsCreateTemplateTool', () => {
15
+ let mockMcpServer;
16
+ let tool;
17
+ let mockRegisteredTool;
18
+ beforeEach(() => {
19
+ vi.clearAllMocks();
20
+ // @ts-expect-error Not mocking the whole server
21
+ mockMcpServer = {
22
+ registerTool: vi.fn(),
23
+ };
24
+ mockRegisteredTool = {};
25
+ mockMcpServer.registerTool.mockReturnValue(mockRegisteredTool);
26
+ tool = new HsCreateTemplateTool(mockMcpServer);
27
+ });
28
+ describe('register', () => {
29
+ it('should register the tool with the MCP server', () => {
30
+ const result = tool.register();
31
+ expect(mockMcpServer.registerTool).toHaveBeenCalledWith('create-hubspot-cms-template', {
32
+ title: 'Create HubSpot CMS Template',
33
+ description: `Creates a new HubSpot CMS template using the hs create template command. Templates can be created non-interactively by specifying templateType. Supports all template types including: ${TEMPLATE_TYPES.join(', ')}.`,
34
+ inputSchema: expect.any(Object),
35
+ }, expect.any(Function));
36
+ expect(result).toBe(mockRegisteredTool);
37
+ });
38
+ });
39
+ describe('handler', () => {
40
+ it('should prompt for missing required parameters', async () => {
41
+ const result = await tool.handler({
42
+ absoluteCurrentWorkingDirectory: '/test/dir',
43
+ });
44
+ expect(result.content).toHaveLength(2);
45
+ expect(result.content[0].text).toContain('Ask the user to specify the name of the template');
46
+ expect(result.content[1].text).toContain('Ask the user what template type they want to create');
47
+ expect(result.content[1].text).toContain('page-template, email-template, partial, global-partial');
48
+ });
49
+ it('should prompt for missing name only when template type provided', async () => {
50
+ const result = await tool.handler({
51
+ absoluteCurrentWorkingDirectory: '/test/dir',
52
+ templateType: 'page-template',
53
+ });
54
+ expect(result.content).toHaveLength(1);
55
+ expect(result.content[0].text).toContain('Ask the user to specify the name of the template');
56
+ });
57
+ it('should prompt for missing templateType when name provided', async () => {
58
+ const result = await tool.handler({
59
+ absoluteCurrentWorkingDirectory: '/test/dir',
60
+ userSuppliedName: 'Test Template',
61
+ });
62
+ expect(result.content).toHaveLength(1);
63
+ expect(result.content[0].text).toContain('Ask the user what template type they want to create');
64
+ });
65
+ it('should execute command with all required parameters (page template)', async () => {
66
+ mockAddFlag.mockReturnValueOnce('hs create template "Page Template" --template-type page-template');
67
+ mockRunCommandInDir.mockResolvedValue({
68
+ stdout: 'Page template created successfully',
69
+ stderr: '',
70
+ });
71
+ const result = await tool.handler({
72
+ absoluteCurrentWorkingDirectory: '/test/dir',
73
+ userSuppliedName: 'Page Template',
74
+ templateType: 'page-template',
75
+ });
76
+ expect(mockAddFlag).toHaveBeenCalledWith('hs create template "Page Template"', 'template-type', 'page-template');
77
+ expect(mockRunCommandInDir).toHaveBeenCalledWith('/test/dir', 'hs create template "Page Template" --template-type page-template');
78
+ expect(result.content).toHaveLength(2);
79
+ expect(result.content[0].text).toContain('Page template created successfully');
80
+ });
81
+ it('should execute command with email template', async () => {
82
+ mockAddFlag.mockReturnValueOnce('hs create template "Email Template" --template-type email-template');
83
+ mockRunCommandInDir.mockResolvedValue({
84
+ stdout: 'Email template created successfully',
85
+ stderr: '',
86
+ });
87
+ const result = await tool.handler({
88
+ absoluteCurrentWorkingDirectory: '/test/dir',
89
+ userSuppliedName: 'Email Template',
90
+ templateType: 'email-template',
91
+ });
92
+ expect(mockAddFlag).toHaveBeenCalledWith('hs create template "Email Template"', 'template-type', 'email-template');
93
+ expect(result.content[0].text).toContain('Email template created successfully');
94
+ });
95
+ it('should execute command with partial template', async () => {
96
+ mockAddFlag.mockReturnValueOnce('hs create template "Header Partial" --template-type partial');
97
+ mockRunCommandInDir.mockResolvedValue({
98
+ stdout: 'Partial template created successfully',
99
+ stderr: '',
100
+ });
101
+ const result = await tool.handler({
102
+ absoluteCurrentWorkingDirectory: '/test/dir',
103
+ userSuppliedName: 'Header Partial',
104
+ templateType: 'partial',
105
+ });
106
+ expect(mockAddFlag).toHaveBeenCalledWith('hs create template "Header Partial"', 'template-type', 'partial');
107
+ expect(result.content[0].text).toContain('Partial template created successfully');
108
+ });
109
+ it('should execute command with blog-listing-template', async () => {
110
+ mockAddFlag.mockReturnValueOnce('hs create template "Blog Listing" --template-type blog-listing-template');
111
+ mockRunCommandInDir.mockResolvedValue({
112
+ stdout: 'Blog listing template created successfully',
113
+ stderr: '',
114
+ });
115
+ const result = await tool.handler({
116
+ absoluteCurrentWorkingDirectory: '/test/dir',
117
+ userSuppliedName: 'Blog Listing',
118
+ templateType: 'blog-listing-template',
119
+ });
120
+ expect(mockAddFlag).toHaveBeenCalledWith('hs create template "Blog Listing"', 'template-type', 'blog-listing-template');
121
+ expect(result.content[0].text).toContain('Blog listing template created successfully');
122
+ });
123
+ it('should execute command with destination path', async () => {
124
+ mockAddFlag.mockReturnValueOnce('hs create template "Test Template" "templates/custom" --template-type page-template');
125
+ mockRunCommandInDir.mockResolvedValue({
126
+ stdout: 'Template created at custom path',
127
+ stderr: '',
128
+ });
129
+ const result = await tool.handler({
130
+ absoluteCurrentWorkingDirectory: '/test/dir',
131
+ userSuppliedName: 'Test Template',
132
+ dest: 'templates/custom',
133
+ templateType: 'page-template',
134
+ });
135
+ expect(mockRunCommandInDir).toHaveBeenCalledWith('/test/dir', expect.stringContaining('"templates/custom"'));
136
+ expect(result.content[0].text).toContain('Template created at custom path');
137
+ });
138
+ it('should execute command with section template', async () => {
139
+ mockAddFlag.mockReturnValueOnce('hs create template "Hero Section" --template-type section');
140
+ mockRunCommandInDir.mockResolvedValue({
141
+ stdout: 'Section template created successfully',
142
+ stderr: '',
143
+ });
144
+ const result = await tool.handler({
145
+ absoluteCurrentWorkingDirectory: '/test/dir',
146
+ userSuppliedName: 'Hero Section',
147
+ templateType: 'section',
148
+ });
149
+ expect(mockAddFlag).toHaveBeenCalledWith('hs create template "Hero Section"', 'template-type', 'section');
150
+ expect(result.content[0].text).toContain('Section template created successfully');
151
+ });
152
+ it('should execute command with search template', async () => {
153
+ mockAddFlag.mockReturnValueOnce('hs create template "Search Results" --template-type search-template');
154
+ mockRunCommandInDir.mockResolvedValue({
155
+ stdout: 'Search template created successfully',
156
+ stderr: '',
157
+ });
158
+ const result = await tool.handler({
159
+ absoluteCurrentWorkingDirectory: '/test/dir',
160
+ userSuppliedName: 'Search Results',
161
+ templateType: 'search-template',
162
+ });
163
+ expect(mockAddFlag).toHaveBeenCalledWith('hs create template "Search Results"', 'template-type', 'search-template');
164
+ expect(result.content[0].text).toContain('Search template created successfully');
165
+ });
166
+ it('should execute command with blog-post-template', async () => {
167
+ mockAddFlag.mockReturnValueOnce('hs create template "Custom Blog Post" --template-type blog-post-template');
168
+ mockRunCommandInDir.mockResolvedValue({
169
+ stdout: 'Blog post template created successfully',
170
+ stderr: '',
171
+ });
172
+ const result = await tool.handler({
173
+ absoluteCurrentWorkingDirectory: '/test/dir',
174
+ userSuppliedName: 'Custom Blog Post',
175
+ templateType: 'blog-post-template',
176
+ });
177
+ expect(mockAddFlag).toHaveBeenCalledWith('hs create template "Custom Blog Post"', 'template-type', 'blog-post-template');
178
+ expect(result.content[0].text).toContain('Blog post template created successfully');
179
+ });
180
+ it('should handle command execution errors', async () => {
181
+ mockRunCommandInDir.mockRejectedValue(new Error('Template creation failed'));
182
+ const result = await tool.handler({
183
+ absoluteCurrentWorkingDirectory: '/test/dir',
184
+ userSuppliedName: 'Test Template',
185
+ templateType: 'page-template',
186
+ });
187
+ expect(result.content).toHaveLength(1);
188
+ expect(result.content[0].text).toContain('Template creation failed');
189
+ });
190
+ it('should handle stderr output', async () => {
191
+ mockAddFlag.mockReturnValueOnce('hs create template "Test Template" --template-type page-template');
192
+ mockRunCommandInDir.mockResolvedValue({
193
+ stdout: 'Template created successfully',
194
+ stderr: 'Warning: Using deprecated template syntax',
195
+ });
196
+ const result = await tool.handler({
197
+ absoluteCurrentWorkingDirectory: '/test/dir',
198
+ userSuppliedName: 'Test Template',
199
+ templateType: 'page-template',
200
+ });
201
+ expect(result.content).toHaveLength(2);
202
+ expect(result.content[0].text).toContain('Template created successfully');
203
+ expect(result.content[1].text).toContain('Warning: Using deprecated template syntax');
204
+ });
205
+ });
206
+ });
@@ -0,0 +1,183 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { HsFunctionLogsTool } from '../HsFunctionLogsTool.js';
3
+ import { runCommandInDir } from '../../../utils/project.js';
4
+ import { addFlag } from '../../../utils/command.js';
5
+ vi.mock('@modelcontextprotocol/sdk/server/mcp.js');
6
+ vi.mock('../../../utils/project');
7
+ vi.mock('../../../utils/command');
8
+ vi.mock('../../../utils/toolUsageTracking', () => ({
9
+ trackToolUsage: vi.fn(),
10
+ }));
11
+ const mockRunCommandInDir = runCommandInDir;
12
+ const mockAddFlag = addFlag;
13
+ describe('HsFunctionLogsTool', () => {
14
+ let mockMcpServer;
15
+ let tool;
16
+ let mockRegisteredTool;
17
+ beforeEach(() => {
18
+ vi.clearAllMocks();
19
+ // @ts-expect-error Not mocking the whole server
20
+ mockMcpServer = {
21
+ registerTool: vi.fn(),
22
+ };
23
+ mockRegisteredTool = {};
24
+ mockMcpServer.registerTool.mockReturnValue(mockRegisteredTool);
25
+ tool = new HsFunctionLogsTool(mockMcpServer);
26
+ });
27
+ describe('register', () => {
28
+ it('should register the tool with the MCP server', () => {
29
+ const result = tool.register();
30
+ expect(mockMcpServer.registerTool).toHaveBeenCalledWith('get-hubspot-cms-serverless-function-logs', expect.objectContaining({
31
+ title: 'Get HubSpot CMS serverless function logs for an endpoint',
32
+ description: 'Retrieve logs for HubSpot CMS serverless functions. Use this tool to help debug issues with serverless functions by reading the production logs. Supports various options like latest, compact, and limiting results. Use after listing functions with list-hubspot-cms-serverless-functions to get the endpoint path.',
33
+ inputSchema: expect.any(Object),
34
+ }), expect.any(Function));
35
+ expect(result).toBe(mockRegisteredTool);
36
+ });
37
+ });
38
+ describe('handler', () => {
39
+ it('should execute basic hs logs command with endpoint', async () => {
40
+ mockRunCommandInDir.mockResolvedValue({
41
+ stdout: '2023-01-01 10:00:00 INFO Function executed successfully',
42
+ stderr: '',
43
+ });
44
+ const result = await tool.handler({
45
+ absoluteCurrentWorkingDirectory: '/test/dir',
46
+ endpoint: 'my-function',
47
+ });
48
+ expect(mockRunCommandInDir).toHaveBeenCalledWith('/test/dir', 'hs logs my-function');
49
+ expect(result.content).toHaveLength(2);
50
+ expect(result.content[0].text).toContain('Function executed successfully');
51
+ expect(result.content[1].text).toBe('');
52
+ });
53
+ it('should strip leading slash from endpoint', async () => {
54
+ mockRunCommandInDir.mockResolvedValue({
55
+ stdout: '2023-01-01 10:00:00 INFO Function executed successfully',
56
+ stderr: '',
57
+ });
58
+ const result = await tool.handler({
59
+ absoluteCurrentWorkingDirectory: '/test/dir',
60
+ endpoint: '/api/my-endpoint',
61
+ });
62
+ expect(mockRunCommandInDir).toHaveBeenCalledWith('/test/dir', 'hs logs api/my-endpoint');
63
+ expect(result.content).toHaveLength(2);
64
+ expect(result.content[0].text).toContain('Function executed successfully');
65
+ expect(result.content[1].text).toBe('');
66
+ });
67
+ it('should execute hs logs command with latest flag', async () => {
68
+ mockAddFlag.mockReturnValue('hs logs my-endpoint --latest');
69
+ mockRunCommandInDir.mockResolvedValue({
70
+ stdout: '2023-01-01 10:00:00 INFO Latest log entry',
71
+ stderr: '',
72
+ });
73
+ const result = await tool.handler({
74
+ absoluteCurrentWorkingDirectory: '/test/dir',
75
+ endpoint: 'my-endpoint',
76
+ latest: true,
77
+ });
78
+ expect(mockAddFlag).toHaveBeenCalledWith('hs logs my-endpoint', 'latest', true);
79
+ expect(mockRunCommandInDir).toHaveBeenCalledWith('/test/dir', 'hs logs my-endpoint --latest');
80
+ expect(result.content).toHaveLength(2);
81
+ expect(result.content[0].text).toContain('Latest log entry');
82
+ expect(result.content[1].text).toBe('');
83
+ });
84
+ it('should execute hs logs command with compact flag', async () => {
85
+ mockAddFlag.mockReturnValue('hs logs my-endpoint --compact');
86
+ mockRunCommandInDir.mockResolvedValue({
87
+ stdout: 'compact log output',
88
+ stderr: '',
89
+ });
90
+ const result = await tool.handler({
91
+ absoluteCurrentWorkingDirectory: '/test/dir',
92
+ endpoint: 'my-endpoint',
93
+ compact: true,
94
+ });
95
+ expect(mockAddFlag).toHaveBeenCalledWith('hs logs my-endpoint', 'compact', true);
96
+ expect(mockRunCommandInDir).toHaveBeenCalledWith('/test/dir', 'hs logs my-endpoint --compact');
97
+ expect(result.content).toHaveLength(2);
98
+ expect(result.content[0].text).toContain('compact log output');
99
+ expect(result.content[1].text).toBe('');
100
+ });
101
+ it('should execute hs logs command with limit parameter', async () => {
102
+ mockAddFlag.mockReturnValue('hs logs my-endpoint --limit 10');
103
+ mockRunCommandInDir.mockResolvedValue({
104
+ stdout: 'limited log entries',
105
+ stderr: '',
106
+ });
107
+ const result = await tool.handler({
108
+ absoluteCurrentWorkingDirectory: '/test/dir',
109
+ endpoint: 'my-endpoint',
110
+ limit: 10,
111
+ });
112
+ expect(mockAddFlag).toHaveBeenCalledWith('hs logs my-endpoint', 'limit', 10);
113
+ expect(mockRunCommandInDir).toHaveBeenCalledWith('/test/dir', 'hs logs my-endpoint --limit 10');
114
+ expect(result.content).toHaveLength(2);
115
+ expect(result.content[0].text).toContain('limited log entries');
116
+ expect(result.content[1].text).toBe('');
117
+ });
118
+ it('should execute hs logs command with account parameter', async () => {
119
+ mockAddFlag.mockReturnValue('hs logs my-endpoint --account test-account');
120
+ mockRunCommandInDir.mockResolvedValue({
121
+ stdout: 'account-specific logs',
122
+ stderr: '',
123
+ });
124
+ const result = await tool.handler({
125
+ absoluteCurrentWorkingDirectory: '/test/dir',
126
+ endpoint: 'my-endpoint',
127
+ account: 'test-account',
128
+ });
129
+ expect(mockAddFlag).toHaveBeenCalledWith('hs logs my-endpoint', 'account', 'test-account');
130
+ expect(mockRunCommandInDir).toHaveBeenCalledWith('/test/dir', 'hs logs my-endpoint --account test-account');
131
+ expect(result.content).toHaveLength(2);
132
+ expect(result.content[0].text).toContain('account-specific logs');
133
+ expect(result.content[1].text).toBe('');
134
+ });
135
+ it('should execute hs logs command with multiple parameters', async () => {
136
+ mockAddFlag
137
+ .mockReturnValueOnce('hs logs my-endpoint --latest')
138
+ .mockReturnValueOnce('hs logs my-endpoint --latest --compact')
139
+ .mockReturnValueOnce('hs logs my-endpoint --latest --compact --account test-account');
140
+ mockRunCommandInDir.mockResolvedValue({
141
+ stdout: 'latest compact logs',
142
+ stderr: '',
143
+ });
144
+ const result = await tool.handler({
145
+ absoluteCurrentWorkingDirectory: '/test/dir',
146
+ endpoint: 'my-endpoint',
147
+ latest: true,
148
+ compact: true,
149
+ account: 'test-account',
150
+ });
151
+ expect(mockAddFlag).toHaveBeenCalledTimes(3);
152
+ expect(mockAddFlag).toHaveBeenNthCalledWith(1, 'hs logs my-endpoint', 'latest', true);
153
+ expect(mockAddFlag).toHaveBeenNthCalledWith(2, 'hs logs my-endpoint --latest', 'compact', true);
154
+ expect(mockAddFlag).toHaveBeenNthCalledWith(3, 'hs logs my-endpoint --latest --compact', 'account', 'test-account');
155
+ expect(mockRunCommandInDir).toHaveBeenCalledWith('/test/dir', 'hs logs my-endpoint --latest --compact --account test-account');
156
+ expect(result.content).toHaveLength(2);
157
+ expect(result.content[0].text).toContain('latest compact logs');
158
+ expect(result.content[1].text).toBe('');
159
+ });
160
+ it('should handle command execution errors', async () => {
161
+ mockRunCommandInDir.mockRejectedValue(new Error('Function not found'));
162
+ const result = await tool.handler({
163
+ absoluteCurrentWorkingDirectory: '/test/dir',
164
+ endpoint: 'non-existent-function',
165
+ });
166
+ expect(result.content).toHaveLength(1);
167
+ expect(result.content[0].text).toContain('Error executing hs logs command: Function not found');
168
+ });
169
+ it('should handle stderr output', async () => {
170
+ mockRunCommandInDir.mockResolvedValue({
171
+ stdout: 'function logs',
172
+ stderr: 'Warning: Function may be slow to respond',
173
+ });
174
+ const result = await tool.handler({
175
+ absoluteCurrentWorkingDirectory: '/test/dir',
176
+ endpoint: 'slow-function',
177
+ });
178
+ expect(result.content).toHaveLength(2);
179
+ expect(result.content[0].text).toContain('function logs');
180
+ expect(result.content[1].text).toContain('Warning: Function may be slow to respond');
181
+ });
182
+ });
183
+ });