Skip to content

fix(search): encode cabin class in tfs booking deep-links - #231

Open
Fanfulla wants to merge 1 commit into
punitarani:mainfrom
Fanfulla:fix/tfs-booking-url-cabin-class
Open

fix(search): encode cabin class in tfs booking deep-links#231
Fanfulla wants to merge 1 commit into
punitarani:mainfrom
Fanfulla:fix/tfs-booking-url-cabin-class

Conversation

@Fanfulla

@Fanfulla Fanfulla commented Aug 31, 2026

Copy link
Copy Markdown

Problem

build_tfs_token always writes protobuf field 9 as 1 (economy). Booking URLs built after a premium/business/first search therefore open the economy booking page.

Reproduced on current main by decoding a generated tfs token: the wire bytes contain 0x40 0x01 0x48 0x01 0x70 0x01 (f8=1, f9=1, f14=1) regardless of the cabin used for the search. The same hardcode exists in the JS port.

Fixes #213.

Cause

Field 9 is the seat-class slot (1 economy, 2 premium, 3 business, 4 first), matching SeatType. The encoder never took a cabin argument, and neither the CLI nor the MCP server passed the search's seat_type into build_flight_booking_url.

Change

  • build_tfs_token(..., seat=1) writes field 9 from seat. Default remains economy so captured golden tokens stay byte-equal.
  • SearchFlights.build_flight_booking_url(..., seat_type=SeatType.ECONOMY) forwards seat_type.value.
  • CLI flights and MCP search_flights / get_booking_options pass the search cabin through.
  • Same change in the JS port (buildTfsToken({ seat }), buildFlightBookingUrl({ seatType })).

Passenger count is still hardcoded (field 8). That is a nested message and is out of scope here, as noted in #213.

Tests

Executed locally:

  • uv run pytest -vv tests/search/test_proto.py tests/search/test_booking_url.py tests/cli/test_flights.py — 74 passed
  • uv run pytest -q tests/search/test_proto.py::TestBuildTfsToken::test_seat_business_encodes_field_9 tests/search/test_booking_url.py::TestBuildFlightBookingUrl::test_seat_type_business_changes_tfs_field_9 tests/cli/test_flights.py::test_flights_with_cabin_class — 3 passed
  • Sabotage: hardcoding field 9 back to 1 made the two new encoder tests fail; restoring the fix made them pass
  • uv run ruff check / ruff format --check on the touched Python files — clean
  • bun test tests/search/proto.test.ts tests/search/flights_booking_url.test.ts — 55 passed
  • bun run typecheck — clean

Golden tfs fixtures (economy captures) remain byte-perfect.

Greptile Summary

This PR propagates the selected cabin class into deterministic Google Flights booking deep links while preserving economy as the backward-compatible default.

  • Adds cabin-class encoding to Python and TypeScript tfs token builders.
  • Forwards the search cabin through the Python API, CLI, and MCP booking-link paths.
  • Adds Python and TypeScript coverage for default economy and explicit business-class tokens.

Confidence Score: 5/5

The PR appears safe to merge, with cabin values consistently propagated through the affected booking-link paths.

The supported cabin enums map to the expected numeric values, all repository booking-link adapters forward the search cabin, defaults preserve existing economy tokens, and no changed-code failure remains.

Important Files Changed

Filename Overview
fli/search/_proto.py Adds an optional seat value to Python token construction and writes it to protobuf field 9 while retaining the economy default.
fli/search/flights.py Extends the Python booking-link API with a typed cabin argument and forwards its enum value to the token builder.
fli/cli/commands/flights.py Passes the cabin used for the CLI search into each per-flight booking link.
fli/mcp/server.py Preserves cabin intent in booking links returned by flight-search and booking-option MCP flows.
fli-js/src/search/proto.ts Adds matching cabin-field encoding to the TypeScript token builder with a backward-compatible economy default.
fli-js/src/search/flights.ts Adds a typed booking-link cabin option and forwards it into the TypeScript token.
tests/search/test_proto.py Verifies Python field-9 encoding for the default and business cabins.
tests/search/test_booking_url.py Verifies the Python booking-link API changes its token for business class.
tests/cli/test_flights.py Covers cabin propagation from the CLI search into booking-link generation.
fli-js/tests/search/proto.test.ts Verifies TypeScript field-9 encoding and backward-compatible economy output.
fli-js/tests/search/flights_booking_url.test.ts Verifies the TypeScript booking-link API forwards business class correctly.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[CLI, MCP, or SDK caller] --> B[Typed cabin selection]
  B --> C[Booking URL builder]
  C --> D[Pass SeatType numeric value]
  D --> E[tfs protobuf encoder]
  E --> F[Field 9: cabin class]
  F --> G[Google Flights booking deep link]
Loading

Reviews (1): Last reviewed commit: "fix(search): encode cabin class in tfs b..." | Re-trigger Greptile

Context used (4)

build_tfs_token hardcoded protobuf field 9 to economy (1), so
booking URLs from a business/first search opened the economy
page. Pass SeatType through the encoder, CLI, MCP, and JS port.
Default remains economy so captured golden tokens stay byte-equal.

Closes punitarani#213
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build_flight_booking_url hardcodes economy — booking links open in the wrong cabin

1 participant