The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.
TypeScript budget-trackercollaborativedockeritinerarymcp-serveroffline-firstopen-sourceopenstreetmappacking-listpwareal-timeself-hostedselfhostedtraveltravel-apptravel-journaltravel-plannertripitwanderlog
test(db): run the budget and collections MCP suites on the real database module
Mauricec4c278d2f35d
diff --git a/server/scripts/test-mocks-baseline.json b/server/scripts/test-mocks-baseline.jsonindex 9447ae752..a9b8bb743 100644--- a/server/scripts/test-mocks-baseline.json+++ b/server/scripts/test-mocks-baseline.json@@ -63,9 +63,6 @@"tests/setup.ts": 1,"tests/unit/auto-backup.test.ts": 1,"tests/unit/db/database-lazy-open.test.ts": 1,- "tests/unit/mcp/tools-budget-advanced.test.ts": 1,- "tests/unit/mcp/tools-budget.test.ts": 1,- "tests/unit/mcp/tools-collections.test.ts": 1,"tests/unit/mcp/tools-days-accommodations.test.ts": 1,"tests/unit/mcp/tools-days.test.ts": 1,"tests/unit/mcp/tools-feeds-invite.test.ts": 1,diff --git a/server/scripts/test-new-service-baseline.json b/server/scripts/test-new-service-baseline.jsonindex e94c500b7..47e18e771 100644--- a/server/scripts/test-new-service-baseline.json+++ b/server/scripts/test-new-service-baseline.json@@ -23,7 +23,6 @@"tests/unit/db/repositories/MaintenanceRepository.test.ts": 2,"tests/unit/db/repositories/UserConnections.repository.test.ts": 3,"tests/unit/demo/demo-reset-sessions.test.ts": 3,- "tests/unit/mcp/tools-budget-advanced.test.ts": 2,"tests/unit/mcp/tools-prompts.test.ts": 7,"tests/unit/mcp/tools-roadtrip.test.ts": 1,"tests/unit/mcp/tools-transit.test.ts": 1,diff --git a/server/tests/postgres/snapshot-suites-baseline.json b/server/tests/postgres/snapshot-suites-baseline.jsonindex 4e33e044a..714d9bb36 100644--- a/server/tests/postgres/snapshot-suites-baseline.json+++ b/server/tests/postgres/snapshot-suites-baseline.json@@ -1,7 +1,4 @@[- "tests/unit/mcp/tools-budget-advanced.test.ts",- "tests/unit/mcp/tools-budget.test.ts",- "tests/unit/mcp/tools-collections.test.ts","tests/unit/mcp/tools-days-accommodations.test.ts","tests/unit/mcp/tools-days.test.ts","tests/unit/mcp/tools-feeds-invite.test.ts",diff --git a/server/tests/unit/mcp/tools-budget-advanced.test.ts b/server/tests/unit/mcp/tools-budget-advanced.test.tsindex 2be87d63a..299d7ffe9 100644--- a/server/tests/unit/mcp/tools-budget-advanced.test.ts+++ b/server/tests/unit/mcp/tools-budget-advanced.test.ts@@ -3,41 +3,32 @@* set_budget_item_members, toggle_budget_member_paid.* Resources: trek://trips/{tripId}/budget/per-person, trek://trips/{tripId}/budget/settlement.*/-import { db as testDb } from '../../../src/db/database';import { BudgetItemMembers } from '../../../src/db/entities/BudgetItemMembers.entity';import { BudgetItems } from '../../../src/db/entities/BudgetItems.entity';import { BudgetSettlements } from '../../../src/db/entities/BudgetSettlements.entity';import { Trips } from '../../../src/db/entities/Trips.entity';import type { TripAccess } from '../../../src/db/repositories/Trips.repository';-import type { BudgetWritesService } from '../../../src/nest/budget/budget-writes.service';import { BudgetController } from '../../../src/nest/budget/budget.controller';-import { BudgetService } from '../../../src/nest/budget/budget.service';import { ExchangeRatesService } from '../../../src/nest/budget/exchange-rates.service';-import { PermissionsService } from '../../../src/nest/permissions/permissions.service';-import { RealtimeService } from '../../../src/nest/realtime/realtime.service';+import { withRequestContext } from '../../../src/nest/database/request-context';import type { User } from '../../../src/types';-import { budgetRepoArgs } from '../../helpers/budget-repos';-import { createUser, createTrip, createBudgetItem, addTripMember } from '../../helpers/factories';-import { addBudgetItemMember, addBudgetItemPayer } from '../../helpers/factories/budget';+import { makeBudgetItem, addBudgetItemMember, addBudgetItemPayer } from '../../helpers/factories/budget';import { countRows, updateRows } from '../../helpers/factories/rows';+import { addTripMember, makeTrip } from '../../helpers/factories/trips';+import { makeUser } from '../../helpers/factories/users';import { FakeRealtimeService } from '../../helpers/fake-realtime';import { createMcpHarness, parseToolResult, parseResourceResult, type McpHarness } from '../../helpers/mcp-harness';-import { resetTestDb } from '../../helpers/test-db';-import { createTestOrm, type TestOrm } from '../../helpers/test-orm';-import { createTestUnitOfWork, createTestAppSettingsRepo } from '../../helpers/test-uow';+import { resetDatabase } from '../../helpers/reset-database';+import { bootTestApp } from '../../helpers/test-app';+import { MikroORM } from '@mikro-orm/core';import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';-vi.mock('../../../src/db/database', async () => {- const { createSnapshotTestDb, buildDbMock } = await import('../../helpers/db-mock');- return buildDbMock(createSnapshotTestDb());-});-const realtime = new FakeRealtimeService();const broadcastMock = realtime.broadcastMock;-beforeEach(() => {- resetTestDb(testDb);+beforeEach(async () => {+ await resetDatabase(orm);broadcastMock.mockClear();delete process.env.DEMO_MODE;// get_settlement_summary calls getRates(), which is a real fetch to@@ -51,16 +42,16 @@ beforeEach(() => {);});-let orm: TestOrm;+// The booted container's own ORM, the one the tools write through.+let orm: MikroORM;beforeAll(async () => {- orm = await createTestOrm(testDb);+ orm = (await bootTestApp(realtime)).get(MikroORM);});afterAll(async () => {vi.unstubAllGlobals();- await orm.close();- testDb.close();+ await (await bootTestApp(realtime)).close();});async function withHarness(userId: number, fn: (h: McpHarness) => Promise<void>) {@@ -87,9 +78,9 @@ async function withResourceHarness(userId: number, fn: (h: McpHarness) => Promisdescribe('Tool: set_budget_item_members', () => {it('sets members and returns a hydrated item with members/payers', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createBudgetItem(testDb, trip.id, { name: 'Flights', total_price: 500 });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makeBudgetItem(orm, trip.id, { name: 'Flights', total_price: 500 });await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'set_budget_item_members',@@ -114,8 +105,8 @@ describe('Tool: set_budget_item_members', () => {});it('returns an error for an item not in the trip', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'set_budget_item_members',@@ -126,9 +117,9 @@ describe('Tool: set_budget_item_members', () => {});it('empty array clears members', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createBudgetItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makeBudgetItem(orm, trip.id);await addBudgetItemMember(orm, item.id, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -142,10 +133,10 @@ describe('Tool: set_budget_item_members', () => {});it('returns access denied for non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);- const item = createBudgetItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);+ const item = await makeBudgetItem(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'set_budget_item_members',@@ -157,9 +148,9 @@ describe('Tool: set_budget_item_members', () => {it('blocks demo user', async () => {process.env.DEMO_MODE = 'true';- const { user } = createUser(testDb, { email: '[email protected]' });- const trip = createTrip(testDb, user.id);- const item = createBudgetItem(testDb, trip.id);+ const { user } = await makeUser(orm, { email: '[email protected]' });+ const trip = await makeTrip(orm, user.id);+ const item = await makeBudgetItem(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'set_budget_item_members',@@ -176,10 +167,10 @@ describe('Tool: set_budget_item_members', () => {describe('Tool: create_budget_item_with_members', () => {it('assigns the given members and returns a hydrated item', async () => {- const { user } = createUser(testDb);- const { user: member } = createUser(testDb);- const trip = createTrip(testDb, user.id);- addTripMember(testDb, trip.id, member.id);+ const { user } = await makeUser(orm);+ const { user: member } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ await addTripMember(orm, trip.id, member.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item_with_members',@@ -195,9 +186,9 @@ describe('Tool: create_budget_item_with_members', () => {});it('refuses a trip the caller cannot see with the trip gate, and sends nothing', async () => {- const { user } = createUser(testDb);- const { user: owner } = createUser(testDb);- const trip = createTrip(testDb, owner.id);+ const { user } = await makeUser(orm);+ const { user: owner } = await makeUser(orm);+ const trip = await makeTrip(orm, owner.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item_with_members',@@ -211,10 +202,10 @@ describe('Tool: create_budget_item_with_members', () => {// Regression: omitting userIds previously produced an empty-member (unsaveable) entity.it('defaults to all trip members when userIds omitted', async () => {- const { user } = createUser(testDb);- const { user: member } = createUser(testDb);- const trip = createTrip(testDb, user.id);- addTripMember(testDb, trip.id, member.id);+ const { user } = await makeUser(orm);+ const { user: member } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ await addTripMember(orm, trip.id, member.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item_with_members',@@ -228,8 +219,8 @@ describe('Tool: create_budget_item_with_members', () => {it('blocks demo user', async () => {process.env.DEMO_MODE = 'true';- const { user } = createUser(testDb, { email: '[email protected]' });- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm, { email: '[email protected]' });+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item_with_members',@@ -246,9 +237,9 @@ describe('Tool: create_budget_item_with_members', () => {describe('Tool: toggle_budget_member_paid', () => {it('flips paid flag and broadcasts', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createBudgetItem(testDb, trip.id, { total_price: 200 });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makeBudgetItem(orm, trip.id, { total_price: 200 });// Add member firstawait addBudgetItemMember(orm, item.id, user.id, { paid: 0 });await withHarness(user.id, async (h) => {@@ -269,10 +260,10 @@ describe('Tool: toggle_budget_member_paid', () => {});it('returns access denied for non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);- const item = createBudgetItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);+ const item = await makeBudgetItem(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'toggle_budget_member_paid',@@ -288,31 +279,26 @@ describe('Tool: toggle_budget_member_paid', () => {// ---------------------------------------------------------------------------describe('Settlement tools', () => {- function tripWithTwo() {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, user.id);- addTripMember(testDb, trip.id, other.id);+ async function tripWithTwo() {+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ await addTripMember(orm, trip.id, other.id);return { user, other, trip };}- /** The REST side of the parity cases below: the controller behind GET /budget/settlement, on this suite's db. */- async function restController() {- return new BudgetController(- new BudgetService(- new PermissionsService(await createTestAppSettingsRepo(testDb), await createTestUnitOfWork(testDb)),- new ExchangeRatesService(),- new RealtimeService(),- await createTestUnitOfWork(testDb),- ...(await budgetRepoArgs(testDb)),- ),- // The settlement route reads only; it never reaches the write use cases.- {} as BudgetWritesService,- );+ /**+ * The REST side of the parity cases below: the container's controller behind+ * GET /budget/settlement, called in a request context of its own as a request+ * would be.+ */+ async function restSettlement(...args: Parameters<BudgetController['settlement']>) {+ const controller = (await bootTestApp(realtime)).get(BudgetController);+ return withRequestContext(orm, () => controller.settlement(...args));}it('create_settlement records a payment, broadcasts, and is listed', async () => {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();await withHarness(user.id, async (h) => {const created = await h.client.callTool({name: 'create_settlement',@@ -332,7 +318,7 @@ describe('Settlement tools', () => {});it('update_settlement changes the amount; delete_settlement removes it', async () => {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();await withHarness(user.id, async (h) => {const created = parseToolResult(await h.client.callTool({@@ -365,7 +351,7 @@ describe('Settlement tools', () => {});it('update_settlement returns an error when the settlement is missing', async () => {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'update_settlement',@@ -376,9 +362,9 @@ describe('Settlement tools', () => {});it('create_settlement is denied for a non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_settlement',@@ -392,16 +378,15 @@ describe('Settlement tools', () => {// The two surfaces resolve the trip currency and the rates separately before// calling calculateSettlement, so the parity that matters is on the payload.// The fixture carries the row the fix is about: a total nobody has paid.- const { user, other, trip } = tripWithTwo();- const paid = createBudgetItem(testDb, trip.id, { total_price: 100 });+ const { user, other, trip } = await tripWithTwo();+ const paid = await makeBudgetItem(orm, trip.id, { total_price: 100 });await addBudgetItemMember(orm, paid.id, user.id, { paid: 0 });await addBudgetItemMember(orm, paid.id, other.id, { paid: 0 });await addBudgetItemPayer(orm, paid.id, user.id, 100);- const unpaid = createBudgetItem(testDb, trip.id, { total_price: 40 });+ const unpaid = await makeBudgetItem(orm, trip.id, { total_price: 40 });await addBudgetItemMember(orm, unpaid.id, other.id, { paid: 0 });- const controller = await restController();- const rest = await controller.settlement(+ const rest = await restSettlement({ id: user.id } as User,{ id: trip.id, user_id: user.id } as TripAccess,String(trip.id),@@ -430,16 +415,15 @@ describe('Settlement tools', () => {.spyOn(ExchangeRatesService.prototype, 'getRates').mockImplementation(async (b: string) => quotes[b] ?? null);try {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();await updateRows(orm, Trips, { id: trip.id }, { currency: 'EUR' });- const item = createBudgetItem(testDb, trip.id, { total_price: 12345.67 });+ const item = await makeBudgetItem(orm, trip.id, { total_price: 12345.67 });await updateRows(orm, BudgetItems, { id: item.id }, { currency: 'USD', exchange_rate: 1.1398 });await addBudgetItemMember(orm, item.id, user.id, { paid: 0 });await addBudgetItemMember(orm, item.id, other.id, { paid: 0 });await addBudgetItemPayer(orm, item.id, user.id, 12345.67);- const controller = await restController();- const rest = await controller.settlement(+ const rest = await restSettlement({ id: user.id } as User,{ id: trip.id, user_id: user.id, currency: 'EUR' } as TripAccess,String(trip.id),@@ -466,17 +450,16 @@ describe('Settlement tools', () => {// ₩10,001 for two is 5,000.50 each. A whole won is the smallest amount that can// change hands, so that is what both surfaces offer, and an agent booking the// flow it was given squares the trip.- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();await updateRows(orm, Trips, { id: trip.id }, { currency: 'KRW' });- const item = createBudgetItem(testDb, trip.id, { total_price: 10001 });+ const item = await makeBudgetItem(orm, trip.id, { total_price: 10001 });await updateRows(orm, BudgetItems, { id: item.id }, { currency: 'KRW' });await addBudgetItemMember(orm, item.id, user.id, { paid: 0 });await addBudgetItemMember(orm, item.id, other.id, { paid: 0 });await addBudgetItemPayer(orm, item.id, user.id, 10001);- const controller = await restController();const access = { id: trip.id, user_id: user.id, currency: 'KRW' } as TripAccess;- const rest = await controller.settlement({ id: user.id } as User, access, String(trip.id), {});+ const rest = await restSettlement({ id: user.id } as User, access, String(trip.id), {});await withHarness(user.id, async (h) => {const result = await h.client.callTool({ name: 'get_settlement_summary', arguments: { tripId: trip.id } });@@ -499,9 +482,9 @@ describe('Settlement tools', () => {it('get_settlement_summary returns balances and flows', async () => {try {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();// user paid 100 for an item split between both → other owes user 50.- const item = createBudgetItem(testDb, trip.id, { total_price: 100 });+ const item = await makeBudgetItem(orm, trip.id, { total_price: 100 });await addBudgetItemMember(orm, item.id, user.id, { paid: 0 });await addBudgetItemMember(orm, item.id, other.id, { paid: 0 });await addBudgetItemPayer(orm, item.id, user.id, 100);@@ -524,8 +507,8 @@ describe('Settlement tools', () => {describe('Resource: trek://trips/{tripId}/budget/per-person', () => {it('returns array for trip with no items', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withResourceHarness(user.id, async (h) => {const result = await h.client.readResource({ uri: `trek://trips/${trip.id}/budget/per-person` });const data = parseResourceResult(result);@@ -534,9 +517,9 @@ describe('Resource: trek://trips/{tripId}/budget/per-person', () => {});it('returns access denied for non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);await withResourceHarness(user.id, async (h) => {const result = await h.client.readResource({ uri: `trek://trips/${trip.id}/budget/per-person` });const data = parseResourceResult(result) as { error?: string };@@ -551,8 +534,8 @@ describe('Resource: trek://trips/{tripId}/budget/per-person', () => {describe('Resource: trek://trips/{tripId}/budget/settlement', () => {it('returns settlement object for trip with no items', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withResourceHarness(user.id, async (h) => {const result = await h.client.readResource({ uri: `trek://trips/${trip.id}/budget/settlement` });// The resource may answer with a summary object or a bare array, and thediff --git a/server/tests/unit/mcp/tools-budget.test.ts b/server/tests/unit/mcp/tools-budget.test.tsindex 1ca7d16e8..6b7a96158 100644--- a/server/tests/unit/mcp/tools-budget.test.ts+++ b/server/tests/unit/mcp/tools-budget.test.ts@@ -4,7 +4,6 @@* payment was made in (the rest of the settlement surface lives in* tools-budget-advanced.test.ts).*/-import { db as testDb } from '../../../src/db/database';import { AppSettings } from '../../../src/db/entities/AppSettings.entity';import { BudgetItemMembers } from '../../../src/db/entities/BudgetItemMembers.entity';import { BudgetItems } from '../../../src/db/entities/BudgetItems.entity';@@ -14,34 +13,26 @@ import { TripMembers } from '../../../src/db/entities/TripMembers.entity';import { Trips } from '../../../src/db/entities/Trips.entity';import { BudgetService } from '../../../src/nest/budget/budget.service';import { invalidatePermissionsCache } from '../../../src/nest/permissions/permissions-cache';-import {- createUser,- createTrip,- createBudgetItem,- createPlace,- createReservation,- addTripMember,-} from '../../helpers/factories';-import { addBudgetItemMember, addBudgetItemPayer } from '../../helpers/factories/budget';+import { makeBudgetItem, addBudgetItemMember, addBudgetItemPayer } from '../../helpers/factories/budget';+import { makePlace } from '../../helpers/factories/places';+import { makeReservation } from '../../helpers/factories/reservations';import { countRows, deleteRows, findRow, findRows, insertRow, updateRows } from '../../helpers/factories/rows';import { setAppSetting } from '../../helpers/factories/settings';+import { addTripMember, makeTrip } from '../../helpers/factories/trips';+import { makeUser } from '../../helpers/factories/users';import { FakeRealtimeService } from '../../helpers/fake-realtime';import { createMcpHarness, parseToolResult, parseResourceResult, type McpHarness } from '../../helpers/mcp-harness';-import { resetTestDb } from '../../helpers/test-db';-import { createTestOrm, type TestOrm } from '../../helpers/test-orm';+import { resetDatabase } from '../../helpers/reset-database';+import { bootTestApp } from '../../helpers/test-app';+import { MikroORM } from '@mikro-orm/core';import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';-vi.mock('../../../src/db/database', async () => {- const { createSnapshotTestDb, buildDbMock } = await import('../../helpers/db-mock');- return buildDbMock(createSnapshotTestDb());-});-const realtime = new FakeRealtimeService();const broadcastMock = realtime.broadcastMock;-beforeEach(() => {- resetTestDb(testDb);+beforeEach(async () => {+ await resetDatabase(orm);broadcastMock.mockClear();delete process.env.DEMO_MODE;// Freezing the FX rate of a foreign currency is a real fetch to@@ -55,16 +46,16 @@ beforeEach(() => {);});-let orm: TestOrm;+// The booted container's own ORM, the one the tools write through.+let orm: MikroORM;beforeAll(async () => {- orm = await createTestOrm(testDb);+ orm = (await bootTestApp(realtime)).get(MikroORM);});afterAll(async () => {vi.unstubAllGlobals();- await orm.close();- testDb.close();+ await (await bootTestApp(realtime)).close();});async function withHarness(userId: number, fn: (h: McpHarness) => Promise<void>) {@@ -81,11 +72,11 @@ function errorText(result: Awaited<ReturnType<McpHarness['client']['callTool']>>return text?.text ?? '';}-function tripWithTwo() {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, user.id);- addTripMember(testDb, trip.id, other.id);+async function tripWithTwo() {+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ await addTripMember(orm, trip.id, other.id);return { user, other, trip };}@@ -140,8 +131,8 @@ function stubRates(rates: Record<string, number>): void {describe('Tool: create_budget_item', () => {it('creates a budget item with all fields', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -163,8 +154,8 @@ describe('Tool: create_budget_item', () => {});it('defaults category to "Other" when not specified', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -176,8 +167,8 @@ describe('Tool: create_budget_item', () => {});it('broadcasts budget:created event', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {await h.client.callTool({name: 'create_budget_item',@@ -190,8 +181,8 @@ describe('Tool: create_budget_item', () => {// Regression for #1244: a naive create must seed members so the client save-gate// (participants.size > 0) passes — the entry must be saveable, not member-less.it('defaults members to the trip owner when member_ids omitted (solo trip)', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -206,10 +197,10 @@ describe('Tool: create_budget_item', () => {});it('defaults members to all trip members when member_ids omitted (multi-member)', async () => {- const { user } = createUser(testDb);- const { user: member } = createUser(testDb);- const trip = createTrip(testDb, user.id);- addTripMember(testDb, trip.id, member.id);+ const { user } = await makeUser(orm);+ const { user: member } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ await addTripMember(orm, trip.id, member.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -223,10 +214,10 @@ describe('Tool: create_budget_item', () => {});it('respects an explicit member_ids subset', async () => {- const { user } = createUser(testDb);- const { user: member } = createUser(testDb);- const trip = createTrip(testDb, user.id);- addTripMember(testDb, trip.id, member.id);+ const { user } = await makeUser(orm);+ const { user: member } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ await addTripMember(orm, trip.id, member.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -238,8 +229,8 @@ describe('Tool: create_budget_item', () => {});it('treats an explicit empty member_ids as a planning-only entry (no split)', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -251,8 +242,8 @@ describe('Tool: create_budget_item', () => {});it('round-trips currency, expense_date, and payers', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -275,9 +266,9 @@ describe('Tool: create_budget_item', () => {});it('returns access denied for non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -289,8 +280,8 @@ describe('Tool: create_budget_item', () => {it('blocks demo user', async () => {process.env.DEMO_MODE = 'true';- const { user } = createUser(testDb, { email: '[email protected]' });- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm, { email: '[email protected]' });+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -307,9 +298,9 @@ describe('Tool: create_budget_item', () => {describe('Tool: update_budget_item', () => {it('updates budget item fields', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createBudgetItem(testDb, trip.id, { name: 'Old', category: 'Food', total_price: 50 });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makeBudgetItem(orm, trip.id, { name: 'Old', category: 'Food', total_price: 50 });await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'update_budget_item',@@ -323,9 +314,9 @@ describe('Tool: update_budget_item', () => {});it('broadcasts budget:updated event', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createBudgetItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makeBudgetItem(orm, trip.id);await withHarness(user.id, async (h) => {await h.client.callTool({name: 'update_budget_item',@@ -336,8 +327,8 @@ describe('Tool: update_budget_item', () => {});it('returns error for item not found', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'update_budget_item',@@ -348,10 +339,10 @@ describe('Tool: update_budget_item', () => {});it('returns access denied for non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);- const item = createBudgetItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);+ const item = await makeBudgetItem(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'update_budget_item',@@ -368,9 +359,9 @@ describe('Tool: update_budget_item', () => {describe('Tool: delete_budget_item', () => {it('deletes an existing budget item', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createBudgetItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makeBudgetItem(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'delete_budget_item',@@ -383,9 +374,9 @@ describe('Tool: delete_budget_item', () => {});it('broadcasts budget:deleted event', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createBudgetItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makeBudgetItem(orm, trip.id);await withHarness(user.id, async (h) => {await h.client.callTool({ name: 'delete_budget_item', arguments: { tripId: trip.id, itemId: item.id } });expect(broadcastMock).toHaveBeenCalledWith(trip.id, 'budget:deleted', expect.any(Object));@@ -393,8 +384,8 @@ describe('Tool: delete_budget_item', () => {});it('returns error for item not found', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'delete_budget_item',@@ -405,10 +396,10 @@ describe('Tool: delete_budget_item', () => {});it('returns access denied for non-member', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);- const item = createBudgetItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);+ const item = await makeBudgetItem(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'delete_budget_item',@@ -426,9 +417,9 @@ describe('Tool: delete_budget_item', () => {describe('Resource: trek://trips/{tripId}/budget', () => {it('returns budget items for a trip', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- createBudgetItem(testDb, trip.id, { name: 'Hotel', category: 'Accommodation', total_price: 200 });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ await makeBudgetItem(orm, trip.id, { name: 'Hotel', category: 'Accommodation', total_price: 200 });await withHarness(user.id, async (h) => {const result = await h.client.readResource({ uri: `trek://trips/${trip.id}/budget` });@@ -439,9 +430,9 @@ describe('Resource: trek://trips/{tripId}/budget', () => {});it('returns access denied for unauthorized trip', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- const trip = createTrip(testDb, other.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ const trip = await makeTrip(orm, other.id);await withHarness(user.id, async (h) => {const result = await h.client.readResource({ uri: `trek://trips/${trip.id}/budget` });@@ -458,7 +449,7 @@ describe('Resource: trek://trips/{tripId}/budget', () => {describe('Tool: create_budget_item (uneven split)', () => {it('persists what each member owes', async () => {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -482,7 +473,7 @@ describe('Tool: create_budget_item (uneven split)', () => {});it('refuses a split that does not add up to the total', async () => {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -503,7 +494,7 @@ describe('Tool: create_budget_item (uneven split)', () => {});it('measures the split against the payer sum, not the stated total', async () => {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -525,7 +516,7 @@ describe('Tool: create_budget_item (uneven split)', () => {});it('refuses a split that matches the stated total but not what the payers paid', async () => {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -546,8 +537,8 @@ describe('Tool: create_budget_item (uneven split)', () => {});it('refuses a member who is not on the trip', async () => {- const { user, trip } = tripWithTwo();- const { user: stranger } = createUser(testDb);+ const { user, trip } = await tripWithTwo();+ const { user: stranger } = await makeUser(orm);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -568,7 +559,7 @@ describe('Tool: create_budget_item (uneven split)', () => {});it('refuses members alongside member_ids', async () => {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -592,14 +583,14 @@ describe('Tool: create_budget_item (uneven split)', () => {describe('Tool: update_budget_item (uneven split)', () => {async function itemWithEqualSplit(tripId: number, userIds: number[]) {- const item = createBudgetItem(testDb, tripId, { name: 'Dinner', total_price: 100 });+ const item = await makeBudgetItem(orm, tripId, { name: 'Dinner', total_price: 100 });for (const id of userIds) await addBudgetItemMember(orm, item.id, id, { paid: 0, amount: null });await updateRows(orm, BudgetItems, { id: item.id }, { persons: userIds.length });return item;}it('replaces the equal split with per-member amounts', async () => {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();const item = await itemWithEqualSplit(trip.id, [user.id, other.id]);await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -623,7 +614,7 @@ describe('Tool: update_budget_item (uneven split)', () => {});it('measures the split against the stored total when the call does not restate it', async () => {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();const item = await itemWithEqualSplit(trip.id, [user.id, other.id]);await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -647,7 +638,7 @@ describe('Tool: update_budget_item (uneven split)', () => {});it('refuses the same member twice', async () => {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();const item = await itemWithEqualSplit(trip.id, [user.id, other.id]);await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -668,7 +659,7 @@ describe('Tool: update_budget_item (uneven split)', () => {});it('refuses members alongside member_ids', async () => {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();const item = await itemWithEqualSplit(trip.id, [user.id, other.id]);await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -687,7 +678,7 @@ describe('Tool: update_budget_item (uneven split)', () => {});it('reports a missing item before it looks at the split', async () => {- const { user, trip } = tripWithTwo();+ const { user, trip } = await tripWithTwo();await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'update_budget_item',@@ -705,9 +696,9 @@ describe('Tool: update_budget_item (uneven split)', () => {describe('Tool: update_budget_item (currency)', () => {it('changes the currency and freezes the rate at entry time', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createBudgetItem(testDb, trip.id, { total_price: 100 });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makeBudgetItem(orm, trip.id, { total_price: 100 });stubRates({ USD: 1.1 });await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -722,9 +713,9 @@ describe('Tool: update_budget_item (currency)', () => {});it('clears the currency back to the trip currency', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createBudgetItem(testDb, trip.id, { total_price: 100 });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makeBudgetItem(orm, trip.id, { total_price: 100 });await updateRows(orm, BudgetItems, { id: item.id }, { currency: 'USD', exchange_rate: 1.1 });await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -737,7 +728,7 @@ describe('Tool: update_budget_item (currency)', () => {});it('records and edits a note on the payment (#2340)', async () => {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();await withHarness(user.id, async (h) => {const created = parseToolResult(await h.client.callTool({@@ -764,9 +755,9 @@ describe('Tool: update_budget_item (currency)', () => {});it('refuses a currency that is not a code', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createBudgetItem(testDb, trip.id, { total_price: 100 });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makeBudgetItem(orm, trip.id, { total_price: 100 });await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'update_budget_item',@@ -780,9 +771,9 @@ describe('Tool: update_budget_item (currency)', () => {describe('Tool: update_budget_item (expense date)', () => {it('moves the expense to another date', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createBudgetItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makeBudgetItem(orm, trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'update_budget_item',@@ -794,9 +785,9 @@ describe('Tool: update_budget_item (expense date)', () => {});it('clears the expense date', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createBudgetItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makeBudgetItem(orm, trip.id);await updateRows(orm, BudgetItems, { id: item.id }, { expense_date: '2026-09-14' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -809,9 +800,9 @@ describe('Tool: update_budget_item (expense date)', () => {});it('refuses a date that is not a string', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const item = createBudgetItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const item = await makeBudgetItem(orm, trip.id);await updateRows(orm, BudgetItems, { id: item.id }, { expense_date: '2026-09-14' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -830,9 +821,9 @@ describe('Tool: update_budget_item (expense date)', () => {describe('Budget tools: place link', () => {it('create_budget_item links the expense to a place on the trip', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const place = createPlace(testDb, trip.id, { name: 'Louvre' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const place = await makePlace(orm, trip.id, { name: 'Louvre' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -844,10 +835,10 @@ describe('Budget tools: place link', () => {});it('create_budget_item refuses a place from another trip', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const elsewhere = createTrip(testDb, user.id);- const place = createPlace(testDb, elsewhere.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const elsewhere = await makeTrip(orm, user.id);+ const place = await makePlace(orm, elsewhere.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -860,8 +851,8 @@ describe('Budget tools: place link', () => {});it('create_budget_item_with_members links the expense to a place on the trip', async () => {- const { user, other, trip } = tripWithTwo();- const place = createPlace(testDb, trip.id, { name: 'Louvre' });+ const { user, other, trip } = await tripWithTwo();+ const place = await makePlace(orm, trip.id, { name: 'Louvre' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item_with_members',@@ -879,9 +870,9 @@ describe('Budget tools: place link', () => {});it('create_budget_item_with_members refuses a place from another trip', async () => {- const { user, trip } = tripWithTwo();- const elsewhere = createTrip(testDb, user.id);- const place = createPlace(testDb, elsewhere.id);+ const { user, trip } = await tripWithTwo();+ const elsewhere = await makeTrip(orm, user.id);+ const place = await makePlace(orm, elsewhere.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item_with_members',@@ -907,9 +898,9 @@ describe('Budget tools: booking link on create', () => {}it('create_budget_item links the expense to a booking, which mirrors its total', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const booking = createReservation(testDb, trip.id, { title: 'Flight' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const booking = await makeReservation(orm, trip.id, { title: 'Flight' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -924,9 +915,9 @@ describe('Budget tools: booking link on create', () => {});it('create_budget_item adds a second expense to a booking, which then mirrors their sum', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const booking = createReservation(testDb, trip.id, { title: 'Flight' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const booking = await makeReservation(orm, trip.id, { title: 'Flight' });await withHarness(user.id, async (h) => {const add = (name: string, total_price: number) =>h.client.callTool({@@ -940,10 +931,10 @@ describe('Budget tools: booking link on create', () => {});it('create_budget_item refuses a booking from another trip and writes nothing', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const elsewhere = createTrip(testDb, user.id);- const foreign = createReservation(testDb, elsewhere.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const elsewhere = await makeTrip(orm, user.id);+ const foreign = await makeReservation(orm, elsewhere.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -957,8 +948,8 @@ describe('Budget tools: booking link on create', () => {});it('create_budget_item_with_members links the expense to a booking', async () => {- const { user, other, trip } = tripWithTwo();- const booking = createReservation(testDb, trip.id, { title: 'Train' });+ const { user, other, trip } = await tripWithTwo();+ const booking = await makeReservation(orm, trip.id, { title: 'Train' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item_with_members',@@ -977,9 +968,9 @@ describe('Budget tools: booking link on create', () => {});it('create_budget_item_with_members refuses a booking from another trip', async () => {- const { user, trip } = tripWithTwo();- const elsewhere = createTrip(testDb, user.id);- const foreign = createReservation(testDb, elsewhere.id);+ const { user, trip } = await tripWithTwo();+ const elsewhere = await makeTrip(orm, user.id);+ const foreign = await makeReservation(orm, elsewhere.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item_with_members',@@ -1014,11 +1005,11 @@ describe('Tool: update_budget_item (links)', () => {}it('links two expenses to one booking, which then mirrors their sum', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const booking = createReservation(testDb, trip.id, { title: 'Flight' });- const fare = createBudgetItem(testDb, trip.id, { name: 'Fare', total_price: 180 });- const luggage = createBudgetItem(testDb, trip.id, { name: 'Luggage', total_price: 35.5 });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const booking = await makeReservation(orm, trip.id, { title: 'Flight' });+ const fare = await makeBudgetItem(orm, trip.id, { name: 'Fare', total_price: 180 });+ const luggage = await makeBudgetItem(orm, trip.id, { name: 'Luggage', total_price: 35.5 });await withHarness(user.id, async (h) => {const result = await update(h, { tripId: trip.id, itemId: fare.id, reservation_id: booking.id });expect((parseToolResult(result) as any).item.reservation_id).toBe(booking.id);@@ -1043,11 +1034,11 @@ describe('Tool: update_budget_item (links)', () => {});it('refuses a booking from another trip, in the words the REST route uses, and writes nothing', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const elsewhere = createTrip(testDb, user.id);- const foreign = createReservation(testDb, elsewhere.id);- const item = createBudgetItem(testDb, trip.id, { name: 'Fare' });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const elsewhere = await makeTrip(orm, user.id);+ const foreign = await makeReservation(orm, elsewhere.id);+ const item = await makeBudgetItem(orm, trip.id, { name: 'Fare' });await withHarness(user.id, async (h) => {const result = await update(h, { tripId: trip.id, itemId: item.id, reservation_id: foreign.id, name: 'Renamed' });expect(result.isError).toBe(true);@@ -1060,11 +1051,11 @@ describe('Tool: update_budget_item (links)', () => {});it('refuses a place from another trip', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const elsewhere = createTrip(testDb, user.id);- const foreign = createPlace(testDb, elsewhere.id);- const item = createBudgetItem(testDb, trip.id);+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const elsewhere = await makeTrip(orm, user.id);+ const foreign = await makePlace(orm, elsewhere.id);+ const item = await makeBudgetItem(orm, trip.id);await withHarness(user.id, async (h) => {const result = await update(h, { tripId: trip.id, itemId: item.id, place_id: foreign.id });expect(result.isError).toBe(true);@@ -1074,10 +1065,10 @@ describe('Tool: update_budget_item (links)', () => {});it('links an expense to a place, and null lets go of it while the expense stays', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const place = createPlace(testDb, trip.id, { name: 'Louvre' });- const item = createBudgetItem(testDb, trip.id, { name: 'Tickets', total_price: 34 });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const place = await makePlace(orm, trip.id, { name: 'Louvre' });+ const item = await makeBudgetItem(orm, trip.id, { name: 'Tickets', total_price: 34 });await withHarness(user.id, async (h) => {await update(h, { tripId: trip.id, itemId: item.id, place_id: place.id });expect((await links(item.id)).place_id).toBe(place.id);@@ -1091,11 +1082,11 @@ describe('Tool: update_budget_item (links)', () => {});it('null lets go of the booking, keeps the expense and takes its share off the booking price', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const booking = createReservation(testDb, trip.id);- const fare = createBudgetItem(testDb, trip.id, { total_price: 100 });- const extra = createBudgetItem(testDb, trip.id, { total_price: 20 });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const booking = await makeReservation(orm, trip.id);+ const fare = await makeBudgetItem(orm, trip.id, { total_price: 100 });+ const extra = await makeBudgetItem(orm, trip.id, { total_price: 20 });await withHarness(user.id, async (h) => {await update(h, { tripId: trip.id, itemId: fare.id, reservation_id: booking.id });await update(h, { tripId: trip.id, itemId: extra.id, reservation_id: booking.id });@@ -1110,11 +1101,11 @@ describe('Tool: update_budget_item (links)', () => {});it('moving an expense to another booking resyncs both', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const outbound = createReservation(testDb, trip.id, { title: 'Out' });- const inbound = createReservation(testDb, trip.id, { title: 'Back' });- const item = createBudgetItem(testDb, trip.id, { total_price: 75 });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const outbound = await makeReservation(orm, trip.id, { title: 'Out' });+ const inbound = await makeReservation(orm, trip.id, { title: 'Back' });+ const item = await makeBudgetItem(orm, trip.id, { total_price: 75 });await withHarness(user.id, async (h) => {await update(h, { tripId: trip.id, itemId: item.id, reservation_id: outbound.id });await update(h, { tripId: trip.id, itemId: item.id, reservation_id: inbound.id });@@ -1124,10 +1115,10 @@ describe('Tool: update_budget_item (links)', () => {});it('a new total on a linked expense reaches the booking price', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const booking = createReservation(testDb, trip.id);- const item = createBudgetItem(testDb, trip.id, { total_price: 50 });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const booking = await makeReservation(orm, trip.id);+ const item = await makeBudgetItem(orm, trip.id, { total_price: 50 });await updateRows(orm, BudgetItems, { id: item.id }, { reservation: booking.id });await withHarness(user.id, async (h) => {await update(h, { tripId: trip.id, itemId: item.id, total_price: 64.2 });@@ -1136,10 +1127,10 @@ describe('Tool: update_budget_item (links)', () => {});it('a currency change alone on a linked expense re-names the booking price', async () => {- const { user } = createUser(testDb);- const trip = createTrip(testDb, user.id);- const booking = createReservation(testDb, trip.id);- const item = createBudgetItem(testDb, trip.id, { total_price: 50 });+ const { user } = await makeUser(orm);+ const trip = await makeTrip(orm, user.id);+ const booking = await makeReservation(orm, trip.id);+ const item = await makeBudgetItem(orm, trip.id, { total_price: 50 });await updateRows(orm, BudgetItems, { id: item.id }, { reservation: booking.id });stubRates({ USD: 1.1 });await withHarness(user.id, async (h) => {@@ -1157,7 +1148,7 @@ describe('Tool: update_budget_item (links)', () => {describe('Tool: create_settlement (currency)', () => {it('records the payment in the currency it was made in and freezes its rate', async () => {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();stubRates({ USD: 1.1 });await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -1173,7 +1164,7 @@ describe('Tool: create_settlement (currency)', () => {});it('books the payment in the trip currency when none is given', async () => {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();await withHarness(user.id, async (h) => {const result = await h.client.callTool({name: 'create_settlement',@@ -1187,7 +1178,7 @@ describe('Tool: create_settlement (currency)', () => {});it('refuses a currency that is not a code', async () => {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();const before = await settlementCount(trip.id);await withHarness(user.id, async (h) => {const result = await h.client.callTool({@@ -1208,7 +1199,7 @@ describe('Tool: create_settlement (currency)', () => {describe('Tool: update_settlement (currency)', () => {it('changes the currency the payment was made in and freezes its rate', async () => {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();await withHarness(user.id, async (h) => {const created = parseToolResult(await h.client.callTool({@@ -1236,7 +1227,7 @@ describe('Tool: update_settlement (currency)', () => {});it('clears the currency back to the trip currency', async () => {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();stubRates({ USD: 1.1 });await withHarness(user.id, async (h) => {const created = parseToolResult(@@ -1274,9 +1265,9 @@ describe('Tool: update_settlement (currency)', () => {describe('Budget tools: a custom split cannot be certified against a total the row will not get', () => {it('refuses a payer who is not on the trip rather than storing an unbalanced split', async () => {- const { user: owner } = createUser(testDb);- const { user: stranger } = createUser(testDb);- const trip = createTrip(testDb, owner.id);+ const { user: owner } = await makeUser(orm);+ const { user: stranger } = await makeUser(orm);+ const trip = await makeTrip(orm, owner.id);await withHarness(owner.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -1298,10 +1289,10 @@ describe('Budget tools: a custom split cannot be certified against a total the r});it('refuses an empty payer list under a non-zero split, because the stored total becomes zero', async () => {- const { user: owner } = createUser(testDb);- const { user: friend } = createUser(testDb);- const trip = createTrip(testDb, owner.id);- addTripMember(testDb, trip.id, friend.id);+ const { user: owner } = await makeUser(orm);+ const { user: friend } = await makeUser(orm);+ const trip = await makeTrip(orm, owner.id);+ await addTripMember(orm, trip.id, friend.id);await withHarness(owner.id, async (h) => {const created = await h.client.callTool({name: 'create_budget_item',@@ -1330,8 +1321,8 @@ describe('Budget tools: a custom split cannot be certified against a total the r});it('accepts an empty payer list when the split is empty too', async () => {- const { user: owner } = createUser(testDb);- const trip = createTrip(testDb, owner.id);+ const { user: owner } = await makeUser(orm);+ const trip = await makeTrip(orm, owner.id);await withHarness(owner.id, async (h) => {const created = await h.client.callTool({name: 'create_budget_item',@@ -1350,10 +1341,10 @@ describe('Budget tools: a custom split cannot be certified against a total the r});it('still certifies a split against the payer sum when every payer is on the trip', async () => {- const { user: owner } = createUser(testDb);- const { user: friend } = createUser(testDb);- const trip = createTrip(testDb, owner.id);- addTripMember(testDb, trip.id, friend.id);+ const { user: owner } = await makeUser(orm);+ const { user: friend } = await makeUser(orm);+ const trip = await makeTrip(orm, owner.id);+ await addTripMember(orm, trip.id, friend.id);await withHarness(owner.id, async (h) => {const result = await h.client.callTool({name: 'create_budget_item',@@ -1384,11 +1375,11 @@ describe('Budget tools: a custom split cannot be certified against a total the r// #2604: someone removed from the trip keeps their rows on the expense, and an// edit that sends them back must not be refused as if they were a stranger.it('certifies an edit that keeps someone who has left the trip on the expense (#2604)', async () => {- const { user: owner } = createUser(testDb);- const { user: friend } = createUser(testDb);- const { user: stranger } = createUser(testDb);- const trip = createTrip(testDb, owner.id);- addTripMember(testDb, trip.id, friend.id);+ const { user: owner } = await makeUser(orm);+ const { user: friend } = await makeUser(orm);+ const { user: stranger } = await makeUser(orm);+ const trip = await makeTrip(orm, owner.id);+ await addTripMember(orm, trip.id, friend.id);await withHarness(owner.id, async (h) => {const created = await h.client.callTool({name: 'create_budget_item',@@ -1451,10 +1442,10 @@ describe('Budget tools: a custom split cannot be certified against a total the r/** A trip in `currency` with one unfrozen VND bill and one unfrozen VND transfer. */async function tripWithVndRows(currency: string) {- const { user, other, trip } = tripWithTwo();+ const { user, other, trip } = await tripWithTwo();await updateRows(orm, Trips, { id: trip.id }, { currency });await deleteRows(orm, BudgetSettlements, { trip: trip.id });- const item = createBudgetItem(testDb, trip.id, { name: 'Pho', total_price: 8920000 });+ const item = await makeBudgetItem(orm, trip.id, { name: 'Pho', total_price: 8920000 });await updateRows(orm, BudgetItems, { id: item.id }, { currency: 'VND', exchange_rate: 1 });await addBudgetItemMember(orm, item.id, user.id, { paid: 0 });await addBudgetItemMember(orm, item.id, other.id, { paid: 0 });@@ -1473,7 +1464,7 @@ async function tripWithVndRows(currency: string) {describe('Tool: freeze_budget_rates', () => {it('refuses a demo user, a stranger and a member without budget_edit, writing nothing', async () => {const { other, trip, item, settlementId } = await tripWithVndRows('AUD');- const { user: stranger } = createUser(testDb);+ const { user: stranger } = await makeUser(orm);const spy = vi.spyOn(BudgetService.prototype, 'freezeMissingRates');try {await withHarness(stranger.id, async (h) => {@@ -1492,8 +1483,8 @@ describe('Tool: freeze_budget_rates', () => {await invalidatePermissionsCache();process.env.DEMO_MODE = 'true';- const { user: demo } = createUser(testDb, { email: '[email protected]' });- addTripMember(testDb, trip.id, demo.id);+ const { user: demo } = await makeUser(orm, { email: '[email protected]' });+ await addTripMember(orm, trip.id, demo.id);await withHarness(demo.id, async (h) => {const result = await h.client.callTool({ name: 'freeze_budget_rates', arguments: { tripId: trip.id } });expect(result.isError).toBe(true);diff --git a/server/tests/unit/mcp/tools-collections.test.ts b/server/tests/unit/mcp/tools-collections.test.tsindex 8d1ab7a64..97a975df1 100644--- a/server/tests/unit/mcp/tools-collections.test.ts+++ b/server/tests/unit/mcp/tools-collections.test.ts@@ -13,65 +13,46 @@* unconditionally while REST and the plugin host gated; the port fixed that).*/import { ADDON_IDS } from '../../../src/addons';-import { db as testDb } from '../../../src/db/database';import { Addons } from '../../../src/db/entities/Addons.entity';import { CollectionLabels } from '../../../src/db/entities/CollectionLabels.entity';import { CollectionMembers } from '../../../src/db/entities/CollectionMembers.entity';import { CollectionPlaces } from '../../../src/db/entities/CollectionPlaces.entity';import { Collections } from '../../../src/db/entities/Collections.entity';import { Places } from '../../../src/db/entities/Places.entity';-import { createUser, createTrip, createPlace, createCategory } from '../../helpers/factories';import { addCollectionMember } from '../../helpers/factories/collections';+import { makeCategory, makePlace } from '../../helpers/factories/places';import { countRows, findRow, findRows, insertRow, updateRows } from '../../helpers/factories/rows';+import { makeTrip } from '../../helpers/factories/trips';+import { makeUser } from '../../helpers/factories/users';import { FakeRealtimeService } from '../../helpers/fake-realtime';import { createMcpHarness, parseToolResult, type McpHarness } from '../../helpers/mcp-harness';-import { createTestOrm, type TestOrm } from '../../helpers/test-orm';+import { resetDatabase } from '../../helpers/reset-database';+import { bootTestApp } from '../../helpers/test-app';+import { MikroORM } from '@mikro-orm/core';import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';-vi.mock('../../../src/db/database', async () => {- const { createSnapshotTestDb, buildDbMock } = await import('../../helpers/db-mock');- return buildDbMock(createSnapshotTestDb());-});const { notifSend } = vi.hoisted(() => ({ notifSend: vi.fn().mockResolvedValue(undefined) }));const realtime = new FakeRealtimeService();const broadcastToUser = realtime.broadcastToUserMock;-function clearCollections() {- testDb.exec(`- DELETE FROM collection_place_labels;- DELETE FROM collection_labels;- DELETE FROM collection_place_tags;- DELETE FROM collection_place_ratings;- DELETE FROM collection_places;- DELETE FROM collection_members;- DELETE FROM collections;- DELETE FROM place_tags;- DELETE FROM places;- DELETE FROM trip_members;- DELETE FROM trips;- DELETE FROM users;- `);-}-beforeAll(async () => {// The collections addon is seeded DISABLED by default and every tool rides// the `when:` addon gate (post-fold quirk fix) — enable it for the suite.- orm = await createTestOrm(testDb);+ orm = (await bootTestApp(realtime)).get(MikroORM);await updateRows(orm, Addons, { id: ADDON_IDS.COLLECTIONS }, { enabled: true });});-beforeEach(() => {- clearCollections();+beforeEach(async () => {+ await resetDatabase(orm);broadcastToUser.mockClear();notifSend.mockClear();delete process.env.DEMO_MODE;});afterAll(async () => {- await orm.close();- testDb.close();+ await (await bootTestApp(realtime)).close();});async function withHarness(userId: number, fn: (h: McpHarness) => Promise<void>) {@@ -88,7 +69,8 @@ function errorText(result: Awaited<ReturnType<McpHarness['client']['callTool']>>return text?.text ?? '';}-let orm: TestOrm;+// The booted container's own ORM, the one the tools write through.+let orm: MikroORM;/** Seed a collection directly (owner_id row only — no service round trip). */function seedCollection(ownerId: number, name = 'List'): Promise<number> {@@ -138,8 +120,8 @@ async function statusOf(placeId: number): Promise<string | undefined> {describe('Tool: list_collections', () => {it('lists owned collections plus incoming invites', async () => {- const { user } = createUser(testDb);- const { user: inviter } = createUser(testDb);+ const { user } = await makeUser(orm);+ const { user: inviter } = await makeUser(orm);await seedCollection(user.id, 'Mine');const invitedTo = await seedCollection(inviter.id, 'Theirs');await addMember(invitedTo, user.id, 'editor', 'pending');@@ -156,7 +138,7 @@ describe('Tool: list_collections', () => {describe('Tool: get_collection', () => {it('returns the detail with places, labels and members', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const col = await seedCollection(user.id, 'Detail');await seedPlace(col, user.id, 'Louvre');await withHarness(user.id, async (h) => {@@ -172,8 +154,8 @@ describe('Tool: get_collection', () => {});it('surfaces the 404 error text for an inaccessible collection', async () => {- const { user } = createUser(testDb);- const { user: owner } = createUser(testDb);+ const { user } = await makeUser(orm);+ const { user: owner } = await makeUser(orm);const col = await seedCollection(owner.id, 'Hidden');await withHarness(user.id, async (h) => {const result = await h.client.callTool({ name: 'get_collection', arguments: { collectionId: col } });@@ -185,10 +167,10 @@ describe('Tool: get_collection', () => {describe('Tool: available_collection_users', () => {it('is owner-only: owner 200, accepted member gets the bespoke error, stranger a 404 text', async () => {- const { user: owner } = createUser(testDb);- const { user: member } = createUser(testDb);- const { user: stranger } = createUser(testDb);- const { user: invitable } = createUser(testDb);+ const { user: owner } = await makeUser(orm);+ const { user: member } = await makeUser(orm);+ const { user: stranger } = await makeUser(orm);+ const { user: invitable } = await makeUser(orm);const col = await seedCollection(owner.id, 'Members');await addMember(col, member.id);@@ -226,8 +208,8 @@ describe('Tool: available_collection_users', () => {describe('Tool: find_place_in_collections', () => {it('names every visible list holding the place, with its per-list status and edit right', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);const mine = await seedCollection(user.id, 'Paris');const shared = await seedCollection(other.id, 'Their museums');const hidden = await seedCollection(other.id, 'Not shared');@@ -253,7 +235,7 @@ describe('Tool: find_place_in_collections', () => {});it('matches by coordinates within the dedup tolerance and not outside it', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const col = await seedCollection(user.id, 'Rome');await seedPlace(col, user.id, 'Pantheon', { lat: 41.8986, lng: 12.4769 });@@ -279,7 +261,7 @@ describe('Tool: find_place_in_collections', () => {});it('reports nothing for a name-only query, since a repeated name is not a match signal', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const col = await seedCollection(user.id, 'Coffee');await seedPlace(col, user.id, 'Starbucks', { lat: 47.6062, lng: -122.3321 });@@ -297,13 +279,13 @@ describe('Tool: find_place_in_collections', () => {describe('Tool: get_collection_items', () => {it('MCP-COLL-ITEMS-001: reads saved places and labels by their ids with their lists, leaving out what the user cannot see', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);const mine = await seedCollection(user.id, 'Paris');const shared = await seedCollection(other.id, 'Shared with me');const hidden = await seedCollection(other.id, 'Not shared');await addMember(shared, user.id, 'viewer');- const { user: invited } = createUser(testDb);+ const { user: invited } = await makeUser(orm);await addMember(shared, invited.id, 'editor', 'pending');const louvre = await seedPlace(mine, user.id, 'Louvre', { status: 'want' });await seedPlace(mine, user.id, 'Not asked for');@@ -342,7 +324,7 @@ describe('Tool: get_collection_items', () => {});it('MCP-COLL-ITEMS-002: an empty or unknown lookup answers empty lists; more than 50 places is refused', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);await withHarness(user.id, async (h) => {const empty = parseToolResult(await h.client.callTool({ name: 'get_collection_items', arguments: {} }));expect(empty).toEqual({ lists: [], places: [], labels: [] });@@ -361,7 +343,7 @@ describe('Tool: get_collection_items', () => {describe('Tool: create_collection / update_collection / delete_collection / reorder_collections', () => {it('create → update → reorder → delete round trip', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);await withHarness(user.id, async (h) => {const created = parseToolResult(await h.client.callTool({ name: 'create_collection', arguments: { name: 'Italy' } }),@@ -398,8 +380,8 @@ describe('Tool: create_collection / update_collection / delete_collection / reor});it('delete_collection is owner-only (bespoke 403 text) and update surfaces the viewer 403', async () => {- const { user: owner } = createUser(testDb);- const { user: viewer } = createUser(testDb);+ const { user: owner } = await makeUser(orm);+ const { user: viewer } = await makeUser(orm);const col = await seedCollection(owner.id, 'Guarded');await addMember(col, viewer.id, 'viewer');await withHarness(viewer.id, async (h) => {@@ -418,7 +400,7 @@ describe('Tool: create_collection / update_collection / delete_collection / reorit('blocks demo user on writes', async () => {process.env.DEMO_MODE = 'true';- const { user } = createUser(testDb, { email: '[email protected]' });+ const { user } = await makeUser(orm, { email: '[email protected]' });await withHarness(user.id, async (h) => {const result = await h.client.callTool({ name: 'create_collection', arguments: { name: 'X' } });expect(result.isError).toBe(true);@@ -432,7 +414,7 @@ describe('Tool: create_collection / update_collection / delete_collection / reordescribe('Tool: save_place_to_collection', () => {it('saves a place and returns the duplicate marker on a re-save', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const col = await seedCollection(user.id, 'Dedup');await withHarness(user.id, async (h) => {const saved = parseToolResult(@@ -459,7 +441,7 @@ describe('Tool: save_place_to_collection', () => {// search_place is saved with https here too.describe('Tool: save_place_to_collection and a website without a scheme (#2483)', () => {it('MCP-COLL-2483-01: stores https for a bare host and still refuses a script link', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const col = await seedCollection(user.id, 'Bretagne');const site = 'fr.wikipedia.org/wiki/Chapelle_Sainte-Barbe_du_Faouët';await withHarness(user.id, async (h) => {@@ -485,11 +467,11 @@ describe('Tool: save_place_to_collection and a website without a scheme (#2483)'describe('Tool: save_trip_places_to_collection', () => {it('copies trip places, skipping duplicates', async () => {- const { user } = createUser(testDb);- createCategory(testDb);- const trip = createTrip(testDb, user.id);- const p1 = createPlace(testDb, trip.id, { name: 'Colosseum' });- const p2 = createPlace(testDb, trip.id, { name: 'Pantheon' });+ const { user } = await makeUser(orm);+ await makeCategory(orm);+ const trip = await makeTrip(orm, user.id);+ const p1 = await makePlace(orm, trip.id, { name: 'Colosseum' });+ const p2 = await makePlace(orm, trip.id, { name: 'Pantheon' });const col = await seedCollection(user.id, 'From trip');await seedPlace(col, user.id, 'Pantheon'); // pre-existing → duplicateawait withHarness(user.id, async (h) => {@@ -507,7 +489,7 @@ describe('Tool: save_trip_places_to_collection', () => {describe('Tool: update_collection_place / set_collection_place_status / rate_collection_place', () => {it('updates fields, sets status, and stores/clears a rating', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const col = await seedCollection(user.id, 'P');const pid = await seedPlace(col, user.id, 'Gate');await withHarness(user.id, async (h) => {@@ -549,8 +531,8 @@ describe('Tool: update_collection_place / set_collection_place_status / rate_col});it('update_collection_place refuses an editor moving a place out of a shared list', async () => {- const { user: owner } = createUser(testDb);- const { user: editor } = createUser(testDb);+ const { user: owner } = await makeUser(orm);+ const { user: editor } = await makeUser(orm);const shared = await seedCollection(owner.id, 'Shared');await addMember(shared, editor.id, 'editor');const own = await seedCollection(editor.id, 'Mine');@@ -568,7 +550,7 @@ describe('Tool: update_collection_place / set_collection_place_status / rate_col// #2646: the fields saving takes, through the same contract and checks as REST.it('update_collection_place sets and clears provider ids, website, phone and price, and refuses a script link', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const col = await seedCollection(user.id, 'Listings');const pid = await seedPlace(col, user.id, 'Septime');const update = (h: McpHarness, args: Record<string, unknown>) =>@@ -622,11 +604,11 @@ describe('Tool: update_collection_place / set_collection_place_status / rate_coldescribe('Tool: set_collection_place_status_from_trip', () => {it('marks every saved copy of a trip place across the lists holding it', async () => {- const { user } = createUser(testDb);- createCategory(testDb);- const trip = createTrip(testDb, user.id);- const louvre = createPlace(testDb, trip.id, { name: 'Louvre', lat: 48.8606, lng: 2.3376 });- const orsay = createPlace(testDb, trip.id, { name: "Musee d'Orsay", lat: 48.86, lng: 2.3266 });+ const { user } = await makeUser(orm);+ await makeCategory(orm);+ const trip = await makeTrip(orm, user.id);+ const louvre = await makePlace(orm, trip.id, { name: 'Louvre', lat: 48.8606, lng: 2.3376 });+ const orsay = await makePlace(orm, trip.id, { name: "Musee d'Orsay", lat: 48.86, lng: 2.3266 });const paris = await seedCollection(user.id, 'Paris');const museums = await seedCollection(user.id, 'Museums');// Two different match signals: coordinates in one list, the source link the@@ -655,11 +637,11 @@ describe('Tool: set_collection_place_status_from_trip', () => {});it('skips a list the user may only read instead of refusing the batch', async () => {- const { user } = createUser(testDb);- const { user: owner } = createUser(testDb);- createCategory(testDb);- const trip = createTrip(testDb, user.id);- const prado = createPlace(testDb, trip.id, { name: 'Prado', lat: 40.4138, lng: -3.6921 });+ const { user } = await makeUser(orm);+ const { user: owner } = await makeUser(orm);+ await makeCategory(orm);+ const trip = await makeTrip(orm, user.id);+ const prado = await makePlace(orm, trip.id, { name: 'Prado', lat: 40.4138, lng: -3.6921 });const own = await seedCollection(user.id, 'Madrid');const readOnly = await seedCollection(owner.id, 'Their list');await addMember(readOnly, user.id, 'viewer');@@ -681,11 +663,11 @@ describe('Tool: set_collection_place_status_from_trip', () => {});it('surfaces the 404 text for a trip the user cannot access, leaving statuses alone', async () => {- const { user } = createUser(testDb);- const { user: stranger } = createUser(testDb);- createCategory(testDb);- const trip = createTrip(testDb, stranger.id);- const place = createPlace(testDb, trip.id, { name: 'Alhambra', lat: 37.176, lng: -3.5881 });+ const { user } = await makeUser(orm);+ const { user: stranger } = await makeUser(orm);+ await makeCategory(orm);+ const trip = await makeTrip(orm, stranger.id);+ const place = await makePlace(orm, trip.id, { name: 'Alhambra', lat: 37.176, lng: -3.5881 });const col = await seedCollection(user.id, 'Spain');const saved = await seedPlace(col, user.id, 'Alhambra', { lat: 37.176, lng: -3.5881 });@@ -701,10 +683,10 @@ describe('Tool: set_collection_place_status_from_trip', () => {});it('refuses an empty place_ids, and falls back to idea on an unknown status like the REST contract', async () => {- const { user } = createUser(testDb);- createCategory(testDb);- const trip = createTrip(testDb, user.id);- const place = createPlace(testDb, trip.id, { name: 'Sagrada Familia', lat: 41.4036, lng: 2.1744 });+ const { user } = await makeUser(orm);+ await makeCategory(orm);+ const trip = await makeTrip(orm, user.id);+ const place = await makePlace(orm, trip.id, { name: 'Sagrada Familia', lat: 41.4036, lng: 2.1744 });const col = await seedCollection(user.id, 'Barcelona');const saved = await seedPlace(col, user.id, 'Sagrada Familia', { lat: 41.4036, lng: 2.1744, status: 'want' });@@ -729,7 +711,7 @@ describe('Tool: set_collection_place_status_from_trip', () => {describe('Tool: delete_collection_place', () => {it('deletes a place; an unknown id surfaces the 404 text', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const col = await seedCollection(user.id, 'D');const pid = await seedPlace(col, user.id, 'Gone');await withHarness(user.id, async (h) => {@@ -745,9 +727,9 @@ describe('Tool: delete_collection_place', () => {describe('Tool: copy_collection_places_to_trip', () => {it('copies saved places into a trip the user can edit', async () => {- const { user } = createUser(testDb);- createCategory(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ await makeCategory(orm);+ const trip = await makeTrip(orm, user.id);const col = await seedCollection(user.id, 'Plan');const pid = await seedPlace(col, user.id, 'Trevi Fountain');await withHarness(user.id, async (h) => {@@ -763,9 +745,9 @@ describe('Tool: copy_collection_places_to_trip', () => {});it('MCP-COLL-COPY-001: each copied place reaches every tab of the trip as place:created, the asking one included', async () => {- const { user } = createUser(testDb);- createCategory(testDb);- const trip = createTrip(testDb, user.id);+ const { user } = await makeUser(orm);+ await makeCategory(orm);+ const trip = await makeTrip(orm, user.id);const col = await seedCollection(user.id, 'Plan');const pid = await seedPlace(col, user.id, 'Spanish Steps');realtime.broadcastMock.mockClear();@@ -784,10 +766,10 @@ describe('Tool: copy_collection_places_to_trip', () => {});it('surfaces the 404 text for a trip the user cannot access', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);- createCategory(testDb);- const trip = createTrip(testDb, other.id);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);+ await makeCategory(orm);+ const trip = await makeTrip(orm, other.id);const col = await seedCollection(user.id, 'C');const pid = await seedPlace(col, user.id, 'X');realtime.broadcastMock.mockClear();@@ -810,7 +792,7 @@ describe('Tool: copy_collection_places_to_trip', () => {describe('Label tools', () => {it('create → assign → update → unassign → delete a label', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const col = await seedCollection(user.id, 'DE');const pid = await seedPlace(col, user.id, 'Gate');await withHarness(user.id, async (h) => {@@ -856,7 +838,7 @@ describe('Label tools', () => {});it('duplicate label name surfaces the 409 text', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const col = await seedCollection(user.id, 'DE');await withHarness(user.id, async (h) => {await h.client.callTool({ name: 'create_collection_label', arguments: { collection_id: col, name: 'Berlin' } });@@ -876,8 +858,8 @@ describe('Label tools', () => {describe('Sharing tools', () => {it('invite → accept → set role → remove member round trip', async () => {- const { user: owner } = createUser(testDb);- const { user: target } = createUser(testDb);+ const { user: owner } = await makeUser(orm);+ const { user: target } = await makeUser(orm);const col = await seedCollection(owner.id, 'Shared');await withHarness(owner.id, async (h) => {@@ -920,8 +902,8 @@ describe('Sharing tools', () => {});it('invite errors come back as isError text (self-invite / not owner)', async () => {- const { user: owner } = createUser(testDb);- const { user: other } = createUser(testDb);+ const { user: owner } = await makeUser(orm);+ const { user: other } = await makeUser(orm);const col = await seedCollection(owner.id, 'OwnerOnly');await withHarness(owner.id, async (h) => {const self = await h.client.callTool({@@ -942,8 +924,8 @@ describe('Sharing tools', () => {});it('accept without a pending invite → error text; decline and cancel clear the pending row', async () => {- const { user: owner } = createUser(testDb);- const { user: target } = createUser(testDb);+ const { user: owner } = await makeUser(orm);+ const { user: target } = await makeUser(orm);const col = await seedCollection(owner.id, 'Pending');await withHarness(target.id, async (h) => {@@ -977,8 +959,8 @@ describe('Sharing tools', () => {});it('leave_collection: member leaves; the owner gets the bespoke 400 text', async () => {- const { user: owner } = createUser(testDb);- const { user: member } = createUser(testDb);+ const { user: owner } = await makeUser(orm);+ const { user: member } = await makeUser(orm);const col = await seedCollection(owner.id, 'Leavable');await addMember(col, member.id);await withHarness(member.id, async (h) => {@@ -1025,7 +1007,7 @@ describe('Tool: list_collection_places', () => {}it('MCP-COLL-PAGE-001: pages through a list in its order, compact rows leaving out what a place lacks', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const col = await seedCollection(user.id, 'Paris');await seedPlaces(col, user.id, 4);await seedPlace(col, user.id, 'Septime', { lat: 48.85, lng: 2.38, status: 'want', google_place_id: 'ChIJseptime' });@@ -1061,7 +1043,7 @@ describe('Tool: list_collection_places', () => {});it('MCP-COLL-PAGE-002: labelling each page while paging through the unlabeled places skips none', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const col = await seedCollection(user.id, 'Long list');const ids = await seedPlaces(col, user.id, 6);const done = await insertRow(orm, CollectionLabels, { collection: col, name: 'Done' });@@ -1093,8 +1075,8 @@ describe('Tool: list_collection_places', () => {});it('MCP-COLL-PAGE-003: filters by status, and refuses a foreign label, both label filters at once and a made-up cursor', async () => {- const { user } = createUser(testDb);- const { user: other } = createUser(testDb);+ const { user } = await makeUser(orm);+ const { user: other } = await makeUser(orm);const col = await seedCollection(user.id, 'Paris');const elsewhere = await seedCollection(other.id, 'Theirs');await seedPlace(col, user.id, 'Louvre', { status: 'visited' });@@ -1180,20 +1162,20 @@ describe('Collection tools — scope gating', () => {}it('registers all 29 tools with null scopes (full access)', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const names = await listToolNames(user.id, null);for (const tool of [...READ_TOOLS, ...WRITE_TOOLS]) expect(names).toContain(tool);});it('registers only the read tools with collections:read', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const names = await listToolNames(user.id, ['collections:read']);for (const tool of READ_TOOLS) expect(names).toContain(tool);for (const tool of WRITE_TOOLS) expect(names).not.toContain(tool);});it('registers no collection tools for an unrelated scope', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);const names = await listToolNames(user.id, ['budget:read']);for (const tool of [...READ_TOOLS, ...WRITE_TOOLS]) expect(names).not.toContain(tool);});@@ -1208,7 +1190,7 @@ describe('Collection tools — scope gating', () => {describe('Collection tools — collections addon gating', () => {it('registers nothing when the collections addon is disabled', async () => {- const { user } = createUser(testDb);+ const { user } = await makeUser(orm);await updateRows(orm, Addons, { id: ADDON_IDS.COLLECTIONS }, { enabled: false });try {await withHarness(user.id, async (h) => {