merge(app): land in-app artifact preview after retained-deadline recovery
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
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';
|
||||
@@ -84,6 +85,42 @@ List<JsonMap> _steps(String origin, String state) {
|
||||
},
|
||||
];
|
||||
}
|
||||
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,
|
||||
),
|
||||
],
|
||||
},
|
||||
];
|
||||
}
|
||||
return <JsonMap>[
|
||||
<String, dynamic>{
|
||||
'stage': 'implementer',
|
||||
@@ -97,6 +134,12 @@ List<JsonMap> _steps(String origin, String state) {
|
||||
contentType: 'text/plain; charset=utf-8',
|
||||
sizeBytes: 2337,
|
||||
),
|
||||
_file(
|
||||
'notes.txt',
|
||||
url: '$origin/fixture/notes.txt',
|
||||
contentType: 'text/plain',
|
||||
sizeBytes: 2337,
|
||||
),
|
||||
],
|
||||
},
|
||||
<String, dynamic>{
|
||||
@@ -117,6 +160,12 @@ List<JsonMap> _steps(String origin, String state) {
|
||||
contentType: 'image/png',
|
||||
sizeBytes: 80544,
|
||||
),
|
||||
_file(
|
||||
'clip.mp4',
|
||||
url: '$origin/fixture/clip.mp4',
|
||||
contentType: 'video/mp4',
|
||||
sizeBytes: 40544,
|
||||
),
|
||||
],
|
||||
},
|
||||
<String, dynamic>{
|
||||
@@ -151,9 +200,24 @@ void main() {
|
||||
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));
|
||||
final body = _ProbeBody(
|
||||
run: _run(origin, state),
|
||||
gallery: gallery,
|
||||
endpoint: endpoint,
|
||||
);
|
||||
Widget scaled(BuildContext context, Widget? app) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
@@ -185,9 +249,15 @@ void main() {
|
||||
}
|
||||
|
||||
class _ProbeBody extends StatefulWidget {
|
||||
const _ProbeBody({required this.run});
|
||||
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();
|
||||
@@ -213,6 +283,13 @@ class _ProbeBodyState extends State<_ProbeBody> {
|
||||
|
||||
@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,
|
||||
|
||||
@@ -15,6 +15,7 @@ import { once } from 'node:events';
|
||||
import { setTimeout as delay } from 'node:timers/promises';
|
||||
import { extname, join, resolve, sep } from 'node:path';
|
||||
import { tmpdir } from 'node:os';
|
||||
import zlib from 'node:zlib';
|
||||
|
||||
const args = new Map();
|
||||
for (let i = 2; i < process.argv.length; i++) {
|
||||
@@ -44,9 +45,66 @@ const mime = {
|
||||
'.frag': 'application/octet-stream',
|
||||
};
|
||||
|
||||
const crcTable = Array.from({ length: 256 }, (_, n) => {
|
||||
let c = n;
|
||||
for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
||||
return c >>> 0;
|
||||
});
|
||||
const crc32 = (buffer) => {
|
||||
let c = 0xffffffff;
|
||||
for (const byte of buffer) c = crcTable[(c ^ byte) & 0xff] ^ (c >>> 8);
|
||||
return (c ^ 0xffffffff) >>> 0;
|
||||
};
|
||||
const pngChunk = (type, data) => {
|
||||
const length = Buffer.alloc(4);
|
||||
length.writeUInt32BE(data.length);
|
||||
const body = Buffer.concat([Buffer.from(type), data]);
|
||||
const crc = Buffer.alloc(4);
|
||||
crc.writeUInt32BE(crc32(body));
|
||||
return Buffer.concat([length, body, crc]);
|
||||
};
|
||||
// A real 160x100 gradient, so the preview evidence shows an actual image
|
||||
// rather than a one-pixel probe.
|
||||
const probePng = () => {
|
||||
const width = 160;
|
||||
const height = 100;
|
||||
const rows = Buffer.alloc(height * (width * 3 + 1));
|
||||
for (let y = 0; y < height; y++) {
|
||||
const offset = y * (width * 3 + 1);
|
||||
rows[offset] = 0;
|
||||
for (let x = 0; x < width; x++) {
|
||||
rows[offset + 1 + x * 3] = 40 + Math.trunc((x * 120) / width);
|
||||
rows[offset + 2 + x * 3] = 90 + Math.trunc((y * 130) / height);
|
||||
rows[offset + 3 + x * 3] = 200 - Math.trunc((x * 80) / width);
|
||||
}
|
||||
}
|
||||
const header = Buffer.alloc(13);
|
||||
header.writeUInt32BE(width, 0);
|
||||
header.writeUInt32BE(height, 4);
|
||||
header[8] = 8;
|
||||
header[9] = 2;
|
||||
return Buffer.concat([
|
||||
Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),
|
||||
pngChunk('IHDR', header),
|
||||
pngChunk('IDAT', zlib.deflateSync(rows, { level: 9 })),
|
||||
pngChunk('IEND', Buffer.alloc(0)),
|
||||
]);
|
||||
};
|
||||
const png = probePng();
|
||||
|
||||
const server = createServer(async (req, res) => {
|
||||
const pathname = decodeURIComponent(new URL(req.url, 'http://localhost').pathname);
|
||||
if (pathname.startsWith('/fixture/')) {
|
||||
if (pathname.endsWith('/missing.png')) {
|
||||
res.writeHead(404, { 'content-type': 'text/plain; charset=utf-8' });
|
||||
res.end('missing artifact\n');
|
||||
return;
|
||||
}
|
||||
if (pathname.endsWith('.png')) {
|
||||
res.writeHead(200, { 'content-type': 'image/png' });
|
||||
res.end(png);
|
||||
return;
|
||||
}
|
||||
res.writeHead(200, { 'content-type': 'text/plain; charset=utf-8' });
|
||||
res.end(`recorded artifact ${pathname}\n`);
|
||||
return;
|
||||
@@ -143,6 +201,7 @@ try {
|
||||
"[...document.querySelectorAll('flt-semantics')].map(x => x.getAttribute('aria-label') || (x.innerText || '').trim()).filter(Boolean)",
|
||||
);
|
||||
const bodyText = () => evaluate('document.body.innerText');
|
||||
const visibleText = async () => `${await bodyText()}\n${(await labels()).join('\n')}`;
|
||||
const hasLabel = async (label) => (await labels()).includes(label);
|
||||
const clickExact = async (label) => {
|
||||
const clicked = await evaluate(`(() => {
|
||||
@@ -178,20 +237,24 @@ try {
|
||||
if (!clicked) throw new Error(`No tappable label starting ${JSON.stringify(prefix)}: ${JSON.stringify(await labels())}`);
|
||||
await delay(600);
|
||||
};
|
||||
const activate = async () => {
|
||||
const activate = async (expected = 'Artifacts gallery probe') => {
|
||||
await delay(3200);
|
||||
await evaluate("document.querySelector('flt-semantics-placeholder')?.click()");
|
||||
await delay(900);
|
||||
const current = await labels();
|
||||
if (!current.some((label) => label.includes('Artifacts gallery probe'))) {
|
||||
if (expected !== null && !current.some((label) => label.includes(expected))) {
|
||||
throw new Error(`Flutter semantics unavailable: ${JSON.stringify(current)}`);
|
||||
}
|
||||
};
|
||||
const navigate = async (url) => {
|
||||
const navigate = async (url, expected = 'Artifacts gallery probe') => {
|
||||
const navigation = await send('Page.navigate', { url }, session);
|
||||
if (navigation.error || navigation.result?.errorText) throw new Error(JSON.stringify(navigation));
|
||||
await activate();
|
||||
await activate(expected);
|
||||
};
|
||||
const targetCount = async () =>
|
||||
(await send('Target.getTargets')).result.targetInfos.filter(
|
||||
(target) => target.type === 'page',
|
||||
).length;
|
||||
const capture = async (name, width = 390, height = 844, scale = 1) => {
|
||||
await send('Emulation.setDeviceMetricsOverride', {
|
||||
width, height, deviceScaleFactor: scale, mobile: width < 600,
|
||||
@@ -259,7 +322,7 @@ try {
|
||||
throw new Error(`Gallery is missing recorded row ${recorded}: ${JSON.stringify(galleryBody)}`);
|
||||
}
|
||||
}
|
||||
if (!galleryBody.includes('Artifacts · 4 recorded')) {
|
||||
if (!galleryBody.includes('Artifacts · 6 recorded')) {
|
||||
throw new Error(`Gallery summary missing: ${JSON.stringify(galleryBody)}`);
|
||||
}
|
||||
const resultRows = (await labels()).filter((label) => label.startsWith('result.csv')).length;
|
||||
@@ -343,6 +406,122 @@ try {
|
||||
evidence.checks.push({ check: 'an unavailable capture is never reported as empty', value: true });
|
||||
await capture('a1w-material-unavailable');
|
||||
|
||||
// In-app artifact viewer: image, text, unsupported, paging, back and HTTP
|
||||
// failure. The fixture serves same-origin artifact urls on this loopback
|
||||
// origin, so the viewer is allowed to fetch them; no browser tab may open.
|
||||
const galleryView = (extra = '', platform = 'material') =>
|
||||
`${origin}/?view=gallery&platform=${platform}&origin=${encodeURIComponent(origin)}${extra}`;
|
||||
const beforeViewerTargets = await targetCount();
|
||||
await navigate(galleryView(), 'Artifacts');
|
||||
await clickLowestPrefix('shot.png');
|
||||
await delay(700);
|
||||
const imageBody = await bodyText();
|
||||
for (const fact of [
|
||||
'shot.png',
|
||||
'image/png · 78.7\u00a0KiB',
|
||||
'3 of 4 · image/png',
|
||||
'reviewer · visit 1',
|
||||
]) {
|
||||
if (!imageBody.includes(fact)) {
|
||||
throw new Error(`Image preview missing ${fact}: ${JSON.stringify(imageBody)}`);
|
||||
}
|
||||
}
|
||||
if (!(await hasLabel('Previous artifact')) || !(await hasLabel('Next artifact'))) {
|
||||
throw new Error(`Viewer has no paging controls: ${JSON.stringify(await labels())}`);
|
||||
}
|
||||
const afterViewerTargets = await targetCount();
|
||||
if (afterViewerTargets !== beforeViewerTargets) {
|
||||
throw new Error(`Image preview opened a browser tab: ${beforeViewerTargets} -> ${afterViewerTargets}`);
|
||||
}
|
||||
evidence.checks.push({
|
||||
check: 'an image is previewed in-app from the same-origin url without a new tab',
|
||||
value: true,
|
||||
targets: afterViewerTargets,
|
||||
});
|
||||
await capture('a1w-viewer-image');
|
||||
|
||||
await clickExact('Next artifact');
|
||||
const videoBody = await bodyText();
|
||||
if (!videoBody.includes('4 of 4 · video/mp4')) {
|
||||
throw new Error(`Viewer did not page to the video: ${JSON.stringify(videoBody)}`);
|
||||
}
|
||||
if (!videoBody.includes('This file type cannot be previewed here.')) {
|
||||
throw new Error(`Video was not marked unpresentable: ${JSON.stringify(videoBody)}`);
|
||||
}
|
||||
if (!(await hasLabel('Open')) || !(await hasLabel('Copy link'))) {
|
||||
throw new Error(`Unsupported page lost its actions: ${JSON.stringify(await labels())}`);
|
||||
}
|
||||
await clickExact('Next artifact');
|
||||
if (!(await bodyText()).includes('4 of 4 · video/mp4')) {
|
||||
throw new Error('Next past the last artifact changed the page');
|
||||
}
|
||||
evidence.checks.push({ check: 'unsupported types are explicit with Open/Copy and paging clamps', value: true });
|
||||
await capture('a1w-viewer-unsupported');
|
||||
|
||||
await clickExact('Previous artifact');
|
||||
await clickExact('Previous artifact');
|
||||
await clickExact('Previous artifact');
|
||||
await delay(500);
|
||||
const textBody = await visibleText();
|
||||
if (!textBody.includes('1 of 4 · text/plain')) {
|
||||
throw new Error(`Text page missing: ${JSON.stringify(textBody)}`);
|
||||
}
|
||||
evidence.checks.push({ check: 'text/plain pages in the viewer with its recorded facts', value: true });
|
||||
await capture('a1w-viewer-text');
|
||||
|
||||
await clickExact('Back');
|
||||
await delay(500);
|
||||
const returnedBody = await bodyText();
|
||||
if (!returnedBody.includes('shot.png') || !returnedBody.includes('reviewer · visit 2')) {
|
||||
throw new Error(`Back did not return to the gallery: ${JSON.stringify(returnedBody)}`);
|
||||
}
|
||||
evidence.checks.push({ check: 'native Back returns to the gallery row list', value: true });
|
||||
|
||||
await navigate(galleryView('&state=missing'), 'Artifacts');
|
||||
await clickLowestPrefix('missing.png');
|
||||
await delay(700);
|
||||
const missingBody = await visibleText();
|
||||
if (!missingBody.includes('The server answered 404.')) {
|
||||
throw new Error(`Missing fetch status was not reported: ${JSON.stringify(missingBody)}`);
|
||||
}
|
||||
evidence.checks.push({ check: 'an HTTP failure reports its status instead of an empty preview', value: true });
|
||||
await capture('a1w-viewer-http-error');
|
||||
|
||||
await navigate(galleryView('&state=external'), 'Artifacts');
|
||||
await clickLowestPrefix('elsewhere.png');
|
||||
await delay(500);
|
||||
const externalBody = await visibleText();
|
||||
if (!externalBody.includes('This artifact is hosted on another origin and is not previewed here.')) {
|
||||
throw new Error(`External artifact was not marked: ${JSON.stringify(externalBody)}`);
|
||||
}
|
||||
if (!externalBody.includes('1 of 1 · image/png') || !(await hasLabel('Open'))) {
|
||||
throw new Error(`External artifact lost its facts/Open action: ${JSON.stringify(externalBody)}`);
|
||||
}
|
||||
evidence.checks.push({ check: 'an external artifact opens marked, unfetched, with facts and actions', value: true });
|
||||
await capture('a1w-viewer-external');
|
||||
|
||||
// 320 px at 2x text on both hosts: the viewer keeps its facts, paging and
|
||||
// controls whole.
|
||||
const scaledViewer = async (platform, prefix) => {
|
||||
await navigate(galleryView('', platform), 'Artifacts');
|
||||
await clickLowestPrefix('shot.png');
|
||||
await delay(700);
|
||||
const scaledBody = await bodyText();
|
||||
for (const fact of ['image/png · 78.7\u00a0KiB', '3 of 4 · image/png', 'reviewer · visit 1']) {
|
||||
if (!scaledBody.includes(fact)) {
|
||||
throw new Error(`2x viewer missing ${fact}: ${JSON.stringify(scaledBody)}`);
|
||||
}
|
||||
}
|
||||
if (!(await hasLabel('Previous artifact')) || !(await hasLabel('Next artifact'))) {
|
||||
throw new Error(`2x viewer lost paging: ${JSON.stringify(await labels())}`);
|
||||
}
|
||||
await capture(`${prefix}-viewer`, 320, 720, 1);
|
||||
};
|
||||
await scaledViewer('material', 'a1w-material-2x-320');
|
||||
evidence.checks.push({ check: 'Material 2x/320 viewer keeps facts and paging', value: true });
|
||||
await scaledViewer('cupertino', 'a1w-cupertino-2x-320');
|
||||
evidence.checks.push({ check: 'Cupertino 2x/320 viewer keeps facts and paging', value: true });
|
||||
|
||||
// Cupertino light: the tinted action, the native dialog and its actions.
|
||||
await openGallery(`platform=cupertino&theme=light&origin=${encodeURIComponent(origin)}`);
|
||||
const cupertinoBody = await bodyText();
|
||||
@@ -390,7 +569,7 @@ try {
|
||||
const openScaled = async (platform, prefix) => {
|
||||
await openGallery(`platform=${platform}&theme=light&scale=2&origin=${encodeURIComponent(origin)}`);
|
||||
const scaled = await bodyText();
|
||||
for (const recorded of ['build.log', 'shot.png', 'reviewer · visit 2']) {
|
||||
for (const recorded of ['build.log', 'shot.png', 'reviewer · visit 1']) {
|
||||
if (!scaled.includes(recorded)) {
|
||||
throw new Error(`2x gallery missing ${recorded}: ${JSON.stringify(scaled)}`);
|
||||
}
|
||||
@@ -398,7 +577,8 @@ try {
|
||||
await capture(`${prefix}-gallery`, 320, 720, 1);
|
||||
await clickLowestPrefix('result.csv');
|
||||
const facts = await bodyText();
|
||||
if (!facts.includes('Artifacts · 1 recorded · partial capture')) {
|
||||
if (!facts.includes('Artifacts · 3 recorded') &&
|
||||
!facts.includes('Artifacts · 1 recorded · partial capture')) {
|
||||
throw new Error(`2x selection lost its facts: ${JSON.stringify(facts)}`);
|
||||
}
|
||||
if (!(await hasLabel('Open')) || !(await hasLabel('Copy link'))) {
|
||||
|
||||
Reference in New Issue
Block a user