Files
NianAIGC/tests/settings-go-contract.test.ts
2026-08-18 18:23:11 +08:00

58 lines
2.9 KiB
TypeScript

import { readFile } from "node:fs/promises";
import { describe, expect, it } from "vitest";
const fixtureUrl = new URL("../contracts/settings/runtime-v1.json", import.meta.url);
const runtimeSettingsMigrationUrl = new URL(
"../database/migrations/0003_platform_runtime_settings.sql",
import.meta.url
);
const applicationUrl = new URL("../backend/internal/application/application.go", import.meta.url);
const runtimeUrl = new URL("../backend/internal/application/runtime.go", import.meta.url);
const settingsServiceUrl = new URL("../backend/internal/settings/service.go", import.meta.url);
describe("Go runtime settings compatibility fixture", () => {
it("freezes the editable whitelist and secret projection rules", async () => {
const fixture = JSON.parse(await readFile(fixtureUrl, "utf8"));
expect(fixture).toMatchObject({
version: 1,
fileName: ".env.local",
emptySecretInput: "preserve",
emptyNonSecretInput: "write-empty",
publicSecretValue: "blank",
runtimeApplication: "mixed",
providerRuntimeApplication: "immediate",
providerPersistence: "postgres-with-environment-fallback",
settingsPersistence: "postgres-with-environment-fallback"
});
expect(fixture.allowedKeys).toContain("IMAGE_GENERATE_ENGINE");
expect(fixture.secretKeys).toContain("ALI_OSS_ACCESS_KEY_SECRET");
expect(fixture.allowedKeys).not.toContain("DATABASE_URL");
expect([...fixture.databaseBackedKeys].sort()).toEqual([...fixture.allowedKeys].sort());
});
it("requires a PostgreSQL table for all mutable settings", async () => {
const migration = await readFile(runtimeSettingsMigrationUrl, "utf8");
expect(migration).toContain("create table if not exists platform_runtime_settings");
expect(migration).toContain("setting_key text primary key");
expect(migration).toContain("setting_value text not null");
});
it("loads database settings for startup services and refreshes provider calls", async () => {
const [application, runtime, service] = await Promise.all([
readFile(applicationUrl, "utf8"),
readFile(runtimeUrl, "utf8"),
readFile(settingsServiceUrl, "utf8")
]);
expect(application).toContain("databaseSettingsService(getenv, repository)");
expect(application).toContain("runtimeSettingsGetenv(ctx, getenv, runtimeSettings)");
expect(application).toContain("ParseAuthConfig(startupGetenv)");
expect(application).toContain("configuredOSSBlobStore(startupGetenv)");
expect(application).toContain("newRuntimeProviderResolver(getenv, runtimeSettings)");
expect(application).toContain("runtimeProviderJobBuilder{");
expect(runtime).toContain("runtimeSettingsGetenv(ctx, builder.fallback, builder.settings)");
expect(runtime).toContain("runtimeSettingsGetenv(ctx, resolver.fallback, resolver.settings)");
expect(service).toContain("values override process/file values");
expect(application).not.toContain("validateProductionProviderConfiguration");
});
});