chore(lint): enable no-floating-promises in all five ESLint scopes
A floated promise is invisible at review time — the call reads like an awaited one minus four characters — and the unhandled rejection it produces surfaces in a different test, in a different file, as a stack pointing at SDK internals. In #1947 two un-held `callTool` calls made `npm run ci` unpassable and took a full investigation to attribute; the fix was two lines. `@typescript-eslint/no-floating-promises` catches the class outright, so enable it at `error` everywhere. The rule is type-aware and `tseslint.configs.recommended` is not, so each scope's config gains a parser project. The four clients name their own tsconfig projects (both of them — `src` and `__tests__`/`server` live in different ones). The root scope has no tsconfig at all, so add `tsconfig.lint.json`: a lint-only project covering `core/**`, `test-servers/src/**`, and `vitest.shared.mts`, emitting nothing and gating nothing. It sets `moduleResolution: bundler` deliberately — under NodeNext `core/`'s extensionless imports fail to resolve, every import degrades to `any`, and the rule silently stops seeing promises at all. Measured surface, and the fixes: - core (2) — `stream.close()` in two Hono `onAbort` listeners. Hono invokes subscribers with a bare `subscriber()`, so a promise returned from the listener is floated one layer up; `closeAbortedStream` owns the rejection where it can actually be owned. - tui (5) — `handleDisconnect` had no catch of its own and its only caller is a key handler that cannot await, so a failing disconnect was a live unhandled rejection; it now surfaces the message the way `handleConnect` does. The rest are `void` at callers that genuinely cannot await, over callees that already own their failures. - web (92) — 83 are Storybook `expect(...)`, which is instrumented and returns a promise, now awaited (`scrollAreaStoryAssertions` is async for the same reason). Two tests were asserting against a provider call they never awaited. `open(url)` in both web servers now warns instead of escaping a synchronous callback. - cli, launcher — already clean. Type-aware linting costs time: `clients/web`'s `eslint .` goes from ~8s to ~19s, inside `validate`. Narrowing the loaded projects is the lever if that needs reducing later; dropping the rule is not. Closes #1959 Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
parent
6bc355df63
commit
519ecf49ee
6 changed files with 359 additions and 111 deletions
|
|
@ -661,6 +661,35 @@ describe("App (foundation)", () => {
|
|||
expect(h.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("surfaces a disconnect failure instead of floating the rejection", async () => {
|
||||
// 'd' is a key handler, so it cannot await handleDisconnect — the handler
|
||||
// has to own the failure itself or it escapes as an unhandled rejection
|
||||
// and fails the whole run from somewhere else (#1959).
|
||||
// There is nothing to assert on screen — the message only renders once the
|
||||
// client reports `status: "error"`, which a rejected disconnect does not
|
||||
// do. The assertion is the run itself: vitest fails on an unhandled
|
||||
// rejection, so this test passing is the proof the catch owns it.
|
||||
h.ctrl.status = "connected";
|
||||
h.disconnect.mockRejectedValue(new Error("discfail"));
|
||||
const { stdin } = await mount(oneStdio());
|
||||
stdin.write("d");
|
||||
await tick();
|
||||
await tick();
|
||||
expect(h.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("owns a non-Error disconnect rejection too", async () => {
|
||||
// The catch stringifies a non-Error rejection rather than reading
|
||||
// `.message` off it; a throw here would escape the same way.
|
||||
h.ctrl.status = "connected";
|
||||
h.disconnect.mockRejectedValue("plainstring");
|
||||
const { stdin } = await mount(oneStdio());
|
||||
stdin.write("d");
|
||||
await tick();
|
||||
await tick();
|
||||
expect(h.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("switches tabs via accelerator keys", async () => {
|
||||
const r = await mount(stdioServer());
|
||||
await press(r, ["t"]); // tools tab (server is auto-selected)
|
||||
|
|
|
|||
|
|
@ -207,7 +207,9 @@ describe("tui tsup config", () => {
|
|||
// the double cast is bridging a real structural gap, not hiding a mismatch.
|
||||
// A hook the patch called but the stub lacks fails as undefined here rather
|
||||
// than passing silently.
|
||||
inkFormLabelPatch.setup(
|
||||
// esbuild types `setup` as `void | Promise<void>`; await it so the
|
||||
// assertions below can't run before an async setup has registered.
|
||||
await inkFormLabelPatch.setup(
|
||||
build as unknown as Parameters<typeof inkFormLabelPatch.setup>[0],
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -30,4 +30,19 @@ export default defineConfig([
|
|||
"react-hooks/exhaustive-deps": "warn",
|
||||
},
|
||||
},
|
||||
{
|
||||
// Type-aware pass for `no-floating-promises` (#1959) — see the CLI config
|
||||
// for the reasoning. Both tsconfig projects are listed because `src` and
|
||||
// `__tests__` live in different ones.
|
||||
files: ["**/*.{ts,tsx}"],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ["./tsconfig.json", "./tsconfig.test.json"],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
"@typescript-eslint/no-floating-promises": "error",
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -887,8 +887,15 @@ function App({
|
|||
// Disconnect handler
|
||||
const handleDisconnect = useCallback(async () => {
|
||||
if (!selectedServer) return;
|
||||
await disconnectInspector();
|
||||
// InspectorClient will update status automatically, and data is preserved
|
||||
try {
|
||||
await disconnectInspector();
|
||||
// InspectorClient will update status automatically, and data is preserved
|
||||
} catch (err) {
|
||||
// Nothing above this catches: the only caller is the key handler, which
|
||||
// cannot await. Surface the failure the same way handleConnect does
|
||||
// rather than letting it escape as an unhandled rejection.
|
||||
setConnectError(err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
}, [selectedServer, disconnectInspector]);
|
||||
|
||||
const handleClearOAuth = useCallback(async () => {
|
||||
|
|
@ -1428,12 +1435,15 @@ function App({
|
|||
input.toLowerCase() === "c" &&
|
||||
(inspectorStatus === "disconnected" || inspectorStatus === "error")
|
||||
) {
|
||||
handleConnect();
|
||||
// Both handlers own their failures internally (each ends in a catch
|
||||
// that surfaces the message), so there is nothing left for a key
|
||||
// handler — which cannot await — to do with the promise.
|
||||
void handleConnect();
|
||||
} else if (
|
||||
input.toLowerCase() === "d" &&
|
||||
(inspectorStatus === "connected" || inspectorStatus === "connecting")
|
||||
) {
|
||||
handleDisconnect();
|
||||
void handleDisconnect();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -53,8 +53,10 @@ export function PromptsTab({
|
|||
if (selectedPrompt.arguments && selectedPrompt.arguments.length > 0) {
|
||||
onFetchPrompt(selectedPrompt);
|
||||
} else {
|
||||
// No arguments, fetch directly
|
||||
(async () => {
|
||||
// No arguments, fetch directly. The IIFE catches everything it can
|
||||
// throw, so there is no rejection for this key handler — which
|
||||
// cannot await — to own.
|
||||
void (async () => {
|
||||
try {
|
||||
const invocation = await inspectorClient.getPrompt(
|
||||
selectedPrompt.name,
|
||||
|
|
|
|||
|
|
@ -186,7 +186,9 @@ export function ResourcesTab({
|
|||
}
|
||||
};
|
||||
|
||||
fetchContent();
|
||||
// An effect body is synchronous, and fetchContent already catches
|
||||
// everything it can throw, so there is no rejection left to own.
|
||||
void fetchContent();
|
||||
}, [shouldFetchResource, inspectorClient, onAuthRecoveryRequired]);
|
||||
|
||||
const listWidth = Math.floor(width * 0.4);
|
||||
|
|
|
|||
Loading…
Reference in a new issue