Fix e2e tests

This commit is contained in:
Reinier Criel 2025-11-19 14:32:44 -08:00
parent c71320386e
commit a7fc215354
4 changed files with 47 additions and 124 deletions

View file

@ -1,7 +1,6 @@
#!/usr/bin/env node
import chalk from "chalk";
import { createRequire } from "module";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
@ -81,7 +80,7 @@ function writeHelp() {
ui.writeInformation(
`- ${chalk.cyan(
"safe-chain run"
)}: Run the proxy as a standalone service. Sets system-wide proxy environment variables. Options: --verbose`
)}: Run the proxy as a standalone service. (Used by the background agent). Options: --verbose`
);
ui.writeInformation(
`- ${chalk.cyan(
@ -99,7 +98,7 @@ function getVersion() {
const packageJsonPath = join(__dirname, '../package.json');
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
return packageJson.version;
} catch (error) {
} catch {
// Fallback for bundled version
return '1.0.0';
}

View file

@ -2,8 +2,6 @@ import { generateCACertificate } from "../registryProxy/certUtils.js";
import { writeFileSync, mkdirSync } from "node:fs";
import { join } from "node:path";
import { homedir } from "node:os";
import { ui } from "../environment/userInteraction.js";
import chalk from "chalk";
/**
* Generate certificate command
@ -34,7 +32,7 @@ export async function generateCertCommand(args) {
writeFileSync(certPath, cert);
writeFileSync(keyPath, key);
} catch (/** @type {any} */ error) {
} catch {
process.exit(1);
}
}

View file

@ -3,11 +3,34 @@ import path from "path";
import fs from "fs";
import os from "os";
const certFolder = process.env.SAFE_CHAIN_CERT_DIR || path.join(os.homedir(), ".safe-chain", "certs");
const certFolder = determineCertFolder();
const ca = loadCa();
const certCache = new Map();
/**
* Determine the certificate folder location
* Priority:
* 1. SAFE_CHAIN_CERT_DIR environment variable (set by installer/LaunchAgent)
* 2. System-wide installation directory (if certificates exist there)
* 3. User home directory (fallback for CLI wrapper mode and development)
*/
function determineCertFolder() {
// 1. Explicit env var takes precedence (set by LaunchAgent)
if (process.env.SAFE_CHAIN_CERT_DIR) {
return process.env.SAFE_CHAIN_CERT_DIR;
}
// 2. Check if system-wide installation exists (macOS/Linux standard location)
const systemCertDir = "/usr/local/share/safe-chain/certs";
if (fs.existsSync(path.join(systemCertDir, "ca-cert.pem"))) {
return systemCertDir;
}
// 3. Fallback to user home directory (CLI wrapper mode, development)
return path.join(os.homedir(), ".safe-chain", "certs");
}
export function getCaCertPath() {
return path.join(certFolder, "ca-cert.pem");
}