@jetthai/cuora 1.1.488-dev.1 → 1.1.488

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/.claude/commands/sync-ai-prompts.md +1 -88
  2. package/.claude/settings.local.json +1 -3
  3. package/.github/copilot-instructions.md +6 -17
  4. package/.husky/post-checkout +3 -3
  5. package/.husky/pre-push +1 -1
  6. package/.prettierignore +1 -2
  7. package/AGENTS.md +6 -17
  8. package/AI_PROMPT_SOURCE.md +6 -17
  9. package/CHANGELOG.md +23 -420
  10. package/CLAUDE.md +6 -17
  11. package/GEMINI.md +6 -17
  12. package/package.json +1 -1
  13. package/scripts/auto-version.js +0 -1
  14. package/scripts/branch-auto-npm-publish.js +2 -9
  15. package/src/api/payment.js +0 -1
  16. package/src/machine/auth.js +33 -36
  17. package/src/machine/game_v2_1.js +0 -15
  18. package/src/machine/user_sign_up.js +0 -3
  19. package/src/machine/withdraw/withdraw_manual_cash.js +7 -17
  20. package/src/request/request.js +4 -103
  21. package/src/util/constant.js +0 -6
  22. package/e2e/feature-map.md +0 -19
  23. package/prepare-for-pr/JT-1776243420.md +0 -85
  24. package/prepare-for-pr/TI-16026/STATE.md +0 -18
  25. package/prepare-for-pr/TI-16026/after-prepare-authorization.md +0 -3
  26. package/prepare-for-pr/TI-16026/analysis.md +0 -38
  27. package/prepare-for-pr/TI-16026/answer-analyze-01.md +0 -1
  28. package/prepare-for-pr/TI-16026/answer-commit-01.md +0 -2
  29. package/prepare-for-pr/TI-16026/answer-commit-02.md +0 -1
  30. package/prepare-for-pr/TI-16026/bundle.json +0 -18
  31. package/prepare-for-pr/TI-16026/checklist.md +0 -196
  32. package/prepare-for-pr/TI-16026/checklist.unit-test-original.md +0 -39
  33. package/prepare-for-pr/TI-16026/claude-after-model +0 -1
  34. package/prepare-for-pr/TI-16026/claude-commit-session +0 -1
  35. package/prepare-for-pr/TI-16026/claude-harvest-session +0 -1
  36. package/prepare-for-pr/TI-16026/claude-hops/01-analyze.err +0 -1
  37. package/prepare-for-pr/TI-16026/claude-hops/01-analyze.out +0 -2
  38. package/prepare-for-pr/TI-16026/claude-hops/02-analyze.err +0 -1
  39. package/prepare-for-pr/TI-16026/claude-hops/02-analyze.out +0 -4
  40. package/prepare-for-pr/TI-16026/claude-hops/03-dev.err +0 -1
  41. package/prepare-for-pr/TI-16026/claude-hops/03-dev.out +0 -4
  42. package/prepare-for-pr/TI-16026/claude-hops/04-dev.err +0 -1
  43. package/prepare-for-pr/TI-16026/claude-hops/04-dev.out +0 -4
  44. package/prepare-for-pr/TI-16026/claude-hops/05-dev.err +0 -1
  45. package/prepare-for-pr/TI-16026/claude-hops/05-dev.out +0 -3
  46. package/prepare-for-pr/TI-16026/claude-hops/06-after.err +0 -1
  47. package/prepare-for-pr/TI-16026/claude-hops/06-after.out +0 -2
  48. package/prepare-for-pr/TI-16026/claude-hops/07-commit.err +0 -1
  49. package/prepare-for-pr/TI-16026/claude-hops/07-commit.out +0 -2
  50. package/prepare-for-pr/TI-16026/claude-hops/08-commit.err +0 -1
  51. package/prepare-for-pr/TI-16026/claude-hops/08-commit.out +0 -2
  52. package/prepare-for-pr/TI-16026/claude-hops/09-commit.err +0 -1
  53. package/prepare-for-pr/TI-16026/claude-hops/09-commit.out +0 -8
  54. package/prepare-for-pr/TI-16026/claude-hops/10-harvest.err +0 -1
  55. package/prepare-for-pr/TI-16026/claude-hops/10-harvest.out +0 -3
  56. package/prepare-for-pr/TI-16026/claude-hops/11-harvest.err +0 -1
  57. package/prepare-for-pr/TI-16026/claude-hops/11-harvest.out +0 -3
  58. package/prepare-for-pr/TI-16026/commit-note.md +0 -5
  59. package/prepare-for-pr/TI-16026/evidence-index.json +0 -215
  60. package/prepare-for-pr/TI-16026/feature-map.before.md +0 -61
  61. package/prepare-for-pr/TI-16026/harvest-redaction.json +0 -34
  62. package/prepare-for-pr/TI-16026/harvest-redaction.out +0 -37
  63. package/prepare-for-pr/TI-16026/harvest.md +0 -46
  64. package/prepare-for-pr/TI-16026/lessons.md +0 -5
  65. package/prepare-for-pr/TI-16026/note-harvest-redaction.md +0 -1
  66. package/prepare-for-pr/TI-16026/open-questions.md +0 -6
  67. package/prepare-for-pr/TI-16026/publish.md +0 -32
  68. package/prepare-for-pr/TI-16026/review-convergence-response.md +0 -3
  69. package/prepare-for-pr/TI-16026/review-input/scope.md +0 -18
  70. package/prepare-for-pr/TI-16026/review-log.md +0 -57
  71. package/prepare-for-pr/TI-16026/review-notes.md +0 -97
  72. package/prepare-for-pr/TI-16026/review-response-r1.md +0 -7
  73. package/prepare-for-pr/TI-16026/self-test-report.md +0 -67
  74. package/prepare-for-pr/TI-16026/spec-proposal.md +0 -34
  75. package/prepare-for-pr/TI-16026/spec-snapshot.md +0 -291
  76. package/prepare-for-pr/TI-16026/state-log.md +0 -57
  77. package/prepare-for-pr/TI-16026/user-messages/01.md +0 -12
  78. package/prepare-for-pr/TI-16026/user-messages/02.md +0 -20
  79. package/prepare-for-pr/TI-16026/user-messages/03.md +0 -1
  80. package/prepare-for-pr/TI-16026/user-messages/04.md +0 -1
  81. package/prepare-for-pr/TI-16026/user-messages/05.md +0 -1
  82. package/prepare-for-pr/TI-16026/user-messages/06.md +0 -1
  83. package/prepare-for-pr/TI-16026/user-messages/07.md +0 -1
  84. package/prepare-for-pr/TI-16026/user-messages/08.md +0 -1
  85. package/prepare-for-pr/TI-16026/user-messages/09.md +0 -1
  86. package/prepare-for-pr/TI-16026/user-messages/10.md +0 -1
  87. package/prepare-for-pr/TI-16026/user-messages/11.md +0 -1
  88. package/prepare-for-pr/TI-16026/user-messages/12.md +0 -1
  89. package/prepare-for-pr/TI-16026/user-messages/13.md +0 -1
  90. package/prepare-for-pr/TI-16026/user-messages/14.md +0 -1
  91. package/prepare-for-pr/TI-16026/user-messages/15.md +0 -1
  92. package/prepare-for-pr/TI-16026/user-messages/16.md +0 -1
  93. package/prepare-for-pr/TI-16026/user-messages/17.md +0 -1
  94. package/prepare-for-pr/TI-16026/user-messages/18.md +0 -10
  95. package/prepare-for-pr/TI-16026/user-messages/19.md +0 -1
  96. package/prepare-for-pr/TI-16026/user-messages/20.md +0 -1
  97. package/prepare-for-pr/TI-16026/user-messages/21.md +0 -1
  98. package/prepare-for-pr/TI-16026/user-messages/22.md +0 -1
  99. package/prepare-for-pr/TI-16026/user-messages/23.md +0 -8
  100. package/prepare-for-pr/TI-16026/user-messages/24.md +0 -24
  101. package/prepare-for-pr/TI-16026/user-question.md +0 -24
  102. package/prepare-for-pr/TI-16026/verify/metrics-check.json +0 -13
  103. package/prepare-for-pr/TI-16026/verify/redaction.json +0 -38
  104. package/prepare-for-pr/TI-16026/verify/row-closure.json +0 -45
  105. package/prepare-for-pr/TI-16026/verify/s04-ws-capture.md +0 -23
  106. package/prepare-for-pr/TI-16026/verify-after.md +0 -23
  107. package/prepare-for-pr/TI-16026/verify.json +0 -80
  108. package/prepare-for-pr/TI-16026.md +0 -408
  109. package/src/util/tokenStore.js +0 -44
  110. package/test/auth_self_timeout.test.js +0 -171
  111. package/test/request_self.test.js +0 -288
  112. package/test/withdraw_manual_cash.test.js +0 -149
  113. package/tests/session.test.mjs +0 -177
@@ -1,408 +0,0 @@
1
- # TI-16026: Withdraw submitted-state REFRESH review
2
-
3
- ## Key Changes
4
-
5
- 1. `submitted` accepts REFRESH -> loading and reuses fetchInitData. The r2 fix makes loading.onError return to submitted when processing exists, preserving the pending order and allowing retry; first-load failure still falls back to loaded (`src/machine/withdraw/withdraw_manual_cash.js:40`, :98-101).
6
- 2. Target: feat/stone/JT-1791856380-ws-refresh; HEAD/base c9186b6b3f424d74a9fe1363e64b17eb63809b58. Product changes and test/withdraw_manual_cash.test.js remain uncommitted. The r2 incremental review verified the failure fix; its fresh independent convergence check reviews the complete base-to-working-tree change, including the original submitted REFRESH handler and all six untracked tests.
7
-
8
- ---
9
-
10
- ## Key Findings
11
-
12
- ### Strengths
13
-
14
- 1. The fix reuses isProcessing and existing state names, keeps successful initialization unchanged and adds observable rejection/retry assertions with a bound bank.
15
- 2. A memory-only old-onError negative control makes exactly the new retry test fail, proving that it detects the original defect.
16
-
17
- ---
18
-
19
- ### Behavior Observed
20
-
21
- 1. **F-r1-01 [medium], ACCEPT, verified in r2: yes.** Pending W-1 + bound bank -> REFRESH -> second pendingOrder rejects ERR_998 -> submitted with W-1 retained -> next REFRESH makes request 3 and reaches loaded. No new findings in r2. The historical finding and response remain in review-log.md.
22
- 2. Initial pendingOrder rejection with processing=null still reaches loaded. Successful submitted reload enters loading; an empty response clears processing and reaches loaded; another pending order replaces W-1/500 with W-2/800 and reaches submitted. All six targeted tests pass.
23
- 3. Root REFRESH remains conditional outside submitted. The loaded bank/no-bank transition probe passes both outcomes; other non-submitted definitions were inspected, not individually executed.
24
- 4. The fresh whole-change reviewer formed observations from spec/diff/source before reading the full prior STATE/log/notes, then independently reproduced the six passing tests, the negative-control failure and root boundary results. No additional finding or re-raise was identified. The driver owns the next check-review.sh invocation and STATE update; this report does not declare loop convergence.
25
-
26
- ---
27
-
28
- ## 🔧 Change Type
29
-
30
- - [x] 🐛 Bug fix
31
- - [ ] ✨ New feature
32
- - [ ] 💄 Style
33
- - [ ] ♻️ Refactor
34
- - [ ] ⚡ Performance
35
- - [ ] 🔧 Chore
36
-
37
- ---
38
-
39
- ## 📱 Impact Scope
40
-
41
- The shared SDK factory now accepts REFRESH from submitted regardless of bound banks, enters loading and fetches status again. Empty pending-order results reach loaded; a remaining order replaces processing and returns submitted. If initialization fails with an existing processing order, callers retain submitted and the previous order, then retry with the same REFRESH event. Import/export contracts, factory arguments, event/state names and successful initialization remain unchanged.
42
-
43
- Internal unchanged consumers were searched with `rg -n 'withdraw_manual_cash|withdraw/index|\.\.\.withdraw|machine/index' src`: src/machine/withdraw/index.js:4 -> src/machine/index.js:18/:54 -> src/index.js:2/:7. Each is an export-forwarding layer without state/error decisions, needs no adaptation, and is listed in the r2 Impact block. The supplied scope also names client-pwa-cash; its exact consumer paths and rendering were not verified because no other repo was inspected. Other frontends using the factory receive the same corrected failure state.
44
-
45
- The user selected unit tests and review for this SDK repo: adapter=none, delivery local, no SDK screenshots. Cash UI, WebSocket strict-ID behavior, real backend payloads and published-package integration remain with the cash verification flow. The convergence reviewer independently confirmed that src/machine/websocket.js:296-301 already forwards payment-info without a windowType toast filter; the spec's conditional relaxation therefore needs no additional patch on that static criterion. No real socket event was exercised. client-pwa-cash is an explicit downstream consumer; exact downstream paths were not inspected. client-pwa and client-pwa-ssr have no established direct callsite in this scoped input and were not inspected; any caller using this factory receives the same SDK behavior.
46
-
47
- ---
48
-
49
- ## Test Completion Status
50
-
51
- | Item | Validation Tested | Status |
52
- | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
53
- | R2-E1 — accepted failure fix and success regression | node --test test/withdraw_manual_cash.test.js; six cases listed below, 6 passed, 0 failed, exit 0. | PASS |
54
- | R2-E2 — test sensitivity | Same suite with only old unconditional loading.onError restored in memory: failed retry case times out waiting for submitted; 5 passed, 1 failed, exit 1 expected. | PASS |
55
- | R2-E3 — root REFRESH boundary | Pure transitions: loaded with no bank -> loading; loaded with bound bank -> loaded; assertions pass, exit 0, no request. | PASS |
56
- | R2-E4 — code/whitespace | git diff --check, empty output, exit 0; inspect onError, onDone, guard, initializer and exports. | PASS |
57
- | C2-E1–C2-E4 — independent whole-change convergence | Fresh spec/source review, complete base-to-working-tree diff and untracked test; independently rerun six tests (6 pass), old-onError negative control (expected 1 failure), root boundaries (pass) and whitespace check (pass). Raw output below. | PASS |
58
- | Full suite / alternate wallet gates / OTP / other errors | Not selected for this scoped whole-change review: services, wallet gating and OTP definitions are unchanged; no exhaustive event or error enumeration. | NOT RUN |
59
- | Cash UI / real backend / published package | Outside this SDK review and not executed; user choice A replaces SDK screenshot evidence. | NOT RUN |
60
-
61
- Evidence is embedded in this report because only this report, review-log.md and review-notes.md are writable. All commands ran from cuora-module. Local response stubs exercise the real XState factory and initializer without transport/backend calls or transactions.
62
-
63
- R2-E1 raw output:
64
-
65
- ```text
66
- $ node --test test/withdraw_manual_cash.test.js
67
- ✔ REFRESH in submitted re-runs loading and fetches the pending order again (4.531542ms)
68
- ✔ REFRESH in submitted returns to the form when no order is pending (0.86175ms)
69
- ✔ REFRESH in submitted keeps submitted with the updated order when one is still pending (1.483625ms)
70
- ✔ a failed refresh in submitted keeps the pending order and a later REFRESH retries (0.742208ms)
71
- ✔ a failed first load without a pending order still shows the form (0.394833ms)
72
- ✔ REFRESH in loaded with a bound bank is still ignored (22.485208ms)
73
- ℹ tests 6
74
- ℹ suites 0
75
- ℹ pass 6
76
- ℹ fail 0
77
- ℹ cancelled 0
78
- ℹ skipped 0
79
- ℹ todo 0
80
- ℹ duration_ms 114.366834
81
- exit: 0
82
- ```
83
-
84
- R2-E2 exact command (memory only):
85
-
86
- ```sh
87
- node --input-type=module <<'NODE'
88
- import test from 'node:test'
89
- import assert from 'node:assert/strict'
90
- import { readFileSync } from 'node:fs'
91
- import { interpret, createMachine } from 'xstate'
92
- import original from './src/machine/withdraw/withdraw_manual_cash.js'
93
- const suite = readFileSync('test/withdraw_manual_cash.test.js', 'utf8').replace(/^import .*\n/gm, '')
94
- const mutant = (...args) => {
95
- const machine = original(...args)
96
- return createMachine({ ...machine.config, states: { ...machine.config.states, loading: { ...machine.config.states.loading, invoke: { ...machine.config.states.loading.invoke, onError: { target: 'loaded' } } } } }, machine.options)
97
- }
98
- console.log('NEGATIVE CONTROL ONLY: restore old loading.onError in memory; files unchanged')
99
- new Function('test', 'assert', 'interpret', 'withdrawManualCash', suite)(test, assert, interpret, mutant)
100
- NODE
101
- ```
102
-
103
- ```text
104
- NEGATIVE CONTROL ONLY: restore old loading.onError in memory; files unchanged
105
- ✔ REFRESH in submitted re-runs loading and fetches the pending order again (4.642166ms)
106
- ✔ REFRESH in submitted returns to the form when no order is pending (1.186167ms)
107
- ✔ REFRESH in submitted keeps submitted with the updated order when one is still pending (1.146458ms)
108
- ✖ a failed refresh in submitted keeps the pending order and a later REFRESH retries (1001.534792ms)
109
- ✔ a failed first load without a pending order still shows the form (0.655125ms)
110
- ✔ REFRESH in loaded with a bound bank is still ignored (22.874459ms)
111
- ℹ tests 6
112
- ℹ suites 0
113
- ℹ pass 5
114
- ℹ fail 1
115
- ℹ cancelled 0
116
- ℹ skipped 0
117
- ℹ todo 0
118
- ℹ duration_ms 1034.528792
119
- Error: Timed out waiting for submitted
120
- at Timeout.eval [as _onTimeout] (eval at <anonymous> (.../[eval1]:12:1), <anonymous>:7:45)
121
- at listOnTimeout (node:internal/timers:605:17)
122
- at process.processTimers (node:internal/timers:541:7)
123
- exit: 1 (expected)
124
- ```
125
-
126
- R2-E3 exact command and output:
127
-
128
- ```sh
129
- node --input-type=module <<'NODE'
130
- import assert from 'node:assert/strict'
131
- import factory from './src/machine/withdraw/withdraw_manual_cash.js'
132
- const machine = factory({ send() { throw new Error('No requests expected') } })
133
- assert.equal(machine.transition('loaded', 'REFRESH').value, 'loading')
134
- const withBank = machine.withContext({ ...machine.context, userBanks: [{ bankCode: 'BANK' }] })
135
- assert.equal(withBank.transition('loaded', 'REFRESH').value, 'loaded')
136
- console.log('PASS: root REFRESH no bank -> loading; bound bank -> loaded; no requests')
137
- NODE
138
- ```
139
-
140
- ```text
141
- PASS: root REFRESH no bank -> loading; bound bank -> loaded; no requests
142
- exit: 0
143
- ```
144
-
145
- ### Fresh r2 whole-change convergence evidence
146
-
147
- C2-E1 repeats `node --test test/withdraw_manual_cash.test.js` against the actual working tree:
148
-
149
- ```text
150
- ✔ REFRESH in submitted re-runs loading and fetches the pending order again (4.552ms)
151
- ✔ REFRESH in submitted returns to the form when no order is pending (1.1955ms)
152
- ✔ REFRESH in submitted keeps submitted with the updated order when one is still pending (1.1305ms)
153
- ✔ a failed refresh in submitted keeps the pending order and a later REFRESH retries (0.741834ms)
154
- ✔ a failed first load without a pending order still shows the form (0.394833ms)
155
- ✔ REFRESH in loaded with a bound bank is still ignored (22.575125ms)
156
- ℹ tests 6
157
- ℹ suites 0
158
- ℹ pass 6
159
- ℹ fail 0
160
- ℹ cancelled 0
161
- ℹ skipped 0
162
- ℹ todo 0
163
- ℹ duration_ms 118.840542
164
- exit: 0
165
- ```
166
-
167
- C2-E2 independently repeats the R2-E2 memory-only command above (only the console label changes):
168
-
169
- ```text
170
- NEGATIVE CONTROL: old loading.onError in memory; files unchanged
171
- ✔ REFRESH in submitted re-runs loading and fetches the pending order again (4.803667ms)
172
- ✔ REFRESH in submitted returns to the form when no order is pending (1.337542ms)
173
- ✔ REFRESH in submitted keeps submitted with the updated order when one is still pending (1.228041ms)
174
- ✖ a failed refresh in submitted keeps the pending order and a later REFRESH retries (1002.164458ms)
175
- ✔ a failed first load without a pending order still shows the form (2.062334ms)
176
- ✔ REFRESH in loaded with a bound bank is still ignored (24.000333ms)
177
- ℹ tests 6
178
- ℹ suites 0
179
- ℹ pass 5
180
- ℹ fail 1
181
- ℹ cancelled 0
182
- ℹ skipped 0
183
- ℹ todo 0
184
- ℹ duration_ms 1039.1935
185
- Error: Timed out waiting for submitted
186
- at Timeout.eval (.../[eval1]:12:1, <anonymous>:7:45)
187
- at listOnTimeout (node:internal/timers:605:17)
188
- at process.processTimers (node:internal/timers:541:7)
189
- exit: 1 (expected)
190
- ```
191
-
192
- C2-E3 independently repeats the exact R2-E3 root-boundary command:
193
-
194
- ```text
195
- PASS: root REFRESH no bank -> loading; bound bank -> loaded; no requests
196
- exit: 0
197
- ```
198
-
199
- C2-E4: `git diff --check` produced no output. `shasum -a 256 src/machine/withdraw/withdraw_manual_cash.js test/withdraw_manual_cash.test.js` confirms the same reviewed product/test artifacts:
200
-
201
- ```text
202
- 13cfd851560c1b60c1bdf206d1c67d1db04d2f2db6652dde698659a34ec391f9 src/machine/withdraw/withdraw_manual_cash.js
203
- fecacc81d718bc118f791d125768c0ee0204d89b9d3762d0ca15c45725c29268 test/withdraw_manual_cash.test.js
204
- ```
205
-
206
- `ps -eo pid,rss,command` was denied (`operation not permitted`). No server or background process was started; each Node tool call returned an exit status. No product file was changed by any probe.
207
-
208
- ### Historical r1 evidence
209
-
210
- These runs predate the r2 fix and preserve E1–E6 references in the append-only review log/notes. E5 records the original defect; current verification is R2-E1–E3 above.
211
-
212
- E1 command and raw output (final targeted run):
213
-
214
- ```text
215
- $ node --test test/withdraw_manual_cash.test.js
216
- ✔ REFRESH in submitted re-runs loading and fetches the pending order again (4.575458ms)
217
- ✔ REFRESH in submitted returns to the form when no order is pending (0.872334ms)
218
- ✔ REFRESH in submitted keeps submitted with the updated order when one is still pending (1.584917ms)
219
- ✔ REFRESH in loaded with a bound bank is still ignored (23.343833ms)
220
- ℹ tests 4
221
- ℹ suites 0
222
- ℹ pass 4
223
- ℹ fail 0
224
- ℹ cancelled 0
225
- ℹ skipped 0
226
- ℹ todo 0
227
- ℹ duration_ms 119.1075
228
- exit: 0
229
- ```
230
-
231
- E2 exact read-only probe:
232
-
233
- ```sh
234
- node --input-type=module <<'NODE'
235
- import assert from 'node:assert/strict'
236
- import factory from './src/machine/withdraw/withdraw_manual_cash.js'
237
- const machine = factory({ send() { throw new Error('Pure transition check must not send requests') } })
238
- assert.equal(machine.transition('loaded', 'REFRESH').value, 'loading')
239
- const withBank = machine.withContext({ ...machine.context, userBanks: [{ bankCode: 'BANK' }] })
240
- assert.equal(withBank.transition('loaded', 'REFRESH').value, 'loaded')
241
- console.log('PASS: loaded + no bank -> loading; loaded + bound bank -> loaded (pure transitions, no network)')
242
- NODE
243
- ```
244
-
245
- ```text
246
- PASS: loaded + no bank -> loading; loaded + bound bank -> loaded (pure transitions, no network)
247
- exit: 0
248
- ```
249
-
250
- E3 exact negative-control command (the changed guard exists only in a new in-memory machine):
251
-
252
- ```sh
253
- node --input-type=module <<'NODE'
254
- import test from 'node:test'
255
- import assert from 'node:assert/strict'
256
- import { readFileSync } from 'node:fs'
257
- import { interpret } from 'xstate'
258
- import original from './src/machine/withdraw/withdraw_manual_cash.js'
259
- const suite = readFileSync('test/withdraw_manual_cash.test.js', 'utf8').replace(/^import .*\n/gm, '')
260
- const mutant = (...args) => original(...args).withConfig({ guards: { hasNoBank: () => true } })
261
- console.log('NEGATIVE CONTROL ONLY: force hasNoBank=true in memory; repository files are unchanged')
262
- new Function('test', 'assert', 'interpret', 'withdrawManualCash', suite)(test, assert, interpret, mutant)
263
- NODE
264
- ```
265
-
266
- ```text
267
- NEGATIVE CONTROL ONLY: force hasNoBank=true in memory; repository files are unchanged
268
- ✔ REFRESH in submitted re-runs loading and fetches the pending order again (4.814583ms)
269
- ✔ REFRESH in submitted returns to the form when no order is pending (1.313709ms)
270
- ✔ REFRESH in submitted keeps submitted with the updated order when one is still pending (1.213916ms)
271
- ✖ REFRESH in loaded with a bound bank is still ignored (1.107ms)
272
- ℹ tests 4
273
- ℹ suites 0
274
- ℹ pass 3
275
- ℹ fail 1
276
- ℹ cancelled 0
277
- ℹ skipped 0
278
- ℹ todo 0
279
- ℹ duration_ms 11.370083
280
-
281
- ✖ failing tests:
282
-
283
- ✖ REFRESH in loaded with a bound bank is still ignored (1.107ms)
284
- AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
285
- false !== true
286
- at TestContext.eval (...[eval1]:9:1), <anonymous>:103:12)
287
- code: ERR_ASSERTION; actual: false; expected: true; operator: strictEqual
288
- exit: 1 (expected)
289
- ```
290
-
291
- The negative control corresponds to `test/withdraw_manual_cash.test.js:105`; in the evaluated copy, import removal and Function wrapping shift the displayed line number. No files needed restoration.
292
-
293
- E5 exact read-only convergence reproduction (local stub, no network or transaction):
294
-
295
- ```sh
296
- node --input-type=module <<'NODE'
297
- import assert from 'node:assert/strict'
298
- import { interpret } from 'xstate'
299
- import factory from './src/machine/withdraw/withdraw_manual_cash.js'
300
- const pending = { applyId: 'W-1', amount: 500 }
301
- let pendingCalls = 0
302
- const request = {
303
- async send({ url }) {
304
- if (url === 'payment/v2/getBindingPaymentInfo') return { bankList: [{ bankCode: 'BANK' }], ewalletList: [], cryptoList: [] }
305
- if (url === 'payment/v2/withdrawRule') return { enableWithdraw: true }
306
- if (url === 'payment/v2/pendingOrder') {
307
- if (++pendingCalls === 1) return [pending]
308
- throw { code: 'ERR_998' }
309
- }
310
- throw new Error(`Unexpected descriptor: ${url}`)
311
- },
312
- }
313
- const service = interpret(factory(request, {
314
- paymentDetail: [{ category: 'manual', transferType: 'withdraw', method: 'MANUAL', minimum: 100, maximum: 10000 }],
315
- })).start()
316
- async function waitFor(value) {
317
- for (let i = 0; i < 100; i++) {
318
- if (service.state.matches(value)) return
319
- await new Promise(resolve => setTimeout(resolve, 1))
320
- }
321
- throw new Error(`Did not reach ${value}: ${service.state.value}`)
322
- }
323
- try {
324
- await waitFor('submitted')
325
- service.send('REFRESH')
326
- await waitFor('loaded')
327
- assert.deepEqual(service.state.context.processing, pending)
328
- assert.equal(pendingCalls, 2)
329
- service.send('REFRESH')
330
- assert.equal(service.state.value, 'loaded')
331
- assert.equal(pendingCalls, 2)
332
- console.log('REPRODUCED: pendingOrder ERR_998 after submitted REFRESH -> loaded, stale processing W-1; bound-bank REFRESH retry ignored (2 calls).')
333
- } finally {
334
- service.stop()
335
- }
336
- NODE
337
- ```
338
-
339
- ```text
340
- REPRODUCED: pendingOrder ERR_998 after submitted REFRESH -> loaded, stale processing W-1; bound-bank REFRESH retry ignored (2 calls).
341
- exit: 0
342
- ```
343
-
344
- This run asserts the observed bad outcome to prove the counterexample. It does not claim that error recovery passed. The production Request path rethrows ERR_998 without errorHandler (`src/request/request.js:337–338`), matching the stub's rejection contract. No duplicate submission or rendered downstream outcome was tested.
345
-
346
- E6 command and raw output:
347
-
348
- ```text
349
- $ node --test test/withdraw_manual_cash.test.js
350
- ✔ REFRESH in submitted re-runs loading and fetches the pending order again (4.547083ms)
351
- ✔ REFRESH in submitted returns to the form when no order is pending (0.8585ms)
352
- ✔ REFRESH in submitted keeps submitted with the updated order when one is still pending (1.423208ms)
353
- ✔ REFRESH in loaded with a bound bank is still ignored (22.29425ms)
354
- ℹ tests 4
355
- ℹ suites 0
356
- ℹ pass 4
357
- ℹ fail 0
358
- ℹ cancelled 0
359
- ℹ skipped 0
360
- ℹ todo 0
361
- ℹ duration_ms 115.091791
362
- exit: 0
363
- ```
364
-
365
- ---
366
-
367
- ## Conditional Review Triggers
368
-
369
- | Trigger | Hit | Action |
370
- | ---------------------------------- | --- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
371
- | Stateful SDK error/retry selection | YES | Trace invoke rejection, guarded transition, context preservation, successful assignment/checking, handler precedence and root guard. No identity/storage/attribution/queue changes, so those sdk-state.md sections do not apply. |
372
- | Required SDK UI checks | NO | No SDK UI runtime; explicit user choice A. Rendered cash evidence is outside this repo review. |
373
-
374
- ---
375
-
376
- ## 📋 Spec Validation (Aligned with review-playbook)
377
-
378
- The driver restricts review inputs; no checklist or author analysis was read. Rows cite raw spec clauses and the explicit acceptance criteria rather than claim unseen checklist alignment. The fresh convergence check repeats the whole-change source review and C2-E1–C2-E3 checks independently.
379
-
380
- | Spec Item | Evidence (File/Line/Result) | Status |
381
- | ----------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
382
- | Confirmed — submitted REFRESH reloads pending order (spec-snapshot.md:76) | Handler :100 -> invoke :34 -> getPendingOrder :276; test :58-70 asserts loading and query 2; R2-E1. | PASS |
383
- | Confirmed — empty response returns form; remaining order updates pending (spec-snapshot.md:71), SDK state portion | setInitData :172-184 -> checking :44; tests :72-100 assert undefined processing/loaded and replacement W-2/submitted; R2-E1. | PASS |
384
- | Confirmed r2 — failure preserves Pending and permits bound-bank retry | onError :40 uses isProcessing :229-230 and skips assignment; test :106-121 proves retained W-1 and call 3; R2-E1/E2. F-r1-01 verified yes. | PASS |
385
- | Confirmed r2 — first-load failure preserves previous behavior | processing starts null at :21; fallback :40 -> loaded; test :123-133, R2-E1. | PASS |
386
- | Confirmed r2 regression — non-submitted root guard unchanged | Root :159 and hasNoBank :226-227 unchanged; test :135-149 and R2-E3. Other non-submitted states inspected only. | PASS |
387
- | Conditional SDK WebSocket filter relaxation (spec-snapshot.md:77) | src/machine/websocket.js:296-301 already forwards payment-info without a toast filter; no additional filter patch required on this static criterion. Real payload behavior is unverified. | PASS |
388
- | Full cash UI / WebSocket strict-ID / published-package integration | Outside SDK repo review; cash flow owns verification. | NOT RUN |
389
-
390
- ---
391
-
392
- ## 📋 Standards Checklist (Summary)
393
-
394
- | Category | Result | Notes |
395
- | ------------------- | ------- | ------------------------------------------------------------------------------------------------------------- |
396
- | XState v4 / context | PASS | Reuses isProcessing; rejection adds no assignment; successful onDone unchanged. |
397
- | Correctness | PASS | All selected whole-change SDK acceptance cases pass; F-r1-01 independently verified again during convergence. |
398
- | Security | NOT RUN | No wider security audit; no auth/request-boundary edits or remote requests. |
399
- | Performance | PASS | Static inspection: no new timer, loop or dependency; retries remain explicit REFRESH events. No benchmark. |
400
- | Project Conventions | PASS | Minimal guarded transition fits existing checking pattern; whitespace check passes. No formatter/lint run. |
401
-
402
- ## Conclusion
403
-
404
- The fresh r2 convergence reviewer independently checked the complete base-to-working-tree change before reading prior review records and found no additional product-code defect. F-r1-01 remains ACCEPT + verified in r2 yes. Targeted tests pass 6/6, the old-onError negative control fails exactly the new retry case as expected, and both root guard boundaries pass. The r2 Impact block now covers the whole change with one line for each of the three internal consumers. This independent review is complete within the assigned SDK scope. The driver must run check-review.sh and update STATE; this report does not declare loop convergence or readiness to publish.
405
-
406
- Limits: injected local ERR_998 responses exercise the real initializer but not transport/backend, cash rendering, real WebSocket payloads, published-package wiring, alternate wallet gates, OTP, exhaustive non-submitted events or other errors. No browser ran, so browser exceptions were not assessed. ps -eo pid,rss,command was denied (operation not permitted); no server/background process started, all Node commands exited. Only three assigned review files were written; STATE remains the driver's responsibility. Convergence pre-edit backups: /var/folders/s8/rjb4nddx2f1c_nl7p_wwz8kh0000gn/T/TI-16026-cuora-r2-convergence.iivyDMK8Pm/.
407
-
408
- **Overall Result:** PASS
@@ -1,44 +0,0 @@
1
- import storage from './storage.js'
2
- import { TOKEN_MAX_AGE } from './constant.js'
3
-
4
- // document.cookie 在受限的環境(sandbox iframe、停用 cookie)會直接拋錯:讀不到視為沒有,寫不進去就算了
5
- function read(name) {
6
- const prefix = `${name}=`
7
- try {
8
- const pair = document.cookie.split('; ').find((item) => item.startsWith(prefix))
9
- return pair ? decodeURIComponent(pair.slice(prefix.length)) || null : null
10
- } catch (error) {
11
- return null
12
- }
13
- }
14
-
15
- // 不帶 Domain:cookie 只屬於寫入它的網域,不跨子網域
16
- function write(name, value, maxAge) {
17
- try {
18
- const secure = location.protocol === 'https:' ? '; Secure' : ''
19
- document.cookie = `${name}=${encodeURIComponent(value)}; Path=/; Max-Age=${maxAge}; SameSite=Lax${secure}`
20
- } catch (error) {
21
- console.error(`Error writing cookie: ${error}`)
22
- }
23
- }
24
-
25
- export default function createTokenStore(key) {
26
- // token 原本存在 localStorage;改放 cookie 後不沿用舊值,殘留的一併清掉
27
- storage.remove(key)
28
-
29
- const store = {
30
- get: () => read(key),
31
- set(token) {
32
- if (token) write(key, token, TOKEN_MAX_AGE)
33
- else store.clear()
34
- },
35
- // 以現有的值重寫一次,讓存活時間重新起算
36
- extend() {
37
- const token = read(key)
38
- if (token) write(key, token, TOKEN_MAX_AGE)
39
- return token
40
- },
41
- clear: () => write(key, '', 0),
42
- }
43
- return store
44
- }
@@ -1,171 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
- import { registerHooks } from 'node:module'
4
- import { interpret } from 'xstate'
5
-
6
- // src/api/auth.js 以無副檔名的 'lodash/pickBy' 匯入(專案慣例,交由下游 bundler 解析),Node 原生 ESM 需補副檔名
7
- registerHooks({
8
- resolve: (specifier, context, nextResolve) => nextResolve(specifier === 'lodash/pickBy' ? 'lodash/pickBy.js' : specifier, context),
9
- })
10
-
11
- const store = new Map()
12
- globalThis.localStorage = {
13
- getItem: (k) => (store.has(k) ? store.get(k) : null),
14
- setItem: (k, v) => store.set(k, v),
15
- removeItem: (k) => store.delete(k),
16
- }
17
- globalThis.window = { atob: (value) => Buffer.from(value, 'base64').toString(), location: { search: '', protocol: 'https:' } }
18
-
19
- const { default: auth } = await import('../src/machine/auth.js')
20
-
21
- const TIMEOUT = { code: 'ERR_998', endpoint: 'self', isTimeout: true }
22
- const NETWORK = { code: 'ERR_998', endpoint: 'self' }
23
- // 不帶 rank:isNotInline 成立,inline 立即轉 login(多數帳號的實際路徑)
24
- const USER = { uid_site: 'u@test' }
25
- const INLINE_USER = { uid_site: 'u@test', rank: 1 }
26
- const siteConfig = Buffer.from(JSON.stringify({ loginMethods: {}, registerMethods: {}, dtVerify: false })).toString('base64')
27
-
28
- // selfResults 依序決定每一筆 /self 的結果(Error 物件以外視為成功回應);用完後一律成功
29
- function start({ token = null, selfResults = [] } = {}) {
30
- store.clear()
31
- const calls = { self: 0, logout: 0 }
32
- // auth machine 只經 Request 的 token API 讀寫 token(實作是 cookie),這裡以記憶體值代替
33
- const session = { token }
34
- const request = {
35
- config: { appSecret: 's', clientId: 'test' },
36
- getToken: () => session.token,
37
- setToken: (value) => {
38
- session.token = value || null
39
- },
40
- extendToken: () => session.token,
41
- removeToken: () => {
42
- session.token = null
43
- },
44
- async send(descriptor) {
45
- if (descriptor.url === 'getConfig') return { config: siteConfig }
46
- if (descriptor.url === 'login') return { token: 'token-new' }
47
- if (descriptor.url === 'logout') return void calls.logout++
48
- if (descriptor.url === 'self') {
49
- const result = calls.self < selfResults.length ? selfResults[calls.self] : USER
50
- calls.self++
51
- if (result.code) throw result
52
- return result
53
- }
54
- throw new Error(`Unexpected request: ${descriptor.url}`)
55
- },
56
- }
57
- const machine = auth(request)
58
- const visited = []
59
- const service = interpret(machine.withContext({ ...machine.context, tick: 5 }))
60
- service.onTransition((state) => visited.push(state.toStrings().at(-1)))
61
- service.start()
62
- return { service, calls, visited, session }
63
- }
64
-
65
- function waitFor(service, predicate) {
66
- return new Promise((resolve, reject) => {
67
- const timer = setTimeout(() => reject(new Error(`Timed out, state: ${JSON.stringify(service.state.value)}`)), 1000)
68
- const check = (state) => {
69
- if (!predicate(state)) return
70
- clearTimeout(timer)
71
- resolve(state)
72
- }
73
- service.onTransition(check)
74
- })
75
- }
76
-
77
- const count = (visited, name) => visited.filter((value) => value === name).length
78
-
79
- test('開站帶 token:/self 逾時不登出,重發到成功後完成登入', async () => {
80
- const { service, calls, visited, session } = start({ token: 'token-A', selfResults: [TIMEOUT, TIMEOUT] })
81
- try {
82
- await waitFor(service, (state) => state.matches('login.pending'))
83
- assert.equal(count(visited, 'leaving'), 0)
84
- assert.equal(count(visited, 'logout'), 0)
85
- assert.equal(calls.logout, 0)
86
- assert.equal(service.state.context.token, 'token-A')
87
- assert.deepEqual(service.state.context.userInfo, USER)
88
- assert.equal(session.token, 'token-A')
89
- } finally {
90
- service.stop()
91
- }
92
- })
93
-
94
- test('開站帶 token:一般 ERR_998(非逾時)維持原行為,走 leaving 登出', async () => {
95
- const { service, calls, visited, session } = start({ token: 'token-A', selfResults: [NETWORK] })
96
- try {
97
- await waitFor(service, (state) => state.matches('idle') && visited.includes('logoutFinish'))
98
- assert.equal(count(visited, 'leaving'), 1)
99
- assert.equal(calls.self, 1)
100
- assert.equal(session.token, null)
101
- } finally {
102
- service.stop()
103
- }
104
- })
105
-
106
- test('剛登入:/self 逾時改在 userInfoRetrying 重發,authenticated 只進入一次', async () => {
107
- const { service, calls, visited } = start({ selfResults: [TIMEOUT, TIMEOUT] })
108
- try {
109
- await waitFor(service, (state) => state.matches('idle'))
110
- service.send({ type: 'LOGIN_ID', data: { username: 'u', password: 'p' } })
111
- await waitFor(service, (state) => state.matches('otpChecking'))
112
- assert.equal(count(visited, 'authenticated'), 1)
113
- assert.equal(count(visited, 'userInfoRetrying'), 2)
114
- assert.equal(count(visited, 'leaving'), 0)
115
- assert.equal(calls.self, 3)
116
- assert.equal(service.state.context.token, 'token-new')
117
- assert.deepEqual(service.state.context.userInfo, USER)
118
- } finally {
119
- service.stop()
120
- }
121
- })
122
-
123
- test('剛登入:重發期間遇到非逾時錯誤仍走 leaving', async () => {
124
- const { service, visited } = start({ selfResults: [TIMEOUT, { code: 'ERR_A113' }] })
125
- try {
126
- await waitFor(service, (state) => state.matches('idle'))
127
- service.send({ type: 'LOGIN_ID', data: { username: 'u', password: 'p' } })
128
- await waitFor(service, (state) => visited.includes('logoutFinish') && state.matches('idle'))
129
- assert.equal(count(visited, 'userInfoRetrying'), 1)
130
- assert.equal(count(visited, 'leaving'), 1)
131
- } finally {
132
- service.stop()
133
- }
134
- })
135
-
136
- test('登入態輪詢:/self 逾時回 pending 等下一輪,不登出', async () => {
137
- // 第 1 筆 tokenAuthenticated、第 2 筆 checkDeviceTokenDone 成功;第 3、4 筆(checkDeviceTokenDone 後的輪詢)逾時
138
- const { service, calls, visited } = start({ token: 'token-A', selfResults: [USER, TIMEOUT, TIMEOUT, TIMEOUT] })
139
- try {
140
- await waitFor(service, () => calls.self >= 6)
141
- assert.equal(count(visited, 'leaving'), 0)
142
- assert.ok(service.state.matches('login'))
143
- assert.equal(service.state.context.token, 'token-A')
144
- assert.deepEqual(service.state.context.userInfo, USER)
145
- } finally {
146
- service.stop()
147
- }
148
- })
149
-
150
- test('登入態輪詢:驗證失敗(非逾時)維持原行為,走 leaving 登出', async () => {
151
- const { service, visited, session } = start({ token: 'token-A', selfResults: [USER, USER, { code: 'ERR_A113' }] })
152
- try {
153
- await waitFor(service, (state) => visited.includes('logoutFinish') && state.matches('idle'))
154
- assert.equal(count(visited, 'leaving'), 1)
155
- assert.equal(session.token, null)
156
- } finally {
157
- service.stop()
158
- }
159
- })
160
-
161
- test('inline 輪詢:/self 逾時回 pending 等下一輪,不登出', async () => {
162
- const { service, calls, visited } = start({ token: 'token-A', selfResults: [INLINE_USER, TIMEOUT, TIMEOUT, INLINE_USER, TIMEOUT] })
163
- try {
164
- await waitFor(service, () => calls.self >= 6)
165
- assert.equal(count(visited, 'leaving'), 0)
166
- assert.ok(visited.includes('inline.fetching'))
167
- assert.equal(service.state.context.token, 'token-A')
168
- } finally {
169
- service.stop()
170
- }
171
- })