Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125import { describe, expect, it } from "vitest";import { spindleUrl, toPipelineSummary } from "$lib/api/spindle";import type * as Pipeline from "$lib/api/lexicons/types/sh/tangled/ci/pipeline";
describe("spindleUrl", () => { it("gives bare hosts https and localhost plain http", () => { expect(spindleUrl("spindle.tangled.org")).toBe("https://spindle.tangled.org"); expect(spindleUrl("localhost:6555")).toBe("http://localhost:6555"); });
it("keeps an explicit scheme and drops the trailing slash", () => { expect(spindleUrl("http://spindle.test/")).toBe("http://spindle.test"); });});
const workflow = (over: Partial<Pipeline.Workflow> = {}): Pipeline.Workflow => ({ id: "build", name: "build", status: "success", ...over});
const pipeline = (over: Partial<Pipeline.Main>): Pipeline.Main => ({ id: "3lz", commit: "9f2c1ab4d8e7350f6b1c2d9e4a5b6c7d8e9f0a1b", trigger: { $type: "sh.tangled.ci.trigger#manual", sha: "9f2c1ab" }, workflows: [workflow()], ...over }) as Pipeline.Main;
describe("toPipelineSummary", () => { it("strips the ref prefix off a push trigger", () => { const summary = toPipelineSummary( pipeline({ trigger: { $type: "sh.tangled.ci.trigger#push", ref: "refs/heads/master", newSha: "a".repeat(40), oldSha: "b".repeat(40) } }) ); expect(summary.trigger).toEqual({ kind: "push", targetRef: "master" }); });
it("reads a pull request's target and source branches", () => { const summary = toPipelineSummary( pipeline({ trigger: { $type: "sh.tangled.ci.trigger#pullRequest", targetBranch: "master", sourceBranch: "fix-timeout", sourceSha: "c".repeat(40) } }) ); expect(summary.trigger).toEqual({ kind: "pull_request", targetRef: "master", sourceLabel: "fix-timeout" }); });
it("keeps a fork's repo did so the page can upgrade the label", () => { const summary = toPipelineSummary( pipeline({ trigger: { $type: "sh.tangled.ci.trigger#pullRequest", targetBranch: "master", sourceBranch: "fix-timeout", sourceSha: "c".repeat(40), sourceRepo: "did:plc:forkowner" } }), "did:plc:thisrepo" ); expect(summary.trigger).toEqual({ kind: "pull_request", targetRef: "master", sourceLabel: "fix-timeout", sourceRepo: "did:plc:forkowner" }); });
it("drops the did when the pull came from the same repo", () => { const summary = toPipelineSummary( pipeline({ trigger: { $type: "sh.tangled.ci.trigger#pullRequest", targetBranch: "master", sourceBranch: "fix-timeout", sourceSha: "c".repeat(40), sourceRepo: "did:plc:thisrepo" } }), "did:plc:thisrepo" ); expect(summary.trigger).toEqual({ kind: "pull_request", targetRef: "master", sourceLabel: "fix-timeout" }); });
it("times a workflow from its own start and finish stamps", () => { const summary = toPipelineSummary( pipeline({ workflows: [ workflow({ startedAt: "2026-08-04T09:00:00.000Z", finishedAt: "2026-08-04T09:01:12.000Z" }), workflow({ name: "test", status: "running", startedAt: "2026-08-04T09:00:00.000Z" }) ] }) ); expect(summary.workflows.map((w) => w.duration)).toEqual([72_000, 0]); });});