Files
pipelines/app/tool/artifact_gallery_probe.dart
alan b60ad6d98f Remove alternate hosts from tooling probes
Keep the probe suite on the Material composition so browser fixtures and capture drivers no longer render or select Cupertino hosts. Record the final residual legacy arguments and implementation checks for the delivery gate.
2026-11-11 21:38:30 +00:00

364 lines
9.5 KiB
Dart

// Standalone fixture entry for real-browser run-detail Artifacts evidence.
//
// Build and probe (from app/):
// flutter build web --target tool/artifact_gallery_probe.dart --output build/probe-gallery
// node tool/artifact_gallery_probe.mjs --root build/probe-gallery --out DIR
//
// Server-shaped fixtures only: a fake gateway answers the same get_run envelope
// the app consumes. The recorded urls point at the probe's own loopback origin,
// so the external Open action has a real target. No server or operator run is
// touched.
import 'package:flutter/material.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/artifacts/ui/artifact_gallery_page.dart';
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_view.dart';
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
class _FakeGateway implements ApiGateway {
_FakeGateway(this.detail);
final JsonMap detail;
@override
Stream<JsonMap> get frames => const Stream<JsonMap>.empty();
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type != 'get_run') throw UnsupportedError(type);
return Future.value({'run_detail': detail});
}
}
JsonMap _file(
String name, {
required String url,
required String contentType,
required int sizeBytes,
}) => <String, dynamic>{
'name': name,
'url': url,
'content_type': contentType,
'size_bytes': sizeBytes,
};
/// The recorded steps for one probe state. `default` carries two visits that
/// both record `result.zip` plus a partial capture on the second visit.
List<JsonMap> _steps(String origin, String state) {
if (state == 'unavailable') {
return <JsonMap>[
<String, dynamic>{
'stage': 'implementer',
'sequence': 1,
'status': 'completed',
'control': <String, dynamic>{'visit': 1},
},
];
}
if (state == 'empty') {
return <JsonMap>[
<String, dynamic>{
'stage': 'implementer',
'sequence': 1,
'status': 'completed',
'control': <String, dynamic>{'visit': 1},
'artifacts': const <JsonMap>[],
},
];
}
if (state == 'unsafe' || state == 'nourl') {
return <JsonMap>[
<String, dynamic>{
'stage': 'reviewer',
'sequence': 1,
'status': 'completed',
'control': <String, dynamic>{'visit': 1},
'artifacts': [
_file(
'result.zip',
url: state == 'unsafe' ? '//evil.test/result.zip' : '',
contentType: 'application/zip',
sizeBytes: 2048,
),
],
},
];
}
if (state == 'missing') {
return <JsonMap>[
<String, dynamic>{
'stage': 'reviewer',
'sequence': 1,
'status': 'completed',
'control': <String, dynamic>{'visit': 1},
'artifacts': [
_file(
'missing.png',
url: '$origin/fixture/missing.png',
contentType: 'image/png',
sizeBytes: 128,
),
],
},
];
}
if (state == 'external') {
return <JsonMap>[
<String, dynamic>{
'stage': 'reviewer',
'sequence': 1,
'status': 'completed',
'control': <String, dynamic>{'visit': 1},
'artifacts': [
_file(
'elsewhere.png',
url: 'https://elsewhere.test/elsewhere.png',
contentType: 'image/png',
sizeBytes: 4096,
),
],
},
];
}
if (state == 'documents') {
return <JsonMap>[
<String, dynamic>{
'stage': 'reviewer',
'sequence': 1,
'status': 'completed',
'control': <String, dynamic>{'visit': 1},
'artifacts': [
_file(
'report.zip',
url: '$origin/fixture/report.zip',
contentType: 'application/zip',
sizeBytes: 23,
),
_file(
'input.md',
url: '$origin/fixture/input.md',
contentType: 'text/markdown',
sizeBytes: 120,
),
_file(
'output.md',
url: '$origin/fixture/output.md',
contentType: 'text/markdown',
sizeBytes: 240,
),
// Deliberately sniffed as text/plain: the session export must still
// stay external-only.
_file(
'session.html',
url: '$origin/fixture/session.html',
contentType: 'text/plain',
sizeBytes: 512,
),
],
},
<String, dynamic>{
'stage': 'reviewer',
'sequence': 2,
'status': 'completed',
'control': <String, dynamic>{'visit': 2},
'artifacts': [
_file(
'input.md',
url: '$origin/fixture/input-2.md',
contentType: 'text/markdown',
sizeBytes: 130,
),
_file(
'memory.md',
url: '$origin/fixture/memory.md',
contentType: 'text/markdown',
sizeBytes: 256,
),
],
},
];
}
if (state == 'files') {
return <JsonMap>[
<String, dynamic>{
'stage': 'reviewer',
'sequence': 1,
'status': 'completed',
'control': <String, dynamic>{'visit': 1},
'artifacts': [
_file(
'report.zip',
url: '$origin/fixture/report.zip',
contentType: 'application/zip',
sizeBytes: 23,
),
],
},
];
}
return <JsonMap>[
<String, dynamic>{
'stage': 'implementer',
'sequence': 1,
'status': 'completed',
'control': <String, dynamic>{'visit': 1},
'artifacts': [
_file(
'build.log',
url: '$origin/fixture/build.log',
contentType: 'text/plain; charset=utf-8',
sizeBytes: 2337,
),
_file(
'notes.txt',
url: '$origin/fixture/notes.txt',
contentType: 'text/plain',
sizeBytes: 2337,
),
],
},
<String, dynamic>{
'stage': 'reviewer',
'sequence': 2,
'status': 'completed',
'control': <String, dynamic>{'visit': 1},
'artifacts': [
_file(
'result.zip',
url: '$origin/fixture/result.zip',
contentType: 'application/zip',
sizeBytes: 2048,
),
_file(
'shot.png',
url: '$origin/fixture/shot.png',
contentType: 'image/png',
sizeBytes: 80544,
),
_file(
'clip.mp4',
url: '$origin/fixture/clip.mp4',
contentType: 'video/mp4',
sizeBytes: 40544,
),
],
},
<String, dynamic>{
'stage': 'reviewer',
'sequence': 3,
'status': 'completed',
'control': <String, dynamic>{'visit': 2},
'artifacts': [
_file(
'result.zip',
url: '$origin/fixture/result-2.zip',
contentType: 'application/zip',
sizeBytes: 4096,
),
],
'artifacts_skipped': 2,
},
];
}
JsonMap _run(String origin, String state) => <String, dynamic>{
'id': 31,
'title': 'Artifacts gallery probe',
'name': 'gallery',
'status': 'succeeded',
'steps': _steps(origin, state),
};
void main() {
final params = Uri.base.queryParameters;
final theme = params['theme'] == 'dark' ? Brightness.dark : Brightness.light;
final origin = params['origin'] ?? 'https://artifacts.invalid';
final state = params['state'] ?? 'default';
final gallery = params['view'] == 'gallery';
final originUrl = Uri.tryParse(origin);
final endpoint = originUrl == null
? ''
: originUrl
.replace(
scheme: originUrl.scheme == 'https' ? 'wss' : 'ws',
path: '/connect',
query: null,
)
.toString();
// Browser text scaling is a fixture input like platform and theme.
final textScale = double.tryParse(params['scale'] ?? '') ?? 1;
final body = _ProbeBody(
run: _run(origin, state),
gallery: gallery,
endpoint: endpoint,
);
Widget scaled(BuildContext context, Widget? app) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(textScale)),
child: app!,
);
runApp(
MaterialApp(
title: 'Artifacts probe',
theme: ThemeData(brightness: theme, platform: TargetPlatform.android),
builder: scaled,
home: body,
),
);
}
class _ProbeBody extends StatefulWidget {
const _ProbeBody({
required this.run,
required this.gallery,
required this.endpoint,
});
final JsonMap run;
final bool gallery;
final String endpoint;
@override
State<_ProbeBody> createState() => _ProbeBodyState();
}
class _ProbeBodyState extends State<_ProbeBody> {
late final _FakeGateway _gateway = _FakeGateway(widget.run);
late final RunsController _controller = RunsController(
RunsRepository(_gateway),
);
@override
void initState() {
super.initState();
_controller.select(31);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
if (widget.gallery) {
final steps = (widget.run['steps'] as List).cast<JsonMap>();
return ArtifactGalleryPage(
steps: steps,
configuredEndpoint: widget.endpoint,
);
}
final detail = RunDetailView(
controller: _controller,
gateway: _gateway,
onBack: () {},
);
return Scaffold(
appBar: AppBar(title: const Text('Runs')),
body: detail,
);
}
}