From d37fafd2078f7f6225f186919d127a532e80cb8a Mon Sep 17 00:00:00 2001 From: Claude Code Date: Fri, 14 Aug 2026 18:28:07 +0300 Subject: [PATCH] test: POSIX-normalise paths in link_priority_structural_test These four tests fail on Windows and pass on CI, so the breakage is invisible to the project and costs every Windows contributor the same half hour. `Directory('lib').listSync()` returns NATIVE separators, so on Windows the collected keys are `lib\ble\ble_engine.dart` while every assertion in the file is written `lib/ble/ble_engine.dart`. Two failure shapes follow: Expected: a string starting with 'lib/ble/ble_engine.dart:' Actual: 'lib\ble\ble_engine.dart:781' and, worse, `_engine()`'s `.firstWhere((e) => e.key.endsWith('ble/ble_engine.dart'))` throws a bare "Bad state: No element" that names neither the file nor the cause. Normalised once where the paths are collected, rather than at each assertion: nothing this file pins is platform-specific, so the paths it reasons about should not be either, and the assertions keep reading as the single spelling they already use. Replacing `Platform.pathSeparator` rather than a literal backslash keeps it a no-op on POSIX instead of corrupting a filename that legally contains one. Behaviour is otherwise unchanged. Verified the test still bites: dropping a second `requestConnectionPriority` call into lib/ fails it as before, and the diagnostic now reads `[lib/_tmp_violation.dart:4, lib/ble/ble_engine.dart:797]` rather than a mix of separators. Before: 1 passed, 4 failed (Windows). After: 5 passed. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01RrVjCqVDMANK5sa5eyjATw --- test/link_priority_structural_test.dart | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/test/link_priority_structural_test.dart b/test/link_priority_structural_test.dart index f7205e5..290305b 100644 --- a/test/link_priority_structural_test.dart +++ b/test/link_priority_structural_test.dart @@ -59,7 +59,20 @@ List>> _libSources() { final out = >>[]; for (final entity in lib.listSync(recursive: true)) { if (entity is! File || !entity.path.endsWith('.dart')) continue; - out.add(MapEntry(entity.path, codeLines(entity.readAsStringSync()))); + // POSIX-normalise. Directory.listSync returns NATIVE separators, so on + // Windows every key here is `lib\ble\ble_engine.dart` while every assertion + // below is written `lib/ble/ble_engine.dart`. Nothing about what this file + // pins is platform-specific, so the paths it reasons about should not be + // either — normalising once here keeps the assertions readable as the + // single spelling they already use. + // + // Replacing Platform.pathSeparator rather than a literal backslash: on + // POSIX that is a no-op, whereas a blanket `\` replacement would corrupt + // the (legal, if perverse) filename that contains one. + out.add(MapEntry( + entity.path.replaceAll(Platform.pathSeparator, '/'), + codeLines(entity.readAsStringSync()), + )); } out.sort((a, b) => a.key.compareTo(b.key)); return out;