channelstack 0.0.0-placeholder.0 → 0.1.1
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/LICENSE +21 -0
- package/README.md +55 -1
- package/bin/channelstack.mjs +31 -0
- package/dist/integrations/checks/checks.test.d.ts +1 -0
- package/dist/integrations/checks/checks.test.js +31 -0
- package/dist/integrations/checks/index.d.ts +69 -0
- package/dist/integrations/checks/index.js +578 -0
- package/dist/integrations/matchers-core/index.d.ts +138 -0
- package/dist/integrations/matchers-core/index.js +458 -0
- package/dist/integrations/matchers-core/matchers.test.d.ts +1 -0
- package/dist/integrations/matchers-core/matchers.test.js +159 -0
- package/dist/integrations/vitest/global-setup.d.ts +3 -0
- package/dist/integrations/vitest/global-setup.js +19 -0
- package/dist/integrations/vitest/index.d.ts +80 -0
- package/dist/integrations/vitest/index.js +42 -0
- package/dist/integrations/vitest/plugin.test.d.ts +1 -0
- package/dist/integrations/vitest/plugin.test.js +19 -0
- package/dist/integrations/vitest/refused.d.ts +22 -0
- package/dist/integrations/vitest/refused.js +49 -0
- package/dist/integrations/vitest/setup.d.ts +1 -0
- package/dist/integrations/vitest/setup.js +109 -0
- package/dist/sdks/typescript/client.d.ts +13 -0
- package/dist/sdks/typescript/client.js +11 -0
- package/dist/sdks/typescript/generated/channels.d.ts +24 -0
- package/dist/sdks/typescript/generated/channels.js +2 -0
- package/dist/sdks/typescript/generated/index.d.ts +2747 -0
- package/dist/sdks/typescript/generated/index.js +3039 -0
- package/dist/sdks/typescript/runtime/client.d.ts +47 -0
- package/dist/sdks/typescript/runtime/client.js +69 -0
- package/dist/sdks/typescript/runtime/credentials.d.ts +7 -0
- package/dist/sdks/typescript/runtime/credentials.js +20 -0
- package/dist/sdks/typescript/runtime/duration.d.ts +4 -0
- package/dist/sdks/typescript/runtime/duration.js +13 -0
- package/dist/sdks/typescript/runtime/files.d.ts +32 -0
- package/dist/sdks/typescript/runtime/files.js +45 -0
- package/dist/sdks/typescript/runtime/launcher.d.ts +24 -0
- package/dist/sdks/typescript/runtime/launcher.js +121 -0
- package/dist/sdks/typescript/runtime/transport.d.ts +43 -0
- package/dist/sdks/typescript/runtime/transport.js +95 -0
- package/dist/sdks/typescript/runtime/wait.d.ts +82 -0
- package/dist/sdks/typescript/runtime/wait.js +136 -0
- package/dist/sdks/typescript/types.d.ts +72 -0
- package/dist/sdks/typescript/types.js +1 -0
- package/package.json +78 -4
- package/index.js +0 -1
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { parseDuration } from "./duration.js";
|
|
2
|
+
const defaults = { timeout: "10s", quietFor: "750ms" };
|
|
3
|
+
/**
|
|
4
|
+
* Change the default `timeout` and `quietFor` of every wait: `waitFor…`, `latest…`, the reads that
|
|
5
|
+
* wait for quiet, and calls repeated while refused. The Vitest plugin sets them from its `timeout`
|
|
6
|
+
* and `quietFor` options. What isn't given stays as it is.
|
|
7
|
+
*/
|
|
8
|
+
export function setWaitDefaults(options) {
|
|
9
|
+
for (const key of ["timeout", "quietFor"]) {
|
|
10
|
+
const value = options[key];
|
|
11
|
+
if (value === undefined)
|
|
12
|
+
continue;
|
|
13
|
+
parseDuration(value);
|
|
14
|
+
defaults[key] = value;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** The defaults every wait uses now (a copy). */
|
|
18
|
+
export function waitDefaults() {
|
|
19
|
+
return { ...defaults };
|
|
20
|
+
}
|
|
21
|
+
export class WaitTimeoutError extends Error {
|
|
22
|
+
constructor(what, timeoutMs) {
|
|
23
|
+
super(`Timed out after ${timeoutMs}ms waiting for ${what}`);
|
|
24
|
+
this.name = "WaitTimeoutError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The one polling loop: read until `read` returns something other than undefined, or the
|
|
29
|
+
* timeout passes. Every `waitFor…`, `latest…` and matcher is built on it; tests never sleep.
|
|
30
|
+
*/
|
|
31
|
+
export async function waitFor(what, read, options = {}) {
|
|
32
|
+
const timeout = parseDuration(options.timeout ?? defaults.timeout);
|
|
33
|
+
const interval = parseDuration(options.interval ?? "50ms");
|
|
34
|
+
const deadline = Date.now() + timeout;
|
|
35
|
+
for (;;) {
|
|
36
|
+
const value = await read();
|
|
37
|
+
if (value !== undefined)
|
|
38
|
+
return value;
|
|
39
|
+
if (Date.now() + interval > deadline)
|
|
40
|
+
throw new WaitTimeoutError(typeof what === "string" ? what : what(), timeout);
|
|
41
|
+
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Repeat a call while it is refused with one of these error codes, the way a person waits for a
|
|
46
|
+
* button to appear before clicking it. When the time is up, the last refusal is the error.
|
|
47
|
+
*/
|
|
48
|
+
export async function retryWhile(codes, call, options = {}) {
|
|
49
|
+
let refusal;
|
|
50
|
+
try {
|
|
51
|
+
return await waitFor("the call to be accepted", async () => {
|
|
52
|
+
try {
|
|
53
|
+
return { value: await call() };
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (!codes.includes(String(error?.code)))
|
|
57
|
+
throw error;
|
|
58
|
+
refusal = error;
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
}, options).then(({ value }) => value);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
throw error instanceof WaitTimeoutError && refusal !== undefined ? refusal : error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Does an item's author match a `from` filter: a handle, a name, or nothing (anyone)? */
|
|
68
|
+
export function fromMatches(author, from) {
|
|
69
|
+
if (from === undefined)
|
|
70
|
+
return true;
|
|
71
|
+
return typeof from === "string" ? author.name === from || author.id === from : author.id === from.id;
|
|
72
|
+
}
|
|
73
|
+
/** Does a text match what was asked for: a string it contains, a pattern, or nothing (any text)? */
|
|
74
|
+
export function textMatches(text, expected) {
|
|
75
|
+
if (expected === undefined)
|
|
76
|
+
return true;
|
|
77
|
+
if (typeof expected === "string")
|
|
78
|
+
return text.includes(expected);
|
|
79
|
+
// A pattern with the `g` or `y` flag remembers where it stopped; every test starts afresh.
|
|
80
|
+
expected.lastIndex = 0;
|
|
81
|
+
return expected.test(text);
|
|
82
|
+
}
|
|
83
|
+
/** Text to find as it goes to the server: a string as it is, a `RegExp` as its source and flags. */
|
|
84
|
+
export function patternOnWire(pattern) {
|
|
85
|
+
return typeof pattern === "string" ? pattern : { source: pattern.source, flags: pattern.flags };
|
|
86
|
+
}
|
|
87
|
+
/** "a reply" → "a reply from my-agent", for timeout messages. */
|
|
88
|
+
export function describeWait(what, from) {
|
|
89
|
+
return from === undefined ? what : `${what} from ${typeof from === "string" ? from : from.name}`;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Wait for the next new item of a list that matches, after the last one this handle returned.
|
|
93
|
+
* `seen` belongs to the handle and remembers, per wait, how far it has looked. With `startsTurn`,
|
|
94
|
+
* the wait also looks only after the newest item that starts a turn (a person's prompt).
|
|
95
|
+
*/
|
|
96
|
+
export function waitForNext(seen, key, read, matches, what, options = {}, startsTurn) {
|
|
97
|
+
return waitFor(what, async () => {
|
|
98
|
+
const items = await read();
|
|
99
|
+
const turn = startsTurn ? items.findLastIndex(startsTurn) + 1 : 0;
|
|
100
|
+
const from = Math.max(seen.get(key) ?? 0, turn);
|
|
101
|
+
const index = items.findIndex((item, position) => position >= from && matches(item));
|
|
102
|
+
if (index === -1)
|
|
103
|
+
return undefined;
|
|
104
|
+
seen.set(key, index + 1);
|
|
105
|
+
return items[index];
|
|
106
|
+
}, options);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Resolve once the agent has been quiet for `quietFor`. Negative and exact-count checks read after this.
|
|
110
|
+
*
|
|
111
|
+
* With `watching`, the quiet time counts from now at the earliest: the caller wants to have looked
|
|
112
|
+
* for the whole window. An agent that is thinking makes no sound, so a session that went quiet a
|
|
113
|
+
* while ago says nothing about what arrives next.
|
|
114
|
+
*/
|
|
115
|
+
export async function untilQuiet(quiet, options = {}) {
|
|
116
|
+
const quietFor = parseDuration(options.quietFor ?? defaults.quietFor);
|
|
117
|
+
const started = Date.now();
|
|
118
|
+
let open = [];
|
|
119
|
+
await waitFor(
|
|
120
|
+
// A wait that gives up says what the agent left open: that is usually the bug.
|
|
121
|
+
() => `the agent to be quiet for ${quietFor}ms${open.length > 0 ? `. Still open: ${open.join("; ")}` : ""}`, async () => {
|
|
122
|
+
const state = await quiet();
|
|
123
|
+
open = state.open;
|
|
124
|
+
if (options.watching && Date.now() - started < quietFor)
|
|
125
|
+
return undefined;
|
|
126
|
+
return !state.busy && state.quietForMs >= quietFor ? true : undefined;
|
|
127
|
+
}, options);
|
|
128
|
+
}
|
|
129
|
+
/** The last item of a list that matches, read once the agent is quiet. Waits for at least one first. */
|
|
130
|
+
export async function latestOnceQuiet(read, matches, quiet, what, options = {}) {
|
|
131
|
+
const latest = async () => (await read()).filter(matches).at(-1);
|
|
132
|
+
await waitFor(what, latest, options);
|
|
133
|
+
await untilQuiet(quiet, options);
|
|
134
|
+
// The agent may have said more while it was settling: the answer is what is there now.
|
|
135
|
+
return waitFor(what, latest, options);
|
|
136
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract's type names (`api/*.d.ts`) that the generated SDK has no type of its own for: unions
|
|
3
|
+
* of its handles, the option bags of its methods, and the values of its fields. Each one is read
|
|
4
|
+
* from the generated code, so it can't drift from it. With them, `import type { AuthorRef } from
|
|
5
|
+
* "channelstack"` works as the contract says.
|
|
6
|
+
*
|
|
7
|
+
* Not here: the test framework's own types (`ChannelstackFixture`, `ChannelstackIntegrationOptions`,
|
|
8
|
+
* `ChannelstackMatchers`, `TextOptions`, in `channelstack/vitest`), and `SlackInjectedFault`, which
|
|
9
|
+
* the SDK calls `SlackFault` (#37).
|
|
10
|
+
*/
|
|
11
|
+
import type { AnyDelivery, App, Transcript, User } from "./generated/channels.ts";
|
|
12
|
+
import type * as G from "./generated/index.ts";
|
|
13
|
+
export type { ApiCall, App, ChannelKind, DeliveryFilter, Inspectable, Resource, Transcript, User, } from "./generated/channels.ts";
|
|
14
|
+
type Option<Method extends (...args: never[]) => unknown> = NonNullable<Parameters<Method>[0]>;
|
|
15
|
+
/** Text that may contain `@name` mentions. */
|
|
16
|
+
export type RichText = string;
|
|
17
|
+
/** ISO 8601 timestamp string. */
|
|
18
|
+
export type Timestamp = string;
|
|
19
|
+
export type SlackParticipant = G.SlackUser | G.SlackApp;
|
|
20
|
+
export type GitHubAuthor = G.GitHubUser | G.GitHubApp;
|
|
21
|
+
export type LinearAuthor = G.LinearUser | G.LinearApp;
|
|
22
|
+
export type NotionAuthor = G.NotionUser | G.NotionIntegration;
|
|
23
|
+
export type Principal = User | App;
|
|
24
|
+
/** Anything that can be named as an author in a matcher: a handle or its `name`. */
|
|
25
|
+
export type AuthorRef = Principal | string;
|
|
26
|
+
/** A delivery of any channel, narrowed by its `type` and `payload` as the contract's `Delivery<TType, TPayload>` is. */
|
|
27
|
+
export type Delivery<TType extends string = string, TPayload = unknown> = AnyDelivery & {
|
|
28
|
+
readonly type: TType;
|
|
29
|
+
readonly payload: TPayload;
|
|
30
|
+
};
|
|
31
|
+
export type DeliveryStatus = Delivery["status"];
|
|
32
|
+
export type DeliveryTransport = G.DeliveryAttempt["transport"];
|
|
33
|
+
export type SlackDeliveryType = G.SlackDelivery["type"];
|
|
34
|
+
export type DeliveryResendOptions = Option<G.GitHubDelivery["resend"]>;
|
|
35
|
+
export type SlackDeliveryResendOptions = Option<G.SlackDelivery["resend"]>;
|
|
36
|
+
export type LinearDeliveryResendOptions = Option<G.LinearDelivery["resend"]>;
|
|
37
|
+
export type ApiCallFilter = Option<G.SlackFixture["calls"]>;
|
|
38
|
+
export type TranscriptEntry = Transcript["entries"][number];
|
|
39
|
+
export type HasTranscript = {
|
|
40
|
+
transcript(): Promise<Transcript>;
|
|
41
|
+
};
|
|
42
|
+
export type SlackHasTranscript = {
|
|
43
|
+
transcript(options?: {
|
|
44
|
+
as?: SlackParticipant;
|
|
45
|
+
}): Promise<G.SlackTranscript>;
|
|
46
|
+
};
|
|
47
|
+
export type SlackUserOptions = Option<G.SlackFixture["createUser"]>;
|
|
48
|
+
export type SlackChannelOptions = Option<G.SlackFixture["createChannel"]>;
|
|
49
|
+
export type GitHubUserOptions = Option<G.GitHubFixture["createUser"]>;
|
|
50
|
+
export type GitHubRepoOptions = Option<G.GitHubFixture["createRepo"]>;
|
|
51
|
+
export type GitHubChanges = Parameters<G.GitHubUser["push"]>[0];
|
|
52
|
+
export type LinearUserOptions = Option<G.LinearFixture["createUser"]>;
|
|
53
|
+
export type LinearTeamOptions = Option<G.LinearFixture["createTeam"]>;
|
|
54
|
+
export type LinearStateType = G.LinearIssueState["type"];
|
|
55
|
+
export type LinearPriority = NonNullable<Parameters<G.LinearUser["createIssue"]>[0]["priority"]>;
|
|
56
|
+
export type LinearSessionState = Awaited<ReturnType<G.LinearAgentSession["state"]>>;
|
|
57
|
+
export type LinearActivityType = G.LinearAgentActivity["type"];
|
|
58
|
+
export type NotionUserOptions = Option<G.NotionFixture["createUser"]>;
|
|
59
|
+
export type NotionPageOptions = Option<G.NotionFixture["createPage"]>;
|
|
60
|
+
export type NotionDatabaseOptions = Option<G.NotionFixture["createDatabase"]>;
|
|
61
|
+
export type ResendUserOptions = Option<G.ResendFixture["createUser"]>;
|
|
62
|
+
export type ResendEventType = G.ResendDelivery["type"];
|
|
63
|
+
export type ResendDeliveryResendOptions = Option<G.ResendDelivery["resend"]>;
|
|
64
|
+
export type GoogleUserOptions = Option<G.GoogleFixture["createUser"]>;
|
|
65
|
+
export type GoogleEventType = G.GoogleDelivery["type"];
|
|
66
|
+
export type GoogleDeliveryResendOptions = Option<G.GoogleDelivery["resend"]>;
|
|
67
|
+
/** An email a person sends, with the channel's own people and app as its recipients. */
|
|
68
|
+
export type EmailSendOptions<TRecipient = unknown> = Omit<Option<G.ResendUser["send"]>, "to" | "cc"> & {
|
|
69
|
+
to: readonly TRecipient[];
|
|
70
|
+
cc?: readonly TRecipient[];
|
|
71
|
+
};
|
|
72
|
+
export type EmailReplyOptions = NonNullable<Parameters<G.ResendUser["reply"]>[1]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,8 +1,82 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "channelstack",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Test the apps and agents you build for Slack, GitHub, Linear, Notion, Resend and Gmail: fake platforms on localhost, the TypeScript SDK, Vitest fixtures and matchers.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"testing",
|
|
7
|
+
"test-harness",
|
|
8
|
+
"fake",
|
|
9
|
+
"slack",
|
|
10
|
+
"github",
|
|
11
|
+
"linear",
|
|
12
|
+
"notion",
|
|
13
|
+
"resend",
|
|
14
|
+
"gmail",
|
|
15
|
+
"agents",
|
|
16
|
+
"vitest"
|
|
17
|
+
],
|
|
18
|
+
"homepage": "https://channelstack.dev",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/christian-bromann/channelstack/issues"
|
|
21
|
+
},
|
|
5
22
|
"license": "MIT",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
23
|
+
"type": "module",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/christian-bromann/channelstack.git",
|
|
27
|
+
"directory": "sdks/typescript"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=22"
|
|
31
|
+
},
|
|
32
|
+
"bin": {
|
|
33
|
+
"channelstack": "bin/channelstack.mjs"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"bin",
|
|
37
|
+
"dist"
|
|
38
|
+
],
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"types": "./dist/sdks/typescript/client.d.ts",
|
|
42
|
+
"default": "./dist/sdks/typescript/client.js"
|
|
43
|
+
},
|
|
44
|
+
"./client": {
|
|
45
|
+
"types": "./dist/sdks/typescript/client.d.ts",
|
|
46
|
+
"default": "./dist/sdks/typescript/client.js"
|
|
47
|
+
},
|
|
48
|
+
"./vitest": {
|
|
49
|
+
"types": "./dist/integrations/vitest/index.d.ts",
|
|
50
|
+
"default": "./dist/integrations/vitest/index.js"
|
|
51
|
+
},
|
|
52
|
+
"./checks": {
|
|
53
|
+
"types": "./dist/integrations/checks/index.d.ts",
|
|
54
|
+
"default": "./dist/integrations/checks/index.js"
|
|
55
|
+
},
|
|
56
|
+
"./vitest/setup": {
|
|
57
|
+
"default": "./dist/integrations/vitest/setup.js"
|
|
58
|
+
},
|
|
59
|
+
"./vitest/global-setup": {
|
|
60
|
+
"default": "./dist/integrations/vitest/global-setup.js"
|
|
61
|
+
},
|
|
62
|
+
"./package.json": "./package.json"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "tsc -p tsconfig.build.json"
|
|
66
|
+
},
|
|
67
|
+
"optionalDependencies": {
|
|
68
|
+
"@channelstack/server-darwin-arm64": "0.1.1",
|
|
69
|
+
"@channelstack/server-darwin-x64": "0.1.1",
|
|
70
|
+
"@channelstack/server-linux-arm64": "0.1.1",
|
|
71
|
+
"@channelstack/server-linux-x64": "0.1.1",
|
|
72
|
+
"@channelstack/server-win32-x64": "0.1.1"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"vitest": ">=5.0.0 <6"
|
|
76
|
+
},
|
|
77
|
+
"peerDependenciesMeta": {
|
|
78
|
+
"vitest": {
|
|
79
|
+
"optional": true
|
|
80
|
+
}
|
|
81
|
+
}
|
|
8
82
|
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
throw new Error("channelstack is not released yet: this package only reserves the name.");
|