fix: 将 production release 归并回 v0.3 单线历史

This commit is contained in:
root
2026-07-18 12:46:15 +02:00
19 changed files with 1761 additions and 121 deletions
+45 -3
View File
@@ -8,10 +8,32 @@ import test from "node:test";
import { parse as parseYaml } from "yaml";
import { configString } from "./src/gitops-render/core.mjs";
import { opencodeEgressProxyUrlForProfile } from "./src/gitops-render/runtime-manifests.mjs";
import { externalPostgresConfigForLane, externalPostgresManifest, opencodeEgressProxyUrlForProfile } from "./src/gitops-render/runtime-manifests.mjs";
import { CLOUD_CORE_MIGRATIONS, CLOUD_TRANSACTIONAL_REALTIME_MIGRATION_ID } from "../internal/db/schema.ts";
test("production migration uses its YAML-declared database Secret key", async () => {
const deploy = parseYaml(await readFile("deploy/deploy.yaml", "utf8"));
assert.deepEqual(deploy.lanes.production.workbench.rawHwlabEventWindow, {
enabled: true,
maxEntries: 200,
maxRetainedBytes: 1048576
});
const config = externalPostgresConfigForLane(deploy, "production", { nodeId: "NC01" });
const manifest = externalPostgresManifest({
profile: "production",
config,
source: { full: "a".repeat(40), short: "a".repeat(12), imageTag: "a".repeat(12) },
deploy,
migrationSources: [{ path: "0001_test.sql", sql: "select 1;" }]
});
const job = manifest.items.find((item) => item.kind === "Job");
assert.deepEqual(job?.spec?.template?.spec?.containers?.[0]?.env?.[0]?.valueFrom?.secretKeyRef, {
name: "hwlab-cloud-api-production-db",
key: "migration-database-url"
});
});
function taskByName(pipeline, name) {
const task = pipeline.spec.tasks.find((item) => item.name === name);
assert.ok(task, `missing task ${name}`);
@@ -296,6 +318,8 @@ test("v02 render follows TypeScript runtime checks and does not self-patch boots
assert.match(gitMirrorScript, /refs\/heads\/v0\.2-gitops:refs\/mirror-stage\/heads\/v0\.2-gitops/u);
assert.match(gitMirrorScript, /refs\/heads\/v0\.3:refs\/mirror-stage\/heads\/v0\.3/u);
assert.match(gitMirrorScript, /refs\/heads\/v0\.3-gitops:refs\/mirror-stage\/heads\/v0\.3-gitops/u);
assert.match(gitMirrorScript, /refs\/heads\/release:refs\/mirror-stage\/heads\/release/u);
assert.match(gitMirrorScript, /refs\/heads\/release-gitops:refs\/mirror-stage\/heads\/release-gitops/u);
assert.doesNotMatch(gitMirrorScript, /refs\/heads\/G14:refs\/mirror-stage\/heads\/G14/u);
assert.doesNotMatch(gitMirrorScript, /refs\/heads\/G14-gitops:refs\/mirror-stage\/heads\/G14-gitops/u);
assert.doesNotMatch(gitMirrorScript, /refs\/heads\/\*:refs\/mirror-stage\/heads\/\*/u);
@@ -311,7 +335,7 @@ test("v02 render follows TypeScript runtime checks and does not self-patch boots
assert.match(gitMirrorScript, /refs\/unidesk\/snapshots\/hwlab-node-runtime/u);
assert.match(gitMirrorScript, /refs\/mirror-stage\/heads\/v0\.2/u);
assert.match(gitMirrorScript, /refs\/mirror-stage\/heads\/v0\.3/u);
assert.match(gitMirrorScript, /for gitops_branch in 'v0\.2-gitops' 'v0\.3-gitops'/u);
assert.match(gitMirrorScript, /for gitops_branch in 'release-gitops' 'v0\.2-gitops' 'v0\.3-gitops'/u);
assert.match(gitMirrorScript, /keeps local \$name ahead of GitHub/u);
assert.doesNotMatch(gitMirror, /not allowlisted/u);
assert.doesNotMatch(gitMirror, /path allowlist/u);
@@ -731,7 +755,25 @@ test("v03 render keeps node identity as data instead of generated structure", as
assert.ok((projectManagementContainer?.volumeMounts ?? []).some((mount) => mount.name === "project-management-bootstrap" && mount.mountPath === "/etc/hwlab/project-management"));
assert.ok((projectManagementContainer?.env ?? []).some((entry) => entry.name === "HWLAB_PROJECT_MANAGEMENT_BOOTSTRAP_SOURCES_PATH" && entry.value === "/etc/hwlab/project-management/sources.json"));
const externalPostgres = JSON.parse(await readFile(path.join(outDir, "runtime-v03", "external-postgres.yaml"), "utf8"));
assert.deepEqual((externalPostgres.items ?? []).map((item) => item.kind), ["Service", "EndpointSlice"]);
assert.deepEqual((externalPostgres.items ?? []).map((item) => item.kind), ["ConfigMap", "Job", "Service", "EndpointSlice"]);
const externalPostgresMigrationConfig = (externalPostgres.items ?? []).find((item) => item.kind === "ConfigMap");
const externalPostgresMigrationJob = (externalPostgres.items ?? []).find((item) => item.kind === "Job");
assert.deepEqual(
Object.keys(externalPostgresMigrationConfig?.data ?? {}).filter((name) => name.endsWith(".sql")),
CLOUD_CORE_MIGRATIONS.map((migration) => path.basename(migration.path))
);
assert.match(externalPostgresMigrationConfig?.data?.["run.mjs"] ?? "", /DATABASE_URL is required/u);
assert.match(externalPostgresMigrationConfig?.data?.["run.mjs"] ?? "", /hwlab-runtime-migration-started/u);
assert.equal(externalPostgresMigrationConfig?.metadata?.annotations?.["argocd.argoproj.io/sync-wave"], "-2");
assert.equal(externalPostgresMigrationJob?.metadata?.annotations?.["argocd.argoproj.io/sync-wave"], "-1");
assert.equal(
externalPostgresMigrationJob?.spec?.template?.spec?.containers?.[0]?.image,
`127.0.0.1:5000/hwlab/hwlab-cloud-api-env@sha256:${"1".repeat(64)}`
);
assert.deepEqual(externalPostgresMigrationJob?.spec?.template?.spec?.containers?.[0]?.env?.[0]?.valueFrom?.secretKeyRef, {
name: "hwlab-cloud-api-v03-db",
key: "database-url"
});
const externalPostgresSlice = (externalPostgres.items ?? []).find((item) => item.kind === "EndpointSlice");
assert.equal(externalPostgresSlice?.metadata?.name, "jd01-pk01-platform-postgres-host");
assert.equal(externalPostgresSlice?.metadata?.labels?.["kubernetes.io/service-name"], "jd01-pk01-platform-postgres");