Update hivegrid-cloud reference to latest main

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
davidandClaude Fable 5 committed 2026-07-08 16:15:37 +02:00
1 parent e98d38e716
commit 7b21524c86
3781 files changed
+373484 -225607

No files matched your search

@@ -1,4 +1,4 @@
import { describe, expect, expectTypeOf, test } from "vitest";
import { afterEach, describe, expect, expectTypeOf, test, vi } from "vitest";
import {
createPluginSettingsClient,
defineHook,
@@ -33,7 +33,7 @@ function makeContext(overrides: Partial<PluginContext> = {}): PluginContext {
error: () => undefined,
};
return {
pluginId: "de.toolctrl.test",
pluginId: "de.hivegrid.test",
pluginVersion: "1.0.0",
tenantId: "t-1",
hookName: "ping",
@@ -73,14 +73,14 @@ function makeSettingsFrameWindow() {
};
}
describe("@toolctrl/plugin-sdk", () => {
describe("@hivegrid/plugin-sdk", () => {
test("exports a stable version constant", () => {
expect(PLUGIN_SDK_PACKAGE_VERSION).toBe("0.0.0");
});
test("exports the structured payload ABI contract", () => {
expect(PLUGIN_PAYLOAD_ABI_VERSION).toBe(1);
expect(PLUGIN_PAYLOAD_ABI_IMPORTS).toEqual(["env.toolctrl_payload_len", "env.toolctrl_payload_byte"]);
expect(PLUGIN_PAYLOAD_ABI_IMPORTS).toEqual(["env.hivegrid_payload_len", "env.hivegrid_payload_byte"]);
});
test("exports the settings iframe postMessage protocol contract", () => {
@@ -90,7 +90,7 @@ describe("@toolctrl/plugin-sdk", () => {
const getMessage: PluginSettingsFrameGetMessage = {
type: "plugin.settings.get",
version: PLUGIN_SETTINGS_FRAME_PROTOCOL_VERSION,
pluginId: "de.toolctrl.test",
pluginId: "de.hivegrid.test",
channelId: "channel-1",
requestId: "get-1",
key: "theme",
@@ -98,7 +98,7 @@ describe("@toolctrl/plugin-sdk", () => {
const setMessage: PluginSettingsFrameSetMessage = {
type: "plugin.settings.set",
version: PLUGIN_SETTINGS_FRAME_PROTOCOL_VERSION,
pluginId: "de.toolctrl.test",
pluginId: "de.hivegrid.test",
channelId: "channel-1",
requestId: "set-1",
key: "theme",
@@ -107,7 +107,7 @@ describe("@toolctrl/plugin-sdk", () => {
const resultMessage: PluginSettingsFrameResultMessage = {
type: "plugin.settings.result",
version: PLUGIN_SETTINGS_FRAME_PROTOCOL_VERSION,
pluginId: "de.toolctrl.test",
pluginId: "de.hivegrid.test",
channelId: "channel-1",
requestId: "get-1",
ok: true,
@@ -127,7 +127,7 @@ describe("@toolctrl/plugin-sdk", () => {
test("createPluginSettingsClient posts ready, get, and set messages", async () => {
const frameWindow = makeSettingsFrameWindow();
const client = createPluginSettingsClient({
pluginId: "de.toolctrl.test",
pluginId: "de.hivegrid.test",
channelId: "channel-1",
targetOrigin: "https://app.example.test",
requestId: () => "request-1",
@@ -144,7 +144,7 @@ describe("@toolctrl/plugin-sdk", () => {
message: {
type: "plugin.settings.ready",
version: PLUGIN_SETTINGS_FRAME_PROTOCOL_VERSION,
pluginId: "de.toolctrl.test",
pluginId: "de.hivegrid.test",
channelId: "channel-1",
requestId: "ready-1",
},
@@ -154,7 +154,7 @@ describe("@toolctrl/plugin-sdk", () => {
message: {
type: "plugin.settings.get",
version: PLUGIN_SETTINGS_FRAME_PROTOCOL_VERSION,
pluginId: "de.toolctrl.test",
pluginId: "de.hivegrid.test",
channelId: "channel-1",
requestId: "request-1",
key: "theme",
@@ -165,7 +165,7 @@ describe("@toolctrl/plugin-sdk", () => {
message: {
type: "plugin.settings.set",
version: PLUGIN_SETTINGS_FRAME_PROTOCOL_VERSION,
pluginId: "de.toolctrl.test",
pluginId: "de.hivegrid.test",
channelId: "channel-1",
requestId: "set-1",
key: "mode",
@@ -179,7 +179,7 @@ describe("@toolctrl/plugin-sdk", () => {
data: {
type: "plugin.settings.result",
version: PLUGIN_SETTINGS_FRAME_PROTOCOL_VERSION,
pluginId: "de.toolctrl.test",
pluginId: "de.hivegrid.test",
channelId: "channel-1",
requestId: "request-1",
ok: true,
@@ -192,7 +192,7 @@ describe("@toolctrl/plugin-sdk", () => {
data: {
type: "plugin.settings.result",
version: PLUGIN_SETTINGS_FRAME_PROTOCOL_VERSION,
pluginId: "de.toolctrl.test",
pluginId: "de.hivegrid.test",
channelId: "channel-1",
requestId: "set-1",
ok: true,
@@ -210,7 +210,7 @@ describe("@toolctrl/plugin-sdk", () => {
test("createPluginSettingsClient reads the injected channel meta tag", () => {
const frameWindow = makeSettingsFrameWindow();
const client = createPluginSettingsClient({
pluginId: "de.toolctrl.test",
pluginId: "de.hivegrid.test",
window: frameWindow,
document: {
querySelector: (selector) => {
@@ -227,7 +227,7 @@ describe("@toolctrl/plugin-sdk", () => {
test("createPluginSettingsClient ignores result messages that do not match the parent and request scope", async () => {
const frameWindow = makeSettingsFrameWindow();
const client = createPluginSettingsClient({
pluginId: "de.toolctrl.test",
pluginId: "de.hivegrid.test",
channelId: "channel-1",
timeoutMs: 0,
window: frameWindow,
@@ -235,10 +235,10 @@ describe("@toolctrl/plugin-sdk", () => {
const promise = client.get("theme", { requestId: "get-1" });
for (const data of [
{ version: 2, pluginId: "de.toolctrl.test", channelId: "channel-1", requestId: "get-1" },
{ version: 2, pluginId: "de.hivegrid.test", channelId: "channel-1", requestId: "get-1" },
{ version: PLUGIN_SETTINGS_FRAME_PROTOCOL_VERSION, pluginId: "other", channelId: "channel-1", requestId: "get-1" },
{ version: PLUGIN_SETTINGS_FRAME_PROTOCOL_VERSION, pluginId: "de.toolctrl.test", channelId: "other", requestId: "get-1" },
{ version: PLUGIN_SETTINGS_FRAME_PROTOCOL_VERSION, pluginId: "de.toolctrl.test", channelId: "channel-1", requestId: "other" },
{ version: PLUGIN_SETTINGS_FRAME_PROTOCOL_VERSION, pluginId: "de.hivegrid.test", channelId: "other", requestId: "get-1" },
{ version: PLUGIN_SETTINGS_FRAME_PROTOCOL_VERSION, pluginId: "de.hivegrid.test", channelId: "channel-1", requestId: "other" },
]) {
frameWindow.emit({
source: frameWindow.parent,
@@ -257,7 +257,7 @@ describe("@toolctrl/plugin-sdk", () => {
data: {
type: "plugin.settings.result",
version: PLUGIN_SETTINGS_FRAME_PROTOCOL_VERSION,
pluginId: "de.toolctrl.test",
pluginId: "de.hivegrid.test",
channelId: "channel-1",
requestId: "get-1",
ok: true,
@@ -270,7 +270,7 @@ describe("@toolctrl/plugin-sdk", () => {
data: {
type: "plugin.settings.result",
version: PLUGIN_SETTINGS_FRAME_PROTOCOL_VERSION,
pluginId: "de.toolctrl.test",
pluginId: "de.hivegrid.test",
channelId: "channel-1",
requestId: "get-1",
ok: true,
@@ -286,7 +286,7 @@ describe("@toolctrl/plugin-sdk", () => {
test("createPluginSettingsClient rejects host errors and mismatched response keys", async () => {
const frameWindow = makeSettingsFrameWindow();
const client = createPluginSettingsClient({
pluginId: "de.toolctrl.test",
pluginId: "de.hivegrid.test",
channelId: "channel-1",
timeoutMs: 0,
window: frameWindow,
@@ -298,7 +298,7 @@ describe("@toolctrl/plugin-sdk", () => {
data: {
type: "plugin.settings.result",
version: PLUGIN_SETTINGS_FRAME_PROTOCOL_VERSION,
pluginId: "de.toolctrl.test",
pluginId: "de.hivegrid.test",
channelId: "channel-1",
requestId: "set-1",
ok: false,
@@ -316,7 +316,7 @@ describe("@toolctrl/plugin-sdk", () => {
data: {
type: "plugin.settings.result",
version: PLUGIN_SETTINGS_FRAME_PROTOCOL_VERSION,
pluginId: "de.toolctrl.test",
pluginId: "de.hivegrid.test",
channelId: "channel-1",
requestId: "get-1",
ok: true,
@@ -332,7 +332,7 @@ describe("@toolctrl/plugin-sdk", () => {
test("createPluginSettingsClient rejects timed out requests", async () => {
const frameWindow = makeSettingsFrameWindow();
const client = createPluginSettingsClient({
pluginId: "de.toolctrl.test",
pluginId: "de.hivegrid.test",
channelId: "channel-1",
timeoutMs: 1,
window: frameWindow,
@@ -459,3 +459,179 @@ describe("@toolctrl/plugin-sdk", () => {
expect(result).toEqual({ changed: 1 });
});
});
describe("createPluginSettingsClient default-environment + lifecycle coverage", () => {
afterEach(() => {
vi.unstubAllGlobals();
});
test("throws when the default window has no parent postMessage target", () => {
vi.stubGlobal("window", undefined);
expect(() => createPluginSettingsClient({ pluginId: "de.hivegrid.test", channelId: "channel-1" })).toThrow(
"Plugin settings client requires a window with a parent postMessage target"
);
});
test("ignores a default window that is missing a parent", () => {
vi.stubGlobal("window", { addEventListener: () => undefined, removeEventListener: () => undefined });
expect(() => createPluginSettingsClient({ pluginId: "de.hivegrid.test", channelId: "channel-1" })).toThrow(
"Plugin settings client requires a window with a parent postMessage target"
);
});
test("ignores a default window whose parent is present but lacks addEventListener", () => {
vi.stubGlobal("window", { parent: { postMessage: () => undefined }, removeEventListener: () => undefined });
expect(() => createPluginSettingsClient({ pluginId: "de.hivegrid.test", channelId: "channel-1" })).toThrow(
"Plugin settings client requires a window with a parent postMessage target"
);
});
test("ignores a default window that lacks removeEventListener", () => {
vi.stubGlobal("window", { parent: { postMessage: () => undefined }, addEventListener: () => undefined });
expect(() => createPluginSettingsClient({ pluginId: "de.hivegrid.test", channelId: "channel-1" })).toThrow(
"Plugin settings client requires a window with a parent postMessage target"
);
});
test("falls back to the default window when no window option is given", () => {
const frameWindow = makeSettingsFrameWindow();
vi.stubGlobal("window", frameWindow);
const client = createPluginSettingsClient({ pluginId: "de.hivegrid.test", channelId: "channel-1" });
expect(frameWindow.listenerCount()).toBe(1);
client.ready();
expect(frameWindow.posted).toHaveLength(1);
client.destroy();
expect(frameWindow.listenerCount()).toBe(0);
});
test("reads the channel id from the default document meta tag", () => {
const frameWindow = makeSettingsFrameWindow();
vi.stubGlobal("document", {
querySelector: (selector: string) => {
expect(selector).toBe(`meta[name="${PLUGIN_SETTINGS_FRAME_CHANNEL_META_NAME}"]`);
return { getAttribute: () => "default-doc-channel" };
},
});
const client = createPluginSettingsClient({ pluginId: "de.hivegrid.test", window: frameWindow });
expect(client.channelId).toBe("default-doc-channel");
client.destroy();
});
test("throws on a missing channel when the default document has no matching meta tag", () => {
const frameWindow = makeSettingsFrameWindow();
vi.stubGlobal("document", { querySelector: () => null });
expect(() => createPluginSettingsClient({ pluginId: "de.hivegrid.test", window: frameWindow })).toThrow(
"Missing plugin settings channel"
);
});
test("ignores a default document without a querySelector and throws on the missing channel", () => {
const frameWindow = makeSettingsFrameWindow();
vi.stubGlobal("document", {});
expect(() => createPluginSettingsClient({ pluginId: "de.hivegrid.test", window: frameWindow })).toThrow(
"Missing plugin settings channel"
);
});
test("ignores an absent default document and throws on the missing channel", () => {
const frameWindow = makeSettingsFrameWindow();
vi.stubGlobal("document", undefined);
expect(() => createPluginSettingsClient({ pluginId: "de.hivegrid.test", window: frameWindow })).toThrow(
"Missing plugin settings channel"
);
});
test("throws when the channel meta tag is present but empty", () => {
const frameWindow = makeSettingsFrameWindow();
expect(() =>
createPluginSettingsClient({
pluginId: "de.hivegrid.test",
window: frameWindow,
document: { querySelector: () => ({ getAttribute: () => null }) },
})
).toThrow("Missing plugin settings channel");
});
test("throws when the channel meta tag is absent", () => {
const frameWindow = makeSettingsFrameWindow();
expect(() =>
createPluginSettingsClient({
pluginId: "de.hivegrid.test",
window: frameWindow,
document: { querySelector: () => null },
})
).toThrow("Missing plugin settings channel");
});
test("generates sequential request ids when none are provided", async () => {
const frameWindow = makeSettingsFrameWindow();
const client = createPluginSettingsClient({
pluginId: "de.hivegrid.test",
channelId: "channel-1",
timeoutMs: 0,
window: frameWindow,
});
const first = client.get("a");
const second = client.set("b", 7);
const ids = frameWindow.posted.map((entry) => (entry.message as { requestId?: string }).requestId);
expect(ids).toEqual(["plugin-settings-1", "plugin-settings-2"]);
for (const [requestId, key, value] of [
["plugin-settings-1", "a", 1],
["plugin-settings-2", "b", 7],
] as const) {
frameWindow.emit({
source: frameWindow.parent,
data: {
type: "plugin.settings.result",
version: PLUGIN_SETTINGS_FRAME_PROTOCOL_VERSION,
pluginId: "de.hivegrid.test",
channelId: "channel-1",
requestId,
ok: true,
key,
value,
},
});
}
await expect(first).resolves.toBe(1);
await expect(second).resolves.toBe(7);
client.destroy();
});
test("destroy rejects pending requests and clears their active timeouts", async () => {
const frameWindow = makeSettingsFrameWindow();
const client = createPluginSettingsClient({
pluginId: "de.hivegrid.test",
channelId: "channel-1",
timeoutMs: 60_000,
window: frameWindow,
});
const pending = client.get("theme", { requestId: "get-1" });
client.destroy();
await expect(pending).rejects.toThrow("Plugin settings client destroyed before response: get-1");
expect(frameWindow.listenerCount()).toBe(0);
});
test("destroy rejects pending requests that were created without an active timeout", async () => {
const frameWindow = makeSettingsFrameWindow();
const client = createPluginSettingsClient({
pluginId: "de.hivegrid.test",
channelId: "channel-1",
timeoutMs: 0,
window: frameWindow,
});
const pending = client.set("theme", "dark", { requestId: "set-1" });
client.destroy();
await expect(pending).rejects.toThrow("Plugin settings client destroyed before response: set-1");
});
});
@@ -1,5 +1,5 @@
/**
* @toolctrl/plugin-sdk — Phase 06 Task #21 foundation.
* @hivegrid/plugin-sdk — Phase 06 Task #21 foundation.
*
* Type definitions plugin authors `import` against. The package ships
* type-only declarations in this foundation step; the AssemblyScript /
@@ -8,7 +8,7 @@
*
* Authoring shape:
*
* import type { HookHandler, PluginContext } from "@toolctrl/plugin-sdk";
* import type { HookHandler, PluginContext } from "@hivegrid/plugin-sdk";
*
* export const handleHello: HookHandler<{ name: string }, { greeting: string }> = (
* input,
@@ -21,13 +21,13 @@
export const PLUGIN_SDK_PACKAGE_VERSION = "0.0.0";
export const PLUGIN_PAYLOAD_ABI_VERSION = 1;
export const PLUGIN_PAYLOAD_ABI_IMPORTS = ["env.toolctrl_payload_len", "env.toolctrl_payload_byte"] as const;
export const PLUGIN_PAYLOAD_ABI_IMPORTS = ["env.hivegrid_payload_len", "env.hivegrid_payload_byte"] as const;
export const PLUGIN_SETTINGS_FRAME_PROTOCOL_VERSION = 1;
export const PLUGIN_SETTINGS_FRAME_CHANNEL_META_NAME = "plugin-settings-channel";
/**
* Capability names a host exposes to a plugin — mirrors the closed enum
* in `@toolctrl/plugin-runtime`. Kept duplicated here so plugin authors
* in `@hivegrid/plugin-runtime`. Kept duplicated here so plugin authors
* don't need to install the runtime package as a build-time dep.
*/
export type PluginCapabilityName =
@@ -44,7 +44,7 @@ export type PluginCapabilityName =
/**
* Foundation hook names the host can emit. Mirrors the runtime hook
* registry so plugin authors can type their handlers without importing
* `@toolctrl/plugin-runtime`.
* `@hivegrid/plugin-runtime`.
*/
export type PluginHookName =
| "tenant.created"