merge(app): land route-vocabulary micro-slice
This commit is contained in:
@@ -1,16 +1,45 @@
|
||||
part 'app_route_codec.dart';
|
||||
|
||||
/// The destinations the app has a URL for.
|
||||
///
|
||||
/// The set mirrors [AppDestination] but stays free of widget imports so the
|
||||
/// parser and serialiser can be exercised without a Flutter host.
|
||||
enum AppRouteKind { pipelines, runs, chat, search, settings, templates }
|
||||
|
||||
/// One page route: a destination plus the run it opens, if any.
|
||||
/// One page route: a destination plus the detail, pane and query it opens.
|
||||
///
|
||||
/// Parsing is total, like the web client's route model: an unknown or
|
||||
/// malformed path resolves to the default Pipelines list instead of throwing.
|
||||
/// The serialiser is its inverse for every route the app can produce.
|
||||
/// The URL vocabulary mirrors `web/src/routes.js`:
|
||||
///
|
||||
/// /pipelines Pipelines list
|
||||
/// /pipelines/:id pipeline detail, latest version
|
||||
/// /pipelines/:id/:version pipeline detail at a version
|
||||
/// /pipelines/:id[/:version]/stage/:key definition stage pane
|
||||
/// /runs Runs list (optional ?pipeline=)
|
||||
/// /runs/:id run detail (optional ?action=decide)
|
||||
/// /runs/:id/stage/:key[?visit=N] one visit's stage pane
|
||||
/// /templates[/:key] template gallery / detail
|
||||
/// /settings/templates[/:key] aliases for the template routes
|
||||
/// /chat[/:id], /search, /settings unchanged destinations
|
||||
///
|
||||
/// Only the two stage panes are deep-linkable; other in-page state stays out
|
||||
/// of the URL. Unknown query parameters are ignored, and an invalid `visit`,
|
||||
/// `action` or `pipeline` value is dropped rather than failing the route.
|
||||
///
|
||||
/// Parsing is total: an unknown or malformed path resolves to the default
|
||||
/// Pipelines list instead of throwing, and the serialiser is its inverse for
|
||||
/// every route the app can produce.
|
||||
class AppRoute {
|
||||
const AppRoute(this.kind, {this.runId, this.chatSessionId});
|
||||
const AppRoute(
|
||||
this.kind, {
|
||||
this.runId,
|
||||
this.chatSessionId,
|
||||
this.pipelineId,
|
||||
this.version = 0,
|
||||
this.stageKey,
|
||||
this.visit,
|
||||
this.decide = false,
|
||||
this.templateKey,
|
||||
});
|
||||
|
||||
static const pipelines = AppRoute(AppRouteKind.pipelines);
|
||||
static const runs = AppRoute(AppRouteKind.runs);
|
||||
@@ -29,74 +58,74 @@ class AppRoute {
|
||||
? AppRoute(AppRouteKind.chat, chatSessionId: id)
|
||||
: chat;
|
||||
|
||||
/// A pipeline detail; [version] 0 is the latest published version.
|
||||
static AppRoute pipeline(int id, {int version = 0}) => _validId(id) == null
|
||||
? pipelines
|
||||
: AppRoute(
|
||||
AppRouteKind.pipelines,
|
||||
pipelineId: id,
|
||||
version: _latest(version),
|
||||
);
|
||||
|
||||
/// The definition pane's stage [stageKey] for pipeline [id].
|
||||
static AppRoute pipelineStage(int id, String stageKey, {int version = 0}) =>
|
||||
_validId(id) == null || stageKey.isEmpty
|
||||
? pipelines
|
||||
: AppRoute(
|
||||
AppRouteKind.pipelines,
|
||||
pipelineId: id,
|
||||
version: _latest(version),
|
||||
stageKey: stageKey,
|
||||
);
|
||||
|
||||
/// The Runs list filtered to one pipeline.
|
||||
static AppRoute runsForPipeline(int pipelineId) =>
|
||||
_validId(pipelineId) == null
|
||||
? runs
|
||||
: AppRoute(AppRouteKind.runs, pipelineId: pipelineId);
|
||||
|
||||
/// One template's detail page, or the gallery for an empty [key].
|
||||
static AppRoute template(String key) => key.isEmpty
|
||||
? templates
|
||||
: AppRoute(AppRouteKind.templates, templateKey: key);
|
||||
|
||||
final AppRouteKind kind;
|
||||
|
||||
/// The run shown by the Runs destination, or null for the list.
|
||||
/// The run shown by the Runs destination, or null for the list. When
|
||||
/// [stageKey] is also set, this is the run whose stage pane is open.
|
||||
final int? runId;
|
||||
|
||||
/// The chat session shown by the Chat destination, or null for the list.
|
||||
final String? chatSessionId;
|
||||
|
||||
/// The pipeline shown by the Pipelines destination, or the pipeline the Runs
|
||||
/// list is filtered to. Null is the unfiltered list.
|
||||
final int? pipelineId;
|
||||
|
||||
/// The pipeline version for [pipelineId]; 0 is the latest.
|
||||
final int version;
|
||||
|
||||
/// The stage pane's key, for a pipeline definition or a run visit.
|
||||
final String? stageKey;
|
||||
|
||||
/// The zero-based visit index for a run's [stageKey], or null when absent.
|
||||
final int? visit;
|
||||
|
||||
/// Whether a run detail opens its decision prompt (`?action=decide`).
|
||||
final bool decide;
|
||||
|
||||
/// The template whose detail page is open, or null for the gallery.
|
||||
final String? templateKey;
|
||||
|
||||
/// The path the app writes into history for this route.
|
||||
String get path => switch (kind) {
|
||||
AppRouteKind.pipelines => '/pipelines',
|
||||
AppRouteKind.runs => runId == null ? '/runs' : '/runs/$runId',
|
||||
AppRouteKind.chat =>
|
||||
chatSessionId == null || !isChatSessionId(chatSessionId!)
|
||||
? '/chat'
|
||||
: '/chat/${Uri.encodeComponent(chatSessionId!)}',
|
||||
AppRouteKind.search => '/search',
|
||||
AppRouteKind.settings => '/settings',
|
||||
AppRouteKind.templates => '/templates',
|
||||
};
|
||||
String get path => _routePath(this);
|
||||
|
||||
/// Parses a browser pathname (or a full URL) into a route.
|
||||
///
|
||||
/// `/runs/abc` and other malformed details are the default route, matching
|
||||
/// the web parser; `/pipelines/` and other trailing slashes are normalised.
|
||||
static AppRoute parse(String location) {
|
||||
var path = location.trim();
|
||||
if (path.isEmpty) return pipelines;
|
||||
if (path.contains('://')) {
|
||||
final uri = Uri.tryParse(path);
|
||||
if (uri == null) return pipelines;
|
||||
path = uri.path;
|
||||
}
|
||||
final hash = path.indexOf('#');
|
||||
if (hash != -1) path = path.substring(0, hash);
|
||||
final query = path.indexOf('?');
|
||||
if (query != -1) path = path.substring(0, query);
|
||||
|
||||
final segments = <String>[];
|
||||
for (final raw in path.split('/')) {
|
||||
if (raw.isEmpty) continue;
|
||||
try {
|
||||
segments.add(Uri.decodeComponent(raw));
|
||||
} on ArgumentError {
|
||||
return pipelines;
|
||||
}
|
||||
}
|
||||
if (segments.isEmpty) return pipelines;
|
||||
|
||||
return switch (segments.first) {
|
||||
'pipelines' when segments.length == 1 => pipelines,
|
||||
'runs' when segments.length == 1 => runs,
|
||||
'runs' when segments.length == 2 => _runRoute(segments[1]),
|
||||
'chat' when segments.length == 1 => chat,
|
||||
'chat' when segments.length == 2 => _chatRoute(segments[1]),
|
||||
'search' when segments.length == 1 => search,
|
||||
'settings' when segments.length == 1 => settings,
|
||||
'templates' when segments.length == 1 => templates,
|
||||
_ => pipelines,
|
||||
};
|
||||
}
|
||||
|
||||
static AppRoute _runRoute(String value) {
|
||||
if (!RegExp(r'^[0-9]+$').hasMatch(value)) return pipelines;
|
||||
final id = int.tryParse(value);
|
||||
if (id == null || id <= 0) return pipelines;
|
||||
return AppRoute(AppRouteKind.runs, runId: id);
|
||||
}
|
||||
/// `/runs/abc`, `/pipelines/0` and other malformed details are the default
|
||||
/// route, matching the web parser; `/pipelines/` and other trailing slashes
|
||||
/// are normalised.
|
||||
static AppRoute parse(String location) => _parseRoute(location);
|
||||
|
||||
/// A chat session id is nonempty, bounded and URL-safe, matching the web
|
||||
/// parser. Anything else is malformed rather than a stale session the
|
||||
@@ -106,18 +135,31 @@ class AppRoute {
|
||||
value.length <= 200 &&
|
||||
RegExp(r'^[A-Za-z0-9_-]+$').hasMatch(value);
|
||||
|
||||
static AppRoute _chatRoute(String value) =>
|
||||
isChatSessionId(value) ? chatSession(value) : pipelines;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
other is AppRoute &&
|
||||
other.kind == kind &&
|
||||
other.runId == runId &&
|
||||
other.chatSessionId == chatSessionId;
|
||||
other.chatSessionId == chatSessionId &&
|
||||
other.pipelineId == pipelineId &&
|
||||
other.version == version &&
|
||||
other.stageKey == stageKey &&
|
||||
other.visit == visit &&
|
||||
other.decide == decide &&
|
||||
other.templateKey == templateKey;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(kind, runId, chatSessionId);
|
||||
int get hashCode => Object.hash(
|
||||
kind,
|
||||
runId,
|
||||
chatSessionId,
|
||||
pipelineId,
|
||||
version,
|
||||
stageKey,
|
||||
visit,
|
||||
decide,
|
||||
templateKey,
|
||||
);
|
||||
|
||||
@override
|
||||
String toString() => path;
|
||||
@@ -127,5 +169,23 @@ class AppRoute {
|
||||
class _RunRouteFactory {
|
||||
const _RunRouteFactory();
|
||||
|
||||
AppRoute call(int id) => AppRoute(AppRouteKind.runs, runId: id);
|
||||
AppRoute call(int id) => _validId(id) == null
|
||||
? AppRoute.runs
|
||||
: AppRoute(AppRouteKind.runs, runId: id);
|
||||
|
||||
/// One visit's stage pane; [visit] is zero-based and omitted when null.
|
||||
AppRoute stage(int id, String stageKey, {int? visit}) =>
|
||||
_validId(id) == null || stageKey.isEmpty
|
||||
? AppRoute.runs
|
||||
: AppRoute(
|
||||
AppRouteKind.runs,
|
||||
runId: id,
|
||||
stageKey: stageKey,
|
||||
visit: _nonNegative(visit),
|
||||
);
|
||||
|
||||
/// A run detail with its decision prompt open.
|
||||
AppRoute decide(int id) => _validId(id) == null
|
||||
? AppRoute.runs
|
||||
: AppRoute(AppRouteKind.runs, runId: id, decide: true);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
part of 'app_route.dart';
|
||||
|
||||
/// The largest integer a browser can represent exactly, so ids parsed here
|
||||
/// survive a round trip through `Number`.
|
||||
const _maxSafe = 9007199254740991;
|
||||
final _digits = RegExp(r'^[0-9]+$');
|
||||
|
||||
String _routePath(AppRoute route) => switch (route.kind) {
|
||||
AppRouteKind.pipelines => _pipelinePath(route),
|
||||
AppRouteKind.runs => _runsPath(route),
|
||||
AppRouteKind.chat => _chatPath(route),
|
||||
AppRouteKind.search => '/search',
|
||||
AppRouteKind.settings => '/settings',
|
||||
AppRouteKind.templates => _templatesPath(route),
|
||||
};
|
||||
|
||||
String _pipelinePath(AppRoute route) {
|
||||
final id = _validId(route.pipelineId);
|
||||
if (id == null) return '/pipelines';
|
||||
final revision = _latest(route.version);
|
||||
final base = revision == 0 ? '/pipelines/$id' : '/pipelines/$id/$revision';
|
||||
final key = route.stageKey;
|
||||
return key == null || key.isEmpty
|
||||
? base
|
||||
: '$base/stage/${Uri.encodeComponent(key)}';
|
||||
}
|
||||
|
||||
String _runsPath(AppRoute route) {
|
||||
if (route.runId != null) {
|
||||
final id = _validId(route.runId);
|
||||
if (id == null) return '/runs';
|
||||
final base = '/runs/$id';
|
||||
final key = route.stageKey;
|
||||
if (key != null && key.isNotEmpty) {
|
||||
final index = _nonNegative(route.visit);
|
||||
return index == null
|
||||
? '$base/stage/${Uri.encodeComponent(key)}'
|
||||
: '$base/stage/${Uri.encodeComponent(key)}?visit=$index';
|
||||
}
|
||||
return route.decide ? '$base?action=decide' : base;
|
||||
}
|
||||
final filter = _validId(route.pipelineId);
|
||||
return filter == null ? '/runs' : '/runs?pipeline=$filter';
|
||||
}
|
||||
|
||||
String _templatesPath(AppRoute route) {
|
||||
final key = route.templateKey;
|
||||
return key == null || key.isEmpty
|
||||
? '/templates'
|
||||
: '/templates/${Uri.encodeComponent(key)}';
|
||||
}
|
||||
|
||||
String _chatPath(AppRoute route) {
|
||||
final id = route.chatSessionId;
|
||||
return id == null || !AppRoute.isChatSessionId(id)
|
||||
? '/chat'
|
||||
: '/chat/${Uri.encodeComponent(id)}';
|
||||
}
|
||||
|
||||
/// Parses a pathname plus its optional query. Total: anything unrecognised is
|
||||
/// the Pipelines list. Unknown query parameters are ignored, and an invalid
|
||||
/// `visit`, `action` or `pipeline` value is dropped without failing the route.
|
||||
AppRoute _parseRoute(String location) {
|
||||
var raw = location.trim();
|
||||
if (raw.isEmpty) return AppRoute.pipelines;
|
||||
|
||||
var query = '';
|
||||
if (raw.contains('://')) {
|
||||
final uri = Uri.tryParse(raw);
|
||||
if (uri == null) return AppRoute.pipelines;
|
||||
raw = uri.path;
|
||||
query = uri.query;
|
||||
}
|
||||
final hash = raw.indexOf('#');
|
||||
if (hash != -1) raw = raw.substring(0, hash);
|
||||
final mark = raw.indexOf('?');
|
||||
if (mark != -1) {
|
||||
if (query.isEmpty) query = raw.substring(mark + 1);
|
||||
raw = raw.substring(0, mark);
|
||||
}
|
||||
raw = raw.replaceAll(RegExp(r'/+$'), '');
|
||||
|
||||
final segments = _decodeSegments(raw);
|
||||
if (segments == null || segments.isEmpty) return AppRoute.pipelines;
|
||||
final params = _decodeQuery(query);
|
||||
|
||||
return switch (segments.first) {
|
||||
'pipelines' => _pipelineRoute(segments),
|
||||
'runs' => _runsRoute(segments, params),
|
||||
'chat' => _chatRoute(segments),
|
||||
'search' when segments.length == 1 => AppRoute.search,
|
||||
'settings' => _settingsRoute(segments),
|
||||
'templates' => _templatesRoute(segments),
|
||||
_ => AppRoute.pipelines,
|
||||
};
|
||||
}
|
||||
|
||||
List<String>? _decodeSegments(String path) {
|
||||
final parts = path.split('/');
|
||||
final first = parts.isNotEmpty && parts.first.isEmpty ? 1 : 0;
|
||||
final values = <String>[];
|
||||
for (var index = first; index < parts.length; index++) {
|
||||
if (parts[index].isEmpty) return null;
|
||||
try {
|
||||
values.add(Uri.decodeComponent(parts[index]));
|
||||
} on ArgumentError {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
Map<String, String> _decodeQuery(String query) {
|
||||
if (query.isEmpty) return const {};
|
||||
try {
|
||||
return Uri.splitQueryString(query);
|
||||
} on ArgumentError {
|
||||
return const {};
|
||||
} on FormatException {
|
||||
return const {};
|
||||
}
|
||||
}
|
||||
|
||||
/// `/pipelines/:id[/:version][/stage/:key]`.
|
||||
AppRoute _pipelineRoute(List<String> segments) {
|
||||
if (segments.length == 1) return AppRoute.pipelines;
|
||||
final id = _positiveId(segments[1]);
|
||||
if (id == null) return AppRoute.pipelines;
|
||||
if (segments.length == 2) return AppRoute.pipeline(id);
|
||||
// `stage` comes before a version on purpose: /pipelines/9/stage/7 is the
|
||||
// pane for stage `7`, not version 7 of pipeline stage `stage`.
|
||||
if (segments[2] == 'stage') {
|
||||
return segments.length == 4
|
||||
? AppRoute.pipelineStage(id, segments[3])
|
||||
: AppRoute.pipelines;
|
||||
}
|
||||
final revision = _number(segments[2]);
|
||||
if (revision == null) return AppRoute.pipelines;
|
||||
if (segments.length == 3) return AppRoute.pipeline(id, version: revision);
|
||||
return segments[3] == 'stage' && segments.length == 5
|
||||
? AppRoute.pipelineStage(id, segments[4], version: revision)
|
||||
: AppRoute.pipelines;
|
||||
}
|
||||
|
||||
/// `/runs[?pipeline=]`, `/runs/:id[?action=decide]` and the stage pane.
|
||||
///
|
||||
/// `decide` is the only URL action the app has, so any other `action` value is
|
||||
/// dropped instead of carried as an opaque string.
|
||||
AppRoute _runsRoute(List<String> segments, Map<String, String> params) {
|
||||
if (segments.length == 1) {
|
||||
final filter = _positiveId(params['pipeline']);
|
||||
return filter == null ? AppRoute.runs : AppRoute.runsForPipeline(filter);
|
||||
}
|
||||
final id = _positiveId(segments[1]);
|
||||
if (id == null) return AppRoute.pipelines;
|
||||
if (segments.length == 2) {
|
||||
return params['action'] == 'decide'
|
||||
? AppRoute.run.decide(id)
|
||||
: AppRoute.run(id);
|
||||
}
|
||||
if (segments[2] == 'stage' && segments.length == 4) {
|
||||
return AppRoute.run.stage(id, segments[3], visit: _number(params['visit']));
|
||||
}
|
||||
return AppRoute.pipelines;
|
||||
}
|
||||
|
||||
AppRoute _chatRoute(List<String> segments) {
|
||||
if (segments.length == 1) return AppRoute.chat;
|
||||
if (segments.length != 2) return AppRoute.pipelines;
|
||||
final id = segments[1];
|
||||
return AppRoute.isChatSessionId(id)
|
||||
? AppRoute.chatSession(id)
|
||||
: AppRoute.pipelines;
|
||||
}
|
||||
|
||||
/// `/settings` and the `/settings/templates[/:key]` aliases.
|
||||
AppRoute _settingsRoute(List<String> segments) {
|
||||
if (segments.length == 1) return AppRoute.settings;
|
||||
if (segments[1] != 'templates') return AppRoute.pipelines;
|
||||
if (segments.length == 2) return AppRoute.templates;
|
||||
return segments.length == 3
|
||||
? AppRoute.template(segments[2])
|
||||
: AppRoute.pipelines;
|
||||
}
|
||||
|
||||
AppRoute _templatesRoute(List<String> segments) {
|
||||
if (segments.length == 1) return AppRoute.templates;
|
||||
return segments.length == 2
|
||||
? AppRoute.template(segments[1])
|
||||
: AppRoute.pipelines;
|
||||
}
|
||||
|
||||
/// A non-negative safe integer, or null. Digits only, so `-1`, `1.5` and an
|
||||
/// empty value are all dropped exactly where the web parser drops them.
|
||||
int? _number(String? value) {
|
||||
if (value == null || !_digits.hasMatch(value)) return null;
|
||||
final number = int.tryParse(value);
|
||||
if (number == null || number < 0 || number > _maxSafe) return null;
|
||||
return number;
|
||||
}
|
||||
|
||||
/// A positive safe integer, or null.
|
||||
int? _positiveId(String? value) {
|
||||
final number = _number(value);
|
||||
return number == null || number == 0 ? null : number;
|
||||
}
|
||||
|
||||
int? _validId(int? value) =>
|
||||
value == null || value <= 0 || value > _maxSafe ? null : value;
|
||||
|
||||
int? _nonNegative(int? value) =>
|
||||
value == null || value < 0 || value > _maxSafe ? null : value;
|
||||
|
||||
int _latest(int version) => version > 0 && version <= _maxSafe ? version : 0;
|
||||
@@ -2,10 +2,28 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/app_route.dart';
|
||||
|
||||
void main() {
|
||||
test('parses each destination and a run detail', () {
|
||||
test('parses each destination, detail and stage pane', () {
|
||||
expect(AppRoute.parse('/pipelines'), AppRoute.pipelines);
|
||||
expect(AppRoute.parse('/pipelines/5'), AppRoute.pipeline(5));
|
||||
expect(AppRoute.parse('/pipelines/5/7'), AppRoute.pipeline(5, version: 7));
|
||||
expect(
|
||||
AppRoute.parse('/pipelines/5/stage/build'),
|
||||
AppRoute.pipelineStage(5, 'build'),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('/pipelines/5/7/stage/build'),
|
||||
AppRoute.pipelineStage(5, 'build', version: 7),
|
||||
);
|
||||
expect(AppRoute.parse('/runs'), AppRoute.runs);
|
||||
expect(AppRoute.parse('/runs/12'), AppRoute.run(12));
|
||||
expect(
|
||||
AppRoute.parse('/runs/12/stage/build'),
|
||||
AppRoute.run.stage(12, 'build'),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('/runs/12/stage/build?visit=3'),
|
||||
AppRoute.run.stage(12, 'build', visit: 3),
|
||||
);
|
||||
expect(AppRoute.parse('/chat'), AppRoute.chat);
|
||||
expect(
|
||||
AppRoute.parse('/chat/abc_DEF-123'),
|
||||
@@ -14,6 +32,94 @@ void main() {
|
||||
expect(AppRoute.parse('/search'), AppRoute.search);
|
||||
expect(AppRoute.parse('/settings'), AppRoute.settings);
|
||||
expect(AppRoute.parse('/templates'), AppRoute.templates);
|
||||
expect(AppRoute.parse('/templates/release'), AppRoute.template('release'));
|
||||
});
|
||||
|
||||
test('version before stage: /stage/ is a pane key, not a version', () {
|
||||
expect(
|
||||
AppRoute.parse('/pipelines/9/stage/7'),
|
||||
AppRoute.pipelineStage(9, '7'),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('/pipelines/9/7/stage/7'),
|
||||
AppRoute.pipelineStage(9, '7', version: 7),
|
||||
);
|
||||
});
|
||||
|
||||
test('version 0 means latest and is omitted from the path', () {
|
||||
expect(AppRoute.parse('/pipelines/5/0'), AppRoute.pipeline(5));
|
||||
expect(AppRoute.parse('/pipelines/5/0').path, '/pipelines/5');
|
||||
expect(
|
||||
AppRoute.parse('/pipelines/5/0/stage/build'),
|
||||
AppRoute.pipelineStage(5, 'build'),
|
||||
);
|
||||
expect(AppRoute.pipeline(5, version: 0).path, '/pipelines/5');
|
||||
expect(AppRoute.pipeline(5, version: -1).path, '/pipelines/5');
|
||||
});
|
||||
|
||||
test('template aliases resolve to the canonical template route', () {
|
||||
expect(AppRoute.parse('/settings/templates'), AppRoute.templates);
|
||||
expect(
|
||||
AppRoute.parse('/settings/templates/release'),
|
||||
AppRoute.template('release'),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('/settings/templates/release').path,
|
||||
'/templates/release',
|
||||
);
|
||||
expect(AppRoute.parse('/settings/templates/a/b'), AppRoute.pipelines);
|
||||
expect(AppRoute.parse('/settings/other'), AppRoute.pipelines);
|
||||
expect(AppRoute.parse('/templates/a/b'), AppRoute.pipelines);
|
||||
});
|
||||
|
||||
test('runs list pipeline filter and run action are parsed', () {
|
||||
expect(AppRoute.parse('/runs?pipeline=7'), AppRoute.runsForPipeline(7));
|
||||
expect(AppRoute.parse('/runs?pipeline=7').path, '/runs?pipeline=7');
|
||||
expect(AppRoute.parse('/runs?pipeline=0'), AppRoute.runs);
|
||||
expect(AppRoute.parse('/runs?pipeline=abc'), AppRoute.runs);
|
||||
expect(AppRoute.parse('/runs/5?action=decide'), AppRoute.run.decide(5));
|
||||
expect(AppRoute.run.decide(5).path, '/runs/5?action=decide');
|
||||
expect(AppRoute.parse('/runs/5?action='), AppRoute.run(5));
|
||||
expect(AppRoute.parse('/runs/5?action=retry'), AppRoute.run(5));
|
||||
expect(AppRoute.parse('/runs/5?action=retry').path, '/runs/5');
|
||||
});
|
||||
|
||||
test('unknown query parameters are ignored and invalid values dropped', () {
|
||||
expect(
|
||||
AppRoute.parse('/runs/5/stage/build?visit=-1'),
|
||||
AppRoute.run.stage(5, 'build'),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('/runs/5/stage/build?visit=1.5'),
|
||||
AppRoute.run.stage(5, 'build'),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('/runs/5/stage/build?visit=abc'),
|
||||
AppRoute.run.stage(5, 'build'),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('/runs/5/stage/build?visit=0&x=1'),
|
||||
AppRoute.run.stage(5, 'build', visit: 0),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('/runs/5/stage/build?visit=99999999999999999999'),
|
||||
AppRoute.run.stage(5, 'build'),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('/runs/5/stage/build?action=decide'),
|
||||
AppRoute.run.stage(5, 'build'),
|
||||
);
|
||||
expect(AppRoute.parse('/runs/5?pipeline=7'), AppRoute.run(5));
|
||||
expect(AppRoute.parse('/runs/5?x=1'), AppRoute.run(5));
|
||||
expect(AppRoute.parse('/runs/5?x=%E0%A4%A'), AppRoute.run(5));
|
||||
expect(
|
||||
AppRoute.parse('/pipelines/5/stage/build?visit=2'),
|
||||
AppRoute.pipelineStage(5, 'build'),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('/templates/release?x=1'),
|
||||
AppRoute.template('release'),
|
||||
);
|
||||
});
|
||||
|
||||
test('normalises slashes and accepts a full URL, query and fragment', () {
|
||||
@@ -22,7 +128,11 @@ void main() {
|
||||
expect(AppRoute.parse('/templates/'), AppRoute.templates);
|
||||
expect(
|
||||
AppRoute.parse('http://127.0.0.1:8096/runs/7?action=decide#top'),
|
||||
AppRoute.run(7),
|
||||
AppRoute.run.decide(7),
|
||||
);
|
||||
expect(
|
||||
AppRoute.parse('https://example.test/runs/7/stage/build?visit=2#top'),
|
||||
AppRoute.run.stage(7, 'build', visit: 2),
|
||||
);
|
||||
expect(AppRoute.parse('/runs/7/'), AppRoute.run(7));
|
||||
expect(
|
||||
@@ -43,9 +153,20 @@ void main() {
|
||||
'/runs/0',
|
||||
'/runs/-1',
|
||||
'/runs/1/extra',
|
||||
'/pipelines/2',
|
||||
'/runs/5/stage',
|
||||
'/runs/5/stage/a/b',
|
||||
'/runs/5/stage/',
|
||||
'/pipelines/0',
|
||||
'/pipelines/abc',
|
||||
'/pipelines/5/abc',
|
||||
'/pipelines/5/-1',
|
||||
'/pipelines/5/stage',
|
||||
'/pipelines/5/stage/a/b',
|
||||
'/pipelines/5/1/2',
|
||||
'/search/1',
|
||||
'/templates/release',
|
||||
'/runs/9007199254740992',
|
||||
'/pipelines/9007199254740992',
|
||||
'/templates/a/b',
|
||||
'/chat/a/b',
|
||||
'/chat/%2F',
|
||||
'/chat/${'x' * 201}',
|
||||
@@ -59,19 +180,70 @@ void main() {
|
||||
test('serialises every route back to a parsable path', () {
|
||||
for (final route in [
|
||||
AppRoute.pipelines,
|
||||
AppRoute.pipeline(5),
|
||||
AppRoute.pipeline(5, version: 2),
|
||||
AppRoute.pipelineStage(5, 'build'),
|
||||
AppRoute.pipelineStage(5, 'build', version: 2),
|
||||
AppRoute.pipelineStage(5, 'a/b'),
|
||||
AppRoute.runs,
|
||||
AppRoute.runsForPipeline(7),
|
||||
AppRoute.run(3),
|
||||
AppRoute.run.decide(3),
|
||||
AppRoute.run.stage(3, 'build'),
|
||||
AppRoute.run.stage(3, 'build', visit: 0),
|
||||
AppRoute.run.stage(3, 'build', visit: 4),
|
||||
AppRoute.chat,
|
||||
AppRoute.chatSession('probe_open-1'),
|
||||
AppRoute.search,
|
||||
AppRoute.settings,
|
||||
AppRoute.templates,
|
||||
AppRoute.template('release'),
|
||||
AppRoute.template('release notes'),
|
||||
AppRoute.template('café'),
|
||||
AppRoute.pipelineStage(5, 'build ✓'),
|
||||
]) {
|
||||
expect(AppRoute.parse(route.path), route);
|
||||
expect(AppRoute.parse(route.path), route, reason: route.path);
|
||||
}
|
||||
expect(AppRoute.run(3).path, '/runs/3');
|
||||
expect(AppRoute.chatSession('probe_open-1').path, '/chat/probe_open-1');
|
||||
expect(AppRoute.chatSession('bad id').path, '/chat');
|
||||
expect(AppRoute.templates.path, '/templates');
|
||||
});
|
||||
|
||||
test('canonical paths for the extended vocabulary', () {
|
||||
expect(AppRoute.pipeline(5).path, '/pipelines/5');
|
||||
expect(AppRoute.pipeline(5, version: 2).path, '/pipelines/5/2');
|
||||
expect(AppRoute.pipelineStage(5, 'build').path, '/pipelines/5/stage/build');
|
||||
expect(
|
||||
AppRoute.pipelineStage(5, 'build', version: 2).path,
|
||||
'/pipelines/5/2/stage/build',
|
||||
);
|
||||
expect(
|
||||
AppRoute.pipelineStage(5, 'release notes').path,
|
||||
'/pipelines/5/stage/release%20notes',
|
||||
);
|
||||
expect(AppRoute.runsForPipeline(7).path, '/runs?pipeline=7');
|
||||
expect(AppRoute.run.decide(3).path, '/runs/3?action=decide');
|
||||
expect(
|
||||
AppRoute.run.stage(3, 'build', visit: 2).path,
|
||||
'/runs/3/stage/build?visit=2',
|
||||
);
|
||||
expect(AppRoute.run.stage(3, 'build').path, '/runs/3/stage/build');
|
||||
expect(AppRoute.template('release').path, '/templates/release');
|
||||
expect(AppRoute.template('').path, '/templates');
|
||||
});
|
||||
|
||||
test('invalid ids never serialise outside the vocabulary', () {
|
||||
expect(AppRoute.pipeline(0), AppRoute.pipelines);
|
||||
expect(AppRoute.pipeline(-1), AppRoute.pipelines);
|
||||
expect(AppRoute.pipelineStage(0, 'build'), AppRoute.pipelines);
|
||||
expect(AppRoute.pipelineStage(5, ''), AppRoute.pipelines);
|
||||
expect(AppRoute.runsForPipeline(0), AppRoute.runs);
|
||||
expect(AppRoute.run(0), AppRoute.runs);
|
||||
expect(AppRoute.run.stage(0, 'build'), AppRoute.runs);
|
||||
expect(AppRoute.run.stage(3, ''), AppRoute.runs);
|
||||
expect(AppRoute.run.decide(0), AppRoute.runs);
|
||||
expect(AppRoute(AppRouteKind.pipelines, pipelineId: 0).path, '/pipelines');
|
||||
expect(AppRoute(AppRouteKind.runs, runId: 0).path, '/runs');
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user