@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,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A programmable fake Telegram Bot API (for the Telegram channel plugin's tests).
|
|
3
|
+
*
|
|
4
|
+
* - **Routing**: `GET|POST /bot<token>/<method>` (method names are case-insensitive, like Telegram);
|
|
5
|
+
* parameters come from the query string and a JSON or form-urlencoded body. Every answer is the
|
|
6
|
+
* Bot API envelope: `{ ok: true, result }` or `{ ok: false, error_code, description, parameters? }`.
|
|
7
|
+
* An unknown token → 401 `Unauthorized`; an unknown method → 404 `Not Found`. Point a client at
|
|
8
|
+
* `apiUrl` (it appends `/bot<token>/<method>`).
|
|
9
|
+
* - **Methods**: `getMe`, `getWebhookInfo` (the url given to {@link FakeTelegramServer.setWebhook}),
|
|
10
|
+
* `getUpdates`, `sendMessage`, `editMessageText`, `answerCallbackQuery`, and the multipart uploads
|
|
11
|
+
* `sendPhoto` / `sendDocument` (recorded in `messages` with `file`).
|
|
12
|
+
* - **Long polling**: {@link FakeTelegramServer.push} queues an update per bot and assigns its
|
|
13
|
+
* `update_id`. `getUpdates` with `offset` confirms (drops) the lower ids; with `timeout` it waits
|
|
14
|
+
* until a push or the timeout; `allowed_updates` is remembered per bot like Telegram and updates of
|
|
15
|
+
* other types are dropped. While a webhook is set `getUpdates` answers 409; a second concurrent
|
|
16
|
+
* `getUpdates` for the same token ends the earlier one with 409 "Conflict: terminated by other
|
|
17
|
+
* getUpdates request", as Telegram does.
|
|
18
|
+
* - **Several bots**: {@link FakeTelegramOptions.bots}; each token has its own queue, offset, webhook
|
|
19
|
+
* and pollers.
|
|
20
|
+
* - **Failures**: {@link FakeTelegramServer.failNext} answers a method with an error envelope
|
|
21
|
+
* (`parameters.retry_after` / `migrate_to_chat_id`), {@link FakeTelegramServer.delay} holds it.
|
|
22
|
+
*
|
|
23
|
+
* Records: `messages` (sendMessage), `edits` (successful editMessageText), `calls` (every call with
|
|
24
|
+
* a known token), `callbackAnswers` (answerCallbackQuery ids).
|
|
25
|
+
*/
|
|
26
|
+
export interface FakeTelegramBot {
|
|
27
|
+
/** `<id>:<secret>`, as BotFather issues it. */
|
|
28
|
+
token: string;
|
|
29
|
+
id: number;
|
|
30
|
+
username: string;
|
|
31
|
+
firstName?: string;
|
|
32
|
+
/** getMe `can_read_all_group_messages` (privacy mode off); default false. */
|
|
33
|
+
canReadAllGroupMessages?: boolean;
|
|
34
|
+
/** getMe `has_topics_enabled` (forum topics in private chats); default false. */
|
|
35
|
+
hasTopicsEnabled?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** One Bot API call with a known token (parameters merged from query string and body). */
|
|
38
|
+
export interface FakeTelegramCall {
|
|
39
|
+
method: string;
|
|
40
|
+
token: string;
|
|
41
|
+
params: Record<string, unknown>;
|
|
42
|
+
at: number;
|
|
43
|
+
}
|
|
44
|
+
/** A message the bot sent (`sendMessage`) or an edit of one (`editMessageText`). */
|
|
45
|
+
export interface FakeTelegramMessage {
|
|
46
|
+
chatId: number;
|
|
47
|
+
messageId: number;
|
|
48
|
+
text: string;
|
|
49
|
+
parseMode?: string;
|
|
50
|
+
replyMarkup?: unknown;
|
|
51
|
+
messageThreadId?: number;
|
|
52
|
+
replyToMessageId?: number;
|
|
53
|
+
/** The uploaded file of a `sendPhoto` / `sendDocument` (the text is its caption). */
|
|
54
|
+
file?: {
|
|
55
|
+
kind: "photo" | "document";
|
|
56
|
+
name: string;
|
|
57
|
+
contentType: string;
|
|
58
|
+
data: Buffer;
|
|
59
|
+
};
|
|
60
|
+
at: number;
|
|
61
|
+
}
|
|
62
|
+
/** An injected error answer: `status` is the HTTP status, `errorCode` defaults to it. */
|
|
63
|
+
export interface FakeTelegramFailure {
|
|
64
|
+
status: number;
|
|
65
|
+
errorCode?: number;
|
|
66
|
+
description: string;
|
|
67
|
+
retryAfter?: number;
|
|
68
|
+
migrateToChatId?: number;
|
|
69
|
+
}
|
|
70
|
+
export interface FakeTelegramOptions {
|
|
71
|
+
/** The bots this fake serves; default one bot (`123456:fake-telegram-token`, `capybara_bot`). */
|
|
72
|
+
bots?: FakeTelegramBot[];
|
|
73
|
+
}
|
|
74
|
+
export interface FakeTelegramServer {
|
|
75
|
+
url: string;
|
|
76
|
+
/** Same as `url`: the client appends `/bot<token>/<method>`. */
|
|
77
|
+
apiUrl: string;
|
|
78
|
+
/** The first bot (the default for every `token?` argument). */
|
|
79
|
+
bot: FakeTelegramBot;
|
|
80
|
+
bots: FakeTelegramBot[];
|
|
81
|
+
/** sendMessage results, in order. */
|
|
82
|
+
messages: FakeTelegramMessage[];
|
|
83
|
+
/** Successful editMessageText calls, in order (markup-only edits are recorded too). */
|
|
84
|
+
edits: FakeTelegramMessage[];
|
|
85
|
+
calls: FakeTelegramCall[];
|
|
86
|
+
/** answerCallbackQuery `callback_query_id`s, in order. */
|
|
87
|
+
callbackAnswers: string[];
|
|
88
|
+
/** Queues an update for the bot, assigns its `update_id` and returns it; wakes a long poll. */
|
|
89
|
+
push(update: Record<string, unknown>, token?: string): number;
|
|
90
|
+
/** The highest offset passed to getUpdates (0 before any). */
|
|
91
|
+
confirmedOffset(token?: string): number;
|
|
92
|
+
/** Updates pushed and not yet confirmed. */
|
|
93
|
+
pending(token?: string): number;
|
|
94
|
+
/** In-flight getUpdates requests. */
|
|
95
|
+
activePollers(token?: string): number;
|
|
96
|
+
/**
|
|
97
|
+
* The peak number of overlapping getUpdates requests: a request that arrives while another is in
|
|
98
|
+
* flight counts as concurrent with it, although it ends the earlier one with 409.
|
|
99
|
+
*/
|
|
100
|
+
maxConcurrentPollers(token?: string): number;
|
|
101
|
+
/**
|
|
102
|
+
* The client TCP ports of the in-flight getUpdates requests; dual-replica tests map them to the
|
|
103
|
+
* replica process holding the poll.
|
|
104
|
+
*/
|
|
105
|
+
pollerPeerPorts(token?: string): number[];
|
|
106
|
+
/** Sets (or clears with null) the webhook getWebhookInfo reports; while set, getUpdates is 409. */
|
|
107
|
+
setWebhook(url: string | null, token?: string): void;
|
|
108
|
+
/** The next `count` (default 1) calls of `method` answer with `failure`. */
|
|
109
|
+
failNext(method: string, failure: FakeTelegramFailure, count?: number): void;
|
|
110
|
+
/** Every later call of `method` waits `ms` before answering (0 cancels). */
|
|
111
|
+
delay(method: string, ms: number): void;
|
|
112
|
+
close(): Promise<void>;
|
|
113
|
+
}
|
|
114
|
+
export type TgUser = {
|
|
115
|
+
id: number;
|
|
116
|
+
first_name: string;
|
|
117
|
+
last_name?: string;
|
|
118
|
+
username?: string;
|
|
119
|
+
is_bot?: boolean;
|
|
120
|
+
};
|
|
121
|
+
export type TgChat = {
|
|
122
|
+
id: number;
|
|
123
|
+
type: "private" | "group" | "supergroup";
|
|
124
|
+
title?: string;
|
|
125
|
+
is_forum?: boolean;
|
|
126
|
+
};
|
|
127
|
+
/** Starts the fake Telegram Bot API (listens on a random 127.0.0.1 port). */
|
|
128
|
+
export declare function startFakeTelegram(opts?: FakeTelegramOptions): Promise<FakeTelegramServer>;
|
|
129
|
+
/** An update with a private (direct) message from `from`. */
|
|
130
|
+
export declare function telegramPrivateMessage(from: TgUser, text: string, o?: {
|
|
131
|
+
messageId?: number;
|
|
132
|
+
date?: number;
|
|
133
|
+
}): Record<string, unknown>;
|
|
134
|
+
/**
|
|
135
|
+
* An update with a group message. `mention` (with or without `@`) adds a `mention` entity at its
|
|
136
|
+
* UTF-16 offset, prefixing `@<mention> ` when the text lacks it; `replyTo` sets `reply_to_message`
|
|
137
|
+
* (from the bot when `fromBot` is given); `messageThreadId` sets the thread, with
|
|
138
|
+
* `is_topic_message` defaulting to the chat's `is_forum`; `caption` turns the message into a photo
|
|
139
|
+
* whose caption carries the text and entities.
|
|
140
|
+
*/
|
|
141
|
+
export declare function telegramGroupMessage(chat: TgChat, from: TgUser, text: string, o?: {
|
|
142
|
+
messageId?: number;
|
|
143
|
+
mention?: string;
|
|
144
|
+
replyTo?: {
|
|
145
|
+
messageId: number;
|
|
146
|
+
fromBot?: FakeTelegramBot;
|
|
147
|
+
text?: string;
|
|
148
|
+
};
|
|
149
|
+
messageThreadId?: number;
|
|
150
|
+
isTopicMessage?: boolean;
|
|
151
|
+
caption?: boolean;
|
|
152
|
+
}): Record<string, unknown>;
|
|
153
|
+
/** An update with a callback query: `from` pressed an inline button with `data` on a bot message. */
|
|
154
|
+
export declare function telegramCallback(from: TgUser, message: {
|
|
155
|
+
chatId: number;
|
|
156
|
+
messageId: number;
|
|
157
|
+
chatType?: string;
|
|
158
|
+
messageThreadId?: number;
|
|
159
|
+
}, data: string, o?: {
|
|
160
|
+
id?: string;
|
|
161
|
+
}): Record<string, unknown>;
|
|
162
|
+
/** Finds an inline keyboard button in a `reply_markup` (object or JSON string). */
|
|
163
|
+
export declare function findTelegramButton(replyMarkup: unknown, pred: (b: {
|
|
164
|
+
text: string;
|
|
165
|
+
callback_data?: string;
|
|
166
|
+
url?: string;
|
|
167
|
+
}) => boolean): {
|
|
168
|
+
text: string;
|
|
169
|
+
callback_data?: string;
|
|
170
|
+
url?: string;
|
|
171
|
+
} | undefined;
|
|
172
|
+
/** The headers Telegram sends to a webhook set with `secret_token`. */
|
|
173
|
+
export declare function telegramWebhookHeaders(secret: string): Record<string, string>;
|