@mintlify/cli 4.0.1813 → 4.1.2

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 (274) hide show
  1. package/dist/assets/export-scripts/README.classic.md +15 -0
  2. package/dist/assets/export-scripts/README.md +14 -0
  3. package/dist/assets/export-scripts/serve.js +114 -0
  4. package/dist/assets/export-scripts/start-docs.bat +10 -0
  5. package/dist/assets/export-scripts/start-docs.sh +9 -0
  6. package/dist/assets/og/Inter-Bold.ttf +0 -0
  7. package/dist/assets/og/Inter-Medium.ttf +0 -0
  8. package/dist/assets/og/Inter-Regular.ttf +0 -0
  9. package/dist/assets/og/Inter-SemiBold.ttf +0 -0
  10. package/dist/assets/og/PaperMono-Regular.ttf +0 -0
  11. package/dist/assets/og/index_bg.wasm +0 -0
  12. package/dist/assets/openChrome.applescript +94 -0
  13. package/dist/assets/socket.io/socket.io.esm.min.js +7 -0
  14. package/dist/assets/socket.io/socket.io.esm.min.js.map +1 -0
  15. package/dist/assets/socket.io/socket.io.js +4907 -0
  16. package/dist/assets/socket.io/socket.io.js.map +1 -0
  17. package/dist/assets/socket.io/socket.io.min.js +7 -0
  18. package/dist/assets/socket.io/socket.io.min.js.map +1 -0
  19. package/dist/assets/socket.io/socket.io.msgpack.min.js +7 -0
  20. package/dist/assets/socket.io/socket.io.msgpack.min.js.map +1 -0
  21. package/dist/assets/xdg-open +1066 -0
  22. package/dist/assets/yargs-locales/be.json +46 -0
  23. package/dist/assets/yargs-locales/cs.json +51 -0
  24. package/dist/assets/yargs-locales/de.json +46 -0
  25. package/dist/assets/yargs-locales/en.json +55 -0
  26. package/dist/assets/yargs-locales/es.json +46 -0
  27. package/dist/assets/yargs-locales/fi.json +49 -0
  28. package/dist/assets/yargs-locales/fr.json +53 -0
  29. package/dist/assets/yargs-locales/hi.json +49 -0
  30. package/dist/assets/yargs-locales/hu.json +46 -0
  31. package/dist/assets/yargs-locales/id.json +50 -0
  32. package/dist/assets/yargs-locales/it.json +46 -0
  33. package/dist/assets/yargs-locales/ja.json +51 -0
  34. package/dist/assets/yargs-locales/ko.json +49 -0
  35. package/dist/assets/yargs-locales/nb.json +44 -0
  36. package/dist/assets/yargs-locales/nl.json +49 -0
  37. package/dist/assets/yargs-locales/nn.json +44 -0
  38. package/dist/assets/yargs-locales/pirate.json +13 -0
  39. package/dist/assets/yargs-locales/pl.json +49 -0
  40. package/dist/assets/yargs-locales/pt.json +45 -0
  41. package/dist/assets/yargs-locales/pt_BR.json +48 -0
  42. package/dist/assets/yargs-locales/ru.json +51 -0
  43. package/dist/assets/yargs-locales/th.json +46 -0
  44. package/dist/assets/yargs-locales/tr.json +48 -0
  45. package/dist/assets/yargs-locales/uk_UA.json +51 -0
  46. package/dist/assets/yargs-locales/uz.json +52 -0
  47. package/dist/assets/yargs-locales/zh_CN.json +48 -0
  48. package/dist/assets/yargs-locales/zh_TW.json +51 -0
  49. package/dist/converter-d8O3xkdU.js +102 -0
  50. package/dist/devtools-CGNZQKFV.js +24 -0
  51. package/dist/index.js +8 -0
  52. package/dist/rolldown-runtime-CEAe2Uac.js +7 -0
  53. package/dist/schemas-CBsmCNpK.js +372 -0
  54. package/dist/start.js +2310 -0
  55. package/package.json +38 -31
  56. package/.oxlintrc.json +0 -5
  57. package/.prettierignore +0 -2
  58. package/.turbo/turbo-build.log +0 -1
  59. package/CONTRIBUTING.md +0 -45
  60. package/__test__/agent-auth.test.ts +0 -114
  61. package/__test__/agent-claim.test.ts +0 -164
  62. package/__test__/agent-credentials.test.ts +0 -149
  63. package/__test__/agent-deployment.test.ts +0 -106
  64. package/__test__/agent-setup-config.test.ts +0 -324
  65. package/__test__/agent-setup.test.ts +0 -207
  66. package/__test__/agent.test.ts +0 -64
  67. package/__test__/analytics/client.test.ts +0 -180
  68. package/__test__/analytics/dates.test.ts +0 -12
  69. package/__test__/analytics/filters.test.ts +0 -116
  70. package/__test__/analytics/format.test.ts +0 -137
  71. package/__test__/authenticatedFetch.test.ts +0 -182
  72. package/__test__/brokenLinks.test.ts +0 -283
  73. package/__test__/checkPort.test.ts +0 -92
  74. package/__test__/deploy-github-actions.test.ts +0 -202
  75. package/__test__/deploy-github-setup.test.ts +0 -240
  76. package/__test__/deploy-instructions.test.ts +0 -155
  77. package/__test__/deploy.test.ts +0 -202
  78. package/__test__/feedback.test.ts +0 -34
  79. package/__test__/foreignSyntax.test.ts +0 -73
  80. package/__test__/format.test.ts +0 -72
  81. package/__test__/helpers.test.ts +0 -52
  82. package/__test__/init.test.ts +0 -119
  83. package/__test__/instructions.test.ts +0 -53
  84. package/__test__/keyring.test.ts +0 -82
  85. package/__test__/mdxAccessibility.test.ts +0 -81
  86. package/__test__/migrate.test.ts +0 -186
  87. package/__test__/openApiCheck.test.ts +0 -185
  88. package/__test__/pathValidation.test.ts +0 -25
  89. package/__test__/resolveFiles.test.ts +0 -70
  90. package/__test__/sessionId.test.ts +0 -46
  91. package/__test__/signup.test.ts +0 -36
  92. package/__test__/update.test.ts +0 -117
  93. package/__test__/utils.ts +0 -25
  94. package/__test__/validateCommand.test.ts +0 -647
  95. package/__test__/validateEngine.test.ts +0 -245
  96. package/__test__/validateRules.test.ts +0 -1275
  97. package/__test__/welcome.test.ts +0 -15
  98. package/__test__/workflows/client.test.ts +0 -126
  99. package/bin/accessibility.js +0 -111
  100. package/bin/accessibilityCheck.js +0 -82
  101. package/bin/addDomain.js +0 -130
  102. package/bin/agent-auth.js +0 -104
  103. package/bin/agent-claim.js +0 -97
  104. package/bin/agent-credentials.js +0 -124
  105. package/bin/agent-deployment.js +0 -96
  106. package/bin/agent-http.js +0 -45
  107. package/bin/agent-setup-config.js +0 -141
  108. package/bin/agent-setup.js +0 -146
  109. package/bin/agent.js +0 -42
  110. package/bin/analytics/client.js +0 -60
  111. package/bin/analytics/dates.js +0 -6
  112. package/bin/analytics/filters.js +0 -27
  113. package/bin/analytics/format.js +0 -13
  114. package/bin/analytics/index.js +0 -496
  115. package/bin/analytics/output.js +0 -75
  116. package/bin/analytics/types.js +0 -1
  117. package/bin/authenticatedFetch.js +0 -46
  118. package/bin/brokenLinks.js +0 -122
  119. package/bin/callbackServer.js +0 -65
  120. package/bin/cli.js +0 -813
  121. package/bin/comingSoon.js +0 -26
  122. package/bin/config.js +0 -78
  123. package/bin/constants.js +0 -16
  124. package/bin/deploy-base.js +0 -20
  125. package/bin/deploy-github-actions.js +0 -102
  126. package/bin/deploy-github-setup.js +0 -165
  127. package/bin/deploy-instructions.js +0 -71
  128. package/bin/deploy.js +0 -123
  129. package/bin/feedback.js +0 -36
  130. package/bin/format.js +0 -121
  131. package/bin/helpers.js +0 -238
  132. package/bin/idToken.js +0 -14
  133. package/bin/index.js +0 -102
  134. package/bin/init.js +0 -182
  135. package/bin/instructions.js +0 -101
  136. package/bin/keyring.js +0 -78
  137. package/bin/login.js +0 -123
  138. package/bin/logout.js +0 -18
  139. package/bin/mdxAccessibility.js +0 -113
  140. package/bin/mdxLinter.js +0 -55
  141. package/bin/middlewares/subdomainMiddleware.js +0 -28
  142. package/bin/middlewares/telemetryMiddleware.js +0 -61
  143. package/bin/migrate.js +0 -54
  144. package/bin/og.js +0 -145
  145. package/bin/openApiCheck.js +0 -99
  146. package/bin/resolveFiles.js +0 -114
  147. package/bin/score/client.js +0 -40
  148. package/bin/score/index.js +0 -211
  149. package/bin/score/types.js +0 -1
  150. package/bin/signup.js +0 -118
  151. package/bin/start.js +0 -36
  152. package/bin/status.js +0 -106
  153. package/bin/telemetry/client.js +0 -53
  154. package/bin/telemetry/distinctId.js +0 -68
  155. package/bin/telemetry/sessionId.js +0 -36
  156. package/bin/telemetry/track.js +0 -149
  157. package/bin/templates.js +0 -127
  158. package/bin/tokenRefresh.js +0 -50
  159. package/bin/tsconfig.build.tsbuildinfo +0 -1
  160. package/bin/update.js +0 -65
  161. package/bin/validate/command.js +0 -127
  162. package/bin/validate/engine.js +0 -154
  163. package/bin/validate/files.js +0 -163
  164. package/bin/validate/mdx.js +0 -238
  165. package/bin/validate/output.js +0 -44
  166. package/bin/validate/report.js +0 -11
  167. package/bin/validate/rules/build.js +0 -102
  168. package/bin/validate/rules/content/duplicateH1.js +0 -57
  169. package/bin/validate/rules/content/foreignSyntax.js +0 -120
  170. package/bin/validate/rules/content/katex.js +0 -34
  171. package/bin/validate/rules/content/missingSnippet.js +0 -34
  172. package/bin/validate/rules/content/undefinedVariable.js +0 -13
  173. package/bin/validate/rules/content/unknownComponent.js +0 -121
  174. package/bin/validate/rules/content/voidTags.js +0 -38
  175. package/bin/validate/rules/index.js +0 -21
  176. package/bin/validate/rules/openapi.js +0 -50
  177. package/bin/validate/rules/parseError.js +0 -7
  178. package/bin/validate/site.js +0 -57
  179. package/bin/validate/types.js +0 -1
  180. package/bin/vendor/converter.js +0 -30882
  181. package/bin/welcome.js +0 -108
  182. package/bin/workflows/client.js +0 -34
  183. package/bin/workflows/index.js +0 -269
  184. package/bin/workflows/types.js +0 -11
  185. package/scripts/bundle-converter.mjs +0 -26
  186. package/scripts/generate-logo.mjs +0 -79
  187. package/src/accessibility.ts +0 -180
  188. package/src/accessibilityCheck.tsx +0 -150
  189. package/src/addDomain.tsx +0 -206
  190. package/src/agent-auth.ts +0 -119
  191. package/src/agent-claim.ts +0 -124
  192. package/src/agent-credentials.ts +0 -104
  193. package/src/agent-deployment.ts +0 -116
  194. package/src/agent-http.ts +0 -34
  195. package/src/agent-setup-config.ts +0 -144
  196. package/src/agent-setup.ts +0 -165
  197. package/src/agent.ts +0 -56
  198. package/src/analytics/client.ts +0 -153
  199. package/src/analytics/dates.ts +0 -6
  200. package/src/analytics/filters.ts +0 -50
  201. package/src/analytics/format.ts +0 -13
  202. package/src/analytics/index.tsx +0 -599
  203. package/src/analytics/output.ts +0 -99
  204. package/src/analytics/types.ts +0 -145
  205. package/src/authenticatedFetch.ts +0 -42
  206. package/src/brokenLinks.tsx +0 -152
  207. package/src/callbackServer.ts +0 -64
  208. package/src/cli.tsx +0 -1105
  209. package/src/comingSoon.tsx +0 -29
  210. package/src/config.ts +0 -75
  211. package/src/constants.ts +0 -28
  212. package/src/deploy-base.ts +0 -18
  213. package/src/deploy-github-actions.ts +0 -139
  214. package/src/deploy-github-setup.ts +0 -189
  215. package/src/deploy-instructions.ts +0 -76
  216. package/src/deploy.ts +0 -165
  217. package/src/feedback.tsx +0 -31
  218. package/src/format.tsx +0 -82
  219. package/src/helpers.tsx +0 -279
  220. package/src/idToken.ts +0 -17
  221. package/src/index.ts +0 -109
  222. package/src/init.tsx +0 -237
  223. package/src/instructions.ts +0 -99
  224. package/src/keyring.ts +0 -65
  225. package/src/login.tsx +0 -166
  226. package/src/logout.tsx +0 -8
  227. package/src/mdxAccessibility.ts +0 -134
  228. package/src/mdxLinter.tsx +0 -88
  229. package/src/middlewares/subdomainMiddleware.ts +0 -20
  230. package/src/middlewares/telemetryMiddleware.ts +0 -55
  231. package/src/migrate.ts +0 -76
  232. package/src/og.tsx +0 -185
  233. package/src/openApiCheck.tsx +0 -125
  234. package/src/resolveFiles.ts +0 -101
  235. package/src/score/client.ts +0 -36
  236. package/src/score/index.tsx +0 -205
  237. package/src/score/types.ts +0 -15
  238. package/src/signup.tsx +0 -172
  239. package/src/start.ts +0 -27
  240. package/src/status.tsx +0 -129
  241. package/src/telemetry/client.ts +0 -46
  242. package/src/telemetry/distinctId.ts +0 -70
  243. package/src/telemetry/sessionId.ts +0 -40
  244. package/src/telemetry/track.ts +0 -163
  245. package/src/templates.tsx +0 -143
  246. package/src/tokenRefresh.ts +0 -53
  247. package/src/update.tsx +0 -89
  248. package/src/validate/command.tsx +0 -135
  249. package/src/validate/engine.ts +0 -210
  250. package/src/validate/files.ts +0 -249
  251. package/src/validate/mdx.ts +0 -290
  252. package/src/validate/output.tsx +0 -76
  253. package/src/validate/report.ts +0 -40
  254. package/src/validate/rules/build.ts +0 -146
  255. package/src/validate/rules/content/duplicateH1.ts +0 -78
  256. package/src/validate/rules/content/foreignSyntax.ts +0 -144
  257. package/src/validate/rules/content/katex.ts +0 -33
  258. package/src/validate/rules/content/missingSnippet.ts +0 -36
  259. package/src/validate/rules/content/undefinedVariable.ts +0 -20
  260. package/src/validate/rules/content/unknownComponent.ts +0 -130
  261. package/src/validate/rules/content/voidTags.ts +0 -43
  262. package/src/validate/rules/index.ts +0 -23
  263. package/src/validate/rules/openapi.ts +0 -59
  264. package/src/validate/rules/parseError.ts +0 -9
  265. package/src/validate/site.ts +0 -53
  266. package/src/validate/types.ts +0 -102
  267. package/src/vendor/converter.ts +0 -1
  268. package/src/welcome.ts +0 -154
  269. package/src/workflows/client.ts +0 -39
  270. package/src/workflows/index.tsx +0 -287
  271. package/src/workflows/types.ts +0 -73
  272. package/tsconfig.build.json +0 -4
  273. package/tsconfig.json +0 -10
  274. package/vitest.config.ts +0 -9
@@ -1,106 +0,0 @@
1
- import { afterEach, describe, expect, it, vi } from 'vitest';
2
-
3
- import { getAgentWriteToken, provisionAgentSite } from '../src/agent-deployment.js';
4
-
5
- vi.mock('node:timers/promises', () => ({ setTimeout: vi.fn().mockResolvedValue(undefined) }));
6
- const ready = {
7
- status: 'ready',
8
- deploymentId: 'deployment',
9
- subdomain: 'actual-name',
10
- remote: 'https://git.example.com/repo.git',
11
- branch: 'main',
12
- expiresAt: '2026-12-01T00:00:00.000Z',
13
- };
14
- const existing = { ...ready, code: 'deployment_already_exists' };
15
- const provision = () =>
16
- provisionAgentSite('https://api.example.com', 'access', {
17
- subdomain: 'requested',
18
- orgName: 'Docs',
19
- });
20
- function response(body: unknown, status: number) {
21
- return new Response(JSON.stringify(body), { status });
22
- }
23
- afterEach(() => vi.unstubAllGlobals());
24
-
25
- describe('agent deployment API', () => {
26
- it('sends root content layout and uses the allocated subdomain', async () => {
27
- const request = vi.fn().mockResolvedValue(response(ready, 201));
28
- vi.stubGlobal('fetch', request);
29
- expect(await provision()).toEqual({ ...ready, created: true });
30
- expect(JSON.parse(request.mock.calls[0]?.[1].body)).toEqual({
31
- subdomain: 'requested',
32
- orgName: 'Docs',
33
- docsPath: '',
34
- });
35
- });
36
- it('requests a base when the project type is workspace', async () => {
37
- const request = vi.fn().mockResolvedValue(response({ ...ready, orgSlug: 'acme' }, 201));
38
- vi.stubGlobal('fetch', request);
39
- expect(
40
- await provisionAgentSite('https://api.example.com', 'access', {
41
- subdomain: 'requested',
42
- projectType: 'workspace',
43
- })
44
- ).toEqual({ ...ready, orgSlug: 'acme', created: true });
45
- expect(JSON.parse(request.mock.calls[0]?.[1].body)).toEqual({
46
- subdomain: 'requested',
47
- projectType: 'workspace',
48
- docsPath: '',
49
- });
50
- });
51
- it('returns an existing site as an update, not a new creation', async () => {
52
- vi.stubGlobal('fetch', vi.fn().mockResolvedValue(response(existing, 409)));
53
- expect(await provision()).toEqual({ ...existing, created: false });
54
- });
55
- it('retries provisioning even when no deployment ID exists yet', async () => {
56
- const request = vi
57
- .fn()
58
- .mockResolvedValueOnce(response({ status: 'provisioning', code: existing.code }, 409))
59
- .mockResolvedValueOnce(response(existing, 409));
60
- vi.stubGlobal('fetch', request);
61
- expect((await provision()).status).toBe('ready');
62
- expect(request).toHaveBeenCalledTimes(2);
63
- });
64
- it('bounds provisioning retries', async () => {
65
- const request = vi
66
- .fn()
67
- .mockImplementation(async () =>
68
- response({ status: 'provisioning', code: existing.code }, 409)
69
- );
70
- vi.stubGlobal('fetch', request);
71
- await expect(provision()).rejects.toThrow('still provisioning');
72
- expect(request).toHaveBeenCalledTimes(4);
73
- });
74
- it('distinguishes confirmed expiry from upstream failure', async () => {
75
- const request = vi
76
- .fn()
77
- .mockResolvedValueOnce(response({ ...existing, status: 'expired' }, 409))
78
- .mockResolvedValueOnce(response({ error: 'unavailable' }, 503));
79
- vi.stubGlobal('fetch', request);
80
- expect((await provision()).status).toBe('expired');
81
- await expect(provision()).rejects.toThrow('503');
82
- });
83
- it('treats a swept registration as expired', async () => {
84
- const swept = {
85
- created: false,
86
- code: 'deployment_claim_expired',
87
- status: 'expired',
88
- deploymentId: 'deployment',
89
- subdomain: 'actual-name',
90
- };
91
- vi.stubGlobal('fetch', vi.fn().mockResolvedValue(response(swept, 409)));
92
- expect(await provision()).toEqual(swept);
93
- });
94
- it('requests a write token without a caller-selected deployment', async () => {
95
- const credential = {
96
- remote: ready.remote,
97
- branch: 'main',
98
- token: 'write-secret',
99
- tokenExpiresAt: ready.expiresAt,
100
- };
101
- const request = vi.fn().mockResolvedValue(response(credential, 200));
102
- vi.stubGlobal('fetch', request);
103
- expect(await getAgentWriteToken('https://api.example.com', 'access')).toEqual(credential);
104
- expect(request.mock.calls[0]?.[1].body).toBeUndefined();
105
- });
106
- });
@@ -1,324 +0,0 @@
1
- import { parse as parseJsonc } from 'jsonc-parser';
2
- import fs from 'node:fs/promises';
3
- import os from 'node:os';
4
- import path from 'node:path';
5
- import { parse as parseToml } from 'smol-toml';
6
- import { afterEach, beforeEach, describe, expect, it } from 'vitest';
7
-
8
- import {
9
- ADMIN_MCP_NAME,
10
- ADMIN_MCP_URL,
11
- prepareMcpConfig,
12
- writeMcpConfig,
13
- type SetupAgent,
14
- } from '../src/agent-setup-config.js';
15
-
16
- let directory: string;
17
- let cwd: string;
18
- let homeDir: string;
19
-
20
- const projectPaths: [SetupAgent, string][] = [
21
- ['claude-code', '.mcp.json'],
22
- ['codex', '.codex/config.toml'],
23
- ['cursor', '.cursor/mcp.json'],
24
- ];
25
-
26
- const globalPaths: [SetupAgent, string][] = [
27
- ['claude-code', '.claude.json'],
28
- ['codex', '.codex/config.toml'],
29
- ['cursor', '.cursor/mcp.json'],
30
- ];
31
-
32
- function options(global = false, env: NodeJS.ProcessEnv = {}) {
33
- return { cwd, homeDir, global, env };
34
- }
35
-
36
- async function fixture(filePath: string, contents: string) {
37
- await fs.mkdir(path.dirname(filePath), { recursive: true });
38
- await fs.writeFile(filePath, contents);
39
- }
40
-
41
- beforeEach(async () => {
42
- directory = await fs.mkdtemp(path.join(os.tmpdir(), 'mint-agent-setup-config-'));
43
- cwd = path.join(directory, 'project');
44
- homeDir = path.join(directory, 'home');
45
- await fs.mkdir(cwd);
46
- await fs.mkdir(homeDir);
47
- });
48
-
49
- afterEach(async () => {
50
- await fs.rm(directory, { recursive: true, force: true });
51
- });
52
-
53
- describe('agent setup MCP configuration', () => {
54
- it.each(projectPaths)(
55
- 'prepares project configuration for %s without writing it',
56
- async (agent, relativePath) => {
57
- const plan = await prepareMcpConfig(agent, options());
58
-
59
- expect(plan.path).toBe(path.join(cwd, relativePath));
60
- expect(plan.original).toBeUndefined();
61
- expect(plan.contents).toEqual(expect.any(String));
62
- await expect(fs.readFile(plan.path, 'utf8')).rejects.toThrow();
63
-
64
- if (plan.contents === undefined) throw new Error('Missing prepared configuration');
65
- if (agent === 'codex') {
66
- expect(parseToml(plan.contents)).toMatchObject({
67
- mcp_servers: { [ADMIN_MCP_NAME]: { url: ADMIN_MCP_URL } },
68
- });
69
- return;
70
- }
71
-
72
- const expectedServer: { url: string; type?: string } = { url: ADMIN_MCP_URL };
73
- if (agent === 'claude-code') expectedServer.type = 'http';
74
- expect(parseJsonc(plan.contents)).toEqual({
75
- mcpServers: { [ADMIN_MCP_NAME]: expectedServer },
76
- });
77
- }
78
- );
79
-
80
- it.each(globalPaths)(
81
- 'uses the user configuration path for global %s setup',
82
- async (agent, relativePath) => {
83
- const plan = await prepareMcpConfig(agent, options(true));
84
-
85
- expect(plan.path).toBe(path.join(homeDir, relativePath));
86
- expect(plan.original).toBeUndefined();
87
- expect(plan.contents).toContain(ADMIN_MCP_URL);
88
- }
89
- );
90
-
91
- it('honors CODEX_HOME for global setup while retaining project scope', async () => {
92
- const codexHome = path.join(directory, 'custom-codex');
93
- const env = { CODEX_HOME: codexHome };
94
-
95
- const globalPlan = await prepareMcpConfig('codex', options(true, env));
96
- const projectPlan = await prepareMcpConfig('codex', options(false, env));
97
-
98
- expect(globalPlan.path).toBe(path.join(codexHome, 'config.toml'));
99
- expect(projectPlan.path).toBe(path.join(cwd, '.codex/config.toml'));
100
- });
101
-
102
- it('refuses an unsupported Claude global directory without blocking project setup', async () => {
103
- const env = { CLAUDE_CONFIG_DIR: path.join(directory, 'custom-claude') };
104
-
105
- await expect(prepareMcpConfig('claude-code', options(true, env))).rejects.toThrow();
106
- const projectPlan = await prepareMcpConfig('claude-code', options(false, env));
107
- expect(projectPlan.path).toBe(path.join(cwd, '.mcp.json'));
108
- });
109
-
110
- it.each(['claude-code', 'cursor'])(
111
- 'preserves JSONC comments, trailing commas, and other %s settings',
112
- async (client) => {
113
- const agent = projectPaths.find(([name]) => name === client);
114
- if (agent === undefined) throw new Error('Missing test agent');
115
- const [name, relativePath] = agent;
116
- const original = `{
117
- // Personal preferences
118
- "theme": "dark",
119
- "mcpServers": {
120
- "other": { "url": "https://example.com/mcp", },
121
- },
122
- }
123
- `;
124
- await fixture(path.join(cwd, relativePath), original);
125
-
126
- const plan = await prepareMcpConfig(name, options());
127
-
128
- expect(plan.original).toBe(original);
129
- expect(plan.contents).toContain('// Personal preferences');
130
- if (plan.contents === undefined) throw new Error('Missing prepared configuration');
131
- expect(parseJsonc(plan.contents)).toMatchObject({
132
- theme: 'dark',
133
- mcpServers: {
134
- other: { url: 'https://example.com/mcp' },
135
- [ADMIN_MCP_NAME]: { url: ADMIN_MCP_URL },
136
- },
137
- });
138
- expect(await fs.readFile(plan.path, 'utf8')).toBe(original);
139
- }
140
- );
141
-
142
- it('appends Codex settings while preserving existing TOML text and tables', async () => {
143
- const original =
144
- '# Personal preferences\nmodel = "example-model"\n\n[mcp_servers.other]\nurl = "https://example.com/mcp"\n';
145
- await fixture(path.join(cwd, '.codex/config.toml'), original);
146
-
147
- const plan = await prepareMcpConfig('codex', options());
148
-
149
- expect(plan.original).toBe(original);
150
- expect(plan.contents?.startsWith(original)).toBe(true);
151
- if (plan.contents === undefined) throw new Error('Missing prepared configuration');
152
- expect(parseToml(plan.contents)).toMatchObject({
153
- model: 'example-model',
154
- mcp_servers: {
155
- other: { url: 'https://example.com/mcp' },
156
- [ADMIN_MCP_NAME]: { url: ADMIN_MCP_URL },
157
- },
158
- });
159
- });
160
-
161
- it.each(['claude-code', 'cursor'])(
162
- 'skips a matching %s server without changing extra fields',
163
- async (client) => {
164
- const agent = projectPaths.find(([name]) => name === client);
165
- if (agent === undefined) throw new Error('Missing test agent');
166
- const [name, relativePath] = agent;
167
- const original = JSON.stringify({
168
- mcpServers: {
169
- [ADMIN_MCP_NAME]: {
170
- url: ADMIN_MCP_URL,
171
- type: 'http',
172
- disabled: true,
173
- headers: { Example: 'value' },
174
- },
175
- },
176
- });
177
- await fixture(path.join(cwd, relativePath), original);
178
-
179
- const plan = await prepareMcpConfig(name, options());
180
-
181
- expect(plan.original).toBe(original);
182
- expect(plan.contents).toBeUndefined();
183
- await writeMcpConfig(plan);
184
- expect(await fs.readFile(plan.path, 'utf8')).toBe(original);
185
- }
186
- );
187
-
188
- it('refuses to extend an inline Codex mcp_servers table', async () => {
189
- const original = 'mcp_servers = { other = { url = "https://example.com/mcp" } }\n';
190
- await fixture(path.join(cwd, '.codex/config.toml'), original);
191
-
192
- await expect(prepareMcpConfig('codex', options())).rejects.toThrow(
193
- `Add a ${ADMIN_MCP_NAME} entry with url = "${ADMIN_MCP_URL}" to mcp_servers manually.`
194
- );
195
- expect(await fs.readFile(path.join(cwd, '.codex/config.toml'), 'utf8')).toBe(original);
196
- });
197
-
198
- it('skips a matching Codex server without enabling or rewriting it', async () => {
199
- const original = `[mcp_servers.${ADMIN_MCP_NAME}]\nurl = "${ADMIN_MCP_URL}"\nenabled = false\nstartup_timeout_sec = 20\n`;
200
- await fixture(path.join(cwd, '.codex/config.toml'), original);
201
-
202
- const plan = await prepareMcpConfig('codex', options());
203
-
204
- expect(plan.original).toBe(original);
205
- expect(plan.contents).toBeUndefined();
206
- await writeMcpConfig(plan);
207
- expect(await fs.readFile(plan.path, 'utf8')).toBe(original);
208
- });
209
-
210
- it.each([undefined, 'stdio'])('rejects an invalid Claude server transport %s', async (type) => {
211
- const original = JSON.stringify({
212
- mcpServers: { [ADMIN_MCP_NAME]: { url: ADMIN_MCP_URL, type } },
213
- });
214
- await fixture(path.join(cwd, '.mcp.json'), original);
215
-
216
- await expect(prepareMcpConfig('claude-code', options())).rejects.toThrow('type');
217
- expect(await fs.readFile(path.join(cwd, '.mcp.json'), 'utf8')).toBe(original);
218
- });
219
-
220
- it('detects changes to a server that was already configured', async () => {
221
- const original = `[mcp_servers.${ADMIN_MCP_NAME}]\nurl = "${ADMIN_MCP_URL}"\n`;
222
- const filePath = path.join(cwd, '.codex/config.toml');
223
- await fixture(filePath, original);
224
- const plan = await prepareMcpConfig('codex', options());
225
- await fs.writeFile(filePath, '# Changed during installation\n');
226
-
227
- await expect(writeMcpConfig(plan)).rejects.toThrow('changed during setup');
228
- expect(await fs.readFile(filePath, 'utf8')).toBe('# Changed during installation\n');
229
- });
230
-
231
- it.each([
232
- { url: 'https://example.com/different' },
233
- { command: 'example-server', args: ['serve'] },
234
- ])('refuses a conflicting JSON server %j', async (server) => {
235
- for (const [agent, relativePath] of projectPaths) {
236
- if (agent === 'codex') continue;
237
- const original = JSON.stringify({ mcpServers: { [ADMIN_MCP_NAME]: server } });
238
- const filePath = path.join(cwd, relativePath);
239
- await fixture(filePath, original);
240
-
241
- await expect(prepareMcpConfig(agent, options())).rejects.toThrow();
242
- expect(await fs.readFile(filePath, 'utf8')).toBe(original);
243
- }
244
- });
245
-
246
- it.each([
247
- `url = "https://example.com/different"`,
248
- `command = "example-server"\nargs = ["serve"]`,
249
- ])('refuses a conflicting Codex server with %s', async (server) => {
250
- const original = `[mcp_servers.${ADMIN_MCP_NAME}]\n${server}\n`;
251
- const filePath = path.join(cwd, '.codex/config.toml');
252
- await fixture(filePath, original);
253
-
254
- await expect(prepareMcpConfig('codex', options())).rejects.toThrow();
255
- expect(await fs.readFile(filePath, 'utf8')).toBe(original);
256
- });
257
-
258
- it.each(['{', '[]', '{"mcpServers": []}', '{"mcpServers": null}'])(
259
- 'rejects malformed or incompatible JSON configuration %s',
260
- async (original) => {
261
- const filePath = path.join(cwd, '.cursor/mcp.json');
262
- await fixture(filePath, original);
263
-
264
- await expect(prepareMcpConfig('cursor', options())).rejects.toThrow();
265
- expect(await fs.readFile(filePath, 'utf8')).toBe(original);
266
- }
267
- );
268
-
269
- it.each([
270
- '[mcp_servers\n',
271
- 'mcp_servers = "example"\n',
272
- 'mcp_servers = { other = { url = "https://example.com/mcp" } }\n',
273
- ])('rejects malformed or incompatible TOML configuration %s', async (original) => {
274
- const filePath = path.join(cwd, '.codex/config.toml');
275
- await fixture(filePath, original);
276
-
277
- await expect(prepareMcpConfig('codex', options())).rejects.toThrow();
278
- expect(await fs.readFile(filePath, 'utf8')).toBe(original);
279
- });
280
-
281
- it.each([0o640, 0o664])(
282
- 'writes the prepared contents while preserving permissions %i',
283
- async (mode) => {
284
- const filePath = path.join(cwd, '.mcp.json');
285
- await fixture(filePath, '{"theme":"dark"}\n');
286
- await fs.chmod(filePath, mode);
287
- const plan = await prepareMcpConfig('claude-code', options());
288
-
289
- await writeMcpConfig(plan);
290
-
291
- expect(await fs.readFile(filePath, 'utf8')).toBe(plan.contents);
292
- if (process.platform !== 'win32') expect((await fs.stat(filePath)).mode & 0o777).toBe(mode);
293
- const rerun = await prepareMcpConfig('claude-code', options());
294
- expect(rerun.contents).toBeUndefined();
295
- }
296
- );
297
-
298
- it.each([false, true])(
299
- 'refuses configuration drift when an original file existed: %s',
300
- async (existing) => {
301
- const filePath = path.join(cwd, '.mcp.json');
302
- if (existing) await fixture(filePath, '{}\n');
303
- const plan = await prepareMcpConfig('claude-code', options());
304
- const changed = '{"theme":"new-preference"}\n';
305
- await fixture(filePath, changed);
306
-
307
- await expect(writeMcpConfig(plan)).rejects.toThrow();
308
- expect(await fs.readFile(filePath, 'utf8')).toBe(changed);
309
- }
310
- );
311
-
312
- it('refuses to replace a configuration symlink or change its target', async () => {
313
- const filePath = path.join(cwd, '.mcp.json');
314
- const targetPath = path.join(directory, 'shared-config.json');
315
- const original = '{"theme":"shared"}\n';
316
- await fixture(targetPath, original);
317
- const plan = await prepareMcpConfig('claude-code', options());
318
- await fs.symlink(targetPath, filePath);
319
-
320
- await expect(writeMcpConfig(plan)).rejects.toThrow();
321
- expect((await fs.lstat(filePath)).isSymbolicLink()).toBe(true);
322
- expect(await fs.readFile(targetPath, 'utf8')).toBe(original);
323
- });
324
- });
@@ -1,207 +0,0 @@
1
- import { spawnSync } from 'node:child_process';
2
- import fs from 'node:fs/promises';
3
- import os from 'node:os';
4
- import path from 'node:path';
5
- import { parse as parseToml } from 'smol-toml';
6
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
7
-
8
- import { installSkills, setupAgent } from '../src/agent-setup.js';
9
-
10
- let directory: string;
11
- let argumentsFile: string;
12
- let project: string;
13
- const originalIsTTY = process.stdin.isTTY;
14
-
15
- function executablePath(command: string): string {
16
- const extension = process.platform === 'win32' ? '.cmd' : '';
17
- return path.join(directory, `${command}${extension}`);
18
- }
19
-
20
- async function fakeExecutable(command: string, source: string) {
21
- if (process.platform === 'win32') {
22
- const script = path.join(directory, `${command}.cjs`);
23
- await fs.writeFile(script, source);
24
- await fs.writeFile(executablePath(command), `@"${process.execPath}" "${script}" %*\r\n`);
25
- return;
26
- }
27
- await fs.writeFile(executablePath(command), `#!${process.execPath}\n${source}\n`, {
28
- mode: 0o755,
29
- });
30
- }
31
-
32
- beforeEach(async () => {
33
- directory = await fs.mkdtemp(path.join(os.tmpdir(), 'mint-agent-setup-'));
34
- argumentsFile = path.join(directory, 'arguments.json');
35
- project = path.join(directory, 'project');
36
- await fs.mkdir(project);
37
- vi.stubEnv('PATH', directory);
38
- vi.stubEnv('CODEX_HOME', '');
39
- vi.stubEnv('CLAUDE_CONFIG_DIR', '');
40
- vi.spyOn(process, 'cwd').mockReturnValue(project);
41
- vi.spyOn(os, 'homedir').mockReturnValue(path.join(directory, 'home'));
42
- process.stdin.isTTY = false;
43
- await fakeExecutable(
44
- 'npx',
45
- `require('node:fs').writeFileSync(${JSON.stringify(argumentsFile)}, JSON.stringify(process.argv.slice(2)));`
46
- );
47
- });
48
-
49
- afterEach(async () => {
50
- vi.restoreAllMocks();
51
- process.stdin.isTTY = originalIsTTY;
52
- vi.unstubAllEnvs();
53
- await fs.rm(directory, { recursive: true, force: true });
54
- });
55
-
56
- describe('agent setup skills installer', () => {
57
- it('passes explicit agents and project scope without an interactive installer', async () => {
58
- await installSkills(['claude-code', 'codex', 'cursor'], false);
59
-
60
- expect(JSON.parse(await fs.readFile(argumentsFile, 'utf8'))).toEqual([
61
- '--yes',
62
- 'skills@1.7.4',
63
- 'add',
64
- 'https://mintlify.com/docs',
65
- '--agent',
66
- 'claude-code',
67
- 'codex',
68
- 'cursor',
69
- '--yes',
70
- ]);
71
- });
72
-
73
- it('forwards global scope to the skills installer', async () => {
74
- await installSkills(['codex'], true);
75
-
76
- expect(JSON.parse(await fs.readFile(argumentsFile, 'utf8'))).toContain('--global');
77
- });
78
-
79
- it('rejects a nonzero installer exit', async () => {
80
- await fakeExecutable('npx', 'process.exit(1);');
81
-
82
- await expect(installSkills(['codex'], false)).rejects.toThrow('Skills installation failed');
83
- });
84
-
85
- it('rejects partial installation failures even when the pinned installer exits zero', async () => {
86
- await fakeExecutable('npx', "console.error('\\u001b[31mFailed to install 1\\u001b[0m');");
87
-
88
- await expect(installSkills(['codex'], false)).rejects.toThrow('Skills installation failed');
89
- });
90
-
91
- it('rejects a missing npm runner', async () => {
92
- await fs.unlink(executablePath('npx'));
93
- const message =
94
- process.platform === 'win32' ? 'Skills installation failed' : 'Could not run npx';
95
-
96
- await expect(installSkills(['codex'], false)).rejects.toThrow(message);
97
- });
98
- });
99
-
100
- describe('agent setup orchestration', () => {
101
- it('passes a TOML URL override without embedded native argument quotes', async () => {
102
- let output = '';
103
- vi.spyOn(process.stdout, 'write').mockImplementation((chunk) => {
104
- output += chunk.toString();
105
- return true;
106
- });
107
- await fakeExecutable(
108
- 'codex',
109
- `require('node:fs').writeFileSync(${JSON.stringify(argumentsFile)}, JSON.stringify(process.argv.slice(2)));`
110
- );
111
-
112
- await setupAgent({ agents: ['codex'], global: false });
113
- const command = output.match(/Codex: run (.+)\. Trust/)?.[1];
114
- if (command === undefined) throw new Error('Missing Codex login command');
115
-
116
- const result = spawnSync(command, { shell: true, env: process.env });
117
- expect(result.status).toBe(0);
118
- const args: unknown = JSON.parse(await fs.readFile(argumentsFile, 'utf8'));
119
- if (!Array.isArray(args) || typeof args[1] !== 'string') {
120
- throw new Error('Missing Codex configuration override');
121
- }
122
- expect(args[0]).toBe('-c');
123
- expect(args[1]).not.toContain('"');
124
- expect(args.slice(2)).toEqual(['mcp', 'login', 'mintlify-admin']);
125
- expect(parseToml(args[1])).toEqual({
126
- mcp_servers: { 'mintlify-admin': { url: 'https://mcp.mintlify.com' } },
127
- });
128
- });
129
-
130
- it('preflights every target before installing skills or changing configuration', async () => {
131
- await fs.mkdir(path.join(project, '.cursor'));
132
- const conflict = '{"mcpServers":{"mintlify-admin":{"url":"https://example.com/mcp"}}}';
133
- await fs.writeFile(path.join(project, '.cursor/mcp.json'), conflict);
134
-
135
- await expect(setupAgent({ agents: ['codex', 'cursor'], global: false })).rejects.toThrow(
136
- 'different configuration'
137
- );
138
- await expect(fs.readFile(argumentsFile)).rejects.toThrow();
139
- await expect(fs.readFile(path.join(project, '.codex/config.toml'))).rejects.toThrow();
140
- expect(await fs.readFile(path.join(project, '.cursor/mcp.json'), 'utf8')).toBe(conflict);
141
- });
142
-
143
- it('leaves MCP configuration untouched when skills installation fails', async () => {
144
- await fakeExecutable('npx', 'process.exit(1);');
145
-
146
- await expect(setupAgent({ agents: ['codex'], global: false })).rejects.toThrow();
147
- await expect(fs.readFile(path.join(project, '.codex/config.toml'))).rejects.toThrow();
148
- });
149
-
150
- it('configures all selected agents after skills finish and deduplicates targets', async () => {
151
- await setupAgent({
152
- agents: ['codex', 'claude-code', 'cursor', 'codex'],
153
- global: false,
154
- });
155
-
156
- const args: unknown = JSON.parse(await fs.readFile(argumentsFile, 'utf8'));
157
- expect(args).toEqual([
158
- '--yes',
159
- 'skills@1.7.4',
160
- 'add',
161
- 'https://mintlify.com/docs',
162
- '--agent',
163
- 'codex',
164
- 'claude-code',
165
- 'cursor',
166
- '--yes',
167
- ]);
168
- for (const file of ['.codex/config.toml', '.mcp.json', '.cursor/mcp.json']) {
169
- expect(await fs.readFile(path.join(project, file), 'utf8')).toContain(
170
- 'https://mcp.mintlify.com'
171
- );
172
- }
173
- });
174
-
175
- it('configures detected agents when running without a terminal', async () => {
176
- vi.stubEnv('AI_AGENT', 'codex_cli');
177
-
178
- await setupAgent({ global: false });
179
-
180
- expect(JSON.parse(await fs.readFile(argumentsFile, 'utf8'))).toEqual([
181
- '--yes',
182
- 'skills@1.7.4',
183
- 'add',
184
- 'https://mintlify.com/docs',
185
- '--agent',
186
- 'codex',
187
- '--yes',
188
- ]);
189
- expect(await fs.readFile(path.join(project, '.codex/config.toml'), 'utf8')).toContain(
190
- 'https://mcp.mintlify.com'
191
- );
192
- });
193
-
194
- it('requires agent selection when no supported agents are detected without a terminal', async () => {
195
- vi.stubEnv('AI_AGENT', 'unknown-agent');
196
-
197
- await expect(setupAgent({ global: false })).rejects.toThrow('Pass --agent');
198
- await expect(fs.readFile(argumentsFile)).rejects.toThrow();
199
- });
200
-
201
- it('rejects unsupported agent names before spawning a command', async () => {
202
- await expect(setupAgent({ agents: ['codex;echo unsafe'], global: false })).rejects.toThrow(
203
- 'Unsupported agent'
204
- );
205
- await expect(fs.readFile(argumentsFile)).rejects.toThrow();
206
- });
207
- });