@mintlify/cli 4.0.1813 → 4.1.1
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.
- package/dist/assets/export-scripts/README.classic.md +15 -0
- package/dist/assets/export-scripts/README.md +14 -0
- package/dist/assets/export-scripts/serve.js +114 -0
- package/dist/assets/export-scripts/start-docs.bat +10 -0
- package/dist/assets/export-scripts/start-docs.sh +9 -0
- package/dist/assets/og/Inter-Bold.ttf +0 -0
- package/dist/assets/og/Inter-Medium.ttf +0 -0
- package/dist/assets/og/Inter-Regular.ttf +0 -0
- package/dist/assets/og/Inter-SemiBold.ttf +0 -0
- package/dist/assets/og/PaperMono-Regular.ttf +0 -0
- package/dist/assets/og/index_bg.wasm +0 -0
- package/dist/assets/openChrome.applescript +94 -0
- package/dist/assets/socket.io/socket.io.esm.min.js +7 -0
- package/dist/assets/socket.io/socket.io.esm.min.js.map +1 -0
- package/dist/assets/socket.io/socket.io.js +4907 -0
- package/dist/assets/socket.io/socket.io.js.map +1 -0
- package/dist/assets/socket.io/socket.io.min.js +7 -0
- package/dist/assets/socket.io/socket.io.min.js.map +1 -0
- package/dist/assets/socket.io/socket.io.msgpack.min.js +7 -0
- package/dist/assets/socket.io/socket.io.msgpack.min.js.map +1 -0
- package/dist/assets/xdg-open +1066 -0
- package/dist/assets/yargs-locales/be.json +46 -0
- package/dist/assets/yargs-locales/cs.json +51 -0
- package/dist/assets/yargs-locales/de.json +46 -0
- package/dist/assets/yargs-locales/en.json +55 -0
- package/dist/assets/yargs-locales/es.json +46 -0
- package/dist/assets/yargs-locales/fi.json +49 -0
- package/dist/assets/yargs-locales/fr.json +53 -0
- package/dist/assets/yargs-locales/hi.json +49 -0
- package/dist/assets/yargs-locales/hu.json +46 -0
- package/dist/assets/yargs-locales/id.json +50 -0
- package/dist/assets/yargs-locales/it.json +46 -0
- package/dist/assets/yargs-locales/ja.json +51 -0
- package/dist/assets/yargs-locales/ko.json +49 -0
- package/dist/assets/yargs-locales/nb.json +44 -0
- package/dist/assets/yargs-locales/nl.json +49 -0
- package/dist/assets/yargs-locales/nn.json +44 -0
- package/dist/assets/yargs-locales/pirate.json +13 -0
- package/dist/assets/yargs-locales/pl.json +49 -0
- package/dist/assets/yargs-locales/pt.json +45 -0
- package/dist/assets/yargs-locales/pt_BR.json +48 -0
- package/dist/assets/yargs-locales/ru.json +51 -0
- package/dist/assets/yargs-locales/th.json +46 -0
- package/dist/assets/yargs-locales/tr.json +48 -0
- package/dist/assets/yargs-locales/uk_UA.json +51 -0
- package/dist/assets/yargs-locales/uz.json +52 -0
- package/dist/assets/yargs-locales/zh_CN.json +48 -0
- package/dist/assets/yargs-locales/zh_TW.json +51 -0
- package/dist/converter-d8O3xkdU.js +102 -0
- package/dist/devtools-CGNZQKFV.js +24 -0
- package/dist/index.js +8 -0
- package/dist/rolldown-runtime-CEAe2Uac.js +7 -0
- package/dist/schemas-CBsmCNpK.js +372 -0
- package/dist/start.js +2310 -0
- package/package.json +38 -31
- package/.oxlintrc.json +0 -5
- package/.prettierignore +0 -2
- package/.turbo/turbo-build.log +0 -1
- package/CONTRIBUTING.md +0 -45
- package/__test__/agent-auth.test.ts +0 -114
- package/__test__/agent-claim.test.ts +0 -164
- package/__test__/agent-credentials.test.ts +0 -149
- package/__test__/agent-deployment.test.ts +0 -106
- package/__test__/agent-setup-config.test.ts +0 -324
- package/__test__/agent-setup.test.ts +0 -207
- package/__test__/agent.test.ts +0 -64
- package/__test__/analytics/client.test.ts +0 -180
- package/__test__/analytics/dates.test.ts +0 -12
- package/__test__/analytics/filters.test.ts +0 -116
- package/__test__/analytics/format.test.ts +0 -137
- package/__test__/authenticatedFetch.test.ts +0 -182
- package/__test__/brokenLinks.test.ts +0 -283
- package/__test__/checkPort.test.ts +0 -92
- package/__test__/deploy-github-actions.test.ts +0 -202
- package/__test__/deploy-github-setup.test.ts +0 -240
- package/__test__/deploy-instructions.test.ts +0 -155
- package/__test__/deploy.test.ts +0 -202
- package/__test__/feedback.test.ts +0 -34
- package/__test__/foreignSyntax.test.ts +0 -73
- package/__test__/format.test.ts +0 -72
- package/__test__/helpers.test.ts +0 -52
- package/__test__/init.test.ts +0 -119
- package/__test__/instructions.test.ts +0 -53
- package/__test__/keyring.test.ts +0 -82
- package/__test__/mdxAccessibility.test.ts +0 -81
- package/__test__/migrate.test.ts +0 -186
- package/__test__/openApiCheck.test.ts +0 -185
- package/__test__/pathValidation.test.ts +0 -25
- package/__test__/resolveFiles.test.ts +0 -70
- package/__test__/sessionId.test.ts +0 -46
- package/__test__/signup.test.ts +0 -36
- package/__test__/update.test.ts +0 -117
- package/__test__/utils.ts +0 -25
- package/__test__/validateCommand.test.ts +0 -647
- package/__test__/validateEngine.test.ts +0 -245
- package/__test__/validateRules.test.ts +0 -1275
- package/__test__/welcome.test.ts +0 -15
- package/__test__/workflows/client.test.ts +0 -126
- package/bin/accessibility.js +0 -111
- package/bin/accessibilityCheck.js +0 -82
- package/bin/addDomain.js +0 -130
- package/bin/agent-auth.js +0 -104
- package/bin/agent-claim.js +0 -97
- package/bin/agent-credentials.js +0 -124
- package/bin/agent-deployment.js +0 -96
- package/bin/agent-http.js +0 -45
- package/bin/agent-setup-config.js +0 -141
- package/bin/agent-setup.js +0 -146
- package/bin/agent.js +0 -42
- package/bin/analytics/client.js +0 -60
- package/bin/analytics/dates.js +0 -6
- package/bin/analytics/filters.js +0 -27
- package/bin/analytics/format.js +0 -13
- package/bin/analytics/index.js +0 -496
- package/bin/analytics/output.js +0 -75
- package/bin/analytics/types.js +0 -1
- package/bin/authenticatedFetch.js +0 -46
- package/bin/brokenLinks.js +0 -122
- package/bin/callbackServer.js +0 -65
- package/bin/cli.js +0 -813
- package/bin/comingSoon.js +0 -26
- package/bin/config.js +0 -78
- package/bin/constants.js +0 -16
- package/bin/deploy-base.js +0 -20
- package/bin/deploy-github-actions.js +0 -102
- package/bin/deploy-github-setup.js +0 -165
- package/bin/deploy-instructions.js +0 -71
- package/bin/deploy.js +0 -123
- package/bin/feedback.js +0 -36
- package/bin/format.js +0 -121
- package/bin/helpers.js +0 -238
- package/bin/idToken.js +0 -14
- package/bin/index.js +0 -102
- package/bin/init.js +0 -182
- package/bin/instructions.js +0 -101
- package/bin/keyring.js +0 -78
- package/bin/login.js +0 -123
- package/bin/logout.js +0 -18
- package/bin/mdxAccessibility.js +0 -113
- package/bin/mdxLinter.js +0 -55
- package/bin/middlewares/subdomainMiddleware.js +0 -28
- package/bin/middlewares/telemetryMiddleware.js +0 -61
- package/bin/migrate.js +0 -54
- package/bin/og.js +0 -145
- package/bin/openApiCheck.js +0 -99
- package/bin/resolveFiles.js +0 -114
- package/bin/score/client.js +0 -40
- package/bin/score/index.js +0 -211
- package/bin/score/types.js +0 -1
- package/bin/signup.js +0 -118
- package/bin/start.js +0 -36
- package/bin/status.js +0 -106
- package/bin/telemetry/client.js +0 -53
- package/bin/telemetry/distinctId.js +0 -68
- package/bin/telemetry/sessionId.js +0 -36
- package/bin/telemetry/track.js +0 -149
- package/bin/templates.js +0 -127
- package/bin/tokenRefresh.js +0 -50
- package/bin/tsconfig.build.tsbuildinfo +0 -1
- package/bin/update.js +0 -65
- package/bin/validate/command.js +0 -127
- package/bin/validate/engine.js +0 -154
- package/bin/validate/files.js +0 -163
- package/bin/validate/mdx.js +0 -238
- package/bin/validate/output.js +0 -44
- package/bin/validate/report.js +0 -11
- package/bin/validate/rules/build.js +0 -102
- package/bin/validate/rules/content/duplicateH1.js +0 -57
- package/bin/validate/rules/content/foreignSyntax.js +0 -120
- package/bin/validate/rules/content/katex.js +0 -34
- package/bin/validate/rules/content/missingSnippet.js +0 -34
- package/bin/validate/rules/content/undefinedVariable.js +0 -13
- package/bin/validate/rules/content/unknownComponent.js +0 -121
- package/bin/validate/rules/content/voidTags.js +0 -38
- package/bin/validate/rules/index.js +0 -21
- package/bin/validate/rules/openapi.js +0 -50
- package/bin/validate/rules/parseError.js +0 -7
- package/bin/validate/site.js +0 -57
- package/bin/validate/types.js +0 -1
- package/bin/vendor/converter.js +0 -30882
- package/bin/welcome.js +0 -108
- package/bin/workflows/client.js +0 -34
- package/bin/workflows/index.js +0 -269
- package/bin/workflows/types.js +0 -11
- package/scripts/bundle-converter.mjs +0 -26
- package/scripts/generate-logo.mjs +0 -79
- package/src/accessibility.ts +0 -180
- package/src/accessibilityCheck.tsx +0 -150
- package/src/addDomain.tsx +0 -206
- package/src/agent-auth.ts +0 -119
- package/src/agent-claim.ts +0 -124
- package/src/agent-credentials.ts +0 -104
- package/src/agent-deployment.ts +0 -116
- package/src/agent-http.ts +0 -34
- package/src/agent-setup-config.ts +0 -144
- package/src/agent-setup.ts +0 -165
- package/src/agent.ts +0 -56
- package/src/analytics/client.ts +0 -153
- package/src/analytics/dates.ts +0 -6
- package/src/analytics/filters.ts +0 -50
- package/src/analytics/format.ts +0 -13
- package/src/analytics/index.tsx +0 -599
- package/src/analytics/output.ts +0 -99
- package/src/analytics/types.ts +0 -145
- package/src/authenticatedFetch.ts +0 -42
- package/src/brokenLinks.tsx +0 -152
- package/src/callbackServer.ts +0 -64
- package/src/cli.tsx +0 -1105
- package/src/comingSoon.tsx +0 -29
- package/src/config.ts +0 -75
- package/src/constants.ts +0 -28
- package/src/deploy-base.ts +0 -18
- package/src/deploy-github-actions.ts +0 -139
- package/src/deploy-github-setup.ts +0 -189
- package/src/deploy-instructions.ts +0 -76
- package/src/deploy.ts +0 -165
- package/src/feedback.tsx +0 -31
- package/src/format.tsx +0 -82
- package/src/helpers.tsx +0 -279
- package/src/idToken.ts +0 -17
- package/src/index.ts +0 -109
- package/src/init.tsx +0 -237
- package/src/instructions.ts +0 -99
- package/src/keyring.ts +0 -65
- package/src/login.tsx +0 -166
- package/src/logout.tsx +0 -8
- package/src/mdxAccessibility.ts +0 -134
- package/src/mdxLinter.tsx +0 -88
- package/src/middlewares/subdomainMiddleware.ts +0 -20
- package/src/middlewares/telemetryMiddleware.ts +0 -55
- package/src/migrate.ts +0 -76
- package/src/og.tsx +0 -185
- package/src/openApiCheck.tsx +0 -125
- package/src/resolveFiles.ts +0 -101
- package/src/score/client.ts +0 -36
- package/src/score/index.tsx +0 -205
- package/src/score/types.ts +0 -15
- package/src/signup.tsx +0 -172
- package/src/start.ts +0 -27
- package/src/status.tsx +0 -129
- package/src/telemetry/client.ts +0 -46
- package/src/telemetry/distinctId.ts +0 -70
- package/src/telemetry/sessionId.ts +0 -40
- package/src/telemetry/track.ts +0 -163
- package/src/templates.tsx +0 -143
- package/src/tokenRefresh.ts +0 -53
- package/src/update.tsx +0 -89
- package/src/validate/command.tsx +0 -135
- package/src/validate/engine.ts +0 -210
- package/src/validate/files.ts +0 -249
- package/src/validate/mdx.ts +0 -290
- package/src/validate/output.tsx +0 -76
- package/src/validate/report.ts +0 -40
- package/src/validate/rules/build.ts +0 -146
- package/src/validate/rules/content/duplicateH1.ts +0 -78
- package/src/validate/rules/content/foreignSyntax.ts +0 -144
- package/src/validate/rules/content/katex.ts +0 -33
- package/src/validate/rules/content/missingSnippet.ts +0 -36
- package/src/validate/rules/content/undefinedVariable.ts +0 -20
- package/src/validate/rules/content/unknownComponent.ts +0 -130
- package/src/validate/rules/content/voidTags.ts +0 -43
- package/src/validate/rules/index.ts +0 -23
- package/src/validate/rules/openapi.ts +0 -59
- package/src/validate/rules/parseError.ts +0 -9
- package/src/validate/site.ts +0 -53
- package/src/validate/types.ts +0 -102
- package/src/vendor/converter.ts +0 -1
- package/src/welcome.ts +0 -154
- package/src/workflows/client.ts +0 -39
- package/src/workflows/index.tsx +0 -287
- package/src/workflows/types.ts +0 -73
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -10
- package/vitest.config.ts +0 -9
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import { execFile } 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 { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
GITHUB_WORKFLOW_PATH,
|
|
9
|
-
githubWorkflow,
|
|
10
|
-
parseGithubRemote,
|
|
11
|
-
setupGithubDeployment,
|
|
12
|
-
writeGithubWorkflow,
|
|
13
|
-
} from '../src/deploy-github-setup.js';
|
|
14
|
-
import { prepareAgentDeployment } from '../src/deploy.js';
|
|
15
|
-
|
|
16
|
-
vi.mock('node:child_process', async (importOriginal) => ({
|
|
17
|
-
...(await importOriginal<typeof import('node:child_process')>()),
|
|
18
|
-
execFile: vi.fn(),
|
|
19
|
-
}));
|
|
20
|
-
vi.mock('../src/deploy.js', async (importOriginal) => ({
|
|
21
|
-
...(await importOriginal<typeof import('../src/deploy.js')>()),
|
|
22
|
-
prepareAgentDeployment: vi.fn(),
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
const apiUrl = 'https://leaves.mintlify.com';
|
|
26
|
-
const site = {
|
|
27
|
-
status: 'ready' as const,
|
|
28
|
-
created: false,
|
|
29
|
-
deploymentId: 'id',
|
|
30
|
-
subdomain: 'my-docs',
|
|
31
|
-
remote: 'https://git.example.com/repo.git',
|
|
32
|
-
branch: 'main' as const,
|
|
33
|
-
expiresAt: '2026-12-01T00:00:00.000Z',
|
|
34
|
-
};
|
|
35
|
-
const credentials = {
|
|
36
|
-
registrationId: 'reg',
|
|
37
|
-
issuer: 'https://auth.example.com',
|
|
38
|
-
assertion: 'assertion',
|
|
39
|
-
claimToken: 'claim',
|
|
40
|
-
accessToken: 'access',
|
|
41
|
-
};
|
|
42
|
-
let root: string;
|
|
43
|
-
|
|
44
|
-
function stubCommands(outputs: Record<string, string | NodeJS.ErrnoException>) {
|
|
45
|
-
vi.mocked(execFile).mockImplementation(((
|
|
46
|
-
command: string,
|
|
47
|
-
args: string[],
|
|
48
|
-
_options: unknown,
|
|
49
|
-
callback: (error: Error | null, stdout: string) => void
|
|
50
|
-
) => {
|
|
51
|
-
const output = outputs[`${command} ${args[0]}`];
|
|
52
|
-
if (output instanceof Error) callback(output, '');
|
|
53
|
-
else if (output === undefined) callback(new Error('unexpected'), '');
|
|
54
|
-
else callback(null, `${output}\n`);
|
|
55
|
-
}) as unknown as typeof execFile);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
beforeEach(async () => {
|
|
59
|
-
vi.resetAllMocks();
|
|
60
|
-
root = await fs.realpath(await fs.mkdtemp(path.join(os.tmpdir(), 'mint-github-')));
|
|
61
|
-
await fs.writeFile(path.join(root, 'docs.json'), '{}');
|
|
62
|
-
stubCommands({
|
|
63
|
-
'git rev-parse': root,
|
|
64
|
-
'git remote': 'git@github.com:acme/docs.git',
|
|
65
|
-
'gh api': JSON.stringify({ id: 123, full_name: 'acme/docs', default_branch: 'trunk' }),
|
|
66
|
-
});
|
|
67
|
-
vi.mocked(prepareAgentDeployment).mockResolvedValue({
|
|
68
|
-
status: 'ready',
|
|
69
|
-
projectType: 'site',
|
|
70
|
-
site,
|
|
71
|
-
write: { remote: site.remote, branch: 'main', token: 'write', tokenExpiresAt: site.expiresAt },
|
|
72
|
-
created: false,
|
|
73
|
-
credentials,
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
afterEach(async () => {
|
|
77
|
-
vi.unstubAllGlobals();
|
|
78
|
-
await fs.rm(root, { recursive: true, force: true });
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe('parseGithubRemote', () => {
|
|
82
|
-
it.each([
|
|
83
|
-
'https://github.com/acme/docs',
|
|
84
|
-
'https://github.com/acme/docs.git',
|
|
85
|
-
'https://user@github.com/acme/docs.git',
|
|
86
|
-
'git@github.com:acme/docs.git',
|
|
87
|
-
'ssh://git@github.com/acme/docs.git',
|
|
88
|
-
'ssh://git@github.com:22/acme/docs',
|
|
89
|
-
])('parses %s', (remote) => {
|
|
90
|
-
expect(parseGithubRemote(remote)).toEqual({ owner: 'acme', repo: 'docs' });
|
|
91
|
-
});
|
|
92
|
-
it('keeps dots in repository names', () => {
|
|
93
|
-
expect(parseGithubRemote('git@github.com:acme/docs.site.git')).toEqual({
|
|
94
|
-
owner: 'acme',
|
|
95
|
-
repo: 'docs.site',
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
it.each(['https://gitlab.com/acme/docs.git', 'git@example.com:acme/docs.git', 'docs'])(
|
|
99
|
-
'rejects %s',
|
|
100
|
-
(remote) => {
|
|
101
|
-
expect(parseGithubRemote(remote)).toBeNull();
|
|
102
|
-
}
|
|
103
|
-
);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
describe('GitHub workflow', () => {
|
|
107
|
-
it('deploys the subdomain on pushes to the branch with OIDC', () => {
|
|
108
|
-
expect(githubWorkflow('release,stable', 'my-docs')).toBe(`name: Deploy to Mintlify
|
|
109
|
-
on:
|
|
110
|
-
push:
|
|
111
|
-
branches: ["release,stable"]
|
|
112
|
-
permissions:
|
|
113
|
-
id-token: write
|
|
114
|
-
contents: read
|
|
115
|
-
concurrency:
|
|
116
|
-
group: mintlify-deploy
|
|
117
|
-
cancel-in-progress: true
|
|
118
|
-
jobs:
|
|
119
|
-
deploy:
|
|
120
|
-
runs-on: ubuntu-latest
|
|
121
|
-
steps:
|
|
122
|
-
- uses: actions/checkout@v4
|
|
123
|
-
- run: npx mint@latest deploy --subdomain my-docs
|
|
124
|
-
`);
|
|
125
|
-
});
|
|
126
|
-
it('deploys only the docs folder of a monorepo', () => {
|
|
127
|
-
const workflow = githubWorkflow('main', 'my-docs', 'apps/docs');
|
|
128
|
-
expect(workflow).toContain(' paths: ["apps/docs/**", ".github/workflows/mintlify.yml"]\n');
|
|
129
|
-
expect(workflow).toContain(
|
|
130
|
-
' - run: npx mint@latest deploy --subdomain my-docs --directory apps/docs\n'
|
|
131
|
-
);
|
|
132
|
-
expect(githubWorkflow('main', 'my-docs', 'my docs')).toContain('--directory "my docs"');
|
|
133
|
-
});
|
|
134
|
-
it('creates the workflow and accepts identical contents', async () => {
|
|
135
|
-
await expect(writeGithubWorkflow(root, 'a')).resolves.toBe('created');
|
|
136
|
-
await expect(writeGithubWorkflow(root, 'a')).resolves.toBe('unchanged');
|
|
137
|
-
expect(await fs.readFile(path.join(root, GITHUB_WORKFLOW_PATH), 'utf8')).toBe('a');
|
|
138
|
-
});
|
|
139
|
-
it('does not overwrite a different workflow without --force', async () => {
|
|
140
|
-
await writeGithubWorkflow(root, 'a');
|
|
141
|
-
await expect(writeGithubWorkflow(root, 'b')).rejects.toThrow('--force');
|
|
142
|
-
expect(await fs.readFile(path.join(root, GITHUB_WORKFLOW_PATH), 'utf8')).toBe('a');
|
|
143
|
-
await expect(writeGithubWorkflow(root, 'b', true)).resolves.toBe('updated');
|
|
144
|
-
expect(await fs.readFile(path.join(root, GITHUB_WORKFLOW_PATH), 'utf8')).toBe('b');
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
describe('mint deploy --github', () => {
|
|
149
|
-
const options = { apiUrl, directory: '', subdomain: 'my-docs' };
|
|
150
|
-
|
|
151
|
-
it('trusts the repository and writes the workflow', async () => {
|
|
152
|
-
const request = vi
|
|
153
|
-
.fn()
|
|
154
|
-
.mockResolvedValue(
|
|
155
|
-
new Response(JSON.stringify({ subdomain: 'my-docs', trustedRepos: [] }), { status: 200 })
|
|
156
|
-
);
|
|
157
|
-
vi.stubGlobal('fetch', request);
|
|
158
|
-
|
|
159
|
-
const result = await setupGithubDeployment({ ...options, directory: root }, vi.fn());
|
|
160
|
-
|
|
161
|
-
expect(vi.mocked(execFile).mock.calls.find(([command]) => command === 'gh')?.[1]).toEqual([
|
|
162
|
-
'api',
|
|
163
|
-
'repos/acme/docs',
|
|
164
|
-
'--jq',
|
|
165
|
-
'{id: .id, full_name: .full_name, default_branch: .default_branch}',
|
|
166
|
-
]);
|
|
167
|
-
expect(request.mock.calls[0]?.[0]).toBe(`${apiUrl}/api/agent/deployments/trusted-repos`);
|
|
168
|
-
expect(request.mock.calls[0]?.[1].headers.Authorization).toBe('Bearer access');
|
|
169
|
-
expect(JSON.parse(request.mock.calls[0]?.[1].body)).toEqual({
|
|
170
|
-
repositoryId: '123',
|
|
171
|
-
repository: 'acme/docs',
|
|
172
|
-
branch: 'trunk',
|
|
173
|
-
});
|
|
174
|
-
expect(await fs.readFile(path.join(root, GITHUB_WORKFLOW_PATH), 'utf8')).toBe(
|
|
175
|
-
githubWorkflow('trunk', 'my-docs')
|
|
176
|
-
);
|
|
177
|
-
expect(result).toMatchObject({
|
|
178
|
-
siteUrl: 'https://my-docs.mintlify.site/',
|
|
179
|
-
repository: 'acme/docs',
|
|
180
|
-
branch: 'trunk',
|
|
181
|
-
workflow: 'created',
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it('writes the workflow at the repository root for a docs subdirectory', async () => {
|
|
186
|
-
vi.stubGlobal(
|
|
187
|
-
'fetch',
|
|
188
|
-
vi
|
|
189
|
-
.fn()
|
|
190
|
-
.mockResolvedValue(
|
|
191
|
-
new Response(JSON.stringify({ subdomain: 'my-docs', trustedRepos: [] }), { status: 200 })
|
|
192
|
-
)
|
|
193
|
-
);
|
|
194
|
-
const docs = path.join(root, 'docs');
|
|
195
|
-
await fs.mkdir(docs);
|
|
196
|
-
await fs.writeFile(path.join(docs, 'docs.json'), '{}');
|
|
197
|
-
await setupGithubDeployment({ ...options, directory: docs }, vi.fn());
|
|
198
|
-
expect(await fs.readFile(path.join(root, GITHUB_WORKFLOW_PATH), 'utf8')).toBe(
|
|
199
|
-
githubWorkflow('trunk', 'my-docs', 'docs')
|
|
200
|
-
);
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
it('requires docs.json in the docs directory before provisioning', async () => {
|
|
204
|
-
const docs = path.join(root, 'empty');
|
|
205
|
-
await fs.mkdir(docs);
|
|
206
|
-
await expect(setupGithubDeployment({ ...options, directory: docs }, vi.fn())).rejects.toThrow(
|
|
207
|
-
'No docs.json'
|
|
208
|
-
);
|
|
209
|
-
expect(prepareAgentDeployment).not.toHaveBeenCalled();
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it('rejects non-GitHub origins before provisioning', async () => {
|
|
213
|
-
stubCommands({ 'git rev-parse': root, 'git remote': 'https://gitlab.com/acme/docs.git' });
|
|
214
|
-
await expect(setupGithubDeployment({ ...options, directory: root }, vi.fn())).rejects.toThrow(
|
|
215
|
-
'not a github.com repository'
|
|
216
|
-
);
|
|
217
|
-
expect(prepareAgentDeployment).not.toHaveBeenCalled();
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it('explains when gh is missing', async () => {
|
|
221
|
-
stubCommands({
|
|
222
|
-
'git rev-parse': root,
|
|
223
|
-
'git remote': 'https://github.com/acme/docs',
|
|
224
|
-
'gh api': Object.assign(new Error('spawn gh ENOENT'), { code: 'ENOENT' }),
|
|
225
|
-
});
|
|
226
|
-
await expect(setupGithubDeployment({ ...options, directory: root }, vi.fn())).rejects.toThrow(
|
|
227
|
-
'GitHub CLI (gh) is required'
|
|
228
|
-
);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it('does not support claimed sites yet', async () => {
|
|
232
|
-
vi.mocked(prepareAgentDeployment).mockResolvedValue({ status: 'claimed' });
|
|
233
|
-
const request = vi.fn();
|
|
234
|
-
vi.stubGlobal('fetch', request);
|
|
235
|
-
await expect(setupGithubDeployment({ ...options, directory: root }, vi.fn())).rejects.toThrow(
|
|
236
|
-
'not supported yet'
|
|
237
|
-
);
|
|
238
|
-
expect(request).not.toHaveBeenCalled();
|
|
239
|
-
});
|
|
240
|
-
});
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { createAgentClaimLink } from '../src/agent-claim.js';
|
|
4
|
-
import { DASHBOARD_URL } from '../src/constants.js';
|
|
5
|
-
import { deploymentInstructions, DEPLOY_HELP } from '../src/deploy-instructions.js';
|
|
6
|
-
import { trackEvent } from '../src/telemetry/track.js';
|
|
7
|
-
import { renderWelcome } from '../src/welcome.js';
|
|
8
|
-
|
|
9
|
-
vi.mock('../src/agent-auth.js', async (importOriginal) => ({
|
|
10
|
-
...(await importOriginal<typeof import('../src/agent-auth.js')>()),
|
|
11
|
-
discoverAgentAuth: async () => ({
|
|
12
|
-
issuer: 'https://auth.example.com',
|
|
13
|
-
agent_auth: { claim_endpoint: 'https://auth.example.com/agent/identity/claim' },
|
|
14
|
-
}),
|
|
15
|
-
}));
|
|
16
|
-
vi.mock('../src/telemetry/track.js', () => ({ trackEvent: vi.fn() }));
|
|
17
|
-
afterEach(() => vi.unstubAllGlobals());
|
|
18
|
-
const credentials = {
|
|
19
|
-
registrationId: 'reg',
|
|
20
|
-
issuer: 'https://auth.example.com',
|
|
21
|
-
assertion: 'assertion-secret',
|
|
22
|
-
claimToken: 'claim-secret',
|
|
23
|
-
};
|
|
24
|
-
const site = {
|
|
25
|
-
status: 'ready' as const,
|
|
26
|
-
deploymentId: 'id',
|
|
27
|
-
subdomain: 'docs',
|
|
28
|
-
remote: 'https://git.example.com/repo',
|
|
29
|
-
branch: 'main' as const,
|
|
30
|
-
expiresAt: '2026-12-01T00:00:00.000Z',
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
describe('deploy help and claim handoff', () => {
|
|
34
|
-
it('uses the actual claim attempt API and returns its human-facing link', async () => {
|
|
35
|
-
const request = vi.fn().mockResolvedValue(
|
|
36
|
-
new Response(
|
|
37
|
-
JSON.stringify({
|
|
38
|
-
attempt: {
|
|
39
|
-
verification_uri:
|
|
40
|
-
'https://auth.example.com/verify?token=attempt%2Btoken%26value&other=ignored',
|
|
41
|
-
},
|
|
42
|
-
})
|
|
43
|
-
)
|
|
44
|
-
);
|
|
45
|
-
vi.stubGlobal('fetch', request);
|
|
46
|
-
expect(
|
|
47
|
-
await createAgentClaimLink('https://api.example.com', credentials, 'user@example.com')
|
|
48
|
-
).toBe(`${DASHBOARD_URL}/agent-claim?token=attempt%2Btoken%26value®istration=reg`);
|
|
49
|
-
expect(trackEvent).toHaveBeenCalledWith('agent_signup.claim_started', {
|
|
50
|
-
registration_id: 'reg',
|
|
51
|
-
});
|
|
52
|
-
expect(JSON.parse(request.mock.calls[0]?.[1].body)).toEqual({
|
|
53
|
-
type: 'service_auth',
|
|
54
|
-
claim_token: 'claim-secret',
|
|
55
|
-
login_hint: 'user@example.com',
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
it('rejects a verification link without an attempt token', async () => {
|
|
59
|
-
vi.stubGlobal(
|
|
60
|
-
'fetch',
|
|
61
|
-
vi.fn().mockResolvedValue(
|
|
62
|
-
new Response(
|
|
63
|
-
JSON.stringify({
|
|
64
|
-
attempt: { verification_uri: 'https://auth.example.com/verify' },
|
|
65
|
-
})
|
|
66
|
-
)
|
|
67
|
-
)
|
|
68
|
-
);
|
|
69
|
-
await expect(
|
|
70
|
-
createAgentClaimLink('https://api.example.com', credentials, 'user@example.com')
|
|
71
|
-
).rejects.toThrow();
|
|
72
|
-
});
|
|
73
|
-
it('keeps Git operations with the agent and omits identity credentials', () => {
|
|
74
|
-
const text = deploymentInstructions(
|
|
75
|
-
{
|
|
76
|
-
status: 'ready',
|
|
77
|
-
projectType: 'site',
|
|
78
|
-
created: true,
|
|
79
|
-
site,
|
|
80
|
-
credentials,
|
|
81
|
-
write: {
|
|
82
|
-
remote: site.remote,
|
|
83
|
-
branch: site.branch,
|
|
84
|
-
token: 'write-secret',
|
|
85
|
-
tokenExpiresAt: site.expiresAt,
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
'https://app.example.com/claim'
|
|
89
|
-
);
|
|
90
|
-
expect(text).toContain('Do not force-push');
|
|
91
|
-
expect(text).toContain('mint claim --code <code>');
|
|
92
|
-
expect(text).not.toContain('/auth.md');
|
|
93
|
-
expect(text).toContain('docs.json');
|
|
94
|
-
expect(text).toContain('https://app.example.com/claim');
|
|
95
|
-
expect(text).not.toContain('assertion-secret');
|
|
96
|
-
expect(text).not.toContain('claim-secret');
|
|
97
|
-
expect(text).not.toContain('write-secret');
|
|
98
|
-
});
|
|
99
|
-
it('gives base claim, clone, and push steps without site build or GitHub hints', () => {
|
|
100
|
-
const write = {
|
|
101
|
-
remote: site.remote,
|
|
102
|
-
branch: site.branch,
|
|
103
|
-
token: 'write-secret',
|
|
104
|
-
tokenExpiresAt: site.expiresAt,
|
|
105
|
-
};
|
|
106
|
-
const text = deploymentInstructions({
|
|
107
|
-
status: 'ready',
|
|
108
|
-
projectType: 'workspace',
|
|
109
|
-
created: true,
|
|
110
|
-
site,
|
|
111
|
-
credentials,
|
|
112
|
-
write,
|
|
113
|
-
});
|
|
114
|
-
expect(text).toContain('mint deploy --base --email <their-email>');
|
|
115
|
-
expect(text).toContain('mint claim --code <code>');
|
|
116
|
-
expect(text).toContain(
|
|
117
|
-
`git -c http.${site.remote}.extraHeader="Authorization: Bearer write-secret" clone ${site.remote} ${site.subdomain}`
|
|
118
|
-
);
|
|
119
|
-
expect(text).toContain(`mint deploy --base --push ${site.subdomain}`);
|
|
120
|
-
expect(text).not.toContain('Git examples');
|
|
121
|
-
expect(text.indexOf('--push')).toBeLessThan(text.indexOf('mint claim --code'));
|
|
122
|
-
expect(text).not.toContain('build');
|
|
123
|
-
expect(text).not.toContain('--github');
|
|
124
|
-
});
|
|
125
|
-
it('gives the base claim link when one was created', () => {
|
|
126
|
-
const text = deploymentInstructions(
|
|
127
|
-
{
|
|
128
|
-
status: 'ready',
|
|
129
|
-
projectType: 'workspace',
|
|
130
|
-
created: true,
|
|
131
|
-
site,
|
|
132
|
-
credentials,
|
|
133
|
-
write: {
|
|
134
|
-
remote: site.remote,
|
|
135
|
-
branch: site.branch,
|
|
136
|
-
token: 't',
|
|
137
|
-
tokenExpiresAt: site.expiresAt,
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
'https://claim.example.com/x'
|
|
141
|
-
);
|
|
142
|
-
expect(text).toContain('Send the user this link: https://claim.example.com/x');
|
|
143
|
-
expect(text).not.toContain('--email <their-email>');
|
|
144
|
-
});
|
|
145
|
-
it('documents the command in root help and explains that it does not push files', () => {
|
|
146
|
-
expect(renderWelcome({ packageName: 'mint', signedIn: false })).toContain('deploy');
|
|
147
|
-
expect(DEPLOY_HELP).toContain('Commit and push the documentation yourself');
|
|
148
|
-
expect(DEPLOY_HELP).toContain('--new');
|
|
149
|
-
expect(DEPLOY_HELP).toContain('mint claim --code <code>');
|
|
150
|
-
expect(renderWelcome({ packageName: 'mint', signedIn: false })).toContain('claim --email');
|
|
151
|
-
expect(DEPLOY_HELP).toContain('ask the user for their email');
|
|
152
|
-
expect(DEPLOY_HELP).toContain('--base cannot be combined with --github');
|
|
153
|
-
expect(DEPLOY_HELP).toContain('mint deploy --base --push <clone-directory>');
|
|
154
|
-
});
|
|
155
|
-
});
|
package/__test__/deploy.test.ts
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import * as auth from '../src/agent-auth.js';
|
|
5
|
-
import * as storage from '../src/agent-credentials.js';
|
|
6
|
-
import * as deployment from '../src/agent-deployment.js';
|
|
7
|
-
import * as config from '../src/config.js';
|
|
8
|
-
import { DASHBOARD_URL } from '../src/constants.js';
|
|
9
|
-
import { prepareAgentDeployment, formatDeployment } from '../src/deploy.js';
|
|
10
|
-
import { trackEvent } from '../src/telemetry/track.js';
|
|
11
|
-
|
|
12
|
-
vi.mock('../src/agent-auth.js');
|
|
13
|
-
vi.mock('../src/agent-credentials.js');
|
|
14
|
-
vi.mock('../src/agent-deployment.js');
|
|
15
|
-
vi.mock('../src/config.js');
|
|
16
|
-
vi.mock('../src/telemetry/track.js');
|
|
17
|
-
|
|
18
|
-
const credentials = {
|
|
19
|
-
registrationId: 'reg_1',
|
|
20
|
-
issuer: 'https://auth.example.com',
|
|
21
|
-
assertion: 'assertion',
|
|
22
|
-
claimToken: 'claim',
|
|
23
|
-
};
|
|
24
|
-
const site = {
|
|
25
|
-
status: 'ready' as const,
|
|
26
|
-
created: true,
|
|
27
|
-
deploymentId: 'id',
|
|
28
|
-
subdomain: 'allocated',
|
|
29
|
-
remote: 'https://git.example.com/repo',
|
|
30
|
-
branch: 'main' as const,
|
|
31
|
-
expiresAt: '2026-12-01T00:00:00.000Z',
|
|
32
|
-
};
|
|
33
|
-
const write = {
|
|
34
|
-
remote: site.remote,
|
|
35
|
-
branch: site.branch,
|
|
36
|
-
token: 'write',
|
|
37
|
-
tokenExpiresAt: site.expiresAt,
|
|
38
|
-
};
|
|
39
|
-
const options = {
|
|
40
|
-
apiUrl: 'https://api.example.com',
|
|
41
|
-
directory: path.resolve('docs'),
|
|
42
|
-
subdomain: 'requested',
|
|
43
|
-
};
|
|
44
|
-
const warn = vi.fn();
|
|
45
|
-
|
|
46
|
-
beforeEach(() => {
|
|
47
|
-
vi.resetAllMocks();
|
|
48
|
-
vi.mocked(storage.loadAgentCredentials).mockResolvedValue(null);
|
|
49
|
-
vi.mocked(storage.saveAgentCredentials).mockResolvedValue(undefined);
|
|
50
|
-
vi.mocked(auth.registerAgent).mockResolvedValue(credentials);
|
|
51
|
-
vi.mocked(auth.exchangeAgentToken).mockImplementation(async (_, value) => ({
|
|
52
|
-
...value,
|
|
53
|
-
accessToken: 'access',
|
|
54
|
-
}));
|
|
55
|
-
vi.mocked(auth.getAgentIdentity).mockResolvedValue({
|
|
56
|
-
registrationId: 'reg_1',
|
|
57
|
-
identityType: 'anonymous',
|
|
58
|
-
});
|
|
59
|
-
vi.mocked(deployment.provisionAgentSite).mockResolvedValue(site);
|
|
60
|
-
vi.mocked(deployment.getAgentWriteToken).mockResolvedValue(write);
|
|
61
|
-
vi.mocked(config.setAgentSiteMetadata).mockResolvedValue(undefined);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe('mint deploy', () => {
|
|
65
|
-
it('tracks discovery and registration for a new agent', async () => {
|
|
66
|
-
await prepareAgentDeployment(options, warn);
|
|
67
|
-
expect(vi.mocked(trackEvent).mock.calls).toEqual([
|
|
68
|
-
['agent_signup.discovered', { registration_id: 'reg_1' }],
|
|
69
|
-
['agent_signup.registered', { registration_id: 'reg_1' }],
|
|
70
|
-
[
|
|
71
|
-
'cli.deploy.provisioned',
|
|
72
|
-
{ registration_id: 'reg_1', deployment_id: 'id', subdomain: 'allocated', created: true },
|
|
73
|
-
],
|
|
74
|
-
]);
|
|
75
|
-
});
|
|
76
|
-
it('tracks only discovery for a saved registration', async () => {
|
|
77
|
-
vi.mocked(storage.loadAgentCredentials).mockResolvedValue(credentials);
|
|
78
|
-
await prepareAgentDeployment(options, warn);
|
|
79
|
-
expect(vi.mocked(trackEvent).mock.calls).toEqual([
|
|
80
|
-
['agent_signup.discovered', { registration_id: 'reg_1' }],
|
|
81
|
-
[
|
|
82
|
-
'cli.deploy.provisioned',
|
|
83
|
-
{ registration_id: 'reg_1', deployment_id: 'id', subdomain: 'allocated', created: true },
|
|
84
|
-
],
|
|
85
|
-
]);
|
|
86
|
-
});
|
|
87
|
-
it('tracks a provisioned site when write access fails', async () => {
|
|
88
|
-
vi.mocked(deployment.getAgentWriteToken).mockRejectedValue(new Error('timeout'));
|
|
89
|
-
await expect(prepareAgentDeployment(options, warn)).rejects.toThrow('timeout');
|
|
90
|
-
expect(vi.mocked(trackEvent)).toHaveBeenCalledWith('cli.deploy.provisioned', {
|
|
91
|
-
registration_id: 'reg_1',
|
|
92
|
-
deployment_id: 'id',
|
|
93
|
-
subdomain: 'allocated',
|
|
94
|
-
created: true,
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
it.each([
|
|
98
|
-
['https://leaves.mintlify.com', 'https://allocated.mintlify.site/'],
|
|
99
|
-
['https://leaves-dev.mintlify.com', 'https://allocated.mint-dev.mintlify.me/'],
|
|
100
|
-
])('prints the site URL for %s', async (apiUrl, siteUrl) => {
|
|
101
|
-
const result = await prepareAgentDeployment({ ...options, apiUrl }, warn);
|
|
102
|
-
expect(formatDeployment(result, apiUrl)).toContain(`Site: ${siteUrl}`);
|
|
103
|
-
});
|
|
104
|
-
it('provisions a base and prints its editor link instead of a site URL', async () => {
|
|
105
|
-
vi.mocked(deployment.provisionAgentSite).mockResolvedValue({ ...site, orgSlug: 'acme' });
|
|
106
|
-
const result = await prepareAgentDeployment({ ...options, base: true }, warn);
|
|
107
|
-
expect(deployment.provisionAgentSite).toHaveBeenCalledWith(options.apiUrl, 'access', {
|
|
108
|
-
subdomain: 'requested',
|
|
109
|
-
orgName: undefined,
|
|
110
|
-
projectType: 'workspace',
|
|
111
|
-
});
|
|
112
|
-
const text = formatDeployment(result, options.apiUrl);
|
|
113
|
-
expect(text).toContain(`Editor: ${new URL('/acme/allocated/editor', DASHBOARD_URL)}`);
|
|
114
|
-
expect(text).not.toContain('Site:');
|
|
115
|
-
expect(text).not.toContain('build');
|
|
116
|
-
expect(text).not.toContain('Write token');
|
|
117
|
-
});
|
|
118
|
-
it('fails before provisioning when credentials cannot be saved', async () => {
|
|
119
|
-
vi.mocked(storage.saveAgentCredentials).mockRejectedValue(new Error('disk full'));
|
|
120
|
-
await expect(prepareAgentDeployment(options, warn)).rejects.toThrow('disk full');
|
|
121
|
-
expect(deployment.provisionAgentSite).not.toHaveBeenCalled();
|
|
122
|
-
});
|
|
123
|
-
it('persists the exchanged access token for later commands', async () => {
|
|
124
|
-
await prepareAgentDeployment(options, warn);
|
|
125
|
-
expect(storage.saveAgentCredentials).toHaveBeenLastCalledWith(
|
|
126
|
-
options.apiUrl,
|
|
127
|
-
options.directory,
|
|
128
|
-
{ ...credentials, accessToken: 'access' }
|
|
129
|
-
);
|
|
130
|
-
});
|
|
131
|
-
it('reuses the current registration and the saved site name', async () => {
|
|
132
|
-
vi.mocked(storage.loadAgentCredentials).mockResolvedValue(credentials);
|
|
133
|
-
vi.mocked(config.getAgentSiteMetadata).mockReturnValue({
|
|
134
|
-
registrationId: 'reg_1',
|
|
135
|
-
subdomain: 'allocated',
|
|
136
|
-
});
|
|
137
|
-
await prepareAgentDeployment({ ...options, subdomain: undefined }, warn);
|
|
138
|
-
expect(auth.registerAgent).not.toHaveBeenCalled();
|
|
139
|
-
expect(deployment.provisionAgentSite).toHaveBeenCalledWith(options.apiUrl, 'access', {
|
|
140
|
-
subdomain: 'allocated',
|
|
141
|
-
orgName: undefined,
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
it('starts a new registration only when explicitly requested or the site expired', async () => {
|
|
145
|
-
vi.mocked(storage.loadAgentCredentials).mockResolvedValue(credentials);
|
|
146
|
-
await prepareAgentDeployment({ ...options, newSite: true }, warn);
|
|
147
|
-
expect(storage.loadAgentCredentials).not.toHaveBeenCalled();
|
|
148
|
-
expect(auth.registerAgent).toHaveBeenCalledTimes(1);
|
|
149
|
-
});
|
|
150
|
-
it('requires an explicit site name for --new even when a previous name is saved', async () => {
|
|
151
|
-
vi.mocked(config.getAgentSiteMetadata).mockReturnValue({
|
|
152
|
-
registrationId: 'reg_1',
|
|
153
|
-
subdomain: 'allocated',
|
|
154
|
-
});
|
|
155
|
-
await expect(
|
|
156
|
-
prepareAgentDeployment({ ...options, newSite: true, subdomain: undefined }, warn)
|
|
157
|
-
).rejects.toThrow('Choose a site name with --subdomain');
|
|
158
|
-
expect(auth.discoverAgentAuth).not.toHaveBeenCalled();
|
|
159
|
-
expect(auth.registerAgent).not.toHaveBeenCalled();
|
|
160
|
-
expect(storage.saveAgentCredentials).not.toHaveBeenCalled();
|
|
161
|
-
expect(deployment.provisionAgentSite).not.toHaveBeenCalled();
|
|
162
|
-
});
|
|
163
|
-
it('starts again on confirmed deployment expiry', async () => {
|
|
164
|
-
vi.mocked(storage.loadAgentCredentials).mockResolvedValue(credentials);
|
|
165
|
-
vi.mocked(deployment.provisionAgentSite).mockResolvedValueOnce({
|
|
166
|
-
status: 'expired',
|
|
167
|
-
created: false,
|
|
168
|
-
code: 'deployment_already_exists',
|
|
169
|
-
deploymentId: 'old',
|
|
170
|
-
subdomain: 'old',
|
|
171
|
-
});
|
|
172
|
-
await prepareAgentDeployment(options, warn);
|
|
173
|
-
expect(auth.registerAgent).toHaveBeenCalledTimes(1);
|
|
174
|
-
expect(deployment.provisionAgentSite).toHaveBeenCalledTimes(2);
|
|
175
|
-
});
|
|
176
|
-
it('does not provision for a claimed identity', async () => {
|
|
177
|
-
vi.mocked(auth.getAgentIdentity).mockResolvedValue({
|
|
178
|
-
registrationId: 'reg_1',
|
|
179
|
-
identityType: 'user_bound',
|
|
180
|
-
userId: 'user',
|
|
181
|
-
orgId: 'org',
|
|
182
|
-
});
|
|
183
|
-
const result = await prepareAgentDeployment(options, warn);
|
|
184
|
-
expect(formatDeployment(result, options.apiUrl)).toContain('--new');
|
|
185
|
-
expect(deployment.provisionAgentSite).not.toHaveBeenCalled();
|
|
186
|
-
});
|
|
187
|
-
it('does not replace an existing identity after an authentication outage', async () => {
|
|
188
|
-
vi.mocked(storage.loadAgentCredentials).mockResolvedValue(credentials);
|
|
189
|
-
vi.mocked(auth.getAgentIdentity).mockRejectedValue(new Error('unavailable'));
|
|
190
|
-
await expect(prepareAgentDeployment(options, warn)).rejects.toThrow('unavailable');
|
|
191
|
-
expect(auth.registerAgent).not.toHaveBeenCalled();
|
|
192
|
-
});
|
|
193
|
-
it('does not create a site after failing to read known credentials', async () => {
|
|
194
|
-
vi.mocked(config.getAgentSiteMetadata).mockReturnValue({
|
|
195
|
-
registrationId: 'reg_1',
|
|
196
|
-
subdomain: 'allocated',
|
|
197
|
-
});
|
|
198
|
-
vi.mocked(storage.loadAgentCredentials).mockRejectedValue(new Error('locked'));
|
|
199
|
-
await expect(prepareAgentDeployment(options, warn)).rejects.toThrow('Could not read');
|
|
200
|
-
expect(auth.registerAgent).not.toHaveBeenCalled();
|
|
201
|
-
});
|
|
202
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { API_URL } from '../src/constants.js';
|
|
4
|
-
import { sendFeedback } from '../src/feedback.js';
|
|
5
|
-
|
|
6
|
-
const fetchMock = vi.fn();
|
|
7
|
-
vi.stubGlobal('fetch', fetchMock);
|
|
8
|
-
|
|
9
|
-
const input = { message: 'mint dev crashed', clientId: 'c1', category: 'bug' as const };
|
|
10
|
-
const respond = (status: number) => fetchMock.mockResolvedValue(new Response('{}', { status }));
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
fetchMock.mockReset();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
describe('mint feedback', () => {
|
|
17
|
-
it('posts the feedback with the cli source and no login', async () => {
|
|
18
|
-
respond(201);
|
|
19
|
-
expect(await sendFeedback(input)).toBeUndefined();
|
|
20
|
-
const [url, init] = fetchMock.mock.calls[0]!;
|
|
21
|
-
expect(url).toBe(`${API_URL}/api/cli/feedback`);
|
|
22
|
-
expect(init?.method).toBe('POST');
|
|
23
|
-
expect(init?.headers).not.toHaveProperty('Authorization');
|
|
24
|
-
expect(JSON.parse(String(init?.body))).toEqual({ ...input, source: 'cli' });
|
|
25
|
-
});
|
|
26
|
-
it('reports a network failure', async () => {
|
|
27
|
-
fetchMock.mockRejectedValue(new Error('fetch failed'));
|
|
28
|
-
expect(await sendFeedback(input)).toBe('could not reach the server');
|
|
29
|
-
});
|
|
30
|
-
it('reports a server error', async () => {
|
|
31
|
-
respond(400);
|
|
32
|
-
expect(await sendFeedback(input)).toBe('could not send feedback (HTTP 400)');
|
|
33
|
-
});
|
|
34
|
-
});
|