Commit graph

8 commits

Author SHA1 Message Date
Jeffrey (Dongkyu) Kim
7a0cefb832 Cover NCard error branches
Add regression coverage for missing NCard package handling and zero-based NCard selection so the KTX helper keeps clear failures around optional korail2-ncard support.

Constraint: PR #231 adds optional NCard behavior that must still be safe when korail2-ncard is not installed.

Rejected: Changing runtime NCard behavior now | existing implementation already returns explicit SystemExit messages and only lacked regression coverage.

Confidence: high

Scope-risk: narrow

Directive: Keep NCard fallback behavior tested separately from normal korail2 imports.

Tested: python3 -m pytest scripts/test_ktx_booking.py -q

Not-tested: Live Korail NCard reservation against production account.
2026-05-12 19:09:45 +09:00
Jeffrey (Dongkyu) Kim
d31157cba3 Reduce N-card number exposure in KTX booking
Prefer N-card selection by list index so full card numbers are not echoed through JSON output or required in shell history. Keep direct card-number input as a compatibility escape hatch with an explicit warning.\n\nConstraint: PR #231 scope is limited to ktx-booking docs, helper, and tests.\nRejected: Require users to copy full card numbers from ncard-list | exposes sensitive identifiers in logs and shell history.\nConfidence: high\nScope-risk: narrow\nDirective: Keep N-card list outputs masked; prefer index-based selection for future reservation flows.\nTested: python3 -m py_compile scripts/ktx_booking.py scripts/test_ktx_booking.py; PYTHONPATH=scripts python3 -m unittest scripts.test_ktx_booking; npm run lint; npm run typecheck; npm test\nNot-tested: Live Korail N-card reservation; requires real user credentials and owned N-card.
2026-05-12 19:06:27 +09:00
cedric
83a1dd1409 feat: N카드 할인 예매 지원 추가 (ktx-booking)
- ncard-list: 보유 N카드 목록 조회 (owned_ncards)
- ncard-search: N카드 할인 열차 조회 (search_owned_ncard_trains)
- reserve --ncard-no: N카드 번호로 할인 승객 예약
- NCardPassenger는 별도 try/except ImportError 블록으로 분리해
  표준 korail2 환경에서도 모듈이 정상 로드되도록 처리
- korail2-ncard 미설치 시 N카드 커맨드에서 설치 안내 출력
- 관련 테스트 7개 추가 (총 18개)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 23:24:02 +09:00
Jeffrey (Dongkyu) Kim
dff4d1c323
Feature/#171 (#191)
* Protect explicit Korail train-type replay

Issue #171 added explicit train-type selection for non-KTX Korail routes. The merged implementation already wires search and reserve through TRAIN_TYPE_MAP; this follow-up locks that behavior with command-level and parser regression coverage, removes stale test import noise, and aligns the skill shortlist wording with the broader train_type output.

Constraint: The ktx-booking skill keeps ktx as the default train type for backward compatibility.

Rejected: Encode train type into train_id in this follow-up | larger selector schema change already marked as non-blocking UX follow-up.

Confidence: high

Scope-risk: narrow

Directive: Do not hardcode command_search or command_reserve back to TrainType.KTX; keep parser choices derived from TRAIN_TYPE_MAP.

Tested: python3 scripts/ktx_booking.py search --help

Tested: python3 scripts/ktx_booking.py reserve --help

Tested: PYTHONPATH=scripts python3 -m unittest scripts.test_ktx_booking

Tested: python3 -m py_compile scripts/ktx_booking.py scripts/test_ktx_booking.py

Tested: PYTHONNOUSERSITE=1 PYTHONPATH=scripts python3 -S -c 'import ktx_booking; print(ktx_booking._KORAIL_IMPORT_ERROR); print(ktx_booking.TRAIN_TYPE_MAP["itx-cheongchun"])'

Tested: PYTHONNOUSERSITE=1 PYTHONPATH=scripts python3 -m unittest discover -s scripts -p 'test_ktx_booking.py'

Tested: python3 -S scripts/ktx_booking.py search --help; python3 -S scripts/ktx_booking.py reserve --help

Tested: npm run lint

Tested: npm run typecheck

Tested: npm test

Not-tested: Live Korail search/reserve requiring credentials and external availability

* Guard KTX search default during train-type regression

Issue #171 locked explicit train-type choices for Korail search and reserve flows. The follow-up review found reserve default coverage but no direct search default assertion, so this adds the narrow parser regression without changing runtime behavior.\n\nConstraint: Issue #171 requires search and reserve train-type behavior to stay regression-covered.\nRejected: Broaden command-level tests for every train type | parser choices already loop over TRAIN_TYPE_MAP and command forwarding is covered for the non-KTX regression route.\nConfidence: high\nScope-risk: narrow\nTested: PYTHONPATH=scripts python3 -m unittest scripts.test_ktx_booking\nTested: python3 -m py_compile scripts/ktx_booking.py scripts/test_ktx_booking.py\nTested: npm run lint\nTested: npm run typecheck\nTested: npm test\nNot-tested: live Korail search/reserve requiring credentials and external service availability

* Tighten KTX train-type regression tests

The Issue #171 follow-up already locked the train-type CLI behavior. This pass addresses the remaining review cleanup in the modified test file by narrowing the normalized train_id before reuse and tidying formatting without changing behavior.

Constraint: Keep the PR scoped to ktx-booking regression coverage and documentation

Rejected: Encode train_type into train_id in this follow-up | broader selector migration is outside the approved regression scope

Confidence: high

Scope-risk: narrow

Tested: PYTHONPATH=scripts python3 -m unittest scripts.test_ktx_booking

Tested: python3 -m py_compile scripts/ktx_booking.py scripts/test_ktx_booking.py

Tested: pyright scripts/test_ktx_booking.py

Tested: npm run lint

Tested: npm run typecheck

Tested: npm test

Not-tested: live Korail search/reserve requiring credentials and external service availability
2026-04-30 19:58:55 +09:00
Jeffrey (Dongkyu) Kim
1eaa7eb7d8 fix(ktx-booking): make korail2 fallback TrainType import-safe
The fallback TrainType class only defined ALL/KTX, but TRAIN_TYPE_MAP
references ITX_SAEMAEUL, MUGUNGHWA, NURIRO, TONGGUEN, ITX_CHEONGCHUN,
and AIRPORT at import time, so the module crashed with AttributeError
in environments where korail2 is missing. This bypassed the controlled
guidance from ensure_runtime_dependencies() and broke even `--help`.

Mirror upstream korail2.TrainType numeric IDs in the fallback so the
import-time TRAIN_TYPE_MAP construction succeeds and the helper can
surface its install message. Add regression tests that exercise the
missing-korail2 path via subprocess to lock the behavior in.

Addresses round 2 review on #172.
2026-04-30 01:18:46 +09:00
Jeffrey (Dongkyu) Kim
aa1768a055 Keep KTX train-type changes covered by regression tests
The new reserve train-type argument is consumed by direct command_reserve
calls as well as the CLI parser, so the existing unit helpers need to
model the parser default and assert non-KTX replay behavior explicitly.

Constraint: PR #172 is now retargeted to dev and must be mergeable without weakening the train_id stability tests
Confidence: high
Scope-risk: narrow
Tested: python3 -m py_compile scripts/ktx_booking.py scripts/test_ktx_booking.py
Tested: PYTHONPATH=.:scripts python3 -m unittest scripts.test_ktx_booking
Tested: npm run lint
2026-04-26 22:36:14 +09:00
Jeffrey (Dongkyu) Kim
6c2c0d54e3 Keep waiting-list reservations aligned with the selected train
The reserve replay search now auto-includes waiting-list candidates when users opt into --try-waiting, so the stable train_id chosen from search remains resolvable for docs-following flows. A regression test reproduces the prior stale-train failure and locks the corrected behavior.\n\nConstraint: Reserve must keep using the existing train_id replay flow without broad CLI redesign\nRejected: Require users to repeat --include-waiting-list on reserve | contradicts the documented flow and review feedback\nConfidence: high\nScope-risk: narrow\nReversibility: clean\nDirective: Keep --try-waiting and reserve replay search semantics aligned so waiting-list-only trains remain selectable\nTested: python3 -m py_compile scripts/ktx_booking.py; python3 -m unittest discover -s scripts -p test_ktx_booking.py; node --test scripts/skill-docs.test.js; npm run ci; python3 scripts/ktx_booking.py --help; python3 scripts/ktx_booking.py reserve --help; live search/reservations/reserve/cancel/reservations via sops-managed Korail credentials\nNot-tested: Live waiting-list reservation creation (no waiting-list-eligible train appeared in the smoke search output)
2026-03-27 11:26:38 +09:00
Jeffrey (Dongkyu) Kim
04653f761f Prevent KTX reserve retries from drifting to the wrong train
Reserve used to replay search results and trust a fresh ordinal index, which could silently target a different train when sold-out entries disappeared or ordering changed. This change emits a stable train_id from search output, requires reserve to match the exact train identity on replay, and updates docs/tests to lock the safer CLI contract.

Constraint: Korail search results can reorder between search and reserve while the helper still needs to replay the live lookup
Rejected: Keep --train-index as the reserve selector | still allows silent wrong-train bookings when the result set shifts
Confidence: high
Scope-risk: narrow
Reversibility: clean
Directive: If upstream train identity fields change, update the train_id payload and the docs/tests together before changing reserve selection again
Tested: python3 -m py_compile scripts/ktx_booking.py; python3 -m unittest discover -s scripts -p test_ktx_booking.py; node --test scripts/skill-docs.test.js; npm run ci; live search/reservations/reserve/cancel/reservations with sops-managed Korail credentials
Not-tested: Forced live stale-train_id failure against a disappearing train between search and reserve
2026-03-27 11:09:14 +09:00