refactor: migrate monorepo from pnpm to Bun runtime and workspaces

- root: bun workspaces via package.json, packageManager bun@1.4.0, scripts use bun --filter
- backend: Bun.serve, bun test (vitest removed), bun --watch dev script, tsconfig types bun
- tests: migrate 6 test files from vitest to bun:test (mock.module)
- validate: replace @hono/zod-validator with hono validator + zod safeParse (fixes TS2589)
- lockfile: bunfig.toml saveTextLockfile, regenerated bun.lock (text) for turbo
- docs: AGENTS.md, README.md, stack.md updated to Bun stack
This commit is contained in:
Jose Selesan
2026-09-14 10:58:56 -03:00
parent 4b1f356fab
commit 6246bf2341
21 changed files with 1125 additions and 4936 deletions

View File

@@ -1,44 +1,27 @@
import { beforeEach, describe, expect, it, mock, vi } from 'bun:test';
import { Hono } from 'hono';
import { beforeEach, describe, expect, it, vi } from 'vitest';
const { db } = vi.hoisted(() => {
return {
db: {
group: {
findMany: vi.fn(),
findFirst: vi.fn(),
count: vi.fn(),
create: vi.fn(),
},
groupMember: {
create: vi.fn(),
},
organization: {
findUnique: vi.fn(),
},
} as {
group: {
findMany: ReturnType<typeof vi.fn>;
findFirst: ReturnType<typeof vi.fn>;
count: ReturnType<typeof vi.fn>;
create: ReturnType<typeof vi.fn>;
};
groupMember: { create: ReturnType<typeof vi.fn> };
organization: { findUnique: ReturnType<typeof vi.fn> };
},
};
});
const db = {
group: {
findMany: mock(),
findFirst: mock(),
count: mock(),
create: mock(),
},
groupMember: {
create: mock(),
},
organization: {
findUnique: mock(),
},
};
vi.mock('@/lib/prisma', () => ({
mock.module('@/lib/prisma', () => ({
default: db,
getPrismaClient: vi.fn(),
getPrismaClient: mock(),
UnitOfWork: class {
executeResult = vi.fn(
async (cb: (tx: unknown) => Promise<unknown>) => cb(db),
);
execute = vi.fn(
async (cb: (tx: unknown) => Promise<unknown>) => cb(db),
);
executeResult = mock(async (cb: (tx: unknown) => Promise<unknown>) => cb(db));
execute = mock(async (cb: (tx: unknown) => Promise<unknown>) => cb(db));
},
}));
@@ -71,8 +54,8 @@ describe('groups routes', () => {
});
it('lists groups scoped to the current user', async () => {
vi.mocked(prisma.group.findMany).mockResolvedValue([group]);
vi.mocked(prisma.group.count).mockResolvedValue(1);
prisma.group.findMany.mockResolvedValue([group]);
prisma.group.count.mockResolvedValue(1);
const res = await makeApp({ id: userId }).request('/groups');
@@ -118,9 +101,9 @@ describe('groups routes', () => {
name: 'Escuela Alfa',
members: [{ userId, role: 'owner' }],
};
vi.mocked(prisma.organization.findUnique).mockResolvedValue(organization as never);
vi.mocked(prisma.group.findFirst).mockResolvedValue(null);
vi.mocked(prisma.group.create).mockResolvedValue(group);
prisma.organization.findUnique.mockResolvedValue(organization as never);
prisma.group.findFirst.mockResolvedValue(null);
prisma.group.create.mockResolvedValue(group);
const res = await makeApp({ id: userId }).request('/groups/from-organization', {
method: 'POST',
@@ -148,8 +131,8 @@ describe('groups routes', () => {
name: 'Escuela Alfa',
members: [{ userId, role: 'owner' }],
};
vi.mocked(prisma.organization.findUnique).mockResolvedValue(organization as never);
vi.mocked(prisma.group.findFirst).mockResolvedValue(group);
prisma.organization.findUnique.mockResolvedValue(organization as never);
prisma.group.findFirst.mockResolvedValue(group);
const res = await makeApp({ id: userId }).request('/groups/from-organization', {
method: 'POST',
@@ -164,7 +147,7 @@ describe('groups routes', () => {
});
it('rejects creating a group for an unknown organization', async () => {
vi.mocked(prisma.organization.findUnique).mockResolvedValue(null);
prisma.organization.findUnique.mockResolvedValue(null);
const res = await makeApp({ id: userId }).request('/groups/from-organization', {
method: 'POST',
@@ -183,7 +166,7 @@ describe('groups routes', () => {
name: 'Escuela Alfa',
members: [{ userId: 'other-user', role: 'owner' }],
};
vi.mocked(prisma.organization.findUnique).mockResolvedValue(organization as never);
prisma.organization.findUnique.mockResolvedValue(organization as never);
const res = await makeApp({ id: userId }).request('/groups/from-organization', {
method: 'POST',

View File

@@ -1,11 +1,11 @@
import { beforeEach, describe, expect, it, mock, vi } from 'bun:test';
import { Hono } from 'hono';
import { beforeEach, describe, expect, it, vi } from 'vitest';
vi.mock('@/lib/prisma', () => ({
mock.module('@/lib/prisma', () => ({
default: {
$queryRaw: vi.fn(),
$queryRaw: mock(),
},
getPrismaClient: vi.fn(),
getPrismaClient: mock(),
UnitOfWork: class {},
}));
@@ -21,7 +21,7 @@ describe('health check routes', () => {
});
it('reports ok when the database answers', async () => {
vi.mocked(prisma.$queryRaw).mockResolvedValue([{ '?column?': 1 }]);
prisma.$queryRaw.mockResolvedValue([{ '?column?': 1 }]);
const res = await app.request('/health');
@@ -32,7 +32,7 @@ describe('health check routes', () => {
});
it('reports degraded when the database is unreachable', async () => {
vi.mocked(prisma.$queryRaw).mockRejectedValue(new Error('connection refused'));
prisma.$queryRaw.mockRejectedValue(new Error('connection refused'));
const res = await app.request('/health');

View File

@@ -1,14 +1,14 @@
import { beforeEach, describe, expect, it, mock, vi } from 'bun:test';
import { Hono } from 'hono';
import { beforeEach, describe, expect, it, vi } from 'vitest';
vi.mock('@/lib/prisma', () => ({
mock.module('@/lib/prisma', () => ({
default: {
payment: {
findMany: vi.fn(),
count: vi.fn(),
findMany: mock(),
count: mock(),
},
},
getPrismaClient: vi.fn(),
getPrismaClient: mock(),
UnitOfWork: class {},
}));
@@ -37,8 +37,8 @@ describe('payments routes', () => {
});
it('lists payments with pagination and converts Decimal amounts', async () => {
vi.mocked(prisma.payment.findMany).mockResolvedValue([payment]);
vi.mocked(prisma.payment.count).mockResolvedValue(1);
prisma.payment.findMany.mockResolvedValue([payment]);
prisma.payment.count.mockResolvedValue(1);
const res = await app.request('/payments');

View File

@@ -1,18 +1,20 @@
import { beforeEach, describe, expect, it, mock, vi } from 'bun:test';
import { Hono } from 'hono';
import { beforeEach, describe, expect, it, vi } from 'vitest';
vi.mock('@/lib/prisma', () => ({
default: {
$queryRaw: vi.fn(),
},
getPrismaClient: vi.fn(),
const db = {
$queryRaw: mock(),
};
mock.module('@/lib/prisma', () => ({
default: db,
getPrismaClient: mock(() => db),
UnitOfWork: class {},
}));
vi.mock('@/modules/auth/auth', () => ({
mock.module('@/modules/auth/auth', () => ({
auth: {
api: {
getSession: vi.fn(),
getSession: mock(),
},
},
}));
@@ -48,7 +50,7 @@ describe('session auth', () => {
});
it('rejects protected requests without a session', async () => {
vi.mocked(auth.api.getSession).mockResolvedValue(null);
auth.api.getSession.mockResolvedValue(null);
const app = new Hono();
app.use('*', sessionAuthMiddleware);
@@ -65,7 +67,7 @@ describe('session auth', () => {
user: { id: 'user-1', name: 'Ana' },
session: { id: 'session-1' },
};
vi.mocked(auth.api.getSession).mockResolvedValue(session as never);
auth.api.getSession.mockResolvedValue(session as never);
const app = new Hono();
app.use('*', sessionAuthMiddleware);

View File

@@ -1,14 +1,14 @@
import { beforeEach, describe, expect, it, mock, vi } from 'bun:test';
import { Hono } from 'hono';
import { beforeEach, describe, expect, it, vi } from 'vitest';
vi.mock('@/lib/prisma', () => ({
mock.module('@/lib/prisma', () => ({
default: {
student: {
findMany: vi.fn(),
count: vi.fn(),
findMany: mock(),
count: mock(),
},
},
getPrismaClient: vi.fn(),
getPrismaClient: mock(),
UnitOfWork: class {},
}));
@@ -37,8 +37,8 @@ describe('students routes', () => {
});
it('lists students with pagination', async () => {
vi.mocked(prisma.student.findMany).mockResolvedValue([student]);
vi.mocked(prisma.student.count).mockResolvedValue(21);
prisma.student.findMany.mockResolvedValue([student]);
prisma.student.count.mockResolvedValue(21);
const res = await app.request('/students?page=2&pageSize=10');
@@ -62,8 +62,8 @@ describe('students routes', () => {
});
it('uses default pagination', async () => {
vi.mocked(prisma.student.findMany).mockResolvedValue([]);
vi.mocked(prisma.student.count).mockResolvedValue(0);
prisma.student.findMany.mockResolvedValue([]);
prisma.student.count.mockResolvedValue(0);
const res = await app.request('/students');

View File

@@ -1,14 +1,14 @@
import { beforeEach, describe, expect, it, mock, vi } from 'bun:test';
import { Hono } from 'hono';
import { beforeEach, describe, expect, it, vi } from 'vitest';
vi.mock('@/lib/prisma', () => ({
mock.module('@/lib/prisma', () => ({
default: {
waitlistEntry: {
findMany: vi.fn(),
count: vi.fn(),
findMany: mock(),
count: mock(),
},
},
getPrismaClient: vi.fn(),
getPrismaClient: mock(),
UnitOfWork: class {},
}));
@@ -33,8 +33,8 @@ describe('waitlist routes', () => {
});
it('lists waitlist entries with pagination', async () => {
vi.mocked(prisma.waitlistEntry.findMany).mockResolvedValue([entry]);
vi.mocked(prisma.waitlistEntry.count).mockResolvedValue(1);
prisma.waitlistEntry.findMany.mockResolvedValue([entry]);
prisma.waitlistEntry.count.mockResolvedValue(1);
const res = await app.request('/waitlist');