mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-13 04:02:28 +02:00
Attribute optional server and browser Sentry events to their source build. Use validated build commits for Docker and source/npm artifacts, preserve explicit server release overrides, and keep cached browser bundles tied to the commit they loaded. Verify 127 focused tests, server/UI typechecks, Docker and source build stamps, all 53 CI checks, and Greptile 5/5 with no unresolved comments. Co-Authored-By: Paperclip <noreply@paperclip.ing>
65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { parseBuildCommit, readBuildCommit } from "../build-commit.js";
|
|
|
|
describe("parseBuildCommit", () => {
|
|
it("normalizes a full deployment commit", () => {
|
|
expect(parseBuildCommit(" ABCDEF0123456789ABCDEF0123456789ABCDEF01\n")).toBe(
|
|
"abcdef0123456789abcdef0123456789abcdef01",
|
|
);
|
|
});
|
|
|
|
it("rejects truncated and malformed commits", () => {
|
|
expect(parseBuildCommit("abcdef0")).toBeNull();
|
|
expect(parseBuildCommit("not-a-commit")).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("readBuildCommit", () => {
|
|
it("reads the built server stamp in npm packages without a deployment marker", () => {
|
|
const commit = "0123456789abcdef0123456789abcdef01234567";
|
|
expect(readBuildCommit({
|
|
environmentCommit: null,
|
|
buildCommitPath: "/app/.paperclip-build-commit",
|
|
buildInfoPath: "/app/server/dist/build-info.json",
|
|
readTextFile: (path) => {
|
|
if (path.endsWith(".paperclip-build-commit")) throw new Error("ENOENT");
|
|
return JSON.stringify({ commit });
|
|
},
|
|
})).toBe(commit);
|
|
});
|
|
|
|
it.each(["invalid json", "null", '{"commit":"short"}', '{"commit":42}'])(
|
|
"fails open on an invalid server stamp: %s", (stamp) => {
|
|
expect(readBuildCommit({
|
|
environmentCommit: null,
|
|
readTextFile: () => stamp,
|
|
})).toBeNull();
|
|
},
|
|
);
|
|
|
|
it("prefers an explicit environment commit", () => {
|
|
const readTextFile = vi.fn(() => "ffffffffffffffffffffffffffffffffffffffff");
|
|
|
|
expect(
|
|
readBuildCommit({
|
|
environmentCommit: "0123456789abcdef0123456789abcdef01234567",
|
|
readTextFile,
|
|
}),
|
|
).toBe("0123456789abcdef0123456789abcdef01234567");
|
|
expect(readTextFile).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("reads the deployment marker when no environment commit is set", () => {
|
|
expect(
|
|
readBuildCommit({
|
|
environmentCommit: null,
|
|
buildCommitPath: "/app/.paperclip-build-commit",
|
|
readTextFile: (path) => {
|
|
expect(path).toBe("/app/.paperclip-build-commit");
|
|
return "0123456789abcdef0123456789abcdef01234567\n";
|
|
},
|
|
}),
|
|
).toBe("0123456789abcdef0123456789abcdef01234567");
|
|
});
|
|
});
|