refactor: split GitOps renderer by responsibility
This commit is contained in:
@@ -5,7 +5,9 @@ import { mkdir, mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promis
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
import vm from "node:vm";
|
||||
|
||||
import { configString } from "./src/gitops-render/core.mjs";
|
||||
import { opencodeEgressProxyUrlForProfile } from "./src/gitops-render/runtime-manifests.mjs";
|
||||
|
||||
import { CLOUD_CORE_MIGRATIONS, CLOUD_TRANSACTIONAL_REALTIME_MIGRATION_ID } from "../internal/db/schema.ts";
|
||||
|
||||
@@ -101,36 +103,11 @@ async function runtimeNoopDecision(gitopsPromoteScript, { oldRuntime, newRuntime
|
||||
}
|
||||
}
|
||||
|
||||
function extractNamedFunction(source, name) {
|
||||
const start = source.indexOf(`function ${name}`);
|
||||
assert.notEqual(start, -1, `missing function ${name}`);
|
||||
const bodyStart = source.indexOf("{", start);
|
||||
assert.notEqual(bodyStart, -1, `missing function body for ${name}`);
|
||||
let depth = 0;
|
||||
for (let index = bodyStart; index < source.length; index += 1) {
|
||||
const char = source[index];
|
||||
if (char === "{") depth += 1;
|
||||
else if (char === "}") {
|
||||
depth -= 1;
|
||||
if (depth === 0) return source.slice(start, index + 1);
|
||||
}
|
||||
}
|
||||
assert.fail(`unterminated function ${name}`);
|
||||
}
|
||||
|
||||
test("opencode APK proxy prefers explicit gitMirror proxyUrl", async () => {
|
||||
const source = await readFile("scripts/gitops-render.mjs", "utf8");
|
||||
const context = {};
|
||||
vm.runInNewContext(`${extractNamedFunction(source, "configString")}
|
||||
${extractNamedFunction(source, "opencodeEgressProxyUrlForProfile")}
|
||||
globalThis.result = {
|
||||
hostRoute: opencodeEgressProxyUrlForProfile({ lanes: { v03: { gitMirror: { egressProxy: { required: true, proxyUrl: "http://10.42.0.1:10808", namespace: "platform-infra", serviceName: "jd01-host-proxy", port: 10808 } } } } }, "v03"),
|
||||
serviceFallback: opencodeEgressProxyUrlForProfile({ lanes: { v03: { gitMirror: { egressProxy: { required: true, namespace: "platform-infra", serviceName: "sub2api-egress-proxy", port: 10808 } } } } }, "v03"),
|
||||
disabled: opencodeEgressProxyUrlForProfile({ lanes: { v03: { gitMirror: { egressProxy: { required: false, proxyUrl: "http://10.42.0.1:10808" } } } } }, "v03")
|
||||
};`, context, { filename: "gitops-render-opencode-proxy.test.mjs" });
|
||||
assert.equal(context.result.hostRoute, "http://10.42.0.1:10808");
|
||||
assert.equal(context.result.serviceFallback, "http://sub2api-egress-proxy.platform-infra.svc.cluster.local:10808");
|
||||
assert.equal(context.result.disabled, "");
|
||||
assert.equal(configString(" value "), "value");
|
||||
assert.equal(opencodeEgressProxyUrlForProfile({ lanes: { v03: { gitMirror: { egressProxy: { required: true, proxyUrl: "http://10.42.0.1:10808", namespace: "platform-infra", serviceName: "jd01-host-proxy", port: 10808 } } } } }, "v03"), "http://10.42.0.1:10808");
|
||||
assert.equal(opencodeEgressProxyUrlForProfile({ lanes: { v03: { gitMirror: { egressProxy: { required: true, namespace: "platform-infra", serviceName: "sub2api-egress-proxy", port: 10808 } } } } }, "v03"), "http://sub2api-egress-proxy.platform-infra.svc.cluster.local:10808");
|
||||
assert.equal(opencodeEgressProxyUrlForProfile({ lanes: { v03: { gitMirror: { egressProxy: { required: false, proxyUrl: "http://10.42.0.1:10808" } } } } }, "v03"), "");
|
||||
});
|
||||
|
||||
test("v02 render follows TypeScript runtime checks and does not self-patch bootstrap RBAC", async () => {
|
||||
|
||||
Reference in New Issue
Block a user