From 386d77b351066aa49103d57dcf2ae1f7cf2789c6 Mon Sep 17 00:00:00 2001 From: Bobban Rydh Date: Tue, 17 Nov 2026 18:27:04 +0100 Subject: [PATCH] Inspect for n8n and Home Assistant Both read through the shared HTTP helper but were missing from the web list of inspectable kinds, so no Inspect button showed. Home Assistant's reader was named listEntities, which the inspect route doesn't recognise; it now also answers to read. Test and INTEGRATIONS.md updated. Co-Authored-By: Claude Sonnet 5.5 --- INTEGRATIONS.md | 2 +- .../src/integrations/homeassistant/adapter.ts | 4 ++- server/test/inspector.test.ts | 32 ++++++++++++++++++- web/src/utils/integrationTypes.ts | 2 +- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/INTEGRATIONS.md b/INTEGRATIONS.md index 5606ee0..0f3422c 100644 --- a/INTEGRATIONS.md +++ b/INTEGRATIONS.md @@ -34,7 +34,7 @@ The numbers an integration reports — queries a day and how many were blocked ( ### Checking what an integration can read -On the Integrations page an administrator has an **Inspect** button on each integration that reads through the shared HTTP helper (Authentik, Immich, Jellyfin, NetBox, Nextcloud, Paperless-ngx, Prometheus, Hetzner Cloud, Hetzner Robot, Speedtest Tracker, Fragnet, Sonarr, Radarr, Prowlarr, Lidarr, Readarr, qBittorrent, SABnzbd, AdGuard Home, Technitium DNS and Grafana). It runs the integration's reader once and shows: +On the Integrations page an administrator has an **Inspect** button on each integration that reads through the shared HTTP helper (Authentik, Immich, Jellyfin, NetBox, Nextcloud, Paperless-ngx, Prometheus, Hetzner Cloud, Hetzner Robot, Speedtest Tracker, Fragnet, Sonarr, Radarr, Prowlarr, Lidarr, Readarr, qBittorrent, SABnzbd, AdGuard Home, Technitium DNS, Grafana, n8n and Home Assistant). It runs the integration's reader once and shows: - **what was asked** — each request, its path (with the *names* of the query parameters, not their values), the status, how long it took and how many bytes; - **what came back** — the *shape* of each JSON answer to three levels: the names of the fields and the kind of each (`string`, `number`, `array(12) of { … }`), with a `?` on a field that only some items of a list have. Never a value, never a token, so the report can be copied into a message; diff --git a/server/src/integrations/homeassistant/adapter.ts b/server/src/integrations/homeassistant/adapter.ts index 29481bc..ca1ea52 100644 --- a/server/src/integrations/homeassistant/adapter.ts +++ b/server/src/integrations/homeassistant/adapter.ts @@ -34,6 +34,8 @@ export interface HaEntity { export interface HomeAssistantAdapter { ping(): Promise<{ ok: boolean; latencyMs?: number; error?: string }>; listEntities(): Promise; + /** The same read under the name the inspector looks for. */ + read(): Promise; } const obj = (v: unknown): Record => (v !== null && typeof v === "object" && !Array.isArray(v) ? (v as Record) : {}); @@ -87,5 +89,5 @@ export function createHomeAssistantAdapter(config: HomeAssistantConfig): HomeAss } } - return withDiagLogging("homeassistant", { ping, listEntities }); + return withDiagLogging("homeassistant", { ping, listEntities, read: listEntities }); } diff --git a/server/test/inspector.test.ts b/server/test/inspector.test.ts index ee2e89e..3a1bbcf 100644 --- a/server/test/inspector.test.ts +++ b/server/test/inspector.test.ts @@ -7,7 +7,7 @@ import { test, describe, before, after } from "node:test"; import assert from "node:assert/strict"; import { createServer as createHttpServer, type Server } from "node:http"; -import { mkdtempSync, rmSync } from "node:fs"; +import { mkdtempSync, readFileSync, rmSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import type { AddressInfo } from "node:net"; @@ -201,4 +201,34 @@ describe("the route", () => { assert.equal(entries.length, 2, "the two that ran"); assert.deepEqual(entries.map((e) => [e.category, e.targetType]), [["integration", "integration"], ["integration", "integration"]]); }); + + test("n8n and Home Assistant can be inspected too, and the web page offers the button for both", async () => { + const other = createHttpServer((req, res) => { + res.setHeader("content-type", "application/json"); + const u = new URL(req.url ?? "", "http://x"); + if (u.pathname === "/api/v1/workflows") return void res.end(JSON.stringify({ data: [{ id: "1", name: "Backup", active: true }], nextCursor: null })); + if (u.pathname === "/api/v1/executions") return void res.end(JSON.stringify({ data: [{ workflowId: "1", status: "success", stoppedAt: "2026-01-01T00:00:00Z" }] })); + if (u.pathname === "/api/states") return void res.end(JSON.stringify([{ entity_id: "sensor.t", state: "21.5", attributes: { friendly_name: "Temp", unit_of_measurement: "°C" }, last_changed: "2026-01-01T00:00:00Z" }])); + res.statusCode = 404; + res.end("{}"); + }); + await new Promise((r) => other.listen(0, "127.0.0.1", r)); + try { + const url = `http://127.0.0.1:${(other.address() as AddressInfo).port}`; + const n8nId = (await db.insert(integrations).values({ type: "n8n", name: "Flows", baseUrl: url, config: JSON.stringify({ url, apiKey: "n8n_secret" }) }).returning({ id: integrations.id }))[0].id; + const haId = (await db.insert(integrations).values({ type: "homeassistant", name: "Home", baseUrl: url, config: JSON.stringify({ url, token: "ha_secret" }) }).returning({ id: integrations.id }))[0].id; + for (const [id, path] of [[n8nId, "/api/v1/workflows"], [haId, "/api/states"]] as const) { + const text = await (await call("admin", id)).text(); + assert.doesNotMatch(text, /n8n_secret|ha_secret/); + const body = JSON.parse(text) as { ok: boolean; calls: { path: string; status: number }[] }; + assert.equal(body.ok, true, text); + assert.ok(body.calls.some((c) => c.path.startsWith(path) && c.status === 200), path); + } + } finally { + other.close(); + } + const types = readFileSync(new URL("../../web/src/utils/integrationTypes.ts", import.meta.url), "utf8"); + const list = types.match(/INSPECTABLE[^=]*=\s*\[([^\]]*)\]/)?.[1] ?? ""; + for (const kind of ["n8n", "homeassistant"]) assert.ok(list.includes(`"${kind}"`), kind); + }); }); diff --git a/web/src/utils/integrationTypes.ts b/web/src/utils/integrationTypes.ts index 24283b8..d95d58a 100644 --- a/web/src/utils/integrationTypes.ts +++ b/web/src/utils/integrationTypes.ts @@ -91,7 +91,7 @@ export const TYPE_GROUPS: { id: string; label: string; types: IntegrationType[] ]; /** The kinds whose reader can be inspected (Settings → Integrations → Check what can be read): the ones that read through the shared HTTP helper and have a reader to run. */ -export const INSPECTABLE: IntegrationType[] = ["authentik", "immich", "jellyfin", "netbox", "nextcloud", "paperless", "prometheus", "hetzner", "speedtest", "fragnet", "sonarr", "radarr", "prowlarr", "lidarr", "readarr", "qbittorrent", "sabnzbd", "hetznerrobot", "adguard", "technitium", "grafana"]; +export const INSPECTABLE: IntegrationType[] = ["authentik", "immich", "jellyfin", "netbox", "nextcloud", "paperless", "prometheus", "hetzner", "speedtest", "fragnet", "sonarr", "radarr", "prowlarr", "lidarr", "readarr", "qbittorrent", "sabnzbd", "hetznerrobot", "adguard", "technitium", "grafana", "n8n", "homeassistant"]; /** The group a kind belongs to; a kind nobody has placed yet falls in "Other" rather than vanishing. */ export function groupOfType(type: IntegrationType): { id: string; label: string } {