Skip to content

Commit 59c163c

Browse files
authored
[unified_analytics] Add hostArch parameter to Event.flutterCommandResult (#2558)
## Description Adds an optional `hostArch` parameter to `Event.flutterCommandResult` in `package:unified_analytics`. This allows the Flutter CLI (and other tools using `flutterCommandResult`) to explicitly report the host CPU architecture rather than relying on inconsistent OS version string parsing heuristics (e.g. Flutter issue flutter/flutter#191765). ## Changes - Updated `Event.flutterCommandResult` in `lib/src/event.dart` with optional `String? hostArch`. - Added test coverage in `test/event_test.dart`. - Updated `CHANGELOG.md`.
1 parent 8108a7c commit 59c163c

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎pkgs/unified_analytics/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 8.0.18-wip
22

3+
- Added optional `hostArch` parameter to `Event.flutterCommandResult`.
34
- Added optional `pubspecHasFlutterSdk`, `pubspecEnvironmentSdk`, and
45
`pubspecDependencies` parameters to the `Event.dartCliCommandExecuted`
56
constructor.

‎pkgs/unified_analytics/lib/src/event.dart‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,18 +651,23 @@ final class Event {
651651
/// * [commandHasTerminal] - Boolean indicating if the flutter command ran
652652
/// with a terminal.
653653
///
654+
/// * [hostArch] - the host CPU architecture executing the command (e.g.,
655+
/// "x64", "arm64", "arm", "ia32", "riscv64").
656+
///
654657
/// * [maxRss] - maximum resident size for a given flutter command.
655658
Event.flutterCommandResult({
656659
required String commandPath,
657660
required String result,
658661
required bool commandHasTerminal,
662+
String? hostArch,
659663
int? maxRss,
660664
}) : this._(
661665
eventName: DashEvent.flutterCommandResult,
662666
eventData: {
663667
'commandPath': commandPath,
664668
'result': result,
665669
'commandHasTerminal': commandHasTerminal,
670+
'hostArch': ?hostArch,
666671
'maxRss': ?maxRss,
667672
},
668673
);

‎pkgs/unified_analytics/test/event_test.dart‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ void main() {
663663
commandPath: 'commandPath',
664664
result: 'result',
665665
commandHasTerminal: true,
666+
hostArch: 'arm64',
666667
maxRss: 123,
667668
);
668669

@@ -673,10 +674,33 @@ void main() {
673674
expect(constructedEvent.eventData['commandPath'], 'commandPath');
674675
expect(constructedEvent.eventData['result'], 'result');
675676
expect(constructedEvent.eventData['commandHasTerminal'], true);
677+
expect(constructedEvent.eventData['hostArch'], 'arm64');
676678
expect(constructedEvent.eventData['maxRss'], 123);
677-
expect(constructedEvent.eventData.length, 4);
679+
expect(constructedEvent.eventData.length, 5);
678680
});
679681

682+
test(
683+
'Event.flutterCommandResult constructed with optional values omitted',
684+
() {
685+
Event generateEvent() => Event.flutterCommandResult(
686+
commandPath: 'commandPath',
687+
result: 'result',
688+
commandHasTerminal: true,
689+
);
690+
691+
final constructedEvent = generateEvent();
692+
693+
expect(generateEvent, returnsNormally);
694+
expect(constructedEvent.eventName, DashEvent.flutterCommandResult);
695+
expect(constructedEvent.eventData['commandPath'], 'commandPath');
696+
expect(constructedEvent.eventData['result'], 'result');
697+
expect(constructedEvent.eventData['commandHasTerminal'], true);
698+
expect(constructedEvent.eventData['hostArch'], isNull);
699+
expect(constructedEvent.eventData['maxRss'], isNull);
700+
expect(constructedEvent.eventData.length, 3);
701+
},
702+
);
703+
680704
test('Event.flutterWasmDryRunPackage constructed', () {
681705
Event generateEvent() => Event.flutterWasmDryRunPackage(
682706
result: 'success',

0 commit comments

Comments
 (0)