@capybara-hq/testing 0.1.0-rc.3 → 0.1.0-rc.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/containers.d.ts +7 -2
- package/dist/containers.js +7 -3
- package/dist/dual-replica.d.ts +17 -1
- package/dist/dual-replica.js +52 -0
- package/dist/fake-channel.d.ts +51 -3
- package/dist/fake-channel.js +71 -3
- package/dist/fake-e2b.d.ts +34 -0
- package/dist/fake-e2b.js +95 -1
- package/dist/fake-git-server.d.ts +32 -4
- package/dist/fake-git-server.js +87 -19
- package/dist/fake-lark.d.ts +12 -1
- package/dist/fake-lark.js +63 -10
- package/dist/fake-oauth-server.d.ts +16 -2
- package/dist/fake-oauth-server.js +21 -1
- package/dist/fake-slack.d.ts +17 -1
- package/dist/fake-slack.js +98 -0
- package/dist/fake-telegram.d.ts +173 -0
- package/dist/fake-telegram.js +632 -0
- package/dist/fixtures.d.ts +25 -7
- package/dist/fixtures.js +35 -7
- package/dist/index.d.ts +12 -8
- package/dist/index.js +8 -4
- package/dist/kernel-helpers.d.ts +16 -4
- package/dist/kernel-helpers.js +39 -4
- package/dist/media-samples.d.ts +2 -0
- package/dist/media-samples.js +2 -0
- package/dist/model-conformance.d.ts +15 -10
- package/dist/model-conformance.js +87 -14
- package/dist/push-conformance.d.ts +31 -0
- package/dist/push-conformance.js +160 -0
- package/dist/replica-runner.js +2 -0
- package/dist/sandbox-native-conformance.d.ts +31 -0
- package/dist/sandbox-native-conformance.js +153 -0
- package/dist/sandbox-permission-conformance.d.ts +307 -0
- package/dist/sandbox-permission-conformance.js +1475 -0
- package/fixtures/extensions/fake-client/.capybara-plugin/plugin.json +11 -0
- package/fixtures/extensions/fake-client/client/styles/fake.css +11 -0
- package/fixtures/extensions/fake-client/package.json +12 -0
- package/fixtures/extensions/fake-client/src/client.tsx +51 -0
- package/fixtures/extensions/fake-client/src/index.ts +43 -0
- package/fixtures/extensions/fake-client/themes/fake.json +11 -0
- package/fixtures/extensions/fake-client-broken/.capybara-plugin/plugin.json +7 -0
- package/fixtures/extensions/fake-client-broken/package.json +12 -0
- package/fixtures/extensions/fake-client-broken/src/client.tsx +22 -0
- package/fixtures/extensions/fake-client-broken/src/index.ts +27 -0
- package/fixtures/extensions/fake-config-form/.capybara-plugin/plugin.json +11 -0
- package/fixtures/extensions/fake-config-form/package.json +12 -0
- package/fixtures/extensions/fake-config-form/src/index.ts +205 -0
- package/fixtures/extensions/fake-connector/src/index.ts +41 -21
- package/fixtures/extensions/fake-context/.capybara-plugin/plugin.json +7 -0
- package/fixtures/extensions/fake-context/package.json +12 -0
- package/fixtures/extensions/fake-context/src/index.ts +81 -0
- package/fixtures/extensions/fake-dep-provider/src/index.ts +1 -1
- package/fixtures/extensions/fake-dep-requirer/src/index.ts +1 -1
- package/fixtures/extensions/fake-embed/src/index.ts +26 -26
- package/fixtures/extensions/fake-im/.capybara-plugin/plugin.json +7 -1
- package/fixtures/extensions/fake-im/guides/fake-im-app.md +32 -0
- package/fixtures/extensions/fake-im/guides/fake-im-app.zh.md +32 -0
- package/fixtures/extensions/fake-im/src/channel.ts +22 -1
- package/fixtures/extensions/fake-im/src/checks.ts +94 -0
- package/fixtures/extensions/fake-im/src/index.ts +45 -2
- package/fixtures/extensions/fake-lifecycle/.capybara-plugin/plugin.json +7 -0
- package/fixtures/extensions/fake-lifecycle/migrations/0001_init.sql +16 -0
- package/fixtures/extensions/fake-lifecycle/package.json +12 -0
- package/fixtures/extensions/fake-lifecycle/src/index.ts +72 -0
- package/fixtures/extensions/fake-openapi/src/index.ts +46 -34
- package/fixtures/extensions/fake-push/.capybara-plugin/plugin.json +13 -0
- package/fixtures/extensions/fake-push/guides/fake-push-key.md +6 -0
- package/fixtures/extensions/fake-push/guides/fake-push-key.zh.md +6 -0
- package/fixtures/extensions/fake-push/migrations/0001_sends.sql +9 -0
- package/fixtures/extensions/fake-push/package.json +12 -0
- package/fixtures/extensions/fake-push/src/check.ts +40 -0
- package/fixtures/extensions/fake-push/src/index.ts +48 -0
- package/fixtures/extensions/fake-push/src/push.ts +103 -0
- package/fixtures/extensions/fake-storage-user/src/index.ts +1 -1
- package/fixtures/extensions/fake-tools-ui/skills/fake-notes/SKILL.md +1 -1
- package/fixtures/extensions/fake-tools-ui/src/index.ts +62 -3
- package/fixtures/extensions/fake-web/.capybara-plugin/plugin.json +7 -0
- package/fixtures/extensions/fake-web/package.json +12 -0
- package/fixtures/extensions/fake-web/src/index.ts +22 -0
- package/fixtures/extensions/fake-web/src/web.ts +183 -0
- package/fixtures/extensions/fake-web-2/.capybara-plugin/plugin.json +7 -0
- package/fixtures/extensions/fake-web-2/package.json +12 -0
- package/fixtures/extensions/fake-web-2/src/index.ts +16 -0
- package/fixtures/extensions/fake-web-2/src/web.ts +183 -0
- package/fixtures/plugins/fake-theme/.capybara-plugin/plugin.json +7 -0
- package/fixtures/plugins/fake-theme/fonts/FakeSans.woff2 +1 -0
- package/fixtures/plugins/fake-theme/logo.svg +1 -0
- package/fixtures/plugins/fake-theme/package.json +8 -0
- package/fixtures/plugins/fake-theme/themes/neon-grid.json +13 -0
- package/fixtures/plugins/fake-theme/themes/paper.json +12 -0
- package/package.json +6 -5
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import {
|
|
2
|
+
secret,
|
|
3
|
+
type WebFetchPage,
|
|
4
|
+
type WebFetchProvider,
|
|
5
|
+
WebProviderError,
|
|
6
|
+
type WebProviderErrorKind,
|
|
7
|
+
type WebSearchProvider,
|
|
8
|
+
type WebSearchResult,
|
|
9
|
+
} from "@capybara-hq/plugin-sdk";
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
|
|
12
|
+
// fake-web/src/web.ts and fake-web-2/src/web.ts are byte-identical (a plugin imports only from its
|
|
13
|
+
// own directory); test/fixtures.test.ts of @capybara-hq/testing keeps them equal.
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Org config of the fake web providers: `configured()` is true iff `token` is set (and throws for
|
|
17
|
+
* the token `throw:configured`).
|
|
18
|
+
*/
|
|
19
|
+
export const FakeWebOrgConfig = z.object({ token: secret(z.string().min(1)).optional() });
|
|
20
|
+
|
|
21
|
+
/** One provider call, recorded on `globalThis.__fakeWeb` (in-process kernels only). */
|
|
22
|
+
export interface FakeWebCall {
|
|
23
|
+
provider: string;
|
|
24
|
+
op: "search" | "fetch";
|
|
25
|
+
/** The query (search) or the URL (fetch). */
|
|
26
|
+
input: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The probe tests read: every call of every fake web provider in this process. */
|
|
30
|
+
export function fakeWebProbe(): { calls: FakeWebCall[] } {
|
|
31
|
+
const g = globalThis as { __fakeWeb?: { calls: FakeWebCall[] } };
|
|
32
|
+
g.__fakeWeb ??= { calls: [] };
|
|
33
|
+
return g.__fakeWeb;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// capybara:allow-module-state a read-only constant list
|
|
37
|
+
const KINDS: readonly WebProviderErrorKind[] = [
|
|
38
|
+
"not_found",
|
|
39
|
+
"blocked",
|
|
40
|
+
"auth",
|
|
41
|
+
"rate_limited",
|
|
42
|
+
"unavailable",
|
|
43
|
+
"invalid",
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
/** True iff the token is set; the token `throw:configured` makes it throw. */
|
|
47
|
+
const configured = (orgConfig: unknown): boolean => {
|
|
48
|
+
const token = (orgConfig as { token?: unknown } | null)?.token;
|
|
49
|
+
if (token === "throw:configured") throw new Error("fake web: configured() failed");
|
|
50
|
+
return typeof token === "string" && token.length > 0;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** The script of a fetch: the decoded URL path (and query) after the first `/`. */
|
|
54
|
+
function fetchScript(url: string): string {
|
|
55
|
+
try {
|
|
56
|
+
const u = new URL(url);
|
|
57
|
+
return decodeURIComponent(u.pathname.slice(1)) + u.search;
|
|
58
|
+
} catch {
|
|
59
|
+
return "";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Rejects with the signal's reason once it aborts (`hang:`). */
|
|
64
|
+
function hang(signal: AbortSignal): Promise<never> {
|
|
65
|
+
return new Promise((_, reject) => {
|
|
66
|
+
if (signal.aborted) reject(signal.reason);
|
|
67
|
+
else signal.addEventListener("abort", () => reject(signal.reason), { once: true });
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The scripted failures shared by search and fetch; returns normally for other scripts. */
|
|
72
|
+
async function scriptedFailure(name: string, script: string, signal: AbortSignal): Promise<void> {
|
|
73
|
+
if (script.startsWith("error:")) {
|
|
74
|
+
const kind = script.slice("error:".length).split(/[\s/?]/)[0] as WebProviderErrorKind;
|
|
75
|
+
if (!KINDS.includes(kind)) throw new Error(`${name}: unknown scripted error kind ${kind}`);
|
|
76
|
+
throw new WebProviderError(`${name}: scripted ${kind} failure`, { kind });
|
|
77
|
+
}
|
|
78
|
+
if (script.startsWith("throw:")) {
|
|
79
|
+
throw new Error(`${name} internal failure: ${script.slice("throw:".length)}`);
|
|
80
|
+
}
|
|
81
|
+
if (script.startsWith("hang:")) await hang(signal);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The two providers of a fake web extension named `name`. Behavior is scripted by a prefix of the
|
|
86
|
+
* search `query`, or of the fetched URL's path after the first `/` (e.g.
|
|
87
|
+
* `https://example.com/redirect:https://other.com/x`):
|
|
88
|
+
* - `error:<kind>`: throws `WebProviderError` of that kind;
|
|
89
|
+
* - `throw:<text>`: throws a plain `Error` whose message names the provider and carries `<text>`;
|
|
90
|
+
* - `hang:`: waits until the signal aborts, then rejects with its reason;
|
|
91
|
+
* - `redirect:<url>` (fetch): the page's `finalUrl` is `<url>`;
|
|
92
|
+
* - `redirect-long:<n>` (fetch): the page's `finalUrl` is `https://example.com/` followed by `n`
|
|
93
|
+
* characters;
|
|
94
|
+
* - `junk:` (search): unusable results (relative URL, `javascript:`, `ftp:`, empty title) plus one
|
|
95
|
+
* usable result and a second result with its URL; `junk:all`: only the four unusable ones;
|
|
96
|
+
* - `idn:` (search): one result on the IDN host `bücher.example` (its URL parses to the punycode
|
|
97
|
+
* host `xn--bcher-kva.example`) and one on example.org;
|
|
98
|
+
* - `empty:`: no results (search) / an empty `markdown` (fetch);
|
|
99
|
+
* - `big:<n>`: `n` results, ignoring `maxResults` (search) / `n` characters of markdown (fetch).
|
|
100
|
+
* Anything else: three results on docs.example.com, example.org and www.example.net (search) or
|
|
101
|
+
* a short page (fetch). Every title, snippet and page names the provider.
|
|
102
|
+
*/
|
|
103
|
+
export function makeFakeWeb(name: string): { search: WebSearchProvider; fetch: WebFetchProvider } {
|
|
104
|
+
const search: WebSearchProvider = {
|
|
105
|
+
configured,
|
|
106
|
+
async search({ query, signal }) {
|
|
107
|
+
fakeWebProbe().calls.push({ provider: name, op: "search", input: query });
|
|
108
|
+
await scriptedFailure(name, query, signal);
|
|
109
|
+
if (query.startsWith("empty:")) return { results: [] };
|
|
110
|
+
if (query.startsWith("idn:")) {
|
|
111
|
+
return {
|
|
112
|
+
results: [
|
|
113
|
+
{ title: `${name} idn`, url: `https://bücher.example/${name}/1` },
|
|
114
|
+
{ title: `${name} other`, url: `https://example.org/${name}/2` },
|
|
115
|
+
],
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
if (query.startsWith("junk:")) {
|
|
119
|
+
const bad: WebSearchResult[] = [
|
|
120
|
+
{ title: `${name} relative`, url: "/relative/path" },
|
|
121
|
+
{ title: `${name} script`, url: "javascript:alert(1)" },
|
|
122
|
+
{ title: `${name} ftp`, url: "ftp://example.com/file" },
|
|
123
|
+
{ title: "", url: "https://example.com/untitled" },
|
|
124
|
+
];
|
|
125
|
+
if (query.startsWith("junk:all")) return { results: bad };
|
|
126
|
+
return {
|
|
127
|
+
results: [
|
|
128
|
+
...bad,
|
|
129
|
+
{ title: `${name} first`, url: "https://example.com/dup" },
|
|
130
|
+
{ title: `${name} again`, url: "https://example.com/dup" },
|
|
131
|
+
],
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
if (query.startsWith("big:")) {
|
|
135
|
+
const n = Number.parseInt(query.slice("big:".length), 10) || 0;
|
|
136
|
+
return {
|
|
137
|
+
results: Array.from({ length: n }, (_, i) => ({
|
|
138
|
+
title: `${name} result ${i + 1}`,
|
|
139
|
+
url: `https://example.com/${name}/${i + 1}`,
|
|
140
|
+
snippet: `${name} snippet ${i + 1} for ${query}`,
|
|
141
|
+
})),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
const hosts = ["docs.example.com", "example.org", "www.example.net"];
|
|
145
|
+
const results: WebSearchResult[] = hosts.map((h, i) => ({
|
|
146
|
+
title: `${name} result ${i + 1}`,
|
|
147
|
+
url: `https://${h}/${name}/${i + 1}`,
|
|
148
|
+
snippet: `${name} snippet ${i + 1} for ${query}`,
|
|
149
|
+
publishedAt: "2026-11-01",
|
|
150
|
+
}));
|
|
151
|
+
return { results };
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
const fetch: WebFetchProvider = {
|
|
155
|
+
configured,
|
|
156
|
+
async fetch({ url, signal }): Promise<WebFetchPage> {
|
|
157
|
+
fakeWebProbe().calls.push({ provider: name, op: "fetch", input: url });
|
|
158
|
+
const script = fetchScript(url);
|
|
159
|
+
await scriptedFailure(name, script, signal);
|
|
160
|
+
if (script.startsWith("redirect-long:")) {
|
|
161
|
+
const n = Number.parseInt(script.slice("redirect-long:".length), 10) || 0;
|
|
162
|
+
const finalUrl = `https://example.com/${"a".repeat(n)}`;
|
|
163
|
+
return { finalUrl, title: `${name} redirect`, markdown: "Moved." };
|
|
164
|
+
}
|
|
165
|
+
if (script.startsWith("redirect:")) {
|
|
166
|
+
const finalUrl = script.slice("redirect:".length);
|
|
167
|
+
return { finalUrl, title: `${name} redirect`, markdown: `Moved to ${finalUrl}.` };
|
|
168
|
+
}
|
|
169
|
+
if (script.startsWith("empty:")) return { finalUrl: url, markdown: "" };
|
|
170
|
+
if (script.startsWith("big:")) {
|
|
171
|
+
const n = Number.parseInt(script.slice("big:".length), 10) || 0;
|
|
172
|
+
return { finalUrl: url, title: `${name} big page`, markdown: "x".repeat(n) };
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
finalUrl: url,
|
|
176
|
+
title: `${name} page`,
|
|
177
|
+
markdown: `# Page from ${name}\n\nFetched ${url} with ${name}.`,
|
|
178
|
+
contentType: "text/html",
|
|
179
|
+
};
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
return { search, fetch };
|
|
183
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capybara-hq/test-plugin-fake-web-2",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Test fake: a scripted web search and web fetch provider (web-search@1, web-fetch@1)",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.0",
|
|
10
|
+
"zod": "^4.6.7"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineExtension } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { FakeWebOrgConfig, makeFakeWeb } from "./web.js";
|
|
3
|
+
|
|
4
|
+
/** Test fake: `fake-web` under another name (a second provider of `web-search@1` / `web-fetch@1`). */
|
|
5
|
+
export default defineExtension({
|
|
6
|
+
name: "fake-web-2",
|
|
7
|
+
version: "0.1.0",
|
|
8
|
+
sdk: "^0.1.0-rc.0",
|
|
9
|
+
provides: ["web-search@1", "web-fetch@1"],
|
|
10
|
+
config: { org: FakeWebOrgConfig },
|
|
11
|
+
setup(ctx) {
|
|
12
|
+
const { search, fetch } = makeFakeWeb("fake-web-2");
|
|
13
|
+
ctx.provide("web-search@1", search);
|
|
14
|
+
ctx.provide("web-fetch@1", fetch);
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import {
|
|
2
|
+
secret,
|
|
3
|
+
type WebFetchPage,
|
|
4
|
+
type WebFetchProvider,
|
|
5
|
+
WebProviderError,
|
|
6
|
+
type WebProviderErrorKind,
|
|
7
|
+
type WebSearchProvider,
|
|
8
|
+
type WebSearchResult,
|
|
9
|
+
} from "@capybara-hq/plugin-sdk";
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
|
|
12
|
+
// fake-web/src/web.ts and fake-web-2/src/web.ts are byte-identical (a plugin imports only from its
|
|
13
|
+
// own directory); test/fixtures.test.ts of @capybara-hq/testing keeps them equal.
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Org config of the fake web providers: `configured()` is true iff `token` is set (and throws for
|
|
17
|
+
* the token `throw:configured`).
|
|
18
|
+
*/
|
|
19
|
+
export const FakeWebOrgConfig = z.object({ token: secret(z.string().min(1)).optional() });
|
|
20
|
+
|
|
21
|
+
/** One provider call, recorded on `globalThis.__fakeWeb` (in-process kernels only). */
|
|
22
|
+
export interface FakeWebCall {
|
|
23
|
+
provider: string;
|
|
24
|
+
op: "search" | "fetch";
|
|
25
|
+
/** The query (search) or the URL (fetch). */
|
|
26
|
+
input: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The probe tests read: every call of every fake web provider in this process. */
|
|
30
|
+
export function fakeWebProbe(): { calls: FakeWebCall[] } {
|
|
31
|
+
const g = globalThis as { __fakeWeb?: { calls: FakeWebCall[] } };
|
|
32
|
+
g.__fakeWeb ??= { calls: [] };
|
|
33
|
+
return g.__fakeWeb;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// capybara:allow-module-state a read-only constant list
|
|
37
|
+
const KINDS: readonly WebProviderErrorKind[] = [
|
|
38
|
+
"not_found",
|
|
39
|
+
"blocked",
|
|
40
|
+
"auth",
|
|
41
|
+
"rate_limited",
|
|
42
|
+
"unavailable",
|
|
43
|
+
"invalid",
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
/** True iff the token is set; the token `throw:configured` makes it throw. */
|
|
47
|
+
const configured = (orgConfig: unknown): boolean => {
|
|
48
|
+
const token = (orgConfig as { token?: unknown } | null)?.token;
|
|
49
|
+
if (token === "throw:configured") throw new Error("fake web: configured() failed");
|
|
50
|
+
return typeof token === "string" && token.length > 0;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** The script of a fetch: the decoded URL path (and query) after the first `/`. */
|
|
54
|
+
function fetchScript(url: string): string {
|
|
55
|
+
try {
|
|
56
|
+
const u = new URL(url);
|
|
57
|
+
return decodeURIComponent(u.pathname.slice(1)) + u.search;
|
|
58
|
+
} catch {
|
|
59
|
+
return "";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Rejects with the signal's reason once it aborts (`hang:`). */
|
|
64
|
+
function hang(signal: AbortSignal): Promise<never> {
|
|
65
|
+
return new Promise((_, reject) => {
|
|
66
|
+
if (signal.aborted) reject(signal.reason);
|
|
67
|
+
else signal.addEventListener("abort", () => reject(signal.reason), { once: true });
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The scripted failures shared by search and fetch; returns normally for other scripts. */
|
|
72
|
+
async function scriptedFailure(name: string, script: string, signal: AbortSignal): Promise<void> {
|
|
73
|
+
if (script.startsWith("error:")) {
|
|
74
|
+
const kind = script.slice("error:".length).split(/[\s/?]/)[0] as WebProviderErrorKind;
|
|
75
|
+
if (!KINDS.includes(kind)) throw new Error(`${name}: unknown scripted error kind ${kind}`);
|
|
76
|
+
throw new WebProviderError(`${name}: scripted ${kind} failure`, { kind });
|
|
77
|
+
}
|
|
78
|
+
if (script.startsWith("throw:")) {
|
|
79
|
+
throw new Error(`${name} internal failure: ${script.slice("throw:".length)}`);
|
|
80
|
+
}
|
|
81
|
+
if (script.startsWith("hang:")) await hang(signal);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The two providers of a fake web extension named `name`. Behavior is scripted by a prefix of the
|
|
86
|
+
* search `query`, or of the fetched URL's path after the first `/` (e.g.
|
|
87
|
+
* `https://example.com/redirect:https://other.com/x`):
|
|
88
|
+
* - `error:<kind>`: throws `WebProviderError` of that kind;
|
|
89
|
+
* - `throw:<text>`: throws a plain `Error` whose message names the provider and carries `<text>`;
|
|
90
|
+
* - `hang:`: waits until the signal aborts, then rejects with its reason;
|
|
91
|
+
* - `redirect:<url>` (fetch): the page's `finalUrl` is `<url>`;
|
|
92
|
+
* - `redirect-long:<n>` (fetch): the page's `finalUrl` is `https://example.com/` followed by `n`
|
|
93
|
+
* characters;
|
|
94
|
+
* - `junk:` (search): unusable results (relative URL, `javascript:`, `ftp:`, empty title) plus one
|
|
95
|
+
* usable result and a second result with its URL; `junk:all`: only the four unusable ones;
|
|
96
|
+
* - `idn:` (search): one result on the IDN host `bücher.example` (its URL parses to the punycode
|
|
97
|
+
* host `xn--bcher-kva.example`) and one on example.org;
|
|
98
|
+
* - `empty:`: no results (search) / an empty `markdown` (fetch);
|
|
99
|
+
* - `big:<n>`: `n` results, ignoring `maxResults` (search) / `n` characters of markdown (fetch).
|
|
100
|
+
* Anything else: three results on docs.example.com, example.org and www.example.net (search) or
|
|
101
|
+
* a short page (fetch). Every title, snippet and page names the provider.
|
|
102
|
+
*/
|
|
103
|
+
export function makeFakeWeb(name: string): { search: WebSearchProvider; fetch: WebFetchProvider } {
|
|
104
|
+
const search: WebSearchProvider = {
|
|
105
|
+
configured,
|
|
106
|
+
async search({ query, signal }) {
|
|
107
|
+
fakeWebProbe().calls.push({ provider: name, op: "search", input: query });
|
|
108
|
+
await scriptedFailure(name, query, signal);
|
|
109
|
+
if (query.startsWith("empty:")) return { results: [] };
|
|
110
|
+
if (query.startsWith("idn:")) {
|
|
111
|
+
return {
|
|
112
|
+
results: [
|
|
113
|
+
{ title: `${name} idn`, url: `https://bücher.example/${name}/1` },
|
|
114
|
+
{ title: `${name} other`, url: `https://example.org/${name}/2` },
|
|
115
|
+
],
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
if (query.startsWith("junk:")) {
|
|
119
|
+
const bad: WebSearchResult[] = [
|
|
120
|
+
{ title: `${name} relative`, url: "/relative/path" },
|
|
121
|
+
{ title: `${name} script`, url: "javascript:alert(1)" },
|
|
122
|
+
{ title: `${name} ftp`, url: "ftp://example.com/file" },
|
|
123
|
+
{ title: "", url: "https://example.com/untitled" },
|
|
124
|
+
];
|
|
125
|
+
if (query.startsWith("junk:all")) return { results: bad };
|
|
126
|
+
return {
|
|
127
|
+
results: [
|
|
128
|
+
...bad,
|
|
129
|
+
{ title: `${name} first`, url: "https://example.com/dup" },
|
|
130
|
+
{ title: `${name} again`, url: "https://example.com/dup" },
|
|
131
|
+
],
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
if (query.startsWith("big:")) {
|
|
135
|
+
const n = Number.parseInt(query.slice("big:".length), 10) || 0;
|
|
136
|
+
return {
|
|
137
|
+
results: Array.from({ length: n }, (_, i) => ({
|
|
138
|
+
title: `${name} result ${i + 1}`,
|
|
139
|
+
url: `https://example.com/${name}/${i + 1}`,
|
|
140
|
+
snippet: `${name} snippet ${i + 1} for ${query}`,
|
|
141
|
+
})),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
const hosts = ["docs.example.com", "example.org", "www.example.net"];
|
|
145
|
+
const results: WebSearchResult[] = hosts.map((h, i) => ({
|
|
146
|
+
title: `${name} result ${i + 1}`,
|
|
147
|
+
url: `https://${h}/${name}/${i + 1}`,
|
|
148
|
+
snippet: `${name} snippet ${i + 1} for ${query}`,
|
|
149
|
+
publishedAt: "2026-11-01",
|
|
150
|
+
}));
|
|
151
|
+
return { results };
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
const fetch: WebFetchProvider = {
|
|
155
|
+
configured,
|
|
156
|
+
async fetch({ url, signal }): Promise<WebFetchPage> {
|
|
157
|
+
fakeWebProbe().calls.push({ provider: name, op: "fetch", input: url });
|
|
158
|
+
const script = fetchScript(url);
|
|
159
|
+
await scriptedFailure(name, script, signal);
|
|
160
|
+
if (script.startsWith("redirect-long:")) {
|
|
161
|
+
const n = Number.parseInt(script.slice("redirect-long:".length), 10) || 0;
|
|
162
|
+
const finalUrl = `https://example.com/${"a".repeat(n)}`;
|
|
163
|
+
return { finalUrl, title: `${name} redirect`, markdown: "Moved." };
|
|
164
|
+
}
|
|
165
|
+
if (script.startsWith("redirect:")) {
|
|
166
|
+
const finalUrl = script.slice("redirect:".length);
|
|
167
|
+
return { finalUrl, title: `${name} redirect`, markdown: `Moved to ${finalUrl}.` };
|
|
168
|
+
}
|
|
169
|
+
if (script.startsWith("empty:")) return { finalUrl: url, markdown: "" };
|
|
170
|
+
if (script.startsWith("big:")) {
|
|
171
|
+
const n = Number.parseInt(script.slice("big:".length), 10) || 0;
|
|
172
|
+
return { finalUrl: url, title: `${name} big page`, markdown: "x".repeat(n) };
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
finalUrl: url,
|
|
176
|
+
title: `${name} page`,
|
|
177
|
+
markdown: `# Page from ${name}\n\nFetched ${url} with ${name}.`,
|
|
178
|
+
contentType: "text/html",
|
|
179
|
+
};
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
return { search, fetch };
|
|
183
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
wOF2
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><title>Fake theme</title><path d="M0 0h10v10z" fill="#FCE300"/></svg>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": { "en": "Neon Grid", "zh": "霓虹网格" },
|
|
3
|
+
"schemes": {
|
|
4
|
+
"dark": {
|
|
5
|
+
"color": { "bg": "#05070D", "panel": "#0A0E18", "accent": "#FCE300", "on-accent": "#141200" },
|
|
6
|
+
"radius": { "sm": 0, "md": 2 }
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"fonts": [
|
|
10
|
+
{ "family": "FakeSans", "file": "./fonts/FakeSans.woff2", "weight": 400, "role": "prose" }
|
|
11
|
+
],
|
|
12
|
+
"logo": { "mark": "./logo.svg", "wordmark": "NEON GRID" }
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/testing",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.31",
|
|
4
4
|
"description": "Test helpers for Capybara: test containers, dual-replica harness and fake third-party servers",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -47,17 +47,18 @@
|
|
|
47
47
|
"tsx": "^4.23.15",
|
|
48
48
|
"ws": "^8.22.0",
|
|
49
49
|
"zod": "^4.6.7",
|
|
50
|
-
"@capybara-hq/kernel": "^0.1.0-rc.
|
|
50
|
+
"@capybara-hq/kernel": "^0.1.0-rc.63"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/pg": "^8.23.1",
|
|
54
54
|
"@types/ws": "^8.18.2",
|
|
55
|
-
"@capybara-hq/plugin-
|
|
55
|
+
"@capybara-hq/plugin-client": "^0.1.0-rc.7",
|
|
56
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.48"
|
|
56
57
|
},
|
|
57
58
|
"peerDependencies": {
|
|
58
59
|
"vitest": "^5.0.5",
|
|
59
|
-
"@capybara-hq/plugin-
|
|
60
|
-
"@capybara-hq/plugin-
|
|
60
|
+
"@capybara-hq/plugin-tools": "^0.1.0-rc.18",
|
|
61
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.48"
|
|
61
62
|
},
|
|
62
63
|
"peerDependenciesMeta": {
|
|
63
64
|
"@capybara-hq/plugin-tools": {
|