Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions test/unit/tooling/run_local_e2e_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,9 @@ Future<void> main(List<String> args) async {
'https://user:[email protected]/m.litertlm',
'https://example.com/m.litertlm?X-Amz-Signature=abc',
'https://example.com/m.litertlm#token',
'https://[bad/token?x=1',
'https://h:port/m?token=S',
'HTTPS://user:[email protected]/m.litertlm',
])
['--model-path', secret, '--backend', 'cpu'],
]) {
Expand All @@ -1731,6 +1734,19 @@ Future<void> main(List<String> args) async {
'--dart-define=LITERT_LM_BACKEND=gpu',
),
);
final upper = await dryRun([
'--model-path',
'HTTPS://example.com/Qwen3-0.6B.litertlm',
'--backend',
'cpu',
]);
expect(
upper.stdout,
contains(
'--dart-define=LITERT_LM_MODEL_URL='
'HTTPS://example.com/Qwen3-0.6B.litertlm',
),
);
final url = await dryRun([
'--model-path',
'http://10.0.2.2:8765/gemma-4-E2B-it.litertlm',
Expand Down
37 changes: 20 additions & 17 deletions tool/testing/run_local_e2e.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2247,8 +2247,7 @@ List<LocalE2eScenario> buildLocalE2eScenarios({String? projectRoot}) {
requiresDevice: true,
stepsBuilder: (context) {
final model = context.modelPath!;
final remote =
model.startsWith('http://') || model.startsWith('https://');
final remote = _isRemoteModel(model);
return [
LocalE2eCommandStep(
workingDirectory: context.chatAppDir,
Expand Down Expand Up @@ -2993,21 +2992,22 @@ Future<LocalE2eResult> runLocalE2e(
stderr: '--model-path is required for ${scenario.name}.\n',
);
}
// The URL is printed and compiled into the app, so it must carry no secret.
final modelUrl = scenario.name == 'chat-app-litert-json-schema'
? Uri.tryParse(parsed.modelPath!)
: null;
if (modelUrl != null &&
modelUrl.hasScheme &&
(modelUrl.userInfo.isNotEmpty ||
modelUrl.hasQuery ||
modelUrl.hasFragment)) {
return LocalE2eResult(
64,
stderr:
'${scenario.name} accepts a model URL without credentials, query or '
'fragment; serve the bundle from a plain URL.\n',
);
// The URL is printed and compiled into the app, so it must carry no secret;
// a URL that does not parse cannot be checked, so it is refused too.
if (scenario.name == 'chat-app-litert-json-schema' &&
_isRemoteModel(parsed.modelPath!)) {
final modelUrl = Uri.tryParse(parsed.modelPath!);
if (modelUrl == null ||
modelUrl.userInfo.isNotEmpty ||
modelUrl.hasQuery ||
modelUrl.hasFragment) {
return LocalE2eResult(
64,
stderr:
'${scenario.name} accepts a model URL without credentials, query or '
'fragment; serve the bundle from a plain URL.\n',
);
}
}
if ((scenario.name == 'litert-lm-json-schema' ||
scenario.name == 'chat-app-litert-json-schema') &&
Expand Down Expand Up @@ -4021,3 +4021,6 @@ Future<void> main(List<String> args) async {
await stderr.flush();
exit(result.exitCode);
}

bool _isRemoteModel(String model) =>
RegExp(r'^https?://', caseSensitive: false).hasMatch(model);
Loading