revert(version): undo version refactor and tests, keep single-file change

Keep the User-Agent change as a single edit to
packages/core/src/infrastructure/http/request.ts. Remove the @homarr/version
package, the consumer migrations, and the unit tests.
This commit is contained in:
ajnart committed 2026-08-16 15:50:35 +02:00
1 parent 44d7426e9f
commit 1b74d73de0
13 files changed
+19 -154

No files matched your search

-1
View File
@@ -36,7 +36,6 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@homarr/version": "workspace:^0.1.0",
"@t3-oss/env-nextjs": "catalog:",
"better-sqlite3": "catalog:",
"dns-caching": "catalog:",
@@ -1,77 +0,0 @@
import { describe, expect, it, vi, beforeEach } from "vitest";
const { fetchMock } = vi.hoisted(() => ({ fetchMock: vi.fn() }));
vi.mock("undici", async (importOriginal) => {
const actual = await (importOriginal as () => Promise<Record<string, unknown>>)();
return { ...actual, fetch: fetchMock };
});
import { Headers } from "undici";
import { fetchWithTrustedCertificatesAsync, getDefaultUserAgent } from "./request";
const dummyDispatcher = {} as never;
const lastFetchHeaders = (): Headers => {
const [, init] = fetchMock.mock.calls.at(-1) ?? [];
return init?.headers as unknown as Headers;
};
describe("fetchWithTrustedCertificatesAsync default User-Agent", () => {
beforeEach(() => {
fetchMock.mockReset();
});
const defaultUserAgent = getDefaultUserAgent();
it("sets the default User-Agent when no header is provided", async () => {
await fetchWithTrustedCertificatesAsync("https://example.com", { dispatcher: dummyDispatcher });
expect(lastFetchHeaders().get("User-Agent")).toBe(defaultUserAgent);
});
it("keeps caller-provided record headers", async () => {
await fetchWithTrustedCertificatesAsync("https://example.com", {
dispatcher: dummyDispatcher,
headers: { Authorization: "token" },
});
const headers = lastFetchHeaders();
expect(headers.get("authorization")).toBe("token");
expect(headers.get("User-Agent")).toBe(defaultUserAgent);
});
it("normalizes a Headers instance without losing entries", async () => {
await fetchWithTrustedCertificatesAsync("https://example.com", {
dispatcher: dummyDispatcher,
headers: new Headers({ "x-custom": "present" }),
});
const headers = lastFetchHeaders();
expect(headers.get("x-custom")).toBe("present");
expect(headers.get("User-Agent")).toBe(defaultUserAgent);
});
it("normalizes a tuple-array of headers", async () => {
await fetchWithTrustedCertificatesAsync("https://example.com", {
dispatcher: dummyDispatcher,
headers: [["x-tuple", "value"]],
});
const headers = lastFetchHeaders();
expect(headers.get("x-tuple")).toBe("value");
expect(headers.get("User-Agent")).toBe(defaultUserAgent);
});
it("does not override a caller-provided User-Agent regardless of casing", async () => {
await fetchWithTrustedCertificatesAsync("https://example.com", {
dispatcher: dummyDispatcher,
headers: { "user-agent": "custom-agent" },
});
expect(lastFetchHeaders().get("User-Agent")).toBe("custom-agent");
});
it("sets the default User-Agent on the timeout path too", async () => {
await fetchWithTrustedCertificatesAsync("https://example.com", {
dispatcher: dummyDispatcher,
timeout: 1000,
});
expect(lastFetchHeaders().get("User-Agent")).toBe(defaultUserAgent);
});
});
@@ -3,27 +3,20 @@ import { Agent as HttpsAgent } from "node:https";
import { checkServerIdentity } from "node:tls";
import axios from "axios";
import type { Agent as UndiciAgent, RequestInfo, RequestInit, Response } from "undici";
import { Headers, fetch } from "undici";
import { fetch } from "undici";
import {
getAllTrustedCertificatesAsync,
getTrustedCertificateHostnamesAsync,
} from "@homarr/core/infrastructure/certificates";
import { UndiciHttpAgent } from "@homarr/core/infrastructure/http";
import { VERSION } from "@homarr/version";
import type { TrustedCertificateHostname } from "../certificates/hostnames";
import { withTimeoutAsync } from "./timeout";
export const getDefaultUserAgent = () => `Homarr/${VERSION} (+https://homarr.dev)`;
import packageJson from "../../../../../package.json";
const createFetchHeaders = (initial: RequestInit["headers"]): Headers => {
const headers = new Headers(initial);
if (!headers.has("User-Agent")) {
headers.set("User-Agent", getDefaultUserAgent());
}
return headers;
};
export const getDefaultUserAgent = () => `Homarr/${packageJson.version} (+https://homarr.dev)`;
export const createCustomCheckServerIdentity = (
trustedHostnames: TrustedCertificateHostname[],
@@ -90,7 +83,10 @@ export const fetchWithTrustedCertificatesAsync = async (
async (signal) =>
fetch(url, {
...fetchOptions,
headers: createFetchHeaders(fetchOptions.headers),
headers: {
"User-Agent": getDefaultUserAgent(),
...fetchOptions.headers,
},
signal,
dispatcher: agent,
}),
@@ -101,7 +97,10 @@ export const fetchWithTrustedCertificatesAsync = async (
const { bodyTimeout: _bodyTimeout, dispatcher: _dispatcher, ...fetchOptions } = options ?? {};
return fetch(url, {
...fetchOptions,
headers: createFetchHeaders(fetchOptions.headers),
headers: {
"User-Agent": getDefaultUserAgent(),
...fetchOptions.headers,
},
dispatcher: agent,
});
};