@hubspot/cli 7.10.0 → 7.11.0-beta.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 (211) hide show
  1. package/bin/cli.js +5 -4
  2. package/commands/__tests__/getStarted.test.js +10 -0
  3. package/commands/__tests__/project.test.js +3 -0
  4. package/commands/account/__tests__/rename.test.js +10 -3
  5. package/commands/account/auth.js +10 -14
  6. package/commands/account/clean.js +11 -19
  7. package/commands/account/createOverride.js +15 -11
  8. package/commands/account/info.js +8 -5
  9. package/commands/account/list.js +15 -19
  10. package/commands/account/remove.js +23 -22
  11. package/commands/account/removeOverride.js +6 -6
  12. package/commands/account/rename.js +2 -2
  13. package/commands/account/use.js +19 -8
  14. package/commands/app/__tests__/migrate.test.js +8 -4
  15. package/commands/app/migrate.js +2 -2
  16. package/commands/auth.js +18 -14
  17. package/commands/config/migrate.js +5 -5
  18. package/commands/customObject/createSchema.js +2 -3
  19. package/commands/customObject/updateSchema.js +2 -3
  20. package/commands/getStarted.js +2 -3
  21. package/commands/hubdb/__tests__/list.test.js +1 -0
  22. package/commands/hubdb/list.js +2 -2
  23. package/commands/init.js +36 -32
  24. package/commands/project/__tests__/deploy.test.js +16 -11
  25. package/commands/project/__tests__/devUnifiedFlow.test.js +6 -4
  26. package/commands/project/__tests__/lint.test.js +709 -0
  27. package/commands/project/__tests__/logs.test.js +4 -0
  28. package/commands/project/__tests__/validate.test.js +2 -2
  29. package/commands/project/cloneApp.js +2 -2
  30. package/commands/project/create.js +20 -14
  31. package/commands/project/deploy.js +2 -2
  32. package/commands/project/dev/deprecatedFlow.js +4 -5
  33. package/commands/project/dev/index.js +6 -3
  34. package/commands/project/dev/unifiedFlow.js +11 -6
  35. package/commands/project/lint.d.ts +6 -0
  36. package/commands/project/lint.js +178 -0
  37. package/commands/project/logs.js +2 -3
  38. package/commands/project/migrate.js +4 -13
  39. package/commands/project/profile/add.js +6 -7
  40. package/commands/project/profile/delete.js +2 -2
  41. package/commands/project/upload.js +2 -2
  42. package/commands/project/validate.js +2 -2
  43. package/commands/project.js +2 -0
  44. package/commands/sandbox/__tests__/create.test.js +14 -5
  45. package/commands/sandbox/create.js +4 -5
  46. package/commands/sandbox/delete.js +23 -20
  47. package/commands/testAccount/create.js +2 -2
  48. package/commands/testAccount/delete.js +9 -8
  49. package/lang/en.d.ts +54 -12
  50. package/lang/en.js +64 -16
  51. package/lib/__tests__/buildAccount.test.js +22 -30
  52. package/lib/__tests__/commonOpts.test.js +9 -13
  53. package/lib/__tests__/developerTestAccounts.test.js +29 -17
  54. package/lib/__tests__/importData.test.js +20 -10
  55. package/lib/__tests__/oauth.test.js +19 -8
  56. package/lib/__tests__/sandboxSync.test.js +33 -11
  57. package/lib/__tests__/sandboxes.test.js +30 -19
  58. package/lib/__tests__/usageTracking.test.js +10 -10
  59. package/lib/__tests__/validation.test.js +32 -32
  60. package/lib/accountTypes.d.ts +9 -9
  61. package/lib/accountTypes.js +2 -4
  62. package/lib/app/__tests__/migrate.test.js +15 -0
  63. package/lib/app/__tests__/migrate_legacy.test.js +9 -0
  64. package/lib/app/migrate_legacy.d.ts +2 -2
  65. package/lib/buildAccount.d.ts +4 -4
  66. package/lib/buildAccount.js +7 -14
  67. package/lib/commonOpts.js +3 -3
  68. package/lib/configMigrate.d.ts +2 -2
  69. package/lib/configMigrate.js +42 -18
  70. package/lib/configOptions.js +3 -2
  71. package/lib/developerTestAccounts.d.ts +3 -3
  72. package/lib/developerTestAccounts.js +4 -7
  73. package/lib/doctor/DiagnosticInfoBuilder.d.ts +1 -1
  74. package/lib/doctor/DiagnosticInfoBuilder.js +9 -6
  75. package/lib/doctor/Doctor.js +4 -3
  76. package/lib/doctor/__tests__/Diagnosis.test.js +4 -3
  77. package/lib/doctor/__tests__/DiagnosticInfoBuilder.test.js +17 -9
  78. package/lib/doctor/__tests__/Doctor.test.js +14 -0
  79. package/lib/errorHandlers/index.js +10 -7
  80. package/lib/importData.js +8 -7
  81. package/lib/links.js +5 -5
  82. package/lib/middleware/{__test__ → __tests__}/commandTargetingUtils.test.js +3 -3
  83. package/lib/middleware/{__test__ → __tests__}/configMiddleware.test.js +23 -22
  84. package/lib/middleware/{__test__ → __tests__}/gitMiddleware.test.js +9 -7
  85. package/lib/middleware/autoUpdateMiddleware.js +34 -23
  86. package/lib/middleware/commandTargetingUtils.js +3 -2
  87. package/lib/middleware/configMiddleware.d.ts +6 -1
  88. package/lib/middleware/configMiddleware.js +36 -15
  89. package/lib/middleware/fireAlarmMiddleware.js +4 -15
  90. package/lib/middleware/gitMiddleware.js +8 -4
  91. package/lib/oauth.d.ts +2 -2
  92. package/lib/oauth.js +8 -10
  93. package/lib/projects/__tests__/AppDevModeInterface.test.js +17 -6
  94. package/lib/projects/__tests__/DevServerManager.test.js +1 -0
  95. package/lib/projects/__tests__/LocalDevProcess.test.js +1 -0
  96. package/lib/projects/__tests__/components.test.js +2 -22
  97. package/lib/projects/__tests__/deploy.test.js +16 -13
  98. package/lib/projects/__tests__/uieLinting.test.js +640 -0
  99. package/lib/projects/add/__tests__/legacyAddComponent.test.js +1 -1
  100. package/lib/projects/add/__tests__/v2AddComponent.test.js +30 -4
  101. package/lib/projects/add/legacyAddComponent.js +1 -1
  102. package/lib/projects/add/v2AddComponent.js +16 -5
  103. package/lib/projects/components.d.ts +8 -1
  104. package/lib/projects/components.js +91 -8
  105. package/lib/projects/create/__tests__/v2.test.js +11 -0
  106. package/lib/projects/deploy.js +21 -8
  107. package/lib/projects/localDev/AppDevModeInterface.js +2 -2
  108. package/lib/projects/localDev/DevServerManager_DEPRECATED.js +11 -3
  109. package/lib/projects/localDev/LocalDevLogger.js +4 -4
  110. package/lib/projects/localDev/LocalDevManager_DEPRECATED.js +3 -3
  111. package/lib/projects/localDev/helpers/account.d.ts +10 -10
  112. package/lib/projects/localDev/helpers/account.js +6 -11
  113. package/lib/projects/localDev/helpers/process.js +5 -3
  114. package/lib/projects/uieLinting.d.ts +33 -0
  115. package/lib/projects/uieLinting.js +222 -0
  116. package/lib/projects/urls.js +5 -6
  117. package/lib/prompts/__tests__/downloadProjectPrompt.test.js +7 -5
  118. package/lib/prompts/accountNamePrompt.js +3 -3
  119. package/lib/prompts/accountsPrompt.d.ts +1 -1
  120. package/lib/prompts/accountsPrompt.js +6 -7
  121. package/lib/prompts/confirmImportDataPrompt.js +2 -2
  122. package/lib/prompts/downloadProjectPrompt.d.ts +1 -0
  123. package/lib/prompts/downloadProjectPrompt.js +5 -2
  124. package/lib/prompts/importDataTestAccountSelectPrompt.js +4 -5
  125. package/lib/prompts/personalAccessKeyPrompt.js +2 -2
  126. package/lib/prompts/projectDevTargetAccountPrompt.d.ts +3 -3
  127. package/lib/prompts/projectDevTargetAccountPrompt.js +5 -7
  128. package/lib/prompts/sandboxesPrompt.js +7 -8
  129. package/lib/prompts/setAsDefaultAccountPrompt.js +7 -6
  130. package/lib/sandboxSync.d.ts +2 -2
  131. package/lib/sandboxSync.js +3 -9
  132. package/lib/sandboxes.d.ts +4 -4
  133. package/lib/sandboxes.js +6 -11
  134. package/lib/serverlessLogs.js +2 -2
  135. package/lib/theme/__tests__/migrate.test.js +15 -0
  136. package/lib/ui/SpinniesManager.d.ts +5 -7
  137. package/lib/ui/SpinniesManager.js +9 -12
  138. package/lib/ui/__tests__/SpinniesManager.test.d.ts +1 -0
  139. package/lib/ui/__tests__/SpinniesManager.test.js +489 -0
  140. package/lib/ui/index.js +6 -3
  141. package/lib/usageTracking.js +15 -8
  142. package/lib/validation.js +13 -11
  143. package/mcp-server/tools/cms/HsCreateFunctionTool.js +4 -2
  144. package/mcp-server/tools/cms/HsCreateModuleTool.js +4 -2
  145. package/mcp-server/tools/cms/HsCreateTemplateTool.js +4 -2
  146. package/mcp-server/tools/cms/HsFunctionLogsTool.js +4 -2
  147. package/mcp-server/tools/cms/HsListFunctionsTool.js +3 -1
  148. package/mcp-server/tools/cms/HsListTool.js +3 -1
  149. package/mcp-server/tools/cms/__tests__/HsCreateFunctionTool.test.js +1 -0
  150. package/mcp-server/tools/index.js +4 -0
  151. package/mcp-server/tools/project/AddFeatureToProjectTool.js +4 -2
  152. package/mcp-server/tools/project/CreateProjectTool.js +4 -2
  153. package/mcp-server/tools/project/CreateTestAccountTool.js +17 -7
  154. package/mcp-server/tools/project/DeployProjectTool.js +3 -1
  155. package/mcp-server/tools/project/DocFetchTool.js +6 -4
  156. package/mcp-server/tools/project/DocsSearchTool.d.ts +1 -1
  157. package/mcp-server/tools/project/DocsSearchTool.js +10 -8
  158. package/mcp-server/tools/project/GetApiUsagePatternsByAppIdTool.d.ts +1 -1
  159. package/mcp-server/tools/project/GetApiUsagePatternsByAppIdTool.js +9 -7
  160. package/mcp-server/tools/project/GetApplicationInfoTool.js +8 -6
  161. package/mcp-server/tools/project/GetBuildLogsTool.d.ts +26 -0
  162. package/mcp-server/tools/project/GetBuildLogsTool.js +125 -0
  163. package/mcp-server/tools/project/GetBuildStatusTool.d.ts +26 -0
  164. package/mcp-server/tools/project/GetBuildStatusTool.js +166 -0
  165. package/mcp-server/tools/project/GetConfigValuesTool.d.ts +1 -1
  166. package/mcp-server/tools/project/GetConfigValuesTool.js +9 -7
  167. package/mcp-server/tools/project/GuidedWalkthroughTool.d.ts +1 -1
  168. package/mcp-server/tools/project/GuidedWalkthroughTool.js +5 -3
  169. package/mcp-server/tools/project/UploadProjectTools.js +3 -1
  170. package/mcp-server/tools/project/ValidateProjectTool.js +4 -2
  171. package/mcp-server/tools/project/__tests__/CreateTestAccountTool.test.js +12 -2
  172. package/mcp-server/tools/project/__tests__/DocFetchTool.test.js +5 -1
  173. package/mcp-server/tools/project/__tests__/DocsSearchTool.test.js +23 -11
  174. package/mcp-server/tools/project/__tests__/GetApiUsagePatternsByAppIdTool.test.js +7 -5
  175. package/mcp-server/tools/project/__tests__/GetApplicationInfoTool.test.js +7 -5
  176. package/mcp-server/tools/project/__tests__/GetBuildLogsTool.test.d.ts +1 -0
  177. package/mcp-server/tools/project/__tests__/GetBuildLogsTool.test.js +305 -0
  178. package/mcp-server/tools/project/__tests__/GetBuildStatusTool.test.d.ts +1 -0
  179. package/mcp-server/tools/project/__tests__/GetBuildStatusTool.test.js +240 -0
  180. package/mcp-server/tools/project/__tests__/GetConfigValuesTool.test.js +8 -6
  181. package/mcp-server/utils/__tests__/content.test.js +21 -20
  182. package/mcp-server/utils/__tests__/feedbackTracking.test.js +34 -28
  183. package/mcp-server/utils/config.d.ts +1 -0
  184. package/mcp-server/utils/config.js +10 -0
  185. package/mcp-server/utils/content.d.ts +1 -1
  186. package/mcp-server/utils/content.js +2 -2
  187. package/mcp-server/utils/feedbackTracking.d.ts +1 -1
  188. package/mcp-server/utils/feedbackTracking.js +3 -3
  189. package/mcp-server/utils/toolUsageTracking.js +4 -3
  190. package/package.json +9 -9
  191. package/ui/components/BoxWithTitle.d.ts +2 -1
  192. package/ui/components/BoxWithTitle.js +2 -2
  193. package/ui/components/StatusMessageBoxes.d.ts +5 -4
  194. package/ui/components/StatusMessageBoxes.js +8 -8
  195. package/lib/middleware/__test__/notificationsMiddleware.test.js +0 -8
  196. package/lib/middleware/notificationsMiddleware.d.ts +0 -1
  197. package/lib/middleware/notificationsMiddleware.js +0 -28
  198. package/lib/ui/boxen.d.ts +0 -5
  199. package/lib/ui/boxen.js +0 -26
  200. package/mcp-server/utils/__tests__/cliConfig.test.js +0 -110
  201. package/mcp-server/utils/cliConfig.d.ts +0 -1
  202. package/mcp-server/utils/cliConfig.js +0 -12
  203. /package/{lib/middleware/__test__/commandTargetingUtils.test.d.ts → commands/project/__tests__/lint.test.d.ts} +0 -0
  204. /package/lib/middleware/{__test__/configMiddleware.test.d.ts → __tests__/commandTargetingUtils.test.d.ts} +0 -0
  205. /package/lib/middleware/{__test__/gitMiddleware.test.d.ts → __tests__/configMiddleware.test.d.ts} +0 -0
  206. /package/lib/middleware/{__test__/notificationsMiddleware.test.d.ts → __tests__/gitMiddleware.test.d.ts} +0 -0
  207. /package/lib/middleware/{__test__ → __tests__}/requestMiddleware.test.d.ts +0 -0
  208. /package/lib/middleware/{__test__ → __tests__}/requestMiddleware.test.js +0 -0
  209. /package/lib/middleware/{__test__ → __tests__}/yargsChecksMiddleware.test.d.ts +0 -0
  210. /package/lib/middleware/{__test__ → __tests__}/yargsChecksMiddleware.test.js +0 -0
  211. /package/{mcp-server/utils/__tests__/cliConfig.test.d.ts → lib/projects/__tests__/uieLinting.test.d.ts} +0 -0
@@ -1,6 +1,6 @@
1
1
  import { GetApiUsagePatternsByAppIdTool } from '../GetApiUsagePatternsByAppIdTool.js';
2
2
  import { z } from 'zod';
3
- import { getAccountId } from '@hubspot/local-dev-lib/config';
3
+ import { getConfigDefaultAccountIfExists } from '@hubspot/local-dev-lib/config';
4
4
  import { http } from '@hubspot/local-dev-lib/http';
5
5
  import { isHubSpotHttpError } from '@hubspot/local-dev-lib/errors/index';
6
6
  import { mcpFeedbackRequest } from '../../../utils/feedbackTracking.js';
@@ -11,7 +11,7 @@ vi.mock('@hubspot/local-dev-lib/errors/index');
11
11
  vi.mock('@hubspot/local-dev-lib/config');
12
12
  vi.mock('../../../utils/feedbackTracking');
13
13
  const mockMcpFeedbackRequest = mcpFeedbackRequest;
14
- const mockGetAccountId = getAccountId;
14
+ const mockGetConfigDefaultAccountIfExists = getConfigDefaultAccountIfExists;
15
15
  const mockHttp = http;
16
16
  const mockIsHubSpotHttpError = isHubSpotHttpError;
17
17
  describe('mcp-server/tools/project/GetApiUsagePatternsByAppIdTool', () => {
@@ -89,7 +89,9 @@ describe('mcp-server/tools/project/GetApiUsagePatternsByAppIdTool', () => {
89
89
  endDate: '2025-12-31',
90
90
  };
91
91
  beforeEach(() => {
92
- mockGetAccountId.mockReturnValue(123456789);
92
+ mockGetConfigDefaultAccountIfExists.mockReturnValue({
93
+ accountId: 123456789,
94
+ });
93
95
  mockIsHubSpotHttpError.mockReturnValue(false);
94
96
  });
95
97
  it('should return API usage patterns successfully', async () => {
@@ -118,7 +120,7 @@ describe('mcp-server/tools/project/GetApiUsagePatternsByAppIdTool', () => {
118
120
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
119
121
  mockHttp.get.mockResolvedValue(mockResponse);
120
122
  const result = await tool.handler(input);
121
- expect(mockGetAccountId).toHaveBeenCalledWith();
123
+ expect(mockGetConfigDefaultAccountIfExists).toHaveBeenCalledWith();
122
124
  expect(mockHttp.get).toHaveBeenCalledWith(123456789, {
123
125
  url: 'app/feature/utilization/public/v3/insights/app/12345/usage-patterns',
124
126
  params: {
@@ -136,7 +138,7 @@ describe('mcp-server/tools/project/GetApiUsagePatternsByAppIdTool', () => {
136
138
  });
137
139
  });
138
140
  it('should return error when account ID cannot be determined', async () => {
139
- mockGetAccountId.mockReturnValue(null);
141
+ mockGetConfigDefaultAccountIfExists.mockReturnValue(undefined);
140
142
  const result = await tool.handler(input);
141
143
  expect(result).toEqual({
142
144
  content: [
@@ -1,5 +1,5 @@
1
1
  import { GetApplicationInfoTool } from '../GetApplicationInfoTool.js';
2
- import { getAccountId } from '@hubspot/local-dev-lib/config';
2
+ import { getConfigDefaultAccountIfExists } from '@hubspot/local-dev-lib/config';
3
3
  import { http } from '@hubspot/local-dev-lib/http';
4
4
  import { isHubSpotHttpError } from '@hubspot/local-dev-lib/errors/index';
5
5
  import { mcpFeedbackRequest } from '../../../utils/feedbackTracking.js';
@@ -10,7 +10,7 @@ vi.mock('@hubspot/local-dev-lib/errors/index');
10
10
  vi.mock('@hubspot/local-dev-lib/config');
11
11
  vi.mock('../../../utils/feedbackTracking');
12
12
  const mockMcpFeedbackRequest = mcpFeedbackRequest;
13
- const mockGetAccountId = getAccountId;
13
+ const mockGetConfigDefaultAccountIfExists = getConfigDefaultAccountIfExists;
14
14
  const mockHttp = http;
15
15
  const mockIsHubSpotHttpError = isHubSpotHttpError;
16
16
  describe('mcp-server/tools/project/GetApplicationInfoTool', () => {
@@ -42,7 +42,9 @@ describe('mcp-server/tools/project/GetApplicationInfoTool', () => {
42
42
  describe('handler', () => {
43
43
  const input = { absoluteCurrentWorkingDirectory: '/test/dir' };
44
44
  beforeEach(() => {
45
- mockGetAccountId.mockReturnValue(123456789);
45
+ mockGetConfigDefaultAccountIfExists.mockReturnValue({
46
+ accountId: 123456789,
47
+ });
46
48
  mockIsHubSpotHttpError.mockReturnValue(false);
47
49
  });
48
50
  it('should return application information successfully', async () => {
@@ -67,7 +69,7 @@ describe('mcp-server/tools/project/GetApplicationInfoTool', () => {
67
69
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
70
  mockHttp.get.mockResolvedValue(mockResponse);
69
71
  const result = await tool.handler(input);
70
- expect(mockGetAccountId).toHaveBeenCalledWith();
72
+ expect(mockGetConfigDefaultAccountIfExists).toHaveBeenCalledWith();
71
73
  expect(mockHttp.get).toHaveBeenCalledWith(123456789, {
72
74
  url: 'app/feature/utilization/public/v3/insights/apps',
73
75
  });
@@ -81,7 +83,7 @@ describe('mcp-server/tools/project/GetApplicationInfoTool', () => {
81
83
  });
82
84
  });
83
85
  it('should return error when account ID cannot be determined', async () => {
84
- mockGetAccountId.mockReturnValue(null);
86
+ mockGetConfigDefaultAccountIfExists.mockReturnValue(undefined);
85
87
  const result = await tool.handler(input);
86
88
  expect(result).toEqual({
87
89
  content: [
@@ -0,0 +1,305 @@
1
+ import { GetBuildLogsTool } from '../GetBuildLogsTool.js';
2
+ import { http } from '@hubspot/local-dev-lib/http';
3
+ import { isHubSpotHttpError } from '@hubspot/local-dev-lib/errors/index';
4
+ import { getProjectConfig, validateProjectConfig, } from '../../../../lib/projects/config.js';
5
+ import { mcpFeedbackRequest } from '../../../utils/feedbackTracking.js';
6
+ import { getConfigDefaultAccountIfExists } from '@hubspot/local-dev-lib/config';
7
+ vi.mock('@modelcontextprotocol/sdk/server/mcp.js');
8
+ vi.mock('../../../utils/toolUsageTracking');
9
+ vi.mock('../../../utils/cliConfig');
10
+ vi.mock('@hubspot/local-dev-lib/http');
11
+ vi.mock('@hubspot/local-dev-lib/errors/index');
12
+ vi.mock('../../../../lib/projects/config.js');
13
+ vi.mock('../../../utils/feedbackTracking');
14
+ vi.mock('@hubspot/local-dev-lib/config');
15
+ const mockMcpFeedbackRequest = mcpFeedbackRequest;
16
+ const mockGetConfigDefaultAccountIfExists = getConfigDefaultAccountIfExists;
17
+ const mockHttpGet = http.get;
18
+ const mockIsHubSpotHttpError = isHubSpotHttpError;
19
+ const mockGetProjectConfig = getProjectConfig;
20
+ const mockValidateProjectConfig = validateProjectConfig;
21
+ const TEST_ACCOUNT_ID = 123456789;
22
+ const TEST_PROJECT_NAME = 'test-project';
23
+ const TEST_PROJECT_PATH = '/test/project';
24
+ const TEST_WORKING_DIR = '/test';
25
+ const TEST_BUILD_ID = 123;
26
+ const TEST_PLATFORM_VERSION = '2025.2';
27
+ function createMockLog(overrides = {}) {
28
+ return {
29
+ lineNumber: 1,
30
+ logLevel: 'INFO',
31
+ message: 'Starting build validation',
32
+ pipelineStepId: 1,
33
+ pipelineSubstepId: 'test-step',
34
+ pipelineSubstepName: 'test-component',
35
+ timestamp: Date.now(),
36
+ ...overrides,
37
+ };
38
+ }
39
+ function createMockLogs() {
40
+ return {
41
+ pipelineStage: 'BUILD',
42
+ pipelineStepId: 2,
43
+ projectName: TEST_PROJECT_NAME,
44
+ logs: [
45
+ {
46
+ pipelineStepId: 2,
47
+ pipelineSubstepId: 'test-app-id',
48
+ pipelineStage: 'BUILD',
49
+ projectName: TEST_PROJECT_NAME,
50
+ logs: [
51
+ createMockLog({
52
+ lineNumber: 1,
53
+ logLevel: 'INFO',
54
+ message: "Starting build validation for app 'Test App'",
55
+ pipelineSubstepName: 'test-app',
56
+ pipelineSubstepId: 'test-app-id',
57
+ }),
58
+ createMockLog({
59
+ lineNumber: 2,
60
+ logLevel: 'INFO',
61
+ message: "Successfully validated app configuration for 'Test App'",
62
+ pipelineSubstepName: 'test-app',
63
+ pipelineSubstepId: 'test-app-id',
64
+ }),
65
+ ],
66
+ },
67
+ {
68
+ pipelineStepId: 2,
69
+ pipelineSubstepId: 'test-card-id',
70
+ pipelineStage: 'BUILD',
71
+ projectName: TEST_PROJECT_NAME,
72
+ logs: [
73
+ createMockLog({
74
+ lineNumber: 1,
75
+ logLevel: 'INFO',
76
+ message: 'Starting card build...',
77
+ pipelineSubstepName: 'test-card',
78
+ pipelineSubstepId: 'test-card-id',
79
+ }),
80
+ createMockLog({
81
+ lineNumber: 2,
82
+ logLevel: 'INFO',
83
+ message: 'Validating card configuration...',
84
+ pipelineSubstepName: 'test-card',
85
+ pipelineSubstepId: 'test-card-id',
86
+ }),
87
+ createMockLog({
88
+ lineNumber: 3,
89
+ logLevel: 'ERROR',
90
+ message: 'Failed to build card. The preview image file /app/cards/assets/preview.png was not found. Make sure the file exists in /app/cards and try again.',
91
+ pipelineSubstepName: 'test-card',
92
+ pipelineSubstepId: 'test-card-id',
93
+ }),
94
+ ],
95
+ },
96
+ {
97
+ pipelineStepId: 2,
98
+ pipelineSubstepId: 'test-webhook-id',
99
+ pipelineStage: 'BUILD',
100
+ projectName: TEST_PROJECT_NAME,
101
+ logs: [
102
+ createMockLog({
103
+ lineNumber: 1,
104
+ logLevel: 'WARN',
105
+ message: 'Deprecated API usage detected in webhook configuration',
106
+ pipelineSubstepName: 'test-webhook',
107
+ pipelineSubstepId: 'test-webhook-id',
108
+ }),
109
+ ],
110
+ },
111
+ ],
112
+ };
113
+ }
114
+ function createLogsResponse(data) {
115
+ return {
116
+ data,
117
+ };
118
+ }
119
+ function createMockProjectConfig(overrides = {}) {
120
+ return {
121
+ name: TEST_PROJECT_NAME,
122
+ srcDir: 'src',
123
+ platformVersion: TEST_PLATFORM_VERSION,
124
+ ...overrides,
125
+ };
126
+ }
127
+ function expectTextContent(result, ...expectedStrings) {
128
+ expectedStrings.forEach(str => {
129
+ expect(result.content[1].text).toContain(str);
130
+ });
131
+ }
132
+ describe('mcp-server/tools/project/GetBuildLogsTool', () => {
133
+ let mockMcpServer;
134
+ let tool;
135
+ let mockRegisteredTool;
136
+ beforeEach(() => {
137
+ vi.clearAllMocks();
138
+ // @ts-expect-error Not mocking the whole thing
139
+ mockMcpServer = {
140
+ registerTool: vi.fn(),
141
+ };
142
+ mockRegisteredTool = {};
143
+ mockMcpServer.registerTool.mockReturnValue(mockRegisteredTool);
144
+ mockMcpFeedbackRequest.mockResolvedValue('');
145
+ tool = new GetBuildLogsTool(mockMcpServer);
146
+ // Default mock implementations
147
+ mockGetConfigDefaultAccountIfExists.mockReturnValue({
148
+ accountId: TEST_ACCOUNT_ID,
149
+ });
150
+ mockIsHubSpotHttpError.mockReturnValue(false);
151
+ mockGetProjectConfig.mockResolvedValue({
152
+ projectConfig: createMockProjectConfig(),
153
+ projectDir: TEST_PROJECT_PATH,
154
+ });
155
+ mockValidateProjectConfig.mockImplementation(() => { });
156
+ });
157
+ describe('register', () => {
158
+ it('should register tool with correct parameters', () => {
159
+ const result = tool.register();
160
+ expect(mockMcpServer.registerTool).toHaveBeenCalledWith('get-build-logs', expect.objectContaining({
161
+ title: 'Get HubSpot Project Build Logs',
162
+ description: expect.stringContaining('Retrieves build logs for a specific HubSpot project build'),
163
+ inputSchema: expect.anything(),
164
+ }), expect.any(Function));
165
+ expect(result).toBe(mockRegisteredTool);
166
+ });
167
+ });
168
+ describe('handler', () => {
169
+ const baseInput = {
170
+ absoluteProjectPath: TEST_PROJECT_PATH,
171
+ absoluteCurrentWorkingDirectory: TEST_WORKING_DIR,
172
+ buildId: TEST_BUILD_ID,
173
+ logLevel: 'ALL',
174
+ };
175
+ describe('error handling', () => {
176
+ it('should return error when account ID cannot be determined', async () => {
177
+ mockGetConfigDefaultAccountIfExists.mockReturnValue(undefined);
178
+ const result = await tool.handler(baseInput);
179
+ expect(result).toEqual({
180
+ content: [
181
+ {
182
+ type: 'text',
183
+ text: TEST_WORKING_DIR,
184
+ },
185
+ {
186
+ type: 'text',
187
+ text: 'No account ID found. Please run `hs account auth` to configure an account, or set a default account with `hs account use <account>`',
188
+ },
189
+ ],
190
+ });
191
+ expect(mockHttpGet).not.toHaveBeenCalled();
192
+ });
193
+ it('should handle HubSpot HTTP errors', async () => {
194
+ const error = new Error('API Error');
195
+ mockIsHubSpotHttpError.mockReturnValue(true);
196
+ mockHttpGet.mockRejectedValue(error);
197
+ const result = await tool.handler(baseInput);
198
+ expectTextContent(result, 'API Error');
199
+ });
200
+ it('should handle generic errors', async () => {
201
+ const error = new Error('Generic error');
202
+ mockIsHubSpotHttpError.mockReturnValue(false);
203
+ mockHttpGet.mockRejectedValue(error);
204
+ const result = await tool.handler(baseInput);
205
+ expectTextContent(result, 'Generic error');
206
+ });
207
+ it('should handle empty logs', async () => {
208
+ const emptyLogsResponse = {
209
+ pipelineStage: 'BUILD',
210
+ pipelineStepId: 2,
211
+ projectName: TEST_PROJECT_NAME,
212
+ logs: [],
213
+ };
214
+ mockHttpGet.mockResolvedValue(
215
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
216
+ createLogsResponse(emptyLogsResponse));
217
+ const result = await tool.handler(baseInput);
218
+ expectTextContent(result, `No logs found for build #${TEST_BUILD_ID}`, TEST_PROJECT_NAME);
219
+ });
220
+ });
221
+ describe('log fetching', () => {
222
+ it('should fetch and display all logs', async () => {
223
+ const mockLogs = createMockLogs();
224
+ mockHttpGet.mockResolvedValue(
225
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
226
+ createLogsResponse(mockLogs));
227
+ const result = await tool.handler(baseInput);
228
+ expect(mockGetProjectConfig).toHaveBeenCalledWith(TEST_PROJECT_PATH);
229
+ expect(mockHttpGet).toHaveBeenCalledWith(TEST_ACCOUNT_ID, {
230
+ url: `dfs/logging/v1/logs/projects/${TEST_PROJECT_NAME}/builds/${TEST_BUILD_ID}`,
231
+ });
232
+ expectTextContent(result, `Logs for build #${TEST_BUILD_ID}`, TEST_PROJECT_NAME, 'ALL level', 'Starting build validation', 'Successfully validated', 'Failed to build card', 'Deprecated API usage');
233
+ });
234
+ it('should filter logs by ERROR level', async () => {
235
+ const mockLogs = createMockLogs();
236
+ mockHttpGet.mockResolvedValue(
237
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
238
+ createLogsResponse(mockLogs));
239
+ const result = await tool.handler({
240
+ ...baseInput,
241
+ logLevel: 'ERROR',
242
+ });
243
+ expectTextContent(result, 'ERROR level', 'Failed to build card', 'preview.png was not found');
244
+ expect(result.content[1].text).not.toContain('Starting build');
245
+ expect(result.content[1].text).not.toContain('Deprecated API');
246
+ });
247
+ it('should filter logs by WARN level', async () => {
248
+ const mockLogs = createMockLogs();
249
+ mockHttpGet.mockResolvedValue(
250
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
251
+ createLogsResponse(mockLogs));
252
+ const result = await tool.handler({
253
+ ...baseInput,
254
+ logLevel: 'WARN',
255
+ });
256
+ expectTextContent(result, 'WARN level', 'Deprecated API usage detected');
257
+ expect(result.content[1].text).not.toContain('Starting build');
258
+ expect(result.content[1].text).not.toContain('Failed to build card');
259
+ });
260
+ it('should filter logs by INFO level', async () => {
261
+ const mockLogs = createMockLogs();
262
+ mockHttpGet.mockResolvedValue(
263
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
264
+ createLogsResponse(mockLogs));
265
+ const result = await tool.handler({
266
+ ...baseInput,
267
+ logLevel: 'INFO',
268
+ });
269
+ expectTextContent(result, 'INFO level', 'Starting build validation', 'Successfully validated');
270
+ expect(result.content[1].text).not.toContain('Failed to build card');
271
+ expect(result.content[1].text).not.toContain('Deprecated API');
272
+ });
273
+ it('should show all logs when no logs match filter', async () => {
274
+ const infoOnlyResponse = {
275
+ pipelineStage: 'BUILD',
276
+ pipelineStepId: 2,
277
+ projectName: TEST_PROJECT_NAME,
278
+ logs: [
279
+ {
280
+ pipelineStepId: 2,
281
+ pipelineSubstepId: 'info-only-id',
282
+ pipelineStage: 'BUILD',
283
+ projectName: TEST_PROJECT_NAME,
284
+ logs: [
285
+ createMockLog({
286
+ logLevel: 'INFO',
287
+ message: 'Info message only',
288
+ pipelineSubstepId: 'info-only-id',
289
+ }),
290
+ ],
291
+ },
292
+ ],
293
+ };
294
+ mockHttpGet.mockResolvedValue(
295
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
296
+ createLogsResponse(infoOnlyResponse));
297
+ const result = await tool.handler({
298
+ ...baseInput,
299
+ logLevel: 'ERROR',
300
+ });
301
+ expectTextContent(result, `No ERROR level logs found`, `build #${TEST_BUILD_ID}`, 'Showing all logs instead', 'Info message only');
302
+ });
303
+ });
304
+ });
305
+ });
@@ -0,0 +1,240 @@
1
+ import { GetBuildStatusTool } from '../GetBuildStatusTool.js';
2
+ import { fetchProjectBuilds, getBuildStatus, } from '@hubspot/local-dev-lib/api/projects';
3
+ import { isHubSpotHttpError } from '@hubspot/local-dev-lib/errors/index';
4
+ import { getProjectConfig, validateProjectConfig, } from '../../../../lib/projects/config.js';
5
+ import { mcpFeedbackRequest } from '../../../utils/feedbackTracking.js';
6
+ import { getConfigDefaultAccountIfExists } from '@hubspot/local-dev-lib/config';
7
+ vi.mock('@modelcontextprotocol/sdk/server/mcp.js');
8
+ vi.mock('../../../utils/toolUsageTracking');
9
+ vi.mock('@hubspot/local-dev-lib/api/projects');
10
+ vi.mock('@hubspot/local-dev-lib/errors/index');
11
+ vi.mock('../../../../lib/projects/config.js');
12
+ vi.mock('../../../utils/feedbackTracking');
13
+ vi.mock('@hubspot/local-dev-lib/config');
14
+ const mockMcpFeedbackRequest = mcpFeedbackRequest;
15
+ const mockFetchProjectBuilds = fetchProjectBuilds;
16
+ const mockGetBuildStatus = getBuildStatus;
17
+ const mockIsHubSpotHttpError = isHubSpotHttpError;
18
+ const mockGetProjectConfig = getProjectConfig;
19
+ const mockValidateProjectConfig = validateProjectConfig;
20
+ const mockGetConfigDefaultAccountIfExists = getConfigDefaultAccountIfExists;
21
+ const TEST_ACCOUNT_ID = 123456789;
22
+ const TEST_PROJECT_NAME = 'test-project';
23
+ const TEST_PROJECT_PATH = '/test/project';
24
+ const TEST_WORKING_DIR = '/test';
25
+ const TEST_PLATFORM_VERSION = '2025.2';
26
+ function createMockBuild(overrides = {}) {
27
+ return {
28
+ buildId: 10,
29
+ status: 'FAILURE',
30
+ createdAt: '2025-11-18T21:50:50.632Z',
31
+ enqueuedAt: null,
32
+ finishedAt: '2025-11-20T22:32:07.008Z',
33
+ startedAt: '2025-11-18T21:50:50.632Z',
34
+ subbuildStatuses: [
35
+ {
36
+ buildName: 'my-card',
37
+ buildType: 'CARD',
38
+ status: 'FAILURE',
39
+ errorMessage: 'There were errors building this component:\n - The preview image file /app/cards/assets/preview.png was not found. Make sure the file exists in /app/cards and try again.',
40
+ },
41
+ {
42
+ buildName: 'my-app',
43
+ buildType: 'APPLICATION',
44
+ status: 'SUCCESS',
45
+ errorMessage: '',
46
+ },
47
+ ],
48
+ buildErrorMessage: 'The source code for this project is too large. HubSpot projects have a maximum size limit of 50.0 MB.',
49
+ platformVersion: TEST_PLATFORM_VERSION,
50
+ deployable: true,
51
+ deployableState: 'DEPLOYABLE',
52
+ ...overrides,
53
+ };
54
+ }
55
+ function createMockProjectConfig(overrides = {}) {
56
+ return {
57
+ name: TEST_PROJECT_NAME,
58
+ srcDir: 'src',
59
+ platformVersion: TEST_PLATFORM_VERSION,
60
+ ...overrides,
61
+ };
62
+ }
63
+ function createBuildListResponse(builds) {
64
+ return {
65
+ data: {
66
+ results: builds,
67
+ paging: undefined,
68
+ },
69
+ };
70
+ }
71
+ function createBuildDetailsResponse(build) {
72
+ return {
73
+ data: build,
74
+ };
75
+ }
76
+ function expectTextContent(result, ...expectedStrings) {
77
+ expectedStrings.forEach(str => {
78
+ expect(result.content[1].text).toContain(str);
79
+ });
80
+ }
81
+ describe('mcp-server/tools/project/GetBuildStatusTool', () => {
82
+ let mockMcpServer;
83
+ let tool;
84
+ let mockRegisteredTool;
85
+ beforeEach(() => {
86
+ vi.clearAllMocks();
87
+ // @ts-expect-error Not mocking the whole thing
88
+ mockMcpServer = {
89
+ registerTool: vi.fn(),
90
+ };
91
+ mockRegisteredTool = {};
92
+ mockMcpServer.registerTool.mockReturnValue(mockRegisteredTool);
93
+ mockMcpFeedbackRequest.mockResolvedValue('');
94
+ tool = new GetBuildStatusTool(mockMcpServer);
95
+ // Default mock implementations
96
+ mockIsHubSpotHttpError.mockReturnValue(false);
97
+ mockGetProjectConfig.mockResolvedValue({
98
+ projectConfig: createMockProjectConfig(),
99
+ projectDir: TEST_PROJECT_PATH,
100
+ });
101
+ mockValidateProjectConfig.mockImplementation(() => { });
102
+ mockGetConfigDefaultAccountIfExists.mockReturnValue({
103
+ accountId: TEST_ACCOUNT_ID,
104
+ });
105
+ });
106
+ describe('register', () => {
107
+ it('should register tool with correct parameters', () => {
108
+ const result = tool.register();
109
+ expect(mockMcpServer.registerTool).toHaveBeenCalledWith('get-build-status', expect.objectContaining({
110
+ title: 'Get HubSpot Projects Build Status and Errors',
111
+ description: expect.stringContaining('Retrieves build status and error messages for HubSpot projects'),
112
+ inputSchema: expect.any(Object),
113
+ }), expect.any(Function));
114
+ expect(result).toBe(mockRegisteredTool);
115
+ });
116
+ });
117
+ describe('handler', () => {
118
+ const baseInput = {
119
+ absoluteProjectPath: TEST_PROJECT_PATH,
120
+ absoluteCurrentWorkingDirectory: TEST_WORKING_DIR,
121
+ buildId: undefined,
122
+ limit: 5,
123
+ };
124
+ describe('error handling', () => {
125
+ it('should return error when account ID cannot be determined', async () => {
126
+ mockGetConfigDefaultAccountIfExists.mockReturnValue(undefined);
127
+ const result = await tool.handler(baseInput);
128
+ expect(result).toEqual({
129
+ content: [
130
+ {
131
+ type: 'text',
132
+ text: TEST_WORKING_DIR,
133
+ },
134
+ {
135
+ type: 'text',
136
+ text: 'No account ID found. Please run `hs account auth` to configure an account, or set a default account with `hs account use <account>`',
137
+ },
138
+ ],
139
+ });
140
+ expect(mockFetchProjectBuilds).not.toHaveBeenCalled();
141
+ });
142
+ it('should return error when specific build for provided buildId is not found', async () => {
143
+ const error = new Error('Build not found');
144
+ // @ts-expect-error Adding status property
145
+ error.status = 404;
146
+ mockIsHubSpotHttpError.mockReturnValue(true);
147
+ mockGetBuildStatus.mockRejectedValue(error);
148
+ const result = await tool.handler({ ...baseInput, buildId: 999 });
149
+ expectTextContent(result, 'Build not found');
150
+ });
151
+ it('should handle HubSpot HTTP errors', async () => {
152
+ const error = new Error('API Error');
153
+ mockIsHubSpotHttpError.mockReturnValue(true);
154
+ mockFetchProjectBuilds.mockRejectedValue(error);
155
+ const result = await tool.handler(baseInput);
156
+ expectTextContent(result, 'API Error');
157
+ });
158
+ it('should handle generic errors', async () => {
159
+ const error = new Error('Generic error');
160
+ mockIsHubSpotHttpError.mockReturnValue(false);
161
+ mockFetchProjectBuilds.mockRejectedValue(error);
162
+ const result = await tool.handler(baseInput);
163
+ expectTextContent(result, 'Generic error');
164
+ });
165
+ });
166
+ describe('list view (no buildId)', () => {
167
+ it('should return recent builds when no buildId is provided', async () => {
168
+ const mockBuild = createMockBuild();
169
+ mockFetchProjectBuilds.mockResolvedValue(
170
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
171
+ createBuildListResponse([mockBuild]));
172
+ const result = await tool.handler(baseInput);
173
+ expect(mockGetProjectConfig).toHaveBeenCalledWith(TEST_PROJECT_PATH);
174
+ expect(mockFetchProjectBuilds).toHaveBeenCalledWith(TEST_ACCOUNT_ID, TEST_PROJECT_NAME, { limit: 5 });
175
+ expectTextContent(result, `Recent builds for '${TEST_PROJECT_NAME}':`, 'Build #10 - FAILURE', 'The source code for this project is too large');
176
+ });
177
+ it('should return error when no builds exist', async () => {
178
+ mockFetchProjectBuilds.mockResolvedValue(
179
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
180
+ createBuildListResponse([]));
181
+ const result = await tool.handler(baseInput);
182
+ expectTextContent(result, `No builds found for project '${TEST_PROJECT_NAME}'`);
183
+ });
184
+ it('should handle successful builds', async () => {
185
+ const successBuild = createMockBuild({
186
+ buildId: 11,
187
+ status: 'SUCCESS',
188
+ buildErrorMessage: undefined,
189
+ subbuildStatuses: [
190
+ {
191
+ buildName: 'my-app',
192
+ buildType: 'APPLICATION',
193
+ status: 'SUCCESS',
194
+ errorMessage: '',
195
+ },
196
+ ],
197
+ });
198
+ mockFetchProjectBuilds.mockResolvedValue(
199
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
200
+ createBuildListResponse([successBuild]));
201
+ const result = await tool.handler(baseInput);
202
+ expectTextContent(result, 'Build #11 - SUCCESS ✓');
203
+ expect(result.content[1].text).not.toContain('Error:');
204
+ });
205
+ it('should display all subbuilds (success and failure)', async () => {
206
+ const buildWithSubbuilds = createMockBuild({
207
+ subbuildStatuses: [
208
+ {
209
+ buildName: 'my-webhooks',
210
+ buildType: 'WEBHOOKS',
211
+ status: 'SUCCESS',
212
+ },
213
+ {
214
+ buildName: 'my-app',
215
+ buildType: 'APPLICATION',
216
+ status: 'FAILURE',
217
+ errorMessage: 'Duplicate UID',
218
+ },
219
+ ],
220
+ });
221
+ mockFetchProjectBuilds.mockResolvedValue(
222
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
223
+ createBuildListResponse([buildWithSubbuilds]));
224
+ const result = await tool.handler(baseInput);
225
+ expectTextContent(result, 'Subbuilds:', '✓ my-webhooks (WEBHOOKS): SUCCESS', '⚠️ my-app (APPLICATION): FAILURE', 'Error: Duplicate UID');
226
+ });
227
+ });
228
+ describe('detail view (with buildId)', () => {
229
+ it('should return specific build details when buildId is provided', async () => {
230
+ const mockBuild = createMockBuild();
231
+ mockGetBuildStatus.mockResolvedValue(
232
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
233
+ createBuildDetailsResponse(mockBuild));
234
+ const result = await tool.handler({ ...baseInput, buildId: 10 });
235
+ expect(mockGetBuildStatus).toHaveBeenCalledWith(TEST_ACCOUNT_ID, TEST_PROJECT_NAME, 10);
236
+ expectTextContent(result, 'Build #10 Details', 'Status: FAILURE', `Platform Version: ${TEST_PLATFORM_VERSION}`, 'Build Error:');
237
+ });
238
+ });
239
+ });
240
+ });