Skip to content

Commit 9fc036d

Browse files
author
Eva
committed
fix(workspaces): satisfy pubsub lint and export gates
1 parent b651b4d commit 9fc036d

4 files changed

Lines changed: 33 additions & 28 deletions

File tree

ui/src/components/workspace-custom-widget.test.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -359,17 +359,22 @@ describe("attachWidgetBridge parent-brokered pub/sub", () => {
359359
const filter = connected({ id: "filter", tabSlug: "a", bus });
360360
const chart = connected({ id: "chart", tabSlug: "a", bus });
361361
const otherTab = connected({ id: "other", tabSlug: "b", bus });
362-
chart.childPort.postMessage({ v: 1, type: "workspace:subscribe", channel: "selection" });
363-
otherTab.childPort.postMessage({ v: 1, type: "workspace:subscribe", channel: "selection" });
362+
chart.childPort.postMessage({ v: 1, type: "workspace:subscribe", channel: "selection" }, []);
363+
otherTab.childPort.postMessage({ v: 1, type: "workspace:subscribe", channel: "selection" }, []);
364364
// MessagePorts are ordered individually, not across distinct ports. Let both
365365
// subscriptions reach the parent before publishing from the third port.
366-
await new Promise((resolve) => setTimeout(resolve, 0));
367-
filter.childPort.postMessage({
368-
v: 1,
369-
type: "workspace:publish",
370-
channel: "selection",
371-
payload: { region: "eu" },
366+
await new Promise<void>((resolve) => {
367+
setTimeout(resolve, 0);
372368
});
369+
filter.childPort.postMessage(
370+
{
371+
v: 1,
372+
type: "workspace:publish",
373+
channel: "selection",
374+
payload: { region: "eu" },
375+
},
376+
[],
377+
);
373378

374379
await vi.waitFor(() => expect(chart.posts).toHaveLength(1));
375380
expect(chart.posts[0]).toEqual({
@@ -391,19 +396,26 @@ describe("attachWidgetBridge parent-brokered pub/sub", () => {
391396
const bus = createWorkspaceWidgetBus();
392397
const publisher = connected({ id: "publisher", tabSlug: "removed", bus });
393398
const subscriber = connected({ id: "subscriber", tabSlug: "removed", bus });
394-
subscriber.childPort.postMessage({ v: 1, type: "workspace:subscribe", channel: "updates" });
395-
await new Promise((resolve) => setTimeout(resolve, 0));
399+
subscriber.childPort.postMessage({ v: 1, type: "workspace:subscribe", channel: "updates" }, []);
400+
await new Promise<void>((resolve) => {
401+
setTimeout(resolve, 0);
402+
});
396403

397404
subscriber.detach();
398-
publisher.childPort.postMessage({
399-
v: 1,
400-
type: "workspace:publish",
401-
channel: "updates",
402-
payload: 1,
403-
});
405+
publisher.childPort.postMessage(
406+
{
407+
v: 1,
408+
type: "workspace:publish",
409+
channel: "updates",
410+
payload: 1,
411+
},
412+
[],
413+
);
404414
bus.retainTabs(new Set());
405415
bus.dispose();
406-
await new Promise((resolve) => setTimeout(resolve, 0));
416+
await new Promise<void>((resolve) => {
417+
setTimeout(resolve, 0);
418+
});
407419

408420
expect(subscriber.posts).toHaveLength(0);
409421
publisher.detach();

ui/src/lib/workspace/bridge.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
22
import {
33
createWidgetBridge,
44
isWellFormedInbound,
5-
resetBusRateStatesForTest,
65
resetPromptRateStatesForTest,
76
type WidgetBridgeDeps,
8-
type WidgetBusBridge,
97
type WidgetErrorCode,
108
type WidgetOutboundMessage,
119
} from "./bridge.ts";
@@ -14,7 +12,6 @@ import type { WidgetManifestView } from "./types.ts";
1412
beforeEach(() => {
1513
// Rate-limit state is module-level (keyed by widget name); reset between tests.
1614
resetPromptRateStatesForTest();
17-
resetBusRateStatesForTest();
1815
});
1916

2017
function manifest(overrides?: Partial<WidgetManifestView>): WidgetManifestView {
@@ -245,7 +242,7 @@ describe("pub/sub capability + limits + cleanup", () => {
245242
function fakeBus() {
246243
const published: Array<{ channel: string; payload: unknown }> = [];
247244
const subscriptions = new Map<string, (channel: string, payload: unknown) => void>();
248-
const bus: WidgetBusBridge = {
245+
const bus: NonNullable<WidgetBridgeDeps["bus"]> = {
249246
publish: (channel, payload) => published.push({ channel, payload }),
250247
subscribe: (channel, deliver) => {
251248
subscriptions.set(channel, deliver);

ui/src/lib/workspace/bridge.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export type WidgetOutboundMessage =
5050
| { v: 1; type: "workspace:message"; channel: string; payload: unknown }
5151
| { v: 1; type: "workspace:error"; requestId?: string; code: WidgetErrorCode; message: string };
5252

53-
export type WidgetBusBridge = {
53+
type WidgetBusBridge = {
5454
publish: (channel: string, payload: unknown) => void;
5555
subscribe: (channel: string, deliver: (channel: string, payload: unknown) => void) => () => void;
5656
};
@@ -124,6 +124,7 @@ function getPromptRateState(widgetName: string): PromptRateState {
124124
/** Test-only: reset all persisted rate-limit budgets. */
125125
export function resetPromptRateStatesForTest(): void {
126126
promptRateStates.clear();
127+
busRateStates.clear();
127128
}
128129

129130
type BusRateState = { timestamps: number[] };
@@ -138,11 +139,6 @@ function getBusRateState(widgetName: string): BusRateState {
138139
return state;
139140
}
140141

141-
/** Test-only: reset all persisted pub/sub rate-limit budgets. */
142-
export function resetBusRateStatesForTest(): void {
143-
busRateStates.clear();
144-
}
145-
146142
function isStrictJsonValue(root: unknown): boolean {
147143
const ancestors = new Set<object>();
148144
const stack: Array<{ value: unknown; exit?: boolean }> = [{ value: root }];

ui/src/lib/workspace/bus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** Parent-owned, in-memory pub/sub for custom widgets in one Workspaces view. */
22

3-
export type WorkspaceWidgetBusConnection = {
3+
type WorkspaceWidgetBusConnection = {
44
publish: (channel: string, payload: unknown) => number;
55
subscribe: (channel: string, deliver: (channel: string, payload: unknown) => void) => () => void;
66
dispose: () => void;

0 commit comments

Comments
 (0)