chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
import type { PrismaClient, RuntimeEnvironmentType } from "@trigger.dev/database";
|
||||
import type { EnvironmentVariablesRepository } from "~/v3/environmentVariables/environmentVariablesRepository.server";
|
||||
|
||||
let idCounter = 0;
|
||||
|
||||
export function uniqueId(prefix: string) {
|
||||
idCounter += 1;
|
||||
return `${prefix}-${idCounter}-${Date.now()}`;
|
||||
}
|
||||
|
||||
export async function createTestUser(prisma: PrismaClient, email?: string) {
|
||||
return prisma.user.create({
|
||||
data: {
|
||||
email: email ?? `${uniqueId("user")}@test.com`,
|
||||
authenticationMethod: "MAGIC_LINK",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function createTestOrgProjectWithMember(
|
||||
prisma: PrismaClient,
|
||||
options?: { userId?: string }
|
||||
) {
|
||||
const user = options?.userId
|
||||
? await prisma.user.findUniqueOrThrow({ where: { id: options.userId } })
|
||||
: await createTestUser(prisma);
|
||||
|
||||
const orgSlug = uniqueId("org");
|
||||
const organization = await prisma.organization.create({
|
||||
data: {
|
||||
title: "Test Org",
|
||||
slug: orgSlug,
|
||||
members: { create: { userId: user.id, role: "ADMIN" } },
|
||||
},
|
||||
include: { members: true },
|
||||
});
|
||||
|
||||
const projectSlug = uniqueId("proj");
|
||||
const project = await prisma.project.create({
|
||||
data: {
|
||||
name: "Test Project",
|
||||
slug: projectSlug,
|
||||
organizationId: organization.id,
|
||||
externalRef: uniqueId("ext"),
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
user,
|
||||
organization,
|
||||
project,
|
||||
orgMember: organization.members[0]!,
|
||||
projectSlug,
|
||||
};
|
||||
}
|
||||
|
||||
export async function createRuntimeEnvironment(
|
||||
prisma: PrismaClient,
|
||||
options: {
|
||||
projectId: string;
|
||||
organizationId: string;
|
||||
type: RuntimeEnvironmentType;
|
||||
orgMemberId?: string | null;
|
||||
slug?: string;
|
||||
}
|
||||
) {
|
||||
const slug = options.slug ?? uniqueId("env");
|
||||
return prisma.runtimeEnvironment.create({
|
||||
data: {
|
||||
slug,
|
||||
type: options.type,
|
||||
projectId: options.projectId,
|
||||
organizationId: options.organizationId,
|
||||
orgMemberId: options.orgMemberId ?? null,
|
||||
apiKey: uniqueId("api"),
|
||||
pkApiKey: uniqueId("pk"),
|
||||
shortcode: uniqueId("sc"),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function createEnvironmentVariable(
|
||||
repository: EnvironmentVariablesRepository,
|
||||
projectId: string,
|
||||
options: {
|
||||
environmentId: string;
|
||||
key: string;
|
||||
value: string;
|
||||
isSecret?: boolean;
|
||||
userId: string;
|
||||
}
|
||||
) {
|
||||
const result = await repository.create(projectId, {
|
||||
override: true,
|
||||
environmentIds: [options.environmentId],
|
||||
variables: [{ key: options.key, value: options.value }],
|
||||
isSecret: options.isSecret ?? false,
|
||||
lastUpdatedBy: { type: "user", userId: options.userId },
|
||||
});
|
||||
|
||||
if (!result.success) {
|
||||
throw new Error(result.error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// Minimal real worker for OtlpWorkerPool metric tests: echoes an ok result with a compute time.
|
||||
const { parentPort } = require("node:worker_threads");
|
||||
|
||||
parentPort.on("message", (message) => {
|
||||
if (message && message.type === "pricing") return;
|
||||
parentPort.postMessage({ id: message.id, ok: true, result: { rows: [] }, computeMs: 2 });
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
// Real worker that always reports a failed task, to exercise the pool's error-outcome metric.
|
||||
const { parentPort } = require("node:worker_threads");
|
||||
|
||||
parentPort.on("message", (message) => {
|
||||
if (message && message.type === "pricing") return;
|
||||
parentPort.postMessage({ id: message.id, ok: false, error: "boom" });
|
||||
});
|
||||
Reference in New Issue
Block a user