Wenchao An e2f19d8335
feat(plugins): full-stack plugin APIs and bookmarks (#5647)
* feat(plugins): add full-stack contributions and bookmarks example

* ci(plugins): provision bookmark gateway for browser tests

* fix(plugins): authenticate module downloads through configured backend

* fix(plugins): isolate contributions and localize extension UI

* fix(plugins): preserve bookmark agent routing and contain async callbacks

* fix(plugins): pin durable batch workers to app extension snapshots
2026-09-22 11:18:57 +08:00

63 lines
2.0 KiB
TypeScript

import { expect, rs, test } from "@rstest/core";
import { resolveConversationActions } from "@/core/extensions/actions";
import type { FrontendExtension } from "@/core/extensions/contracts";
import { enUS } from "@/core/i18n";
for (const callback of ["factory", "availability", "thenable"]) {
test(`contains rejected asynchronous ${callback} without an unhandled rejection`, async () => {
const warning = rs
.spyOn(console, "warn")
.mockImplementation(() => undefined);
try {
const rejected = () => Promise.reject(new Error("invalid async plugin"));
const extension = {
conversationActions:
callback === "factory"
? rejected
: () => ({
label: "Broken",
icon: "bookmark",
actions: [
{
id: "save",
label: "Save",
icon: "bookmark",
execute: async () => undefined,
available:
callback === "thenable"
? () => ({
then: (
_resolve: unknown,
reject: (error: Error) => void,
) => reject(new Error("invalid thenable")),
})
: rejected,
},
],
}),
} as unknown as FrontendExtension;
expect(
resolveConversationActions(
extension,
{
namespace: "broken",
module: null,
entry: null,
title: "Broken",
description: "",
settings: {},
},
enUS,
"en-US",
),
).toBeUndefined();
// Give rejected promises a full event-loop turn. Rstest fails on unhandled rejections.
await new Promise((resolve) => setTimeout(resolve, 0));
expect(warning).toHaveBeenCalledTimes(1);
} finally {
warning.mockRestore();
}
});
}