-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathexamples-service-host-neutrality.test.js
More file actions
74 lines (63 loc) · 2.18 KB
/
examples-service-host-neutrality.test.js
File metadata and controls
74 lines (63 loc) · 2.18 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"use strict";
// This file keeps the importable examples clean.
// It checks that example flows do not ship with a bundled Service Host config node or a prewired host selection that people did not choose themselves.
const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
const test = require("node:test");
const examplesRoot = path.join(__dirname, "..", "examples");
const exampleFiles = listJsonFiles(examplesRoot);
const exampleFlows = exampleFiles.map((filePath) => {
const raw = fs.readFileSync(filePath, "utf8");
return {
relativePath: path.relative(path.join(__dirname, ".."), filePath),
raw,
nodes: JSON.parse(raw),
};
});
function listJsonFiles(directoryPath) {
return fs.readdirSync(directoryPath, { withFileTypes: true })
.flatMap((entry) => {
const entryPath = path.join(directoryPath, entry.name);
if (entry.isDirectory()) {
return listJsonFiles(entryPath);
}
return entry.name.endsWith(".json") ? [entryPath] : [];
})
.sort();
}
test("example flows do not bundle a Service Host config node", () => {
for (const exampleFlow of exampleFlows) {
const bundledServiceHosts = exampleFlow.nodes.filter(
(node) => node.type === "Service Host"
);
assert.equal(
bundledServiceHosts.length,
0,
`${exampleFlow.relativePath} should not include a bundled Service Host node`
);
}
});
test("example OpenAI API nodes are left unconfigured for Service Host selection", () => {
for (const exampleFlow of exampleFlows) {
const openaiNodes = exampleFlow.nodes.filter(
(node) => node.type === "OpenAI API"
);
for (const openaiNode of openaiNodes) {
assert.equal(
openaiNode.service,
"",
`${exampleFlow.relativePath} should leave ${openaiNode.name || openaiNode.id} with an empty service selection`
);
}
}
});
test("example flows do not mention the old OpenAI Auth config-node name", () => {
for (const exampleFlow of exampleFlows) {
assert.doesNotMatch(
exampleFlow.raw,
/OpenAI Auth/,
`${exampleFlow.relativePath} should not mention the old OpenAI Auth config node`
);
}
});