@capybara-hq/testing 0.1.0-rc.0 → 0.1.0-rc.10

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