Avoid Electron initialization in plain Node tests
Managed validation / full (pull_request) Successful in 27s
ChatGPT validation / quality (push) Successful in 4m57s

This commit is contained in:
NuklearRabbit
2026-08-31 20:15:31 +02:00
parent 8cca1bfc01
commit b5d615d53d
2 changed files with 21 additions and 3 deletions
+20 -2
View File
@@ -3,9 +3,21 @@
const fs = require('node:fs/promises');
const path = require('node:path');
const crypto = require('node:crypto');
const { safeStorage } = require('electron');
const { normalizeBaseUrl, assertHttpUrl, assertWorkflowFileName, assertBranchName, assertEnvironmentName, assertCloneRemote, assertRepositoryRelativePath, assertRepositoryRelativePaths } = require('../shared/validation.cjs');
let cachedSafeStorage;
function getSafeStorage() {
if (cachedSafeStorage !== undefined) return cachedSafeStorage;
try {
const electron = require('electron');
cachedSafeStorage = electron && typeof electron === 'object' ? electron.safeStorage || null : null;
} catch {
cachedSafeStorage = null;
}
return cachedSafeStorage;
}
const DEFAULT_CONFIG = {
schemaVersion: 13,
setupComplete: false,
@@ -215,6 +227,7 @@ class ConfigStore {
return { persistent: true, preserved: false };
}
const safeStorage = getSafeStorage();
if (safeStorage?.isEncryptionAvailable?.()) {
this.data.gitea.encryptedToken = safeStorage.encryptString(value).toString('base64');
this.sessionToken = null;
@@ -230,6 +243,7 @@ class ConfigStore {
if (this.sessionToken) return this.sessionToken;
if (!this.data.gitea.encryptedToken) return '';
try {
const safeStorage = getSafeStorage();
return safeStorage?.decryptString?.(Buffer.from(this.data.gitea.encryptedToken, 'base64')) || '';
} catch {
return '';
@@ -240,6 +254,7 @@ class ConfigStore {
encryptSecret(value) {
const text = String(value || '');
if (!text) return null;
const safeStorage = getSafeStorage();
if (!safeStorage?.isEncryptionAvailable?.()) {
const error = new Error('Secure credential storage is unavailable. ForgeFlow will not persist server passwords or key passphrases.');
error.code = 'SECURE_STORAGE_UNAVAILABLE';
@@ -250,7 +265,10 @@ class ConfigStore {
decryptSecret(value) {
if (!value) return '';
try { return safeStorage?.decryptString?.(Buffer.from(value, 'base64')) || ''; }
try {
const safeStorage = getSafeStorage();
return safeStorage?.decryptString?.(Buffer.from(value, 'base64')) || '';
}
catch { return ''; }
}