fix(train): only the firmware version the person agreed to is written (ADR 0030, D55)
Relayed by the instance, the version asked again before downloading was written even where it wasn't the one shown and agreed to, and the band recorded as at the agreed one. Another version now writes nothing and is offered instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
c8f16686ec
commit
ac6cff179f
2 changed files with 28 additions and 0 deletions
|
|
@ -297,6 +297,14 @@ class PolarLoop(
|
|||
_update(_with(_status.loop!.copyWith(firmwareOffered: () => null)));
|
||||
throw const LoopFailed('no update');
|
||||
}
|
||||
// Only the version the person agreed to is written: another one
|
||||
// offered since is offered to them instead.
|
||||
if (offered != version) {
|
||||
_update(
|
||||
_with(_status.loop!.copyWith(firmwareOffered: () => offered)),
|
||||
);
|
||||
throw const LoopFailed('another update');
|
||||
}
|
||||
final bytes = await _relayed(
|
||||
() =>
|
||||
relay.download(hardwareCode: info.hardwareCode, version: offered),
|
||||
|
|
|
|||
|
|
@ -583,6 +583,26 @@ void main() {
|
|||
expect(File('${folder.path}/loop_firmware.zip').existsSync(), isFalse);
|
||||
});
|
||||
|
||||
test('through the instance, another version than the one agreed to is '
|
||||
'never written: it is offered instead', () async {
|
||||
final relay = FakeFirmwareRelay()..version = '2.1.0';
|
||||
final loop = await setUpBand(relay: relay);
|
||||
loop.setFirmwareVia(FirmwareVia.instance);
|
||||
await loop.checkFirmware();
|
||||
relay.version = '2.2.0';
|
||||
platform.calls.clear();
|
||||
|
||||
await expectLater(loop.updateFirmware(), throwsA(isA<LoopFailed>()));
|
||||
|
||||
expect(relay.downloaded, isEmpty);
|
||||
expect(
|
||||
platform.calls.where((c) => c.startsWith('updateFirmware')),
|
||||
isEmpty,
|
||||
);
|
||||
expect(store().read()?.firmwareOffered, '2.2.0');
|
||||
expect(store().read()?.firmware, isNot('2.2.0'));
|
||||
});
|
||||
|
||||
test('a read failing leaves the band untouched', () async {
|
||||
platform.firmwareOffered = '2.1.0';
|
||||
final loop = await setUpBand();
|
||||
|
|
|
|||
Loading…
Reference in a new issue