feat: 配置变量系统与 target id/name 双字段标识
- 新增顶层 variables 段支持 string/number/boolean 字面量
- target 字符串字段支持 、、{...} 转义语法
- 变量解析优先级: variables -> process.env -> 默认值 -> 报错
- 完整引用保留原始类型,部分引用拼接为字符串
- 变量替换在 YAML 解析后、AJV 校验前执行
- 替换仅作用于 targets,跳过 id/type 字段
- target 新增必填 id 字段作为唯一标识,name 改为可选展示名称
- 数据库存储/API/前端全面迁移到 id 标识
- 统一 checker 运行时类型检查为 es-toolkit predicates
- 同步 delta specs 到主 specs,归档 config-variables 变更
This commit is contained in:
@@ -11,7 +11,7 @@ describe("validateDbConfig", () => {
|
||||
test("缺少 db.url 返回错误", () => {
|
||||
const result = validateDbConfig({
|
||||
defaults: {},
|
||||
targets: [{ name: "test", type: "db" }],
|
||||
targets: [{ id: "test", name: "test", type: "db" }],
|
||||
});
|
||||
expect(result.length).toBeGreaterThan(0);
|
||||
const dbError = result.find((e) => e.path.includes("db"));
|
||||
@@ -22,7 +22,7 @@ describe("validateDbConfig", () => {
|
||||
test("db.url 为空字符串返回错误", () => {
|
||||
const result = validateDbConfig({
|
||||
defaults: {},
|
||||
targets: [{ db: { url: "" }, name: "test", type: "db" }],
|
||||
targets: [{ db: { url: "" }, id: "test", name: "test", type: "db" }],
|
||||
});
|
||||
const urlError = result.find((e) => e.path.includes("db.url"));
|
||||
expect(urlError).toBeDefined();
|
||||
@@ -32,7 +32,7 @@ describe("validateDbConfig", () => {
|
||||
test("db.query 为空字符串返回错误", () => {
|
||||
const result = validateDbConfig({
|
||||
defaults: {},
|
||||
targets: [{ db: { query: "", url: "sqlite://:memory:" }, name: "test", type: "db" }],
|
||||
targets: [{ db: { query: "", url: "sqlite://:memory:" }, id: "test", name: "test", type: "db" }],
|
||||
});
|
||||
const queryError = result.find((e) => e.path.includes("db.query"));
|
||||
expect(queryError).toBeDefined();
|
||||
@@ -42,7 +42,7 @@ describe("validateDbConfig", () => {
|
||||
test("db 分组未知字段返回错误", () => {
|
||||
const result = validateDbConfig({
|
||||
defaults: {},
|
||||
targets: [{ db: { timeout: 5, url: "sqlite://:memory:" }, name: "test", type: "db" }],
|
||||
targets: [{ db: { timeout: 5, url: "sqlite://:memory:" }, id: "test", name: "test", type: "db" }],
|
||||
});
|
||||
const unknownError = result.find((e) => e.path.includes("db.timeout"));
|
||||
expect(unknownError).toBeDefined();
|
||||
@@ -52,7 +52,15 @@ describe("validateDbConfig", () => {
|
||||
test("expect.maxDurationMs 非数字返回错误", () => {
|
||||
const result = validateDbConfig({
|
||||
defaults: {},
|
||||
targets: [{ db: { url: "sqlite://:memory:" }, expect: { maxDurationMs: "invalid" }, name: "test", type: "db" }],
|
||||
targets: [
|
||||
{
|
||||
db: { url: "sqlite://:memory:" },
|
||||
expect: { maxDurationMs: "invalid" },
|
||||
id: "test",
|
||||
name: "test",
|
||||
type: "db",
|
||||
},
|
||||
],
|
||||
});
|
||||
const durationError = result.find((e) => e.path.includes("expect.maxDurationMs"));
|
||||
expect(durationError).toBeDefined();
|
||||
@@ -62,7 +70,9 @@ describe("validateDbConfig", () => {
|
||||
test("expect.rowCount 非法 operator 返回错误", () => {
|
||||
const result = validateDbConfig({
|
||||
defaults: {},
|
||||
targets: [{ db: { url: "sqlite://:memory:" }, expect: { rowCount: { foo: 1 } }, name: "test", type: "db" }],
|
||||
targets: [
|
||||
{ db: { url: "sqlite://:memory:" }, expect: { rowCount: { foo: 1 } }, id: "test", name: "test", type: "db" },
|
||||
],
|
||||
});
|
||||
const rowCountError = result.find((e) => e.path.includes("expect.rowCount"));
|
||||
expect(rowCountError).toBeDefined();
|
||||
@@ -72,7 +82,9 @@ describe("validateDbConfig", () => {
|
||||
test("expect.rows 不是数组返回错误", () => {
|
||||
const result = validateDbConfig({
|
||||
defaults: {},
|
||||
targets: [{ db: { url: "sqlite://:memory:" }, expect: { rows: "not-array" }, name: "test", type: "db" }],
|
||||
targets: [
|
||||
{ db: { url: "sqlite://:memory:" }, expect: { rows: "not-array" }, id: "test", name: "test", type: "db" },
|
||||
],
|
||||
});
|
||||
const rowsError = result.find((e) => e.path.includes("expect.rows"));
|
||||
expect(rowsError).toBeDefined();
|
||||
@@ -82,7 +94,9 @@ describe("validateDbConfig", () => {
|
||||
test("expect.rows 元素不是对象返回错误", () => {
|
||||
const result = validateDbConfig({
|
||||
defaults: {},
|
||||
targets: [{ db: { url: "sqlite://:memory:" }, expect: { rows: ["not-object"] }, name: "test", type: "db" }],
|
||||
targets: [
|
||||
{ db: { url: "sqlite://:memory:" }, expect: { rows: ["not-object"] }, id: "test", name: "test", type: "db" },
|
||||
],
|
||||
});
|
||||
const rowError = result.find((e) => e.path.includes("expect.rows[0]"));
|
||||
expect(rowError).toBeDefined();
|
||||
@@ -96,6 +110,7 @@ describe("validateDbConfig", () => {
|
||||
{
|
||||
db: { url: "sqlite://:memory:" },
|
||||
expect: { rows: [{ name: { match: "[invalid" } }] },
|
||||
id: "test",
|
||||
name: "test",
|
||||
type: "db",
|
||||
},
|
||||
@@ -109,7 +124,7 @@ describe("validateDbConfig", () => {
|
||||
test("expect 未知字段返回错误", () => {
|
||||
const result = validateDbConfig({
|
||||
defaults: {},
|
||||
targets: [{ db: { url: "sqlite://:memory:" }, expect: { status: [200] }, name: "test", type: "db" }],
|
||||
targets: [{ db: { url: "sqlite://:memory:" }, expect: { status: [200] }, id: "test", name: "test", type: "db" }],
|
||||
});
|
||||
const unknownError = result.find((e) => e.path.includes("expect.status"));
|
||||
expect(unknownError).toBeDefined();
|
||||
@@ -123,6 +138,7 @@ describe("validateDbConfig", () => {
|
||||
{
|
||||
db: { query: "SELECT 1", url: "sqlite://:memory:" },
|
||||
expect: { maxDurationMs: 5000, rowCount: { gte: 1 }, rows: [{ cnt: { gte: 1 } }] },
|
||||
id: "test",
|
||||
name: "test",
|
||||
type: "db",
|
||||
},
|
||||
@@ -134,7 +150,7 @@ describe("validateDbConfig", () => {
|
||||
test("忽略非 db 类型 target", () => {
|
||||
const result = validateDbConfig({
|
||||
defaults: {},
|
||||
targets: [{ name: "test", type: "http" }],
|
||||
targets: [{ id: "test", name: "test", type: "http" }],
|
||||
});
|
||||
expect(result).toHaveLength(0);
|
||||
});
|
||||
@@ -143,8 +159,8 @@ describe("validateDbConfig", () => {
|
||||
const result = validateDbConfig({
|
||||
defaults: {},
|
||||
targets: [
|
||||
{ db: { url: "sqlite://:memory:" }, name: "db1", type: "db" },
|
||||
{ db: { url: "" }, name: "db2", type: "db" },
|
||||
{ db: { url: "sqlite://:memory:" }, id: "db1", name: "db1", type: "db" },
|
||||
{ db: { url: "" }, id: "db2", name: "db2", type: "db" },
|
||||
],
|
||||
});
|
||||
expect(result.length).toBeGreaterThan(0);
|
||||
|
||||
Reference in New Issue
Block a user