forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify-shell-docs.test.ts
More file actions
228 lines (214 loc) · 7.03 KB
/
Copy pathverify-shell-docs.test.ts
File metadata and controls
228 lines (214 loc) · 7.03 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import { describe, it, expect } from "vitest";
import { runBuildCheck } from "./verify-shell-docs.js";
import { checkInlineDemoRefs } from "./verify-shell-docs.js";
import { checkSnippetRegions } from "./verify-shell-docs.js";
import { checkInternalLinks } from "./verify-shell-docs.js";
import { checkImportPaths } from "./verify-shell-docs.js";
import { checkComponentImports } from "./verify-shell-docs.js";
describe("runBuildCheck", () => {
it("returns a result with name, status, and messages", () => {
const result = runBuildCheck({ skipExecution: true });
expect(result.name).toBe("nx-build-shell-docs");
expect(["pass", "fail", "skipped"]).toContain(result.status);
expect(Array.isArray(result.messages)).toBe(true);
});
});
describe("checkInlineDemoRefs", () => {
it("fails when a referenced demo id is not in registry", () => {
const fakeRegistry = {
integrations: [
{
slug: "langgraph-python",
demos: [{ id: "agentic-chat" }],
},
],
};
const pages = [
{
path: "frontend-tools.mdx",
body: '<InlineDemo demo="not-a-real-demo" />',
},
];
const result = checkInlineDemoRefs({ pages, registry: fakeRegistry });
expect(result.status).toBe("fail");
expect(result.messages.join(" ")).toContain("not-a-real-demo");
});
it("passes when every referenced demo id is in the registry", () => {
const fakeRegistry = {
integrations: [
{
slug: "langgraph-python",
demos: [{ id: "agentic-chat" }, { id: "frontend-tools" }],
},
],
};
const pages = [
{
path: "frontend-tools.mdx",
body: '<InlineDemo demo="frontend-tools" />',
},
];
const result = checkInlineDemoRefs({ pages, registry: fakeRegistry });
expect(result.status).toBe("pass");
});
it("ignores InlineDemo refs inside fenced code blocks", () => {
// A docs page that *shows* `<InlineDemo demo="some-example" />` in a
// code sample (for users to copy) must not register that as a real
// demo reference — otherwise the validator false-positives on every
// tutorial that documents how to use InlineDemo.
const fakeRegistry = {
integrations: [
{ slug: "langgraph-python", demos: [{ id: "agentic-chat" }] },
],
};
const pages = [
{
path: "tutorial.mdx",
body:
"Here is how to embed a demo:\n\n```mdx\n" +
'<InlineDemo demo="not-a-real-demo" />\n' +
"```\n",
},
];
const result = checkInlineDemoRefs({ pages, registry: fakeRegistry });
expect(result.status).toBe("pass");
});
});
describe("checkSnippetRegions", () => {
it("fails when a referenced region is not in any demo's regions map", () => {
const demoContent = {
demos: {
"langgraph-python::frontend-tools": {
regions: {
"frontend-tool-registration": {
file: "src/page.tsx",
startLine: 10,
endLine: 20,
code: "...",
language: "tsx",
},
},
files: [],
},
},
};
const pages = [
{
path: "frontend-tools.mdx",
body: '<Snippet region="nope" />',
},
];
const result = checkSnippetRegions({ pages, demoContent });
expect(result.status).toBe("fail");
expect(result.messages.join(" ")).toContain("nope");
});
it("passes when every region is present in at least one demo", () => {
const demoContent = {
demos: {
"langgraph-python::frontend-tools": {
regions: {
"frontend-tool-registration": {
file: "src/page.tsx",
startLine: 10,
endLine: 20,
code: "...",
language: "tsx",
},
},
files: [],
},
},
};
const pages = [
{
path: "frontend-tools.mdx",
body: '<Snippet region="frontend-tool-registration" />',
},
];
const result = checkSnippetRegions({ pages, demoContent });
expect(result.status).toBe("pass");
});
});
describe("checkInternalLinks", () => {
it("fails when an internal link does not resolve to a known page", () => {
const pages = [{ path: "a.mdx", body: "[link](/does-not-exist)" }];
const knownRoutes = new Set(["/a", "/b"]);
const result = checkInternalLinks({ pages, knownRoutes });
expect(result.status).toBe("fail");
expect(result.messages.join(" ")).toContain("/does-not-exist");
});
it("ignores external links", () => {
const pages = [{ path: "a.mdx", body: "[link](https://example.com)" }];
const knownRoutes = new Set<string>();
const result = checkInternalLinks({ pages, knownRoutes });
expect(result.status).toBe("pass");
});
it("strips fragments and queries before resolution", () => {
const pages = [{ path: "a.mdx", body: "[link](/a#section?q=1)" }];
const knownRoutes = new Set(["/a"]);
const result = checkInternalLinks({ pages, knownRoutes });
expect(result.status).toBe("pass");
});
});
describe("checkImportPaths", () => {
it("fails when an @/snippets/... path does not exist", () => {
const pages = [
{
path: "a.mdx",
body: 'import X from "@/snippets/does-not-exist.mdx";',
},
];
const existsOnDisk = (_p: string) => false;
const result = checkImportPaths({ pages, existsOnDisk });
expect(result.status).toBe("fail");
expect(result.messages.join(" ")).toContain(
"@/snippets/does-not-exist.mdx",
);
});
it("passes when all paths resolve", () => {
const pages = [
{
path: "a.mdx",
body: 'import X from "@/snippets/exists.mdx";',
},
];
const existsOnDisk = (_p: string) => true;
const result = checkImportPaths({ pages, existsOnDisk });
expect(result.status).toBe("pass");
});
});
describe("checkComponentImports", () => {
it("fails when a snippet component is used with props but no import", () => {
const pages = [
{
path: "agno/prebuilt-components.mdx",
body: '<PrebuiltComponents components={props.components} framework="agno" />',
},
];
const result = checkComponentImports({ pages });
expect(result.status).toBe("fail");
expect(result.messages.join(" ")).toContain("PrebuiltComponents");
});
it("passes when a snippet component has an explicit import", () => {
const pages = [
{
path: "agno/prebuilt-components.mdx",
body:
'import PrebuiltComponents from "@/snippets/shared/basics/prebuilt-components.mdx";\n\n' +
'<PrebuiltComponents components={props.components} framework="agno" />',
},
];
const result = checkComponentImports({ pages });
expect(result.status).toBe("pass");
});
it("passes when a bare component is used without props or import", () => {
const pages = [
{
path: "some-page.mdx",
body: "<PrebuiltComponents />",
},
];
const result = checkComponentImports({ pages });
expect(result.status).toBe("pass");
});
});