fix(booking-import): stop writing an unreadable type down as a hotel (#2076)

When neither the keyword table nor the model produced a type, the router wrote
"hotel" and cast whatever string it got to FlatType without checking it. A hotel
is a booking type, so a ferry voucher imported from the Transport tab opened the
booking form, which offers six chips and not one transport among them, and
"other" was the only honest pick left. An unrecognised string got through the
cast too and then vanished silently in nuExtractToKiReservations.

The type is validated against FLAT_TYPES now. When it cannot be read the item is
still extracted with the lodging shape so it survives mapping, but it says so,
and the tie-breaker #2080 added finally has something to fire on: isUnplaceableItem
only ever matched a type outside both form's vocabularies, and the server can
only emit its own eight, so on a real document it never matched at all.

The tab travels with the job instead of sitting in component state. The parse
deliberately outlives navigation and reload and the review is triggered by the
global widget on any page, so by the time it ran the state had remounted back to
its default and the context was gone.
This commit is contained in:
Maurice
2026-08-28 13:23:23 +02:00
committed by Maurice
parent 016fdeec64
commit 130272cfb0
12 changed files with 175 additions and 28 deletions
@@ -114,7 +114,10 @@ describe('routeExtraction', () => {
expect(res.kiItems).toEqual([{ '@type': 'Mock' }]);
const flats = mapToKi.mock.calls[0][0];
expect(flats).toHaveLength(2);
expect(flats[0].departure_time).toMatch(/^2025-08-23T\d{2}:\d{2}:00$/); // natural-language → ISO
// Exact now, not a pattern: toIso reads and prints local components, so a naive
// string is the same wall clock on every machine. It used to parse locally and
// print in UTC, which shifted the value by the container's offset (#2094).
expect(flats[0].departure_time).toBe('2025-08-23T10:00:00');
expect(flats[1].arrival_time).toBe('2025-08-31T07:00:00'); // overnight roll (TZ-safe: derived from the ISO departure date)
});
@@ -214,3 +217,43 @@ describe('routeExtraction', () => {
});
});
describe('printed 12-hour clocks and unreadable types (#2094, #2076)', () => {
it('fixArrivalDate resolves both meridiems before deciding the day rolled over', () => {
// '01:11 pm' used to be read as '01:11', which sorts before the 09:51
// departure, so a three-hour hop was rolled onto the next day.
const out = fixArrivalDate({ type: 'flight', departure_time: '2026-06-11T09:51 am', arrival_time: '2026-06-11T01:11 pm' });
expect(out.arrival_time).toBe('2026-06-11T13:11:00');
});
it('fixArrivalDate still rolls a genuine overnight', () => {
const out = fixArrivalDate({ type: 'flight', departure_time: '2026-06-11T10:00 pm', arrival_time: '2026-06-12T06:00 am' });
expect(out.arrival_time).toBe('2026-06-12T06:00:00');
});
it('resolves a meridiem that sits behind an ISO date', async () => {
extractEnforced.mockResolvedValue({ name: 'B&B Hotel', address: 'Str 1', checkin_time: '2026-05-01T03:00 pm', checkout_time: '2026-05-02T11:00 am' });
await routeExtraction('Hotel booking — check-in 1 May', CTX);
const flats = mapToKi.mock.calls[0][0];
expect(flats[0].checkin_time).toBe('2026-05-01T15:00:00');
expect(flats[0].checkout_time).toBe('2026-05-02T11:00:00');
});
it('marks a type it could not read instead of writing it down as a hotel', async () => {
extractEnforced.mockResolvedValue({ type: 'shuttle voucher', name: 'Airport Transfer' });
await routeExtraction('A document with no obvious type keywords', CTX);
const flats = mapToKi.mock.calls[0][0];
// Still the hotel shape, so the item survives mapping, but the guess is
// declared so the importer can offer the form the user was importing into.
expect(flats[0].type).toBe('hotel');
expect(flats[0].type_guessed).toBe(true);
});
it('does not mark a type the model picked legitimately', async () => {
extractEnforced.mockResolvedValue({ type: 'event', name: 'Concert' });
await routeExtraction('A document with no obvious type keywords', CTX);
const flats = mapToKi.mock.calls[0][0];
expect(flats[0].type).toBe('event');
expect(flats[0].type_guessed).toBeUndefined();
});
});