Keep retrying the connection and say why; never lose a message that didn't send
As the web's connection supervisor and composer: - The first connection retries too, so tui3 opens without a server and connects when it's up. One-off commands still fail fast. - The header says why it couldn't connect and when it retries; r, a click on it, or the palette retries now. - Enter while disconnected keeps the message and says so. - A failed send, or a new thread that doesn't start, puts the message, its attachments and its mentions back in the composer. - Opening a PR in the browser says why it failed and copies the link. - Error notices stay 8s instead of 4s.
This commit is contained in:
1 parent
275a2bcde1
commit
2c5eedc869
9 files changed
+169
-42
No files matched your search
@@ -207,6 +207,41 @@ describe("composer", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("connection", () => {
|
||||
const reconnecting = () => ({ type: "reconnecting", message: "connect ECONNREFUSED 127.0.0.1:3773", retryAt: Date.now() + 5_000 }) as const;
|
||||
|
||||
test("a dropped connection says why and when it retries; r and a click on it retry now", async () => {
|
||||
const app = await open({ session: fakeSession({ status: reconnecting() }) });
|
||||
expect(app.frame()).toMatch(/couldn't connect, retrying in \ds · connect ECONNREFUSED/);
|
||||
expect(app.hints()).toStartWith("r reconnect now · ");
|
||||
await app.press("r");
|
||||
expect(app.calls("retryNow")).toHaveLength(1);
|
||||
const at = app.find("couldn't connect");
|
||||
await app.click(at.x, at.y);
|
||||
expect(app.calls("retryNow")).toHaveLength(2);
|
||||
});
|
||||
|
||||
test("while disconnected, enter keeps the message rather than sending it", async () => {
|
||||
const app = await open({ session: fakeSession({ status: reconnecting() }) });
|
||||
await app.press("i");
|
||||
await app.type("hello there");
|
||||
await app.press("return");
|
||||
expect(app.calls("sendMessage")).toHaveLength(0);
|
||||
expect(app.hints()).toStartWith("Not connected: message not sent.");
|
||||
expect(app.frame()).toContain("hello there");
|
||||
});
|
||||
|
||||
test("a send that fails puts the message back in the composer", async () => {
|
||||
const app = await open({ session: fakeSession({ failures: { sendMessage: "socket closed" } }) });
|
||||
await app.press("i");
|
||||
await app.type("hello there");
|
||||
await app.press("return");
|
||||
expect(app.calls("sendMessage")).toHaveLength(1);
|
||||
expect(app.hints()).toBe("Not sent: socket closed");
|
||||
expect(app.frame()).toContain("hello there");
|
||||
});
|
||||
});
|
||||
|
||||
describe("mouse", () => {
|
||||
test("the header button opens the palette", async () => {
|
||||
const app = await open();
|
||||
|
||||
+15
-5
@@ -2,7 +2,7 @@ import { testRender } from "@opentui/react/test-utils";
|
||||
import { createMockKeys, type KeyInput } from "@opentui/core/testing";
|
||||
import type { OrchestrationV2ShellSnapshot, OrchestrationV2ThreadProjection, ThreadId } from "@t3tools/contracts";
|
||||
|
||||
import type { T3Session } from "../../src/client/session.ts";
|
||||
import type { ConnectionStatus, T3Session } from "../../src/client/session.ts";
|
||||
import { DEFAULT_CONFIG, type Tui3Config } from "../../src/config.ts";
|
||||
import { App } from "../../src/ui/App.tsx";
|
||||
import { v2Projection, v2ShellSnapshot, v2ThreadId } from "../../vendor/t3code/packages/client-runtime/src/state/orchestrationV2TestFixtures.ts";
|
||||
@@ -23,9 +23,18 @@ export interface Call {
|
||||
|
||||
/**
|
||||
* A session that serves fixed state and records every other call. Watchers get one live
|
||||
* value straight away; anything not listed resolves to undefined.
|
||||
* value straight away; anything not listed resolves to undefined, or rejects with its
|
||||
* `failures` message.
|
||||
*/
|
||||
export function fakeSession(state: { readonly snapshot?: OrchestrationV2ShellSnapshot; readonly projection?: OrchestrationV2ThreadProjection; readonly results?: Record<string, unknown> } = {}) {
|
||||
export function fakeSession(
|
||||
state: {
|
||||
readonly snapshot?: OrchestrationV2ShellSnapshot;
|
||||
readonly projection?: OrchestrationV2ThreadProjection;
|
||||
readonly status?: ConnectionStatus;
|
||||
readonly results?: Record<string, unknown>;
|
||||
readonly failures?: Record<string, string>;
|
||||
} = {},
|
||||
) {
|
||||
const calls: Call[] = [];
|
||||
const snapshot = state.snapshot ?? v2ShellSnapshot;
|
||||
const projection = state.projection ?? v2Projection;
|
||||
@@ -34,7 +43,7 @@ export function fakeSession(state: { readonly snapshot?: OrchestrationV2ShellSna
|
||||
return () => {};
|
||||
};
|
||||
const known: Record<string, unknown> = {
|
||||
getShell: () => ({ status: { type: "live" }, snapshot, serverUrl: "ws://test" }),
|
||||
getShell: () => ({ status: state.status ?? { type: "live" }, snapshot, serverUrl: "ws://test" }),
|
||||
onShell: () => () => {},
|
||||
watchThread: (_id: ThreadId, listener: (value: unknown) => void) => live({ status: "live", projection, history: { cursor: null, hasMore: false, loading: false } })(listener),
|
||||
watchServerConfig: live({ status: "loading", config: null }),
|
||||
@@ -51,7 +60,8 @@ export function fakeSession(state: { readonly snapshot?: OrchestrationV2ShellSna
|
||||
return (...args: unknown[]) => {
|
||||
calls.push({ method: name, args });
|
||||
if (name.startsWith("watch") || name.startsWith("on")) return () => {};
|
||||
return Promise.resolve(state.results?.[name]);
|
||||
const failure = state.failures?.[name];
|
||||
return failure ? Promise.reject(new Error(failure)) : Promise.resolve(state.results?.[name]);
|
||||
};
|
||||
},
|
||||
}) as unknown as T3Session;
|
||||
|
||||
Reference in new issue
Block a user