ci(flutter): verify Windows builds on Forgejo #34

Merged
morrning merged 1 commit from Seyyed/Seyyed_arc:codex/windows-flutter-ci into master 2026-10-25 17:17:37 +03:30
6 changed files with 251 additions and 101 deletions

View file

@ -0,0 +1,62 @@
name: Flutter Windows
on:
pull_request:
paths:
- ".forgejo/workflows/flutter-windows.yml"
- "hesabixUI/hesabix_ui/**"
push:
branches:
- master
paths:
- ".forgejo/workflows/flutter-windows.yml"
- "hesabixUI/hesabix_ui/**"
workflow_dispatch:
concurrency:
group: flutter-windows-${{ forgejo.ref }}
cancel-in-progress: true
jobs:
verify-windows:
# The Forgejo repository must have an online Windows runner with this label.
runs-on: windows-latest
timeout-minutes: 45
defaults:
run:
working-directory: hesabixUI/hesabix_ui
shell: pwsh
steps:
- name: Check out source
uses: actions/checkout@v4
- name: Set up Flutter
uses: subosito/flutter-action@v2.23.0
with:
channel: stable
flutter-version: 3.47.2
- name: Resolve locked dependencies
run: flutter pub get
- name: Apply verified flutter_sound Windows patch
run: ./scripts/patch_flutter_sound_windows.ps1 -ProjectRoot $PWD.Path
- name: Analyze Dart sources
run: flutter analyze
- name: Run Flutter tests
run: flutter test
- name: Build Windows release bundle
run: flutter build windows --release --dart-define=API_BASE_URL=https://hsxn.hesabix.ir
- name: Verify Windows bundle
run: |
$bundle = "build/windows/x64/runner/Release"
if (-not (Test-Path -LiteralPath $bundle -PathType Container)) {
throw "Windows release bundle was not produced at $bundle"
}
if (-not (Get-ChildItem -LiteralPath $bundle -Filter "*.exe" -File)) {
throw "Windows release bundle does not contain an executable"
}

View file

@ -16,18 +16,25 @@ function Get-PackageRootFromConfig {
if (-not (Test-Path -LiteralPath $ConfigPath)) {
return $null
}
$raw = Get-Content -LiteralPath $ConfigPath -Raw -Encoding UTF8
$pattern = '"name"\s*:\s*"' + [regex]::Escape($PackageName) + '"\s*,\s*"rootUri"\s*:\s*"([^"]+)"'
$m = [regex]::Match($raw, $pattern)
if (-not $m.Success) {
$config = Get-Content -LiteralPath $ConfigPath -Raw -Encoding UTF8 | ConvertFrom-Json
$package = $config.packages | Where-Object { $_.name -eq $PackageName } | Select-Object -First 1
if (-not $package -or -not $package.rootUri) {
return $null
}
$uri = [System.Uri]$m.Groups[1].Value
$path = $uri.LocalPath
if ($path.StartsWith('/')) {
$path = $path.Substring(1)
$rootUri = [string]$package.rootUri
if ([System.Uri]::IsWellFormedUriString($rootUri, [System.UriKind]::Absolute)) {
$uri = [System.Uri]$rootUri
$path = [System.Uri]::UnescapeDataString($uri.LocalPath)
if ($path -match '^/[A-Za-z]:/') {
$path = $path.Substring(1)
}
return $path
}
return $path
return [System.IO.Path]::GetFullPath(
(Join-Path (Split-Path -Parent $ConfigPath) $rootUri)
)
}
function Apply-FlutterSoundWindowsPatch {
@ -39,12 +46,34 @@ function Apply-FlutterSoundWindowsPatch {
$cmakePatch = Join-Path $patchRoot "CMakeLists.txt"
$headerPatch = Join-Path $patchRoot "include\flutter_sound\flutter_sound_plugin_c_api.h"
foreach ($patchFile in @($cmakePatch, $headerPatch)) {
if (-not (Test-Path -LiteralPath $patchFile -PathType Leaf)) {
throw "Required flutter_sound patch file is missing: $patchFile"
}
}
$destWindows = Join-Path $PackageRoot "windows"
if (-not (Test-Path -LiteralPath $destWindows)) {
throw "flutter_sound has no windows/ folder at: $destWindows"
}
Copy-Item -LiteralPath $cmakePatch -Destination (Join-Path $destWindows "CMakeLists.txt") -Force
$destCmake = Join-Path $destWindows "CMakeLists.txt"
if (-not (Test-Path -LiteralPath $destCmake -PathType Leaf)) {
throw "flutter_sound CMakeLists.txt is missing: $destCmake"
}
$patchHash = (Get-FileHash -LiteralPath $cmakePatch -Algorithm SHA256).Hash
$destinationHash = (Get-FileHash -LiteralPath $destCmake -Algorithm SHA256).Hash
if ($patchHash -ne $destinationHash) {
$destinationText = Get-Content -LiteralPath $destCmake -Raw -Encoding UTF8
$knownUpstreamLayout =
$destinationText -match 'set\(PLUGIN_NAME\s+"taudio_plugin"\)' -and
$destinationText -match 'set\(taudio_bundled_libraries'
if (-not $knownUpstreamLayout) {
throw "Unsupported flutter_sound Windows CMake layout; refusing to overwrite $destCmake"
}
Copy-Item -LiteralPath $cmakePatch -Destination $destCmake -Force
}
$destHeaderDir = Join-Path $destWindows "include\flutter_sound"
New-Item -ItemType Directory -Path $destHeaderDir -Force | Out-Null
@ -72,13 +101,16 @@ if (-not $packageRoot -or -not (Test-Path -LiteralPath $packageRoot)) {
$lockPath = Join-Path $ProjectRoot "pubspec.lock"
$lockText = if (Test-Path -LiteralPath $lockPath) { Get-Content -LiteralPath $lockPath -Raw } else { "" }
if ($lockText -notmatch '(?s)flutter_sound:.*?version:\s*"([^"]+)"') {
Write-Host "[warn] Could not read flutter_sound version from pubspec.lock; applying patch anyway." -ForegroundColor Yellow
throw "Could not read flutter_sound version from pubspec.lock; refusing an unverified patch."
} else {
$ver = $Matches[1]
if ([version]$ver -lt [version]"9.29.0") {
Write-Host "[info] flutter_sound $ver (< 9.29): Windows desktop plugin patch not required." -ForegroundColor DarkGray
exit 0
}
if ([version]$ver -ge [version]"10.0.0") {
throw "flutter_sound $ver is outside the verified patch range (>=9.29.0,<10.0.0)."
}
}
Apply-FlutterSoundWindowsPatch -PackageRoot $packageRoot

View file

@ -5,34 +5,42 @@ import 'package:hesabix_ui/widgets/data_table/data_table_config.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('Column Settings Isolation Tests', () {
setUp(() {
SharedPreferences.setMockInitialValues({});
});
test('should have different settings for different tables', () async {
// Clear any existing settings
await ColumnSettingsService.clearColumnSettings('table1');
await ColumnSettingsService.clearColumnSettings('table2');
// Create different settings for two tables
final settings1 = ColumnSettings(
visibleColumns: ['id', 'name'],
columnOrder: ['name', 'id'],
columnWidths: {'name': 200.0},
);
final settings2 = ColumnSettings(
visibleColumns: ['id', 'email', 'createdAt'],
columnOrder: ['id', 'createdAt', 'email'],
columnWidths: {'email': 300.0, 'createdAt': 150.0},
);
// Save settings for both tables
await ColumnSettingsService.saveColumnSettings('table1', settings1);
await ColumnSettingsService.saveColumnSettings('table2', settings2);
// Retrieve settings
final retrieved1 = await ColumnSettingsService.getColumnSettings('table1');
final retrieved2 = await ColumnSettingsService.getColumnSettings('table2');
final retrieved1 = await ColumnSettingsService.getColumnSettings(
'table1',
);
final retrieved2 = await ColumnSettingsService.getColumnSettings(
'table2',
);
// Verify they are different
expect(retrieved1, isNotNull);
expect(retrieved2, isNotNull);
@ -41,7 +49,10 @@ void main() {
expect(retrieved1.columnOrder, equals(['name', 'id']));
expect(retrieved2.columnOrder, equals(['id', 'createdAt', 'email']));
expect(retrieved1.columnWidths, equals({'name': 200.0}));
expect(retrieved2.columnWidths, equals({'email': 300.0, 'createdAt': 150.0}));
expect(
retrieved2.columnWidths,
equals({'email': 300.0, 'createdAt': 150.0}),
);
});
test('should generate unique table IDs from endpoints', () {
@ -50,21 +61,21 @@ void main() {
endpoint: '/api/users',
columns: [],
);
final config2 = DataTableConfig<String>(
endpoint: '/api/orders',
columns: [],
);
final config3 = DataTableConfig<String>(
endpoint: '/api/products',
columns: [],
);
expect(config1.effectiveTableId, equals('_api_users'));
expect(config2.effectiveTableId, equals('_api_orders'));
expect(config3.effectiveTableId, equals('_api_products'));
// All should be different
expect(config1.effectiveTableId, isNot(equals(config2.effectiveTableId)));
expect(config2.effectiveTableId, isNot(equals(config3.effectiveTableId)));
@ -77,13 +88,13 @@ void main() {
tableId: 'custom_users_table',
columns: [],
);
final config2 = DataTableConfig<String>(
endpoint: '/api/users', // Same endpoint
tableId: 'custom_orders_table', // Different tableId
columns: [],
);
expect(config1.effectiveTableId, equals('custom_users_table'));
expect(config2.effectiveTableId, equals('custom_orders_table'));
expect(config1.effectiveTableId, isNot(equals(config2.effectiveTableId)));
@ -94,12 +105,12 @@ void main() {
endpoint: '/api/v1/users?active=true',
columns: [],
);
final config2 = DataTableConfig<String>(
endpoint: '/api/v2/users?active=false',
columns: [],
);
// Special characters should be replaced with underscores
expect(config1.effectiveTableId, equals('_api_v1_users_active_true'));
expect(config2.effectiveTableId, equals('_api_v2_users_active_false'));
@ -111,20 +122,22 @@ void main() {
final prefs = await SharedPreferences.getInstance();
await prefs.setString('user_preferences', 'some_value');
await prefs.setString('theme_settings', 'dark_mode');
// Save column settings
final settings = ColumnSettings(
visibleColumns: ['id', 'name'],
columnOrder: ['name', 'id'],
);
await ColumnSettingsService.saveColumnSettings('test_table', settings);
// Verify app data is still intact
expect(prefs.getString('user_preferences'), equals('some_value'));
expect(prefs.getString('theme_settings'), equals('dark_mode'));
// Verify column settings are saved
final retrieved = await ColumnSettingsService.getColumnSettings('test_table');
final retrieved = await ColumnSettingsService.getColumnSettings(
'test_table',
);
expect(retrieved, isNotNull);
expect(retrieved!.visibleColumns, equals(['id', 'name']));
});

View file

@ -6,31 +6,40 @@ void main() {
test('should create default settings from column keys', () {
final columnKeys = ['id', 'name', 'email', 'createdAt'];
final settings = ColumnSettingsService.getDefaultSettings(columnKeys);
expect(settings.visibleColumns, equals(columnKeys));
expect(settings.columnOrder, equals(columnKeys));
expect(settings.columnWidths, isEmpty);
});
test('should merge user settings with defaults correctly', () {
test('should expose newly available default columns', () {
final defaultKeys = ['id', 'name', 'email', 'createdAt', 'updatedAt'];
final userSettings = ColumnSettings(
visibleColumns: ['id', 'name', 'email'],
columnOrder: ['name', 'id', 'email'],
columnWidths: {'name': 200.0},
);
final merged = ColumnSettingsService.mergeWithDefaults(userSettings, defaultKeys);
expect(merged.visibleColumns, equals(['id', 'name', 'email']));
expect(merged.columnOrder, equals(['name', 'id', 'email']));
final merged = ColumnSettingsService.mergeWithDefaults(
userSettings,
defaultKeys,
);
expect(
merged.visibleColumns,
equals(['id', 'name', 'email', 'createdAt', 'updatedAt']),
);
expect(
merged.columnOrder,
equals(['name', 'id', 'email', 'createdAt', 'updatedAt']),
);
expect(merged.columnWidths, equals({'name': 200.0}));
});
test('should handle null user settings', () {
final defaultKeys = ['id', 'name', 'email'];
final merged = ColumnSettingsService.mergeWithDefaults(null, defaultKeys);
expect(merged.visibleColumns, equals(defaultKeys));
expect(merged.columnOrder, equals(defaultKeys));
expect(merged.columnWidths, isEmpty);
@ -43,9 +52,12 @@ void main() {
columnOrder: ['name', 'invalidColumn', 'id', 'email'],
columnWidths: {'name': 200.0, 'invalidColumn': 150.0},
);
final merged = ColumnSettingsService.mergeWithDefaults(userSettings, defaultKeys);
final merged = ColumnSettingsService.mergeWithDefaults(
userSettings,
defaultKeys,
);
expect(merged.visibleColumns, equals(['id', 'name', 'email']));
expect(merged.columnOrder, equals(['name', 'id', 'email']));
expect(merged.columnWidths, equals({'name': 200.0}));
@ -59,10 +71,10 @@ void main() {
columnOrder: ['name', 'id', 'email'],
columnWidths: {'name': 200.0, 'email': 150.0},
);
final json = original.toJson();
final restored = ColumnSettings.fromJson(json);
expect(restored.visibleColumns, equals(original.visibleColumns));
expect(restored.columnOrder, equals(original.columnOrder));
expect(restored.columnWidths, equals(original.columnWidths));
@ -74,12 +86,12 @@ void main() {
columnOrder: ['name', 'id'],
columnWidths: {'name': 200.0},
);
final copied = original.copyWith(
visibleColumns: ['id', 'name', 'email'],
columnWidths: {'name': 250.0, 'email': 150.0},
);
expect(copied.visibleColumns, equals(['id', 'name', 'email']));
expect(copied.columnOrder, equals(['name', 'id'])); // unchanged
expect(copied.columnWidths, equals({'name': 250.0, 'email': 150.0}));

View file

@ -10,29 +10,44 @@ void main() {
columnOrder: [],
columnWidths: {},
);
final merged = ColumnSettingsService.mergeWithDefaults(userSettings, defaultKeys);
final merged = ColumnSettingsService.mergeWithDefaults(
userSettings,
defaultKeys,
);
// Should have at least one column visible
expect(merged.visibleColumns, isNotEmpty);
expect(merged.visibleColumns.length, greaterThanOrEqualTo(1));
expect(merged.visibleColumns.first, equals('id')); // First column should be visible
expect(
merged.visibleColumns.first,
equals('id'),
); // First column should be visible
});
test('should preserve existing visible columns', () {
final defaultKeys = ['id', 'name', 'email', 'createdAt'];
final userSettings = ColumnSettings(
visibleColumns: ['name', 'email'], // Some columns visible
columnOrder: ['name', 'email'],
columnWidths: {'name': 200.0},
);
final merged = ColumnSettingsService.mergeWithDefaults(userSettings, defaultKeys);
expect(merged.visibleColumns, equals(['name', 'email']));
expect(merged.columnOrder, equals(['name', 'email']));
expect(merged.columnWidths, equals({'name': 200.0}));
});
test(
'should preserve existing columns and expose newly available columns',
() {
final defaultKeys = ['id', 'name', 'email', 'createdAt'];
final userSettings = ColumnSettings(
visibleColumns: ['name', 'email'], // Some columns visible
columnOrder: ['name', 'email'],
columnWidths: {'name': 200.0},
);
final merged = ColumnSettingsService.mergeWithDefaults(
userSettings,
defaultKeys,
);
expect(merged.visibleColumns, equals(defaultKeys));
expect(
merged.columnOrder,
equals(['name', 'email', 'id', 'createdAt']),
);
expect(merged.columnWidths, equals({'name': 200.0}));
},
);
test('should handle empty default keys gracefully', () {
final defaultKeys = <String>[];
@ -41,9 +56,12 @@ void main() {
columnOrder: [],
columnWidths: {},
);
final merged = ColumnSettingsService.mergeWithDefaults(userSettings, defaultKeys);
final merged = ColumnSettingsService.mergeWithDefaults(
userSettings,
defaultKeys,
);
// Should return empty settings when no default keys
expect(merged.visibleColumns, isEmpty);
expect(merged.columnOrder, isEmpty);
@ -57,30 +75,37 @@ void main() {
columnOrder: ['invalid1', 'invalid2'],
columnWidths: {'invalid1': 200.0, 'name': 150.0},
);
final merged = ColumnSettingsService.mergeWithDefaults(userSettings, defaultKeys);
// Should have at least one valid column visible
expect(merged.visibleColumns, isNotEmpty);
expect(merged.visibleColumns.length, greaterThanOrEqualTo(1));
expect(merged.visibleColumns.first, equals('id')); // First valid column
// Should filter out invalid column widths (name is not in visible columns)
expect(merged.columnWidths, isEmpty);
final merged = ColumnSettingsService.mergeWithDefaults(
userSettings,
defaultKeys,
);
// Invalid saved columns are discarded; newly available defaults are shown.
expect(merged.visibleColumns, equals(defaultKeys));
expect(merged.columnOrder, equals(defaultKeys));
expect(merged.columnWidths, equals({'name': 150.0}));
});
test('should maintain column order when adding missing columns', () {
final defaultKeys = ['id', 'name', 'email', 'createdAt'];
final userSettings = ColumnSettings(
visibleColumns: ['name', 'email'],
columnOrder: ['name', 'email', 'id'], // 'id' is not in visible but in order
columnOrder: [
'name',
'email',
'id',
], // 'id' is not in visible but in order
columnWidths: {},
);
final merged = ColumnSettingsService.mergeWithDefaults(userSettings, defaultKeys);
expect(merged.visibleColumns, equals(['name', 'email']));
expect(merged.columnOrder, equals(['name', 'email'])); // Should filter out 'id'
final merged = ColumnSettingsService.mergeWithDefaults(
userSettings,
defaultKeys,
);
expect(merged.visibleColumns, equals(defaultKeys));
expect(merged.columnOrder, equals(['name', 'email', 'id', 'createdAt']));
});
});
}

View file

@ -7,24 +7,30 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hesabix_ui/main.dart';
import 'package:hesabix_ui/l10n/app_localizations.dart';
import 'package:hesabix_ui/widgets/progress_splash_screen.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
testWidgets(
'progress splash renders without starting network initialization',
(WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: ProgressSplashScreen(
message: 'Loading',
progress: 0.5,
currentStep: 2,
totalSteps: 4,
),
),
);
await tester.pumpAndSettle();
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
expect(find.byType(MaterialApp), findsOneWidget);
expect(find.byType(ProgressSplashScreen), findsOneWidget);
expect(find.text('Loading'), findsOneWidget);
},
);
}