Files
tibi-types/scripts/validate-schemas.mjs
apairon 5a45c4dd3f feat(types): Embedding-Abschnitt der Server-Config (Provider, Failover-Gruppen, goldener Pfad) + Status-Payloads
index.d.ts: EmbeddingProviderConfig/EmbeddingGroupConfig (onSingleQuery, onBulkWrite,
health), EmbeddingConfig für config.server().embedding (Roh-JSON von config.Server.
Embedding) sowie die Status-Payloads von GET …/admin/embedding/status (Projekt- und
Server-Scope, Zustände live|degraded|quarantined|offline, Breaker closed|open|half-open).
VectorConfig.provider dokumentiert jetzt, dass dort auch ein Gruppenname stehen darf.

schemas/config/embedding.schema.json: validierbares Schema des Server-Abschnitts
(Enums für Policies/Distributionen, Go-Duration-Muster, Pflichtfelder, keine
erfundenen Properties); Beispiel examples/server/embedding.yml, per
scripts/validate-schemas.mjs mitgeprüft (npm test: 5 YAML gegen 17 Schemas).

Quelle der Wahrheit: internal/config/server.go + internal/config/embedding_group.go
(tibi-server). Typecheck: tsc --noEmit --strict über index.d.ts grün.
2026-10-17 14:00:53 +00:00

114 lines
3.1 KiB
JavaScript

import fs from "node:fs"
import path from "node:path"
import { fileURLToPath } from "node:url"
import Ajv from "ajv"
import addFormats from "ajv-formats"
import { globSync } from "glob"
import yaml from "js-yaml"
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const repoRoot = path.resolve(__dirname, "..")
const schemaDir = path.join(repoRoot, "schemas", "config")
const includeType = new yaml.Type("!include", {
kind: "scalar",
construct(data) {
return data ?? ""
},
})
const yamlSchema = yaml.DEFAULT_SCHEMA.extend([includeType])
const ajv = new Ajv({
allErrors: true,
strict: false,
})
addFormats(ajv)
const schemaFiles = globSync("*.schema.json", {
cwd: schemaDir,
absolute: true,
}).sort()
if (schemaFiles.length === 0) {
console.error("No schema files found in", schemaDir)
process.exit(1)
}
for (const filePath of schemaFiles) {
const schema = JSON.parse(fs.readFileSync(filePath, "utf8"))
ajv.addSchema(schema, schema.$id || path.basename(filePath))
}
for (const filePath of schemaFiles) {
const schema = JSON.parse(fs.readFileSync(filePath, "utf8"))
ajv.getSchema(schema.$id || path.basename(filePath))
}
const validations = [
{ schema: "project.schema.json", pattern: "demo-api/config.y*ml" },
{
schema: "collection.schema.json",
pattern: "demo-api/collections/*.y*ml",
},
{
schema: "field.schema.json",
pattern: "demo-api/collections/fields/*.y*ml",
},
{
schema: "field-list.schema.json",
pattern: "demo-api/collections/fieldLists/*.y*ml",
},
{ schema: "job.schema.json", pattern: "demo-api/jobs/*.y*ml" },
{ schema: "action.schema.json", pattern: "demo-api/actions/*.y*ml" },
{ schema: "asset.schema.json", pattern: "demo-api/assets/*.y*ml" },
// Server-level Abschnitt (config.yml des tibi-servers), Beispiel getrennt
// vom Projekt-Demo unter examples/server/:
{ schema: "embedding.schema.json", pattern: "examples/server/*.y*ml" },
]
let hasErrors = false
let validatedCount = 0
for (const { schema, pattern } of validations) {
const validate = ajv.getSchema(schema)
if (!validate) {
console.error(`Schema not registered: ${schema}`)
hasErrors = true
continue
}
const files = globSync(pattern, {
cwd: repoRoot,
absolute: true,
}).sort()
for (const filePath of files) {
const raw = fs.readFileSync(filePath, "utf8")
const parsed = yaml.load(raw, { schema: yamlSchema })
const valid = validate(parsed)
validatedCount += 1
if (!valid) {
hasErrors = true
console.error(
`\nValidation failed: ${path.relative(repoRoot, filePath)}`
)
for (const error of validate.errors || []) {
const location = error.instancePath || "/"
console.error(` ${location} ${error.message}`)
}
}
}
}
if (hasErrors) {
process.exit(1)
}
console.log(
`Validated ${validatedCount} YAML file(s) against ${schemaFiles.length} schema file(s).`
)