import * as Context from "../Context.ts"; import * as Duration from "../Duration.ts"; import * as Effect from "../Effect.ts"; import * as Layer from "../Layer.ts"; import * as Option from "../Option.ts"; import * as Schema from "../Schema.ts"; import * as Chat from "./Chat.ts"; import type { Descriptor, File } from "./ChatAdapter.ts"; import { Registry } from "./ChatAdapter.ts"; import type { ChatErrorReason } from "./ChatError.ts"; import { Capability } from "./ChatError.ts"; import type { ThreadKind } from "./ChatEvent.ts"; import * as ChatEvent from "./ChatEvent.ts"; import { ChatHandler } from "./ChatHandler.ts"; import type { NotAccepted } from "./ChatHandler.ts"; import * as ChatInteraction from "./ChatInteraction.ts"; import type { Mention, ReplyTo } from "./ChatMessage.ts"; import * as ChatMessage from "./ChatMessage.ts"; import * as ChatThread from "./ChatThread.ts"; /** * Reads a slice of `ChatMessage.text` as one of the platform's mention * tokens. * * **Details** * * The core does not know any platform's syntax, so the caller supplies it. A * slice that is not a mention token returns `None`. * * @stability unstable * @category models * @since 4.1.5 */ export type ParseMention = (slice: string) => Option.Option<{ readonly kind: Mention["kind"]; readonly id: string; }>; /** * One call the fake adapter received, in order. Every attempt is a call, so a * retried request shows up once per attempt. * * @stability unstable * @category models * @since 4.1.5 */ export interface Call { readonly op: string; readonly thread: ChatThread.ChatThread; readonly messageId?: string | undefined; readonly markdown?: string | undefined; readonly files?: ReadonlyArray | undefined; readonly outcome: "ok" | ChatErrorReason["_tag"]; } declare const NoSuchElement_base: Schema.Class, import("../Cause.ts").YieldableError>; /** * Error for a click on an element the message does not carry, or on a * message that is gone. * * @stability unstable * @category errors * @since 4.1.5 */ export declare class NoSuchElement extends NoSuchElement_base { } declare const ChatTest_base: Context.ServiceClass Effect.Effect; readonly userPosts: (thread: ChatThread.ChatThread, message: { readonly text: string; readonly authorId?: string | undefined; readonly isBot?: boolean | undefined; readonly mentionsSelf?: boolean | undefined; readonly replyTo?: ReplyTo | undefined; readonly files?: ReadonlyArray | undefined; }) => Effect.Effect; readonly deliver: (event: ChatEvent.ChatEvent) => Effect.Effect; readonly messages: (thread: ChatThread.ChatThread) => Effect.Effect>; readonly calls: Effect.Effect>; readonly failNext: (op: string, reason: ChatErrorReason, options?: { readonly times?: number | undefined; readonly landed?: boolean | undefined; }) => Effect.Effect; readonly refuseFiles: (options?: { readonly times?: number | undefined; }) => Effect.Effect; readonly clickStop: (messageId: string) => Effect.Effect; readonly closeStream: (messageId: string) => Effect.Effect; readonly click: (messageId: string, id: string, options?: { readonly userId?: string | undefined; readonly option?: string | undefined; }) => Effect.Effect; readonly command: (thread: ChatThread.ChatThread, id: string, options?: { readonly text?: string | undefined; readonly userId?: string | undefined; }) => Effect.Effect; readonly submit: (from: ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged | ChatInteraction.CommandInvoked, opened: ChatInteraction.OpenModal, values: Readonly>, options?: { readonly userId?: string | undefined; }) => Effect.Effect; readonly interact: { (event: ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged): Effect.Effect; (event: ChatInteraction.ModalSubmitted): Effect.Effect; (event: ChatInteraction.CommandInvoked): Effect.Effect; }; }>; /** * Service that controls the fake adapter built by `layer`. * * **Details** * * - `makeThread` creates a fresh address: a channel by default, a direct * conversation, or a thread under a user's message in a fresh channel. * - `userPosts` puts another identity's message in a thread and returns its * event without delivering it. `deliver` delivers an event the way an * adapter does, by calling the `ChatHandler` service. * - `messages` is what a thread shows now, oldest first, and `calls` is every * call the adapter received. * - `failNext` makes the next `times` calls of `op` fail with `reason`. * `landed` makes the write happen anyway, which is what `uncertain` means. * The native stream's ops are `nativeStream.start`, `nativeStream.append` * and `nativeStream.stop`. * - `refuseFiles` makes the next `times` posts with files fail `denied` with * detail `file_refused`, storing nothing. Text-only posts do not consume it. * - `clickStop` is a user clicking stop on a native stream. It closes * nothing, as on Slack: the stream keeps taking text, and * `NativeStream.stop` then reports `stopped: true`. * - `closeStream` closes a native stream from outside, so the next append * gives `closed`, or `stopped` after a click. * - `click` builds the click on element `id` of a message from what the * fake stored at `post` or `edit`, without delivering it. For a select, * `option` is the encoded value of the option to choose, the first by * default. It fails `NoSuchElement` when the message has no such element, * or no such option, or is gone. * - `command` builds a command typed at `thread`, without delivering it. * `text` defaults to the empty string. The fake has no registration, so * any id can be typed. * - `submit` builds the submit of a modal. It takes the click or the command * that opened it, because an `OpenModal` reply does not say where it was * opened from and a `ModalSubmitted` has to. A command gives a submit * with no `messageId`. `values` are by field id, still encoded, and an * empty one is left out, as for an optional field left empty. * - `interact` delivers an interaction the way an adapter does: through * `ChatInteraction.handle` with the layer's `interactionDeadline`, then * the fake's own checks on an `OpenModal` (the `modals` capability, * `limits.modalMetadataLength` against the modal's id plus its encoded * metadata, and `limits.modalFields`), calling `Handler.refused` when one * fails. It succeeds with the handler's reply as it returned it, or * `Late`. An `OpenModal` shows in `calls` as op `openModal`. * - For a command, `interact` runs the checks of `post` on a `Respond` * (the element capabilities, `limits.messageLength` and the element * limits), and refuses a private `Respond` or `Defer` without * `ephemeral`. A `Respond` shows in `calls` as op `respond`, and a * `followUp` as op `followUp`, each with the command's thread and the * Markdown. Neither is stored as a message. * - The fake's `followUp` succeeds once for a `Defer` that `interact` * returned, inside `limits.followUpAge` on `Clock`. Later, a second time, * or for a deferral the fake never saw, it fails `NotFound` with detail * `interaction_expired`. Failing the second call is stricter than either * platform, to catch a handler that relies on more than one: Slack posts * another message and Discord replaces the first. * * @stability unstable * @category services * @since 4.1.5 */ export declare class ChatTest extends ChatTest_base { } /** * Creates a whole chat in memory: `Chat`, its registry and one fake adapter. * * **When to use** * * Use to test code that posts and reads through `Chat`, and to run the * conformance suite against the fake adapter. * * **Details** * * - The platform defaults to `test` and the bot's user id to `bot`. * - Every capability is on by default. * - `measure` defaults to a count of code points, and the fake checks every * length with it. * - The default limits are 4000 per message, 10 files of up to 10 MiB, and no * write interval. With `nativeStream` on, a stream takes up to * `messageLength` and lasts 10 minutes. * - The native stream behaves the way Slack's was found to. An append past * `limits.streamLength` fails with `TooLarge` and adds nothing. A stream * past `limits.streamAge`, on `Clock`, is closed. An append without * `flush` holds back an unclosed `<` tail of up to 100 characters, or a * trailing high surrogate. Any other lone surrogate is stored as U+FFFD. * An open stream refuses `edit` and `delete`. * - With `buttons` or `selects` on, a message takes 25 elements, and an * element's id plus encoded value 100 code points. With `modals` on, a * modal's id plus encoded metadata takes 100 code points, and a modal 5 * fields. Each limit is there only with its capability. * - `interact` gives a handler 3 seconds by default, on `Clock`. * - With `commands` on, `limits.followUpAge` is 15 minutes. * - Two layers merged with different platforms share one `Chat`, so routing * can be tested. The `ChatTest` service in context is the last one merged. * * @stability unstable * @category layers * @since 4.1.5 */ export declare const layer: (options?: { readonly platform?: string | undefined; readonly selfId?: string | undefined; readonly capabilities?: ReadonlyArray | undefined; readonly limits?: Partial | undefined; readonly measure?: Descriptor["measure"] | undefined; readonly interactionDeadline?: Duration.Duration | undefined; }) => Layer.Layer; declare const ConformanceFailure_base: Schema.Class; }>, import("../Cause.ts").YieldableError>; /** * Error for a conformance rule or invariant that did not hold. * * **Details** * * `rule` names what failed, and `expected` and `actual` say how. A platform * error behind the failure is in `cause`. * * @stability unstable * @category errors * @since 4.1.5 */ export declare class ConformanceFailure extends ConformanceFailure_base { get message(): string; } /** * Returns whether two reads of a message are the same message. * * **Details** * * It compares `id`, `thread`, `author.id`, `author.isBot`, `author.isSelf`, * `text`, `mentions`, `replyTo`, `timestamp` and the attachment ids in order. * `raw`, `author.name` and the optional attachment fields are left out. * * @stability unstable * @category comparisons * @since 4.1.5 */ export declare const sameMessage: (a: ChatMessage.ChatMessage, b: ChatMessage.ChatMessage) => boolean; /** * Checks the invariants every message holds, for fixture tests and live runs. * * **Details** * * - Every mention sits inside `text`, mentions do not overlap, and each slice * parses with `parseMention` as a token of the mention's kind and id. * - `thread.platform` is the platform, and the thread survives its string * codec. * - The message encodes and decodes through its Schema unchanged, `raw` * included. * - Every attachment has an id and no URL. * - `replyTo.isSelf` is set exactly when `replyTo.authorId` is. * * @stability unstable * @category testing * @since 4.1.5 */ export declare const checkMessage: (message: ChatMessage.ChatMessage, options: { readonly platform: string; readonly parseMention: ParseMention; }) => Effect.Effect; /** * Checks the invariants every event holds, for fixture tests and live runs. * * **Details** * * - A message event's message passes `checkMessage`, and the event's thread is * the message's. * - `thread.platform` is the platform, and the thread survives its string * codec. * - The event encodes and decodes through its Schema unchanged, `raw` * included, and two decodes have the same `dedupeKey`. * - A reaction's `dedupeKey` differs between added and removed. * * @stability unstable * @category testing * @since 4.1.5 */ export declare const checkEvent: (event: ChatEvent.ChatEvent, options: { readonly platform: string; readonly parseMention: ParseMention; }) => Effect.Effect; /** * Checks the invariants every interaction holds, for a click, a submit or a * command from a fixture. * * **Details** * * - `thread.platform` is the platform, and the thread survives its string * codec. * - The interaction encodes and decodes through its Schema unchanged, `raw` * included. * - A `ModalSubmitted`'s `messageId` is non-empty when it is there. A modal * a command opened has none. * - A `CommandInvoked` has a non-empty `id`. * * It takes no `parseMention` and checks no dedupe key, since an interaction * carries neither. * * @stability unstable * @category testing * @since 4.1.5 */ export declare const checkInteraction: (interaction: ChatInteraction.Interaction, options: { readonly platform: string; }) => Effect.Effect; /** * The click hook of `conformance`: a way to click, for the adapter under * test. * * **Details** * * - `click` clicks the element `id` on a message the suite posted, through * the adapter's real entry, and fails `NoSuchElement` when the message * carries no such element. `option` is as in `ChatTest.click`. * - `submit` submits the modal the last click or command opened, and * submits it again after an `errors` reply. It does nothing when no modal * is open: the rule then fails on the submit its handler never saw. * - `command` sends a command typed at `thread` through the adapter's real * entry. The command rules exist only when it is given. It is optional, so * a hook written before commands still fits. * - All three need `ChatInteraction.Handler` and nothing else. The suite * provides its own recording handler, so the entry must take its handler * at the call, not at layer build. * * @stability unstable * @category testing * @since 4.1.5 */ export interface Interactions { readonly click: (messageId: string, id: string, options?: { readonly option?: string | undefined; }) => Effect.Effect; readonly submit: (values: Readonly>) => Effect.Effect; readonly command?: ((thread: ChatThread.ChatThread, id: string, options?: { readonly text?: string | undefined; }) => Effect.Effect) | undefined; } /** * Creates the conformance suite, as plain Effects keyed by rule name, so any * test runner can run them. * * **Details** * * - Each rule needs the adapter under test registered in `Chat` and a way to * make another identity's message appear in `thread`, which must be a * channel the suite may write to. * - A rule is never skipped. When the descriptor lacks a capability a rule * needs, the rule becomes its inverse: the op fails with `Unsupported`. * There is an `unsupported/{capability}` rule for every capability. When * the capability is listed, it calls the op and fails if the op fails with * `Unsupported`, so a descriptor that lies in either direction fails. * - A listed capability never fails with `Unsupported`, which every rule * checks as it goes. * - The three `retries/*` rules exist only when `failNext` is given. * `post/refusedFile` exists only when `refuseFiles` is given. * - The rules that need a click exist only when `interactions` is given, * since neither platform has an API that clicks. A live run leaves it out * and runs only the outbound rules. The suite provides its own recording * `ChatInteraction.Handler` to the hook, so the rules still need only * `Chat` and `Registry`. * - `modalErrors` has no inverse rule: without it an `errors` reply is a * degraded answer, not a refusal. * - The `command/*` rules and `unsupported/ephemeral` exist only when * `interactions.command` is given. `unsupported/commands` always runs: it * calls `followUp` with a deferral the suite builds by hand, which must * fail `Unsupported` without `commands`, and fail some other way with it. * - Every rule deletes what it posted when it ends, pass or fail, when the * platform can delete. * * **Gotchas** * * Rule names are stable, an existing rule is never tightened, and a new rule * arrives only behind a new capability or with a changeset saying third-party * adapters may start failing. `unsupported/buttons` and * `unsupported/selects` are such rules: an adapter that ignores `actions` * and posts anyway fails them. So is `unsupported/commands`: an adapter whose * `followUp` does anything but fail `Unsupported` fails it. The `retries/retrySafe` rule waits for real * time, so run the suite on a live `Clock`. * * @stability unstable * @category testing * @since 4.1.5 */ export declare const conformance: (options: { readonly platform: string; readonly thread: ChatThread.ChatThread; readonly userPosts: (thread: ChatThread.ChatThread, text: string) => Effect.Effect; readonly parseMention: ParseMention; readonly refuseFiles?: (() => Effect.Effect) | undefined; readonly interactions?: Interactions | undefined; readonly failNext?: ((op: string, reason: ChatErrorReason, options?: { readonly times?: number | undefined; readonly landed?: boolean | undefined; }) => Effect.Effect) | undefined; }) => Readonly>>; export {}; //# sourceMappingURL=ChatTest.d.ts.map