feat: resolve workspace bindings into runtime configs
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
import { expect, test } from "vitest";
|
||||
import { parse } from "yaml";
|
||||
import { renderRuntimeConfig, type RuntimeBindings, type RuntimePaths } from "../src/workspaces/runtime-renderer.js";
|
||||
import { parseWorkspaceYaml } from "../src/workspaces/schema.js";
|
||||
|
||||
const workspace = parseWorkspaceYaml(`workspace:
|
||||
schema_version: 1
|
||||
id: psd-clinical
|
||||
name: Policlinico San Donato
|
||||
language: it
|
||||
dwh:
|
||||
engine: postgres
|
||||
database: postgres
|
||||
schema: datawarehouse
|
||||
supported_transports: [postgres_direct, rest_api]
|
||||
semantic_index:
|
||||
vector_store:
|
||||
engine: pgvector
|
||||
collection: clinical_documents
|
||||
dimensions: 768
|
||||
distance: cosine
|
||||
supported_transports: [pgvector_direct, rest_api]
|
||||
embedding:
|
||||
provider: ollama_compatible
|
||||
model: nomic-embed-text-v2-moe
|
||||
dimensions: 768
|
||||
llm_policy:
|
||||
allowed: [zai/glm-5.2]
|
||||
`);
|
||||
const paths: RuntimePaths = {
|
||||
sessions: "/data/workspaces/psd-clinical/sessions",
|
||||
artifacts: "/data/workspaces/psd-clinical/artifacts",
|
||||
indexes: "/data/workspaces/psd-clinical/indexes",
|
||||
};
|
||||
|
||||
const directBindings: RuntimeBindings = {
|
||||
dwh: {
|
||||
transport: "postgres_direct",
|
||||
missing: [],
|
||||
values: {
|
||||
THT_WS_PSD_CLINICAL_DWH_HOST: "dwh.internal",
|
||||
THT_WS_PSD_CLINICAL_DWH_PORT: "5432",
|
||||
THT_WS_PSD_CLINICAL_DWH_USER: "thoth_reader",
|
||||
THT_WS_PSD_CLINICAL_DWH_PASSWORD_FILE: "/run/secrets/dwh-password",
|
||||
},
|
||||
},
|
||||
vector: {
|
||||
transport: "pgvector_direct",
|
||||
missing: [],
|
||||
values: {
|
||||
THT_WS_PSD_CLINICAL_VECTOR_HOST: "vector.internal",
|
||||
THT_WS_PSD_CLINICAL_VECTOR_PORT: "5432",
|
||||
THT_WS_PSD_CLINICAL_VECTOR_USER: "vector_reader",
|
||||
THT_WS_PSD_CLINICAL_VECTOR_PASSWORD_FILE: "/run/secrets/vector-password",
|
||||
},
|
||||
},
|
||||
embedding: {
|
||||
transport: "rest_api",
|
||||
missing: [],
|
||||
values: { THT_WS_PSD_CLINICAL_EMBEDDING_BASE_URL: "http://embedding.internal:11434" },
|
||||
},
|
||||
};
|
||||
|
||||
test("renders a direct PostgreSQL binding to the legacy harness shape", () => {
|
||||
const yaml = renderRuntimeConfig(workspace, directBindings, paths);
|
||||
const rendered = parse(yaml);
|
||||
|
||||
expect(rendered).toMatchObject({
|
||||
language: "it",
|
||||
database: {
|
||||
host: "dwh.internal",
|
||||
port: 5432,
|
||||
database: "postgres",
|
||||
schema: "datawarehouse",
|
||||
user: "thoth_reader",
|
||||
password_file: "/run/secrets/dwh-password",
|
||||
transport: "direct",
|
||||
},
|
||||
vector_db: {
|
||||
host: "vector.internal",
|
||||
schema: "datawarehouse",
|
||||
password_file: "/run/secrets/vector-password",
|
||||
},
|
||||
embeddings: {
|
||||
base_url: "http://embedding.internal:11434",
|
||||
model: "nomic-embed-text-v2-moe",
|
||||
dim: 768,
|
||||
},
|
||||
paths,
|
||||
});
|
||||
expect(yaml).toContain("type: postgres_direct");
|
||||
expect(yaml).toContain("schema: datawarehouse");
|
||||
});
|
||||
|
||||
test("renders REST bindings through the legacy rest sections without secret values", () => {
|
||||
const yaml = renderRuntimeConfig(workspace, {
|
||||
...directBindings,
|
||||
dwh: {
|
||||
transport: "rest_api",
|
||||
missing: [],
|
||||
values: {
|
||||
THT_WS_PSD_CLINICAL_DWH_BASE_URL: "https://dwh.example.test",
|
||||
THT_WS_PSD_CLINICAL_DWH_API_KEY_FILE: "/run/secrets/dwh-api-key",
|
||||
THT_WS_PSD_CLINICAL_DWH_TLS_CA_FILE: "/run/secrets/ca.pem",
|
||||
},
|
||||
},
|
||||
vector: {
|
||||
transport: "rest_api",
|
||||
missing: [],
|
||||
values: {
|
||||
THT_WS_PSD_CLINICAL_VECTOR_BASE_URL: "https://vector.example.test",
|
||||
THT_WS_PSD_CLINICAL_VECTOR_API_KEY_FILE: "/run/secrets/vector-api-key",
|
||||
},
|
||||
},
|
||||
}, paths);
|
||||
const rendered = parse(yaml);
|
||||
|
||||
expect(rendered).toMatchObject({
|
||||
database: { transport: "rest", schema: "datawarehouse" },
|
||||
rest: {
|
||||
base_url: "https://dwh.example.test",
|
||||
api_key_file: "/run/secrets/dwh-api-key",
|
||||
ssl_ca_file: "/run/secrets/ca.pem",
|
||||
},
|
||||
vector_rest: {
|
||||
base_url: "https://vector.example.test",
|
||||
api_key_file: "/run/secrets/vector-api-key",
|
||||
},
|
||||
});
|
||||
expect(yaml).not.toContain("\n api_key: ");
|
||||
});
|
||||
Reference in New Issue
Block a user