summaryrefslogtreecommitdiffhomepage
path: root/packages/wire/src/index.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/wire/src/index.test.ts')
-rw-r--r--packages/wire/src/index.test.ts126
1 files changed, 80 insertions, 46 deletions
diff --git a/packages/wire/src/index.test.ts b/packages/wire/src/index.test.ts
index cd297b7..2886ccb 100644
--- a/packages/wire/src/index.test.ts
+++ b/packages/wire/src/index.test.ts
@@ -8,52 +8,86 @@
*/
import { describe, expect, it } from "vitest";
-import type { Computer, ComputerEntry, Workspace } from "./index.js";
+import type { Chunk, Computer, ComputerEntry, ImageChunk, ImageInput, Workspace } from "./index.js";
describe("@dispatch/wire — Computer / Workspace shapes", () => {
- it("a Computer literal satisfies the Computer type", () => {
- const c: Computer = {
- alias: "myserver",
- hostName: "myserver.example.com",
- port: 22,
- user: "deploy",
- identityFile: null,
- knownHost: true,
- };
- expect(c.alias).toBe("myserver");
- expect(c.port).toBe(22);
- expect(c.identityFile).toBeNull();
- expect(c.knownHost).toBe(true);
- });
-
- it("ComputerEntry extends Computer and carries usageCount", () => {
- const entry: ComputerEntry = {
- alias: "buildbox",
- hostName: "buildbox",
- port: 2222,
- user: "root",
- identityFile: "/home/u/.ssh/id_ed25519",
- knownHost: false,
- usageCount: 3,
- };
- // Compile-time proof that ComputerEntry is assignable to Computer.
- const asComputer: Computer = entry;
- expect(asComputer.alias).toBe("buildbox");
- expect(entry.usageCount).toBe(3);
- });
-
- it("a Workspace carries defaultComputerId (null = local)", () => {
- const remote: Workspace = {
- id: "default",
- title: "Default",
- defaultCwd: null,
- defaultComputerId: "myserver",
- createdAt: 0,
- lastActivityAt: 0,
- };
- expect(remote.defaultComputerId).toBe("myserver");
-
- const local: Workspace = { ...remote, defaultComputerId: null };
- expect(local.defaultComputerId).toBeNull();
- });
+ it("a Computer literal satisfies the Computer type", () => {
+ const c: Computer = {
+ alias: "myserver",
+ hostName: "myserver.example.com",
+ port: 22,
+ user: "deploy",
+ identityFile: null,
+ knownHost: true,
+ };
+ expect(c.alias).toBe("myserver");
+ expect(c.port).toBe(22);
+ expect(c.identityFile).toBeNull();
+ expect(c.knownHost).toBe(true);
+ });
+
+ it("ComputerEntry extends Computer and carries usageCount", () => {
+ const entry: ComputerEntry = {
+ alias: "buildbox",
+ hostName: "buildbox",
+ port: 2222,
+ user: "root",
+ identityFile: "/home/u/.ssh/id_ed25519",
+ knownHost: false,
+ usageCount: 3,
+ };
+ // Compile-time proof that ComputerEntry is assignable to Computer.
+ const asComputer: Computer = entry;
+ expect(asComputer.alias).toBe("buildbox");
+ expect(entry.usageCount).toBe(3);
+ });
+
+ it("a Workspace carries defaultComputerId (null = local) and starred", () => {
+ const remote: Workspace = {
+ id: "default",
+ title: "Default",
+ defaultCwd: null,
+ defaultComputerId: "myserver",
+ starred: false,
+ createdAt: 0,
+ lastActivityAt: 0,
+ };
+ expect(remote.defaultComputerId).toBe("myserver");
+ expect(remote.starred).toBe(false);
+
+ const local: Workspace = { ...remote, defaultComputerId: null };
+ expect(local.defaultComputerId).toBeNull();
+
+ const starred: Workspace = { ...remote, starred: true };
+ expect(starred.starred).toBe(true);
+ });
+});
+
+describe("@dispatch/wire — ImageChunk / ImageInput shapes", () => {
+ it("an ImageChunk carries a data URL and optional mimeType", () => {
+ const c: ImageChunk = {
+ type: "image",
+ url: "data:image/png;base64,iVBORw0KGgo=",
+ mimeType: "image/png",
+ };
+ expect(c.type).toBe("image");
+ expect(c.url).toContain("base64");
+ expect(c.mimeType).toBe("image/png");
+ });
+
+ it("an ImageChunk with only a url is valid (mimeType optional)", () => {
+ const c: ImageChunk = { type: "image", url: "https://example.com/cat.png" };
+ expect(c.mimeType).toBeUndefined();
+ });
+
+ it("ImageInput mirrors ImageChunk's url semantics", () => {
+ const input: ImageInput = { url: "data:image/jpeg;base64,/9j/4AAQ" };
+ expect(input.url).toContain("jpeg");
+ });
+
+ it("ImageChunk is a member of the Chunk union (assignable)", () => {
+ const chunk: Chunk = { type: "image", url: "data:image/png;base64,x" };
+ // Compile-time proof: an ImageChunk satisfies the Chunk union.
+ expect(chunk.type).toBe("image");
+ });
});