mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 18:34:09 +00:00
Align trip tags and desktop UI with CI contracts
This commit is contained in:
@@ -54,7 +54,6 @@ export class Trips {
|
||||
user_id!: number;
|
||||
title!: string;
|
||||
description?: string | null;
|
||||
tags_json?: string | null;
|
||||
start_date?: string | null;
|
||||
end_date?: string | null;
|
||||
currency?: string | null = 'EUR';
|
||||
@@ -66,6 +65,7 @@ export class Trips {
|
||||
updated_at?: string | null;
|
||||
reminder_sent_for?: string | null;
|
||||
costs_mode: TTripsCostsMode & Opt = TripsCostsMode.SPLIT;
|
||||
tags_json?: string | null;
|
||||
assistant_attachments_collection = new Collection<AssistantAttachments>(this);
|
||||
assistant_threads_collection = new Collection<AssistantThreads>(this);
|
||||
budget_category_order_collection = new Collection<BudgetCategoryOrder>(this);
|
||||
@@ -136,7 +136,6 @@ export const TripsSchema = defineEntity({
|
||||
user_id: p.integer().persist(false).index('idx_trips_user_id'),
|
||||
title: p.text(),
|
||||
description: p.text().nullable(),
|
||||
tags_json: p.text().nullable(),
|
||||
start_date: p.text().nullable(),
|
||||
end_date: p.text().nullable(),
|
||||
currency: p.text().nullable(),
|
||||
@@ -148,6 +147,7 @@ export const TripsSchema = defineEntity({
|
||||
updated_at: p.type(DbTimestampType).nullable().defaultRaw(`CURRENT_TIMESTAMP`),
|
||||
reminder_sent_for: p.text().nullable(),
|
||||
costs_mode: p.enum(() => TripsCostsMode).default('split'),
|
||||
tags_json: p.text().nullable(),
|
||||
assistant_attachments_collection: () => p.oneToMany(AssistantAttachments).mappedBy('trip').hidden(),
|
||||
assistant_threads_collection: () => p.oneToMany(AssistantThreads).mappedBy('trip').hidden(),
|
||||
budget_category_order_collection: () => p.oneToMany(BudgetCategoryOrder).mappedBy('trip').hidden(),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
import { engineDdl } from '../migration-utils';
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
export class Migration20200101046650_trips_can_carry_custom_tags extends Migration {
|
||||
override name = 'Migration20200101046650_trips_can_carry_custom_tags';
|
||||
|
||||
@@ -67,10 +67,10 @@ export const PLUGIN_ENTITY_CONTRACT = {
|
||||
'reminder_sent_for',
|
||||
'costs_mode',
|
||||
],
|
||||
// The sole credential of the anonymous calendar feed.
|
||||
withheld: ['feed_token'],
|
||||
// Keep the calendar credential and internal tag serialization out of the plugin API.
|
||||
withheld: ['feed_token', 'tags_json'],
|
||||
wholeRow: true,
|
||||
derived: ['day_count', 'place_count', 'is_owner', 'owner_username', 'shared_count'],
|
||||
derived: ['day_count', 'place_count', 'is_owner', 'owner_username', 'shared_count', 'tags'],
|
||||
},
|
||||
place: {
|
||||
table: 'places',
|
||||
|
||||
@@ -35,7 +35,16 @@ export function withoutFeedToken<T>(row: T): T {
|
||||
}
|
||||
|
||||
/** The fields of a trip update that count as an edit, as against archiving it or changing its cover. */
|
||||
const TRIP_EDIT_FIELDS = ['title', 'description', 'tags', 'start_date', 'end_date', 'currency', 'reminder_days', 'day_count'];
|
||||
const TRIP_EDIT_FIELDS = [
|
||||
'title',
|
||||
'description',
|
||||
'tags',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'currency',
|
||||
'reminder_days',
|
||||
'day_count',
|
||||
];
|
||||
|
||||
/**
|
||||
* The permissions a trip update needs, in the order PUT /api/trips/:id checks
|
||||
|
||||
@@ -262,9 +262,21 @@ export class TripsMcp {
|
||||
costs_mode: tripUpdateRequestSchema.shape.costs_mode.describe(
|
||||
'How the trip keeps its costs: split (who paid and who shares each expense, with settling up) or totals (what the trip costs, nothing split). Who paid and the shares stay stored either way. Needs the budget_edit permission rather than trip_edit',
|
||||
),
|
||||
tags: tripTagNamesSchema.optional().describe('Replace all custom tags on the trip. Send an empty array to clear them. Cannot be combined with add_tags or remove_tags'),
|
||||
add_tags: tripTagNamesSchema.optional().describe('Assign existing or new custom tags to the trip, keeping its other tags. Tag names are matched case-insensitively'),
|
||||
remove_tags: tripTagNamesSchema.optional().describe('Remove these custom tags from this trip only. Other tags stay assigned. Removals apply before additions'),
|
||||
tags: tripTagNamesSchema
|
||||
.optional()
|
||||
.describe(
|
||||
'Replace all custom tags on the trip. Send an empty array to clear them. Cannot be combined with add_tags or remove_tags',
|
||||
),
|
||||
add_tags: tripTagNamesSchema
|
||||
.optional()
|
||||
.describe(
|
||||
'Assign existing or new custom tags to the trip, keeping its other tags. Tag names are matched case-insensitively',
|
||||
),
|
||||
remove_tags: tripTagNamesSchema
|
||||
.optional()
|
||||
.describe(
|
||||
'Remove these custom tags from this trip only. Other tags stay assigned. Removals apply before additions',
|
||||
),
|
||||
},
|
||||
annotations: TOOL_ANNOTATIONS_WRITE,
|
||||
access: { group: 'trips', mode: 'write' },
|
||||
@@ -329,7 +341,9 @@ export class TripsMcp {
|
||||
};
|
||||
// The rights PUT /api/trips/:id asks for, field by field: archiving, the cover and the costs mode have their own.
|
||||
const granted = await Promise.all(
|
||||
tripUpdatePermissions({ ...fields, tags: tags ?? add_tags ?? remove_tags }).map(({ action }) => this.guards.hasTripPermission(action, tripId, ctx.userId)),
|
||||
tripUpdatePermissions({ ...fields, tags: tags ?? add_tags ?? remove_tags }).map(({ action }) =>
|
||||
this.guards.hasTripPermission(action, tripId, ctx.userId),
|
||||
),
|
||||
);
|
||||
if (granted.includes(false)) return permissionDenied();
|
||||
if (tags !== undefined && (add_tags !== undefined || remove_tags !== undefined))
|
||||
@@ -425,7 +439,9 @@ export class TripsMcp {
|
||||
const notice = ctx.getDeprecationNotice ? ctx.getDeprecationNotice() : null;
|
||||
const accessible = await this.trips.list(ctx.userId, include_archived ? null : 0);
|
||||
const tagKey = tag ? tripTagKey(tag) : null;
|
||||
const trips = tagKey ? accessible.filter(trip => trip.tags?.some(name => tripTagKey(name) === tagKey)) : accessible;
|
||||
const trips = tagKey
|
||||
? accessible.filter((trip) => trip.tags?.some((name) => tripTagKey(name) === tagKey))
|
||||
: accessible;
|
||||
if (notice)
|
||||
return {
|
||||
isError: true as const,
|
||||
|
||||
@@ -130,6 +130,7 @@ const UNNUMBERED = [
|
||||
'Migration20200101046620_a_journey_link_can_ask_for_a_password_and_run_out',
|
||||
'Migration20200101046630_a_journey_gathers_comments_and_followers',
|
||||
'Migration20200101046640_bahrain_flights_keep_bahrain_time',
|
||||
'Migration20200101046650_trips_can_carry_custom_tags',
|
||||
];
|
||||
// The last step the positional runner ever had; planLegacyBaseline refuses a
|
||||
// schema_version past it.
|
||||
|
||||
@@ -98,7 +98,9 @@ describe('ReservationsRepository — CL1 (findRaw, existing method reused by cal
|
||||
// test-sql-allow: the legacy statement is the oracle the repository read is held to.
|
||||
const legacy = testDb.prepare('SELECT * FROM trips WHERE id = ?').get(trip.id);
|
||||
|
||||
expect(typed).toEqual(legacy);
|
||||
const { tags_json, ...tripFields } = legacy as Record<string, unknown>;
|
||||
expect(tags_json).toBeNull();
|
||||
expect(typed).toEqual({ ...tripFields, tags: [] });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -13,6 +13,10 @@ import type { EntityData } from '@mikro-orm/core';
|
||||
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
||||
|
||||
function expectedTrip({ tags_json, ...fields }: Record<string, unknown>) {
|
||||
return { ...fields, tags: typeof tags_json === 'string' ? JSON.parse(tags_json) : [] };
|
||||
}
|
||||
|
||||
const testDb = createSnapshotTestDb();
|
||||
let t: TestOrm;
|
||||
let trips: TripsRepository;
|
||||
@@ -238,7 +242,7 @@ describe('TripsRepository — TripMembersService / TripReadModelService (Plan 3c
|
||||
// test-sql-allow: the legacy statement is the oracle the repository read is held to.
|
||||
const legacyRow = testDb.prepare('SELECT * FROM trips WHERE id = ?').get(trip.id);
|
||||
const row = await trips.findRaw(trip.id);
|
||||
expect(row).toEqual(legacyRow);
|
||||
expect(row).toEqual(expectedTrip(legacyRow as Record<string, unknown>));
|
||||
expect(row?.feed_token).toBe('secret-token');
|
||||
});
|
||||
|
||||
@@ -329,7 +333,7 @@ describe('TripsRepository.findForViewer / listForUser / activeTrip (Plan 3c Task
|
||||
)
|
||||
.get({ userId: owner.id, tripId: trip.id });
|
||||
const row = await trips.findForViewer(trip.id, owner.id);
|
||||
expect(row).toEqual(legacyOwner);
|
||||
expect(row).toEqual(expectedTrip(legacyOwner as Record<string, unknown>));
|
||||
// createTrip's own start_date/end_date span already generates 5 days;
|
||||
// the two explicit createDay calls above add 2 more, for 7 total.
|
||||
expect(row).toMatchObject({
|
||||
@@ -356,7 +360,7 @@ describe('TripsRepository.findForViewer / listForUser / activeTrip (Plan 3c Task
|
||||
)
|
||||
.get({ userId: member.id, tripId: trip.id });
|
||||
const memberRow = await trips.findForViewer(trip.id, member.id);
|
||||
expect(memberRow).toEqual(legacyMember);
|
||||
expect(memberRow).toEqual(expectedTrip(legacyMember as Record<string, unknown>));
|
||||
expect(memberRow).toMatchObject({ is_owner: 0, day_count: 7, place_count: 3, shared_count: 1 });
|
||||
});
|
||||
|
||||
@@ -376,7 +380,7 @@ describe('TripsRepository.findForViewer / listForUser / activeTrip (Plan 3c Task
|
||||
)
|
||||
.get({ userId: owner.id, tripId: trip.id });
|
||||
const row = await trips.findForViewer(trip.id, owner.id);
|
||||
expect(row).toEqual(legacy);
|
||||
expect(row).toEqual(expectedTrip(legacy as Record<string, unknown>));
|
||||
expect(row).toMatchObject({
|
||||
description: null,
|
||||
start_date: null,
|
||||
@@ -429,7 +433,7 @@ describe('TripsRepository.findForViewer / listForUser / activeTrip (Plan 3c Task
|
||||
)
|
||||
.all({ userId: owner.id });
|
||||
const rows = await trips.listForUser(owner.id, null);
|
||||
expect(rows).toEqual(legacy);
|
||||
expect(rows).toEqual(legacy.map(row => expectedTrip(row as Record<string, unknown>)));
|
||||
expect(rows.map((r) => r.id).sort()).toEqual([owned.id, shared.id, archived.id].sort());
|
||||
});
|
||||
|
||||
@@ -450,7 +454,7 @@ describe('TripsRepository.findForViewer / listForUser / activeTrip (Plan 3c Task
|
||||
`,
|
||||
)
|
||||
.all({ userId: owner.id, archived: 1 });
|
||||
expect(await trips.listForUser(owner.id, 1)).toEqual(legacyArchived);
|
||||
expect(await trips.listForUser(owner.id, 1)).toEqual(legacyArchived.map(row => expectedTrip(row as Record<string, unknown>)));
|
||||
expect((await trips.listForUser(owner.id, 1)).map((r) => r.id)).toEqual([archived.id]);
|
||||
expect((await trips.listForUser(owner.id, 0)).map((r) => r.id)).toEqual([active.id]);
|
||||
});
|
||||
@@ -1082,7 +1086,7 @@ describe('TripsRepository.listOwnedOrMember — AT1 parity with the legacy state
|
||||
const legacy = testDb.prepare(LEGACY_OWNED_OR_MEMBER).all(caller.id, caller.id, caller.id);
|
||||
const rows = await trips.listOwnedOrMember(caller.id);
|
||||
|
||||
expect(rows).toEqual(legacy);
|
||||
expect(rows).toEqual(legacy.map(row => expectedTrip(row as Record<string, unknown>)));
|
||||
expect(rows.map((r) => r.id)).toEqual([memberOf.id, owned.id]);
|
||||
});
|
||||
|
||||
|
||||
@@ -308,9 +308,13 @@ describe('Tool: update_trip', () => {
|
||||
arguments: { tripId: trip.id, remove_tags: ['work'], add_tags: [' FAMILY ', 'City break'] },
|
||||
});
|
||||
expect(parseToolResult(result)).toMatchObject({ trip: { title: 'Weekend', tags: ['Family', 'City break'] } });
|
||||
expect(broadcastMock).toHaveBeenCalledWith(trip.id, 'trip:updated', expect.objectContaining({
|
||||
trip: expect.objectContaining({ tags: ['Family', 'City break'] }),
|
||||
}));
|
||||
expect(broadcastMock).toHaveBeenCalledWith(
|
||||
trip.id,
|
||||
'trip:updated',
|
||||
expect.objectContaining({
|
||||
trip: expect.objectContaining({ tags: ['Family', 'City break'] }),
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user