ГЛОБАЛЬНЫЙ РЕФАКТОРИНГ АРХИТЕКТУРЫ - Архитектура маршрутизации: зафиксирован 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
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import type { AddressCapabilityLayer, AddressCapabilityRouteMode, AddressIntent } from "../types/addressQuery";
|
||||
|
||||
export interface AddressRouteBaselineEntry {
|
||||
intent: AddressIntent;
|
||||
capability_id: string;
|
||||
capability_layer: AddressCapabilityLayer;
|
||||
capability_route_mode: AddressCapabilityRouteMode;
|
||||
}
|
||||
|
||||
export interface AddressRouteBaselineContract {
|
||||
schema_version: "address_route_baseline_v1";
|
||||
updated_at: string;
|
||||
entries: AddressRouteBaselineEntry[];
|
||||
}
|
||||
|
||||
const BASELINE_FILE = path.resolve(__dirname, "..", "..", "..", "..", "docs", "TECH", "address_route_baseline_v1.json");
|
||||
|
||||
function toObject(value: unknown): Record<string, unknown> | null {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
return null;
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function toNonEmptyString(value: unknown): string | null {
|
||||
if (typeof value !== "string") {
|
||||
return null;
|
||||
}
|
||||
const trimmed = value.trim();
|
||||
return trimmed.length > 0 ? trimmed : null;
|
||||
}
|
||||
|
||||
function parseEntry(value: unknown): AddressRouteBaselineEntry | null {
|
||||
const object = toObject(value);
|
||||
if (!object) {
|
||||
return null;
|
||||
}
|
||||
const intent = toNonEmptyString(object.intent) as AddressIntent | null;
|
||||
const capabilityId = toNonEmptyString(object.capability_id);
|
||||
const layer = toNonEmptyString(object.capability_layer) as AddressCapabilityLayer | null;
|
||||
const routeMode = toNonEmptyString(object.capability_route_mode) as AddressCapabilityRouteMode | null;
|
||||
if (!intent || !capabilityId || !layer || !routeMode) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
intent,
|
||||
capability_id: capabilityId,
|
||||
capability_layer: layer,
|
||||
capability_route_mode: routeMode
|
||||
};
|
||||
}
|
||||
|
||||
export function loadAddressRouteBaselineContract(): AddressRouteBaselineContract {
|
||||
const raw = fs.readFileSync(BASELINE_FILE, "utf-8");
|
||||
const parsed = JSON.parse(raw) as unknown;
|
||||
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 is AddressRouteBaselineEntry => 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
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { loadAddressRouteBaselineContract } from "../src/services/addressRouteBaseline";
|
||||
import { resolveAddressCapabilityRouteDecision } from "../src/services/addressCapabilityPolicy";
|
||||
|
||||
describe("address route baseline contract", () => {
|
||||
it("keeps capability route mapping aligned with frozen baseline", () => {
|
||||
const baseline = loadAddressRouteBaselineContract();
|
||||
expect(baseline.schema_version).toBe("address_route_baseline_v1");
|
||||
expect(Array.isArray(baseline.entries)).toBe(true);
|
||||
expect(baseline.entries.length).toBeGreaterThan(0);
|
||||
|
||||
for (const entry of baseline.entries) {
|
||||
const decision = resolveAddressCapabilityRouteDecision(entry.intent);
|
||||
expect(decision.capability_id).toBe(entry.capability_id);
|
||||
expect(decision.capability_layer).toBe(entry.capability_layer);
|
||||
expect(decision.capability_route_mode).toBe(entry.capability_route_mode);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user