ГЛОБАЛЬНЫЙ РЕФАКТОРИНГ АРХИТЕКТУРЫ - Архитектура маршрутизации: зафиксирован baseline-контракт и добавлен anti-regression контроль
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.loadAddressRouteBaselineContract = loadAddressRouteBaselineContract;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const BASELINE_FILE = path_1.default.resolve(__dirname, "..", "..", "..", "..", "docs", "TECH", "address_route_baseline_v1.json");
|
||||
function toObject(value) {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
return null;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
function toNonEmptyString(value) {
|
||||
if (typeof value !== "string") {
|
||||
return null;
|
||||
}
|
||||
const trimmed = value.trim();
|
||||
return trimmed.length > 0 ? trimmed : null;
|
||||
}
|
||||
function parseEntry(value) {
|
||||
const object = toObject(value);
|
||||
if (!object) {
|
||||
return null;
|
||||
}
|
||||
const intent = toNonEmptyString(object.intent);
|
||||
const capabilityId = toNonEmptyString(object.capability_id);
|
||||
const layer = toNonEmptyString(object.capability_layer);
|
||||
const routeMode = toNonEmptyString(object.capability_route_mode);
|
||||
if (!intent || !capabilityId || !layer || !routeMode) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
intent,
|
||||
capability_id: capabilityId,
|
||||
capability_layer: layer,
|
||||
capability_route_mode: routeMode
|
||||
};
|
||||
}
|
||||
function loadAddressRouteBaselineContract() {
|
||||
const raw = fs_1.default.readFileSync(BASELINE_FILE, "utf-8");
|
||||
const parsed = JSON.parse(raw);
|
||||
const root = toObject(parsed);
|
||||
if (!root) {
|
||||
throw new Error("address_route_baseline_v1: invalid root payload");
|
||||
}
|
||||
const schemaVersion = toNonEmptyString(root.schema_version);
|
||||
if (schemaVersion !== "address_route_baseline_v1") {
|
||||
throw new Error(`address_route_baseline_v1: unexpected schema version '${schemaVersion ?? "null"}'`);
|
||||
}
|
||||
const updatedAt = toNonEmptyString(root.updated_at) ?? new Date().toISOString();
|
||||
const entriesRaw = Array.isArray(root.entries) ? root.entries : [];
|
||||
const entries = entriesRaw.map(parseEntry).filter((entry) => entry !== null);
|
||||
if (entries.length === 0) {
|
||||
throw new Error("address_route_baseline_v1: no valid entries");
|
||||
}
|
||||
return {
|
||||
schema_version: "address_route_baseline_v1",
|
||||
updated_at: updatedAt,
|
||||
entries
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user