Phase 4 §4: payment-before-pair for returning users + Maestro suite

Stages 5.1, 5.3, 5.4 of the returning-user flow rework. All three §4
entry paths now require payment BEFORE pairing, matching the updated
mermaid spec.

* Spec (requirement/flow_customer.mermaid.md §4): payment block converges
  three call-sites (bestie-yang-udah-kenal-online, bestie-baru,
  offline-popup → cari bestie lain). PairRoute dispatches lama → targeted
  pair, baru/cari-lain → §3 blast. §3 retains its post-payment-shared
  contract.

* Stage 5.1 (client_app): PaymentDraft carries targetedMitraId +
  topicSensitivity. bestie_history_list seeds the draft + pushes
  /payment/entry (was legacy /payment). searching_screen branches on
  draft.targetedMitraId for blast-vs-targeted dispatch.
  payment_entry uses resetExceptTarget(); bestie_choice_sheet + home
  _onCurhatBestieBaruPressed call explicit reset() before push so
  the keepAlive draft can't leak stale targeting into a blast.

* Stage 5.3 (client_app): new BestieOfflineVariant.prePayReturning.
  Bestie-history-list _BestieRow splits tappable from dim so offline
  rows render dimmed but route taps into the popup. CTA "cari bestie
  lain" resets the draft + pushes /payment/entry.

* Stage 5.4 (client_app): deleted legacy /payment route,
  payment_screen.dart, payment_notifier.dart(+.g.dart). router cleaned.

* Tests (requirement/phase4-customer-flow.md + client_app/.maestro/):
  six Maestro flows TS-01..TS-06 covering every §4 branching point,
  all passing end-to-end. Shared onboarding prelude under
  .maestro/subflows/. New helper scripts: accept_latest_pending,
  force_mitra_offline, force_other_mitra_online,
  reset_all_mitras_online, mitra_accept_latest_internal. New backend
  _test endpoints to match. /reset-phone now cascade-deletes
  customer_transactions (FK was blocking). /force-pairing-timeout
  branches targeted (RETURNING_CHAT_TIMEOUT via
  expireTargetedPairingRequest, now exported) vs blast (PAIRING_FAILED).
  seed_history_session also outputs MITRA_NAME_RE (regex-escaped) for
  reliable selectors against display names containing regex specials.

* mitra_app: dispose-during-deactivate guardrail for back-press on the
  mitra chat screen after the customer's goodbye message. Pending real
  emulator repro verification (carried over from 2026-05-15).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-17 20:25:15 +08:00
parent 1c9d81d81d
commit e09f76ceb6
32 changed files with 1755 additions and 680 deletions

View File

@@ -0,0 +1,17 @@
// Accept the latest pending pairing notification regardless of mitra. Used
// by flows where the acceptor mitra UUID isn't known in advance — e.g.
// TS-02 (blast where the seeded mitra was forced offline, so an unknown
// OTHER online mitra got the chat_request_notification row).
//
// Backed by /internal/_test/accept-latest-pending (no body needed).
const url = BACKEND_INTERNAL_URL || 'http://localhost:3001'
const resp = http.post(`${url}/internal/_test/accept-latest-pending`, {
headers: { 'Content-Type': 'application/json' },
body: '{}',
})
if (resp.status !== 200) {
throw new Error(`accept-latest-pending failed (${resp.status}): ${resp.body}`)
}
const data = json(resp.body)
output.ACCEPTED_SESSION_ID = data.session_id
output.ACCEPTOR_MITRA_ID = data.mitra_id

View File

@@ -0,0 +1,20 @@
// Force a specific mitra OFFLINE via the dev-only
// /internal/_test/force-mitra-offline endpoint. Used by Maestro flows that
// need the bestie-history-list row for a particular mitra to render in its
// offline (dimmed) state — see TS-02 / TS-03 in
// requirement/phase4-customer-flow.md.
//
// Reads MITRA_ID from env (typically `${output.MITRA_ID}` from a prior
// seed_history_session.js run) and BACKEND_INTERNAL_URL.
const mitraId = MITRA_ID
const url = BACKEND_INTERNAL_URL || 'http://localhost:3001'
if (!mitraId) {
throw new Error('MITRA_ID env not set — pass output.MITRA_ID from seed_history_session.js')
}
const resp = http.post(`${url}/internal/_test/force-mitra-offline`, {
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ mitra_id: mitraId }),
})
if (resp.status !== 200) {
throw new Error(`force-mitra-offline failed (${resp.status}): ${resp.body}`)
}

View File

@@ -0,0 +1,17 @@
// Force a DIFFERENT mitra online (one other than the seeded one) so blast
// flows (TS-02, TS-06) have an acceptor available after the seeded mitra is
// forced offline. Picks any currently-offline mitra excluding MITRA_ID.
//
// Reads MITRA_ID (the seeded mitra to exclude, from seed_history_session.js)
// and BACKEND_INTERNAL_URL.
const excludeId = MITRA_ID
const url = BACKEND_INTERNAL_URL || 'http://localhost:3001'
const resp = http.post(`${url}/internal/_test/force-mitra-online`, {
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ exclude_mitra_id: excludeId }),
})
if (resp.status !== 200) {
throw new Error(`force-mitra-online failed (${resp.status}): ${resp.body}`)
}
const data = json(resp.body)
output.OTHER_MITRA_ID = data.mitra_id

View File

@@ -0,0 +1,19 @@
// Have the test mitra "accept" the most recent pending pairing request via
// the dev-only /internal/_test/mitra-accept-latest endpoint (no JWT needed).
//
// Reads MITRA_ID from the env that the calling flow injects — typically
// `${output.MITRA_ID}` from a prior seed_history_session.js run.
const mitraId = MITRA_ID
const url = BACKEND_INTERNAL_URL || 'http://localhost:3001'
if (!mitraId) {
throw new Error('MITRA_ID env not set — pass output.MITRA_ID from seed_history_session.js')
}
const resp = http.post(`${url}/internal/_test/mitra-accept-latest`, {
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ mitra_id: mitraId }),
})
if (resp.status !== 200) {
throw new Error(`mitra-accept-latest failed (${resp.status}): ${resp.body}`)
}
const data = json(resp.body)
output.ACCEPTED_SESSION_ID = data.session_id

View File

@@ -0,0 +1,16 @@
// Bulk-mark every mitra row online in mitra_online_status. Used as a setup
// step at the start of each Maestro flow so seed_history_session has at
// least one online mitra to pick, regardless of what previous tests did
// (e.g. force-mitra-offline lingering from a prior TS-02/TS-03 run).
//
// Backed by /internal/_test/reset-all-mitras-online.
const url = BACKEND_INTERNAL_URL || 'http://localhost:3001'
const resp = http.post(`${url}/internal/_test/reset-all-mitras-online`, {
headers: { 'Content-Type': 'application/json' },
body: '{}',
})
if (resp.status !== 200) {
throw new Error(`reset-all-mitras-online failed (${resp.status}): ${resp.body}`)
}
const data = json(resp.body)
output.ONLINE_COUNT = data.online_count

View File

@@ -16,3 +16,7 @@ const data = json(resp.body)
output.SESSION_ID = data.session_id
output.MITRA_ID = data.mitra_id
output.MITRA_NAME = data.mitra_name
// Regex-escaped variant for Maestro `text:` selectors (which do FULL-string
// regex match). Display names can contain `+` (phone-as-name), `.`, etc.
// which break selectors otherwise.
output.MITRA_NAME_RE = data.mitra_name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')