fix release v2 review issues

This commit is contained in:
ajnart committed 2026-08-14 02:18:46 +02:00
1 parent ef2ed6c602
commit ca856f9f54
29 files changed
+508 -131

No files matched your search

-1
View File
@@ -20,7 +20,6 @@
"./onboarding-claim": "./src/onboarding-claim.ts",
"./assistant": "./src/assistant.ts",
"./onboarding-step": "./src/onboarding-step.ts",
"./custom-widget/display-data": "./src/router/custom-widget/display-data.ts",
"./mcp": "./src/mcp.ts",
"./custom-widget-configuration": "./src/custom-widget-configuration.ts"
},
@@ -53,7 +53,10 @@ export const getDockerReconciliationAsync = async (db: Database) => {
? sameKindIntegrations.filter(({ name }) => normalizeName(name) === normalizeName(container.name))
: [];
const exactIntegration = exactIntegrationMatches.length === 1 ? exactIntegrationMatches[0] : undefined;
const nameIntegration = nameIntegrationMatches.length === 1 ? nameIntegrationMatches[0] : undefined;
const nameIntegration =
exactIntegrationMatches.length === 0 && nameIntegrationMatches.length === 1
? nameIntegrationMatches[0]
: undefined;
const integration = exactIntegration ?? nameIntegration;
const exactAppMatches = apps.filter(({ href }) => {
const normalizedUrl = normalizeDockerServiceUrl(href);
@@ -63,11 +66,16 @@ export const getDockerReconciliationAsync = async (db: Database) => {
? apps.filter(({ name }) => normalizeName(name) === normalizeName(container.name))
: [];
const exactApp = exactAppMatches.length === 1 ? exactAppMatches[0] : undefined;
const nameApp = nameAppMatches.length === 1 ? nameAppMatches[0] : undefined;
const nameApp = exactAppMatches.length === 0 && nameAppMatches.length === 1 ? nameAppMatches[0] : undefined;
const linkedApp = integration?.appId ? apps.find(({ id }) => id === integration.appId) : undefined;
const app = linkedApp ?? exactApp ?? nameApp;
const exactUrl = Boolean(exactIntegration || exactApp);
const linked = Boolean(integration?.appId && linkedApp);
const integrationAmbiguous =
exactIntegrationMatches.length > 1 || (exactIntegrationMatches.length === 0 && nameIntegrationMatches.length > 1);
const appAmbiguous =
!linkedApp && (exactAppMatches.length > 1 || (exactAppMatches.length === 0 && nameAppMatches.length > 1));
const ambiguous = integrationAmbiguous || appAmbiguous;
const state: DockerReconciliationState = linked
? "linked"
: integration && !exactUrl
@@ -87,7 +95,11 @@ export const getDockerReconciliationAsync = async (db: Database) => {
match,
urlCandidates,
state,
nextAction: nextActionForState(state),
nextAction: integrationAmbiguous
? ("reviewIntegration" as const)
: appAmbiguous
? ("viewRepresentation" as const)
: nextActionForState(state),
representation: {
integration: integration
? {
@@ -105,11 +117,7 @@ export const getDockerReconciliationAsync = async (db: Database) => {
exactUrl,
nameMatch: Boolean(nameIntegration || nameApp),
linked,
ambiguous:
exactIntegrationMatches.length > 1 ||
nameIntegrationMatches.length > 1 ||
exactAppMatches.length > 1 ||
nameAppMatches.length > 1,
ambiguous,
},
},
};
@@ -148,7 +156,7 @@ export const getDockerServiceHealthAsync = async (db: Database) => {
Boolean(candidate.representation.integration),
),
nextAction:
candidate.state === "moved"
candidate.nextAction === "reviewIntegration"
? ("reviewIntegration" as const)
: candidate.state === "newRecognized"
? ("setupIntegration" as const)
@@ -159,9 +167,11 @@ export const getDockerServiceHealthAsync = async (db: Database) => {
status: "notObserved" as const,
nextAction: candidate.representation.integration
? ("testConnection" as const)
: candidate.match
? ("setupIntegration" as const)
: ("none" as const),
: candidate.nextAction === "reviewIntegration"
? ("reviewIntegration" as const)
: candidate.match
? ("setupIntegration" as const)
: ("none" as const),
},
{
layer: "apiRequest" as const,
@@ -173,7 +183,11 @@ export const getDockerServiceHealthAsync = async (db: Database) => {
{
layer: "appRepresentation" as const,
status: candidate.representation.app ? ("linked" as const) : ("missing" as const),
nextAction: candidate.representation.app ? ("none" as const) : ("createApp" as const),
nextAction: candidate.representation.app
? ("none" as const)
: candidate.representation.signals.ambiguous && candidate.nextAction === "viewRepresentation"
? ("viewRepresentation" as const)
: ("createApp" as const),
},
{
layer: "widgetConfiguration" as const,
@@ -29,6 +29,12 @@ export const dockerRouter = createTRPCRouter({
.requiresPermission("admin")
.concat(dockerMiddleware())
.query(async ({ ctx }) => await getDockerServiceHealthAsync(ctx.db)),
refreshInventory: permissionRequiredProcedure
.requiresPermission("admin")
.concat(dockerMiddleware())
.mutation(() => {
dockerContainersRequestHandler.invalidateCache();
}),
getContainers: permissionRequiredProcedure
.requiresPermission("admin")
.meta({
@@ -31,6 +31,10 @@ export class KubernetesClient {
return KubernetesClient.getRegistry().getClient(contextId);
}
public static getDefaultInstance(): KubernetesClient {
return KubernetesClient.getRegistry().getDefaultClient();
}
public static async getContextsAsync() {
return await KubernetesClient.getRegistry().getContextsAsync();
}
@@ -68,6 +72,10 @@ export class KubernetesClientRegistry {
return client;
}
public getDefaultClient() {
return this.getClient(this.defaultContextId);
}
public async getContextsAsync() {
const contexts = await Promise.all(
[...this.clients.entries()].map(async ([contextId, client]): Promise<KubernetesContextStatus> => {
@@ -41,7 +41,7 @@ export const probeRuntimeCapabilitiesAsync = async ({
workshopApiUrl,
fetchImpl = fetch,
getKubernetesVersionAsync = async (signal) =>
await KubernetesClient.getInstance().versionApi.getCode({
await KubernetesClient.getDefaultInstance().versionApi.getCode({
middleware: [
{
pre: async (request: RequestContext) => {
@@ -13,6 +13,7 @@ import { dockerRouter } from "../../docker/docker-router";
const findDockerContainerAsyncMock = vi.hoisted(() => vi.fn());
const hasDockerEndpointCapabilityMock = vi.hoisted(() => vi.fn(() => true));
const invalidateDockerCacheMock = vi.hoisted(() => vi.fn());
const getDockerDataAsyncMock = vi.hoisted(() =>
vi.fn<
() => Promise<{
@@ -75,6 +76,7 @@ vi.mock("@homarr/request-handler/docker", () => ({
return () => undefined;
},
dockerContainersRequestHandler: {
invalidateCache: invalidateDockerCacheMock,
handler: () => ({
getDataAsync: getDockerDataAsyncMock,
}),
@@ -103,6 +105,7 @@ const validInputs: {
} = {
reconcileServices: undefined,
getServiceHealth: undefined,
refreshInventory: undefined,
getContainers: undefined,
startAll: { targets: [{ endpointId: "one", id: "1" }] },
stopAll: { targets: [{ endpointId: "one", id: "1" }] },
@@ -317,6 +320,136 @@ test("does not adopt an ambiguous existing integration", async () => {
expect(result.candidates[0]?.representation.integration).toBeNull();
expect(result.candidates[0]?.representation.signals.ambiguous).toBe(true);
expect(result.candidates[0]?.state).toBe("newRecognized");
expect(result.candidates[0]?.nextAction).toBe("reviewIntegration");
});
test("prefers a unique exact integration match over duplicate name matches", async () => {
getDockerDataAsyncMock.mockResolvedValueOnce({
data: {
containers: [createInventoryContainer({ endpointId: "home", id: "one", name: "sonarr", publicPort: 8989 })],
endpoints: [{ id: "home", name: "Home", status: "available" }],
},
timestamp: new Date(),
});
findIntegrationsAsyncMock.mockResolvedValueOnce([
{
id: "exact",
name: "Primary",
kind: "sonarr",
url: "http://home.example:8989",
appId: null,
items: [],
secrets: [],
},
{
id: "name-one",
name: "sonarr",
kind: "sonarr",
url: "http://other.example:8989",
appId: null,
items: [],
secrets: [],
},
{
id: "name-two",
name: "sonarr",
kind: "sonarr",
url: "http://third.example:8989",
appId: null,
items: [],
secrets: [],
},
]);
const result = await createAdminCaller().reconcileServices();
expect(result.candidates[0]?.representation.integration?.id).toBe("exact");
expect(result.candidates[0]?.representation.signals.ambiguous).toBe(false);
});
test("does not fall back to a unique name when exact integration matches are ambiguous", async () => {
getDockerDataAsyncMock.mockResolvedValueOnce({
data: {
containers: [createInventoryContainer({ endpointId: "home", id: "one", name: "sonarr", publicPort: 8989 })],
endpoints: [{ id: "home", name: "Home", status: "available" }],
},
timestamp: new Date(),
});
findIntegrationsAsyncMock.mockResolvedValueOnce([
{ id: "named", name: "sonarr", kind: "sonarr", url: "http://home.example:8989", appId: null },
{ id: "other", name: "Other", kind: "sonarr", url: "http://home.example:8989", appId: null },
]);
const result = await createAdminCaller().reconcileServices();
expect(result.candidates[0]?.representation.integration).toBeNull();
expect(result.candidates[0]?.representation.signals.ambiguous).toBe(true);
expect(result.candidates[0]?.nextAction).toBe("reviewIntegration");
});
test("prefers an explicitly linked app over duplicate app matches", async () => {
getDockerDataAsyncMock.mockResolvedValueOnce({
data: {
containers: [createInventoryContainer({ endpointId: "home", id: "one", name: "sonarr", publicPort: 8989 })],
endpoints: [{ id: "home", name: "Home", status: "available" }],
},
timestamp: new Date(),
});
findIntegrationsAsyncMock.mockResolvedValueOnce([
{
id: "integration",
name: "Sonarr",
kind: "sonarr",
url: "http://home.example:8989",
appId: "linked",
items: [],
secrets: [],
},
]);
findAppsAsyncMock.mockResolvedValueOnce([
{ id: "linked", name: "Sonarr", href: "http://home.example:8989", iconUrl: "" },
{ id: "duplicate", name: "Sonarr duplicate", href: "http://home.example:8989", iconUrl: "" },
]);
const result = await createAdminCaller().reconcileServices();
expect(result.candidates[0]?.representation.app?.id).toBe("linked");
expect(result.candidates[0]?.representation.signals.ambiguous).toBe(false);
expect(result.candidates[0]?.state).toBe("linked");
});
test("does not offer to create an app when existing app matches are ambiguous", async () => {
const dockerData = {
data: {
containers: [createInventoryContainer({ endpointId: "home", id: "one", name: "sonarr", publicPort: 8989 })],
endpoints: [{ id: "home", name: "Home", status: "available" }],
},
timestamp: new Date(),
} satisfies Awaited<ReturnType<typeof getDockerDataAsyncMock>>;
getDockerDataAsyncMock.mockResolvedValueOnce(dockerData).mockResolvedValueOnce(dockerData);
const apps = [
{ id: "first", name: "Sonarr one", href: "http://home.example:8989", iconUrl: "" },
{ id: "second", name: "Sonarr two", href: "http://home.example:8989", iconUrl: "" },
] satisfies Awaited<ReturnType<typeof findAppsAsyncMock>>;
findAppsAsyncMock.mockResolvedValueOnce(apps).mockResolvedValueOnce(apps);
const reconciliation = await createAdminCaller().reconcileServices();
const health = await createAdminCaller().getServiceHealth();
expect(reconciliation.candidates[0]?.representation.app).toBeNull();
expect(reconciliation.candidates[0]?.representation.signals.ambiguous).toBe(true);
expect(reconciliation.candidates[0]?.nextAction).toBe("viewRepresentation");
expect(health.services[0]?.layers).toContainEqual({
layer: "appRepresentation",
status: "missing",
nextAction: "viewRepresentation",
});
});
test("invalidates the shared Docker inventory on explicit refresh", async () => {
await createAdminCaller().refreshInventory();
expect(invalidateDockerCacheMock).toHaveBeenCalledOnce();
});
test("projects persisted service layers without inventing runtime health", async () => {
@@ -53,7 +53,7 @@ export const integrationDocSlugs: Record<IntegrationKind, string | null> = {
peaNut: "peanut",
beszel: "beszel",
traefik: "traefik",
archiveTeamWarrior: null,
archiveTeamWarrior: "archiveteam-warrior",
wud: "whats-up-docker",
mock: null,
};
@@ -0,0 +1,71 @@
// @vitest-environment jsdom
import { act } from "react";
import { createRoot } from "react-dom/client";
import type { Root } from "react-dom/client";
import { MantineProvider } from "@mantine/core";
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
import { ConfirmModal } from "./confirm-modal";
const ConfirmModalComponent = ConfirmModal.component;
vi.mock("@homarr/translation/client", () => ({
useI18n: () => (key: string) => key,
}));
let root: Root;
let host: HTMLDivElement;
beforeEach(() => {
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
window.matchMedia = vi.fn().mockImplementation(() => ({
matches: false,
media: "",
onchange: null,
addListener: vi.fn(),
removeListener: vi.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
}));
host = document.createElement("div");
document.body.append(host);
root = createRoot(host);
});
afterEach(async () => {
await act(() => root.unmount());
host.remove();
});
describe("ConfirmModal", () => {
test("clears loading and stays open when confirmation rejects", async () => {
const closeModal = vi.fn();
let rejectConfirmation!: (error: Error) => void;
const pendingConfirmation = new Promise<void>((_resolve, reject) => {
rejectConfirmation = reject;
});
const onConfirm = vi.fn(() => pendingConfirmation);
await act(async () =>
root.render(
<MantineProvider>
<ConfirmModalComponent actions={{ closeModal }} innerProps={{ children: "Remove containers?", onConfirm }} />
</MantineProvider>,
),
);
const confirmButton = host.querySelectorAll("button").item(1);
await act(async () => confirmButton.click());
expect(confirmButton.disabled).toBe(true);
await act(async () => {
rejectConfirmation(new Error("Removal failed"));
await Promise.resolve();
});
expect(confirmButton.disabled).toBe(false);
expect(closeModal).not.toHaveBeenCalled();
});
});
+16 -12
View File
@@ -36,8 +36,8 @@ export const ConfirmModal = createModal<Omit<ConfirmModalProps, "title">>(({ act
const closeOnConfirm = innerProps.closeOnConfirm ?? true;
const closeOnCancel = innerProps.closeOnCancel ?? true;
const cancelLabel = labels?.cancel ?? ((t: TranslationFunction) => t("common.action.cancel"));
const confirmLabel = labels?.confirm ?? ((t: TranslationFunction) => t("common.action.confirm"));
const cancelLabel = labels?.cancel ?? ((translate: TranslationFunction) => translate("common.action.cancel"));
const confirmLabel = labels?.confirm ?? ((translate: TranslationFunction) => translate("common.action.confirm"));
const handleCancel = useCallback(
async (event: React.MouseEvent<HTMLButtonElement>) => {
@@ -59,19 +59,23 @@ export const ConfirmModal = createModal<Omit<ConfirmModalProps, "title">>(({ act
const handleConfirm = useCallback(
async (event: React.MouseEvent<HTMLButtonElement>) => {
setLoading(true);
try {
if (typeof confirmProps?.onClick === "function") {
confirmProps.onClick(event);
}
if (typeof confirmProps?.onClick === "function") {
confirmProps.onClick(event);
}
if (typeof onConfirm === "function") {
await onConfirm();
}
if (typeof onConfirm === "function") {
await onConfirm();
if (closeOnConfirm) {
actions.closeModal();
}
} catch {
// Keep the modal open. Callers own action-specific error feedback.
} finally {
setLoading(false);
}
if (closeOnConfirm) {
actions.closeModal();
}
setLoading(false);
},
[confirmProps, onConfirm, closeOnConfirm, actions],
);
+2 -7
View File
@@ -281,11 +281,6 @@
"description": "Start a new dashboard and add its first widget.",
"keywords": "dashboard page"
},
"importBoard": {
"label": "Import board",
"description": "Bring an existing Homarr board configuration into this instance.",
"keywords": "upload oldmarr migrate"
},
"workshop": {
"label": "Browse Workshop",
"description": "Discover community-built widgets and install them.",
@@ -2072,8 +2067,8 @@
"tryAgain": "Try again",
"loading": "Loading",
"show": "Show",
"hide": "Hide"
,"undo": "Undo"
"hide": "Hide",
"undo": "Undo"
},
"here": "here",
"iconPicker": {
@@ -11,4 +11,13 @@ describe("buildSortedIntegrations", () => {
expect(kinds).toHaveLength(integrationKinds.length - 1);
expect(kinds).not.toContain("mock");
});
it("limits the grid to the allowed integration kinds", () => {
const kinds = buildSortedIntegrations({ allowedKinds: ["jellyfin", "sonarr"] }).map(
(integration) => integration.kind,
);
expect(kinds).toEqual(expect.arrayContaining(["jellyfin", "sonarr"]));
expect(kinds).toHaveLength(2);
});
});
@@ -47,10 +47,15 @@ export interface IntegrationGridItem {
}
export const buildSortedIntegrations = (
options: { enableMockIntegration?: boolean; onboarding?: boolean } = {},
options: {
enableMockIntegration?: boolean;
onboarding?: boolean;
allowedKinds?: readonly IntegrationKind[];
} = {},
): IntegrationGridItem[] =>
integrationKinds
.filter((kind) => {
if (options.allowedKinds && !options.allowedKinds.includes(kind)) return false;
if (options.onboarding && hiddenFromOnboarding.has(kind)) return false;
if (!options.enableMockIntegration && kind === "mock") return false;
return true;
@@ -15,12 +15,20 @@ import classes from "./integration-select-grid.module.css";
export interface IntegrationSelectGridProps {
onSelect: (kind: IntegrationKind) => void;
enableMockIntegration?: boolean;
allowedKinds?: readonly IntegrationKind[];
}
export const IntegrationSelectGrid = ({ onSelect, enableMockIntegration = false }: IntegrationSelectGridProps) => {
export const IntegrationSelectGrid = ({
onSelect,
enableMockIntegration = false,
allowedKinds,
}: IntegrationSelectGridProps) => {
const [search, setSearch] = useState("");
const t = useI18n();
const integrations = useMemo(() => buildSortedIntegrations({ enableMockIntegration }), [enableMockIntegration]);
const integrations = useMemo(
() => buildSortedIntegrations({ enableMockIntegration, allowedKinds }),
[allowedKinds, enableMockIntegration],
);
const filtered = useMemo(() => filterIntegrations(integrations, search), [integrations, search]);
return (
+13 -3
View File
@@ -247,9 +247,19 @@ export default function DockerWidget({
const hasChangeAccess = board ? constructBoardPermissions(board, session).hasChangeAccess : false;
const isAdvanced = displayMode === "advanced";
const utils = clientApi.useUtils();
const containersQuery = clientApi.docker.getContainers.useQuery();
const data = getUsableWidgetQueryData(containersQuery);
const { refetch, isFetching } = containersQuery;
const { isFetching } = containersQuery;
const refreshInventory = clientApi.docker.refreshInventory.useMutation({
async onSuccess() {
await Promise.all([
utils.docker.getContainers.invalidate(),
utils.docker.reconcileServices.invalidate(),
utils.docker.getServiceHealth.invalidate(),
]);
},
});
const containers = useMemo(() => data?.containers ?? [], [data?.containers]);
const timestamp = useMemo(() => data?.timestamp ?? new Date(), [data?.timestamp]);
const relativeTime = useTimeAgo(timestamp);
@@ -437,8 +447,8 @@ export default function DockerWidget({
size="sm"
variant="transparent"
c="var(--mantine-color-text)"
loading={isFetching}
onClick={() => void refetch()}
loading={isFetching || refreshInventory.isPending}
onClick={() => refreshInventory.mutate()}
aria-label={t("table.refresh.lastUpdated", { when: relativeTime })}
>
<IconRefresh size={16} />