Skip to content

Commit 7750d4a

Browse files
committed
test(e2e): tighten fixture setup env handling and key validation
Inline CLERK_PLATFORM_API_KEY plumbing per CLI invocation instead of a shared helper, validate publishable/secret keys with regex expectations, and force color in the op-wrapped subprocess for readable output.
1 parent a571649 commit 7750d4a

2 files changed

Lines changed: 17 additions & 21 deletions

File tree

scripts/run-e2e-op.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const exitCode = await runWithOpSecrets(["bun", "run", "test:e2e", ...process.ar
1919
"op://AI Enablement/Clerk CLI - E2E Production Secrets/CLERK_PLATFORM_API_KEY",
2020
CLERK_CLI_TEST_APP_ID:
2121
"op://AI Enablement/Clerk CLI - E2E Production Secrets/CLERK_CLI_TEST_APP_ID",
22+
FORCE_COLOR: "1", // ensure color in subprocess output for better readability
2223
});
2324

2425
process.exit(exitCode);

test/e2e/lib/fixture-setup.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { expect } from "bun:test";
12
import { mkdtemp, cp, rm, realpath } from "node:fs/promises";
23
import { join } from "node:path";
34
import { tmpdir } from "node:os";
@@ -25,19 +26,6 @@ function requireEnv(name: string): string {
2526
return val;
2627
}
2728

28-
/** Build a shared env object for CLI commands. Requires CLERK_PLATFORM_API_KEY. */
29-
function clerkEnv(configDir?: string): Record<string, string | undefined> {
30-
if (!process.env.CLERK_PLATFORM_API_KEY) {
31-
throw new Error(
32-
"Missing required env var: set CLERK_PLATFORM_API_KEY before running e2e tests.",
33-
);
34-
}
35-
return {
36-
...process.env,
37-
...(configDir ? { CLERK_CONFIG_DIR: configDir } : {}),
38-
};
39-
}
40-
4129
/** Throw with a descriptive message if a shell command failed. */
4230
function assertSuccess(
4331
label: string,
@@ -62,10 +50,14 @@ async function copyFixture(fixtureDir: string, projectDir: string): Promise<void
6250
*/
6351
async function linkProject(projectDir: string, configDir: string): Promise<void> {
6452
const appId = requireEnv("CLERK_CLI_TEST_APP_ID");
53+
const platformAPIKey = requireEnv("CLERK_PLATFORM_API_KEY");
6554

6655
const result = await Bun.$`bun ${CLI_PATH} --mode human link --app ${appId}`
6756
.cwd(projectDir)
68-
.env(clerkEnv(configDir))
57+
.env({
58+
CLERK_CONFIG_DIR: configDir,
59+
CLERK_PLATFORM_API_KEY: platformAPIKey,
60+
})
6961
.quiet()
7062
.nothrow();
7163

@@ -95,9 +87,14 @@ async function gitInit(projectDir: string): Promise<void> {
9587
* with skill template files that break framework typecheck.
9688
*/
9789
async function runClerkInit(projectDir: string, configDir: string): Promise<void> {
90+
const platformAPIKey = requireEnv("CLERK_PLATFORM_API_KEY");
91+
9892
const result = await Bun.$`bun ${CLI_PATH} --mode human init --yes --no-skills`
9993
.cwd(projectDir)
100-
.env(clerkEnv(configDir))
94+
.env({
95+
CLERK_CONFIG_DIR: configDir,
96+
CLERK_PLATFORM_API_KEY: platformAPIKey,
97+
})
10198
.quiet()
10299
.nothrow();
103100

@@ -168,16 +165,14 @@ export async function setupFixture(name: FixtureName): Promise<Fixture> {
168165

169166
// Verify clerk init wrote env files and extract keys.
170167
const envVars = await parseEnvFiles(projectDir);
168+
171169
const publishableKeyName = await detectPublishableKeyName(projectDir);
172170
publishableKey = envVars[publishableKeyName] ?? "";
173-
if (!publishableKey) {
174-
throw new Error(`${publishableKeyName} not found in env files written by clerk init.`);
175-
}
171+
expect(publishableKey).toMatch(/^pk_(test|live)_[a-z0-9]+$/);
172+
176173
const secretKeyName = await detectSecretKeyName(projectDir);
177174
secretKey = envVars[secretKeyName] ?? "";
178-
if (!secretKey) {
179-
throw new Error(`${secretKeyName} not found in env files written by clerk init.`);
180-
}
175+
expect(secretKey).toMatch(/^sk_(test|live)_[a-z0-9]+$/);
181176

182177
const install = await Bun.$`npm ci --ignore-scripts --legacy-peer-deps`
183178
.cwd(projectDir)

0 commit comments

Comments
 (0)