mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 23:27:31 +00:00
fix: five small defects the audit turned up in the release
An explicit null on a place's duration_minutes advertised a reset it never performed: the column sat behind COALESCE, so null and absent were the same thing and the day plan kept budgeting the old stay length. It clears now, and 0 still writes 0. update_trip_file and link_trip_file never learned the budget_item_id target the REST routes gained, so a receipt could not be attached to an expense from MCP. Added to both, along with the cross-trip check that goes with it: adding the field without it would have opened the hole the same change closed for REST. The roadtrip preferences PUT dropped the X-Socket-Id it was given, so the tab that saved a setting received its own change back and spent a second store commit and a route recompute on an answer it already had. Its two siblings on the same feature forward it. A shared journey did not carry the three "this journey does not use that field" switches, so the phone card read undefined, decided everything was switched on, and showed mood and weather chips on a journey whose owner had turned them off. An entry's country flag followed the pin when the entry was edited and not when the trip sync moved the place underneath it, so a stop dragged across a border kept the old flag with nothing to ever correct it. Also: dawarich.helpers.ts held a raw NUL byte as a hash separator, which made every search tool treat the file as binary and skip it. Same character, written as an escape.
This commit is contained in:
@@ -112,6 +112,7 @@ export class FilesMcp {
|
||||
description: fileUpdateRequestSchema.shape.description.describe('Free-text description, or an empty string to clear it'),
|
||||
place_id: fileUpdateRequestSchema.shape.place_id.describe('Place on the same trip to attach the file to, or null to detach it'),
|
||||
reservation_id: fileUpdateRequestSchema.shape.reservation_id.describe('Booking on the same trip to attach the file to, or null to detach it'),
|
||||
budget_item_id: fileUpdateRequestSchema.shape.budget_item_id.describe('Expense on the same trip to attach the file to (a receipt), or null to detach it'),
|
||||
},
|
||||
annotations: TOOL_ANNOTATIONS_WRITE,
|
||||
access: { group: 'files', mode: 'write' },
|
||||
@@ -131,6 +132,7 @@ export class FilesMcp {
|
||||
const foreign = this.files.findForeignLinkTarget(tripId, {
|
||||
reservation_id: fields.reservation_id,
|
||||
place_id: fields.place_id,
|
||||
budget_item_id: fields.budget_item_id,
|
||||
});
|
||||
if (foreign) return errorResult(`Linked item does not belong to this trip (${foreign}).`);
|
||||
// The rest spread carries only the keys the caller actually sent, which is what
|
||||
@@ -150,6 +152,7 @@ export class FilesMcp {
|
||||
reservation_id: fileLinkRequestSchema.shape.reservation_id.describe('Booking on the same trip'),
|
||||
assignment_id: fileLinkRequestSchema.shape.assignment_id.describe('Day assignment (a place scheduled on a specific day) on the same trip'),
|
||||
place_id: fileLinkRequestSchema.shape.place_id.describe('Place on the same trip'),
|
||||
budget_item_id: fileLinkRequestSchema.shape.budget_item_id.describe('Expense on the same trip, for a receipt'),
|
||||
},
|
||||
annotations: TOOL_ANNOTATIONS_WRITE,
|
||||
access: { group: 'files', mode: 'write' },
|
||||
@@ -165,8 +168,8 @@ export class FilesMcp {
|
||||
// The REST body allows all three to be absent and stores a link row pointing at
|
||||
// nothing. A tool caller that gets here with no target made a mistake, and saying
|
||||
// so is more useful than a success that attached the file to nothing.
|
||||
if (!targets.reservation_id && !targets.assignment_id && !targets.place_id) {
|
||||
return errorResult('Pass at least one of reservation_id, assignment_id or place_id.');
|
||||
if (!targets.reservation_id && !targets.assignment_id && !targets.place_id && !targets.budget_item_id) {
|
||||
return errorResult('Pass at least one of reservation_id, assignment_id, place_id or budget_item_id.');
|
||||
}
|
||||
const foreign = this.files.findForeignLinkTarget(tripId, targets);
|
||||
if (foreign) return errorResult(`Linked item does not belong to this trip (${foreign}).`);
|
||||
|
||||
Binary file not shown.
@@ -608,7 +608,7 @@ export class JourneyDomainService {
|
||||
// update everything on skeletons
|
||||
this.db.prepare(
|
||||
`
|
||||
UPDATE journey_entries SET title = ?, entry_date = ?, entry_time = ?, location_name = ?, location_lat = ?, location_lng = ?, updated_at = ?
|
||||
UPDATE journey_entries SET title = ?, entry_date = ?, entry_time = ?, location_name = ?, location_lat = ?, location_lng = ?, country_code = ?, updated_at = ?
|
||||
WHERE id = ?
|
||||
`,
|
||||
).run(
|
||||
@@ -618,6 +618,9 @@ export class JourneyDomainService {
|
||||
place.address || place.name,
|
||||
place.lat || null,
|
||||
place.lng || null,
|
||||
// The pin moved, so the flag has to follow it — the same rule updateEntry
|
||||
// states, and the one every sync write here used to skip.
|
||||
this.countryFor(place.lat ?? null, place.lng ?? null),
|
||||
now,
|
||||
entry.id,
|
||||
);
|
||||
@@ -625,10 +628,13 @@ export class JourneyDomainService {
|
||||
// for filled entries, only update location silently
|
||||
this.db.prepare(
|
||||
`
|
||||
UPDATE journey_entries SET location_name = ?, location_lat = ?, location_lng = ?, updated_at = ?
|
||||
UPDATE journey_entries SET location_name = ?, location_lat = ?, location_lng = ?, country_code = ?, updated_at = ?
|
||||
WHERE id = ?
|
||||
`,
|
||||
).run(place.address || place.name, place.lat || null, place.lng || null, now, entry.id);
|
||||
).run(
|
||||
place.address || place.name, place.lat || null, place.lng || null,
|
||||
this.countryFor(place.lat ?? null, place.lng ?? null), now, entry.id,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -815,8 +821,8 @@ export class JourneyDomainService {
|
||||
found.location_lng !== lng;
|
||||
if (stale) {
|
||||
this.db.prepare(
|
||||
`UPDATE journey_entries SET title = ?, entry_date = ?, entry_time = ?, location_name = ?, location_lat = ?, location_lng = ?, updated_at = ? WHERE id = ?`,
|
||||
).run(place.name, entryDate, entryTime, locationName, lat, lng, now, found.id);
|
||||
`UPDATE journey_entries SET title = ?, entry_date = ?, entry_time = ?, location_name = ?, location_lat = ?, location_lng = ?, country_code = ?, updated_at = ? WHERE id = ?`,
|
||||
).run(place.name, entryDate, entryTime, locationName, lat, lng, this.countryFor(lat, lng), now, found.id);
|
||||
changed = true;
|
||||
}
|
||||
} else {
|
||||
@@ -825,8 +831,8 @@ export class JourneyDomainService {
|
||||
found.location_name !== locationName || found.location_lat !== lat || found.location_lng !== lng;
|
||||
if (stale) {
|
||||
this.db.prepare(
|
||||
`UPDATE journey_entries SET location_name = ?, location_lat = ?, location_lng = ?, updated_at = ? WHERE id = ?`,
|
||||
).run(locationName, lat, lng, now, found.id);
|
||||
`UPDATE journey_entries SET location_name = ?, location_lat = ?, location_lng = ?, country_code = ?, updated_at = ? WHERE id = ?`,
|
||||
).run(locationName, lat, lng, this.countryFor(lat, lng), now, found.id);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,6 +256,13 @@ export class JourneyShareService {
|
||||
subtitle: journey.subtitle,
|
||||
cover_image: journey.cover_image,
|
||||
status: journey.status,
|
||||
// The three "this journey does not use that field" switches. A public
|
||||
// reader was getting mood and weather chips on a journey that had them
|
||||
// turned off, because the phone card reads these and they were not here
|
||||
// to read: undefined never equals 0, so both always looked switched on.
|
||||
show_verdict: journey.show_verdict ? 1 : 0,
|
||||
show_mood: journey.show_mood ? 1 : 0,
|
||||
show_weather: journey.show_weather ? 1 : 0,
|
||||
},
|
||||
entries: publicEntries,
|
||||
// A photo now carries the coordinates it was taken at, which is a location the
|
||||
|
||||
@@ -349,7 +349,7 @@ export class PlacesService {
|
||||
currency = COALESCE(?, currency),
|
||||
place_time = ?,
|
||||
end_time = ?,
|
||||
duration_minutes = COALESCE(?, duration_minutes),
|
||||
duration_minutes = ?,
|
||||
notes = ?,
|
||||
image_url = ?,
|
||||
google_place_id = ?,
|
||||
@@ -375,9 +375,11 @@ export class PlacesService {
|
||||
currency || null,
|
||||
place_time !== undefined ? place_time : existingPlace.place_time,
|
||||
end_time !== undefined ? end_time : existingPlace.end_time,
|
||||
// `?? null` rather than `|| null`: with COALESCE(?, duration_minutes) a
|
||||
// falsy-coerced 0 read as "absent" and silently kept the old duration.
|
||||
duration_minutes ?? null,
|
||||
// Not COALESCE, like its neighbours: the contract says an explicit null
|
||||
// clears the planned stay length, and COALESCE made null and absent the
|
||||
// same thing, so the field advertised a reset it never performed. 0 keeps
|
||||
// working, which a `|| null` bind would have swallowed.
|
||||
duration_minutes !== undefined ? duration_minutes : existingPlace.duration_minutes,
|
||||
notes !== undefined ? notes : existingPlace.notes,
|
||||
image_url !== undefined ? image_url : existingPlace.image_url,
|
||||
google_place_id !== undefined ? google_place_id : existingPlace.google_place_id,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { RequireAddon } from '../addons/require-addon.decorator';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { RequirePermission, TripAccessGuard } from '../permissions/trip-access.guard';
|
||||
import { RoadtripPreferencesService } from './roadtrip-preferences.service';
|
||||
import { Body, Controller, Get, Param, Put, UseGuards } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Headers, Param, Put, UseGuards } from '@nestjs/common';
|
||||
import { roadtripPreferencesUpdateSchema } from '@trek/shared';
|
||||
|
||||
import { createZodDto } from 'nestjs-zod';
|
||||
@@ -24,7 +24,7 @@ export class RoadtripPreferencesController {
|
||||
|
||||
@Put()
|
||||
@RequirePermission('day_edit')
|
||||
update(@Param('tripId') tripId: string, @Body() patch: PreferencesDto) {
|
||||
return { tripId: Number(tripId), preferences: this.preferences.update(Number(tripId), patch) };
|
||||
update(@Param('tripId') tripId: string, @Body() patch: PreferencesDto, @Headers('x-socket-id') socketId?: string) {
|
||||
return { tripId: Number(tripId), preferences: this.preferences.update(Number(tripId), patch, socketId) };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ export class RoadtripPreferencesService {
|
||||
return roadtripPreferencesSchema.parse(preferences);
|
||||
}
|
||||
|
||||
update(tripId: number, patch: RoadtripPreferences): RoadtripPreferences {
|
||||
update(tripId: number, patch: RoadtripPreferences, socketId?: string): RoadtripPreferences {
|
||||
const validated = roadtripPreferencesUpdateSchema.parse(patch);
|
||||
const saved = this.db.transaction(() => {
|
||||
const next = { ...this.read(tripId), ...validated };
|
||||
@@ -52,7 +52,11 @@ export class RoadtripPreferencesService {
|
||||
}
|
||||
return this.read(tripId);
|
||||
});
|
||||
this.realtime.broadcast(String(tripId), 'roadtripPreferences:changed', { preferences: saved });
|
||||
// The saving tab is left out, like every other trip mutation: it already has
|
||||
// the answer, and its own echo costs it a second store commit and the route
|
||||
// recompute that follows. The MCP tool passes none, which is right — nobody
|
||||
// there is holding the result already.
|
||||
this.realtime.broadcast(String(tripId), 'roadtripPreferences:changed', { preferences: saved }, socketId);
|
||||
return saved;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2471,6 +2471,52 @@ describe('country_code', () => {
|
||||
expect(cleared.country_code).toBeNull();
|
||||
});
|
||||
|
||||
it('JOURNEY-SVC-114: a place that moves across a border moves its skeleton entry country too', () => {
|
||||
// The pin can also move without anybody editing the entry: the place it came
|
||||
// from is dragged, and the trip sync writes the new coordinates onto the
|
||||
// skeleton. The flag has to follow that write like it follows a manual one.
|
||||
const { user } = createUser(testDb);
|
||||
const journey = createJourney(testDb, user.id);
|
||||
const trip = createTrip(testDb, user.id, { title: 'Border', start_date: '2026-08-01', end_date: '2026-08-03' });
|
||||
const place = createPlace(testDb, trip.id, { name: 'Grenzstein', lat: 48.8584, lng: 2.2945 });
|
||||
const day = testDb.prepare('SELECT id FROM days WHERE trip_id = ? ORDER BY date ASC LIMIT 1').get(trip.id) as { id: number };
|
||||
createDayAssignment(testDb, day.id, place.id);
|
||||
svc.addTripToJourney(journey.id, trip.id, user.id);
|
||||
|
||||
const before = testDb.prepare(
|
||||
"SELECT country_code FROM journey_entries WHERE journey_id = ? AND source_place_id = ? AND type = 'skeleton'"
|
||||
).get(journey.id, place.id) as { country_code: string | null };
|
||||
expect(before.country_code).toBe('FR');
|
||||
|
||||
testDb.prepare('UPDATE places SET lat = ?, lng = ? WHERE id = ?').run(52.52, 13.405, place.id);
|
||||
svc.onPlaceUpdated(place.id);
|
||||
|
||||
const after = testDb.prepare(
|
||||
"SELECT country_code FROM journey_entries WHERE journey_id = ? AND source_place_id = ? AND type = 'skeleton'"
|
||||
).get(journey.id, place.id) as { country_code: string | null };
|
||||
expect(after.country_code).toBe('DE');
|
||||
});
|
||||
|
||||
it('JOURNEY-SVC-115: and so does a filled entry, whose location follows the place silently', () => {
|
||||
const { user } = createUser(testDb);
|
||||
const journey = createJourney(testDb, user.id);
|
||||
const trip = createTrip(testDb, user.id, { title: 'Border 2', start_date: '2026-08-01', end_date: '2026-08-03' });
|
||||
const place = createPlace(testDb, trip.id, { name: 'Grenzstein', lat: 48.8584, lng: 2.2945 });
|
||||
const day = testDb.prepare('SELECT id FROM days WHERE trip_id = ? ORDER BY date ASC LIMIT 1').get(trip.id) as { id: number };
|
||||
createDayAssignment(testDb, day.id, place.id);
|
||||
svc.addTripToJourney(journey.id, trip.id, user.id);
|
||||
// Writing a story turns the skeleton into a filled entry.
|
||||
testDb.prepare("UPDATE journey_entries SET type = 'entry' WHERE source_place_id = ?").run(place.id);
|
||||
|
||||
testDb.prepare('UPDATE places SET lat = ?, lng = ? WHERE id = ?').run(52.52, 13.405, place.id);
|
||||
svc.onPlaceUpdated(place.id);
|
||||
|
||||
const after = testDb.prepare(
|
||||
'SELECT country_code, location_lat FROM journey_entries WHERE source_place_id = ?'
|
||||
).get(place.id) as { country_code: string | null; location_lat: number };
|
||||
expect(after).toMatchObject({ country_code: 'DE', location_lat: 52.52 });
|
||||
});
|
||||
|
||||
it('JOURNEY-SVC-113: an edit that does not touch the pin leaves the country alone', () => {
|
||||
const { user } = createUser(testDb);
|
||||
const journey = createJourney(testDb, user.id);
|
||||
|
||||
@@ -447,6 +447,10 @@ describe('getPublicJourney', () => {
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.journey.title).toBe('Japan 2026');
|
||||
expect(result!.journey.subtitle).toBe('Cherry blossom season');
|
||||
// The "this journey does not use that field" switches travel with the share:
|
||||
// the phone card reads them, and reading an absent one made every field look
|
||||
// switched on, so a reader saw chips the owner had turned off.
|
||||
expect(result!.journey).toMatchObject({ show_verdict: 1, show_mood: 1, show_weather: 1 });
|
||||
expect(result!.entries).toHaveLength(2);
|
||||
expect(result!.stats.entries).toBe(2);
|
||||
expect(result!.stats.photos).toBe(1);
|
||||
@@ -456,6 +460,20 @@ describe('getPublicJourney', () => {
|
||||
expect(result!.permissions.share_map).toBe(false);
|
||||
});
|
||||
|
||||
it('JOURNEY-SHARE-017b: a field the owner switched off is switched off for the reader too', () => {
|
||||
const { user } = createUser(testDb);
|
||||
const journey = createJourney(testDb, user.id);
|
||||
testDb.prepare('UPDATE journeys SET show_mood = 0, show_weather = 0 WHERE id = ?').run(journey.id);
|
||||
createJourneyEntry(testDb, journey.id, user.id, { type: 'entry', title: 'Tag 1', entry_date: '2026-03-20' });
|
||||
const { token } = svc.createOrUpdateJourneyShareLink(journey.id, user.id, {
|
||||
share_timeline: true, share_gallery: false, share_map: true,
|
||||
});
|
||||
|
||||
const result = svc.getPublicJourney(token)!;
|
||||
|
||||
expect(result.journey).toMatchObject({ show_mood: 0, show_weather: 0, show_verdict: 1 });
|
||||
});
|
||||
|
||||
it('JOURNEY-SHARE-018: excludes skeleton entries from public view', () => {
|
||||
const { user } = createUser(testDb);
|
||||
const journey = createJourney(testDb, user.id);
|
||||
|
||||
@@ -1418,10 +1418,23 @@ describe('zero-valued numeric fields', () => {
|
||||
const zeroed = await svc.update(String(trip.id), String(place.id), { duration_minutes: 0 }) as any;
|
||||
expect(zeroed.duration_minutes).toBe(0);
|
||||
|
||||
// An omitted duration still leaves the stored value alone (COALESCE).
|
||||
// An omitted duration still leaves the stored value alone.
|
||||
const untouched = await svc.update(String(trip.id), String(place.id), { name: 'Stop 2' }) as any;
|
||||
expect(untouched.duration_minutes).toBe(0);
|
||||
});
|
||||
|
||||
it('PLACE-SVC-067b — an explicit null clears the planned stay length', async () => {
|
||||
// What the write contract and the MCP tool both advertise. Behind COALESCE,
|
||||
// null and absent were the same thing, so the field promised a reset it never
|
||||
// performed and the day plan kept budgeting the old ninety minutes.
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
const place = createPlace(testDb, trip.id, { name: 'Stop' }) as any;
|
||||
testDb.prepare('UPDATE places SET duration_minutes = 90 WHERE id = ?').run(place.id);
|
||||
|
||||
const cleared = await svc.update(String(trip.id), String(place.id), { duration_minutes: null }) as any;
|
||||
expect(cleared.duration_minutes).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
// ── LIKE metacharacter escaping (#1745) ───────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user