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

@@ -1,8 +1,5 @@
import { describe, expect, test, vi } from "vitest";
import {
buildAiBrowserTaskJob,
buildAiChatCompletionJob,
buildAiEmbeddingJob,
buildBrowserSessionCleanupJob,
buildBrowserSessionRunJob,
buildBrowserUsageFlushJob,
@@ -14,14 +11,16 @@ import {
buildTransactionalMailJob,
queueNames,
type WebhookDeliveryJobDescriptor,
} from "@toolctrl/queue";
} from "@hivegrid/queue";
import { buildHandlerRegistry, type HandlerDependencies } from "./handlers.js";
import type { CreateNotificationDeliveryInput } from "@toolctrl/db/notifications.server";
import { MailProviderError, type MailProvider } from "@toolctrl/mail";
import type { StorageScanResult } from "@toolctrl/storage";
import { PRIVACY_GDPR_USER_SELF_EXPORT_TYPE } from "./jobs/privacy-gdpr-export.js";
import type { CreateNotificationDeliveryInput } from "@hivegrid/db/notifications.server";
import { MailProviderError, type MailProvider } from "@hivegrid/mail";
import type { StorageScanResult } from "@hivegrid/storage";
type TestScanService = NonNullable<HandlerDependencies["scanService"]>;
type TestExportService = NonNullable<HandlerDependencies["exportService"]>;
type TestPrivacyGdprExportService = NonNullable<HandlerDependencies["privacyGdprExportService"]>;
type TestImportService = NonNullable<HandlerDependencies["importService"]>;
type TestStorageDeleteService = NonNullable<HandlerDependencies["storageDeleteService"]>;
type TestRetentionListInput = Parameters<NonNullable<HandlerDependencies["listSoftDeletedExportJobsForHardDelete"]>>[0];
@@ -51,9 +50,9 @@ describe("worker handlers", () => {
cc: [{ email: "cc@example.com", name: "CC" }],
bcc: ["bcc@example.com"],
replyTo: "reply@example.com",
subject: "Welcome to ToolCTRL",
text: "Hello from ToolCTRL",
html: "<p>Hello from <strong>ToolCTRL</strong></p>",
subject: "Welcome to HiveGrid",
text: "Hello from HiveGrid",
html: "<p>Hello from <strong>HiveGrid</strong></p>",
templateId: "tmpl_welcome",
attachments: [{ content: "Zm9v", filename: "foo.txt", disposition: "attachment" }],
tags: ["welcome"],
@@ -87,9 +86,9 @@ describe("worker handlers", () => {
cc: [{ email: "cc@example.com", name: "CC" }],
bcc: ["bcc@example.com"],
replyTo: "reply@example.com",
subject: "Welcome to ToolCTRL",
text: "Hello from ToolCTRL",
html: "<p>Hello from <strong>ToolCTRL</strong></p>",
subject: "Welcome to HiveGrid",
text: "Hello from HiveGrid",
html: "<p>Hello from <strong>HiveGrid</strong></p>",
templateId: "tmpl_welcome",
attachments: [{ content: "Zm9v", filename: "foo.txt", disposition: "attachment" }],
tags: ["welcome"],
@@ -115,7 +114,7 @@ describe("worker handlers", () => {
const registry = buildHandlerRegistry({ mailProvider });
const descriptor = buildTransactionalMailJob({
to: ["user@example.com", "admin@example.com"],
subject: "Welcome to ToolCTRL",
subject: "Welcome to HiveGrid",
templateId: "tmpl_welcome",
templateData: {
"user@example.com": { firstName: "Ada" },
@@ -129,7 +128,7 @@ describe("worker handlers", () => {
});
expect(mailProvider.send).toHaveBeenCalledWith({
to: ["user@example.com", "admin@example.com"],
subject: "Welcome to ToolCTRL",
subject: "Welcome to HiveGrid",
text: undefined,
html: undefined,
templateId: "tmpl_welcome",
@@ -1607,39 +1606,6 @@ describe("worker handlers", () => {
expect(listSoftDeletedExportJobsForHardDelete).toHaveBeenCalledWith({ now: expect.any(Date), take: undefined });
});
test("accepts descriptor-derived AI jobs through registry", async () => {
const registry = buildHandlerRegistry();
const descriptors = [
buildAiChatCompletionJob({
tenantId: "tenant_123",
userId: "user_123",
conversationId: "conversation_123",
messages: [{ role: "user", content: "fixture prompt not surfaced" }],
}),
buildAiEmbeddingJob({
tenantId: "tenant_123",
userId: "user_123",
model: "fixture-embedding-model",
task: { text: "fixture embedding text not surfaced" },
}),
buildAiBrowserTaskJob({
tenantId: "tenant_123",
userId: "user_123",
task: { instruction: "fixture browser task not surfaced" },
}),
];
await Promise.all(
descriptors.map((descriptor) =>
expect(registry[descriptor.queueName](descriptor.payload, {})).rejects.toMatchObject({
action: "worker.unsupported",
message: "AI worker job is not configured.",
details: { queueName: queueNames.aiChatbot, kind: descriptor.payload.kind, tenantId: "tenant_123", userId: "user_123" },
})
)
);
});
test("rejects descriptor-derived browser automation jobs through registry without global fetch", async () => {
const fetchSpy = vi.spyOn(globalThis, "fetch");
const registry = buildHandlerRegistry();
@@ -1858,6 +1824,112 @@ describe("worker handlers", () => {
expect(JSON.stringify(markExportJobSucceeded.mock.calls)).not.toContain("payload-secret");
});
test("routes privacy GDPR export jobs through the GDPR service and status table", async () => {
const expiresAt = new Date("2026-05-09T00:00:00.000Z");
const exportService: TestExportService = {
runExport: vi.fn(async () => ({ artifactBucket: "unused", artifactKey: "unused", rowCount: 0, expiresAt })),
};
const privacyGdprExportService: TestPrivacyGdprExportService = {
runExport: vi.fn(async () => ({
artifactBucket: "exports",
artifactKey: "tenants/tenant_1/gdpr/export_job_1.zip",
rowCount: 7,
sizeBytes: 4096,
expiresAt,
})),
};
const markGdprExportProcessing = vi.fn(async () => undefined);
const markGdprExportReady = vi.fn(async () => undefined);
const markGdprExportFailed = vi.fn(async () => undefined);
const markExportJobRunning = vi.fn(async () => undefined);
const registry = buildHandlerRegistry({
exportService,
privacyGdprExportService,
markGdprExportProcessing,
markGdprExportReady,
markGdprExportFailed,
markExportJobRunning,
});
const descriptor = buildExportJob({
exportJobId: "gdpr_export_job_1",
tenantId: "tenant_1",
requestedByUserId: "user_1",
exportType: PRIVACY_GDPR_USER_SELF_EXPORT_TYPE,
format: "json",
requestId: "req_gdpr_export_success",
metadata: { attemptsMade: 1, token: "payload-secret" },
});
await expect(registry[descriptor.queueName](descriptor.payload, {})).resolves.toEqual({
handled: true,
action: "privacy-gdpr-export.completed",
details: {
exportJobId: "gdpr_export_job_1",
tenantId: "tenant_1",
exportType: PRIVACY_GDPR_USER_SELF_EXPORT_TYPE,
format: "json",
requestId: "req_gdpr_export_success",
artifactBucket: "exports",
artifactKey: "tenants/tenant_1/gdpr/export_job_1.zip",
attemptsMade: 1,
expiresAt: "2026-05-09T00:00:00.000Z",
rowCount: 7,
sizeBytes: 4096,
status: "ready",
},
});
expect(markGdprExportProcessing).toHaveBeenCalledWith({ id: "gdpr_export_job_1", tenantId: "tenant_1" });
expect(privacyGdprExportService.runExport).toHaveBeenCalledWith(descriptor.payload);
expect(markGdprExportReady).toHaveBeenCalledWith({
id: "gdpr_export_job_1",
tenantId: "tenant_1",
resultBucket: "exports",
resultKey: "tenants/tenant_1/gdpr/export_job_1.zip",
resultSizeBytes: 4096,
resultExpiresAt: expiresAt,
});
expect(markGdprExportFailed).not.toHaveBeenCalled();
expect(exportService.runExport).not.toHaveBeenCalled();
expect(markExportJobRunning).not.toHaveBeenCalled();
});
test("fails privacy GDPR export jobs when the dedicated service is missing", async () => {
const markGdprExportProcessing = vi.fn(async () => undefined);
const markGdprExportFailed = vi.fn(async () => undefined);
const markExportJobRunning = vi.fn(async () => undefined);
const registry = buildHandlerRegistry({ markGdprExportProcessing, markGdprExportFailed, markExportJobRunning });
const descriptor = buildExportJob({
exportJobId: "gdpr_export_job_missing_service",
tenantId: "tenant_1",
requestedByUserId: "user_1",
exportType: PRIVACY_GDPR_USER_SELF_EXPORT_TYPE,
format: "json",
requestId: "req_gdpr_export_missing_service",
});
await expect(registry[descriptor.queueName](descriptor.payload, {})).rejects.toMatchObject({
action: "export.error",
message: "Privacy GDPR export service is not configured.",
details: {
exportJobId: "gdpr_export_job_missing_service",
tenantId: "tenant_1",
exportType: PRIVACY_GDPR_USER_SELF_EXPORT_TYPE,
format: "json",
requestId: "req_gdpr_export_missing_service",
attemptsMade: 0,
status: "failed",
code: "privacy_gdpr_export_service_missing",
},
});
expect(markGdprExportProcessing).toHaveBeenCalledWith({ id: "gdpr_export_job_missing_service", tenantId: "tenant_1" });
expect(markGdprExportFailed).toHaveBeenCalledWith({
id: "gdpr_export_job_missing_service",
tenantId: "tenant_1",
errorMessage: "Privacy GDPR export service is not configured.",
});
expect(markExportJobRunning).not.toHaveBeenCalled();
});
test("uses BullMQ attempt metadata for export job persistence when available", async () => {
const expiresAt = new Date("2026-05-09T00:00:00.000Z");
const exportService: TestExportService = {