From 675a7d98b99575b9ccdd04aeece7ec3317b5732c Mon Sep 17 00:00:00 2001 From: rimtty Date: Tue, 8 Sep 2026 01:55:09 +0900 Subject: [PATCH] fix(scan-log): align the step value of verdict and session-end events across platforms The first real exports showed iOS logging session_end with the current step and Android logging match/mismatch/duplicate with the barcode step. Both now write session events with step none and verdicts with step result, as the shared schema intends. Refs #120 --- .../codematch/feature/scan/ScanSessionCoordinator.kt | 5 ++++- .../codematch/feature/scan/ScanSessionCoordinatorTest.kt | 2 +- ios/CodeMatch/Features/Scanner/ScannerViewModel.swift | 8 +++++--- ios/CodeMatchTests/BluetoothScannerFlowTests.swift | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/android/feature/scan/src/main/kotlin/jp/rimtty/codematch/feature/scan/ScanSessionCoordinator.kt b/android/feature/scan/src/main/kotlin/jp/rimtty/codematch/feature/scan/ScanSessionCoordinator.kt index cdfa11d..1f64d59 100644 --- a/android/feature/scan/src/main/kotlin/jp/rimtty/codematch/feature/scan/ScanSessionCoordinator.kt +++ b/android/feature/scan/src/main/kotlin/jp/rimtty/codematch/feature/scan/ScanSessionCoordinator.kt @@ -521,12 +521,13 @@ class ScanSessionCoordinator( barcodePayload: String? = null, code: String? = null, boxNumber: Int? = null, + stepOverride: String? = null, ) = recorder.record( ScanLogEvent( atEpochMillis = System.currentTimeMillis(), sessionId = null, source = source, - step = step, + step = stepOverride ?: step, event = event, reason = reason, destination = destination, @@ -578,6 +579,8 @@ class ScanSessionCoordinator( // verdicts still deserve the part number they were about. code = match?.code ?: recordedCode(scan.qrPayload, scan.barcodePayload), boxNumber = match?.boxNumber, + // The verdict belongs to the result step, as on iOS. + stepOverride = ScanLogStep.RESULT, ) } else if (previous.scan is ScanState.Result && reduction.effects.isEmpty()) { // The reducer deliberately swallows callbacks while a result is diff --git a/android/feature/scan/src/test/kotlin/jp/rimtty/codematch/feature/scan/ScanSessionCoordinatorTest.kt b/android/feature/scan/src/test/kotlin/jp/rimtty/codematch/feature/scan/ScanSessionCoordinatorTest.kt index 88708b5..d7a7625 100644 --- a/android/feature/scan/src/test/kotlin/jp/rimtty/codematch/feature/scan/ScanSessionCoordinatorTest.kt +++ b/android/feature/scan/src/test/kotlin/jp/rimtty/codematch/feature/scan/ScanSessionCoordinatorTest.kt @@ -681,7 +681,7 @@ class ScanSessionCoordinatorTest { assertNull(barcodeAccepted.qrPayload) val match = log.events[2] - assertEquals(ScanLogStep.BARCODE, match.step) + assertEquals(ScanLogStep.RESULT, match.step) assertEquals(qrPayload, match.qrPayload) assertEquals(barcodePayload, match.barcodePayload) assertEquals("BCJH-52-81GG", match.code) diff --git a/ios/CodeMatch/Features/Scanner/ScannerViewModel.swift b/ios/CodeMatch/Features/Scanner/ScannerViewModel.swift index d9b81c8..5692e67 100644 --- a/ios/CodeMatch/Features/Scanner/ScannerViewModel.swift +++ b/ios/CodeMatch/Features/Scanner/ScannerViewModel.swift @@ -360,7 +360,8 @@ final class ScannerViewModel: ObservableObject { cancelAutoAdvanceCountdown() guard !isEndingSession else { return } // アクティブセッションのidが残っているうちに記録する。 - log("session_end") + // セッション系のイベントは工程を持たない(Android と同じ `none`)。 + log("session_end", stepOverride: "none") isEndingSession = true scanLocked = true focusPoint = nil @@ -840,14 +841,15 @@ final class ScannerViewModel: ObservableObject { barcode: String? = nil, code: String? = nil, boxNumber: Int? = nil, - message: String? = nil + message: String? = nil, + stepOverride: String? = nil ) { scanLog.record( ScanLogEvent( at: Date(), session: historyStore.activeSession?.id, source: inputSource.scanLogValue, - step: step.scanLogValue, + step: stepOverride ?? step.scanLogValue, event: event, reason: reason, destination: destination?.rawValue, diff --git a/ios/CodeMatchTests/BluetoothScannerFlowTests.swift b/ios/CodeMatchTests/BluetoothScannerFlowTests.swift index abe2c28..fe7f285 100644 --- a/ios/CodeMatchTests/BluetoothScannerFlowTests.swift +++ b/ios/CodeMatchTests/BluetoothScannerFlowTests.swift @@ -1575,7 +1575,7 @@ final class BluetoothScannerFlowTests: XCTestCase { let events = loggedEvents(context.scanLog) XCTAssertEqual(events.map(\.event), ["session_end"]) XCTAssertEqual(events[0].session, sessionID) - XCTAssertEqual(events[0].step, "qr") + XCTAssertEqual(events[0].step, "none") XCTAssertEqual(events[0].source, "camera") }