summaryrefslogtreecommitdiffhomepage
path: root/packages/wire/src/index.test.ts
blob: cd297b70cce82cdbd5a28ac42d46656c7ed36026 (plain)
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
/**
 * 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 { Computer, ComputerEntry, 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();
	});
});