Fix Bifrost bridge runtime and fixture env isolation

This commit is contained in:
Meta Vens 2026-06-22 14:03:07 +01:00
commit ba01b78d68
7 changed files with 147 additions and 15 deletions

View file

@ -16,8 +16,17 @@ const defaultPersonaName = "Bifrost";
const defaultPersonaAvatarUrl =
"https://raw.githubusercontent.com/GameCult/Bifrost/main/src/Bifrost.Web/wwwroot/img/bifrost-profile.png";
const cultCacheRequire = createRequire(resolve(projectsRoot, "CultCacheTS", "node_modules", "cultcache-ts", "package.json"));
const cultNetRequire = createRequire(resolve(projectsRoot, "CultNetTS", "package.json"));
const cultCachePackagePath = resolveFirstExisting("CultCache TypeScript runtime", [
resolve(projectsRoot, "CultLib", "packages", "cultcache-ts", "package.json"),
resolve(projectsRoot, "CultCacheTS", "package.json"),
resolve(projectsRoot, "CultCacheTS", "node_modules", "cultcache-ts", "package.json"),
]);
const cultNetPackagePath = resolveFirstExisting("CultNet TypeScript runtime", [
resolve(projectsRoot, "CultLib", "packages", "cultnet-ts", "package.json"),
resolve(projectsRoot, "CultNetTS", "package.json"),
]);
const cultCacheRequire = createRequire(cultCachePackagePath);
const cultNetRequire = createRequire(cultNetPackagePath);
const {
CultCache,
@ -27,9 +36,19 @@ const {
const {
CultNetDocumentRegistry,
defineCultNetDocumentBinding,
} = cultNetRequire(resolve(projectsRoot, "CultNetTS", "dist", "index.js"));
} = cultNetRequire("cultnet-ts");
const { encode, decode } = cultNetRequire("@msgpack/msgpack");
function resolveFirstExisting(label, candidates) {
for (const candidate of candidates) {
if (existsSync(candidate)) {
return candidate;
}
}
throw new Error(`${label} is unavailable. Tried: ${candidates.join(", ")}`);
}
const documentType = "bifrost.agent-transport.update-request";
const schemaId = "bifrost.agent-transport.update-request.v0";
const validStatuses = new Set(["queued", "claimed", "completed", "cancelled"]);
@ -81,8 +100,7 @@ const cultNetRegistry = new CultNetDocumentRegistry([
]);
async function main() {
loadLocalEnv(resolve(repoRoot, ".env"));
loadLocalEnv(resolve(projectsRoot, "VoidBot", ".env"));
loadBifrostLocalEnv();
const [command, ...rawArgs] = process.argv.slice(2);
const options = parseArgs(rawArgs);
@ -128,6 +146,15 @@ async function main() {
}
}
function loadBifrostLocalEnv() {
if (process.env.BIFROST_SKIP_LOCAL_ENV === "true") {
return;
}
loadLocalEnv(resolve(repoRoot, ".env"));
loadLocalEnv(resolve(projectsRoot, "VoidBot", ".env"));
}
function isMutatingCommand(command) {
return command === "enqueue"
|| command === "claim"

View file

@ -13,8 +13,7 @@ const repoRoot = resolve(scriptDir, "..");
const projectsRoot = resolve(repoRoot, "..");
async function main() {
loadLocalEnv(resolve(repoRoot, ".env"));
loadLocalEnv(resolve(projectsRoot, "VoidBot", ".env"));
loadBifrostLocalEnv();
const [command, ...rawArgs] = process.argv.slice(2);
const options = parseArgs(rawArgs);
@ -44,6 +43,15 @@ async function main() {
}
}
function loadBifrostLocalEnv() {
if (process.env.BIFROST_SKIP_LOCAL_ENV === "true") {
return;
}
loadLocalEnv(resolve(repoRoot, ".env"));
loadLocalEnv(resolve(projectsRoot, "VoidBot", ".env"));
}
async function createGitHubDraftPr(options) {
ensureGitHubBridgeGate(options);
const repoRoot = resolve(requireOption(options, "repo-root"));

View file

@ -17,8 +17,7 @@ const defaultPersonaAvatarUrl =
"https://raw.githubusercontent.com/GameCult/Bifrost/main/src/Bifrost.Web/wwwroot/img/bifrost-profile.png";
async function main() {
loadLocalEnv(resolve(bifrostRoot, ".env"));
loadLocalEnv(resolve(defaultProjectsRoot, "VoidBot", ".env"));
loadBifrostLocalEnv();
const [command, ...rawArgs] = process.argv.slice(2);
const options = parseArgs(rawArgs);
@ -43,6 +42,15 @@ async function main() {
}
}
function loadBifrostLocalEnv() {
if (process.env.BIFROST_SKIP_LOCAL_ENV === "true") {
return;
}
loadLocalEnv(resolve(bifrostRoot, ".env"));
loadLocalEnv(resolve(defaultProjectsRoot, "VoidBot", ".env"));
}
async function dispatchQueuedRequests(options) {
const max = parseInteger(options.max ?? "1", "max");
const statusDir = resolveOptionPath(options["status-dir"] ?? defaultStatusDir);

View file

@ -18,13 +18,28 @@ const defaultPersonaName = "Bifrost";
const defaultPersonaAvatarUrl =
"https://raw.githubusercontent.com/GameCult/Bifrost/main/src/Bifrost.Web/wwwroot/img/bifrost-profile.png";
const cultCacheRequire = createRequire(resolve(projectsRoot, "CultCacheTS", "node_modules", "cultcache-ts", "package.json"));
const cultCachePackagePath = resolveFirstExisting("CultCache TypeScript runtime", [
resolve(projectsRoot, "CultLib", "packages", "cultcache-ts", "package.json"),
resolve(projectsRoot, "CultCacheTS", "package.json"),
resolve(projectsRoot, "CultCacheTS", "node_modules", "cultcache-ts", "package.json"),
]);
const cultCacheRequire = createRequire(cultCachePackagePath);
const {
CultCache,
SingleFileMessagePackBackingStore,
defineDocumentType,
} = cultCacheRequire("cultcache-ts");
function resolveFirstExisting(label, candidates) {
for (const candidate of candidates) {
if (existsSync(candidate)) {
return candidate;
}
}
throw new Error(`${label} is unavailable. Tried: ${candidates.join(", ")}`);
}
const topicType = "bifrost.governance.topic";
const topicSchemaId = "bifrost.governance.topic.v0";
const commentType = "bifrost.governance.topic-comment";
@ -91,8 +106,7 @@ const commentDefinition = defineDocumentType({
});
async function main() {
loadLocalEnv(resolve(repoRoot, ".env"));
loadLocalEnv(resolve(projectsRoot, "VoidBot", ".env"));
loadBifrostLocalEnv();
const [command, ...rawArgs] = process.argv.slice(2);
const options = parseArgs(rawArgs);
@ -138,6 +152,15 @@ async function main() {
}
}
function loadBifrostLocalEnv() {
if (process.env.BIFROST_SKIP_LOCAL_ENV === "true") {
return;
}
loadLocalEnv(resolve(repoRoot, ".env"));
loadLocalEnv(resolve(projectsRoot, "VoidBot", ".env"));
}
async function openCache(storePath) {
const cache = CultCache.builder()
.withDocumentType(topicDefinition)

View file

@ -11,7 +11,7 @@ const repoRoot = resolve(scriptDir, "..");
const projectsRoot = resolve(repoRoot, "..");
const defaultStorePath = resolve(repoRoot, ".bifrost", "provider-advertisement.cc");
const cultCacheRequire = createRequire(resolve(projectsRoot, "CultCacheTS", "package.json"));
const cultCacheRequire = createRequire(resolveCultCachePackagePath());
const cultCacheRuntime = loadCultCacheRuntime();
const {
CultCache,
@ -21,8 +21,8 @@ const {
function loadCultCacheRuntime() {
const candidates = [
resolve(projectsRoot, "CultCacheTS", "dist", "index.js"),
resolve(projectsRoot, "CultLib", "packages", "cultcache-ts", "dist", "index.js"),
resolve(projectsRoot, "CultCacheTS", "dist", "index.js"),
];
for (const candidate of candidates) {
@ -39,6 +39,22 @@ function loadCultCacheRuntime() {
throw new Error("CultCache TypeScript runtime with document APIs is unavailable.");
}
function resolveCultCachePackagePath() {
const candidates = [
resolve(projectsRoot, "CultLib", "packages", "cultcache-ts", "package.json"),
resolve(projectsRoot, "CultCacheTS", "package.json"),
resolve(projectsRoot, "CultCacheTS", "node_modules", "cultcache-ts", "package.json"),
];
for (const candidate of candidates) {
if (existsSync(candidate)) {
return candidate;
}
}
throw new Error(`CultCache TypeScript runtime is unavailable. Tried: ${candidates.join(", ")}`);
}
const documentType = "gamecult.eve.provider_advertisement";
const schemaId = "gamecult.eve.provider_advertisement.v1";
const documentId = "bifrost";