Skip to content

fix(cli): refuse to share an unresolved code, send a numeric city code as cityCode (PET-508) - #115

Open
ahsan-amin-wego wants to merge 7 commits into
mainfrom
fix/PET-508-unknown-place-code
Open

ahsan-amin-wego wants to merge 7 commits into
mainfrom
fix/PET-508-unknown-place-code

Conversation

@ahsan-amin-wego

@ahsan-amin-wego ahsan-amin-wego commented Nov 25, 2026 •

Copy link
Copy Markdown

PET-508 · Share half of PET-508, and the CLI half of Makkah 8283. The search errors and the numeric Places lookup are in wego/wego-ai#2132.

Summary

flights share and hotels share built a durable link from the raw codes, so an unknown code such as ZZZ exited 0 with a dead URL. Each code is now looked up through GET /v1/places first. A code with no exact match exits 6 (EXIT.PERMANENT, the class of validation_failed) and builds no link.

unresolvedShareCodes(fetchPlaces, codes, types)   // exact code match, case-insensitive
  flights share: from, to   types = [city, airport], or [city] with --from-city / --to-city
  hotels share:  city       types = [city]
  any unresolved -> stderr "No link was built: ...", exit 6, getFlightSearchLink / getHotelSearchLink never called

Numeric hotel search. hotels search 8283 sent hotelId: 8283. Makkah has no airport, so 8283 is its city code. An all-digit location is now looked up with getPlaces (types=city). If the top place is the city with exactly that code, the CLI sends cityCode. Otherwise it sends hotelId. A failed lookup other than a 401 keeps the hotelId.

hotels search <digits>
  getPlaces(query=<digits>, types=city)
    results[0] is a city and (code ?? cityCode) == <digits>  -> { cityCode: "<digits>" }
    anything else, or the lookup fails                       -> { hotelId: <digits> }

A valid share makes one or two extra getPlaces reads. The shape checks in the parsers (usage errors, exit 2) are unchanged.

Verification

Local API (apps/api, bun src/dev.ts, local JWKS) with the CLI pointed at it by WEGO_API_URL. main = CLI main (1.5.1) + API main. PR = CLI 05097ed8 + API wego/wego-ai#2132 at 3e16e40b. Upstreams are production: SRV_WEGO_BASE_URL=https://srv.wego.com, HOTELS_METASEARCH_BASE_URL=https://www.wego.com/kong/v3/metasearch/hotels, flights https://api.wego.com. GENZO_API_URL, POSTHOG_API_KEY and POSTHOG_KEY are unset, so no analytics left the machine. Dates are 2027-01-20/22.

Command main PR
hotels search 8283 with the PR CLI returns a Makkah searchId and results exit 4, sent as hotelId, 404 Unknown hotel or city. exit 0, sent as cityCode: "8283", searchId 884506f88954332d, settled: converged, 10 of 183 hotels, all cityName: "Makkah"
hotels search 999999999 2027-01-20 2027-01-22 (no city) exit 4, 404 Unknown hotel or city. exit 4, sent as hotelId, 404 Unknown hotel.
flights share ZZZ CAI 2027-01-20 exit 0, searchUrl …/zzz-cai-2027-01-20/… exit 6, No link was built: the from code "ZZZ" resolves to no city or airport. Find one with \wego places ` and pass the code it reports.`
hotels share ZZZ 2027-01-20 2027-01-22 exit 0, searchUrl …/hotels/searches/zzz/… exit 6, No link was built: the city code "ZZZ" resolves to no city. …
flights share ZZZ QQQ 2027-01-20 exit 0, dead URL exit 6, names both codes
hotels share LHR 2027-01-20 2027-01-22 (airport) exit 0, …/hotels/searches/lhr/… exit 6, the city code "LHR" resolves to no city
flights share DXB CAI 2027-01-20 exit 0, searchUrl …/dxb-cai-2027-01-20/… exit 0, same URL
hotels share DXB 2027-01-20 2027-01-22 exit 0, searchUrl …/hotels/searches/dxb/… exit 0, same URL
flights search ZZZ CAI 2027-01-20 exit 6, 502 bad_gateway exit 6, 400 validation_failed (API PR)
hotels search ZZZ 2027-01-20 2027-01-22 exit 4, 404 Unknown hotel or city. exit 6, 400 validation_failed (API PR)
info schedules ZZZ CAI exit 6, 400 validation_failed unchanged
flights search ABCD CAI 2027-01-20 exit 6, 400 from must be a 3-letter IATA code unchanged
flights search DXB CAI 2027-01-20 exit 0, searchId exit 0, searchId
hotels search DXB 2027-01-20 2027-01-22 exit 0, results exit 0, results

Done when (PET-508)

Item This PR
1. Flights and hotels search: 400 validation_failed, code, recovery, trace_id In the API PR. Rows above show it end to end.
2. Flights and hotels share refuse an unresolvable code, non-zero exit, no URL ✅ exit 6, no link request on the wire (integration: fake.requests("getFlightSearchLink") / getHotelSearchLink empty)
3. Hotels search 8283 gives no 502: it says what is wrong or succeeds ✅ succeeds: exit 0, sent as cityCode, Makkah searchId and results (first row). A number that is no city stays a hotelId
4. No "retry" beside a permanent exit ✅ no output in the PR column contains "retry"; asserted in both share scenarios
5. No regression: ABCD shape error, DXB CAI searchId ✅ rows above; share of DXB still exits 0 with the same URL

QA plan

Check Expected How to verify
wego flights share ZZZ CAI 2026-12-20 on the released CLI exit 6, stderr No link was built …, empty stdout run it, echo $?
wego hotels share ZZZ 2026-12-20 2026-12-22 exit 6, no URL same
wego hotels search 8283 2027-01-20 2027-01-22 exit 0, Makkah hotels same
wego flights share DXB CAI 2026-12-20 and wego hotels share DXB … exit 0, a searchUrl same

Notes for reviewers

  • The vendored contract is the wego-ai #2132 contract (0.19.5), servers set to https://api.wego.com as production serves it. Production still serves 0.19.3, so the non-blocking contract drift step warns until #2132 ships. Merge #2132 first: without its numeric lookup, 8283 stays a hotelId.
  • Share exits 6, not 2: the argv is well-formed, and the refusal needs the API, like validation_failed.

Details for AI and humans who like to read everything

Files

File Change
src/commands.ts fetchPlaces in FlightsDeps and HotelsDeps. unresolvedShareCodes (a city row matches by code ?? cityCode, as the API reads it), unresolvedShareMessage, SharePlan<T>. flightsShare and hotelsShare resolve inside the same withAccessToken call, so a 401 refresh covers the lookup too.
src/commands.ts (hotels search) numericCityCode reads the top place; withNumericCity turns an all-digit hotelId into cityCode inside withAccessToken
src/hotels.test.ts numericCityCode: exact city by code or cityCode, other code, a hotel, no results
contract/openapi.json refreshed to 0.19.5
src/index.ts wires fetchPlaces into the flights and hotels deps
integration/harness/fixtures.ts placesKnowing({ CODE: type }): getPlaces routes by query, and a fallback with no results
integration/flights.test.ts, integration/hotels.test.ts existing share scenarios get Places routes. New: ZZZ refused (exit 6, no link request, types=city for hotels), both codes named, airport accepted for flights, airport refused for hotels, a city reported by cityCode alone accepted, --from-city with an airport-only code refused; hotels search 8283 with a Places city sends cityCode, a number with no city sends hotelId

Evidence: bun run check 1464 pass. bun run test:integration 544 pass. All commits signed and Verified. Raw command outputs: one file per row, produced by a script that runs ./.bin/wego with XDG_CONFIG_HOME pointing at locally minted credentials.

🤖 Generated with Devin

Summary by CodeRabbit

  • New Features
    • Hotel searches now recognize numeric city codes when Places confirms they identify a city, while retaining hotel-ID handling when no matching city is found.
  • Bug Fixes
    • Flight and hotel share requests now verify that location codes match the expected place type before creating a link. Unresolved codes return guidance instead of generating a link.
  • Documentation
    • API documentation now clarifies that numeric queries can match city codes and that hotel city codes may be numeric.

🟢 Devin Review found nothing to fix · View findings · Follow Devin's work

Devin Review

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

Original prompt from Ahsan.amin

Implement PET-508: https://wego.atlassian.net/browse/PET-508

Read the ticket in Jira. It is the source of truth, including the "Done when" checks.
Follow the AGENTS.md of wego/wego-ai (apps/api) and wego/cli.

  • Two PRs, both naming PET-508: wego-ai for the search errors and Makkah 8283, wego/cli for share. Branches fix/PET-508-unknown-place-code off each repo's latest main.
  • Re-checked on prod 2026-11-25 with CLI 1.5.1: hotels search now returns 404 "Unknown hotel or city" for ZZZ and for 8283. Decision: an unknown city code returns 400 validation_failed as the ticket says. An unknown hotelId keeps its 404 (PET-561).
  • Run the API on main and on your branch locally, point the CLI at each with WEGO_API_URL, and post a main vs PR table of the ticket's commands in each PR. Keep any analytics away from production.
  • Open the PRs as ready for review, not as drafts. Put the evidence for each "Done when" item in the PR descriptions.
  • Do not merge or promote, and do not edit Jira or post in Slack.
  • If the ticket is unclear, or the work needs anything outside its boundaries, stop and ask.

When done or blocked, reply with the PR URLs and one line per "Done when" item.

@devin-ai-integration devin-ai-integration Bot added the devin Authored by Devin label Nov 25, 2026
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
Walkthrough

Flight and hotel share commands now validate requested codes through Places before requesting links. Hotel search checks numeric locations for matching city codes. The OpenAPI contract documents numeric city-code support, and tests cover these lookup paths.

Changes: Places Resolution

Layer / File(s) Summary
Resolve codes before link creation
src/commands.ts, src/index.ts
Flight shares require exact, case-insensitive city or airport matches. Hotel shares require exact, case-insensitive city matches. Unresolved codes produce guidance and EXIT.PERMANENT. buildRealDeps supplies fetchPlaces to both commands.
Resolve numeric hotel locations
src/commands.ts, src/hotels.test.ts, integration/hotels.test.ts, contract/openapi.json
Hotel search uses cityCode when Places returns a matching city for an all-digit location. Otherwise, it retains the hotelId. Tests cover matching and non-matching results. The OpenAPI contract documents numeric city codes and removes the three-uppercase-letter restriction from cityCode.
Exercise share resolution
integration/harness/fixtures.ts, integration/flights.test.ts, integration/hotels.test.ts
The placesKnowing fixture returns configured Places results and an empty result for other queries. Integration tests cover accepted and unresolved codes, guidance, and cases where no link request occurs.

API Contract Metadata

Layer / File(s) Summary
Update API metadata
contract/openapi.json
The OpenAPI version changes to 0.19.5, the documentation URL changes to agents.wego.com, and the OAuth2 authorization and token URLs use auth.example.invalid.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant flightsShare
  participant hotelsShare
  participant fetchPlaces
  participant SearchLink
  participant HotelLink
  flightsShare->>fetchPlaces: Resolve origin and destination
  fetchPlaces-->>flightsShare: Return Places results
  alt Both codes match allowed place types
    flightsShare->>SearchLink: Request flight share link
  else A code is unresolved
    flightsShare-->>flightsShare: Report unresolved code and return EXIT.PERMANENT
  end
  hotelsShare->>fetchPlaces: Resolve city
  fetchPlaces-->>hotelsShare: Return Places results
  alt City code matches
    hotelsShare->>HotelLink: Request hotel share link
  else City code is unresolved
    hotelsShare-->>hotelsShare: Report unresolved city and return EXIT.PERMANENT
  end
Loading
Merge Risk: Low · previous review 05097

Share commands now refuse unresolved codes, and numeric hotel locations are checked against Places before being sent as cityCode. One minor edge case remains: a zero-prefixed numeric location such as 008283 can be matched as city code 8283. This is easy to fix and does not block merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title follows Conventional Commits. Type fix and scope cli are valid. The subject is imperative and lowercase. It describes the main change: the share commands refuse unresolved codes, and hotel s…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title follows Conventional Commits. Type fix and scope cli are valid. The subject is imperative and lowercase. It describes the main change: the share commands refuse unresolved codes, and hotel searches send numeric city codes as cityCode. The PET-508 key is extra context and does not conflict with the requirements. No breaking-change marker is needed, because the change adds refusal behavior and does not alter the wire contract shape or stdout format.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

flights share and hotels share now resolve each code through GET /v1/places before building a durable link. A code with no exact match exits 6 with no link, instead of exit 0 and a dead URL.

Co-Authored-By: ahsan.amin@wego.com <ahsan.amin@wego.com>
Co-Authored-By: ahsan.amin@wego.com <ahsan.amin@wego.com>
@devin-ai-integration
devin-ai-integration Bot force-pushed the fix/PET-508-unknown-place-code branch from e430c37 to a2344fd Compare November 25, 2026 11:45

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

coderabbitai[bot]

This comment was marked as resolved.

Co-Authored-By: ahsan.amin@wego.com <ahsan.amin@wego.com>
…o a city

Co-Authored-By: ahsan.amin@wego.com <ahsan.amin@wego.com>
GET /v1/places now also matches an all-digit query as a city code.

Co-Authored-By: ahsan.amin@wego.com <ahsan.amin@wego.com>
When the top place Places returns for an all-digit location is the city
with that exact code, hotels search sends it as cityCode. Makkah has no
airport and is 8283. Any other number stays a hotelId.

Co-Authored-By: ahsan.amin@wego.com <ahsan.amin@wego.com>
@devin-ai-integration devin-ai-integration Bot changed the title fix(cli): refuse to share a code that resolves to no place (PET-508) fix(cli): refuse to share an unresolved code, send a numeric city code as cityCode (PET-508) Nov 26, 2026
@ahsan-amin-wego

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai[bot]

This comment was marked as resolved.

008283 is no exact match for city code 8283, so it stays a hotelId.

Co-Authored-By: ahsan.amin@wego.com <ahsan.amin@wego.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devin Authored by Devin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant