fix(auth): align fallback API key format with test setup

Update the deterministic fallback API key to use hyphens instead of
underscores so generated keys match the expected format.

Also set API_KEY_SECRET in unit tests that exercise API key creation to
ensure consistent resolver behavior under test.
This commit is contained in:
diegosouzapw
2026-04-27 17:40:04 -03:00
parent caeba1fd91
commit a5e32a6d32
3 changed files with 3 additions and 1 deletions

View File

@@ -39,6 +39,6 @@ export async function getOrCreateApiKey(apiKeyId?: string | null): Promise<strin
return keyRecord.key as string;
} catch {
// Fallback: generate a deterministic key if DB write fails
return `sk_${machineId}_fallback_${Date.now()}`;
return `sk-${machineId}-fallback-${Date.now()}`;
}
}

View File

@@ -51,6 +51,7 @@ test.beforeEach(async () => {
// Force XDG_CONFIG_HOME so resolveOpencodeConfigPath resolves to our dummy dir
// (CI runners often have XDG_CONFIG_HOME set, causing path mismatch)
process.env.XDG_CONFIG_HOME = path.join(DUMMY_HOME, ".config");
process.env.API_KEY_SECRET = "test-secret";
await fs.mkdir(path.dirname(QWEN_CONFIG_PATH), { recursive: true }).catch(() => {});
});

View File

@@ -26,6 +26,7 @@ const originalHomedir = os.homedir;
test.beforeEach(async () => {
process.env.DATA_DIR = DUMMY_HOME;
process.env.API_KEY_SECRET = "test-secret";
os.homedir = () => DUMMY_HOME;
await fs.mkdir(DUMMY_HOME, { recursive: true }).catch(() => {});
// Initialize DB