fix(booking-import): say why a recognised booking could not be imported

A document the model read correctly could still come back as "No reservations
could be extracted". Every type mapper can answer null when the node carries no
reservationFor, or one with no name, and both call sites pushed the item only
if there was one — with no else. The unknown-@type branch next to them does
warn, so a node TREK did not recognise was reported while a node it recognised
but could not map vanished: no item, no warning, nothing in the log. Because
the file did produce a node, the "no reservations found" fallback was skipped
too, and the preview arrived empty and silent. Every recognised type could
disappear this way, on both the kitinerary and the AI path.

Each of them now warns, naming the file, the index, the type and the reason.

Three smaller silences went with it. The debug line labelled "Raw LLM Response"
printed the already-parsed array, so its inspect formatting — single quotes,
bare keys — read as a provider emitting broken JSON and sent this report at the
JSON parser, which has handled that shape since 4.0.0. A single reservation
answered on its own, with no array and no wrapper, was dropped by the list
unwrapper although the schema downstream would have taken it. And a response
nobody could read returned an empty list, which is the same answer as a voucher
with no booking in it; it now raises, on the Anthropic client too, where a
reply cut off at the token limit produced exactly this report's symptom. The
plugin AI surface keeps its old empty answer, since a value is what a plugin
contracts for.

The retry ladder gained a rung that sends no response_format at all, for
providers that support neither json_schema nor json_object.

Closes #2375
This commit is contained in:
Maurice
2026-09-16 13:01:05 +02:00
parent 2a7ad1e241
commit 7ccc8dc03d
10 changed files with 352 additions and 26 deletions
@@ -107,3 +107,62 @@ describe('kitinerary mapper — printed 12-hour clocks (#2094)', () => {
expect(items).toHaveLength(2);
});
});
/**
* A recognised @type whose mapper cannot build an item used to leave nothing
* behind: no item, no warning, no log. With a single node in the file the
* service's own "no reservations found" never fired either, so a hotel voucher
* the model had read correctly but namelessly came back as an empty preview,
* indistinguishable from a document holding no booking at all (#2375).
*/
describe('kitinerary mapper — a recognised type that cannot be mapped (#2375)', () => {
it('warns instead of dropping a lodging whose reservationFor carries no name', () => {
const { items, warnings } = mapReservations([
{ '@type': 'LodgingReservation', reservationNumber: 'HMTRSX', reservationFor: {} },
] as any, 'airbnb.pdf');
expect(items).toHaveLength(0);
expect(warnings).toEqual([
'Incomplete LodgingReservation in airbnb.pdf[0] (no name in reservationFor) — skipped',
]);
});
it('warns for a flight that carries no reservationFor at all', () => {
const { items, warnings } = mapReservations([
{ '@type': 'FlightReservation', reservationNumber: 'ABC123' },
] as any, 'ticket.eml');
expect(items).toHaveLength(0);
expect(warnings).toEqual([
'Incomplete FlightReservation in ticket.eml[0] (no reservationFor) — skipped',
]);
});
it('names the type it could not map, TouristAttractionVisit included', () => {
const { warnings } = mapReservations([
{ '@type': 'TouristAttractionVisit', reservationFor: {} },
] as any, 'museum.pdf');
expect(warnings[0]).toBe('Incomplete TouristAttractionVisit in museum.pdf[0] (no name in reservationFor) — skipped');
});
it('keeps the bookings it could map and warns only about the weak one', () => {
const { items, warnings } = mapReservations([
flight('MIX1', FRA, BER, '2026-06-11T10:00:00', '2026-06-11T12:00:00', 'LH 800'),
{ '@type': 'LodgingReservation', reservationFor: {} },
] as any, 'trip.eml');
expect(items).toHaveLength(1);
expect(warnings).toHaveLength(1);
expect(warnings[0]).toContain('trip.eml[1]');
});
it('still warns exactly once for an unknown type', () => {
const { items, warnings } = mapReservations([
{ '@type': 'RocketLaunchReservation', reservationFor: { name: 'Starbase' } },
] as any, 'mars.eml');
expect(items).toHaveLength(0);
expect(warnings).toEqual(['Unknown type "RocketLaunchReservation" in mars.eml[0] — skipped']);
});
});