refactor: remove redundant comments and docstrings (#6527)

* refactor: remove redundant comments and docstrings

* fix(signal): annotate async context manager as a generator
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-30 13:07:03 +08:00
1 parent cb3ba45317
commit a4d2430140
922 files changed
+406 -7738

No files matched your search

-1
View File
@@ -1134,7 +1134,6 @@ describe("App layout", () => {
window.history.replaceState(null, "", "/#/chat/websocket%3Aexisting-chat");
render(<App />);
await waitFor(() => expect(connectSpy).toHaveBeenCalled());
// Wait for the existing chat's lazy composer before opening its sidebar menu.
await screen.findByRole("button", { name: "Workspace access mode: Full Access" });
const projectSection = screen.getByRole("region", { name: "selected-project" });
fireEvent.contextMenu(within(projectSection).getByRole("button", { name: "selected-project" }));
-2
View File
@@ -1563,8 +1563,6 @@ describe("ChatList", () => {
const allRegions = screen.getAllByRole("region");
const regionNames = allRegions.map((r) => r.getAttribute("aria-label") ?? r.textContent);
// The most recently updated conversation ("Recent chat" at 12:00) must be
// in the first group — Topics should come before both projects.
const chatsIdx = regionNames.findIndex((n) => n?.includes("Topics"));
const projAIdx = regionNames.findIndex((n) => n?.includes("project-a"));
const projBIdx = regionNames.findIndex((n) => n?.includes("project-b"));
@@ -122,8 +122,8 @@ describe("Mobile context usage sheet", () => {
});
it.each([
[100, 500], // Deliberate pull.
[32, 40], // Short, quick downward flick.
[100, 500],
[32, 40],
])("dismisses after dragging %dpx in %dms and opens at the original position", async (distance, duration) => {
const { user, handle, sheet, trigger } = await openSheet();
pointer(handle, "pointerDown", { y: 400 });
@@ -155,7 +155,6 @@ describe("Mobile context usage sheet", () => {
expect(sheet.style.transition).toBe("");
fireEvent.click(handle, { detail: 1 });
expect(screen.getByRole("dialog")).toBeVisible();
// A real subsequent tap must still close the sheet.
await user.click(handle);
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
expect(document.body).not.toHaveStyle({ pointerEvents: "none" });
@@ -83,7 +83,6 @@ describe("host compatibility facts", () => {
]);
const values = within(dialog).getAllByRole("definition");
expect(values.map((value) => value.textContent)).toEqual([version, version]);
// Read-only facts must not inherit the settings controls' 60px row floor.
expect(dialog.querySelector(".settings-list-row")).toBeNull();
expect(dialog.querySelector(".break-all, .truncate")).toBeNull();
expect(within(dialog).getByRole("status")).toHaveTextContent(i18n.t("remote.compatibility.compatibleHint"));
+1 -1
View File
@@ -195,7 +195,7 @@ describe("host session lifecycle", () => {
act(() => result.current.loaded(ids[0]));
expect(result.current.selected).toBeNull();
expect(result.current.frames).toHaveLength(0);
expect(vi.getTimerCount()).toBe(1); // health interval only
expect(vi.getTimerCount()).toBe(1);
});
it("a timed-out cold page leaves the old host intact and can be retried", async () => {
@@ -10,7 +10,6 @@ vi.mock("@/lib/bootstrap", async (original) => ({
fetchBootstrap: vi.fn(async () => ({ token: "test", api_token: "test", ws_path: "/" })),
deriveWsUrl: () => "ws://test",
}));
// Keep this suite focused on App's remote boundary rather than the chat implementation.
vi.mock("@/components/thread/ThreadShell", () => ({
ThreadShell: () => <textarea aria-label="Local draft" />,
}));
@@ -6,7 +6,6 @@ import { linearWorkspaceStore } from "../../../nanobot/channels/linear/webui/wor
const installation = { organization_id: "org-1", organization_name: "nanobot" };
const logo = "https://public.linear.app/org-1/logo";
function fixture() {
// Keep the real generic transport type; this client is never connected.
const client = new NanobotClient({ url: "ws://preview.invalid", reconnect: false });
const requestMutation = vi.spyOn(client, "requestMutation").mockImplementation(async (_action, params) =>
params?.operation === "inspect"
-15
View File
@@ -3,11 +3,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { NanobotClient } from "@/lib/nanobot-client";
import type { SidebarStatePayload } from "@/lib/types";
/**
* Minimal fake WebSocket implementing the subset NanobotClient touches.
* Every instance is retrievable via ``FakeSocket.instances`` so tests can
* drive open/close/message lifecycles deterministically.
*/
class FakeSocket {
static instances: FakeSocket[] = [];
static readonly CONNECTING = 0;
@@ -37,8 +32,6 @@ class FakeSocket {
this.onclose?.();
}
/** Simulate a server-initiated drop with a specific wire-level close code
* (e.g. ``1009`` for Message Too Big). */
fakeCloseWithCode(code: number) {
this.readyState = FakeSocket.CLOSED;
this.onclose?.({ code });
@@ -2433,9 +2426,7 @@ describe("NanobotClient", () => {
expect(lastSocket().sent).toContain(
JSON.stringify({ type: "attach", chat_id: "chat-z" }),
);
// Drop the socket.
lastSocket().close();
// Advance the backoff timer.
await vi.advanceTimersByTimeAsync(20);
const reconnected = lastSocket();
expect(reconnected).not.toBe(FakeSocket.instances[0]);
@@ -2471,10 +2462,8 @@ describe("NanobotClient", () => {
client.connect();
lastSocket().fakeOpen();
client.close();
// Advance past any possible backoff window to prove no reconnect was scheduled.
await vi.advanceTimersByTimeAsync(200);
expect(FakeSocket.instances).toHaveLength(1);
// "reconnecting" must never appear after an intentional close.
expect(seen).not.toContain("reconnecting");
expect(seen.at(-1)).toBe("closed");
});
@@ -2529,7 +2518,6 @@ describe("NanobotClient", () => {
client.onError((e) => errors.push(e));
client.connect();
lastSocket().fakeOpen();
// Server rejected an outbound frame as too large.
lastSocket().fakeCloseWithCode(1009);
expect(errors).toEqual([{ kind: "message_too_big" }]);
});
@@ -2587,7 +2575,6 @@ describe("NanobotClient", () => {
maxBackoffMs: 5,
socketFactory: (url) => new FakeSocket(url) as unknown as WebSocket,
});
// First handler explodes; subsequent reconnect state must be untouched.
client.onError(() => {
throw new Error("subscriber blew up");
});
@@ -2596,7 +2583,6 @@ describe("NanobotClient", () => {
client.connect();
lastSocket().fakeOpen();
lastSocket().fakeCloseWithCode(1009);
// Despite the throwing handler, the client must still schedule a reconnect.
expect(seenStatuses).toContain("reconnecting");
await vi.advanceTimersByTimeAsync(20);
expect(FakeSocket.instances.length).toBeGreaterThan(1);
@@ -2627,7 +2613,6 @@ describe("NanobotClient", () => {
client.onStatus((s) => seen.push(s));
client.connect();
lastSocket().fakeOpen();
// Simulate the remote side hanging up (no client.close() call).
lastSocket().close();
await vi.advanceTimersByTimeAsync(50);
expect(seen).toContain("reconnecting");
@@ -205,7 +205,6 @@ describe("settings edit completion", () => {
});
});
// Exercise the real controller and portaled editor, not only the completion primitive.
describe("model editor completion boundaries", () => {
installSettingsViewTestHooks();
@@ -118,7 +118,6 @@ describe("useSkills", () => {
fireEvent.keyDown(input, { key: "Tab" });
expect(input).toHaveValue("$simple-pr-review ");
// A later open must also refresh removals without remounting the page.
vi.mocked(fetchSkills).mockResolvedValue({ skills: [] });
fireEvent.change(input, { target: { value: "$", selectionStart: 1 } });
await act(async () => {});
-1
View File
@@ -1,7 +1,6 @@
import { NanobotClient } from "@/lib/nanobot-client";
import type { InboundEvent } from "@/lib/types";
/** Real lifecycle and dispatch with an in-memory transport. */
export function createStreamClient() {
const socket = {
readyState: 1,
-6
View File
@@ -11,7 +11,6 @@ const CACHE_NAME = "nanobot-static-v2";
const ICON_CACHE_NAME = "nanobot-icons-v1";
const ICON_CACHE_LIMIT = 128;
/** Minimal Cache-compatible in-memory store with SW-style URL normalization. */
class FakeCacheStore {
entries = new Map<string, Response>();
@@ -287,7 +286,6 @@ describe("service worker", () => {
it("removes stale cache names and prunes unreferenced static entries on activate", async () => {
const sw = loadSw();
await sw.fire("install");
// Simulate the latest loaded build: index.html references only v2 assets.
await sw.store.put(`${ORIGIN}/`, indexHtml(["/assets/index-v2.js", "/assets/index-v2.css"]));
await sw.store.put(`${ORIGIN}/assets/index-v2.js`, new Response("v2"));
await sw.store.put(`${ORIGIN}/assets/index-v2.css`, new Response("v2 css"));
@@ -508,11 +506,9 @@ describe("service worker", () => {
it("serves navigation network-first, prunes on shell refresh, and falls back when offline", async () => {
const sw = loadSw();
await sw.store.put(`${ORIGIN}/`, indexHtml(["/assets/index-v2.js"]));
// Assets from an older build, still referenced by the cached v2 shell.
await sw.store.put(`${ORIGIN}/assets/index-v2.js`, new Response("v2"));
await sw.store.put(`${ORIGIN}/assets/index-v1.js`, new Response("v1"));
// Offline: network rejects, cached shell is returned.
sw.fetchMock.mockRejectedValue(new TypeError("Failed to fetch"));
const offlineEvent = {
request: new Request(`${ORIGIN}/`),
@@ -522,8 +518,6 @@ describe("service worker", () => {
const offlineResponse = (await offlineEvent.respondWith.mock.calls[0][0]) as Response;
expect(await offlineResponse.text()).toContain("assets/index-v2.js");
// Online: network response wins, refreshes the cached shell, and prunes
// entries the new index.html no longer references.
const freshShell = indexHtml(["/assets/index-v3.js"]);
sw.fetchMock.mockImplementation((input: Request | string) => {
const url = new URL(typeof input === "string" ? input : input.url, ORIGIN);
@@ -21,7 +21,6 @@ vi.mock("@/lib/bootstrap", async (importOriginal) => ({
deriveWsUrl: () => "ws://test",
}));
// Only the network is fake: App, the workbench, stream hook and multiplexed client are real.
class TestSocket {
static current: TestSocket;
readyState = 0;
-3
View File
@@ -2833,7 +2833,6 @@ describe("ThreadComposer", () => {
expect(screen.queryByText("MCP servers")).not.toBeInTheDocument();
const gimp = screen.getByRole("option", { name: /@gimp GIMP .* CLI/i });
const browserbase = screen.getByRole("option", { name: /@browserbase Browserbase .* MCP/i });
// Reuse the app's 44px coarse-pointer targets without changing desktop density.
expect(gimp).toHaveClass("touch-target");
expect(browserbase).toHaveClass("touch-target");
expect(within(gimp).getByText("CLI")).toBeInTheDocument();
@@ -3214,7 +3213,6 @@ describe("ThreadComposer", () => {
expect(palette).toHaveStyle({ maxHeight: "84px" });
expect(input.closest("form")).toHaveAttribute("data-palette-beside", "true");
// Rotation restores the ordinary floating menu, without changing the draft.
landscape = false;
document.getElementById("root")!.classList.remove("short-visual-viewport");
Object.assign(window.visualViewport!, { height: 396, offsetTop: 350 });
@@ -3620,7 +3618,6 @@ describe("ThreadComposer", () => {
const keyEvent = createEvent.keyDown(input, { key: "Enter" });
fireEvent(input, keyEvent);
// Enter inserts a newline on touch; the send button is the interject path.
expect(keyEvent.defaultPrevented).toBe(false);
expect(onSend).not.toHaveBeenCalled();
expect(screen.getByRole("button", { name: "Send message" })).toBeInTheDocument();
-2
View File
@@ -1555,7 +1555,6 @@ describe("ThreadShell", () => {
expect(client.sendSystemCommand).not.toHaveBeenCalled();
emit("notice-a", true);
expect(notice()).not.toBeInTheDocument();
// A new turn can notify again; it does not inherit the previous dismissal.
emit("notice-a", false);
emit("notice-a", true);
expect(notice()).toBeVisible();
@@ -5157,7 +5156,6 @@ describe("ThreadShell", () => {
),
);
// No banner yet: only appears once the client emits a matching error.
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
await act(async () => {});
@@ -554,7 +554,6 @@ describe("Workspace project picker", () => {
await waitFor(() => expect(input).toHaveValue("/srv/alpha/"));
expect(screen.getAllByRole("listbox")).toHaveLength(1);
await screen.findByRole("option", { name: "/srv/alpha/docs" });
// Once the address is complete, Tab leaves the input instead of entering docs.
await user.tab();
expect(input).not.toHaveFocus();
expect(input).toHaveValue("/srv/alpha/");