@myrialabs/clopen 0.4.38 → 0.4.40
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/backend/auth/permissions.ts +48 -0
- package/backend/chat/stream-manager.ts +1 -1
- package/backend/database/crypto/secret-columns.ts +9 -1
- package/backend/database/migrations/075_create_deploy_bindings.ts +54 -0
- package/backend/database/migrations/076_remove_memory_code_graph.ts +229 -0
- package/backend/database/migrations/077_create_integration_db_links.ts +150 -0
- package/backend/database/migrations/078_create_worktree_branch_tables.ts +158 -0
- package/backend/database/migrations/index.ts +28 -0
- package/backend/database/queries/db-client-connection-queries.ts +19 -0
- package/backend/database/queries/deploy-queries.ts +124 -0
- package/backend/database/queries/graph-queries.ts +291 -247
- package/backend/database/queries/index.ts +10 -0
- package/backend/database/queries/integration-db-link-queries.ts +168 -0
- package/backend/database/queries/integration-queries.ts +34 -6
- package/backend/database/queries/worktree-branch-queries.ts +331 -0
- package/backend/db-client/cloning.test.ts +161 -0
- package/backend/db-client/cloning.ts +672 -0
- package/backend/db-client/connection-url.test.ts +117 -0
- package/backend/db-client/connection-url.ts +126 -0
- package/backend/db-client/drivers/mongodb.ts +2 -14
- package/backend/db-client/drivers/mysql.ts +2 -8
- package/backend/db-client/drivers/postgres.ts +10 -13
- package/backend/db-client/drivers/redis.ts +2 -6
- package/backend/db-client/env/detect.ts +438 -0
- package/backend/db-client/env/diff.ts +94 -0
- package/backend/db-client/env/env.test.ts +574 -0
- package/backend/db-client/env/index.ts +15 -0
- package/backend/db-client/env/naming.ts +202 -0
- package/backend/db-client/env/service.ts +487 -0
- package/backend/db-client/integrations/index.ts +44 -0
- package/backend/db-client/integrations/links.ts +564 -0
- package/backend/db-client/integrations/projector.test.ts +280 -0
- package/backend/db-client/integrations/projector.ts +256 -0
- package/backend/db-client/integrations/supabase-service.ts +266 -0
- package/backend/db-client/providers/neon/adapter.ts +522 -0
- package/backend/db-client/providers/neon/api-types.ts +182 -0
- package/backend/db-client/providers/neon/client.ts +298 -0
- package/backend/db-client/providers/neon/endpoints.test.ts +201 -0
- package/backend/db-client/providers/neon/endpoints.ts +314 -0
- package/backend/db-client/providers/neon/list.test.ts +181 -0
- package/backend/db-client/providers/registry.ts +27 -0
- package/backend/db-client/providers/supabase/adapter.ts +523 -0
- package/backend/db-client/providers/supabase/api-types.ts +92 -0
- package/backend/db-client/providers/supabase/apply-migration.ts +104 -0
- package/backend/db-client/providers/supabase/client.ts +259 -0
- package/backend/db-client/providers/supabase/features.ts +502 -0
- package/backend/db-client/providers/supabase/local.test.ts +78 -0
- package/backend/db-client/providers/supabase/local.ts +137 -0
- package/backend/db-client/providers/types.ts +194 -0
- package/backend/deployments/bindings.test.ts +43 -0
- package/backend/deployments/bindings.ts +216 -0
- package/backend/deployments/index.ts +53 -0
- package/backend/deployments/log-streams.ts +214 -0
- package/backend/deployments/prompts.ts +70 -0
- package/backend/deployments/providers/vercel/adapter.ts +757 -0
- package/backend/deployments/providers/vercel/build-logs.test.ts +80 -0
- package/backend/deployments/providers/vercel/build-logs.ts +211 -0
- package/backend/deployments/providers/vercel/client.ts +203 -0
- package/backend/deployments/providers/vercel/list.test.ts +624 -0
- package/backend/deployments/providers/vercel/normalise.test.ts +115 -0
- package/backend/deployments/providers/vercel/normalise.ts +113 -0
- package/backend/deployments/providers/vercel/types.ts +104 -0
- package/backend/deployments/registry.ts +27 -0
- package/backend/deployments/service.ts +458 -0
- package/backend/deployments/types.ts +278 -0
- package/backend/env-files/discovery.ts +48 -0
- package/backend/env-files/edit.ts +213 -0
- package/backend/env-files/env-files.test.ts +515 -0
- package/backend/env-files/git.ts +27 -0
- package/backend/env-files/index.ts +44 -0
- package/backend/env-files/keys.ts +69 -0
- package/backend/env-files/parse.ts +157 -0
- package/backend/env-files/write.ts +229 -0
- package/backend/index.ts +4 -0
- package/backend/integrations/health.ts +18 -4
- package/backend/integrations/projections/index.ts +0 -0
- package/backend/integrations/projections/mcp-projector.ts +7 -3
- package/backend/integrations/projections/types.ts +28 -9
- package/backend/integrations/registry/index.ts +8 -1
- package/backend/integrations/registry/providers/context7.ts +1 -0
- package/backend/integrations/registry/providers/firecrawl.ts +1 -0
- package/backend/integrations/registry/providers/github.ts +1 -0
- package/backend/integrations/registry/providers/neon.ts +55 -0
- package/backend/integrations/registry/providers/supabase.ts +62 -0
- package/backend/integrations/registry/providers/vercel.ts +47 -0
- package/backend/integrations/registry/types.ts +2 -0
- package/backend/mcp/internal/servers/memory-graph/description.ts +3 -3
- package/backend/mcp/internal/servers/memory-graph/runner.ts +4 -9
- package/backend/mcp/internal/servers/memory-graph/schema.ts +0 -4
- package/backend/memory/README.md +57 -34
- package/backend/memory/compose.test.ts +3 -3
- package/backend/memory/compose.ts +6 -9
- package/backend/memory/config.ts +0 -5
- package/backend/memory/consolidate.ts +1 -2
- package/backend/memory/context.test.ts +8 -54
- package/backend/memory/context.ts +19 -25
- package/backend/memory/extract/episodic.ts +10 -12
- package/backend/memory/extract/index.ts +23 -52
- package/backend/memory/extract/scheduler.ts +3 -6
- package/backend/memory/index.ts +6 -5
- package/backend/memory/invalidate.ts +36 -48
- package/backend/memory/layout.ts +319 -130
- package/backend/memory/retention.ts +12 -42
- package/backend/memory/retrieval.eval.test.ts +2 -2
- package/backend/memory/retrieval.test.ts +228 -183
- package/backend/memory/retrieval.ts +22 -21
- package/backend/memory/revise.test.ts +62 -116
- package/backend/memory/revise.ts +0 -1
- package/backend/memory/view.ts +8 -5
- package/backend/snapshot/helpers.ts +35 -41
- package/backend/snapshot/snapshot-service.ts +90 -0
- package/backend/snapshot/turn-changes.test.ts +163 -0
- package/backend/snapshot/turn-changes.ts +131 -0
- package/backend/work/start-work.ts +4 -0
- package/backend/worktrees/branching/engine.ts +557 -0
- package/backend/worktrees/branching/index.ts +56 -0
- package/backend/worktrees/branching/naming.test.ts +118 -0
- package/backend/worktrees/branching/naming.ts +97 -0
- package/backend/worktrees/branching/projector.test.ts +229 -0
- package/backend/worktrees/branching/projector.ts +139 -0
- package/backend/worktrees/branching/providers/neon.ts +220 -0
- package/backend/worktrees/branching/registry.ts +27 -0
- package/backend/worktrees/branching/service.ts +620 -0
- package/backend/worktrees/branching/suggest.test.ts +154 -0
- package/backend/worktrees/branching/suggest.ts +202 -0
- package/backend/worktrees/branching/types.ts +88 -0
- package/backend/worktrees/index.ts +7 -0
- package/backend/worktrees/service.ts +48 -1
- package/backend/ws/db-client/accounts.ts +225 -0
- package/backend/ws/db-client/connections.ts +34 -3
- package/backend/ws/db-client/context.ts +37 -0
- package/backend/ws/db-client/env.ts +142 -0
- package/backend/ws/db-client/index.ts +22 -1
- package/backend/ws/db-client/supabase.ts +188 -0
- package/backend/ws/deployments/actions.ts +360 -0
- package/backend/ws/deployments/context.ts +43 -0
- package/backend/ws/deployments/crud.ts +152 -0
- package/backend/ws/deployments/index.ts +15 -0
- package/backend/ws/deployments/schemas.ts +183 -0
- package/backend/ws/index.ts +6 -2
- package/backend/ws/memory/crud.ts +4 -16
- package/backend/ws/projects/index.ts +6 -1
- package/backend/ws/projects/info.ts +70 -6
- package/backend/ws/projects/overview.test.ts +108 -0
- package/backend/ws/projects/overview.ts +300 -0
- package/backend/ws/snapshot/changes.ts +279 -0
- package/backend/ws/snapshot/index.ts +4 -3
- package/backend/ws/system/device-info.ts +307 -76
- package/backend/ws/worktrees/branching.ts +212 -0
- package/backend/ws/worktrees/crud.ts +33 -7
- package/backend/ws/worktrees/index.ts +14 -0
- package/dist/assets/{index-DSHIANSy.js → index-D4igjF6e.js} +1 -1
- package/dist/assets/{index-CyH7fSbR.js → index-DONNwiXm.js} +1 -1
- package/dist/assets/main-BrfXH1bL.js +1205 -0
- package/dist/assets/main-CT1PygsW.css +1 -0
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/shared/constants/tool-icons.ts +13 -0
- package/shared/types/db-client/connection.ts +6 -0
- package/shared/types/db-client/env.ts +192 -0
- package/shared/types/db-client/index.ts +3 -0
- package/shared/types/db-client/integrations.ts +204 -0
- package/shared/types/db-client/supabase.ts +131 -0
- package/shared/types/deployments.ts +382 -0
- package/shared/types/integrations.ts +9 -0
- package/shared/types/memory.ts +34 -51
- package/shared/types/ui/components.ts +1 -1
- package/shared/types/worktree-branching.ts +315 -0
- package/shared/utils/diff-calculator.test.ts +89 -0
- package/shared/utils/diff-calculator.ts +30 -65
- package/shared/utils/logger.ts +2 -0
- package/backend/memory/extract/languages.ts +0 -176
- package/backend/memory/extract/structural.test.ts +0 -215
- package/backend/memory/extract/structural.ts +0 -364
- package/backend/ws/snapshot/content.ts +0 -85
- package/dist/assets/main-D2IOjftb.css +0 -1
- package/dist/assets/main-DM-tHKbW.js +0 -1152
|
@@ -0,0 +1,624 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filling a filtered page.
|
|
3
|
+
*
|
|
4
|
+
* Vercel cannot filter previews server-side — `target` is `production` or null,
|
|
5
|
+
* and there is no `target=preview` to send — so the preview and custom filters
|
|
6
|
+
* discard rows after the request. On a project that deploys production often,
|
|
7
|
+
* one request can therefore answer with almost nothing while plenty more pages
|
|
8
|
+
* exist.
|
|
9
|
+
*
|
|
10
|
+
* That is exactly the bug the Issues list shipped with `state=all`, where the
|
|
11
|
+
* fifty most recently updated items were nearly all pull requests and almost
|
|
12
|
+
* nothing survived the filter. These tests are here so it is not shipped twice.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, it, expect, afterEach } from 'bun:test';
|
|
16
|
+
|
|
17
|
+
import { vercelDeployAdapter } from './adapter';
|
|
18
|
+
import type { DeployContext } from '../../types';
|
|
19
|
+
|
|
20
|
+
const realFetch = globalThis.fetch;
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
globalThis.fetch = realFetch;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
function deployment(id: string, target: string | null) {
|
|
26
|
+
return {
|
|
27
|
+
uid: id,
|
|
28
|
+
name: 'web',
|
|
29
|
+
url: `${id}.vercel.app`,
|
|
30
|
+
readyState: 'READY',
|
|
31
|
+
target,
|
|
32
|
+
createdAt: 1_700_000_000_000
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Answer the project call once, then hand back deployment pages in order.
|
|
38
|
+
*
|
|
39
|
+
* `next` is a timestamp cursor, and the last page returns null for it — which
|
|
40
|
+
* is how the adapter learns to stop.
|
|
41
|
+
*/
|
|
42
|
+
function mockApi(pages: { deployments: unknown[]; next: number | null }[]) {
|
|
43
|
+
const requested: string[] = [];
|
|
44
|
+
|
|
45
|
+
globalThis.fetch = (async (input: string | URL) => {
|
|
46
|
+
const url = String(input);
|
|
47
|
+
requested.push(url);
|
|
48
|
+
|
|
49
|
+
if (url.includes('/v9/projects/')) {
|
|
50
|
+
return new Response(
|
|
51
|
+
JSON.stringify({ id: 'prj_1', name: 'web', targets: { production: { id: 'dpl_live' } } }),
|
|
52
|
+
{ status: 200, headers: { 'content-type': 'application/json' } }
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const page = pages.shift() ?? { deployments: [], next: null };
|
|
57
|
+
return new Response(
|
|
58
|
+
JSON.stringify({ deployments: page.deployments, pagination: { count: page.deployments.length, next: page.next, prev: null } }),
|
|
59
|
+
{ status: 200, headers: { 'content-type': 'application/json' } }
|
|
60
|
+
);
|
|
61
|
+
}) as typeof fetch;
|
|
62
|
+
|
|
63
|
+
return requested;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const context: DeployContext = {
|
|
67
|
+
projectId: 'proj',
|
|
68
|
+
// Only the fields the adapter reads; the account row never reaches the API.
|
|
69
|
+
account: { id: 'acc_1', label: 'Vercel' } as DeployContext['account'],
|
|
70
|
+
credentials: { token: 'tok' },
|
|
71
|
+
binding: {
|
|
72
|
+
locator: 'prj_1',
|
|
73
|
+
displayName: 'web',
|
|
74
|
+
detected: true,
|
|
75
|
+
teamId: null,
|
|
76
|
+
config: { environment: 'all', autoRefresh: true }
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
describe('list — filling a filtered page', () => {
|
|
81
|
+
it('keeps pulling until the FILTERED page is full', async () => {
|
|
82
|
+
mockApi([
|
|
83
|
+
// Almost all production: one preview survives the filter per page.
|
|
84
|
+
{ deployments: [deployment('a', 'production'), deployment('b', null)], next: 111 },
|
|
85
|
+
{ deployments: [deployment('c', 'production'), deployment('d', null)], next: 222 },
|
|
86
|
+
{ deployments: [deployment('e', null), deployment('f', null)], next: null }
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
const page = await vercelDeployAdapter.list(context, { environment: 'preview', limit: 4 });
|
|
90
|
+
|
|
91
|
+
expect(page.items.map((item) => item.id)).toEqual(['b', 'd', 'e', 'f']);
|
|
92
|
+
expect(page.items.every((item) => item.environment === 'preview')).toBe(true);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('resumes from where the fill stopped, not from the next page number', async () => {
|
|
96
|
+
const requested = mockApi([
|
|
97
|
+
{ deployments: [deployment('a', 'production')], next: 111 },
|
|
98
|
+
{ deployments: [deployment('b', null)], next: 222 }
|
|
99
|
+
]);
|
|
100
|
+
|
|
101
|
+
const page = await vercelDeployAdapter.list(context, { environment: 'preview', limit: 1 });
|
|
102
|
+
|
|
103
|
+
// The cursor is the one the LAST request returned. Anything else re-reads
|
|
104
|
+
// rows this page already discarded.
|
|
105
|
+
expect(page.nextCursor).toBe('222');
|
|
106
|
+
expect(page.hasMore).toBe(true);
|
|
107
|
+
// The second request carried the first page's cursor.
|
|
108
|
+
expect(requested.at(-1)).toContain('until=111');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('stops and reports no more when the provider runs out', async () => {
|
|
112
|
+
mockApi([{ deployments: [deployment('a', null)], next: null }]);
|
|
113
|
+
|
|
114
|
+
const page = await vercelDeployAdapter.list(context, { environment: 'all', limit: 10 });
|
|
115
|
+
|
|
116
|
+
expect(page.hasMore).toBe(false);
|
|
117
|
+
expect(page.nextCursor).toBeNull();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('filters server-side for production, so no fill is needed', async () => {
|
|
121
|
+
const requested = mockApi([
|
|
122
|
+
{ deployments: [deployment('a', 'production'), deployment('b', 'production')], next: null }
|
|
123
|
+
]);
|
|
124
|
+
|
|
125
|
+
const page = await vercelDeployAdapter.list(context, { environment: 'production', limit: 10 });
|
|
126
|
+
|
|
127
|
+
expect(page.items).toHaveLength(2);
|
|
128
|
+
expect(requested.some((url) => url.includes('target=production'))).toBe(true);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('marks only the deployment the project says is live', async () => {
|
|
132
|
+
mockApi([
|
|
133
|
+
{ deployments: [deployment('dpl_live', 'production'), deployment('dpl_old', 'production')], next: null }
|
|
134
|
+
]);
|
|
135
|
+
|
|
136
|
+
const page = await vercelDeployAdapter.list(context, { environment: 'all', limit: 10 });
|
|
137
|
+
|
|
138
|
+
expect(page.items.find((item) => item.id === 'dpl_live')?.isCurrent).toBe(true);
|
|
139
|
+
// Ready and production, but superseded — and it must not claim otherwise.
|
|
140
|
+
expect(page.items.find((item) => item.id === 'dpl_old')?.isCurrent).toBe(false);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Listing the projects a credential can reach.
|
|
146
|
+
*
|
|
147
|
+
* The default-scope listing and the per-team listing overlap whenever the
|
|
148
|
+
* token's default scope IS one of the user's teams, which is the ordinary state
|
|
149
|
+
* for anyone who works in a team. Concatenating them crashed the picker on a
|
|
150
|
+
* duplicate key, and quietly de-duplicating it the wrong way is worse than the
|
|
151
|
+
* crash: keep the unscoped copy and every later call drops the `teamId`, which
|
|
152
|
+
* a team project answers with a 404 that reads like "no such project".
|
|
153
|
+
*/
|
|
154
|
+
function mockProjectLists(
|
|
155
|
+
defaultScope: { id: string; name: string }[],
|
|
156
|
+
teams: { team: { id: string; name: string }; projects: { id: string; name: string }[] }[]
|
|
157
|
+
) {
|
|
158
|
+
globalThis.fetch = (async (input: string | URL) => {
|
|
159
|
+
const url = new URL(String(input));
|
|
160
|
+
const json = (body: unknown) =>
|
|
161
|
+
new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
|
|
162
|
+
|
|
163
|
+
if (url.pathname === '/v2/teams') {
|
|
164
|
+
return json({ teams: teams.map((entry) => entry.team) });
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const teamId = url.searchParams.get('teamId');
|
|
168
|
+
if (!teamId) return json({ projects: defaultScope });
|
|
169
|
+
|
|
170
|
+
const match = teams.find((entry) => entry.team.id === teamId);
|
|
171
|
+
return json({ projects: match?.projects ?? [] });
|
|
172
|
+
}) as typeof fetch;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const unbound = {
|
|
176
|
+
projectId: 'proj',
|
|
177
|
+
account: { id: 'acc_1', label: 'Vercel' } as DeployContext['account'],
|
|
178
|
+
credentials: { token: 'tok' }
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
describe('listTargets — overlapping scopes', () => {
|
|
182
|
+
it('lists a project once when the default scope is also a team', async () => {
|
|
183
|
+
mockProjectLists(
|
|
184
|
+
[{ id: 'prj_1', name: 'web' }],
|
|
185
|
+
[{ team: { id: 'team_a', name: 'Acme' }, projects: [{ id: 'prj_1', name: 'web' }] }]
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
const targets = await vercelDeployAdapter.listTargets(unbound);
|
|
189
|
+
|
|
190
|
+
expect(targets).toHaveLength(1);
|
|
191
|
+
expect(targets.map((target) => target.id)).toEqual(['prj_1']);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('keeps the TEAM-scoped copy, because every later call needs the team id', async () => {
|
|
195
|
+
mockProjectLists(
|
|
196
|
+
[{ id: 'prj_1', name: 'web' }],
|
|
197
|
+
[{ team: { id: 'team_a', name: 'Acme' }, projects: [{ id: 'prj_1', name: 'web' }] }]
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
const [target] = await vercelDeployAdapter.listTargets(unbound);
|
|
201
|
+
|
|
202
|
+
expect(target.teamId).toBe('team_a');
|
|
203
|
+
expect(target.teamName).toBe('Acme');
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('leaves a genuinely personal project unscoped', async () => {
|
|
207
|
+
mockProjectLists(
|
|
208
|
+
[{ id: 'prj_solo', name: 'solo' }],
|
|
209
|
+
[{ team: { id: 'team_a', name: 'Acme' }, projects: [{ id: 'prj_team', name: 'team-app' }] }]
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
const targets = await vercelDeployAdapter.listTargets(unbound);
|
|
213
|
+
|
|
214
|
+
expect(targets.find((target) => target.id === 'prj_solo')?.teamId).toBeNull();
|
|
215
|
+
expect(targets.find((target) => target.id === 'prj_team')?.teamId).toBe('team_a');
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('still lists the default scope when teams cannot be read', async () => {
|
|
219
|
+
globalThis.fetch = (async (input: string | URL) => {
|
|
220
|
+
const url = new URL(String(input));
|
|
221
|
+
if (url.pathname === '/v2/teams') return new Response('{}', { status: 403 });
|
|
222
|
+
return new Response(JSON.stringify({ projects: [{ id: 'prj_1', name: 'web' }] }), {
|
|
223
|
+
status: 200,
|
|
224
|
+
headers: { 'content-type': 'application/json' }
|
|
225
|
+
});
|
|
226
|
+
}) as typeof fetch;
|
|
227
|
+
|
|
228
|
+
// A token scoped to one project cannot list teams, and that must not turn
|
|
229
|
+
// into an empty picker.
|
|
230
|
+
const targets = await vercelDeployAdapter.listTargets(unbound);
|
|
231
|
+
expect(targets.map((target) => target.id)).toEqual(['prj_1']);
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
describe('list — overlapping pages', () => {
|
|
236
|
+
it('does not repeat a deployment the previous page already returned', async () => {
|
|
237
|
+
// A build landing mid-fill shifts the timestamp window, so the next page
|
|
238
|
+
// can start on a row the last one ended with. The list is keyed by id.
|
|
239
|
+
mockApi([
|
|
240
|
+
{ deployments: [deployment('a', null), deployment('b', null)], next: 111 },
|
|
241
|
+
{ deployments: [deployment('b', null), deployment('c', null)], next: null }
|
|
242
|
+
]);
|
|
243
|
+
|
|
244
|
+
const page = await vercelDeployAdapter.list(context, { environment: 'all', limit: 10 });
|
|
245
|
+
|
|
246
|
+
expect(page.items.map((item) => item.id)).toEqual(['a', 'b', 'c']);
|
|
247
|
+
});
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Starting a build, and creating a project.
|
|
252
|
+
*
|
|
253
|
+
* The trap in `createDeployment` is that `name` alone is enough for the API to
|
|
254
|
+
* accept the request — and when the name does not match an existing project it
|
|
255
|
+
* CREATES one. A build meant for the bound project would silently land in a
|
|
256
|
+
* second project beside it, which is the kind of wrong that looks like nothing
|
|
257
|
+
* happened. `project` is what pins it.
|
|
258
|
+
*/
|
|
259
|
+
function mockPost(project: Record<string, unknown>) {
|
|
260
|
+
const calls: { url: string; body: Record<string, unknown> }[] = [];
|
|
261
|
+
|
|
262
|
+
globalThis.fetch = (async (input: string | URL, init?: RequestInit) => {
|
|
263
|
+
const url = String(input);
|
|
264
|
+
const json = (body: unknown) =>
|
|
265
|
+
new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
|
|
266
|
+
|
|
267
|
+
if (init?.method === 'POST') {
|
|
268
|
+
calls.push({ url, body: JSON.parse(String(init.body ?? '{}')) });
|
|
269
|
+
return json({ uid: 'dpl_new', id: 'prj_new', name: 'web' });
|
|
270
|
+
}
|
|
271
|
+
return json(project);
|
|
272
|
+
}) as typeof fetch;
|
|
273
|
+
|
|
274
|
+
return calls;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
describe('createDeployment', () => {
|
|
278
|
+
const linked = {
|
|
279
|
+
id: 'prj_1',
|
|
280
|
+
name: 'web',
|
|
281
|
+
link: { type: 'github', org: 'acme', repo: 'web', repoId: 42, productionBranch: 'main' }
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
it('pins the build to the bound project, not merely to a name', async () => {
|
|
285
|
+
const calls = mockPost(linked);
|
|
286
|
+
|
|
287
|
+
await vercelDeployAdapter.createDeployment!(context, { ref: 'main', production: false });
|
|
288
|
+
|
|
289
|
+
expect(calls[0].body.project).toBe('prj_1');
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it('builds from the branch asked for, through the project own git provider', async () => {
|
|
293
|
+
const calls = mockPost(linked);
|
|
294
|
+
|
|
295
|
+
await vercelDeployAdapter.createDeployment!(context, { ref: 'feature/x', production: false });
|
|
296
|
+
|
|
297
|
+
// A GitLab-linked project rejects `type: 'github'` outright, so the type
|
|
298
|
+
// comes from the project rather than from a default.
|
|
299
|
+
expect(calls[0].body.gitSource).toEqual({ type: 'github', ref: 'feature/x', repoId: 42 });
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it('omits target for a preview build, because there is no preview target', async () => {
|
|
303
|
+
const calls = mockPost(linked);
|
|
304
|
+
|
|
305
|
+
await vercelDeployAdapter.createDeployment!(context, { ref: 'main', production: false });
|
|
306
|
+
expect(calls[0].body.target).toBeUndefined();
|
|
307
|
+
|
|
308
|
+
await vercelDeployAdapter.createDeployment!(context, { ref: 'main', production: true });
|
|
309
|
+
expect(calls[1].body.target).toBe('production');
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('refuses when the project has no repository to build from', async () => {
|
|
313
|
+
mockPost({ id: 'prj_1', name: 'web', link: null });
|
|
314
|
+
|
|
315
|
+
expect(vercelDeployAdapter.createDeployment!(context, { ref: 'main', production: false }))
|
|
316
|
+
.rejects.toThrow(/not connected to a git repository/);
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
describe('deployInfo', () => {
|
|
321
|
+
it('reports a git-connected project as deployable, with its production branch', async () => {
|
|
322
|
+
mockPost({ id: 'prj_1', name: 'web', link: { type: 'github', org: 'acme', repo: 'web', repoId: 42, productionBranch: 'trunk' } });
|
|
323
|
+
|
|
324
|
+
const info = await vercelDeployAdapter.deployInfo!(context);
|
|
325
|
+
|
|
326
|
+
expect(info).toMatchObject({ canDeploy: true, gitRepo: 'acme/web', productionBranch: 'trunk' });
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it('falls back to main when the project defers to the repository default', async () => {
|
|
330
|
+
mockPost({ id: 'prj_1', name: 'web', link: { type: 'github', org: 'acme', repo: 'web', repoId: 42, productionBranch: null } });
|
|
331
|
+
|
|
332
|
+
expect((await vercelDeployAdapter.deployInfo!(context)).productionBranch).toBe('main');
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it('explains why an unconnected project cannot be deployed, rather than failing later', async () => {
|
|
336
|
+
mockPost({ id: 'prj_1', name: 'web', link: null });
|
|
337
|
+
|
|
338
|
+
const info = await vercelDeployAdapter.deployInfo!(context);
|
|
339
|
+
|
|
340
|
+
expect(info.canDeploy).toBe(false);
|
|
341
|
+
expect(info.reason).toMatch(/not connected to a git repository/);
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
describe('createProject', () => {
|
|
346
|
+
it('connects the repository it was given', async () => {
|
|
347
|
+
const calls = mockPost({});
|
|
348
|
+
|
|
349
|
+
await vercelDeployAdapter.createProject!(unbound, {
|
|
350
|
+
name: 'web',
|
|
351
|
+
gitRepo: 'acme/web',
|
|
352
|
+
gitProvider: 'github',
|
|
353
|
+
framework: null
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
expect(calls[0].body).toMatchObject({
|
|
357
|
+
name: 'web',
|
|
358
|
+
gitRepository: { type: 'github', repo: 'acme/web' }
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it('leaves the framework unset rather than guessing one', async () => {
|
|
363
|
+
const calls = mockPost({});
|
|
364
|
+
|
|
365
|
+
await vercelDeployAdapter.createProject!(unbound, {
|
|
366
|
+
name: 'web',
|
|
367
|
+
gitRepo: null,
|
|
368
|
+
gitProvider: null,
|
|
369
|
+
framework: null
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
// A wrong framework is a broken build with a confusing cause; the host
|
|
373
|
+
// detects it from the repository.
|
|
374
|
+
expect(calls[0].body.framework).toBeUndefined();
|
|
375
|
+
expect(calls[0].body.gitRepository).toBeUndefined();
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
describe('connectRepository', () => {
|
|
380
|
+
it('attaches the repository to the bound project, scoped to its team', async () => {
|
|
381
|
+
const calls = mockPost({});
|
|
382
|
+
const teamContext = { ...context, binding: { ...context.binding, teamId: 'team_a' } };
|
|
383
|
+
|
|
384
|
+
await vercelDeployAdapter.connectRepository!(teamContext, {
|
|
385
|
+
gitRepo: 'acme/web',
|
|
386
|
+
gitProvider: 'github'
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
expect(calls[0].url).toContain('/v9/projects/prj_1/link');
|
|
390
|
+
expect(calls[0].url).toContain('teamId=team_a');
|
|
391
|
+
expect(calls[0].body).toEqual({ type: 'github', repo: 'acme/web' });
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it('passes the provider through rather than assuming github', async () => {
|
|
395
|
+
const calls = mockPost({});
|
|
396
|
+
|
|
397
|
+
await vercelDeployAdapter.connectRepository!(context, {
|
|
398
|
+
gitRepo: 'acme/web',
|
|
399
|
+
gitProvider: 'gitlab'
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
expect(calls[0].body.type).toBe('gitlab');
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Knowing in advance whether Connect can work.
|
|
408
|
+
*
|
|
409
|
+
* Vercel needs the ACCOUNT to hold a git login connection before any project
|
|
410
|
+
* can be linked, and reports its absence only when the link is attempted — at
|
|
411
|
+
* the moment the user has already been promised the button would work. That
|
|
412
|
+
* prerequisite is an OAuth flow on Vercel's own site: no API token can supply
|
|
413
|
+
* it, so the honest move is to detect it and point at the fix.
|
|
414
|
+
*/
|
|
415
|
+
function mockNamespaces(namespaces: unknown[] | { status: number }) {
|
|
416
|
+
globalThis.fetch = (async (input: string | URL) => {
|
|
417
|
+
const url = new URL(String(input));
|
|
418
|
+
if (url.pathname === '/v1/integrations/git-namespaces') {
|
|
419
|
+
if (!Array.isArray(namespaces)) return new Response('{}', { status: namespaces.status });
|
|
420
|
+
return new Response(JSON.stringify(namespaces), {
|
|
421
|
+
status: 200,
|
|
422
|
+
headers: { 'content-type': 'application/json' }
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
return new Response('{}', { status: 200, headers: { 'content-type': 'application/json' } });
|
|
426
|
+
}) as typeof fetch;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
describe('repositoryAccess', () => {
|
|
430
|
+
it('does NOT treat an empty list as proof the account has no connection', async () => {
|
|
431
|
+
// This was the bug. An account with GitHub connected and working reported
|
|
432
|
+
// no namespaces, and the check disabled the button on that inference —
|
|
433
|
+
// telling the user something they could see on screen was false. Silence
|
|
434
|
+
// from this endpoint can also mean a token that cannot read integrations.
|
|
435
|
+
mockNamespaces([]);
|
|
436
|
+
|
|
437
|
+
const access = await vercelDeployAdapter.repositoryAccess!(context, 'argafairuz/calc-2');
|
|
438
|
+
|
|
439
|
+
expect(access.state).toBe('unknown');
|
|
440
|
+
expect(access.actionUrl).toBe('https://github.com/apps/vercel/installations/new');
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
it('allows it when the repository owner is reachable', async () => {
|
|
444
|
+
mockNamespaces([{ id: 1, slug: 'argafairuz', provider: 'github', ownerType: 'user' }]);
|
|
445
|
+
|
|
446
|
+
const access = await vercelDeployAdapter.repositoryAccess!(context, 'argafairuz/calc-2');
|
|
447
|
+
|
|
448
|
+
expect(access.state).toBe('ready');
|
|
449
|
+
expect(access.reason).toBeNull();
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
it('matches the owner case-insensitively', async () => {
|
|
453
|
+
mockNamespaces([{ id: 1, slug: 'ArgaFairuz', provider: 'github', ownerType: 'user' }]);
|
|
454
|
+
|
|
455
|
+
expect((await vercelDeployAdapter.repositoryAccess!(context, 'argafairuz/calc-2')).state).toBe('ready');
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
it('blocks only when the list is NON-empty and still omits the owner', async () => {
|
|
459
|
+
// That combination is informative: the app is installed somewhere, just
|
|
460
|
+
// not where this repository lives.
|
|
461
|
+
mockNamespaces([
|
|
462
|
+
{ id: 1, slug: 'acme', provider: 'github', ownerType: 'team' },
|
|
463
|
+
{ id: 2, slug: 'someone-else', provider: 'github', ownerType: 'user' }
|
|
464
|
+
]);
|
|
465
|
+
|
|
466
|
+
const access = await vercelDeployAdapter.repositoryAccess!(context, 'argafairuz/calc-2');
|
|
467
|
+
|
|
468
|
+
expect(access.state).toBe('blocked');
|
|
469
|
+
expect(access.reason).toContain('acme');
|
|
470
|
+
expect(access.reason).toContain('argafairuz');
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
it('blocks on a restricted namespace, which looks reachable but is not', async () => {
|
|
474
|
+
mockNamespaces([
|
|
475
|
+
{ id: 1, slug: 'argafairuz', provider: 'github', ownerType: 'user', isAccessRestricted: true }
|
|
476
|
+
]);
|
|
477
|
+
|
|
478
|
+
const access = await vercelDeployAdapter.repositoryAccess!(context, 'argafairuz/calc-2');
|
|
479
|
+
expect(access.state).toBe('blocked');
|
|
480
|
+
expect(access.reason).toMatch(/restricted/i);
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it('reports UNKNOWN rather than ready when the check itself fails', async () => {
|
|
484
|
+
// The first version answered "ready" here, which put the button back on
|
|
485
|
+
// screen and let the very failure this check exists to prevent arrive as
|
|
486
|
+
// a toast. Unreadable is its own answer.
|
|
487
|
+
mockNamespaces({ status: 403 });
|
|
488
|
+
|
|
489
|
+
const access = await vercelDeployAdapter.repositoryAccess!(context, 'argafairuz/calc-2');
|
|
490
|
+
|
|
491
|
+
expect(access.state).toBe('unknown');
|
|
492
|
+
expect(access.actionUrl).toBe('https://github.com/apps/vercel/installations/new');
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
it('tolerates a wrapped response instead of reading it as "no namespaces"', async () => {
|
|
496
|
+
// Documented as a bare array. Reading a wrapper as empty would produce a
|
|
497
|
+
// confident "blocked" built on a parsing mistake.
|
|
498
|
+
globalThis.fetch = (async (input: string | URL) => {
|
|
499
|
+
const url = new URL(String(input));
|
|
500
|
+
if (url.pathname === '/v1/integrations/git-namespaces') {
|
|
501
|
+
return new Response(
|
|
502
|
+
JSON.stringify({ gitNamespaces: [{ id: 1, slug: 'argafairuz', provider: 'github', ownerType: 'user' }] }),
|
|
503
|
+
{ status: 200, headers: { 'content-type': 'application/json' } }
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
return new Response('{}', { status: 200, headers: { 'content-type': 'application/json' } });
|
|
507
|
+
}) as typeof fetch;
|
|
508
|
+
|
|
509
|
+
expect((await vercelDeployAdapter.repositoryAccess!(context, 'argafairuz/calc-2')).state).toBe('ready');
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
it('does NOT send teamId, which this endpoint rejects outright', async () => {
|
|
513
|
+
// Nearly every other Vercel endpoint requires `teamId`; this one answers
|
|
514
|
+
// 400 for it, because git namespaces belong to the signed-in user rather
|
|
515
|
+
// than to a team. Sending it turned every check into an error, which the
|
|
516
|
+
// caller reported as "could not verify" and let the button through — one
|
|
517
|
+
// wrong query parameter made the whole pre-flight decoration.
|
|
518
|
+
const urls: string[] = [];
|
|
519
|
+
globalThis.fetch = (async (input: string | URL) => {
|
|
520
|
+
urls.push(String(input));
|
|
521
|
+
return new Response(JSON.stringify([{ id: 1, slug: 'argafairuz', provider: 'github', ownerType: 'user' }]), {
|
|
522
|
+
status: 200,
|
|
523
|
+
headers: { 'content-type': 'application/json' }
|
|
524
|
+
});
|
|
525
|
+
}) as typeof fetch;
|
|
526
|
+
|
|
527
|
+
const teamContext = { ...context, binding: { ...context.binding, teamId: 'team_a' } };
|
|
528
|
+
await vercelDeployAdapter.repositoryAccess!(teamContext, 'argafairuz/calc-2');
|
|
529
|
+
|
|
530
|
+
const call = urls.find((url) => url.includes('git-namespaces'))!;
|
|
531
|
+
expect(call).not.toContain('teamId');
|
|
532
|
+
expect(call).not.toContain('slug=');
|
|
533
|
+
});
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Deleting, pausing, and reading what the target is doing.
|
|
538
|
+
*
|
|
539
|
+
* The rollback candidacy case is the one worth guarding: `isRollbackCandidate`
|
|
540
|
+
* has THREE answers, and collapsing the missing one into `false` hid the
|
|
541
|
+
* rollback action on every listing that omitted the field.
|
|
542
|
+
*/
|
|
543
|
+
describe('deleteDeployment', () => {
|
|
544
|
+
it('deletes through the versioned deployment path, scoped to its team', async () => {
|
|
545
|
+
const urls: string[] = [];
|
|
546
|
+
const methods: string[] = [];
|
|
547
|
+
globalThis.fetch = (async (input: string | URL, init?: RequestInit) => {
|
|
548
|
+
urls.push(String(input));
|
|
549
|
+
methods.push(init?.method ?? 'GET');
|
|
550
|
+
return new Response('{}', { status: 200, headers: { 'content-type': 'application/json' } });
|
|
551
|
+
}) as typeof fetch;
|
|
552
|
+
|
|
553
|
+
const teamContext = { ...context, binding: { ...context.binding, teamId: 'team_a' } };
|
|
554
|
+
await vercelDeployAdapter.deleteDeployment!(teamContext, 'dpl_1');
|
|
555
|
+
|
|
556
|
+
expect(methods[0]).toBe('DELETE');
|
|
557
|
+
expect(urls[0]).toContain('/v13/deployments/dpl_1');
|
|
558
|
+
expect(urls[0]).toContain('teamId=team_a');
|
|
559
|
+
});
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
describe('projectStatus', () => {
|
|
563
|
+
function mockProject(project: Record<string, unknown>) {
|
|
564
|
+
globalThis.fetch = (async (_input: string | URL) =>
|
|
565
|
+
new Response(JSON.stringify(project), {
|
|
566
|
+
status: 200,
|
|
567
|
+
headers: { 'content-type': 'application/json' }
|
|
568
|
+
})) as typeof fetch;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
it('reports a paused target, which is read-only here', async () => {
|
|
572
|
+
// Clopen never pauses: on Vercel that blocks the active production
|
|
573
|
+
// deployment, so the site goes down rather than merely stopping builds.
|
|
574
|
+
// It is surfaced only because nothing else explains an idle list.
|
|
575
|
+
mockProject({ id: 'prj_1', name: 'web', paused: true });
|
|
576
|
+
expect((await vercelDeployAdapter.projectStatus!(context)).paused).toBe(true);
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
it('surfaces a traffic move still being carried out', async () => {
|
|
580
|
+
// This is what turns the `pending` rollback and promote return into an
|
|
581
|
+
// outcome — without it the panel could never say whether traffic moved.
|
|
582
|
+
mockProject({
|
|
583
|
+
id: 'prj_1',
|
|
584
|
+
name: 'web',
|
|
585
|
+
lastAliasRequest: { type: 'rollback', jobStatus: 'in-progress', toDeploymentId: 'dpl_9' }
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
const status = await vercelDeployAdapter.projectStatus!(context);
|
|
589
|
+
|
|
590
|
+
expect(status.aliasRequest).toEqual({
|
|
591
|
+
type: 'rollback',
|
|
592
|
+
status: 'in-progress',
|
|
593
|
+
toDeploymentId: 'dpl_9'
|
|
594
|
+
});
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
it('answers null when no traffic move has been requested', async () => {
|
|
598
|
+
mockProject({ id: 'prj_1', name: 'web' });
|
|
599
|
+
expect((await vercelDeployAdapter.projectStatus!(context)).aliasRequest).toBeNull();
|
|
600
|
+
});
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
describe('rollback candidacy', () => {
|
|
604
|
+
it('keeps the provider three answers apart', async () => {
|
|
605
|
+
mockApi([
|
|
606
|
+
{
|
|
607
|
+
deployments: [
|
|
608
|
+
{ ...deployment('a', 'production'), isRollbackCandidate: true },
|
|
609
|
+
{ ...deployment('b', 'production'), isRollbackCandidate: false },
|
|
610
|
+
// Says nothing — must NOT read as "no".
|
|
611
|
+
deployment('c', 'production')
|
|
612
|
+
],
|
|
613
|
+
next: null
|
|
614
|
+
}
|
|
615
|
+
]);
|
|
616
|
+
|
|
617
|
+
const page = await vercelDeployAdapter.list(context, { environment: 'all', limit: 10 });
|
|
618
|
+
const byId = Object.fromEntries(page.items.map((item) => [item.id, item.isRollbackCandidate]));
|
|
619
|
+
|
|
620
|
+
expect(byId.a).toBe(true);
|
|
621
|
+
expect(byId.b).toBe(false);
|
|
622
|
+
expect(byId.c).toBeNull();
|
|
623
|
+
});
|
|
624
|
+
});
|