Update hivegrid-cloud reference to latest main

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
davidandClaude Fable 5 committed 2026-07-08 16:15:37 +02:00
1 parent e98d38e716
commit 7b21524c86
3781 files changed
+373484 -225607

No files matched your search

@@ -6,7 +6,7 @@ import { MemoryRouter } from "react-router";
const baseEnv = {
API_ACCESS_TOKEN: "test-api-access-token-placeholder",
APP_NAME: "ToolCTRL Test",
APP_NAME: "HiveGrid Test",
CRYPTO_SECRET: "test-crypto-secret-placeholder",
DATABASE_URL: "file:./test.db?connection_limit=1&connect_timeout=30",
JWT_SECRET: "test-jwt-secret-placeholder",
@@ -35,8 +35,8 @@ let NotificationsRoute: typeof import("./notifications").default;
let action: typeof import("./notifications").action;
let loader: typeof import("./notifications").loader;
let streamLoader: typeof import("./notifications/stream").loader;
let getNotificationDeliveryDiagnostics: typeof import("@toolctrl/db/notifications.server").getNotificationDeliveryDiagnostics;
let markInAppNotificationDeliveryRead: typeof import("@toolctrl/db/notifications.server").markInAppNotificationDeliveryRead;
let getNotificationDeliveryDiagnostics: typeof import("@hivegrid/db/notifications.server").getNotificationDeliveryDiagnostics;
let markInAppNotificationDeliveryRead: typeof import("@hivegrid/db/notifications.server").markInAppNotificationDeliveryRead;
let requireAuth: typeof import("~/utils/loaders.middleware").requireAuth;
let getTenantIdFromUrl: typeof import("~/utils/services/.server/urlService").getTenantIdFromUrl;
let getUserInfo: typeof import("~/utils/session.server").getUserInfo;
@@ -44,9 +44,10 @@ let validateCSRFToken: typeof import("~/utils/session.server").validateCSRFToken
let getAbsoluteApiUrl: typeof import("~/utils/url.server").getAbsoluteApiUrl;
let getTranslations: typeof import("~/locale/i18next.server").getTranslations;
vi.mock("@toolctrl/db/notifications.server", () => ({
vi.mock("@hivegrid/db/notifications.server", () => ({
getNotificationDeliveryDiagnostics: vi.fn(),
markInAppNotificationDeliveryRead: vi.fn(),
markAllInAppNotificationDeliveriesRead: vi.fn(),
redactNotificationDiagnosticText: (value: string) =>
value
.replace(/\bBearer\s+[A-Za-z0-9._~+/=-]+/gi, "Bearer [redacted]")
@@ -134,6 +135,7 @@ vi.mock("react-router", async () => {
return {
...actual,
useLoaderData: () => routeLoaderData,
useFetcher: () => ({ submit: vi.fn(), data: undefined, state: "idle" }),
};
});
@@ -162,7 +164,7 @@ function postFormRequest(formData: FormData) {
describe("app tenant notifications route", () => {
beforeAll(async () => {
applyBaseEnv();
const notificationsDb = await import("@toolctrl/db/notifications.server");
const notificationsDb = await import("@hivegrid/db/notifications.server");
const loadersMiddleware = await import("~/utils/loaders.middleware");
const urlService = await import("~/utils/services/.server/urlService");
const sessionServer = await import("~/utils/session.server");
@@ -189,7 +191,10 @@ describe("app tenant notifications route", () => {
vi.mocked(getTenantIdFromUrl).mockResolvedValue("tenant_1");
vi.mocked(getUserInfo).mockResolvedValue({ userId: "user_1", csrf: "csrf-token" } as never);
vi.mocked(getNotificationDeliveryDiagnostics).mockResolvedValue([]);
routeLoaderData = { items: [], streamUrl: "/acme/notifications/stream" };
routeLoaderData = {
vm: { status: "ready", data: { items: [], totalCount: 0, unreadCount: 0, emptyHeadlineKey: "notifications.center.empty", emptyBodyKey: "notifications.center.emptyHelper", unreadEmptyKey: "notifications.center.unreadEmpty", streamAvailable: true } },
streamUrl: "/acme/notifications/stream",
};
vi.stubEnv("API_ACCESS_TOKEN", "service-secret");
});
@@ -252,21 +257,25 @@ describe("app tenant notifications route", () => {
statuses: ["SENT", "READ"],
take: 50,
});
expect(body.items).toEqual([
{
id: "delivery_1",
messageKey: "billing.invoice.paid",
category: "billing",
channel: "IN_APP",
status: "SENT",
attemptsMade: 2,
lastError: "token=[redacted] Authorization: Bearer [redacted]",
createdAt: "2026-05-01T10:00:00.000Z",
updatedAt: "2026-05-01T10:05:00.000Z",
sentAt: "2026-05-01T10:01:00.000Z",
readAt: null,
},
]);
expect(body.vm.status).toBe("ready");
expect(body.vm.data.items).toHaveLength(1);
expect(body.vm.data.items[0]).toMatchObject({
id: "delivery_1",
messageKey: "billing.invoice.paid",
category: "billing",
categoryKey: "notifications.center.categories.billing",
channel: "IN_APP",
status: "SENT",
isRead: false,
attemptsMade: 2,
lastErrorRedacted: "token=[redacted] Authorization: Bearer [redacted]",
createdAtIso: "2026-05-01T10:00:00.000Z",
updatedAtIso: "2026-05-01T10:05:00.000Z",
sentAtIso: "2026-05-01T10:01:00.000Z",
readAtIso: null,
deeplinkHref: null,
});
expect(body.vm.data.unreadCount).toBe(1);
expect(body.csrf).toBe("csrf-token");
expect(body.streamUrl).toBe("/acme/notifications/stream");
expect(JSON.stringify(body)).not.toContain("provider_secret_123");
@@ -278,6 +287,49 @@ describe("app tenant notifications route", () => {
expect(JSON.stringify(body)).not.toContain("abc123");
});
it("derives a validated app-relative deeplink from payloadMetadata", async () => {
vi.mocked(getNotificationDeliveryDiagnostics).mockResolvedValue([
{
id: "delivery_deeplink",
tenantId: "tenant_1",
userId: "user_1",
messageKey: "team.invite.created",
category: "team",
channel: "IN_APP",
status: "SENT",
attemptsMade: 1,
payloadMetadata: { deeplink: "/acme/settings/members" },
createdAt,
updatedAt,
sentAt,
readAt: null,
},
{
id: "delivery_evil",
tenantId: "tenant_1",
userId: "user_1",
messageKey: "team.invite.created",
category: "team",
channel: "IN_APP",
status: "SENT",
attemptsMade: 1,
payloadMetadata: { deeplink: "https://evil.example/phish" },
createdAt,
updatedAt,
sentAt,
readAt: null,
},
] as never);
const response = (await loader(routeArgs())) as Response;
const body = await response.json();
const byId = Object.fromEntries(body.vm.data.items.map((item: { id: string; deeplinkHref: string | null }) => [item.id, item.deeplinkHref]));
expect(byId.delivery_deeplink).toBe("/acme/settings/members");
expect(byId.delivery_evil).toBeNull();
expect(JSON.stringify(body)).not.toContain("evil.example");
});
it("returns 400 for invalid form actions without updating a delivery", async () => {
const formData = new FormData();
formData.set("action", "delete");
@@ -329,41 +381,50 @@ describe("app tenant notifications route", () => {
expect(body).toEqual({ ok: true });
});
it("renders page copy, empty state, and notification diagnostics through the center component", () => {
it("renders page copy, tabs, bounce plain-text and mark-read through the interim screen", async () => {
const { buildNotificationCenterVM } = await import("@hivegrid/view-models");
routeLoaderData = {
streamUrl: "/acme/notifications/stream",
csrf: "csrf-token",
items: [
{
id: "delivery_1",
messageKey: "team.invite.created",
category: "team",
channel: "IN_APP",
status: "FAILED",
attemptsMade: 3,
lastError: "provider_id=provider_secret_123 token=tok_secret",
createdAt: "2026-05-01T10:00:00.000Z",
updatedAt: "2026-05-01T10:05:00.000Z",
sentAt: null,
readAt: null,
},
],
vm: buildNotificationCenterVM({
streamAvailable: true,
items: [
{
id: "delivery_1",
messageKey: "team.invite.created",
category: "team",
channel: "IN_APP",
status: "FAILED",
attemptsMade: 3,
lastError: "provider_id=provider_secret_123 token=tok_secret rate limit",
createdAtIso: "2026-05-01T10:00:00.000Z",
updatedAtIso: "2026-05-01T10:05:00.000Z",
sentAtIso: null,
readAtIso: null,
payloadMetadata: { deeplink: "/acme/settings/members" },
},
],
}),
};
render(
const { container } = render(
<MemoryRouter>
<NotificationsRoute />
</MemoryRouter>
);
expect(screen.getByRole("heading", { name: "Notifications" })).toBeInTheDocument();
expect(screen.getByText("Review in-app notification delivery status, retry diagnostics, and read timestamps for your account.")).toBeInTheDocument();
expect(screen.getByRole("heading", { name: "Notification center" })).toBeInTheDocument();
expect(container.querySelector('[data-ui-id="ui.notifications.center"]')).toBeInTheDocument();
expect(screen.getByText("Notification center")).toBeInTheDocument();
expect(screen.getByText("Delivery diagnostics for in-app notifications.")).toBeInTheDocument();
expect(screen.getByText("Team invite created")).toBeInTheDocument();
expect(screen.getByText("Failed")).toBeInTheDocument();
expect(screen.getByText("3")).toBeInTheDocument();
// Deeplink renders as an app-relative link on the item title.
expect(container.querySelector('[data-ui-id="ui.notifications.center.deeplink"]')).toHaveAttribute("href", "/acme/settings/members");
// Bounce plain-text (M002) is shown; the raw redacted detail never leaks secrets.
expect(container.querySelector('[data-ui-id="ui.notifications.center.bounce"]')).toBeInTheDocument();
expect(screen.getByLabelText("Mark Team invite created as read")).toBeInTheDocument();
expect(screen.getByDisplayValue("csrf-token")).toHaveAttribute("name", "csrf");
expect(container.querySelector('[data-ui-id="ui.notifications.center.tabs"]')).toBeInTheDocument();
expect(container.querySelector('[data-ui-id="ui.notifications.center.bulkClear"]')).toBeInTheDocument();
expect(screen.queryByText("provider_secret_123")).not.toBeInTheDocument();
expect(screen.queryByText("tok_secret")).not.toBeInTheDocument();
});
@@ -400,8 +461,8 @@ describe("app tenant notifications route", () => {
expect(proxiedInit).toEqual({
headers: {
authorization: "Bearer service-secret",
"x-toolctrl-tenant-id": "tenant_1",
"x-toolctrl-user-id": "user_1",
"x-hivegrid-tenant-id": "tenant_1",
"x-hivegrid-user-id": "user_1",
"x-request-id": "req_web",
},
});