|
| 1 | +import { it as effectIt } from "@effect/vitest"; |
| 2 | +import * as ConfigProvider from "effect/ConfigProvider"; |
| 3 | +import * as Effect from "effect/Effect"; |
| 4 | +import { describe, expect, it } from "vite-plus/test"; |
| 5 | + |
| 6 | +import { resolveGitHubPublishConfig } from "../build-desktop-artifact.ts"; |
| 7 | +import { releaseRepositoryDefine, resolveReleaseRepository } from "./release-repository.ts"; |
| 8 | + |
| 9 | +const desktopFeedRepository = (env: Record<string, string>) => |
| 10 | + resolveGitHubPublishConfig("latest").pipe( |
| 11 | + Effect.map((config) => (config ? `${config.owner}/${config.repo}` : "")), |
| 12 | + Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env }))), |
| 13 | + ); |
| 14 | + |
| 15 | +describe("release repository build setting", () => { |
| 16 | + it("is empty (the upstream default) when unset or blank", () => { |
| 17 | + expect(resolveReleaseRepository({})).toBe(""); |
| 18 | + expect(resolveReleaseRepository({ T3CODE_DESKTOP_UPDATE_REPOSITORY: " " })).toBe(""); |
| 19 | + }); |
| 20 | + |
| 21 | + it("is upstream's desktop update setting, so the server follows the desktop feed", () => { |
| 22 | + const env = { T3CODE_DESKTOP_UPDATE_REPOSITORY: " some-owner/t3code " }; |
| 23 | + expect(resolveReleaseRepository(env)).toBe("some-owner/t3code"); |
| 24 | + expect(releaseRepositoryDefine(env)).toEqual({ |
| 25 | + __T3CODE_RELEASE_REPOSITORY__: JSON.stringify("some-owner/t3code"), |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + it("names the repository a GitHub Actions build runs in, unless the setting overrides it", () => { |
| 30 | + const actions = { GITHUB_ACTIONS: "true", GITHUB_REPOSITORY: "fork-owner/t3code" }; |
| 31 | + expect(resolveReleaseRepository(actions)).toBe("fork-owner/t3code"); |
| 32 | + expect( |
| 33 | + resolveReleaseRepository({ ...actions, T3CODE_DESKTOP_UPDATE_REPOSITORY: "other/t3code" }), |
| 34 | + ).toBe("other/t3code"); |
| 35 | + }); |
| 36 | + |
| 37 | + effectIt.effect("names the same repository as the desktop updater feed for every setting", () => |
| 38 | + Effect.gen(function* () { |
| 39 | + const cases: Array<Record<string, string>> = [ |
| 40 | + {}, |
| 41 | + { T3CODE_DESKTOP_UPDATE_REPOSITORY: "fork-owner/t3code" }, |
| 42 | + { GITHUB_REPOSITORY: "fork-owner/t3code" }, |
| 43 | + { T3CODE_DESKTOP_UPDATE_REPOSITORY: "a/t3code", GITHUB_REPOSITORY: "b/t3code" }, |
| 44 | + { T3CODE_RELEASE_REPOSITORY: "b/t3code", GITHUB_REPOSITORY: "b/t3code" }, |
| 45 | + ]; |
| 46 | + for (const env of cases) { |
| 47 | + const feed = yield* desktopFeedRepository(env); |
| 48 | + expect(resolveReleaseRepository(env), JSON.stringify(env)).toBe(feed); |
| 49 | + } |
| 50 | + }), |
| 51 | + ); |
| 52 | + |
| 53 | + it("fails the build when the former setting disagrees with the desktop updater's", () => { |
| 54 | + for (const env of [ |
| 55 | + { T3CODE_RELEASE_REPOSITORY: "fork-owner/t3code" }, |
| 56 | + { T3CODE_RELEASE_REPOSITORY: "b/t3code", T3CODE_DESKTOP_UPDATE_REPOSITORY: "a/t3code" }, |
| 57 | + { T3CODE_RELEASE_REPOSITORY: "b/t3code", GITHUB_REPOSITORY: "a/t3code" }, |
| 58 | + ]) { |
| 59 | + expect(() => resolveReleaseRepository(env), JSON.stringify(env)).toThrow( |
| 60 | + /T3CODE_RELEASE_REPOSITORY=".+" disagrees.*Set T3CODE_DESKTOP_UPDATE_REPOSITORY/, |
| 61 | + ); |
| 62 | + } |
| 63 | + }); |
| 64 | + |
| 65 | + it("fails the build on a malformed value instead of falling back to upstream", () => { |
| 66 | + for (const value of ["owner", "owner/repo/extra", "owner/..", "https://github.com/o/r"]) { |
| 67 | + expect(() => resolveReleaseRepository({ T3CODE_DESKTOP_UPDATE_REPOSITORY: value })).toThrow( |
| 68 | + /T3CODE_DESKTOP_UPDATE_REPOSITORY/, |
| 69 | + ); |
| 70 | + } |
| 71 | + }); |
| 72 | +}); |
0 commit comments