@sequenceholdings/studio-cli 1.0.3 → 1.0.4
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/app-preview/bundle-dependencies.d.ts +4 -0
- package/dist/app-preview/bundle-dependencies.js +7 -0
- package/dist/app-preview/commands.js +14 -7
- package/dist/app-preview/fork-setup.d.ts +11 -4
- package/dist/app-preview/fork-setup.js +19 -5
- package/dist/app-preview/fork.d.ts +43 -0
- package/dist/app-preview/fork.js +96 -0
- package/dist/app-preview/function-source.d.ts +16 -0
- package/dist/app-preview/function-source.js +67 -0
- package/dist/app-preview/install.d.ts +9 -0
- package/dist/app-preview/install.js +34 -3
- package/dist/app-preview/repository-manifest.js +7 -2
- package/dist/app-preview/runners.d.ts +5 -1
- package/dist/app-preview/runners.js +29 -5
- package/dist/app-preview/secrets.d.ts +8 -3
- package/dist/app-preview/secrets.js +15 -8
- package/dist/app-preview/usage.d.ts +3 -1
- package/dist/app-preview/usage.js +8 -2
- package/dist/pnpm-auto-update.js +16 -8
- package/dist/repos/commands.js +11 -3
- package/dist/run-pinned.js +6 -1
- package/dist/storage/import-gcloud.js +4 -1
- package/package.json +5 -5
- package/release-summary.json +2 -1
|
@@ -24,6 +24,10 @@ export interface BundleDependencies {
|
|
|
24
24
|
name: string;
|
|
25
25
|
}>;
|
|
26
26
|
}
|
|
27
|
+
/** Every process id a bundle starts, reads or acts on, from the browser and the server. */
|
|
28
|
+
export declare const declaredProcessIds: (bundle: unknown) => string[];
|
|
29
|
+
/** Whether a bundle reaches runs or tasks through the platform API, where it names no process. */
|
|
30
|
+
export declare function readsRunsThroughApi(bundle: unknown): boolean;
|
|
27
31
|
/**
|
|
28
32
|
* The index resources a bundle depends on. `resources` is the whole index, not only what was asked for: an
|
|
29
33
|
* app's namespace is often declared beside it, outside its directory.
|
|
@@ -33,6 +33,13 @@ function bundleReach(bundle) {
|
|
|
33
33
|
storage: unique(blocks.flatMap((block) => keys(at(block, 'storage')))),
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
+
/** Every process id a bundle starts, reads or acts on, from the browser and the server. */
|
|
37
|
+
export const declaredProcessIds = (bundle) => bundleReach(bundle).processes;
|
|
38
|
+
const RUN_API = /^\/api\/(process-activity|lattice)(\/|$)/;
|
|
39
|
+
/** Whether a bundle reaches runs or tasks through the platform API, where it names no process. */
|
|
40
|
+
export function readsRunsThroughApi(bundle) {
|
|
41
|
+
return capabilityBlocks(bundle).some((block) => [...strings(at(block, 'api', 'read')), ...strings(at(block, 'api', 'write'))].some((path) => RUN_API.test(path)));
|
|
42
|
+
}
|
|
36
43
|
const MATCHES = {
|
|
37
44
|
orm: (resource, name) => resource.namespace === name,
|
|
38
45
|
function: (resource, name) => resource.slug === name || resource.id === name,
|
|
@@ -18,7 +18,7 @@ import { attached } from './session-output.js';
|
|
|
18
18
|
import { mountSourceIncludes } from './source-includes.js';
|
|
19
19
|
import { applyProcess, checkNamespace, deployFunction, inspectArtifact, DEFAULT_PREVIEW_KEY, ensureArtifactDependencies, inspectFunction, publishStaticArtifact, } from './runners.js';
|
|
20
20
|
import { decidePreviewTarget } from './target.js';
|
|
21
|
-
import { PREVIEW_APPS_ORIGIN_ENV, PREVIEW_ORIGIN_ENV, PREVIEW_SECRETS_DIR_ENV, PREVIEW_USAGE } from './usage.js';
|
|
21
|
+
import { APP_PREVIEW_SECRETS_FILENAME, PREVIEW_APPS_ORIGIN_ENV, PREVIEW_ORIGIN_ENV, PREVIEW_SECRETS_DIR_ENV, PREVIEW_USAGE } from './usage.js';
|
|
22
22
|
export { PREVIEW_APPS_ORIGIN_ENV, PREVIEW_ORIGIN_ENV, PREVIEW_SECRETS_DIR_ENV, PREVIEW_USAGE };
|
|
23
23
|
function csv(value) {
|
|
24
24
|
if (typeof value !== 'string')
|
|
@@ -42,6 +42,13 @@ async function readSecretsFile({ flag, appId }) {
|
|
|
42
42
|
}
|
|
43
43
|
return { file, values: parseDotenv(await readFile(file, 'utf8')) };
|
|
44
44
|
}
|
|
45
|
+
/** The previewed directory's own file of values a preview can build or state, when the app commits one. */
|
|
46
|
+
async function readAppSecretsFile(appDir) {
|
|
47
|
+
const file = join(appDir, APP_PREVIEW_SECRETS_FILENAME);
|
|
48
|
+
if (!existsSync(file))
|
|
49
|
+
return undefined;
|
|
50
|
+
return { file, values: parseDotenv(await readFile(file, 'utf8')) };
|
|
51
|
+
}
|
|
45
52
|
function publicOrigin(atlasOrigin) {
|
|
46
53
|
const configured = process.env[PREVIEW_ORIGIN_ENV]?.trim();
|
|
47
54
|
if (!configured)
|
|
@@ -68,7 +75,8 @@ function missingSecretsMessage({ inspections, secretsFile, appId }) {
|
|
|
68
75
|
return lines;
|
|
69
76
|
lines.push(`${LOG} A database copy does not carry secret values, and preview never substitutes another credential.`, secretsFile
|
|
70
77
|
? `${LOG} Add them to ${secretsFile}, or store each in this local Atlas with: seq-studio secret set <NAME> -e local`
|
|
71
|
-
: `${LOG}
|
|
78
|
+
: `${LOG} A value this preview can build (\${preview.atlas_origin}, the fork's database) belongs in ${APP_PREVIEW_SECRETS_FILENAME} in the app's directory. ` +
|
|
79
|
+
`For a credential, pass a reviewed dotenv file with --secrets <file> (or put ${appId}.env under $${PREVIEW_SECRETS_DIR_ENV}), or store it in this local Atlas with: seq-studio secret set <NAME> -e local`);
|
|
72
80
|
return lines;
|
|
73
81
|
}
|
|
74
82
|
function printSummary({ results, plan, target }) {
|
|
@@ -128,10 +136,8 @@ export async function runPreviewCommand(args) {
|
|
|
128
136
|
}
|
|
129
137
|
const json = flagBool(args.flags, 'json');
|
|
130
138
|
const only = csv(args.flags.only);
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
only,
|
|
134
|
-
});
|
|
139
|
+
const appDir = args.positional[0] ?? (typeof args.flags.dir === 'string' ? args.flags.dir : '.');
|
|
140
|
+
const preview = await loadPreviewManifest({ dir: appDir, only });
|
|
135
141
|
const { manifest } = preview;
|
|
136
142
|
const plan = planPreview({ manifest, only });
|
|
137
143
|
const resolved = await resolveTarget({ args, envName, rootDir: preview.rootDir, source: preview.source });
|
|
@@ -139,11 +145,12 @@ export async function runPreviewCommand(args) {
|
|
|
139
145
|
return resolved;
|
|
140
146
|
const ctx = resolved;
|
|
141
147
|
const secrets = await readSecretsFile({ flag: args.flags.secrets, appId: manifest.app.id });
|
|
148
|
+
const appFile = await readAppSecretsFile(resolve(appDir));
|
|
142
149
|
const functions = new Map();
|
|
143
150
|
const artifacts = new Map();
|
|
144
151
|
for (const step of plan.steps) {
|
|
145
152
|
if (step.action === 'deploy-function') {
|
|
146
|
-
functions.set(step.entry.id, await inspectFunction({ ctx, entry: step.entry, provided: secrets.values, providedFile: secrets.file }));
|
|
153
|
+
functions.set(step.entry.id, await inspectFunction({ ctx, entry: step.entry, provided: secrets.values, providedFile: secrets.file, appFile }));
|
|
147
154
|
}
|
|
148
155
|
if (step.action === 'publish-artifact')
|
|
149
156
|
artifacts.set(step.entry.id, await inspectArtifact({ ctx, entry: step.entry }));
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import { type BindingPruneOutcome, type IdentityAdmissionOutcome, type PreviewFork, type SecretSourceDecision, type WorkspaceAdoptionOutcome } from './fork.js';
|
|
2
|
-
import type
|
|
1
|
+
import { type BindingPruneOutcome, type BundleCopyOutcome, type IdentityAdmissionOutcome, type PreviewFork, type SecretSourceDecision, type WorkspaceAdoptionOutcome } from './fork.js';
|
|
2
|
+
import { type Prerequisite } from './bundle-dependencies.js';
|
|
3
3
|
import type { ArtifactInspection, PreviewContext } from './runners.js';
|
|
4
4
|
export interface ForkPlan {
|
|
5
5
|
/** Set when the local Atlas reports a devbox fork. */
|
|
6
6
|
fork: PreviewFork | undefined;
|
|
7
7
|
/** The workspaces to adopt, on a fork only: every name an artifact declares and every workspace primitive planned. */
|
|
8
8
|
workspaceNames: string[];
|
|
9
|
+
/**
|
|
10
|
+
* Whose bundles are copied, on a fork only: the processes the previewed artifacts start, read or
|
|
11
|
+
* act on, or every process when one of them reads runs through the API.
|
|
12
|
+
*/
|
|
13
|
+
processIds: string[] | 'all';
|
|
9
14
|
next: ArtifactInspection | undefined;
|
|
10
15
|
secretNames: string[];
|
|
11
16
|
/** Where the Next.js session's secrets come from; undefined when no Next.js app is previewed. */
|
|
@@ -27,11 +32,13 @@ export interface ForkSetup {
|
|
|
27
32
|
workspaces: WorkspaceAdoptionOutcome | null;
|
|
28
33
|
identities: IdentityAdmissionOutcome | null;
|
|
29
34
|
bindings: BindingPruneOutcome | null;
|
|
35
|
+
bundles: BundleCopyOutcome | null;
|
|
30
36
|
}
|
|
31
37
|
/**
|
|
32
38
|
* Before anything starts on a devbox fork: adopt the declared workspaces from the database copy,
|
|
33
|
-
* admit the identities the copied Next.js project records,
|
|
34
|
-
* records for resources the application no longer declares
|
|
39
|
+
* admit the identities the copied Next.js project records, drop the development bindings it
|
|
40
|
+
* records for resources the application no longer declares, and copy the bundles of the processes
|
|
41
|
+
* the app uses from the fork source. None failing stops the preview; each
|
|
35
42
|
* says what it left undone, and the session start then reports the same gap by name.
|
|
36
43
|
*/
|
|
37
44
|
export declare function setUpFork({ ctx, plan, say }: {
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { UsageError } from '../exit-codes.js';
|
|
7
7
|
import { LOG } from '../prompt.js';
|
|
8
|
-
import { adoptDeclaredWorkspaces, admitProjectIdentities, bindingPruneReport, chooseSecretSource, declaredServerSecretNames, declaredWorkspaceNames, identityAdmissionReport, pruneStaleDevelopmentBindings, resolveUpstream, workspaceAdoptionReport, } from './fork.js';
|
|
8
|
+
import { adoptDeclaredWorkspaces, admitProjectIdentities, bindingPruneReport, bundleCopyReport, copyProcessBundles, chooseSecretSource, declaredServerSecretNames, declaredWorkspaceNames, identityAdmissionReport, pruneStaleDevelopmentBindings, resolveUpstream, workspaceAdoptionReport, } from './fork.js';
|
|
9
|
+
import { declaredProcessIds, readsRunsThroughApi } from './bundle-dependencies.js';
|
|
9
10
|
/** Whether the session's secrets are read from the fork source, by default or by request. */
|
|
10
11
|
const readsUpstream = (source) => source?.args[1] === 'upstream';
|
|
11
12
|
function flagText(value, flag) {
|
|
@@ -19,6 +20,11 @@ export async function planFork({ ctx, flags, artifacts, workspaces = [], next })
|
|
|
19
20
|
const fork = ctx.target.fork;
|
|
20
21
|
const declared = [...workspaces, ...artifacts.flatMap((artifact) => declaredWorkspaceNames(artifact.bundle))];
|
|
21
22
|
const workspaceNames = fork ? [...new Set(declared)].sort() : [];
|
|
23
|
+
const processIds = !fork
|
|
24
|
+
? []
|
|
25
|
+
: artifacts.some((artifact) => readsRunsThroughApi(artifact.bundle))
|
|
26
|
+
? 'all'
|
|
27
|
+
: [...new Set(artifacts.flatMap((artifact) => declaredProcessIds(artifact.bundle)))].sort();
|
|
22
28
|
const secretNames = next ? declaredServerSecretNames(next.bundle) : [];
|
|
23
29
|
const secretSource = next
|
|
24
30
|
? chooseSecretSource({
|
|
@@ -34,12 +40,13 @@ export async function planFork({ ctx, flags, artifacts, workspaces = [], next })
|
|
|
34
40
|
...(readsUpstream(secretSource) ? ['secret'] : []),
|
|
35
41
|
...(fork && next ? ['service-account'] : []),
|
|
36
42
|
]);
|
|
37
|
-
return { fork, workspaceNames, next, secretNames, secretSource, secretArgs: secretSource?.args ?? [], handled };
|
|
43
|
+
return { fork, workspaceNames, processIds, next, secretNames, secretSource, secretArgs: secretSource?.args ?? [], handled };
|
|
38
44
|
}
|
|
39
45
|
/**
|
|
40
46
|
* Before anything starts on a devbox fork: adopt the declared workspaces from the database copy,
|
|
41
|
-
* admit the identities the copied Next.js project records,
|
|
42
|
-
* records for resources the application no longer declares
|
|
47
|
+
* admit the identities the copied Next.js project records, drop the development bindings it
|
|
48
|
+
* records for resources the application no longer declares, and copy the bundles of the processes
|
|
49
|
+
* the app uses from the fork source. None failing stops the preview; each
|
|
43
50
|
* says what it left undone, and the session start then reports the same gap by name.
|
|
44
51
|
*/
|
|
45
52
|
export async function setUpFork({ ctx, plan, say }) {
|
|
@@ -66,7 +73,13 @@ export async function setUpFork({ ctx, plan, say }) {
|
|
|
66
73
|
for (const line of bindingPruneReport({ outcome: bindings, projectSlug }))
|
|
67
74
|
say(`${LOG} ${line}`);
|
|
68
75
|
}
|
|
69
|
-
|
|
76
|
+
let bundles = null;
|
|
77
|
+
if (plan.processIds === 'all' || plan.processIds.length) {
|
|
78
|
+
bundles = await copyProcessBundles({ ctx, fork: plan.fork, processIds: plan.processIds }).catch(failed);
|
|
79
|
+
for (const line of bundleCopyReport({ outcome: bundles, sourceEnvironment: plan.fork.upstreamEnvironment }))
|
|
80
|
+
say(`${LOG} ${line}`);
|
|
81
|
+
}
|
|
82
|
+
return { workspaces, identities, bindings, bundles };
|
|
70
83
|
}
|
|
71
84
|
/**
|
|
72
85
|
* What is still left to the operator once the fork steps have run: the result document lists a
|
|
@@ -99,6 +112,7 @@ export function forkResult({ plan, setup }) {
|
|
|
99
112
|
workspaces: setup?.workspaces ?? null,
|
|
100
113
|
identities: setup?.identities ?? null,
|
|
101
114
|
developmentBindings: setup?.bindings ?? null,
|
|
115
|
+
processBundles: setup?.bundles ?? null,
|
|
102
116
|
secrets: plan.secretSource ? { source: plan.secretSource.source, names: plan.secretNames } : null,
|
|
103
117
|
},
|
|
104
118
|
};
|
|
@@ -168,4 +168,47 @@ export declare function chooseSecretSource({ requested, requestedUpstream, secre
|
|
|
168
168
|
}): SecretSourceDecision;
|
|
169
169
|
/** The fork source's environment as this machine can reach it: its registered URL and whether an owner token for it is live. */
|
|
170
170
|
export declare function resolveUpstream(fork: PreviewFork | undefined): Promise<Parameters<typeof chooseSecretSource>[0]['upstream']>;
|
|
171
|
+
/** The most process ids one request to the local Atlas may name, as its route allows. */
|
|
172
|
+
export declare const BUNDLE_COPY_MAX_PROCESSES = 200;
|
|
173
|
+
export type BundleCopyOutcome = {
|
|
174
|
+
ok: true;
|
|
175
|
+
referenced: number;
|
|
176
|
+
copied: number;
|
|
177
|
+
unreadable: string[];
|
|
178
|
+
}
|
|
179
|
+
/** The copy could not start: the local Atlas has no route for it, or no login for the fork source is held. */
|
|
180
|
+
| {
|
|
181
|
+
ok: false;
|
|
182
|
+
reason: string;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Copy the bundles the fork's rows name and its bundle store lacks. `read` fetches one from the
|
|
186
|
+
* deployment the database was copied from and `store` hands it to the local Atlas, which keeps it
|
|
187
|
+
* only if the fork references its hash and the content hashes to it. A bundle the source cannot
|
|
188
|
+
* serve is counted, not fatal: only the runs pinned to it stay unreadable.
|
|
189
|
+
*/
|
|
190
|
+
export declare function copyMissingBundles({ missing, read, store, concurrency }: {
|
|
191
|
+
missing: readonly string[];
|
|
192
|
+
read: (hash: string) => Promise<unknown>;
|
|
193
|
+
store: (bundle: unknown) => Promise<void>;
|
|
194
|
+
concurrency?: number;
|
|
195
|
+
}): Promise<{
|
|
196
|
+
copied: number;
|
|
197
|
+
unreadable: string[];
|
|
198
|
+
}>;
|
|
199
|
+
/**
|
|
200
|
+
* Bring the bundles of the processes an app uses onto a devbox fork, read from the fork source as
|
|
201
|
+
* you. Without them every existing run and task of those processes fails with "Bundle not found".
|
|
202
|
+
*/
|
|
203
|
+
export declare function copyProcessBundles({ ctx, fork, processIds }: {
|
|
204
|
+
ctx: PreviewContext;
|
|
205
|
+
fork: PreviewFork;
|
|
206
|
+
/** The processes an app names, or `'all'` for one that reads runs through the API or names more than one request holds. */
|
|
207
|
+
processIds: readonly string[] | 'all';
|
|
208
|
+
}): Promise<BundleCopyOutcome>;
|
|
209
|
+
/** One line saying what the bundle copy did. */
|
|
210
|
+
export declare function bundleCopyReport({ outcome, sourceEnvironment }: {
|
|
211
|
+
outcome: BundleCopyOutcome;
|
|
212
|
+
sourceEnvironment: string | null;
|
|
213
|
+
}): string[];
|
|
171
214
|
export {};
|
package/dist/app-preview/fork.js
CHANGED
|
@@ -277,3 +277,99 @@ export async function resolveUpstream(fork) {
|
|
|
277
277
|
}
|
|
278
278
|
return { name, host: new URL(url).host, hasOwnerToken: (await devboxHostToken(url)) !== null };
|
|
279
279
|
}
|
|
280
|
+
/** The most process ids one request to the local Atlas may name, as its route allows. */
|
|
281
|
+
export const BUNDLE_COPY_MAX_PROCESSES = 200;
|
|
282
|
+
/**
|
|
283
|
+
* Copy the bundles the fork's rows name and its bundle store lacks. `read` fetches one from the
|
|
284
|
+
* deployment the database was copied from and `store` hands it to the local Atlas, which keeps it
|
|
285
|
+
* only if the fork references its hash and the content hashes to it. A bundle the source cannot
|
|
286
|
+
* serve is counted, not fatal: only the runs pinned to it stay unreadable.
|
|
287
|
+
*/
|
|
288
|
+
export async function copyMissingBundles({ missing, read, store, concurrency = 6 }) {
|
|
289
|
+
let copied = 0;
|
|
290
|
+
const unreadable = [];
|
|
291
|
+
const queue = [...missing];
|
|
292
|
+
const worker = async () => {
|
|
293
|
+
for (;;) {
|
|
294
|
+
const hash = queue.shift();
|
|
295
|
+
if (hash === undefined)
|
|
296
|
+
return;
|
|
297
|
+
try {
|
|
298
|
+
await store(await read(hash));
|
|
299
|
+
copied += 1;
|
|
300
|
+
}
|
|
301
|
+
catch {
|
|
302
|
+
unreadable.push(hash);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
await Promise.all(Array.from({ length: Math.max(1, Math.min(concurrency, missing.length)) }, worker));
|
|
307
|
+
return { copied, unreadable: unreadable.sort() };
|
|
308
|
+
}
|
|
309
|
+
/** Where the deployment a fork was copied from is reached, and this machine's login for it; null when either is missing. */
|
|
310
|
+
async function forkSourceClient(fork) {
|
|
311
|
+
const name = fork.upstreamEnvironment;
|
|
312
|
+
if (!name)
|
|
313
|
+
return { unresolved: 'the local Atlas does not say which deployment its database was copied from' };
|
|
314
|
+
let url;
|
|
315
|
+
try {
|
|
316
|
+
url = (await resolveConfiguredEnv({ requested: name })).url;
|
|
317
|
+
}
|
|
318
|
+
catch {
|
|
319
|
+
return { unresolved: `the environment ${name} is not registered with seq-studio on this machine (seq-studio envs list)` };
|
|
320
|
+
}
|
|
321
|
+
// The same precedence as any command against that environment (a devbox's owner token, else a
|
|
322
|
+
// cached login), without opening a browser. A service identity is not "you": a bundle is read as a person.
|
|
323
|
+
const { tryGetAccessTokenWithMode } = await import('../auth.js');
|
|
324
|
+
const auth = await tryGetAccessTokenWithMode({ env: name, targetUrl: url }).catch(() => null);
|
|
325
|
+
return auth && auth.authMode !== 'm2m'
|
|
326
|
+
? { baseUrl: url, token: auth.token }
|
|
327
|
+
: { unresolved: `this machine holds no login of yours for ${name} (seq-studio login -e ${name})` };
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Bring the bundles of the processes an app uses onto a devbox fork, read from the fork source as
|
|
331
|
+
* you. Without them every existing run and task of those processes fails with "Bundle not found".
|
|
332
|
+
*/
|
|
333
|
+
export async function copyProcessBundles({ ctx, fork, processIds }) {
|
|
334
|
+
const named = processIds === 'all' ? [] : [...new Set(processIds)].sort();
|
|
335
|
+
const ids = processIds === 'all' || named.length > BUNDLE_COPY_MAX_PROCESSES ? 'all' : named;
|
|
336
|
+
const listed = await postJsonResponse({ ...ctx.client, path: '/api/platform/local-fork/process-bundles/missing', body: { processes: ids } }).catch(() => null);
|
|
337
|
+
if (!listed || listed.status === 404)
|
|
338
|
+
return { ok: false, reason: 'this local Atlas cannot copy process bundles (its checkout predates the fork bundle route)' };
|
|
339
|
+
if (listed.status < 200 || listed.status >= 300)
|
|
340
|
+
return { ok: false, reason: detailOf(listed.body) ?? `the local Atlas answered HTTP ${listed.status}` };
|
|
341
|
+
let state;
|
|
342
|
+
try {
|
|
343
|
+
state = z.looseObject({ referenced: z.number(), missing: z.array(z.string()) }).parse(JSON.parse(listed.body));
|
|
344
|
+
}
|
|
345
|
+
catch {
|
|
346
|
+
return { ok: false, reason: 'the local Atlas sent an unrecognized bundle listing; upgrade seq-studio or that Atlas' };
|
|
347
|
+
}
|
|
348
|
+
if (state.missing.length === 0)
|
|
349
|
+
return { ok: true, referenced: state.referenced, copied: 0, unreadable: [] };
|
|
350
|
+
const source = await forkSourceClient(fork);
|
|
351
|
+
if ('unresolved' in source)
|
|
352
|
+
return { ok: false, reason: `${state.missing.length} bundle(s) are missing and ${source.unresolved}` };
|
|
353
|
+
const result = await copyMissingBundles({
|
|
354
|
+
missing: state.missing,
|
|
355
|
+
read: async (hash) => at(await getJson({ ...source, path: `/api/lattice/bundles/${hash}` }), 'bundle'),
|
|
356
|
+
store: async (bundle) => {
|
|
357
|
+
const response = await postJsonResponse({ ...ctx.client, path: '/api/platform/local-fork/process-bundles', body: { bundle } });
|
|
358
|
+
if (response.status < 200 || response.status >= 300)
|
|
359
|
+
throw new Error(detailOf(response.body) ?? `HTTP ${response.status}`);
|
|
360
|
+
},
|
|
361
|
+
});
|
|
362
|
+
return { ok: true, referenced: state.referenced, ...result };
|
|
363
|
+
}
|
|
364
|
+
/** One line saying what the bundle copy did. */
|
|
365
|
+
export function bundleCopyReport({ outcome, sourceEnvironment }) {
|
|
366
|
+
if (!outcome.ok)
|
|
367
|
+
return [`process bundles: not copied (${outcome.reason}); existing runs and tasks of this app's processes cannot be read here`];
|
|
368
|
+
const from = sourceEnvironment ?? 'the fork source';
|
|
369
|
+
if (outcome.copied === 0 && outcome.unreadable.length === 0)
|
|
370
|
+
return [`process bundles: all ${outcome.referenced} the fork references are here`];
|
|
371
|
+
return [
|
|
372
|
+
`process bundles: copied ${outcome.copied} of the ${outcome.referenced} this fork references from ${from}` +
|
|
373
|
+
(outcome.unreadable.length ? `; ${outcome.unreadable.length} could not be read there, so runs pinned to them stay unreadable` : ''),
|
|
374
|
+
];
|
|
375
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a pnpm-workspace.yaml only sets install policy for the one package beside it. A bundle may not
|
|
3
|
+
* carry the file because `catalog`, `overrides` and workspace members can resolve a dependency outside
|
|
4
|
+
* the pinned registry; a file with none of those changes nothing the bundle installs.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isInstallPolicyOnly(text: string): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* The directory a preview deploys a function from. A function that keeps an install-policy-only
|
|
9
|
+
* pnpm-workspace.yaml for authoring is deployed from a copy without it, as its repository's own release
|
|
10
|
+
* export does; anything else is deployed from where it is, and the bundle check decides.
|
|
11
|
+
*/
|
|
12
|
+
export declare function previewFunctionSource(dir: string): Promise<{
|
|
13
|
+
dir: string;
|
|
14
|
+
omitted: string | null;
|
|
15
|
+
cleanup: () => Promise<void>;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { cp, mkdtemp, readFile, rm } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { basename, join } from 'node:path';
|
|
5
|
+
import { parse as parseYaml } from 'yaml';
|
|
6
|
+
const WORKSPACE_FILES = ['pnpm-workspace.yaml', 'pnpm-workspace.yml'];
|
|
7
|
+
/** Keys that only say how an install behaves. None of them can point a dependency somewhere else. */
|
|
8
|
+
const INSTALL_POLICY_KEYS = new Set([
|
|
9
|
+
'packages',
|
|
10
|
+
'minimumReleaseAge',
|
|
11
|
+
'minimumReleaseAgeExclude',
|
|
12
|
+
'strictDepBuilds',
|
|
13
|
+
'allowBuilds',
|
|
14
|
+
'onlyBuiltDependencies',
|
|
15
|
+
'ignoredBuiltDependencies',
|
|
16
|
+
]);
|
|
17
|
+
const NOT_COPIED = new Set(['node_modules', '.git']);
|
|
18
|
+
/**
|
|
19
|
+
* Whether a pnpm-workspace.yaml only sets install policy for the one package beside it. A bundle may not
|
|
20
|
+
* carry the file because `catalog`, `overrides` and workspace members can resolve a dependency outside
|
|
21
|
+
* the pinned registry; a file with none of those changes nothing the bundle installs.
|
|
22
|
+
*/
|
|
23
|
+
export function isInstallPolicyOnly(text) {
|
|
24
|
+
let parsed;
|
|
25
|
+
try {
|
|
26
|
+
parsed = parseYaml(text);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
if (parsed === null || parsed === undefined)
|
|
32
|
+
return true;
|
|
33
|
+
if (typeof parsed !== 'object' || Array.isArray(parsed))
|
|
34
|
+
return false;
|
|
35
|
+
if (!Object.keys(parsed).every((key) => INSTALL_POLICY_KEYS.has(key)))
|
|
36
|
+
return false;
|
|
37
|
+
const packages = Reflect.get(parsed, 'packages');
|
|
38
|
+
return packages === undefined || (Array.isArray(packages) && packages.every((entry) => entry === '.'));
|
|
39
|
+
}
|
|
40
|
+
async function usesWorkspacePackages(dir) {
|
|
41
|
+
const path = join(dir, 'package.json');
|
|
42
|
+
if (!existsSync(path))
|
|
43
|
+
return false;
|
|
44
|
+
return (await readFile(path, 'utf8')).includes('"workspace:');
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The directory a preview deploys a function from. A function that keeps an install-policy-only
|
|
48
|
+
* pnpm-workspace.yaml for authoring is deployed from a copy without it, as its repository's own release
|
|
49
|
+
* export does; anything else is deployed from where it is, and the bundle check decides.
|
|
50
|
+
*/
|
|
51
|
+
export async function previewFunctionSource(dir) {
|
|
52
|
+
const unchanged = { dir, omitted: null, cleanup: async () => { } };
|
|
53
|
+
const present = WORKSPACE_FILES.filter((name) => existsSync(join(dir, name)));
|
|
54
|
+
if (present.length === 0 || (await usesWorkspacePackages(dir)))
|
|
55
|
+
return unchanged;
|
|
56
|
+
for (const name of present) {
|
|
57
|
+
if (!isInstallPolicyOnly(await readFile(join(dir, name), 'utf8')))
|
|
58
|
+
return unchanged;
|
|
59
|
+
}
|
|
60
|
+
const scratch = await mkdtemp(join(tmpdir(), 'seq-preview-fn-'));
|
|
61
|
+
const copy = join(scratch, basename(dir));
|
|
62
|
+
await cp(dir, copy, {
|
|
63
|
+
recursive: true,
|
|
64
|
+
filter: (source) => !NOT_COPIED.has(basename(source)) && !(present.includes(basename(source)) && join(dir, basename(source)) === source),
|
|
65
|
+
});
|
|
66
|
+
return { dir: copy, omitted: present.join(', '), cleanup: () => rm(scratch, { recursive: true, force: true }) };
|
|
67
|
+
}
|
|
@@ -46,6 +46,15 @@ export declare function repositoryInstallRoot({ artifactDir, gitRoot, exists }:
|
|
|
46
46
|
exists?: (path: string) => boolean;
|
|
47
47
|
}): string;
|
|
48
48
|
/** Progress goes to stderr so `--json` output stays a single document. */
|
|
49
|
+
/** Chainguard's registry of unmodified upstream tarballs, beside its default one of rebuilt packages. */
|
|
50
|
+
export declare const UPSTREAM_BYTES_REGISTRY = "https://libraries.cgr.dev/javascript-upstream/";
|
|
51
|
+
/**
|
|
52
|
+
* Run the install. A lockfile records the checksum of each tarball, and the two Chainguard registries
|
|
53
|
+
* serve different bytes for one version: rebuilt packages by default, the unmodified upstream ones
|
|
54
|
+
* beside them. A frozen install of a lockfile resolved against the other registry is refused for its
|
|
55
|
+
* checksums, so that refusal is retried once against the upstream-bytes registry. The lockfile stays
|
|
56
|
+
* the authority: a tarball matching neither is still refused.
|
|
57
|
+
*/
|
|
49
58
|
export declare function installDependencies({ root, args }: {
|
|
50
59
|
root: string;
|
|
51
60
|
args: string[];
|
|
@@ -2,6 +2,7 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import { existsSync, readFileSync } from 'node:fs';
|
|
3
3
|
import { dirname, isAbsolute, join, relative, sep } from 'node:path';
|
|
4
4
|
import { parse as parseYaml } from 'yaml';
|
|
5
|
+
import { commandInvocation } from '@sequenceholdings/artifact-studio/command-invocation';
|
|
5
6
|
/**
|
|
6
7
|
* A frozen install fails when pnpm's peer setting differs from the one the lockfile was written
|
|
7
8
|
* with, and a fresh clone has no local workspace file to say which that was. The lockfile records
|
|
@@ -105,10 +106,40 @@ export function repositoryInstallRoot({ artifactDir, gitRoot, exists = existsSyn
|
|
|
105
106
|
return artifactDir;
|
|
106
107
|
}
|
|
107
108
|
/** Progress goes to stderr so `--json` output stays a single document. */
|
|
108
|
-
|
|
109
|
+
/** Chainguard's registry of unmodified upstream tarballs, beside its default one of rebuilt packages. */
|
|
110
|
+
export const UPSTREAM_BYTES_REGISTRY = 'https://libraries.cgr.dev/javascript-upstream/';
|
|
111
|
+
const CHECKSUM_MISMATCH = 'ERR_PNPM_TARBALL_INTEGRITY';
|
|
112
|
+
function runInstall({ root, args }) {
|
|
109
113
|
return new Promise((resolvePromise, reject) => {
|
|
110
|
-
const
|
|
114
|
+
const invocation = commandInvocation({ command: 'pnpm', args });
|
|
115
|
+
const child = spawn(invocation.file, invocation.args, {
|
|
116
|
+
cwd: root, stdio: ['ignore', 'pipe', 'pipe'], shell: false,
|
|
117
|
+
...(invocation.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}),
|
|
118
|
+
});
|
|
119
|
+
let checksumMismatch = false;
|
|
120
|
+
// pnpm reports a refused tarball on stdout; both streams go to stderr, where a preview's progress belongs.
|
|
121
|
+
for (const stream of [child.stdout, child.stderr]) {
|
|
122
|
+
stream.on('data', (chunk) => {
|
|
123
|
+
if (chunk.includes(CHECKSUM_MISMATCH))
|
|
124
|
+
checksumMismatch = true;
|
|
125
|
+
process.stderr.write(chunk);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
111
128
|
child.once('error', reject);
|
|
112
|
-
child.once('exit', (code) => resolvePromise(code ?? 1));
|
|
129
|
+
child.once('exit', (code) => resolvePromise({ code: code ?? 1, checksumMismatch }));
|
|
113
130
|
});
|
|
114
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Run the install. A lockfile records the checksum of each tarball, and the two Chainguard registries
|
|
134
|
+
* serve different bytes for one version: rebuilt packages by default, the unmodified upstream ones
|
|
135
|
+
* beside them. A frozen install of a lockfile resolved against the other registry is refused for its
|
|
136
|
+
* checksums, so that refusal is retried once against the upstream-bytes registry. The lockfile stays
|
|
137
|
+
* the authority: a tarball matching neither is still refused.
|
|
138
|
+
*/
|
|
139
|
+
export async function installDependencies({ root, args }) {
|
|
140
|
+
const first = await runInstall({ root, args });
|
|
141
|
+
if (first.code === 0 || !first.checksumMismatch || args.some((arg) => arg.startsWith('--registry')))
|
|
142
|
+
return first.code;
|
|
143
|
+
console.error(`[seq-studio] the lockfile's checksums are not the default registry's; installing from ${UPSTREAM_BYTES_REGISTRY}, which serves the unmodified upstream tarballs`);
|
|
144
|
+
return (await runInstall({ root, args: [...args, `--registry=${UPSTREAM_BYTES_REGISTRY}`] })).code;
|
|
145
|
+
}
|
|
@@ -26,7 +26,7 @@ const declaredDependencies = (resource) => {
|
|
|
26
26
|
const value = Reflect.get(resource, 'depends_on');
|
|
27
27
|
return Array.isArray(value) ? value.filter((id) => typeof id === 'string') : [];
|
|
28
28
|
};
|
|
29
|
-
/** A kebab-case app id from a directory name, which may start with a digit or hold other characters. */
|
|
29
|
+
/** A kebab-case app id from a directory name or a project id, which may start with a digit or hold other characters. */
|
|
30
30
|
function appIdFor(directory) {
|
|
31
31
|
const slug = slugifyAppId(basename(directory));
|
|
32
32
|
return (/^[a-z]/.test(slug) ? slug : `app-${slug}`).slice(0, 64).replace(/-+$/, '');
|
|
@@ -142,7 +142,12 @@ export async function loadPreviewManifest({ dir, only }) {
|
|
|
142
142
|
// each one that is planned until none is left unread. An artifact outside the plan is never opened.
|
|
143
143
|
const bundles = {};
|
|
144
144
|
const read = new Set();
|
|
145
|
-
|
|
145
|
+
// One artifact under the directory names the app: directories called `web` or `artifact` are shared by many.
|
|
146
|
+
const artifactsHere = resources.filter((resource) => resource.kind === 'artifact' && under({ path: resource.path, root: requestedPath }));
|
|
147
|
+
const soleArtifact = artifactsHere.length === 1 ? artifactsHere[0] : undefined;
|
|
148
|
+
const projectId = soleArtifact ? Reflect.get(soleArtifact, 'project_id') : undefined;
|
|
149
|
+
const appId = appIdFor(typeof projectId === 'string' && projectId ? projectId : soleArtifact ? soleArtifact.id : realDir);
|
|
150
|
+
const build = () => manifestFromIndex({ resources, requestedPath, bundles, appId, cliVersion: currentVersion(), only });
|
|
146
151
|
let built = build();
|
|
147
152
|
for (;;) {
|
|
148
153
|
const unread = built.manifest.primitives.filter((entry) => entry.kind === 'artifact' && !read.has(entry.id));
|
|
@@ -43,11 +43,15 @@ export interface FunctionInspection {
|
|
|
43
43
|
unavailableSets: string[];
|
|
44
44
|
}
|
|
45
45
|
/** Read what a function will be able to reach and where its secrets come from, before anything deploys. */
|
|
46
|
-
export declare function inspectFunction({ ctx, entry, provided, providedFile }: {
|
|
46
|
+
export declare function inspectFunction({ ctx, entry, provided, providedFile, appFile }: {
|
|
47
47
|
ctx: PreviewContext;
|
|
48
48
|
entry: PrimitiveEntry;
|
|
49
49
|
provided: Record<string, string>;
|
|
50
50
|
providedFile: string | null;
|
|
51
|
+
appFile?: {
|
|
52
|
+
file: string;
|
|
53
|
+
values: Record<string, string>;
|
|
54
|
+
};
|
|
51
55
|
}): Promise<FunctionInspection>;
|
|
52
56
|
export declare function deployFunction({ ctx, inspection, force }: {
|
|
53
57
|
ctx: PreviewContext;
|
|
@@ -7,6 +7,7 @@ import { getJson, getJsonOr404, postJsonResponse } from '../atlas-client.js';
|
|
|
7
7
|
import { resolveContainedPrimitivePath } from '../app/paths.js';
|
|
8
8
|
import { schemaViewSchema } from '../orm/discover-schema.js';
|
|
9
9
|
import { fingerprintMessage, fingerprintOf, functionFingerprint } from './fingerprint.js';
|
|
10
|
+
import { previewFunctionSource } from './function-source.js';
|
|
10
11
|
import { decideInstall, installDependencies, repositoryInstallRoot } from './install.js';
|
|
11
12
|
import { interpretNamespaceProbe } from './namespace-probe.js';
|
|
12
13
|
import { chooseOrmSdk, installOrmMessage } from './orm-sdk.js';
|
|
@@ -22,13 +23,24 @@ async function applyNamespace({ ctx, entry, namespace }) {
|
|
|
22
23
|
const dir = await primitiveDir({ ctx, entry });
|
|
23
24
|
const { bundledSdk, projectSdk, SDK_ENV } = await import('../sdk-source.js');
|
|
24
25
|
const { pinnedOrmRange } = await import('../orm/version-guard.js');
|
|
25
|
-
const
|
|
26
|
+
const range = await pinnedOrmRange(dir);
|
|
27
|
+
const choose = () => process.env[SDK_ENV]?.trim()
|
|
26
28
|
? { use: 'default' }
|
|
27
29
|
: chooseOrmSdk({
|
|
28
|
-
range
|
|
30
|
+
range,
|
|
29
31
|
bundled: bundledSdk({ name: ORM_PACKAGE })?.version,
|
|
30
32
|
project: projectSdk({ name: ORM_PACKAGE, cwd: dir })?.version,
|
|
31
33
|
});
|
|
34
|
+
let choice = choose();
|
|
35
|
+
// A fresh clone has nothing installed. The namespace's own copy is the only ORM its pin accepts, so
|
|
36
|
+
// install it as an artifact's dependencies are, then decide again. A copy that is installed and
|
|
37
|
+
// still outside the pin is the developer's to change.
|
|
38
|
+
if (choice.use === 'install' && choice.installed === undefined) {
|
|
39
|
+
const failed = await ensureDependencies({ ctx, dir, label: `namespace ${namespace}` });
|
|
40
|
+
if (failed)
|
|
41
|
+
return failed;
|
|
42
|
+
choice = choose();
|
|
43
|
+
}
|
|
32
44
|
if (choice.use === 'install')
|
|
33
45
|
return { status: 'failed', detail: installOrmMessage({ namespace, dir, choice }) };
|
|
34
46
|
const { runOrmCommand } = await import('../orm/delegate.js');
|
|
@@ -106,7 +118,7 @@ export function probeRelations({ tables, views }) {
|
|
|
106
118
|
return [...tables.map(({ table }) => table), ...views.map(({ view }) => view)];
|
|
107
119
|
}
|
|
108
120
|
/** Read what a function will be able to reach and where its secrets come from, before anything deploys. */
|
|
109
|
-
export async function inspectFunction({ ctx, entry, provided, providedFile }) {
|
|
121
|
+
export async function inspectFunction({ ctx, entry, provided, providedFile, appFile }) {
|
|
110
122
|
const { readManifestOptional } = await import('../functions/commands.js');
|
|
111
123
|
const dir = await primitiveDir({ ctx, entry });
|
|
112
124
|
const manifest = await readManifestOptional(dir);
|
|
@@ -120,7 +132,7 @@ export async function inspectFunction({ ctx, entry, provided, providedFile }) {
|
|
|
120
132
|
entry,
|
|
121
133
|
slug: manifest.function.id,
|
|
122
134
|
egress: [...manifest.egress],
|
|
123
|
-
secrets: planFunctionSecrets({ declared: single, provided, providedFile, storedLocally, target: ctx.target }),
|
|
135
|
+
secrets: planFunctionSecrets({ declared: single, provided, providedFile, appFile, storedLocally, target: ctx.target }),
|
|
124
136
|
unavailableSets: sets.filter((name) => !storedLocally.has(name)),
|
|
125
137
|
};
|
|
126
138
|
}
|
|
@@ -174,8 +186,20 @@ async function ownedHere({ ctx, slug }) {
|
|
|
174
186
|
return result.adopted === false;
|
|
175
187
|
}
|
|
176
188
|
export async function deployFunction({ ctx, inspection, force }) {
|
|
189
|
+
const source = await previewFunctionSource(await primitiveDir({ ctx, entry: inspection.entry }));
|
|
190
|
+
try {
|
|
191
|
+
return await deployFunctionFrom({ ctx, inspection, force, source });
|
|
192
|
+
}
|
|
193
|
+
finally {
|
|
194
|
+
await source.cleanup();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
async function deployFunctionFrom({ ctx, inspection, force, source }) {
|
|
177
198
|
const { functionsDeployCommand } = await import('../functions/commands.js');
|
|
178
|
-
const dir =
|
|
199
|
+
const dir = source.dir;
|
|
200
|
+
if (source.omitted) {
|
|
201
|
+
console.error(`[seq-studio] ${inspection.slug}: leaving ${source.omitted} out of the bundle; it only sets install policy, and a function bundle may not carry it`);
|
|
202
|
+
}
|
|
179
203
|
const files = await deployedBundleFiles(dir);
|
|
180
204
|
const fingerprint = functionFingerprint({ files, sources: inspection.secrets.sources, values: inspection.secrets.values });
|
|
181
205
|
// A matching fingerprint only proves what was deployed, not where. A database copied from
|
|
@@ -30,15 +30,20 @@ export interface SecretPlan {
|
|
|
30
30
|
/** Facts about this preview a secret value may be built from. Nothing here is a credential. */
|
|
31
31
|
export declare function previewFacts(target: PreviewTarget): Record<string, string | undefined>;
|
|
32
32
|
/**
|
|
33
|
-
* Decide each declared secret's source, in this order: the reviewed secrets file,
|
|
34
|
-
* already stored in this local Atlas. There is no
|
|
33
|
+
* Decide each declared secret's source, in this order: the reviewed secrets file, the app's own
|
|
34
|
+
* preview file, then a value already stored in this local Atlas. There is no other source. A value copied by a database fork
|
|
35
35
|
* points at another runtime's secret, which a preview cannot and must not read, and a preview
|
|
36
36
|
* never substitutes some other credential the machine happens to hold.
|
|
37
37
|
*/
|
|
38
|
-
export declare function planFunctionSecrets({ declared, provided, providedFile, storedLocally, target, environment }: {
|
|
38
|
+
export declare function planFunctionSecrets({ declared, provided, providedFile, appFile, storedLocally, target, environment }: {
|
|
39
39
|
declared: readonly string[];
|
|
40
40
|
provided: Record<string, string>;
|
|
41
41
|
providedFile: string | null;
|
|
42
|
+
/** The app's own file. It may build a value from this preview or state one, never name a variable of this machine. */
|
|
43
|
+
appFile?: {
|
|
44
|
+
file: string;
|
|
45
|
+
values: Record<string, string>;
|
|
46
|
+
};
|
|
42
47
|
storedLocally: ReadonlySet<string>;
|
|
43
48
|
target: PreviewTarget;
|
|
44
49
|
environment?: Record<string, string | undefined>;
|
|
@@ -26,19 +26,26 @@ function expand({ raw, facts }) {
|
|
|
26
26
|
return { value, used, unknown };
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* Decide each declared secret's source, in this order: the reviewed secrets file,
|
|
30
|
-
* already stored in this local Atlas. There is no
|
|
29
|
+
* Decide each declared secret's source, in this order: the reviewed secrets file, the app's own
|
|
30
|
+
* preview file, then a value already stored in this local Atlas. There is no other source. A value copied by a database fork
|
|
31
31
|
* points at another runtime's secret, which a preview cannot and must not read, and a preview
|
|
32
32
|
* never substitutes some other credential the machine happens to hold.
|
|
33
33
|
*/
|
|
34
|
-
export function planFunctionSecrets({ declared, provided, providedFile, storedLocally, target, environment = process.env }) {
|
|
34
|
+
export function planFunctionSecrets({ declared, provided, providedFile, appFile, storedLocally, target, environment = process.env }) {
|
|
35
35
|
const facts = previewFacts(target);
|
|
36
36
|
const sources = [];
|
|
37
37
|
const values = {};
|
|
38
38
|
const missing = [];
|
|
39
39
|
for (const name of new Set(declared)) {
|
|
40
|
-
const
|
|
41
|
-
|
|
40
|
+
const reviewed = providedFile ? provided[name] : undefined;
|
|
41
|
+
const own = reviewed ? undefined : appFile?.values[name];
|
|
42
|
+
if (own && appFile && own.search(ENVIRONMENT) !== -1) {
|
|
43
|
+
throw new Error(`${name} in ${appFile.file} uses \${env.…}. An app's own preview file may only state a value or build one from ` +
|
|
44
|
+
'${preview.…}; a value held in this machine\'s environment is named in a reviewed file passed with --secrets.');
|
|
45
|
+
}
|
|
46
|
+
const raw = reviewed || own;
|
|
47
|
+
const file = reviewed ? providedFile : appFile?.file;
|
|
48
|
+
if (raw && file) {
|
|
42
49
|
const variables = [];
|
|
43
50
|
const unset = [];
|
|
44
51
|
const withEnvironment = raw.replace(ENVIRONMENT, (_match, variable) => {
|
|
@@ -57,17 +64,17 @@ export function planFunctionSecrets({ declared, provided, providedFile, storedLo
|
|
|
57
64
|
}
|
|
58
65
|
const { value, used, unknown } = expand({ raw: withEnvironment, facts });
|
|
59
66
|
if (unknown.length > 0) {
|
|
60
|
-
throw new Error(`${name} in ${
|
|
67
|
+
throw new Error(`${name} in ${file} uses \${preview.${unknown[0]}}, which this preview cannot supply. ` +
|
|
61
68
|
`Available: ${Object.keys(facts).filter((key) => facts[key] !== undefined).map((key) => `\${preview.${key}}`).join(', ')}`);
|
|
62
69
|
}
|
|
63
70
|
values[name] = value;
|
|
64
71
|
if (variables.length > 0) {
|
|
65
|
-
sources.push({ name, source: 'environment', variables, file:
|
|
72
|
+
sources.push({ name, source: 'environment', variables, file: file });
|
|
66
73
|
continue;
|
|
67
74
|
}
|
|
68
75
|
sources.push(used.length > 0 && raw.replace(PLACEHOLDER, '').length === 0
|
|
69
76
|
? { name, source: 'derived', from: used.map((key) => `preview.${key}`).join(' + ') }
|
|
70
|
-
: { name, source: 'provided', file:
|
|
77
|
+
: { name, source: 'provided', file: file });
|
|
71
78
|
}
|
|
72
79
|
else if (storedLocally.has(name)) {
|
|
73
80
|
sources.push({ name, source: 'local-store' });
|
|
@@ -4,4 +4,6 @@ export declare const PREVIEW_ORIGIN_ENV = "SEQ_STUDIO_PREVIEW_ORIGIN";
|
|
|
4
4
|
export declare const PREVIEW_APPS_ORIGIN_ENV = "SEQ_STUDIO_PREVIEW_APPS_ORIGIN";
|
|
5
5
|
/** A directory of reviewed `<app id>.env` secret files, for machines provisioned to preview apps. */
|
|
6
6
|
export declare const PREVIEW_SECRETS_DIR_ENV = "SEQ_STUDIO_PREVIEW_SECRETS_DIR";
|
|
7
|
-
|
|
7
|
+
/** The file an app keeps beside its manifest (or in the previewed directory) for values a preview can build itself. */
|
|
8
|
+
export declare const APP_PREVIEW_SECRETS_FILENAME = "sequence.preview.env";
|
|
9
|
+
export declare const PREVIEW_USAGE = "usage: seq-studio preview [dir] -e local [--only <id>[,<id>...]] [--secrets <file>] [--secret-source <source>] [--apply-orm] [--watch] [--force] [--yes] [--json]\n\nStand up this app on a local Atlas and print where to open it. Reads sequence.app.yml and, in\ndependency order: checks each ORM namespace answers reads, deploys each function to the local\nruntime, and publishes each artifact to its preview channel. By default it previews the app's\nartifacts and what they depend on; --only names other primitives (a process, a function) to start.\n\nA directory with no sequence.app.yml is previewed from its repository's .seq/repository.yml: the\nresources declared at or under that directory, plus the namespaces, functions, processes and\nworkspaces each artifact.bundle.yml reaches, wherever the repository declares them. Before it runs,\nthe command lists what each artifact declares that it does not set up (workspaces, server secrets,\nexternal-ingress service accounts, anything no resource declares) and carries on.\n\nOn a devbox whose database is a copy of a hosted deployment's, it also adopts the workspaces each\nartifact declares from that copy (their files are not copied), admits the service identities the\ncopied project records, removes from that copy the development bindings the application no longer\ndeclares, copies from that deployment the bundles of the processes the app uses (so the runs and\ntasks the copy already holds can be read), and reads a Next.js app's server secrets from that\ndeployment as you, into memory only, when this machine holds your token for it. Each of these is\nlisted as it happens.\n\nBefore a Next.js session starts, the directories its bundle lists under build.source_includes are\ncopied to .artifact-includes in the app, where the hosted build mounts them.\n\nRuns only against a local Atlas on a personal or devbox database branch. It changes that database\ncopy and nothing else. Only the database is a copy: a function deployed here runs with the secret\nvalues you give it and reaches the real systems those credentials open. Declared egress is not\nenforced by the local runtime. Each function's egress and secret sources are shown before it deploys.\n\n --only <ids> preview these primitives and their dependencies instead of the artifacts\n --secrets <file> reviewed dotenv file of function secret values (default: $SEQ_STUDIO_PREVIEW_SECRETS_DIR/<app id>.env).\n A value may use ${preview.atlas_origin}, ${preview.database.host},\n ${preview.database.endpoint}, ${preview.database.name}, ${preview.database.branch}.\n ${env.NAME} takes the value from that variable of this command's environment.\n A secret with no value there or in this local Atlas stops the preview.\n An app may also commit sequence.preview.env in the directory you preview: the same format,\n limited to stated values and ${preview.\u2026}. The reviewed file wins where both set a name.\n --secret-source <source>\n where a Next.js app's server.secrets come from, as for seq-studio artifact dev\n (local, none). Without it, a devbox fork reads them from the deployment its\n database was copied from; anywhere else the local Atlas store is used.\n --apply-orm apply each namespace's local definition to this database copy before checking it.\n Without a sequence.app.yml, only namespaces under [dir] are applied: one pulled in\n from elsewhere in the repository is checked, and applied only when --only names it.\n --only replaces the selection: list it with what you are previewing (its summary\n line gives the exact flag).\n A namespace pinned to an ORM version this CLI's does not satisfy is applied with\n its own installed copy.\n --watch keep rebuilding a static artifact on change (a Next.js app always stays attached)\n --force redeploy a function even when nothing it is built from changed. Needed after a\n credential held in an environment variable is rotated.\n --yes do not ask before deploying functions\n --json print the result as JSON\n\nSet SEQ_STUDIO_PREVIEW_ORIGIN to the URL you open the local Atlas at when that is not its own address.";
|
|
@@ -4,6 +4,8 @@ export const PREVIEW_ORIGIN_ENV = 'SEQ_STUDIO_PREVIEW_ORIGIN';
|
|
|
4
4
|
export const PREVIEW_APPS_ORIGIN_ENV = 'SEQ_STUDIO_PREVIEW_APPS_ORIGIN';
|
|
5
5
|
/** A directory of reviewed `<app id>.env` secret files, for machines provisioned to preview apps. */
|
|
6
6
|
export const PREVIEW_SECRETS_DIR_ENV = 'SEQ_STUDIO_PREVIEW_SECRETS_DIR';
|
|
7
|
+
/** The file an app keeps beside its manifest (or in the previewed directory) for values a preview can build itself. */
|
|
8
|
+
export const APP_PREVIEW_SECRETS_FILENAME = 'sequence.preview.env';
|
|
7
9
|
export const PREVIEW_USAGE = `usage: seq-studio preview [dir] -e local [--only <id>[,<id>...]] [--secrets <file>] [--secret-source <source>] [--apply-orm] [--watch] [--force] [--yes] [--json]
|
|
8
10
|
|
|
9
11
|
Stand up this app on a local Atlas and print where to open it. Reads sequence.app.yml and, in
|
|
@@ -20,8 +22,10 @@ external-ingress service accounts, anything no resource declares) and carries on
|
|
|
20
22
|
On a devbox whose database is a copy of a hosted deployment's, it also adopts the workspaces each
|
|
21
23
|
artifact declares from that copy (their files are not copied), admits the service identities the
|
|
22
24
|
copied project records, removes from that copy the development bindings the application no longer
|
|
23
|
-
declares,
|
|
24
|
-
|
|
25
|
+
declares, copies from that deployment the bundles of the processes the app uses (so the runs and
|
|
26
|
+
tasks the copy already holds can be read), and reads a Next.js app's server secrets from that
|
|
27
|
+
deployment as you, into memory only, when this machine holds your token for it. Each of these is
|
|
28
|
+
listed as it happens.
|
|
25
29
|
|
|
26
30
|
Before a Next.js session starts, the directories its bundle lists under build.source_includes are
|
|
27
31
|
copied to .artifact-includes in the app, where the hosted build mounts them.
|
|
@@ -37,6 +41,8 @@ enforced by the local runtime. Each function's egress and secret sources are sho
|
|
|
37
41
|
\${preview.database.endpoint}, \${preview.database.name}, \${preview.database.branch}.
|
|
38
42
|
\${env.NAME} takes the value from that variable of this command's environment.
|
|
39
43
|
A secret with no value there or in this local Atlas stops the preview.
|
|
44
|
+
An app may also commit ${APP_PREVIEW_SECRETS_FILENAME} in the directory you preview: the same format,
|
|
45
|
+
limited to stated values and \${preview.…}. The reviewed file wins where both set a name.
|
|
40
46
|
--secret-source <source>
|
|
41
47
|
where a Next.js app's server.secrets come from, as for seq-studio artifact dev
|
|
42
48
|
(local, none). Without it, a devbox fork reads them from the deployment its
|
package/dist/pnpm-auto-update.js
CHANGED
|
@@ -5,14 +5,19 @@ import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
|
5
5
|
import { dirname, join } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { gt, lt, prerelease, valid } from 'semver';
|
|
8
|
+
import { commandInvocation } from '@sequenceholdings/artifact-studio/command-invocation';
|
|
8
9
|
const PACKAGE = '@sequenceholdings/studio-cli';
|
|
9
10
|
const PACKAGE_PATH = join('@sequenceholdings', 'studio-cli');
|
|
10
11
|
function trackPath() { return join(cliConfigDir(), 'update-track.json'); }
|
|
11
12
|
function installedPackageRoot() {
|
|
12
13
|
return dirname(dirname(fileURLToPath(import.meta.url)));
|
|
13
14
|
}
|
|
15
|
+
function runPnpm({ args, options }) {
|
|
16
|
+
const { file, args: commandArgs, ...windowsOptions } = commandInvocation({ command: 'pnpm', args });
|
|
17
|
+
return spawnSync(file, commandArgs, { ...windowsOptions, ...options });
|
|
18
|
+
}
|
|
14
19
|
function globalPackageRoot() {
|
|
15
|
-
const result =
|
|
20
|
+
const result = runPnpm({ args: ['root', '-g'], options: { encoding: 'utf8', timeout: 5000 } });
|
|
16
21
|
if (result.status !== 0)
|
|
17
22
|
return null;
|
|
18
23
|
const root = result.stdout.trim();
|
|
@@ -100,18 +105,21 @@ export async function maybeUpgradeGlobalPnpm(available, expectedTrack) {
|
|
|
100
105
|
const returnsToStable = prerelease(previous) !== null && prerelease(available) === null;
|
|
101
106
|
if (!gt(available, previous) && !returnsToStable)
|
|
102
107
|
return false;
|
|
103
|
-
const pnpm =
|
|
108
|
+
const pnpm = runPnpm({ args: ['--version'], options: { encoding: 'utf8', timeout: 5000 } });
|
|
104
109
|
const pnpmVersion = pnpm.stdout.trim();
|
|
105
110
|
if (pnpm.status !== 0 || !valid(pnpmVersion) || lt(pnpmVersion, '10.28.2') || !lt(pnpmVersion, '11.0.0'))
|
|
106
111
|
return false;
|
|
107
112
|
if (expectedTrack && await globalUpdateTrack() !== expectedTrack)
|
|
108
113
|
return false;
|
|
109
|
-
const result =
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
114
|
+
const result = runPnpm({
|
|
115
|
+
args: ['add', '-g', '--ignore-scripts', '--registry', 'https://registry.npmjs.org/', `${PACKAGE}@${available}`],
|
|
116
|
+
options: {
|
|
117
|
+
encoding: 'utf8', timeout: 300000,
|
|
118
|
+
env: {
|
|
119
|
+
...process.env,
|
|
120
|
+
npm_config_minimum_release_age: '10080',
|
|
121
|
+
npm_config_minimum_release_age_exclude: '["@sequenceholdings/*"]',
|
|
122
|
+
},
|
|
115
123
|
},
|
|
116
124
|
});
|
|
117
125
|
if (result.status !== 0 || packageVersion(root) !== available)
|
package/dist/repos/commands.js
CHANGED
|
@@ -117,6 +117,8 @@ function assertDestWritable({ destDir, force, }) {
|
|
|
117
117
|
* working tree.
|
|
118
118
|
*/
|
|
119
119
|
export function assertSafeForceDest(destDir) {
|
|
120
|
+
// Windows paths are case-insensitive: `c:\users\you` names the same directory as `C:\Users\you`.
|
|
121
|
+
const comparable = (path) => (process.platform === 'win32' ? path.toLowerCase() : path);
|
|
120
122
|
const resolved = resolve(destDir);
|
|
121
123
|
const cwd = resolve(process.cwd());
|
|
122
124
|
const home = resolve(homedir());
|
|
@@ -130,13 +132,19 @@ export function assertSafeForceDest(destDir) {
|
|
|
130
132
|
resolve('/tmp'),
|
|
131
133
|
resolve('/var'),
|
|
132
134
|
resolve('/etc'),
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
// Windows system locations; unset elsewhere.
|
|
136
|
+
process.env['SystemRoot'] ?? '',
|
|
137
|
+
process.env['ProgramFiles'] ?? '',
|
|
138
|
+
process.env['ProgramFiles(x86)'] ?? '',
|
|
139
|
+
process.env['ProgramData'] ?? '',
|
|
140
|
+
].filter(Boolean).map((path) => comparable(resolve(path))));
|
|
141
|
+
if (forbidden.has(comparable(resolved))) {
|
|
135
142
|
throw new Error(`--force refuses to delete ${resolved} (cwd, home, or system path). ` +
|
|
136
143
|
'Pass a dedicated empty subdirectory, e.g. --out ./my-repo.');
|
|
137
144
|
}
|
|
138
145
|
// Ancestor of cwd (e.g. --out .. --force while inside a project).
|
|
139
|
-
|
|
146
|
+
const ancestorPrefix = comparable(resolved.endsWith(sep) ? resolved : `${resolved}${sep}`);
|
|
147
|
+
if (comparable(cwd) !== comparable(resolved) && comparable(cwd).startsWith(ancestorPrefix)) {
|
|
140
148
|
throw new Error(`--force refuses to delete ${resolved} because it contains the current working directory.`);
|
|
141
149
|
}
|
|
142
150
|
// Too shallow to be a sensible clone target (e.g. /Users/you).
|
package/dist/run-pinned.js
CHANGED
|
@@ -17,6 +17,7 @@ import { existsSync, readFileSync } from 'node:fs';
|
|
|
17
17
|
import { mkdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
18
18
|
import { homedir } from 'node:os';
|
|
19
19
|
import { join } from 'node:path';
|
|
20
|
+
import { commandInvocation } from '@sequenceholdings/artifact-studio/command-invocation';
|
|
20
21
|
import { FIRST_PARTY_RELEASE_AGE_EXCLUDE } from './release-age.js';
|
|
21
22
|
export const USE_PIN_ENV = 'SEQ_STUDIO_USE_PIN';
|
|
22
23
|
export const CLI_CACHE_ENV = 'SEQ_STUDIO_CLI_CACHE';
|
|
@@ -84,7 +85,11 @@ async function installPinnedCli({ pin, deps }) {
|
|
|
84
85
|
await writeFile(join(staging, 'package.json'), `${JSON.stringify({ name: 'seq-studio-pinned-cli', private: true })}\n`);
|
|
85
86
|
await writeFile(join(staging, 'pnpm-workspace.yaml'), pinnedInstallWorkspace());
|
|
86
87
|
const spec = `${PACKAGE}@~${pin}.0`;
|
|
87
|
-
const
|
|
88
|
+
const { file, args, ...windowsOptions } = commandInvocation({
|
|
89
|
+
command: 'pnpm',
|
|
90
|
+
args: ['add', '--dir', staging, '--ignore-scripts', '--reporter=silent', spec],
|
|
91
|
+
});
|
|
92
|
+
const result = deps.spawn(file, args, { ...windowsOptions, encoding: 'utf8', stdio: ['ignore', 'ignore', 'pipe'], timeout: INSTALL_TIMEOUT_MS, env: deps.env });
|
|
88
93
|
if (result.error || result.status !== 0) {
|
|
89
94
|
const lines = String(result.stderr ?? '').split('\n').map((line) => line.trim()).filter(Boolean);
|
|
90
95
|
const detail = result.error?.message ?? lines.find((line) => line.startsWith('ERR_PNPM')) ?? lines.at(-1) ?? `exit ${result.status}`;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
2
|
import { promisify } from 'node:util';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
+
import { commandInvocation } from '@sequenceholdings/artifact-studio/command-invocation';
|
|
4
5
|
const exec = promisify(execFile);
|
|
5
6
|
const gcloudConfigSchema = z.object({
|
|
6
7
|
configuration: z
|
|
@@ -21,7 +22,9 @@ const gcloudConfigSchema = z.object({
|
|
|
21
22
|
export async function readGcloudIdentity() {
|
|
22
23
|
const empty = { project: null, account: null, tokenExpiry: null, accessToken: null };
|
|
23
24
|
try {
|
|
24
|
-
const {
|
|
25
|
+
const { file, args, ...windowsOptions } = commandInvocation({ command: 'gcloud', args: ['config', 'config-helper', '--format=json'] });
|
|
26
|
+
const { stdout } = await exec(file, args, {
|
|
27
|
+
...windowsOptions,
|
|
25
28
|
timeout: 15_000,
|
|
26
29
|
maxBuffer: 1024 * 1024,
|
|
27
30
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sequenceholdings/studio-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Unified Sequence Studio CLI — `seq-studio init` / `add` / `deploy` (app monorepos), `seq-studio agents`, `seq-studio process` (Lattice), `seq-studio artifact`, `seq-studio functions` / `secrets`, `seq-studio repos`, and `seq-studio auth whoami`. Includes Auth0 browser login shared with seqapi.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -46,11 +46,11 @@
|
|
|
46
46
|
"yaml": "^2.8.4",
|
|
47
47
|
"zod": "4.6.6",
|
|
48
48
|
"@sequenceholdings/agent-spec": "0.1.6",
|
|
49
|
-
"@sequenceholdings/artifact-studio": "0.11.
|
|
50
|
-
"@sequenceholdings/
|
|
51
|
-
"@sequenceholdings/platform": "0.1.5",
|
|
49
|
+
"@sequenceholdings/artifact-studio": "0.11.26",
|
|
50
|
+
"@sequenceholdings/lattice": "0.1.9",
|
|
52
51
|
"@sequenceholdings/managed-functions": "0.5.16",
|
|
53
|
-
"@sequenceholdings/
|
|
52
|
+
"@sequenceholdings/storage": "0.1.8",
|
|
53
|
+
"@sequenceholdings/platform": "0.1.5"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"@sequenceholdings/orm": "2.12.1",
|
package/release-summary.json
CHANGED
|
@@ -14,5 +14,6 @@
|
|
|
14
14
|
"1.0.0": "seq-studio 1.0: commands, flags, exit codes and JSON output are now stable. Old spellings still work. promote, secret attach and apply, repos, and --repo from git-service are deprecated: each prints its replacement and is removed in 2.0.",
|
|
15
15
|
"1.0.1": "Next.js artifacts may now pin next@16.4.6, which fixes two Next.js security advisories, as well as 16.4.1. New apps are still scaffolded on 16.4.1 until every Atlas environment admits 16.4.6.",
|
|
16
16
|
"1.0.2": "seq-studio upgrade and repo init no longer move the seq-ci workflows back to an older release when they were bumped ahead of seq_ci in .seq/github.yml. Top-level help and setup hints now point at seq-studio login <deployment-url>.",
|
|
17
|
-
"1.0.3": "Artifact builds now use Atlas UI 4.2.0, including the shared SideNav and SideNavLayout components, through Artifact Studio 0.11.25."
|
|
17
|
+
"1.0.3": "Artifact builds now use Atlas UI 4.2.0, including the shared SideNav and SideNavLayout components, through Artifact Studio 0.11.25.",
|
|
18
|
+
"1.0.4": "Fixes Windows: artifact builds and dev no longer fail with a 400 on the Atlas UI stylesheet path (dist\\tokens.css), and pnpm, npx and gcloud calls now run on Windows."
|
|
18
19
|
}
|