@akanjs/devkit 3.3.0-rc.3 → 3.3.0-rc.30
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/CHANGELOG.md +547 -0
- package/DEV_RUNTIME_KNOBS.md +1 -1
- package/README.ko.md +3 -2
- package/README.md +3 -3
- package/akanApp/akanApp.host.test.ts +1 -1
- package/akanApp/akanApp.host.ts +11 -0
- package/akanConfig/akanBin.ts +4 -0
- package/akanConfig/akanConfig.test.ts +66 -7
- package/akanConfig/akanConfig.ts +53 -204
- package/akanConfig/akanWorkers.test.ts +39 -0
- package/akanConfig/akanWorkers.ts +32 -0
- package/akanConfig/desktopServerConfig.ts +96 -0
- package/akanConfig/dockerImage.ts +37 -0
- package/akanConfig/nativeKeys.ts +52 -0
- package/akanConfig/types.ts +1 -0
- package/app/appBin.test.ts +63 -0
- package/app/appBin.ts +50 -0
- package/app/applicationBuildReporter.test.ts +32 -0
- package/app/applicationBuildReporter.ts +4 -0
- package/app/applicationBuildRunner.test.ts +275 -0
- package/app/applicationBuildRunner.ts +126 -5
- package/app/dictionarySizes.ts +94 -0
- package/artifact/implicitRootLayout.test.ts +19 -0
- package/artifact/implicitRootLayout.ts +16 -2
- package/artifact/implicitRootLayoutRender.test.tsx +4 -1
- package/artifact/storeBootstrap.test.ts +28 -0
- package/artifact/storeBootstrap.ts +60 -8
- package/biome.base.json +5 -1
- package/codeAgent/agent/CodeAgent.ts +36 -16
- package/codeAgent/agent/CodeAgentAllowed.ts +35 -0
- package/codeAgent/agent/CodeAgentCommandLine.ts +372 -0
- package/codeAgent/agent/CodeAgentGate.ts +23 -4
- package/codeAgent/agent/CodeAgentRpcHost.ts +1 -1
- package/codeAgent/agent/codeAgent.test.ts +62 -0
- package/codeAgent/agent/codeAgentCommandLine.test.ts +212 -0
- package/codeAgent/agent/codeAgentContract.test.ts +117 -5
- package/codeAgent/skills/akan-agent/SKILL.md +8 -1
- package/codeAgent/skills/akan-code/SKILL.md +38 -3
- package/codeAgent/skills/akan-deps/SKILL.md +3 -2
- package/codeAgent/skills/akan-err/SKILL.md +13 -8
- package/codeAgent/skills/akan-mcp/SKILL.md +1 -1
- package/codeAgent/skills/akan-module/SKILL.md +2 -2
- package/codeAgent/skills/akan-page/SKILL.md +4 -14
- package/codeAgent/skills/akan-query/SKILL.md +13 -20
- package/codeAgent/skills/akan-runtime/SKILL.md +20 -0
- package/codeAgent/skills/akan-service/SKILL.md +2 -5
- package/codeAgent/skills/akan-transport/SKILL.md +5 -14
- package/codeAgent/skills/akan-ui/SKILL.md +2 -5
- package/context/akanContext.ts +2 -0
- package/docs/apiReference.test.ts +9 -0
- package/docs/apiReference.ts +14 -0
- package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
- package/executors/clientRuntimeKeys.fixture.json +393 -0
- package/executors/clientRuntimeKeys.test.ts +1591 -0
- package/executors/executors.test.ts +2 -0
- package/executors/sysExecutor.ts +66 -3
- package/executors/workspaceExecutor.ts +7 -4
- package/frontendBuild/allRoutesBuilder.ts +72 -3
- package/frontendBuild/autoImportSync.ts +3 -2
- package/frontendBuild/buildRouteClient.test.ts +515 -12
- package/frontendBuild/clientBuildTypes.ts +15 -0
- package/frontendBuild/clientEntriesBundler.ts +38 -0
- package/frontendBuild/clientEntryDiscovery.test.ts +95 -1
- package/frontendBuild/clientEntryDiscovery.ts +88 -7
- package/frontendBuild/csrDevModuleCompiler.test.ts +86 -0
- package/frontendBuild/csrDevModuleCompiler.ts +44 -8
- package/frontendBuild/csrDevPatcher.ts +33 -7
- package/frontendBuild/csrDevTypes.ts +9 -0
- package/frontendBuild/devBarrelImports.test.ts +100 -0
- package/frontendBuild/devBarrelImports.ts +82 -23
- package/frontendBuild/devRegistryBundler.ts +4 -2
- package/frontendBuild/devRouteRuntime.test.ts +492 -0
- package/frontendBuild/devRouteRuntime.ts +167 -0
- package/frontendBuild/dictionaryAssetBuilder.test.ts +316 -0
- package/frontendBuild/dictionaryAssetBuilder.ts +152 -16
- package/frontendBuild/dictionaryConstants.ts +82 -0
- package/frontendBuild/dictionaryPacking.test.ts +84 -0
- package/frontendBuild/dictionaryPacking.ts +92 -0
- package/frontendBuild/dictionaryRoutes.test.ts +186 -0
- package/frontendBuild/dictionaryRoutes.ts +225 -0
- package/frontendBuild/pagesBundleBuilder.test.ts +84 -0
- package/frontendBuild/pagesBundleBuilder.ts +81 -3
- package/frontendBuild/precompressArtifacts.ts +7 -0
- package/frontendBuild/registryMetadataFingerprint.ts +3 -3
- package/frontendBuild/routeClientBuilder.ts +288 -15
- package/frontendBuild/routeHandoffs.test.ts +145 -0
- package/frontendBuild/routeHandoffs.ts +115 -0
- package/frontendBuild/routeRuntimeCheck.test.ts +257 -0
- package/frontendBuild/routeRuntimeCheck.ts +241 -0
- package/frontendBuild/routeRuntimePays.test.ts +137 -0
- package/frontendBuild/routeRuntimePays.ts +117 -0
- package/frontendBuild/rscServerRendererGuard.test.ts +60 -0
- package/frontendBuild/rscServerRendererGuard.ts +68 -0
- package/frontendBuild/ssrBaseArtifactBuilder.ts +24 -34
- package/frontendBuild/ssrDevBundler.test.ts +150 -1
- package/frontendBuild/ssrDevBundler.ts +66 -11
- package/frontendBuild/vendorFileImports.test.ts +254 -0
- package/frontendBuild/vendorFileImports.ts +163 -0
- package/frontendBuild/vendorNarrowing.ts +28 -0
- package/frontendBuild/vendorSpecifiers.ts +2 -0
- package/incrementalBuilder/buildBatch.proc.ts +9 -9
- package/incrementalBuilder/buildBatchProtocol.ts +1 -1
- package/incrementalBuilder/builderBoot.ts +5 -5
- package/incrementalBuilder/builderGraphPayloads.ts +4 -4
- package/incrementalBuilder/builderLanes.ts +2 -2
- package/incrementalBuilder/builderWatch.ts +8 -8
- package/incrementalBuilder/csrRegistry.ts +4 -4
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +79 -0
- package/incrementalBuilder/incrementalBuilder.proc.ts +27 -8
- package/incrementalBuilder/ssrRegistry.ts +6 -6
- package/index.ts +1 -1
- package/integration/renderAdmissionSoak.test.ts +99 -0
- package/integration/renderAdmissionSoak.ts +609 -0
- package/lint/__fixtures__/no-arbitrary-color/every-color-function/bad.tsx +11 -0
- package/lint/__fixtures__/no-arbitrary-color/every-color-function/good.tsx +2 -0
- package/lint/__fixtures__/no-daisyui-legacy-class/every-class/bad.tsx +34 -0
- package/lint/__fixtures__/no-daisyui-legacy-class/every-class/good.tsx +2 -0
- package/lint/__fixtures__/no-inline-color/every-color-function/bad.tsx +10 -0
- package/lint/__fixtures__/no-inline-color/every-color-function/good.tsx +2 -0
- package/lint/__fixtures__/no-raw-palette-class/every-palette/bad.tsx +22 -0
- package/lint/__fixtures__/no-raw-palette-class/every-palette/good.tsx +2 -0
- package/lint/biomeCheck.test.ts +145 -0
- package/lint/biomeCheck.ts +131 -0
- package/lint/no-arbitrary-color.grit +5 -0
- package/lint/no-conditional-st-hook.grit +5 -1
- package/lint/no-daisyui-legacy-class.grit +8 -0
- package/lint/no-document-cookie.grit +3 -0
- package/lint/no-inline-color.grit +10 -2
- package/lint/no-oversized-list-limit.grit +2 -0
- package/lint/no-raw-palette-class.grit +7 -0
- package/lint/no-unpublished-form-setter.grit +2 -0
- package/lint/no-web-only-api-outside-webkit.grit +5 -0
- package/lint/no-web-storage.grit +3 -0
- package/lint/withheldEnvFile.ts +17 -0
- package/mobile/desktopBin.ts +2 -2
- package/mobile/desktopServerStage.ts +1 -0
- package/mobile/nativeApp.test.ts +7 -5
- package/mobile/nativeApp.ts +2 -2
- package/mobile/nativeConfig.test.ts +96 -1
- package/mobile/nativeConfig.ts +46 -12
- package/mobile/serverBundleSecrets.ts +43 -0
- package/package.json +15 -169
- package/packageExports.test.ts +38 -24
- package/quality/dictionaryKeys.test.ts +173 -0
- package/quality/dictionaryKeys.ts +415 -0
- package/quality/objectImportReport.test.ts +36 -0
- package/quality/objectImportReport.ts +102 -0
- package/quality/qualityScanner.ts +1 -1
- package/quality/routeRuntimeReport.test.ts +91 -0
- package/quality/routeRuntimeReport.ts +121 -0
- package/quality/runtimeConstantFacts.ts +71 -0
- package/quality/runtimeConstantGraph.ts +123 -0
- package/quality/runtimeConstantReads.ts +116 -0
- package/quality/runtimeImports.test.ts +190 -0
- package/quality/runtimeImports.ts +233 -0
- package/quality/runtimeKeyNames.ts +46 -0
- package/quality/runtimeLexicalScope.ts +132 -0
- package/quality/runtimeMarkerReach.test.ts +84 -0
- package/quality/runtimeMarkerReach.ts +255 -0
- package/quality/runtimeModuleFacts.ts +290 -0
- package/quality/runtimeNameTable.test.ts +172 -0
- package/quality/runtimeNameTable.ts +477 -0
- package/quality/runtimeScopeReport.test.ts +123 -0
- package/quality/runtimeScopeReport.ts +167 -0
- package/quality/runtimeSliceKey.ts +269 -0
- package/quality/runtimeSyntax.ts +133 -0
- package/quality/runtimeTable.fixture.ts +189 -0
- package/quality/runtimeUse.test.ts +737 -0
- package/quality/runtimeUse.ts +696 -0
- package/quality/runtimeUseReadable.test.ts +393 -0
- package/quality/ssrScanner.test.ts +13 -0
- package/quality/ssrScanner.ts +1 -1
- package/test/secretEnvFixture.ts +134 -0
- package/test/testHelpers.ts +11 -0
- package/transforms/barrelAnalyzer.ts +26 -4
- package/transforms/barrelImportsPlugin.ts +82 -14
- package/transforms/frameworkObjects.fixture.tsx +58 -0
- package/transforms/frameworkObjects.test.ts +54 -0
- package/transforms/modelReference.test.ts +196 -0
- package/transforms/modelReference.ts +39 -0
- package/transforms/objectImportEdits.ts +150 -0
- package/transforms/objectMemberImports.test.ts +347 -0
- package/transforms/objectMemberImports.ts +537 -0
- package/transforms/objectModule.test.ts +237 -0
- package/transforms/objectModule.ts +458 -0
- package/transforms/objectModuleAnalyzer.ts +104 -0
- package/transforms/reactIconImports.test.ts +231 -0
- package/transforms/reactIconImports.ts +325 -0
- package/transforms/routeConstants.ts +122 -0
- package/transforms/routeRuntime.test.ts +835 -0
- package/transforms/routeRuntime.ts +703 -0
- package/transforms/routeRuntimeEdits.ts +92 -0
- package/transforms/routeRuntimeGraph.ts +66 -0
- package/transforms/routeRuntimePlan.ts +244 -0
- package/transforms/secretEnvDeclaration.test.ts +208 -0
- package/transforms/secretEnvDeclaration.ts +213 -0
- package/transforms/secretEnvFile.test.ts +117 -0
- package/transforms/secretEnvFile.ts +113 -0
- package/transforms/secretEnvName.test.ts +54 -0
- package/transforms/secretEnvName.ts +29 -0
- package/transforms/secretEnvSource.test.ts +148 -0
- package/transforms/secretEnvSource.ts +166 -0
- package/transforms/serverEnvEvaluationError.ts +11 -0
- package/transforms/serverEnvPlugin.test.ts +2 -1
- package/transforms/serverEnvPlugin.ts +13 -0
- package/transforms/serverEnvProfile.test.ts +115 -2
- package/transforms/serverEnvProfile.ts +117 -40
- package/transforms/serverEnvSecrets.test.ts +292 -0
- package/transforms/signalDescriptors.test.ts +280 -0
- package/transforms/signalDescriptors.ts +227 -0
- package/transforms/thisFreeExports.ts +87 -0
- package/transforms/transforms.test.ts +180 -3
- package/transforms/tsconfigPackageResolver.test.ts +1 -0
- package/tunnel/createTunnel.test.ts +29 -8
- package/tunnel/createTunnel.ts +18 -11
- package/typecheck/projectTypecheck.test.ts +29 -0
- package/typecheck/typeChecker.test.ts +49 -0
- package/typecheck/typeChecker.ts +9 -7
- package/typecheck/withheldDiagnostics.ts +41 -0
- package/util/fileEditor.ts +1 -0
- package/util/selectModel.ts +1 -0
- package/workflow/executor.ts +6 -2
- package/workflow/index.ts +1 -0
- package/workflow/plan.ts +36 -7
- package/workflow/types.ts +1 -1
- package/workflow/uiTarget.ts +50 -0
- package/workspace/getRelatedCnsts.ts +7 -0
- package/workspace/scanInfo.ts +1 -1
- package/workspace/workspaceLayout.ts +1 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, realpathSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { Logger, toError } from "akanjs/common";
|
|
4
|
+
import { ServerEnvEvaluationError } from "./serverEnvEvaluationError";
|
|
4
5
|
|
|
5
6
|
export interface ServerEnvProfileProps {
|
|
6
7
|
envDir: string;
|
|
@@ -20,6 +21,21 @@ export interface LibEnvSource extends ServerEnvSource {
|
|
|
20
21
|
|
|
21
22
|
type EnvLoad = (envFile: string) => Promise<ServerEnvSource>;
|
|
22
23
|
|
|
24
|
+
export interface EnvEvaluation {
|
|
25
|
+
environment?: string;
|
|
26
|
+
loads?: RegExp;
|
|
27
|
+
timeoutMs?: number;
|
|
28
|
+
//* What the child's process env holds beside PATH, HOME and the environment's selector.
|
|
29
|
+
variables?: { readonly [name: string]: string };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface EnvEvaluated {
|
|
33
|
+
value: unknown;
|
|
34
|
+
lossy: string[];
|
|
35
|
+
//* The names the env file and its imports asked the process env for, set or not.
|
|
36
|
+
reads: string[];
|
|
37
|
+
}
|
|
38
|
+
|
|
23
39
|
interface Stripped {
|
|
24
40
|
value: unknown;
|
|
25
41
|
stripped: string[];
|
|
@@ -31,13 +47,15 @@ interface EnvFold<T> {
|
|
|
31
47
|
node(value: object, children: (readonly [string, T])[]): T;
|
|
32
48
|
}
|
|
33
49
|
|
|
34
|
-
type EvaluatedMessage = { load: string } | { env: string; lossy: string[] } | { failure: string };
|
|
50
|
+
type EvaluatedMessage = { load: string } | { env: string; lossy: string[]; reads: string[] } | { failure: string };
|
|
35
51
|
|
|
36
52
|
//* A server env profile is bundled in place of the environment's own file, for a server that runs where its bundle
|
|
37
53
|
//* can be read: the computers a desktop app is installed on. So it may hold no secret.
|
|
38
54
|
export class ServerEnvProfile {
|
|
39
55
|
static readonly namePattern = /^[a-z][a-zA-Z0-9-]*$/;
|
|
40
56
|
static readonly envFilePattern = /[\\/]env[\\/]env\.server\.[A-Za-z0-9-]+\.ts$/;
|
|
57
|
+
static readonly envModulePattern = /[\\/]env[\\/]env\.server(?:\.[A-Za-z0-9-]+)?\.ts$/;
|
|
58
|
+
static readonly evaluationTimeoutMs = 60_000;
|
|
41
59
|
|
|
42
60
|
static fileName(environment: string, profile: string) {
|
|
43
61
|
return `env.server.${environment}.${profile}.ts`;
|
|
@@ -65,7 +83,7 @@ export class ServerEnvProfile {
|
|
|
65
83
|
return !!url && ServerEnvProfile.#carriesCredential(url);
|
|
66
84
|
}
|
|
67
85
|
|
|
68
|
-
static
|
|
86
|
+
static isSecret(value: string, underSecret: boolean) {
|
|
69
87
|
return (underSecret && !!value.trim()) || ServerEnvProfile.#isCredentialUrl(value);
|
|
70
88
|
}
|
|
71
89
|
|
|
@@ -92,7 +110,7 @@ export class ServerEnvProfile {
|
|
|
92
110
|
static strip(value: unknown): Stripped {
|
|
93
111
|
return ServerEnvProfile.#fold<Stripped>(value, {
|
|
94
112
|
text: (text, at, underSecret) =>
|
|
95
|
-
ServerEnvProfile
|
|
113
|
+
ServerEnvProfile.isSecret(text, underSecret)
|
|
96
114
|
? { value: undefined, stripped: [at] }
|
|
97
115
|
: { value: text, stripped: [] },
|
|
98
116
|
other: (other) => ({ value: other, stripped: [] }),
|
|
@@ -152,26 +170,60 @@ export class ServerEnvProfile {
|
|
|
152
170
|
return value.length >= 16 && !/^https?:\/\//.test(value) && !/^[a-z]+(?:[._-][a-z]+)*$/.test(value);
|
|
153
171
|
}
|
|
154
172
|
|
|
155
|
-
static secretPaths(value: unknown): string[] {
|
|
173
|
+
static secretPaths(value: unknown, underSecret = false): string[] {
|
|
156
174
|
return ServerEnvProfile.#fold(
|
|
157
175
|
value,
|
|
158
|
-
ServerEnvProfile.#collect((text, at,
|
|
176
|
+
ServerEnvProfile.#collect((text, at, held) => (ServerEnvProfile.isSecret(text, held) ? [at] : [])),
|
|
177
|
+
"",
|
|
178
|
+
underSecret,
|
|
159
179
|
);
|
|
160
180
|
}
|
|
161
181
|
|
|
182
|
+
//? A URL's password is looked for on its own too: code that holds it holds it without the URL around it.
|
|
183
|
+
static movedTexts(value: unknown, underSecret: boolean): string[] {
|
|
184
|
+
const texts = ServerEnvProfile.#fold(
|
|
185
|
+
value,
|
|
186
|
+
ServerEnvProfile.#collect((text, _at, held) =>
|
|
187
|
+
ServerEnvProfile.isSecret(text, held) ? [text, ServerEnvProfile.#url(text)?.password ?? ""] : [],
|
|
188
|
+
),
|
|
189
|
+
"",
|
|
190
|
+
underSecret,
|
|
191
|
+
);
|
|
192
|
+
return [...new Set(texts)].filter((text) => text !== "");
|
|
193
|
+
}
|
|
194
|
+
|
|
162
195
|
//* Evaluated in a child with no app env, so `process.env.X ?? "fallback"` reads as the fallback the bundle carries.
|
|
163
196
|
//* The result comes back over IPC, as an import may write to stdout; `load` answers for each env file it reaches.
|
|
164
|
-
static async evaluate(file: string, cwd: string, load?: EnvLoad): Promise<unknown> {
|
|
165
|
-
return (await ServerEnvProfile.#evaluated(file, cwd, load)).value;
|
|
197
|
+
static async evaluate(file: string, cwd: string, load?: EnvLoad, evaluation?: EnvEvaluation): Promise<unknown> {
|
|
198
|
+
return (await ServerEnvProfile.#evaluated(file, cwd, load, evaluation)).value;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
static async evaluateReads(file: string, cwd: string, load: EnvLoad, evaluation: EnvEvaluation) {
|
|
202
|
+
return await ServerEnvProfile.#evaluated(file, cwd, load, evaluation, true);
|
|
166
203
|
}
|
|
167
204
|
|
|
168
|
-
//? Bun prints a failing module's source line with its error, so stderr is never read
|
|
169
|
-
//?
|
|
170
|
-
static async #evaluated(
|
|
171
|
-
|
|
172
|
-
|
|
205
|
+
//? Bun prints a failing module's source line with its error, so stderr is never read. The child sends the error's
|
|
206
|
+
//? class and place and never its message, which can quote a value of any file the env file imports.
|
|
207
|
+
static async #evaluated(
|
|
208
|
+
file: string,
|
|
209
|
+
cwd: string,
|
|
210
|
+
load?: EnvLoad,
|
|
211
|
+
{
|
|
212
|
+
environment,
|
|
213
|
+
loads = ServerEnvProfile.envFilePattern,
|
|
214
|
+
timeoutMs = ServerEnvProfile.evaluationTimeoutMs,
|
|
215
|
+
variables,
|
|
216
|
+
}: EnvEvaluation = {},
|
|
217
|
+
notesReads = false,
|
|
218
|
+
): Promise<EnvEvaluated> {
|
|
173
219
|
const frame = /^\s*at (?:[^(]*\()?(.+):(\d+):(\d+)\)?\s*$/;
|
|
174
220
|
const script = [
|
|
221
|
+
//? An import may leave a timer, a server or a socket open, which would keep this process alive past its answer
|
|
222
|
+
//? and past a parent that died: it exits when its answer is sent, when the parent's channel closes, and at a
|
|
223
|
+
//? deadline of its own.
|
|
224
|
+
'process.on("disconnect", () => process.exit(1));',
|
|
225
|
+
"setTimeout(() => process.exit(1), Number(process.env.AKAN_PROFILE_ENV_DEADLINE)).unref();",
|
|
226
|
+
"const finish = (message, code) => process.send(message, undefined, undefined, () => process.exit(code));",
|
|
175
227
|
"const waiting = new Map();",
|
|
176
228
|
'process.on("message", ({ load, error, loader, contents }) => {',
|
|
177
229
|
" const reply = waiting.get(load);",
|
|
@@ -190,23 +242,30 @@ export class ServerEnvProfile {
|
|
|
190
242
|
" }));",
|
|
191
243
|
" },",
|
|
192
244
|
" });",
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
`
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
"
|
|
245
|
+
"const reads = new Set();",
|
|
246
|
+
'const note = (key) => typeof key === "string" && reads.add(key);',
|
|
247
|
+
"const noting = { get: (target, key, receiver) => (note(key), Reflect.get(target, key, receiver)), has: (target, key) => (note(key), Reflect.has(target, key)) };",
|
|
248
|
+
//? `Bun.env` and `import.meta.env` stay the object `process.env` was, which a proxy put in its place does not
|
|
249
|
+
//? see: a name that object lacks is noted through its prototype, and a name it holds through the proxy alone.
|
|
250
|
+
"if (process.env.AKAN_PROFILE_ENV_READS) {",
|
|
251
|
+
" Object.setPrototypeOf(process.env, new Proxy(Object.prototype, noting));",
|
|
252
|
+
" process.env = new Proxy(process.env, noting);",
|
|
253
|
+
"}",
|
|
254
|
+
`const frameOf = new RegExp(${JSON.stringify(frame.source)});`,
|
|
255
|
+
'const { existsSync } = require("node:fs");',
|
|
256
|
+
//? The stack opens with the message, whose own lines could read as a frame: only lines after it are looked at,
|
|
257
|
+
//? and only one that names a file on disk.
|
|
258
|
+
"const describe = (error) => {",
|
|
200
259
|
" const first = Array.isArray(error?.errors) && error.errors.length ? error.errors[0] : error;",
|
|
201
|
-
' const
|
|
202
|
-
|
|
203
|
-
" const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
'
|
|
208
|
-
' const name =
|
|
209
|
-
' return name +
|
|
260
|
+
' const stack = String(first?.stack ?? "");',
|
|
261
|
+
' const message = String(first?.message ?? "");',
|
|
262
|
+
" const frames = message && stack.includes(message) ? stack.slice(stack.indexOf(message) + message.length) : stack;",
|
|
263
|
+
' const frame = frames.split("\\n").map((line) => frameOf.exec(line)).find((found) => found && existsSync(found[1]));',
|
|
264
|
+
" const at = first?.position?.file ? [first.position.file, first.position.line] : frame ? frame.slice(1, 3) : [];",
|
|
265
|
+
//? `error.name` is a property any code can set to a value, so the class is read from the constructor.
|
|
266
|
+
' const named = first === null || first === undefined ? "" : String(Object.getPrototypeOf(first)?.constructor?.name ?? "");',
|
|
267
|
+
' const name = first instanceof Error && /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(named) ? named : "Error";',
|
|
268
|
+
' return name + (at.length ? " at " + at.join(":") : ", which gave no location");',
|
|
210
269
|
"};",
|
|
211
270
|
"try {",
|
|
212
271
|
" const { env } = await import(process.env.AKAN_PROFILE_ENV_FILE);",
|
|
@@ -220,13 +279,12 @@ export class ServerEnvProfile {
|
|
|
220
279
|
" };",
|
|
221
280
|
' walk(env, "");',
|
|
222
281
|
' const plain = (_, value) => (typeof value === "function" || typeof value === "symbol" ? undefined : typeof value === "bigint" ? String(value) : value);',
|
|
223
|
-
'
|
|
282
|
+
' finish({ env: JSON.stringify(env ?? null, plain) ?? "null", lossy, reads: [...reads] }, 0);',
|
|
224
283
|
"} catch (error) {",
|
|
225
|
-
"
|
|
226
|
-
" process.send({ failure: await describe(error) }, undefined, undefined, () => process.disconnect());",
|
|
284
|
+
" finish({ failure: describe(error) }, 1);",
|
|
227
285
|
"}",
|
|
228
286
|
].join("\n");
|
|
229
|
-
let sent: { env: string; lossy: string[] } | undefined;
|
|
287
|
+
let sent: { env: string; lossy: string[]; reads: string[] } | undefined;
|
|
230
288
|
let failure: string | undefined;
|
|
231
289
|
let loadError: unknown;
|
|
232
290
|
const child = Bun.spawn([process.execPath, "--eval", script], {
|
|
@@ -234,8 +292,12 @@ export class ServerEnvProfile {
|
|
|
234
292
|
env: {
|
|
235
293
|
PATH: process.env.PATH ?? "",
|
|
236
294
|
HOME: process.env.HOME ?? "",
|
|
295
|
+
...variables,
|
|
237
296
|
AKAN_PROFILE_ENV_FILE: file,
|
|
238
|
-
|
|
297
|
+
AKAN_PROFILE_ENV_DEADLINE: String(timeoutMs + 5_000),
|
|
298
|
+
...(load ? { AKAN_PROFILE_ENV_LOAD: loads.source } : {}),
|
|
299
|
+
...(notesReads ? { AKAN_PROFILE_ENV_READS: "1" } : {}),
|
|
300
|
+
...(environment ? { AKAN_PUBLIC_ENV: environment } : {}),
|
|
239
301
|
},
|
|
240
302
|
stdout: "ignore",
|
|
241
303
|
stderr: "ignore",
|
|
@@ -264,14 +326,29 @@ export class ServerEnvProfile {
|
|
|
264
326
|
.catch(() => undefined);
|
|
265
327
|
},
|
|
266
328
|
});
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
329
|
+
let timedOut = false;
|
|
330
|
+
const kill = () => child.kill("SIGKILL");
|
|
331
|
+
const timer = setTimeout(() => {
|
|
332
|
+
timedOut = true;
|
|
333
|
+
kill();
|
|
334
|
+
}, timeoutMs);
|
|
335
|
+
process.on("exit", kill);
|
|
336
|
+
const exitCode = await child.exited.finally(() => {
|
|
337
|
+
clearTimeout(timer);
|
|
338
|
+
process.off("exit", kill);
|
|
339
|
+
});
|
|
340
|
+
if (sent && !timedOut && exitCode === 0)
|
|
341
|
+
return { value: JSON.parse(sent.env) as unknown, lossy: sent.lossy, reads: sent.reads };
|
|
342
|
+
if (loadError) throw loadError;
|
|
343
|
+
if (timedOut)
|
|
344
|
+
throw new ServerEnvEvaluationError(
|
|
345
|
+
"timedOut",
|
|
346
|
+
`${file} was not evaluated within ${timeoutMs / 1000}s, so its process was stopped: the file, or one it imports, waits on something as it loads that does not end (a server it starts, a connection it opens, a loop).`,
|
|
272
347
|
);
|
|
273
|
-
|
|
274
|
-
|
|
348
|
+
throw new ServerEnvEvaluationError(
|
|
349
|
+
failure ? "threw" : "exited",
|
|
350
|
+
`${path.basename(file)} could not be evaluated to check it for secrets: ${failure ?? `its process exited with code ${exitCode} and sent nothing`}`,
|
|
351
|
+
);
|
|
275
352
|
}
|
|
276
353
|
|
|
277
354
|
//? A profile is served under the path of the file it replaces, so its import of that file would import itself.
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { SecretEnv } from "akanjs/server/lifecycle/secretEnv";
|
|
4
|
+
import { ServerBundleSecrets } from "../mobile/serverBundleSecrets";
|
|
5
|
+
import {
|
|
6
|
+
computedSecretKeys,
|
|
7
|
+
computedSecrets,
|
|
8
|
+
holdsSentinel,
|
|
9
|
+
secretEnvFixtureNames,
|
|
10
|
+
secretEnvPlain,
|
|
11
|
+
secretEnvSentinels,
|
|
12
|
+
twinSecretEnv,
|
|
13
|
+
twinSecrets,
|
|
14
|
+
writeComputedSecretFixture,
|
|
15
|
+
writeSecretEnvFixture,
|
|
16
|
+
} from "../test/secretEnvFixture";
|
|
17
|
+
import { tempDirs, writeText } from "../test/testHelpers";
|
|
18
|
+
import { SecretEnvDeclaration } from "./secretEnvDeclaration";
|
|
19
|
+
import { createServerEnvPlugin } from "./serverEnvPlugin";
|
|
20
|
+
import { ServerEnvProfile } from "./serverEnvProfile";
|
|
21
|
+
|
|
22
|
+
const makeTempRoot = tempDirs("akan-devkit-server-env-secrets-");
|
|
23
|
+
const environments = ["local", "main"];
|
|
24
|
+
const secretEnvModule = Bun.resolveSync("akanjs/server/lifecycle/secretEnv", import.meta.dir);
|
|
25
|
+
|
|
26
|
+
interface Built {
|
|
27
|
+
root: string;
|
|
28
|
+
appDir: string;
|
|
29
|
+
envDir: string;
|
|
30
|
+
outDir: string;
|
|
31
|
+
file: string;
|
|
32
|
+
text: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const build = async (
|
|
36
|
+
root: string,
|
|
37
|
+
secrets?: "read" | "inline",
|
|
38
|
+
{ mainExtra = "", overSwitch = false } = {},
|
|
39
|
+
): Promise<Built> => {
|
|
40
|
+
const { appDir, envDir } = await writeSecretEnvFixture(root, { mainExtra });
|
|
41
|
+
if (overSwitch)
|
|
42
|
+
await writeText(path.join(envDir, "env.server.ts"), await Bun.file(path.join(envDir, "env.server.main.ts")).text());
|
|
43
|
+
const entry = path.join(appDir, "server.ts");
|
|
44
|
+
await writeText(
|
|
45
|
+
entry,
|
|
46
|
+
[
|
|
47
|
+
`import { SecretEnv } from ${JSON.stringify(secretEnvModule)};`,
|
|
48
|
+
'import { env } from "./env/env.server";',
|
|
49
|
+
"SecretEnv.check({ warn: (message) => console.error(message) });",
|
|
50
|
+
"console.info(JSON.stringify(env));",
|
|
51
|
+
"",
|
|
52
|
+
].join("\n"),
|
|
53
|
+
);
|
|
54
|
+
const outDir = path.join(root, "dist/apps/demo");
|
|
55
|
+
const result = await Bun.build({
|
|
56
|
+
entrypoints: [entry],
|
|
57
|
+
outdir: outDir,
|
|
58
|
+
target: "bun",
|
|
59
|
+
plugins: [createServerEnvPlugin({ envDir, environment: "main", environments, secrets })],
|
|
60
|
+
});
|
|
61
|
+
const output = result.outputs.find((artifact) => artifact.kind === "entry-point");
|
|
62
|
+
if (!output) throw new Error("no entry output");
|
|
63
|
+
return { root, appDir, envDir, outDir, file: output.path, text: await output.text() };
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const declare = async ({ envDir }: Built) => {
|
|
67
|
+
const { variables } = await SecretEnvDeclaration.of(envDir, "main");
|
|
68
|
+
return {
|
|
69
|
+
list: SecretEnv.format(variables),
|
|
70
|
+
values: Object.fromEntries(variables.map((each) => [each.name, each.value])),
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const boot = (file: string, env: { [name: string]: string }) => {
|
|
75
|
+
const proc = Bun.spawnSync([process.execPath, file], {
|
|
76
|
+
env: { PATH: process.env.PATH ?? "", AKAN_PUBLIC_ENV: "main", ...env },
|
|
77
|
+
});
|
|
78
|
+
const stdout = proc.stdout.toString();
|
|
79
|
+
return {
|
|
80
|
+
exitCode: proc.exitCode,
|
|
81
|
+
env: stdout ? (JSON.parse(stdout) as { [key: string]: unknown }) : null,
|
|
82
|
+
warnings: proc.stderr.toString().split("\n").filter(Boolean),
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const evaluated = ({ envDir, appDir }: Built) =>
|
|
87
|
+
ServerEnvProfile.evaluate(path.join(envDir, "env.server.ts"), appDir, undefined, { environment: "main" });
|
|
88
|
+
|
|
89
|
+
describe("createServerEnvPlugin for an image", () => {
|
|
90
|
+
test("the built server holds no secret of the workspace's env files, a lib's defaults included, and every plain value", async () => {
|
|
91
|
+
const built = await build(await makeTempRoot(), "read");
|
|
92
|
+
expect(holdsSentinel(built.text)).toBe(false);
|
|
93
|
+
for (const plain of Object.values(secretEnvPlain)) expect(built.text).toContain(plain);
|
|
94
|
+
expect(built.text).toContain("noreply@example.test");
|
|
95
|
+
expect(await new ServerBundleSecrets(built.root, built.appDir).assertClean(built.outDir)).toEqual([]);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("started with the variables its env file maps to, it runs on the env that file evaluates to, and warns of nothing", async () => {
|
|
99
|
+
const built = await build(await makeTempRoot(), "read");
|
|
100
|
+
const { list, values } = await declare(built);
|
|
101
|
+
const booted = boot(built.file, { AKAN_ENV_NAMES: list, ...values });
|
|
102
|
+
expect(booted.exitCode).toBe(0);
|
|
103
|
+
expect(booted.warnings).toEqual([]);
|
|
104
|
+
expect(booted.env).toEqual((await evaluated(built)) as { [key: string]: unknown });
|
|
105
|
+
expect(booted.env).toMatchObject({
|
|
106
|
+
security: { jwtSecret: secretEnvSentinels.jwt },
|
|
107
|
+
mailer: { auth: { pass: secretEnvSentinels.libPass } },
|
|
108
|
+
discord: { tokens: secretEnvSentinels.bots },
|
|
109
|
+
pushNoti: { firebase: { private_key: secretEnvSentinels.pem } },
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("the developer's own variable still outranks the one the build reads", async () => {
|
|
114
|
+
const built = await build(await makeTempRoot(), "read");
|
|
115
|
+
const { list, values } = await declare(built);
|
|
116
|
+
const booted = boot(built.file, {
|
|
117
|
+
AKAN_ENV_NAMES: list,
|
|
118
|
+
...values,
|
|
119
|
+
DATABASE_URL: "postgres://own.example.test/app",
|
|
120
|
+
});
|
|
121
|
+
expect(booted.env).toMatchObject({ database: { postgres: { url: "postgres://own.example.test/app" } } });
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("started without its variables, it names each one in a single warning and runs without them", async () => {
|
|
125
|
+
const built = await build(await makeTempRoot(), "read");
|
|
126
|
+
const { list, values } = await declare(built);
|
|
127
|
+
const { MAILER__AUTH__PASS: _pass, DISCORD__TOKENS: _tokens, ...set } = values;
|
|
128
|
+
const booted = boot(built.file, { AKAN_ENV_NAMES: list, ...set });
|
|
129
|
+
expect(booted.exitCode).toBe(0);
|
|
130
|
+
expect(booted.warnings).toEqual([
|
|
131
|
+
"2 secret env values this server declares are not set: MAILER__AUTH__PASS, DISCORD__TOKENS. The framework does not stop for them yet, though whatever reads them may, and akanjs 3.5.0 will refuse to boot. Set them in the deployment's environment; `akan secret-env <app> --env main` lists every name.",
|
|
132
|
+
]);
|
|
133
|
+
expect(booted.env).toMatchObject({ mailer: { address: "noreply@example.test", auth: { user: "mailer" } } });
|
|
134
|
+
expect((booted.env?.mailer as { auth: object } | undefined)?.auth).not.toHaveProperty("pass");
|
|
135
|
+
expect(booted.env?.discord).not.toHaveProperty("tokens");
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("after a key is renamed in the env file, a deployment still setting the old variable is told the new name", async () => {
|
|
139
|
+
const before = await build(await makeTempRoot(), "read", {
|
|
140
|
+
mainExtra: '\n llm: { apiKey: "sentinel-llm-1c95" },',
|
|
141
|
+
});
|
|
142
|
+
const old = await declare(before);
|
|
143
|
+
expect(old.values.LLM__API_KEY).toBe("sentinel-llm-1c95");
|
|
144
|
+
const renamed = await build(await makeTempRoot(), "read", {
|
|
145
|
+
mainExtra: '\n llm: { accessKey: "sentinel-llm-1c95" },',
|
|
146
|
+
});
|
|
147
|
+
const { list } = await declare(renamed);
|
|
148
|
+
const booted = boot(renamed.file, { AKAN_ENV_NAMES: list, ...old.values });
|
|
149
|
+
expect(booted.warnings).toEqual([
|
|
150
|
+
"1 secret env value this server declares is not set: LLM__ACCESS_KEY. The framework does not stop for it yet, though whatever reads it may, and akanjs 3.5.0 will refuse to boot. Set it in the deployment's environment; `akan secret-env <app> --env main` lists every name.",
|
|
151
|
+
]);
|
|
152
|
+
expect(booted.env?.llm).toEqual({});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test("an --inline-secrets build keeps the values as what an unset variable falls back to, and a set one wins", async () => {
|
|
156
|
+
const built = await build(await makeTempRoot(), "inline");
|
|
157
|
+
expect(built.text).toContain(secretEnvSentinels.jwt);
|
|
158
|
+
const { list } = await declare(built);
|
|
159
|
+
const fallback = boot(built.file, { AKAN_ENV_NAMES: list, AKAN_ENV_FALLBACK: "image" });
|
|
160
|
+
expect(fallback.env).toEqual((await evaluated(built)) as { [key: string]: unknown });
|
|
161
|
+
expect(fallback.warnings).toHaveLength(1);
|
|
162
|
+
expect(fallback.warnings[0]).toStartWith(
|
|
163
|
+
"10 secret env values this server declares are not set, so it uses the values built into this image (akan build --inline-secrets): JWT_SECRET, ",
|
|
164
|
+
);
|
|
165
|
+
const overridden = boot(built.file, {
|
|
166
|
+
AKAN_ENV_NAMES: list,
|
|
167
|
+
AKAN_ENV_FALLBACK: "image",
|
|
168
|
+
JWT_SECRET: "set-by-the-deployment",
|
|
169
|
+
DISCORD__TOKENS: '["set-by-the-deployment"]',
|
|
170
|
+
});
|
|
171
|
+
expect(overridden.env).toMatchObject({
|
|
172
|
+
security: { jwtSecret: "set-by-the-deployment", sso: { google: { clientSecret: secretEnvSentinels.google } } },
|
|
173
|
+
discord: { tokens: ["set-by-the-deployment"], webhook: secretEnvSentinels.webhook },
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("the env file a pipeline copies over the switch is read the same way", async () => {
|
|
178
|
+
const built = await build(await makeTempRoot(), "read", { overSwitch: true });
|
|
179
|
+
expect(holdsSentinel(built.text)).toBe(false);
|
|
180
|
+
const { list, values } = await declare(built);
|
|
181
|
+
expect(Object.keys(values)).toEqual(secretEnvFixtureNames);
|
|
182
|
+
const booted = boot(built.file, { AKAN_ENV_NAMES: list, ...values });
|
|
183
|
+
expect(booted.warnings).toEqual([]);
|
|
184
|
+
expect(booted.env).toEqual((await evaluated(built)) as { [key: string]: unknown });
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test("a secret the env file imports or computes stays in the built server, and the declaration names its key whatever the value's length", async () => {
|
|
188
|
+
const root = await makeTempRoot();
|
|
189
|
+
const { appDir, envDir } = await writeComputedSecretFixture(root);
|
|
190
|
+
const entry = path.join(appDir, "server.ts");
|
|
191
|
+
await writeText(entry, 'import { env } from "./env/env.server";\nconsole.info(JSON.stringify(env));\n');
|
|
192
|
+
const result = await Bun.build({
|
|
193
|
+
entrypoints: [entry],
|
|
194
|
+
outdir: path.join(root, "dist/apps/demo"),
|
|
195
|
+
target: "bun",
|
|
196
|
+
plugins: [createServerEnvPlugin({ envDir, environment: "main", environments, secrets: "read" })],
|
|
197
|
+
});
|
|
198
|
+
const text = (await result.outputs.find((artifact) => artifact.kind === "entry-point")?.text()) ?? "";
|
|
199
|
+
expect(text).toContain(computedSecrets.password);
|
|
200
|
+
expect(text).toContain(computedSecrets.passphrase);
|
|
201
|
+
expect(text).toContain(computedSecrets.user);
|
|
202
|
+
expect(text).not.toContain(secretEnvSentinels.jwt);
|
|
203
|
+
const declared = await SecretEnvDeclaration.of(envDir, "main");
|
|
204
|
+
expect(declared.unmoved).toEqual(computedSecretKeys);
|
|
205
|
+
expect(declared.variables.map(({ name }) => name)).toEqual(secretEnvFixtureNames);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test("a secret string a plain key holds as well stays in the built server: a long mixed one stops the image check by both keys, a short one is a warning, and neither names the value", async () => {
|
|
209
|
+
const built = await build(await makeTempRoot(), "read", { mainExtra: twinSecretEnv });
|
|
210
|
+
for (const value of Object.values(twinSecrets)) expect(built.text).toContain(value);
|
|
211
|
+
const { moved } = await SecretEnvDeclaration.of(built.envDir, "main");
|
|
212
|
+
expect(moved.filter(({ twins }) => twins.length).map(({ path: at, name, twins }) => ({ at, name, twins }))).toEqual(
|
|
213
|
+
[
|
|
214
|
+
{ at: "audit.password", name: "AUDIT__PASSWORD", twins: ["audit.label"] },
|
|
215
|
+
{ at: "cache.password", name: "CACHE__PASSWORD", twins: ["cache.name"] },
|
|
216
|
+
{ at: "door.secret", name: "DOOR__SECRET", twins: ["door.hint"] },
|
|
217
|
+
],
|
|
218
|
+
);
|
|
219
|
+
const secrets = new ServerBundleSecrets(built.root, built.appDir);
|
|
220
|
+
const failure = await secrets.assertImageClean(built.outDir, moved).then(
|
|
221
|
+
() => "",
|
|
222
|
+
(error: Error) => error.message,
|
|
223
|
+
);
|
|
224
|
+
expect(failure).toStartWith(
|
|
225
|
+
"The build holds secret values the server reads from its process env, so it stops here:\n server.js holds the value of audit.password (AUDIT__PASSWORD), which the env's audit.label holds as well\nThe build left each out",
|
|
226
|
+
);
|
|
227
|
+
expect(holdsSentinel(failure)).toBe(false);
|
|
228
|
+
const note = await secrets.assertImageClean(
|
|
229
|
+
built.outDir,
|
|
230
|
+
moved.filter(({ path: at }) => at !== "audit.password"),
|
|
231
|
+
);
|
|
232
|
+
expect(note).toBe(
|
|
233
|
+
[
|
|
234
|
+
"2 secret values the server reads from its process env are also in what this build wrote, short or plain enough to be there for another reason, so the build goes on:",
|
|
235
|
+
" cache.password (CACHE__PASSWORD): server.js; the env's cache.name holds the same string",
|
|
236
|
+
" door.secret (DOOR__SECRET): the env's door.hint holds the same string",
|
|
237
|
+
"Where another key of the env or the app's code holds a secret's own string, the image holds it too: change one of the two.",
|
|
238
|
+
].join("\n"),
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
const clean = await build(await makeTempRoot(), "read");
|
|
242
|
+
const declared = await SecretEnvDeclaration.of(clean.envDir, "main");
|
|
243
|
+
expect(declared.moved.map(({ name }) => name)).toEqual([
|
|
244
|
+
"JWT_SECRET",
|
|
245
|
+
"SECURITY__SSO__GOOGLE__CLIENT_SECRET",
|
|
246
|
+
"MAILER__AUTH__PASS",
|
|
247
|
+
"OBJECT_STORAGE__ENDPOINT",
|
|
248
|
+
"OBJECT_STORAGE__ENDPOINT",
|
|
249
|
+
"DISCORD__TOKENS",
|
|
250
|
+
"DISCORD__TOKENS",
|
|
251
|
+
"DISCORD__WEBHOOK",
|
|
252
|
+
"PUSH_NOTI__FIREBASE__PRIVATE_KEY",
|
|
253
|
+
"MESSAGE__API_SECRET",
|
|
254
|
+
"MESSAGE__SENDER_PASSWORD",
|
|
255
|
+
"POSTGRES_URL",
|
|
256
|
+
"POSTGRES_URL",
|
|
257
|
+
]);
|
|
258
|
+
expect(await new ServerBundleSecrets(clean.root, clean.appDir).assertImageClean(clean.outDir, declared.moved)).toBe(
|
|
259
|
+
null,
|
|
260
|
+
);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test("a secret the env file reads from the process env itself stays that read in the built server, which holds no value the build's shell gave it", async () => {
|
|
264
|
+
const shell = process.env.ZQ_API_KEY;
|
|
265
|
+
process.env.ZQ_API_KEY = "shell-api-key-1d20";
|
|
266
|
+
try {
|
|
267
|
+
const built = await build(await makeTempRoot(), "read", {
|
|
268
|
+
mainExtra: '\n own: { apiKey: process.env.ZQ_API_KEY, hosts: process.env.ZQ_API_KEY!.split("-") },',
|
|
269
|
+
});
|
|
270
|
+
expect(built.text).toContain("apiKey: process.env.ZQ_API_KEY");
|
|
271
|
+
expect(built.text).not.toContain("shell-api-key-1d20");
|
|
272
|
+
const { list, values } = await declare(built);
|
|
273
|
+
expect(list).not.toContain("OWN__");
|
|
274
|
+
const booted = boot(built.file, { AKAN_ENV_NAMES: list, ...values, ZQ_API_KEY: "deployed-api-key" });
|
|
275
|
+
expect(booted.warnings).toEqual([]);
|
|
276
|
+
expect(booted.env?.own).toEqual({ apiKey: "deployed-api-key", hosts: ["deployed", "api", "key"] });
|
|
277
|
+
} finally {
|
|
278
|
+
if (shell === undefined) delete process.env.ZQ_API_KEY;
|
|
279
|
+
else process.env.ZQ_API_KEY = shell;
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
test("without the setting, as for the server a desktop app carries, the env files are bundled as written", async () => {
|
|
284
|
+
const built = await build(await makeTempRoot());
|
|
285
|
+
expect(built.text).toContain(secretEnvSentinels.jwt);
|
|
286
|
+
expect(built.text).toContain(secretEnvSentinels.libPass);
|
|
287
|
+
expect(built.text).not.toContain("SecretEnv.read(");
|
|
288
|
+
const booted = boot(built.file, {});
|
|
289
|
+
expect(booted.warnings).toEqual([]);
|
|
290
|
+
expect(booted.env).toEqual((await evaluated(built)) as { [key: string]: unknown });
|
|
291
|
+
});
|
|
292
|
+
});
|