Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -0,0 +1,51 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
const { resolvePublicKnowledgeBaseRlsIdentity, listPublicKnowledgeBaseRlsIdentities, runWithIsolatedPublicKnowledgeBaseRlsContext } = vi.hoisted(() => ({
resolvePublicKnowledgeBaseRlsIdentity: vi.fn(),
listPublicKnowledgeBaseRlsIdentities: vi.fn(),
runWithIsolatedPublicKnowledgeBaseRlsContext: vi.fn(async (_resourceId: string, operation: () => Promise<unknown>) => operation()),
}));
vi.mock("@hivegrid/db/rls-resolvers.server", () => ({
resolvePublicKnowledgeBaseRlsIdentity,
listPublicKnowledgeBaseRlsIdentities,
}));
vi.mock("@hivegrid/db/rls-context.server", () => ({
runWithIsolatedPublicKnowledgeBaseRlsContext,
}));
import { mapPublicKnowledgeBasesWithRlsContext, withPublicKnowledgeBaseRlsContext } from "./publicKnowledgeBaseRls.server";
describe("public knowledge-base RLS context", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("fails closed when the slug resolver does not expose an enabled global knowledge base", async () => {
resolvePublicKnowledgeBaseRlsIdentity.mockResolvedValue(null);
const operation = vi.fn();
await expect(withPublicKnowledgeBaseRlsContext("disabled", operation)).resolves.toBeNull();
expect(operation).not.toHaveBeenCalled();
expect(runWithIsolatedPublicKnowledgeBaseRlsContext).not.toHaveBeenCalled();
});
it("binds the resolved id instead of trusting the public slug", async () => {
resolvePublicKnowledgeBaseRlsIdentity.mockResolvedValue({ resourceId: "kb-public" });
const operation = vi.fn().mockResolvedValue("visible");
await expect(withPublicKnowledgeBaseRlsContext("docs", operation)).resolves.toBe("visible");
expect(runWithIsolatedPublicKnowledgeBaseRlsContext).toHaveBeenCalledWith("kb-public", operation);
});
it("runs sitemap operations once per resolver-approved public knowledge base", async () => {
listPublicKnowledgeBaseRlsIdentities.mockResolvedValue([{ resourceId: "kb-a" }, { resourceId: "kb-b" }]);
const operation = vi.fn(async (knowledgeBaseId: string) => (knowledgeBaseId === "kb-a" ? { id: knowledgeBaseId } : null));
await expect(mapPublicKnowledgeBasesWithRlsContext(operation)).resolves.toEqual([{ id: "kb-a" }]);
expect(operation).toHaveBeenCalledTimes(2);
expect(runWithIsolatedPublicKnowledgeBaseRlsContext).toHaveBeenNthCalledWith(1, "kb-a", expect.any(Function));
expect(runWithIsolatedPublicKnowledgeBaseRlsContext).toHaveBeenNthCalledWith(2, "kb-b", expect.any(Function));
});
});
@@ -0,0 +1,16 @@
import { listPublicKnowledgeBaseRlsIdentities, resolvePublicKnowledgeBaseRlsIdentity } from "@hivegrid/db/rls-resolvers.server";
import { runWithIsolatedPublicKnowledgeBaseRlsContext } from "@hivegrid/db/rls-context.server";
export async function withPublicKnowledgeBaseRlsContext<T>(slug: string, operation: () => Promise<T>): Promise<T | null> {
const identity = await resolvePublicKnowledgeBaseRlsIdentity(slug);
if (!identity) {
return null;
}
return runWithIsolatedPublicKnowledgeBaseRlsContext(identity.resourceId, operation);
}
export async function mapPublicKnowledgeBasesWithRlsContext<T>(operation: (knowledgeBaseId: string) => Promise<T | null>): Promise<Awaited<T>[]> {
const identities = await listPublicKnowledgeBaseRlsIdentities();
const values = await Promise.all(identities.map(({ resourceId }) => runWithIsolatedPublicKnowledgeBaseRlsContext(resourceId, () => operation(resourceId))));
return values.flatMap((value) => (value === null ? [] : [value]));
}