Skip to content

Commit 2148f7e

Browse files
committed
fix(uddf): trim mixRef + order-independent tank lookup in test
Addresses Copilot review feedback on PR #253: - tankdata mixRef is now trimmed before being stored as uddfGasMixRef, so whitespace-only refs don't become non-resolvable identifiers downstream. - waypoint <switchmix ref> is trimmed and skipped when empty, so gasSwitches entries the importer couldn't resolve to a tank are never emitted. - Integration test identifies tanks by o2Percent (32% bottom / 80% deco) instead of relying on SQLite/Drift row order, removing cross-version flakiness.
1 parent d6c042f commit 2148f7e

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

lib/core/services/export/uddf/uddf_full_import_service.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,14 +1372,13 @@ class UddfFullImportService {
13721372
// Get linked gas mix
13731373
final mixLink = tankDataElement.findElements('link').firstOrNull;
13741374
if (mixLink != null) {
1375-
final mixRef = mixLink.getAttribute('ref');
1376-
if (mixRef != null) {
1375+
final rawMixRef = mixLink.getAttribute('ref');
1376+
final mixRef = rawMixRef?.trim();
1377+
if (mixRef != null && mixRef.isNotEmpty) {
13771378
// Record the UDDF gas-mix UUID on the tank so the importer can
13781379
// resolve waypoint-level <switchmix ref> markers (which reference
13791380
// gas mixes, not tanks) back to a tank for the gas_switches row.
1380-
if (mixRef.isNotEmpty) {
1381-
tankInfo['uddfGasMixRef'] = mixRef;
1382-
}
1381+
tankInfo['uddfGasMixRef'] = mixRef;
13831382
if (gasMixes.containsKey(mixRef)) {
13841383
tankInfo['gasMix'] = gasMixes[mixRef];
13851384
}
@@ -1576,8 +1575,12 @@ class UddfFullImportService {
15761575

15771576
final switchMix = waypoint.findElements('switchmix').firstOrNull;
15781577
if (switchMix != null) {
1579-
final mixRef = switchMix.getAttribute('ref');
1580-
if (mixRef != null) {
1578+
final rawMixRef = switchMix.getAttribute('ref');
1579+
final mixRef = rawMixRef?.trim();
1580+
// Skip emission entirely when the ref is empty or whitespace-only:
1581+
// the importer would have no way to resolve such a dangling ref
1582+
// back to a persisted tank row.
1583+
if (mixRef != null && mixRef.isNotEmpty) {
15811584
// Emit a gas switch entry for the importer to persist. Shape
15821585
// matches the top-level <gasswitches> parser (timestamp/depth/
15831586
// tankRef), plus `gasMixRef` so the importer can resolve the

test/features/dive_import/macdive_waypoint_gas_switch_test.dart

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,22 +166,27 @@ void main() {
166166
reason: 'expected one gas_switches row per <switchmix ref>',
167167
);
168168

169-
// Tanks are imported in UDDF order; tank[0] = bottom gas, tank[1] = deco.
170-
// Importer preserves tank order from the parsed `tanks` list.
171-
final bottomTankId = diveTanks[0].id;
172-
final decoTankId = diveTanks[1].id;
169+
// Identify tanks by o2Percent rather than relying on row insertion
170+
// order: SQLite/Drift do not guarantee `select(...).get()` ordering
171+
// without an explicit ORDER BY, so positional indexing is flaky
172+
// across engine versions. The synthetic UDDF uses 32% for the
173+
// bottom mix and 80% for the deco mix, which are unambiguous.
174+
final bottomTankId = diveTanks.firstWhere((t) => t.o2Percent == 32).id;
175+
final decoTankId = diveTanks.firstWhere((t) => t.o2Percent == 80).id;
173176

174177
final byTimestamp = {for (final gs in switches) gs.timestamp: gs};
175178
expect(byTimestamp.keys, containsAll(<int>[0, 2400]));
176179
expect(
177180
byTimestamp[0]!.tankId,
178181
bottomTankId,
179-
reason: 'waypoint 0s switch to mix-bottom should land on tank[0]',
182+
reason:
183+
'waypoint 0s switch to mix-bottom should land on the 32% tank',
180184
);
181185
expect(
182186
byTimestamp[2400]!.tankId,
183187
decoTankId,
184-
reason: 'waypoint 2400s switch to mix-deco should land on tank[1]',
188+
reason:
189+
'waypoint 2400s switch to mix-deco should land on the 80% tank',
185190
);
186191
expect(byTimestamp[2400]!.depth, 6.0);
187192
},

0 commit comments

Comments
 (0)