@capybara-hq/testing 0.1.0-rc.2 → 0.1.0-rc.21
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 +11 -2
- package/dist/dual-replica.js +48 -0
- package/dist/fake-channel.d.ts +31 -2
- package/dist/fake-channel.js +29 -2
- 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-oauth-server.d.ts +16 -2
- package/dist/fake-oauth-server.js +21 -1
- package/dist/fake-telegram.d.ts +165 -0
- package/dist/fake-telegram.js +569 -0
- package/dist/fixtures.d.ts +21 -4
- package/dist/fixtures.js +30 -4
- package/dist/index.d.ts +8 -5
- package/dist/index.js +6 -3
- package/dist/kernel-helpers.d.ts +48 -16
- package/dist/kernel-helpers.js +73 -13
- package/dist/model-conformance.d.ts +11 -10
- package/dist/model-conformance.js +38 -14
- package/dist/replica-runner.js +16 -8
- package/dist/sandbox-native-conformance.d.ts +31 -0
- package/dist/sandbox-native-conformance.js +153 -0
- package/dist/sandbox-permission-conformance.d.ts +60 -0
- package/dist/sandbox-permission-conformance.js +486 -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-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 +3 -1
- package/fixtures/extensions/fake-im/src/checks.ts +94 -0
- package/fixtures/extensions/fake-im/src/index.ts +36 -1
- 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-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,153 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { posix } from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* Checks ordinary native API compatibility in a fixture-owned temporary root. Each invocation
|
|
5
|
+
* gets a fresh operation. Passing does not establish OS enforcement or permission capabilities.
|
|
6
|
+
* The fixture owns setup and cleanup; no official plugin, database or network service is used.
|
|
7
|
+
*/
|
|
8
|
+
export async function runSandboxNativeConformance(fixture) {
|
|
9
|
+
const path = (name) => posix.join(fixture.root, name);
|
|
10
|
+
const signal = new AbortController().signal;
|
|
11
|
+
const fresh = async () => {
|
|
12
|
+
const operation = await fixture.operation();
|
|
13
|
+
assert(operation.list && operation.scan, "Native conformance requires list and scan");
|
|
14
|
+
return operation;
|
|
15
|
+
};
|
|
16
|
+
const read = async (name, maxBytes) => (await fresh()).readFile(path(name), { maxBytes, signal });
|
|
17
|
+
const stat = async (name) => (await fresh()).stat(path(name), signal);
|
|
18
|
+
const write = async (name, data) => (await fresh()).writeFile(path(name), data, signal);
|
|
19
|
+
const list = async (name, limit) => (await fresh()).list(path(name), { limit, signal });
|
|
20
|
+
const scan = async (name) => (await fresh()).scan(path(name), { signal });
|
|
21
|
+
const directory = (name) => ({ path: path(name), kind: "directory" });
|
|
22
|
+
const file = (name) => ({
|
|
23
|
+
path: path(name),
|
|
24
|
+
kind: "file",
|
|
25
|
+
data: new Uint8Array(),
|
|
26
|
+
});
|
|
27
|
+
const link = (name, target) => ({
|
|
28
|
+
path: path(name),
|
|
29
|
+
kind: "symlink",
|
|
30
|
+
target: path(target),
|
|
31
|
+
});
|
|
32
|
+
const candidates = (names) => names.map((name) => ({
|
|
33
|
+
path: path(name),
|
|
34
|
+
suggestedName: posix.basename(name),
|
|
35
|
+
}));
|
|
36
|
+
try {
|
|
37
|
+
assert.equal(await stat("missing"), null, "missing stat must return null");
|
|
38
|
+
assert.equal(await read("missing", 10), null, "missing read must return null");
|
|
39
|
+
assert.equal(await list("missing", 10), null, "missing list must return null");
|
|
40
|
+
assert.deepEqual(await scan("missing"), [], "missing scan must be empty");
|
|
41
|
+
await fixture.seed([directory("empty")]);
|
|
42
|
+
assert.equal((await stat("empty"))?.isDir, true);
|
|
43
|
+
assert.equal(await read("empty", 10), null, "directory read must return null");
|
|
44
|
+
assert.deepEqual(await list("empty", 0), { entries: [], truncated: false });
|
|
45
|
+
const bytes = new Uint8Array([0, 255, 128, 10, 65, 0]);
|
|
46
|
+
await write("parents/nested/binary", bytes);
|
|
47
|
+
assert.deepEqual(await stat("parents/nested/binary"), { size: 6, isDir: false });
|
|
48
|
+
assert.deepEqual(await read("parents/nested/binary", 6), { data: bytes, truncated: false });
|
|
49
|
+
assert.deepEqual(await read("parents/nested/binary", 100), { data: bytes, truncated: false });
|
|
50
|
+
assert.deepEqual(await read("parents/nested/binary", 3), {
|
|
51
|
+
data: new Uint8Array([0, 255, 128]),
|
|
52
|
+
truncated: true,
|
|
53
|
+
});
|
|
54
|
+
assert.deepEqual(await read("parents/nested/binary", 0), {
|
|
55
|
+
data: new Uint8Array(),
|
|
56
|
+
truncated: true,
|
|
57
|
+
});
|
|
58
|
+
await write("parents/nested/binary", new Uint8Array());
|
|
59
|
+
assert.deepEqual(await read("parents/nested/binary", 0), {
|
|
60
|
+
data: new Uint8Array(),
|
|
61
|
+
truncated: false,
|
|
62
|
+
});
|
|
63
|
+
assert.deepEqual(await stat("parents/nested/binary"), { size: 0, isDir: false });
|
|
64
|
+
assert.equal(await stat("parents/nested/binary/missing"), null);
|
|
65
|
+
assert.equal(await read("parents/nested/binary/missing", 10), null);
|
|
66
|
+
assert.equal(await list("parents/nested/binary/missing", 10), null);
|
|
67
|
+
assert.deepEqual(await scan("parents/nested/binary/missing"), []);
|
|
68
|
+
await assert.rejects(() => list("parents/nested/binary", 5));
|
|
69
|
+
await assert.rejects(() => scan("parents/nested/binary"));
|
|
70
|
+
await fixture.seed([
|
|
71
|
+
directory("listing/B"),
|
|
72
|
+
file("listing/a"),
|
|
73
|
+
file("listing/\u{1f600}"),
|
|
74
|
+
file("listing/\ue000"),
|
|
75
|
+
link("listing/alias", "listing/B"),
|
|
76
|
+
link("listing/dangling", "listing/missing"),
|
|
77
|
+
link("file-link", "listing/a"),
|
|
78
|
+
]);
|
|
79
|
+
assert.deepEqual(await list("listing", 0), { entries: [], truncated: true });
|
|
80
|
+
assert.deepEqual(await list("listing", 2), {
|
|
81
|
+
entries: [
|
|
82
|
+
{ name: "B", isDir: true },
|
|
83
|
+
{ name: "a", isDir: false },
|
|
84
|
+
],
|
|
85
|
+
truncated: true,
|
|
86
|
+
});
|
|
87
|
+
assert.deepEqual(await list("listing", 6), {
|
|
88
|
+
entries: [
|
|
89
|
+
{ name: "B", isDir: true },
|
|
90
|
+
{ name: "a", isDir: false },
|
|
91
|
+
{ name: "alias", isDir: true },
|
|
92
|
+
{ name: "dangling", isDir: false },
|
|
93
|
+
{ name: "\u{1f600}", isDir: false },
|
|
94
|
+
{ name: "\ue000", isDir: false },
|
|
95
|
+
],
|
|
96
|
+
truncated: false,
|
|
97
|
+
});
|
|
98
|
+
await write("file-link", bytes);
|
|
99
|
+
assert.deepEqual(await read("listing/a", 6), { data: bytes, truncated: false });
|
|
100
|
+
assert.deepEqual(await stat("file-link"), { size: 6, isDir: false });
|
|
101
|
+
assert.deepEqual(await list("listing/alias", 1), { entries: [], truncated: false });
|
|
102
|
+
assert.equal(await read("listing/dangling", 10), null);
|
|
103
|
+
await assert.rejects(() => write("listing/dangling", bytes));
|
|
104
|
+
assert.equal(await stat("listing/missing"), null, "dangling writes must not create a target");
|
|
105
|
+
await fixture.seed([file("percent/a%2f%ZZ/AGENTS.md"), file("percent/a%5c%/AGENTS.md")]);
|
|
106
|
+
assert.deepEqual(await scan("percent"), candidates(["percent/a%2f%ZZ", "percent/a%5c%"]));
|
|
107
|
+
const longName = "x".repeat(65);
|
|
108
|
+
await fixture.seed([
|
|
109
|
+
file("scan/AGENTS.md"),
|
|
110
|
+
file("scan/a/.git"),
|
|
111
|
+
file("scan/a/deep/AGENTS.md"),
|
|
112
|
+
file("scan/a/deep/too-deep/.git"),
|
|
113
|
+
directory("scan/false-hit/AGENTS.md"),
|
|
114
|
+
file("scan/.hidden/.git"),
|
|
115
|
+
file("scan/node_modules/.git"),
|
|
116
|
+
file("scan/Library/.git"),
|
|
117
|
+
file("scan/a/node_modules/.git"),
|
|
118
|
+
file("scan/a/Library/.git"),
|
|
119
|
+
file(`scan/${longName}/.git`),
|
|
120
|
+
file(`scan/${longName}/valid/.git`),
|
|
121
|
+
file("scan/ leading/.git"),
|
|
122
|
+
file("scan/ trailing /.git"),
|
|
123
|
+
file("scan/ leading/valid/.git"),
|
|
124
|
+
link("scan/link", "scan/a"),
|
|
125
|
+
]);
|
|
126
|
+
assert.deepEqual(await scan("scan"), candidates([
|
|
127
|
+
"scan",
|
|
128
|
+
"scan/ leading/valid",
|
|
129
|
+
"scan/a",
|
|
130
|
+
"scan/a/Library",
|
|
131
|
+
"scan/a/deep",
|
|
132
|
+
`scan/${longName}/valid`,
|
|
133
|
+
]), "scan must descend past hits and invalid names, and apply depth/skips exactly");
|
|
134
|
+
await fixture.seed([
|
|
135
|
+
...Array.from({ length: 51 }, (_, i) => file(`results/b${String(i).padStart(3, "0")}/.git`)),
|
|
136
|
+
file("results/a/deep/.git"),
|
|
137
|
+
]);
|
|
138
|
+
assert.deepEqual(await scan("results"), candidates([
|
|
139
|
+
"results/a/deep",
|
|
140
|
+
...Array.from({ length: 49 }, (_, i) => `results/b${String(i).padStart(3, "0")}`),
|
|
141
|
+
]), "scan truncates to 50 only after sorting all visited candidates");
|
|
142
|
+
await fixture.seed([
|
|
143
|
+
...Array.from({ length: 500 }, (_, i) => directory(`visits/d${String(i).padStart(3, "0")}`)),
|
|
144
|
+
file("visits/d498/.git"),
|
|
145
|
+
file("visits/d499/.git"),
|
|
146
|
+
file("visits/d000/deep/.git"),
|
|
147
|
+
]);
|
|
148
|
+
assert.deepEqual(await scan("visits"), candidates(["visits/d498"]), "base counts as visit one; breadth-first visit 500 includes d498, excludes d499 and depth two");
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
await fixture.dispose();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type PermissionProfile, type SandboxFileScope, type SandboxNetworkScope, type SandboxOperation, type SandboxPermissionSupport } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { NativeFixtureEntry } from "./sandbox-native-conformance.js";
|
|
3
|
+
/** A controlled endpoint whose receipts the fixture counts out of band (never via the device). */
|
|
4
|
+
export interface SandboxPermissionEndpoint {
|
|
5
|
+
/** A numeric address the device can reach directly. */
|
|
6
|
+
readonly host: string;
|
|
7
|
+
readonly port: number;
|
|
8
|
+
/** Accepted connections so far, observed by the endpoint itself. */
|
|
9
|
+
receipts(): Promise<number>;
|
|
10
|
+
}
|
|
11
|
+
/** The scope one fresh operation receives; the fixture adds the IDs and revisions. */
|
|
12
|
+
export interface SandboxPermissionGrant {
|
|
13
|
+
readonly profile: PermissionProfile;
|
|
14
|
+
readonly filesystem: SandboxFileScope;
|
|
15
|
+
readonly network: SandboxNetworkScope;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The actual provider under test, on one shared device. All paths are absolute device paths on one
|
|
19
|
+
* shared filesystem; `root` and `sibling` are empty directories owned by the device user. The
|
|
20
|
+
* device must provide `/bin/sh`, `python3`, `node` and `curl`. Inspection is trusted, out of band
|
|
21
|
+
* and read-only; it never runs through a restricted operation and never grants anything.
|
|
22
|
+
*/
|
|
23
|
+
export interface SandboxPermissionFixture {
|
|
24
|
+
/** The project root granted (writable) to restricted operations. */
|
|
25
|
+
readonly root: string;
|
|
26
|
+
/** A directory outside every restricted grant, on the same filesystem. */
|
|
27
|
+
readonly sibling: string;
|
|
28
|
+
/** Existing files the device user may write ordinarily but no restricted grant covers. */
|
|
29
|
+
readonly protectedPaths: readonly string[];
|
|
30
|
+
/** `granted` is reachable by allowlisting its host; `ungranted` never is. */
|
|
31
|
+
readonly endpoints: {
|
|
32
|
+
readonly granted: SandboxPermissionEndpoint;
|
|
33
|
+
readonly ungranted: readonly SandboxPermissionEndpoint[];
|
|
34
|
+
};
|
|
35
|
+
/** The provider's own runtime report; the harness never infers support from a fixture. */
|
|
36
|
+
support(): Promise<SandboxPermissionSupport>;
|
|
37
|
+
/** A fresh operation (new operation ID) for the grant, through the provider's factory. */
|
|
38
|
+
operation(grant: SandboxPermissionGrant): Promise<SandboxOperation>;
|
|
39
|
+
/** Trusted setup under root or sibling; preserves entries from earlier calls. */
|
|
40
|
+
seed(entries: readonly NativeFixtureEntry[]): Promise<void>;
|
|
41
|
+
inspect: {
|
|
42
|
+
readFile(path: string): Promise<Uint8Array | null>;
|
|
43
|
+
/** Permission bits (`st_mode & 0o7777`), or null when missing. */
|
|
44
|
+
mode(path: string): Promise<number | null>;
|
|
45
|
+
/** The subset of `pids` still running on the device. */
|
|
46
|
+
alive(pids: readonly number[]): Promise<number[]>;
|
|
47
|
+
};
|
|
48
|
+
/** Removes fixture-owned resources, including after an assertion failure. */
|
|
49
|
+
dispose(): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Proves an actual provider's permission boundary on one shared device: positive controls, sibling,
|
|
53
|
+
* symlink, protected-path and network denials, Full controls without restricted filters, both
|
|
54
|
+
* overlap orders, component/root swaps and mutable syscall pointers during access, exact
|
|
55
|
+
* cancellation and fresh narrowed scopes. Restricted network none/allowlist may bind and listen on
|
|
56
|
+
* loopback (127.0.0.1, ::1) only. Pathname UNIX services outside the roots stay unreachable under
|
|
57
|
+
* every network kind, environment included; metadata reads outside the roots are not covered. A provider that reports restricted unsupported must
|
|
58
|
+
* refuse restricted operations (fail closed); nothing here substitutes a fixture flag for support.
|
|
59
|
+
*/
|
|
60
|
+
export declare function runSandboxPermissionConformance(fixture: SandboxPermissionFixture): Promise<void>;
|