open-design/packages/sidecar-proto/tests/index.test.ts
marco 5dd70b5016
Some checks failed
ci / Validate workspace (push) Successful in 12m32s
landing-page-ci / Validate landing page (push) Successful in 9m41s
landing-page-deploy / Deploy landing page (push) Failing after 5m23s
github-metrics / Generate repository metrics SVG (push) Failing after 2m3s
refresh-contributors-wall / Refresh contributors wall cache bust (push) Failing after 11s
Initial import: open-design source for helix-mind.ai distribution
This repository contains the open-design daemon CLI source code, built
and packaged at https://helix-mind.ai/cli/open-design/latest.tgz for use
by the HelixMind /design slash command.

Licenses: Apache-2.0 (root) + MIT (skills/*)
2026-05-06 20:50:24 +02:00

78 lines
2.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
APP_KEYS,
normalizeDaemonSidecarMessage,
normalizeDesktopSidecarMessage,
normalizeNamespace,
normalizeSidecarStamp,
OPEN_DESIGN_SIDECAR_CONTRACT,
SIDECAR_MESSAGES,
SIDECAR_SOURCES,
SIDECAR_STAMP_FIELDS,
STAMP_APP_FLAG,
STAMP_IPC_FLAG,
STAMP_MODE_FLAG,
STAMP_NAMESPACE_FLAG,
STAMP_SOURCE_FLAG,
} from "../src/index.js";
const validStamp = {
app: APP_KEYS.WEB,
ipc: "/tmp/open-design/ipc/contract-check/web.sock",
mode: "dev" as const,
namespace: "contract-check",
source: SIDECAR_SOURCES.TOOLS_DEV,
};
describe("open-design sidecar contract", () => {
it("exports the canonical five-field stamp descriptor", () => {
expect(SIDECAR_STAMP_FIELDS).toEqual(["app", "mode", "namespace", "ipc", "source"]);
expect(OPEN_DESIGN_SIDECAR_CONTRACT.stampFlags).toEqual({
app: STAMP_APP_FLAG,
ipc: STAMP_IPC_FLAG,
mode: STAMP_MODE_FLAG,
namespace: STAMP_NAMESPACE_FLAG,
source: STAMP_SOURCE_FLAG,
});
});
it("accepts the explicit namespace contract", () => {
expect(normalizeNamespace("contract-check_1.alpha")).toBe("contract-check_1.alpha");
});
it("rejects path-like or whitespace namespaces", () => {
expect(() => normalizeNamespace("../other")).toThrow();
expect(() => normalizeNamespace(" contract-check")).toThrow();
expect(() => normalizeNamespace("contract check")).toThrow();
});
it("accepts exactly app, mode, namespace, ipc, and source", () => {
expect(normalizeSidecarStamp(validStamp)).toEqual(validStamp);
});
it("rejects legacy or extra stamp fields", () => {
expect(() => normalizeSidecarStamp({ ...validStamp, runtimeToken: "legacy" })).toThrow();
expect(() => normalizeSidecarStamp({ ...validStamp, role: "web-sidecar" })).toThrow();
});
it("rejects non-contract sidecar sources", () => {
expect(() => normalizeSidecarStamp({ ...validStamp, source: "custom-script" })).toThrow();
});
it("validates daemon IPC messages", () => {
expect(normalizeDaemonSidecarMessage({ type: SIDECAR_MESSAGES.STATUS })).toEqual({ type: "status" });
expect(normalizeDaemonSidecarMessage({ type: SIDECAR_MESSAGES.SHUTDOWN })).toEqual({ type: "shutdown" });
expect(() => normalizeDaemonSidecarMessage({ input: {}, type: SIDECAR_MESSAGES.EVAL })).toThrow();
});
it("validates desktop IPC message inputs", () => {
expect(normalizeDesktopSidecarMessage({ input: { expression: "location.href" }, type: SIDECAR_MESSAGES.EVAL })).toEqual({
input: { expression: "location.href" },
type: "eval",
});
expect(() => normalizeDesktopSidecarMessage({ input: { expression: 42 }, type: SIDECAR_MESSAGES.EVAL })).toThrow();
expect(() => normalizeDesktopSidecarMessage({ input: { selector: "" }, type: SIDECAR_MESSAGES.CLICK })).toThrow();
});
});