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

@@ -31,17 +31,39 @@ class FakeSourcePrisma implements PrismaRunner {
const list = this.rows[modelName] ?? [];
for (const r of list) yield r;
}
async *findManyByWhere(
modelName: string,
where: Readonly<Record<string, unknown>>,
pageSize: number,
): AsyncIterable<Record<string, unknown>> {
void where;
void pageSize;
const list = this.rows[modelName] ?? [];
for (const r of list) yield r;
}
async findManyByIds(modelName: string, ids: readonly string[]): Promise<Record<string, unknown>[]> {
const list = this.globals[modelName] ?? [];
return list.filter((r) => typeof r.id === "string" && ids.includes(r.id as string));
}
async findManyByForeignKeys(
modelName: string,
foreignKey: string,
ids: readonly string[],
): Promise<Record<string, unknown>[]> {
const list = this.globals[modelName] ?? [];
return list.filter(
(row) => typeof row[foreignKey] === "string" && ids.includes(row[foreignKey] as string),
);
}
}
class FakeTargetPrisma implements PrismaRestoreRunner {
readonly writes: Record<string, Record<string, unknown>[]> = {};
readonly writeOrder: string[] = [];
/** Rows that already exist on the target — used by upsertManyById to simulate prior state. */
readonly preExisting: Record<string, Set<string>> = {};
async createMany(modelName: string, rows: Record<string, unknown>[]): Promise<{ written: number }> {
if (rows.length > 0) this.writeOrder.push(modelName);
this.writes[modelName] = (this.writes[modelName] ?? []).concat(rows);
return { written: rows.length };
}
@@ -144,6 +166,50 @@ describe("runTenantRestore", () => {
}
// Anonymization preserved on the way in.
expect(target.writes.TenantUserInvitation?.[0]?.email).toMatch(/@anonymized\.test$/u);
}, 15_000);
it("restores FK-derived children without adding tenantId and in parent-first order", async () => {
const sourcePrisma = new FakeSourcePrisma({
TenantInboundAddress: [{ id: "inbound_1", tenantId: "tenant_a", address: "in@local.test" }],
Email: [{ id: "email_1", tenantInboundAddressId: "inbound_1", messageId: "message_1" }],
KnowledgeBase: [{ id: "kb_1", tenantId: "tenant_a" }],
KnowledgeBaseCategory: [{ id: "category_1", knowledgeBaseId: "kb_1" }],
Workflow: [{ id: "workflow_1", tenantId: "tenant_a" }],
WorkflowBlock: [{ id: "block_1", workflowId: "workflow_1" }],
WorkflowExecution: [
{ id: "execution_1", tenantId: "tenant_a", workflowId: "workflow_1", waitingBlockId: "block_1" },
],
Portal: [{ id: "portal_1", tenantId: "tenant_a" }],
PortalPage: [{ id: "page_1", portalId: "portal_1" }],
});
const snapshotPath = join(workdir, "derived.tar.gz");
await runTenantSnapshot({
tenantId: "tenant_a",
profile: "none",
superAdminConfirmed: true,
prisma: sourcePrisma,
output: { kind: "local", path: snapshotPath },
includeGlobals: false,
logger: { info: vi.fn(), warn: vi.fn() },
});
const target = new FakeTargetPrisma();
await runTenantRestore({
tenantId: "tenant_clone",
source: snapshotPath,
prisma: target,
yes: true,
logger: { info: vi.fn(), warn: vi.fn() },
});
for (const model of ["Email", "KnowledgeBaseCategory", "WorkflowBlock", "PortalPage"]) {
expect(target.writes[model]?.[0]).not.toHaveProperty("tenantId");
}
expect(target.writes.TenantInboundAddress?.[0]?.tenantId).toBe("tenant_clone");
expect(target.writeOrder.indexOf("TenantInboundAddress")).toBeLessThan(target.writeOrder.indexOf("Email"));
expect(target.writeOrder.indexOf("KnowledgeBase")).toBeLessThan(target.writeOrder.indexOf("KnowledgeBaseCategory"));
expect(target.writeOrder.indexOf("WorkflowBlock")).toBeLessThan(target.writeOrder.indexOf("WorkflowExecution"));
expect(target.writeOrder.indexOf("Portal")).toBeLessThan(target.writeOrder.indexOf("PortalPage"));
});
it("aborts when the operator answers 'no' to the confirmation prompt", async () => {
@@ -443,6 +509,9 @@ describe("runTenantRestore", () => {
async *findManyByTenant() {
// empty
},
async *findManyByWhere() {
// empty
},
};
const snapshotPath = join(workdir, "legacy.tar.gz");
await runTenantSnapshot({