forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-constraints.test.ts
More file actions
53 lines (45 loc) · 1.72 KB
/
Copy pathvalidate-constraints.test.ts
File metadata and controls
53 lines (45 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { describe, it, expect } from "vitest";
import fs from "fs";
import path from "path";
import yaml from "yaml";
import { validateManifestConstraints } from "../validate-constraints.js";
const CONSTRAINTS_PATH = path.resolve(
__dirname,
"..",
"..",
"shared",
"constraints.yaml",
);
const FIXTURES_DIR = path.resolve(__dirname, "fixtures");
function loadConstraints() {
return yaml.parse(fs.readFileSync(CONSTRAINTS_PATH, "utf-8"));
}
function loadFixture(name: string) {
return yaml.parse(fs.readFileSync(path.join(FIXTURES_DIR, name), "utf-8"));
}
describe("Constraint Validator", () => {
const constraints = loadConstraints();
it("passes a valid manifest", () => {
const manifest = loadFixture("valid-manifest.yaml");
const errors = validateManifestConstraints(manifest, constraints);
expect(errors).toEqual([]);
});
it("rejects a demo not allowed by declared generative_ui", () => {
const manifest = loadFixture("invalid-genui-manifest.yaml");
const errors = validateManifestConstraints(manifest, constraints);
expect(errors.length).toBeGreaterThan(0);
expect(errors[0]).toContain("tool-rendering");
expect(errors[0]).toContain("not allowed");
});
it("skips validation when generative_ui is missing", () => {
const manifest = loadFixture("missing-genui-manifest.yaml");
const errors = validateManifestConstraints(manifest, constraints);
expect(errors).toEqual([]);
});
it("rejects a demo ID not in any allowed list", () => {
const manifest = loadFixture("unknown-demo-manifest.yaml");
const errors = validateManifestConstraints(manifest, constraints);
expect(errors.length).toBeGreaterThan(0);
expect(errors[0]).toContain("nonexistent-feature");
});
});