Verify storage controls and provide isolated browser fixture
This commit is contained in:
@@ -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 {};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user