Verify storage controls and provide isolated browser fixture

This commit is contained in:
2026-11-06 21:28:37 +00:00
parent c9e1124baa
commit 4f2c981a13
4 changed files with 398 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pipelines_app/features/settings/storage/storage_screen.dart';
import 'storage_probe_fixture.dart';
void main() {
final query = Uri.base.queryParameters;
final cupertino = query['platform'] == 'cupertino';
final dark = query['theme'] == 'dark';
final scale = double.tryParse(query['scale'] ?? '') ?? 1;
final screen = StorageScreen(
gateway: StorageProbeGateway()..unsupported = query['unsupported'] == '1',
);
Widget scaled(BuildContext context, Widget? child) => MediaQuery(
data: MediaQuery.of(context).copyWith(textScaler: TextScaler.linear(scale)),
child: child!,
);
runApp(
cupertino
? CupertinoApp(
theme: CupertinoThemeData(
brightness: dark ? Brightness.dark : Brightness.light,
),
builder: scaled,
home: screen,
)
: MaterialApp(
theme: ThemeData(
brightness: dark ? Brightness.dark : Brightness.light,
),
builder: scaled,
home: screen,
),
);
}
+105
View File
@@ -0,0 +1,105 @@
import 'package:pipelines_app/core/api_gateway.dart';
class StorageProbeGateway implements ApiGateway {
final calls = <({String type, JsonMap fields})>[];
JsonMap policy = {
'enabled': false,
'max_age_days': 30,
'max_bytes': 10737418240,
'include_worktrees': true,
};
bool unsupported = false;
@override
Stream<JsonMap> get frames => const Stream.empty();
JsonMap get overview => {
'measured_at': '2026-11-06T12:34:56Z',
'automatic_interval_seconds': 3600,
'total_bytes': 16106127360,
'partial': true,
'policy': policy,
'categories': [
{
'id': 'database',
'label': 'Database',
'bytes': 1073741824,
'files': 3,
'path': '/fixture/data/pipelines.db',
},
{
'id': 'artifacts',
'label': 'Run artifacts',
'bytes': 5368709120,
'files': 148,
'path': '/fixture/data/artifacts',
},
{
'id': 'worktrees',
'label': 'Worktrees',
'bytes': 9663676416,
'files': 10432,
'path': '/fixture/repos/worktrees',
},
],
'warnings': ['One inaccessible directory was excluded.'],
};
JsonMap get cleanup => {
'policy': policy,
'total_bytes': 16106127360,
'reclaimable_bytes': 3221225472,
'target_bytes': 10737418240,
'target_reached': false,
'candidate_count': 2,
'protected_count': 1,
'preview_token': 'fixture-preview-token',
'items': [
{
'kind': 'run',
'id': '42',
'bytes': 1073741824,
'reason': 'Older than retention age',
'protected': false,
},
{
'kind': 'worktree',
'id': 'completed-item',
'path': '/fixture/repos/worktrees/completed-item',
'bytes': 2147483648,
'reason': 'Clean and merged',
'protected': false,
},
{
'kind': 'worktree',
'id': 'active-item',
'bytes': 4294967296,
'reason': 'Active session',
'protected': true,
},
],
'applied': false,
};
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
calls.add((type: type, fields: fields));
if (unsupported) return {'error': 'Unknown command: get_storage'};
switch (type) {
case 'get_storage':
return {'storage': overview};
case 'set_storage_policy':
policy = Map<String, dynamic>.from(fields['storage_policy'] as Map);
return {'storage': overview};
case 'preview_storage_cleanup':
return {'storage_cleanup': cleanup};
case 'apply_storage_cleanup':
return {
'storage_cleanup': {
...cleanup,
'applied': true,
'removed_count': 1,
'removed_bytes': 1073741824,
'errors': ['Worktree became active and was kept.'],
},
};
}
return {};
}
}