[PR #2509] [MERGED] fix(pcap): order evidence ties by code point instead of host locale #5285

Closed
opened 2026-10-31 01:05:26 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/2509
Author: @kaoru0822-kitauji
Created: 10/13/2026
Status: ✅ Merged
Merged: 10/13/2026
Merged by: @morluto

Base: main ← Head: fix/locale-independent-evidence-order


📝 Commits (1)

  • ad129c4 fix(pcap): order evidence ties by code point instead of host locale

📊 Changes

3 files changed (+24 additions, -4 deletions)

View changed files

📝 src/flutter/FlutterBuildProvider.ts (+3 -2)
📝 src/pcap/PcapOutput.test.ts (+18 -0)
📝 src/pcap/PcapOutput.ts (+3 -2)

📄 Description

Problem

inspect_pcap_capture breaks ties between equal-count endpoints and protocol stacks with String#localeCompare. Flutter build inspection sorts APK lib/<abi>/ directory names the same way. localeCompare follows the host's ICU default locale, which comes from LANG. The same capture can therefore produce differently ordered Evidence, with a different digest, depending on which host or shell ran REA:

$ for L in en_US da_DK lt_LT; do LANG=$L.UTF-8 LC_ALL=$L.UTF-8 node -e '…sort((x,y)=>x.localeCompare(y))'; done
en_US ["…:tcp:aarp","…:tcp:zz","…:udp:ssdp","…:udp:syslog","fe80::1","fe80:1::1"]
da_DK ["…:tcp:zz","…:tcp:aarp",…]            # Danish sorts "aa" as å, after z
lt_LT [… ,"…:udp:syslog","…:udp:ssdp", …]     # Lithuanian sorts y with i

Every locale also disagrees with code-point order on IPv6 text: it sorts fe80::1 before fe80:1::1. The other Evidence producers already use the locale-independent compareUnicodeCodePoints (src/domain/unicodeCodePointOrder.ts). These four calls were the only production uses of localeCompare.

Fix

The two pcap sorts and the two Flutter ABI sorts now use compareUnicodeCodePoints. Primary orderings are unchanged: packet count, and Flutter's ABI preference list. The usual Flutter ABIs (arm64-v8a, armeabi-v7a, x86, x86_64) sort the same either way.

Validation

  • New PcapOutput.test.ts case: equal-count fe80::1 and fe80:1::1 endpoints, plus eth:llc:zz and eth:llc:aarp protocols. It fails on main under any locale and passes with this change.
  • npm run test:focused passed for the pcap provider, retained-view, CLI and MCP tests and the Flutter boundary tests, except one pre-existing failure.
    • That failure is pcapProviderCrossPlatform.test.ts > rejects a path that is not a readable file. It fails the same way on clean main on macOS, because hosts without a native bound refuse before reading the path. It's unrelated to this change, and I'm fixing it in a separate PR.
  • npm run check:fast and format:check pass.
  • I didn't run a real TShark; it isn't installed on this macOS host. The change only affects the order of ties in the parsed fields.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Flutter ABI selection and network report sorting now use consistent code-point ordering, avoiding differences caused by host locale.
  • Tests
    • Added coverage for consistent ordering of equally ranked endpoints and protocols.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/2509 **Author:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Created:** 10/13/2026 **Status:** ✅ Merged **Merged:** 10/13/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `fix/locale-independent-evidence-order` --- ### 📝 Commits (1) - [`ad129c4`](https://github.com/morluto/rea/commit/ad129c49fa6493701f69fc18341dfe1b46d47902) fix(pcap): order evidence ties by code point instead of host locale ### 📊 Changes **3 files changed** (+24 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `src/flutter/FlutterBuildProvider.ts` (+3 -2) 📝 `src/pcap/PcapOutput.test.ts` (+18 -0) 📝 `src/pcap/PcapOutput.ts` (+3 -2) </details> ### 📄 Description ## Problem `inspect_pcap_capture` breaks ties between equal-count endpoints and protocol stacks with `String#localeCompare`. Flutter build inspection sorts APK `lib/<abi>/` directory names the same way. `localeCompare` follows the host's ICU default locale, which comes from `LANG`. The same capture can therefore produce differently ordered Evidence, with a different digest, depending on which host or shell ran REA: ```console $ for L in en_US da_DK lt_LT; do LANG=$L.UTF-8 LC_ALL=$L.UTF-8 node -e '…sort((x,y)=>x.localeCompare(y))'; done en_US ["…:tcp:aarp","…:tcp:zz","…:udp:ssdp","…:udp:syslog","fe80::1","fe80:1::1"] da_DK ["…:tcp:zz","…:tcp:aarp",…] # Danish sorts "aa" as å, after z lt_LT [… ,"…:udp:syslog","…:udp:ssdp", …] # Lithuanian sorts y with i ``` Every locale also disagrees with code-point order on IPv6 text: it sorts `fe80::1` before `fe80:1::1`. The other Evidence producers already use the locale-independent `compareUnicodeCodePoints` (`src/domain/unicodeCodePointOrder.ts`). These four calls were the only production uses of `localeCompare`. ## Fix The two pcap sorts and the two Flutter ABI sorts now use `compareUnicodeCodePoints`. Primary orderings are unchanged: packet count, and Flutter's ABI preference list. The usual Flutter ABIs (`arm64-v8a`, `armeabi-v7a`, `x86`, `x86_64`) sort the same either way. ## Validation - New `PcapOutput.test.ts` case: equal-count `fe80::1` and `fe80:1::1` endpoints, plus `eth:llc:zz` and `eth:llc:aarp` protocols. It fails on main under any locale and passes with this change. - `npm run test:focused` passed for the pcap provider, retained-view, CLI and MCP tests and the Flutter boundary tests, except one pre-existing failure. - That failure is `pcapProviderCrossPlatform.test.ts > rejects a path that is not a readable file`. It fails the same way on clean main on macOS, because hosts without a native bound refuse before reading the path. It's unrelated to this change, and I'm fixing it in a separate PR. - `npm run check:fast` and `format:check` pass. - I didn't run a real TShark; it isn't installed on this macOS host. The change only affects the order of ties in the parsed fields. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Flutter ABI selection and network report sorting now use consistent code-point ordering, avoiding differences caused by host locale. * **Tests** * Added coverage for consistent ordering of equally ranked endpoints and protocols. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:05:26 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#5285
No description provided.