1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
/**
* Conformance test for the wire ABI's type-only surface. The wire package ships
* no runtime, so these tests assert that the public shapes COMPILE and round-trip
* — a `Computer` literal satisfies its type, `ComputerEntry` extends `Computer`,
* and a `Workspace` carries the new `defaultComputerId`. The `ComputerEntry →
* Computer` assignment is a genuine compile-time check (it would fail to typecheck
* if the `extends` relationship broke); the runtime assertions are sanity echo.
*/
import { describe, expect, it } from "vitest";
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) 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");
});
});
|