refactor(FN-1616): convert blocking fs operations to async on HTTP request paths

- Convert skills-adapter.ts readFileSync/writeFileSync to async readFile/writeFile
- Cache GitHub webhook private key in memory to avoid repeated fs reads
- Convert usage.ts readFileSync to async readFile
- Update usage.test.ts to work with async file operations
- All HTTP request handlers now use non-blocking async fs operations
This commit is contained in:
Fusion
2026-04-15 01:39:34 -07:00
committed by gsxdsm
parent 97528ee724
commit 4f447b9182
4 changed files with 145 additions and 128 deletions

View File

@@ -3,6 +3,17 @@ import { readFileSync } from "node:fs";
import type { IssueInfo, PrInfo } from "@fusion/core";
import { GitHubClient } from "./github.js";
// Module-level cache for the GitHub App private key
// undefined = not yet read, null = read failed, string = cached key
let cachedPrivateKey: string | null | undefined = undefined;
/**
* Clear the private key cache (for testing).
*/
export function _clearPrivateKeyCache(): void {
cachedPrivateKey = undefined;
}
/**
* GitHub App webhook configuration from environment variables.
*/
@@ -64,16 +75,20 @@ export function getGitHubAppConfig(): GitHubAppConfig | null {
const webhookSecret = process.env.FUSION_GITHUB_WEBHOOK_SECRET;
let privateKey: string | undefined;
if (process.env.FUSION_GITHUB_APP_PRIVATE_KEY) {
privateKey = process.env.FUSION_GITHUB_APP_PRIVATE_KEY;
} else if (process.env.FUSION_GITHUB_APP_PRIVATE_KEY_PATH) {
try {
privateKey = readFileSync(process.env.FUSION_GITHUB_APP_PRIVATE_KEY_PATH, "utf-8");
} catch {
// Failed to read key file
return null;
// Check cache before reading from disk
if (cachedPrivateKey === undefined) {
try {
cachedPrivateKey = readFileSync(process.env.FUSION_GITHUB_APP_PRIVATE_KEY_PATH, "utf-8");
} catch {
// Failed to read key file
cachedPrivateKey = null;
}
}
privateKey = cachedPrivateKey ?? undefined;
}
if (!appId || !privateKey || !webhookSecret) {