1/**
2 * Pins `./gitCafeHosts.ts`, which pass 2 creates as a plain module (no service):
3 *
4 * - `GITCAFE_HOSTS: readonly ["git.cafe", "staging.git.cafe"]` — the only hosts GitCafe lives on.
5 * - `isGitCafeHost(host: string): boolean` — case-insensitive membership in `GITCAFE_HOSTS`.
6 * - `parseGitCafeRemote(url: string): { readonly host: GitCafeHost; readonly repository: string } | null`
7 * — the host and `owner/name` of an https or ssh remote on a GitCafe host; null for anything else.
8 */
9import { assert, describe, it } from "@effect/vitest";
10
11import * as GitCafeHosts from "./gitCafeHosts.ts";
12
13describe("gitCafeHosts", () => {
14 it("knows exactly the production and staging hosts", () => {
15 assert.deepStrictEqual([...GitCafeHosts.GITCAFE_HOSTS], ["git.cafe", "staging.git.cafe"]);
16 assert.isTrue(GitCafeHosts.isGitCafeHost("Git.Cafe"));
17 assert.isTrue(GitCafeHosts.isGitCafeHost("staging.git.cafe"));
18 for (const host of ["cafe", "evil.git.cafe", "git.cafe.example.com", "github.com"]) {
19 assert.isFalse(GitCafeHosts.isGitCafeHost(host), host);
20 }
21 });
22
23 it.each([
24 ["https://git.cafe/team/project.git", "git.cafe"],
25 ["https://git.cafe/team/project", "git.cafe"],
26 ["https://staging.git.cafe/team/project.git/", "staging.git.cafe"],
27 ["ssh@git.cafe:team/project.git", "git.cafe"],
28 ["git@staging.git.cafe:team/project.git", "staging.git.cafe"],
29 ["ssh://git@git.cafe/team/project.git", "git.cafe"],
30 ])("reads the host and repository of %s", (url, host) => {
31 assert.deepStrictEqual(GitCafeHosts.parseGitCafeRemote(url), {
32 host,
33 repository: "team/project",
34 });
35 });
36
37 it.each([
38 "https://github.com/team/project.git",
39 "https://evil.git.cafe/team/project.git",
40 "https://git.cafe/team/nested/project.git",
41 "https://git.cafe/team",
42 "team/project",
43 ])("is not a GitCafe repository: %s", (url) => {
44 assert.isNull(GitCafeHosts.parseGitCafeRemote(url));
45 });
46});