Open History to see the last commit
1import * as Schema from "effect/Schema";
2import { describe, expect, it } from "vite-plus/test";
3
4import { ExecutionEnvironmentDescriptor, RepositoryIdentityLocator } from "./environment.ts";
5
6const decodeDescriptor = Schema.decodeUnknownSync(ExecutionEnvironmentDescriptor);
7const encodeLocator = Schema.encodeUnknownSync(RepositoryIdentityLocator);
8const decodeLocator = Schema.decodeUnknownSync(RepositoryIdentityLocator);
9
10const descriptor = {
11 environmentId: "environment-1",
12 label: "Local",
13 platform: { os: "darwin", arch: "arm64" },
14 serverVersion: "0.0.32",
15 capabilities: { repositoryIdentity: true },
16} as const;
17
18describe("ExecutionEnvironmentDescriptor", () => {
19 it("decodes old, recognized and future manual installation descriptors", () => {
20 expect(decodeDescriptor(descriptor).capabilities.serverInstallation).toBeUndefined();
21 for (const installation of [
22 { kind: "npx" },
23 { kind: "npm-global", prefix: "/opt/node" },
24 { kind: "t3-launcher", launcher: "/opt/bin/t3", baseDir: "/data/t3" },
25 ]) {
26 expect(
27 decodeDescriptor({
28 ...descriptor,
29 capabilities: { ...descriptor.capabilities, serverInstallation: installation },
30 }).capabilities.serverInstallation,
31 ).toEqual(installation);
32 }
33 const spaced = { kind: "t3-launcher", launcher: "/opt/bin/t3 ", baseDir: " /data/t3 " };
34 expect(
35 decodeDescriptor({
36 ...descriptor,
37 capabilities: { ...descriptor.capabilities, serverInstallation: spaced },
38 }).capabilities.serverInstallation,
39 ).toEqual(spaced);
40 for (const installation of [
41 { kind: "future-manager" },
42 { kind: "npm-global" },
43 { kind: "t3-launcher", launcher: "t3" },
44 ]) {
45 expect(
46 decodeDescriptor({
47 ...descriptor,
48 capabilities: { ...descriptor.capabilities, serverInstallation: installation },
49 }).capabilities.serverInstallation,
50 ).toBeUndefined();
51 }
52 });
53});
54
55describe("RepositoryIdentityLocator", () => {
56 it.each(["\u00a0", "contrib\u00a0"])("keeps Git remote name %j intact", (remoteName) => {
57 const locator = { source: "git-remote", remoteName, remoteUrl: "https://github.com/a/b.git" };
58 expect(encodeLocator(locator)).toEqual(locator);
59 expect(decodeLocator(locator)).toEqual(locator);
60 });
61});