From b0c7ea2fc419ea0c743959c23a4bba089d8c879d Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Thu, 15 Oct 2026 12:17:14 -0400 Subject: [PATCH 1/3] fix(hook): name the core's own companion minor from 0.13.0 From core 0.13.0, Apple companions share the core MAJOR.MINOR, but the incompatible-companion error and the earlier-build warning still named ^0.0.23, the first 0.0.x release pinning v0.6.0-3, which keeps a 0.13 app on the old companion line. The hook now reads its own pubspec version and names ^MAJOR.MINOR.0 from the lockstep start; earlier cores keep the first-pinning release. The stable_diffusion error names a release too. The release docs verifier takes its alignment start from the same constant. --- CHANGELOG.md | 5 + hook/build.dart | 66 +++++-- lib/src/hook/apple_companion_constraint.dart | 75 ++++++++ lib/src/hook/native_release_pins.dart | 7 +- test/support/hook_core_version.dart | 28 +++ .../hook/apple_companion_constraint_test.dart | 90 +++++++++ ...build_hook_litert_lm_integration_test.dart | 179 +++++++++++------- ...ook_stable_diffusion_integration_test.dart | 48 +++++ .../testing/verify_release_docs_versions.dart | 11 +- website/docs/changelog/recent-releases.md | 5 + 10 files changed, 426 insertions(+), 88 deletions(-) create mode 100644 lib/src/hook/apple_companion_constraint.dart create mode 100644 test/support/hook_core_version.dart create mode 100644 test/unit/hook/apple_companion_constraint_test.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 30fc08183..befbaa7f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Unreleased +- From core `0.13.0`, the Flutter Apple build error or warning for a + mismatched or earlier-build llama.cpp companion names the companion release + of the core's own minor, such as `^0.13.0`, instead of the first `0.0.x` + release pinning the native runtime; the stable_diffusion companion error + names one too. - With `llamadart_litert_lm_flutter` `0.0.15`, the Flutter macOS build now only warns to upgrade the companion to `0.0.16`, the release pinning `v0.18.0-1`, instead of claiming that the app cannot load LiteRT-LM and needs diff --git a/hook/build.dart b/hook/build.dart index 9d78db0ab..268c4da8b 100644 --- a/hook/build.dart +++ b/hook/build.dart @@ -19,6 +19,7 @@ import 'package:logging/logging.dart'; import 'package:path/path.dart' as path; import 'package:yaml/yaml.dart'; +import 'package:llamadart/src/hook/apple_companion_constraint.dart'; import 'package:llamadart/src/hook/native_archive_digest.dart'; import 'package:llamadart/src/hook/native_bundle_config.dart'; import 'package:llamadart/src/hook/native_release_pins.dart'; @@ -685,7 +686,13 @@ _AppleCompanions? _flutterAppleCompanions({ final runtimes = []; String? liteRtLmMacOsWarning; if (dependencies.contains(_llamaCppFlutterPackageName)) { - _validateAppleCompanion(_llamaCppCompanion, consumerRoot, output, log); + _validateAppleCompanion( + _llamaCppCompanion, + consumerRoot, + packageRoot, + output, + log, + ); runtimes.add(nativeRuntimeLlamaCpp); } if (dependencies.contains(_liteRtLmFlutterPackageName)) { @@ -704,6 +711,7 @@ _AppleCompanions? _flutterAppleCompanions({ _validateAppleCompanion( _stableDiffusionCompanion, consumerRoot, + packageRoot, output, log, ); @@ -727,8 +735,9 @@ _AppleCompanions? _flutterAppleCompanions({ /// its SwiftPM framework: the companion pins [nativeRepository]@[nativeTag] /// through `let [tagVariable]` in the maintained manifest template. /// [compatibleTags] maps earlier tags accepted with a warning to what their -/// frameworks lack. [companionVersion] is the first companion release pinning -/// [nativeTag], when the core records it. +/// frameworks lack. [companionVersion] is the first `0.0.x` companion release +/// pinning [nativeTag], when the core records it; only a core before +/// [appleCompanionLockstepStart] names it. typedef _AppleCompanionContract = ({ String label, String packageName, @@ -765,22 +774,24 @@ const _AppleCompanionContract _stableDiffusionCompanion = ( void _validateAppleCompanion( _AppleCompanionContract contract, Directory consumerRoot, + Directory packageRoot, BuildOutputBuilder output, Logger log, ) { - final companionVersion = contract.companionVersion; - final requiredCompanion = companionVersion == null - ? 'Resolve ${contract.packageName} with a Package.swift pin matching ' - '${contract.nativeRepository}@${contract.nativeTag} and rerun ' - 'flutter pub get. ' - : 'Depend on `${contract.packageName}: ^$companionVersion`, the first ' - 'release pinning ${contract.nativeRepository}@' - '${contract.nativeTag}, in pubspec.yaml and rerun flutter pub ' - 'get; a caret constraint on an earlier 0.0.x release never ' - 'resolves it. '; + final coreVersion = _corePackageVersion(packageRoot); + final nativePin = '${contract.nativeRepository}@${contract.nativeTag}'; + final requiredCompanion = + appleCompanionRequirement( + packageName: contract.packageName, + coreVersion: coreVersion, + nativePin: nativePin, + firstPinningRelease: contract.companionVersion, + ) ?? + 'Resolve ${contract.packageName} with a Package.swift pin matching ' + '$nativePin and rerun flutter pub get.'; Never reject(String reason) => throw StateError( 'Incompatible Apple ${contract.label} companion: $reason ' - '$requiredCompanion' + '$requiredCompanion ' 'Upgrade the core and companion together to a matching released pair; ' 'native tag/path overrides do not replace SPM frameworks. ' 'No in-process native asset was emitted.', @@ -859,12 +870,18 @@ void _validateAppleCompanion( } final missing = contract.compatibleTags[pinnedTag]; if (missing != null) { + final constraint = appleCompanionConstraint( + coreVersion, + firstPinningRelease: contract.companionVersion, + ); + final next = constraint == null + ? 'Upgrade ${contract.packageName} to a release pinning' + : 'Depend on `${contract.packageName}: $constraint` to link'; final upgrade = 'Resolved ${contract.packageName} ${metadata['version']} pins ' '${contract.nativeRepository}@$pinnedTag, an earlier build of the ' 'same ${contract.label} runtime as ${contract.nativeTag}, so this ' - 'build links it. Its frameworks lack $missing. Depend on ' - '`${contract.packageName}: ^${contract.companionVersion}` to link ' + 'build links it. Its frameworks lack $missing. $next ' '${contract.nativeTag}.'; log.warning(upgrade); stderr.writeln('warning: llamadart: $upgrade'); @@ -876,6 +893,23 @@ void _validateAppleCompanion( } } +/// This core's pubspec `version`, which decides the companion constraint a +/// build error or warning names, or `null` when it cannot be read. +/// +/// It is not a build dependency: a cached build emits no error or warning. +String? _corePackageVersion(Directory packageRoot) { + final pubspec = File(path.join(packageRoot.path, 'pubspec.yaml')); + try { + final metadata = loadYaml(pubspec.readAsStringSync()); + final version = metadata is Map ? metadata['version'] : null; + return version is String ? version : null; + } on FileSystemException { + return null; + } on FormatException { + return null; + } +} + /// The root of the one [packageName] the consumer's nearest /// `.dart_tool/package_config.json` resolves; [reject] reports why there is /// none. diff --git a/lib/src/hook/apple_companion_constraint.dart b/lib/src/hook/apple_companion_constraint.dart new file mode 100644 index 000000000..eaab5e198 --- /dev/null +++ b/lib/src/hook/apple_companion_constraint.dart @@ -0,0 +1,75 @@ +/// The Apple companion dependency `hook/build.dart` tells an app to declare. +library; + +/// The first core `MAJOR.MINOR` whose Apple companions share it. +/// +/// Companions paired with an earlier core are numbered `0.0.x`. +const appleCompanionLockstepStart = (major: 0, minor: 13); + +final RegExp _coreVersionPattern = RegExp( + r'^(\d+)\.(\d+)\.\d+(?:[-+][0-9A-Za-z.-]+)?$', +); + +({int major, int minor})? _coreMinor(String? coreVersion) { + final match = coreVersion == null + ? null + : _coreVersionPattern.firstMatch(coreVersion); + if (match == null) return null; + return (major: int.parse(match[1]!), minor: int.parse(match[2]!)); +} + +bool _isLockstep(({int major, int minor}) core) => + core.major > appleCompanionLockstepStart.major || + (core.major == appleCompanionLockstepStart.major && + core.minor >= appleCompanionLockstepStart.minor); + +/// The pubspec constraint that resolves an Apple companion core +/// [coreVersion] pairs with, or `null` when there is none to name. +/// +/// From [appleCompanionLockstepStart] on, that is the core's own minor: +/// `^0.MINOR.0`, or `'>=MAJOR.MINOR.0 =${core.major}.${core.minor}.0 " + "<${core.major}.${core.minor + 1}.0'"; + } + return firstPinningRelease == null ? null : '^$firstPinningRelease'; +} + +/// The sentence an incompatible Apple companion build error uses to tell the +/// app which [packageName] release to depend on, or `null` when +/// [appleCompanionConstraint] names none. +/// +/// [nativePin] is the `repository@tag` the core requires; an earlier core's +/// sentence names it. +String? appleCompanionRequirement({ + required String packageName, + required String? coreVersion, + required String nativePin, + String? firstPinningRelease, +}) { + final constraint = appleCompanionConstraint( + coreVersion, + firstPinningRelease: firstPinningRelease, + ); + if (constraint == null) return null; + final core = _coreMinor(coreVersion)!; + if (_isLockstep(core)) { + return 'Depend on `$packageName: $constraint`, the releases paired with ' + 'core ${core.major}.${core.minor}.x, in pubspec.yaml and rerun ' + 'flutter pub get.'; + } + return 'Depend on `$packageName: $constraint`, the first release pinning ' + '$nativePin, in pubspec.yaml and rerun flutter pub get; a caret ' + 'constraint on an earlier 0.0.x release never resolves it.'; +} diff --git a/lib/src/hook/native_release_pins.dart b/lib/src/hook/native_release_pins.dart index 746a035d0..e3a428f94 100644 --- a/lib/src/hook/native_release_pins.dart +++ b/lib/src/hook/native_release_pins.dart @@ -10,9 +10,10 @@ const llamaCppTag = 'v0.6.0-3'; /// The first `llamadart_llama_cpp_flutter` release whose `Package.swift` pins /// [llamaCppTag]. /// -/// An incompatible-companion build error names it, because a caret constraint -/// on an earlier `0.0.x` companion can never resolve it. The native pin sync -/// sets it whenever it moves the companion pin. +/// A core before `appleCompanionLockstepStart` names it in incompatible- +/// companion build errors, because a caret constraint on an earlier `0.0.x` +/// companion can never resolve it; a later core names its own minor instead. +/// The native pin sync sets it whenever it moves the companion pin. const llamaCppAppleCompanionVersion = '0.0.23'; /// Earlier `leehack/llamadart-native` tags that a published Apple llama.cpp diff --git a/test/support/hook_core_version.dart b/test/support/hook_core_version.dart new file mode 100644 index 000000000..db78d82ba --- /dev/null +++ b/test/support/hook_core_version.dart @@ -0,0 +1,28 @@ +import 'dart:io'; + +import 'package:path/path.dart' as path; +import 'package:test/test.dart'; + +/// The `version` this checkout's core `pubspec.yaml` declares. +String readCheckoutCoreVersion() => RegExp( + r'^version:\s*(\S+)\s*$', + multiLine: true, +).firstMatch(File('pubspec.yaml').readAsStringSync())!.group(1)!; + +/// Runs [body] with the build hook's package root at a core declaring +/// [coreVersion], or at this checkout when it is `null`. +/// +/// `testCodeBuildHook` takes the package root from [Directory.current], so +/// this overrides it for [body] alone. +Future withHookCoreVersion( + String? coreVersion, + Future Function() body, +) async { + if (coreVersion == null) return body(); + final root = await Directory.systemTemp.createTemp('llamadart_core_'); + addTearDown(() => root.deleteSync(recursive: true)); + File( + path.join(root.path, 'pubspec.yaml'), + ).writeAsStringSync('name: llamadart\nversion: $coreVersion\n'); + return IOOverrides.runZoned(body, getCurrentDirectory: () => root); +} diff --git a/test/unit/hook/apple_companion_constraint_test.dart b/test/unit/hook/apple_companion_constraint_test.dart new file mode 100644 index 000000000..1244cc7f6 --- /dev/null +++ b/test/unit/hook/apple_companion_constraint_test.dart @@ -0,0 +1,90 @@ +@TestOn('vm') +library; + +import 'package:llamadart/src/hook/apple_companion_constraint.dart'; +import 'package:test/test.dart'; + +const _nativePin = 'leehack/llamadart-native@v0.6.0-3'; + +String? _requirement(String? coreVersion, {String? firstPinningRelease}) => + appleCompanionRequirement( + packageName: 'llamadart_llama_cpp_flutter', + coreVersion: coreVersion, + nativePin: _nativePin, + firstPinningRelease: firstPinningRelease, + ); + +void main() { + group('appleCompanionConstraint', () { + test('a core before lockstep names the first pinning 0.0.x release', () { + for (final core in ['0.12.0', '0.12.2', '0.9.1']) { + expect( + appleCompanionConstraint(core, firstPinningRelease: '0.0.23'), + '^0.0.23', + reason: core, + ); + expect(appleCompanionConstraint(core), isNull, reason: core); + } + }); + + test('a lockstep core names its own minor, never a 0.0.x release', () { + for (final (core, expected) in [ + ('0.13.0', '^0.13.0'), + ('0.13.4', '^0.13.0'), + ('0.14.1', '^0.14.0'), + ]) { + for (final firstPinning in [null, '0.0.23']) { + expect( + appleCompanionConstraint(core, firstPinningRelease: firstPinning), + expected, + reason: '$core with $firstPinning', + ); + } + } + }); + + test('a 1.x core names a range a caret would widen', () { + expect(appleCompanionConstraint('1.2.3'), "'>=1.2.0 <1.3.0'"); + }); + + test('an unreadable core version names nothing', () { + for (final core in [null, '', 'latest', '0.13']) { + expect( + appleCompanionConstraint(core, firstPinningRelease: '0.0.23'), + isNull, + reason: core, + ); + } + }); + }); + + group('appleCompanionRequirement', () { + test('core 0.12.x names the first release pinning the native tag', () { + expect( + _requirement('0.12.2', firstPinningRelease: '0.0.23'), + 'Depend on `llamadart_llama_cpp_flutter: ^0.0.23`, the first release ' + 'pinning $_nativePin, in pubspec.yaml and rerun flutter pub get; a ' + 'caret constraint on an earlier 0.0.x release never resolves it.', + ); + }); + + test('core 0.13.x names the companions of its minor', () { + for (final core in ['0.13.0', '0.13.2']) { + final requirement = _requirement(core, firstPinningRelease: '0.0.23'); + expect( + requirement, + 'Depend on `llamadart_llama_cpp_flutter: ^0.13.0`, the releases ' + 'paired with core 0.13.x, in pubspec.yaml and rerun flutter pub ' + 'get.', + reason: core, + ); + expect(requirement, isNot(contains('0.0.')), reason: core); + } + }); + + test('names nothing when no constraint is known', () { + expect(_requirement('0.12.2'), isNull); + expect(_requirement(null, firstPinningRelease: '0.0.23'), isNull); + }); + }); +} diff --git a/test/unit/hook/build_hook_litert_lm_integration_test.dart b/test/unit/hook/build_hook_litert_lm_integration_test.dart index 3e1bdbc98..81080da83 100644 --- a/test/unit/hook/build_hook_litert_lm_integration_test.dart +++ b/test/unit/hook/build_hook_litert_lm_integration_test.dart @@ -6,12 +6,14 @@ import 'dart:io'; import 'package:code_assets/code_assets.dart'; import 'package:hooks/hooks.dart'; +import 'package:llamadart/src/hook/apple_companion_constraint.dart'; import 'package:llamadart/src/hook/native_release_pins.dart'; import 'package:logging/logging.dart'; import 'package:path/path.dart' as path; import 'package:test/test.dart'; import '../../../hook/build.dart' as build_hook; +import '../../support/hook_core_version.dart'; void main() { final nativeTag = _readPinnedConst('llamaCppTag'); @@ -393,45 +395,85 @@ void main() { ); } + // The checkout core's guidance comes from the helper; the fixed cores pin + // the literal text, so a hook that stops reading its own version, or names + // a 0.0.x companion from a lockstep core, fails. + final checkoutCore = readCheckoutCoreVersion(); + final coreConstraints = { + null: appleCompanionConstraint( + checkoutCore, + firstPinningRelease: llamaCppAppleCompanionVersion, + )!, + '0.12.2': '^$llamaCppAppleCompanionVersion', + '0.13.0': '^0.13.0', + '0.13.3': '^0.13.0', + }; + final coreRequirements = { + null: appleCompanionRequirement( + packageName: 'llamadart_llama_cpp_flutter', + coreVersion: checkoutCore, + nativePin: 'leehack/llamadart-native@$llamaCppTag', + firstPinningRelease: llamaCppAppleCompanionVersion, + )!, + '0.12.2': + 'Depend on `llamadart_llama_cpp_flutter: ' + '^$llamaCppAppleCompanionVersion`, the first release pinning ' + 'leehack/llamadart-native@$llamaCppTag, in pubspec.yaml and rerun ' + 'flutter pub get; a caret constraint on an earlier 0.0.x release ' + 'never resolves it.', + for (final core in ['0.13.0', '0.13.3']) + core: + 'Depend on `llamadart_llama_cpp_flutter: ^0.13.0`, the releases ' + 'paired with core 0.13.x, in pubspec.yaml and rerun flutter pub ' + 'get.', + }; + String coreLabel(String? core) => core ?? 'checkout $checkoutCore'; + for (final target in [OS.iOS, OS.macOS]) { for (final MapEntry(key: tag, value: missing) in llamaCppCompatibleAppleCompanionTags.entries) { - test('Apple $target links a companion pinning compatible $tag with an ' - 'upgrade warning', () async { - final records = []; - final subscription = Logger.root.onRecord.listen( - (record) => records.add(record.message), - ); - addTearDown(subscription.cancel); - final defines = await _flutterAppleUserDefines( - dependencies: const ['llamadart_llama_cpp_flutter'], - companionTag: tag, - companionVersion: '0.0.22', - ); - final stderrLines = await _capturingStderr( - () => testCodeBuildHook( - mainMethod: build_hook.main, - targetOS: target, - targetArchitecture: Architecture.arm64, - targetIOSSdk: target == OS.iOS ? IOSSdk.iPhoneOS : null, - userDefines: defines, - check: (_, output) { - final asset = output.assets.encodedAssets.single.asCodeAsset; - expect(asset.id, 'package:llamadart/llamadart'); - expect(asset.linkMode, isA()); - }, - ), - ); - final warning = - 'Resolved llamadart_llama_cpp_flutter 0.0.22 pins ' - 'leehack/llamadart-native@$tag, an earlier build of the same ' - 'llama.cpp runtime as $llamaCppTag, so this build links it. ' - 'Its frameworks lack $missing. Depend on ' - '`llamadart_llama_cpp_flutter: ^$llamaCppAppleCompanionVersion` ' - 'to link $llamaCppTag.'; - expect(stderrLines, contains('warning: llamadart: $warning')); - expect(records, contains(warning)); - }); + for (final MapEntry(key: core, value: constraint) + in coreConstraints.entries) { + test('Apple $target core ${coreLabel(core)} links a companion pinning ' + 'compatible $tag and names `$constraint`', () async { + final records = []; + final subscription = Logger.root.onRecord.listen( + (record) => records.add(record.message), + ); + addTearDown(subscription.cancel); + final defines = await _flutterAppleUserDefines( + dependencies: const ['llamadart_llama_cpp_flutter'], + companionTag: tag, + companionVersion: '0.0.22', + ); + final stderrLines = await _capturingStderr( + () => withHookCoreVersion( + core, + () => testCodeBuildHook( + mainMethod: build_hook.main, + targetOS: target, + targetArchitecture: Architecture.arm64, + targetIOSSdk: target == OS.iOS ? IOSSdk.iPhoneOS : null, + userDefines: defines, + check: (_, output) { + final asset = output.assets.encodedAssets.single.asCodeAsset; + expect(asset.id, 'package:llamadart/llamadart'); + expect(asset.linkMode, isA()); + }, + ), + ), + ); + final warning = + 'Resolved llamadart_llama_cpp_flutter 0.0.22 pins ' + 'leehack/llamadart-native@$tag, an earlier build of the same ' + 'llama.cpp runtime as $llamaCppTag, so this build links it. ' + 'Its frameworks lack $missing. Depend on ' + '`llamadart_llama_cpp_flutter: $constraint` to link ' + '$llamaCppTag.'; + expect(stderrLines, contains('warning: llamadart: $warning')); + expect(records, contains(warning)); + }); + } test('Apple $target still rejects local Artifacts beside compatible ' '$tag', () async { @@ -495,39 +537,42 @@ void main() { }); for (final tag in ['v0.6.0-1', 'v0.6.0-4', 'v0.5.0-2']) { - test('Apple $target rejects unlisted companion pin $tag and names the ' - 'companion release to depend on', () async { - final defines = await _flutterAppleUserDefines( - dependencies: const ['llamadart_llama_cpp_flutter'], - companionTag: tag, - companionVersion: '0.0.22', - ); - var emitted = false; - await expectLater( - testCodeBuildHook( - mainMethod: build_hook.main, - targetOS: target, - targetArchitecture: Architecture.arm64, - targetIOSSdk: target == OS.iOS ? IOSSdk.iPhoneOS : null, - userDefines: defines, - check: (_, _) => emitted = true, - ), - throwsA( - predicate( - (error) => error.toString().contains( - 'Incompatible Apple llama.cpp companion: Resolved companion ' - '0.0.22 does not uniquely pin the required native runtime ' - '$llamaCppTag. Depend on `llamadart_llama_cpp_flutter: ' - '^$llamaCppAppleCompanionVersion`, the first release ' - 'pinning leehack/llamadart-native@$llamaCppTag, in ' - 'pubspec.yaml and rerun flutter pub get; a caret ' - 'constraint on an earlier 0.0.x release never resolves it.', + for (final MapEntry(key: core, value: requirement) + in coreRequirements.entries) { + test('Apple $target core ${coreLabel(core)} rejects unlisted companion ' + 'pin $tag and names the companion release to depend on', () async { + final defines = await _flutterAppleUserDefines( + dependencies: const ['llamadart_llama_cpp_flutter'], + companionTag: tag, + companionVersion: '0.0.22', + ); + var emitted = false; + await expectLater( + withHookCoreVersion( + core, + () => testCodeBuildHook( + mainMethod: build_hook.main, + targetOS: target, + targetArchitecture: Architecture.arm64, + targetIOSSdk: target == OS.iOS ? IOSSdk.iPhoneOS : null, + userDefines: defines, + check: (_, _) => emitted = true, ), ), - ), - ); - expect(emitted, isFalse); - }); + throwsA( + predicate( + (error) => error.toString().contains( + 'Incompatible Apple llama.cpp companion: Resolved companion ' + '0.0.22 does not uniquely pin the required native runtime ' + '$llamaCppTag. $requirement Upgrade the core and companion ' + 'together', + ), + ), + ), + ); + expect(emitted, isFalse); + }); + } } } diff --git a/test/unit/hook/build_hook_stable_diffusion_integration_test.dart b/test/unit/hook/build_hook_stable_diffusion_integration_test.dart index 8cab7ca0b..ec00f53a6 100644 --- a/test/unit/hook/build_hook_stable_diffusion_integration_test.dart +++ b/test/unit/hook/build_hook_stable_diffusion_integration_test.dart @@ -13,6 +13,7 @@ import 'package:test/test.dart'; import 'package:llamadart/src/hook/native_release_pins.dart'; import '../../../hook/build.dart' as build_hook; +import '../../support/hook_core_version.dart'; import '../../support/hooks_runner_layout.dart'; const _stableDiffusionAssetId = 'package:llamadart/stable_diffusion'; @@ -806,6 +807,53 @@ dependencies: }, ); } + + for (final (core, requirement) in [ + ( + '0.12.2', + 'Resolve llamadart_stable_diffusion_flutter with a Package.swift pin ' + 'matching leehack/stable-diffusion-native@$stableDiffusionReleaseTag ' + 'and rerun flutter pub get.', + ), + ( + '0.13.0', + 'Depend on `llamadart_stable_diffusion_flutter: ^0.13.0`, the releases ' + 'paired with core 0.13.x, in pubspec.yaml and rerun flutter pub ' + 'get.', + ), + ]) { + test('core $core: the stable_diffusion companion rejection names the ' + 'release to depend on', () async { + final defines = await _flutterAppleApp( + companions: const [_stableDiffusionCompanionName], + editManifest: (manifest) => manifest.replaceFirst( + 'let stableDiffusionTag = "$stableDiffusionReleaseTag"', + 'let stableDiffusionTag = "v0.1.1"', + ), + ); + await expectLater( + withHookCoreVersion( + core, + () => testCodeBuildHook( + mainMethod: build_hook.main, + targetOS: OS.iOS, + targetArchitecture: Architecture.arm64, + targetIOSSdk: IOSSdk.iPhoneOS, + userDefines: defines, + check: (_, _) => fail('Must not emit in-process assets'), + ), + ), + throwsA( + predicate( + (error) => error.toString().contains( + 'the required native runtime $stableDiffusionReleaseTag. ' + '$requirement Upgrade the core and companion together', + ), + ), + ), + ); + }); + } } const _impliedSkipWarning = diff --git a/tool/testing/verify_release_docs_versions.dart b/tool/testing/verify_release_docs_versions.dart index f0d28c4e8..4e5b3e02f 100644 --- a/tool/testing/verify_release_docs_versions.dart +++ b/tool/testing/verify_release_docs_versions.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'dart:io'; +import 'package:llamadart/src/hook/apple_companion_constraint.dart'; import 'package:llamadart/src/hook/native_bundle_config.dart'; import 'package:llamadart/src/hook/native_release_pins.dart'; import 'package:pub_semver/pub_semver.dart'; @@ -398,8 +399,14 @@ List checkCompanionCoreConstraints( /// The first core release whose companions share its `MAJOR.MINOR`. /// /// Earlier companions are numbered `0.0.x` and stay valid beside an earlier -/// core, so the check starts with the release that renumbers them. -final Version companionVersionAlignmentStart = Version(0, 13, 0); +/// core, so the check starts with the release that renumbers them. It is the +/// hook's [appleCompanionLockstepStart], so the companion constraint a build +/// error names always admits the companion this check aligns. +final Version companionVersionAlignmentStart = Version( + appleCompanionLockstepStart.major, + appleCompanionLockstepStart.minor, + 0, +); /// Checks that every companion's `version` shares [coreVersion]'s /// `MAJOR.MINOR`, from [companionVersionAlignmentStart] on. diff --git a/website/docs/changelog/recent-releases.md b/website/docs/changelog/recent-releases.md index 3f556c660..cb9f8730f 100644 --- a/website/docs/changelog/recent-releases.md +++ b/website/docs/changelog/recent-releases.md @@ -9,6 +9,11 @@ For canonical full release notes, use: ## Unreleased +- From core `0.13.0`, the Flutter Apple build error or warning for a + mismatched or earlier-build llama.cpp companion names the companion release + of the core's own minor, such as `^0.13.0`, instead of the first `0.0.x` + release pinning the native runtime; the stable_diffusion companion error + names one too. - A chat template that fails to render now names its source in the `LlamaInferenceException` message: the model's `tokenizer.chat_template` or its `tool_use` variant, `ModelParams.chatTemplate`, or `customTemplate` From 776516f96f8de9d107f4b09d2f2d7b6edf6440c5 Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Thu, 15 Oct 2026 12:48:36 -0400 Subject: [PATCH 2/3] fix(hook): name a same-minor first pinning companion and share lockstep precedence A lockstep core now names the first companion release pinning its native tag when that release shares the core MAJOR.MINOR, so a pin moved inside a minor no longer yields a ^M.m.0 hint that pub get already satisfies. The hook and the release docs verifier decide lockstep with one semver predicate, which places 0.13.0 prereleases before lockstep. The native pin sync test records the next same-minor companion for a lockstep companion. --- hook/build.dart | 6 +- lib/src/hook/apple_companion_constraint.dart | 83 ++++++++++++------- lib/src/hook/native_release_pins.dart | 10 ++- .../hook/apple_companion_constraint_test.dart | 72 ++++++++++++++-- ...build_hook_litert_lm_integration_test.dart | 22 ++--- ...ook_stable_diffusion_integration_test.dart | 7 +- ...e_docs_companion_core_constraint_test.dart | 24 ++++++ tool/native/test_sync_native_release_pins.py | 31 +++++++ .../testing/verify_release_docs_versions.dart | 21 ++--- 9 files changed, 203 insertions(+), 73 deletions(-) diff --git a/hook/build.dart b/hook/build.dart index 268c4da8b..a9f253095 100644 --- a/hook/build.dart +++ b/hook/build.dart @@ -735,9 +735,9 @@ _AppleCompanions? _flutterAppleCompanions({ /// its SwiftPM framework: the companion pins [nativeRepository]@[nativeTag] /// through `let [tagVariable]` in the maintained manifest template. /// [compatibleTags] maps earlier tags accepted with a warning to what their -/// frameworks lack. [companionVersion] is the first `0.0.x` companion release -/// pinning [nativeTag], when the core records it; only a core before -/// [appleCompanionLockstepStart] names it. +/// frameworks lack. [companionVersion] is the first companion release pinning +/// [nativeTag], when the core records it; [appleCompanionConstraint] decides +/// whether a build error names it. typedef _AppleCompanionContract = ({ String label, String packageName, diff --git a/lib/src/hook/apple_companion_constraint.dart b/lib/src/hook/apple_companion_constraint.dart index eaab5e198..b20f605e4 100644 --- a/lib/src/hook/apple_companion_constraint.dart +++ b/lib/src/hook/apple_companion_constraint.dart @@ -6,52 +6,75 @@ library; /// Companions paired with an earlier core are numbered `0.0.x`. const appleCompanionLockstepStart = (major: 0, minor: 13); -final RegExp _coreVersionPattern = RegExp( - r'^(\d+)\.(\d+)\.\d+(?:[-+][0-9A-Za-z.-]+)?$', +final RegExp _versionPattern = RegExp( + r'^(\d+)\.(\d+)\.(\d+)(-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$', ); -({int major, int minor})? _coreMinor(String? coreVersion) { - final match = coreVersion == null - ? null - : _coreVersionPattern.firstMatch(coreVersion); +typedef _Version = ({int major, int minor, int patch, bool prerelease}); + +_Version? _parse(String? version) { + final match = version == null ? null : _versionPattern.firstMatch(version); if (match == null) return null; - return (major: int.parse(match[1]!), minor: int.parse(match[2]!)); + return ( + major: int.parse(match[1]!), + minor: int.parse(match[2]!), + patch: int.parse(match[3]!), + prerelease: match[4] != null, + ); } -bool _isLockstep(({int major, int minor}) core) => - core.major > appleCompanionLockstepStart.major || - (core.major == appleCompanionLockstepStart.major && - core.minor >= appleCompanionLockstepStart.minor); +bool _isLockstep(_Version core) { + const start = appleCompanionLockstepStart; + if (core.major != start.major) return core.major > start.major; + if (core.minor != start.minor) return core.minor > start.minor; + // A prerelease of the first lockstep version precedes it. + return core.patch > 0 || !core.prerelease; +} + +/// Whether core [coreVersion] is at or after `appleCompanionLockstepStart.0` +/// in semver precedence, so its Apple companions share its `MAJOR.MINOR`. +/// +/// A prerelease of that first version, such as `0.13.0-dev.1`, is not; a +/// [coreVersion] that is not a version is not either. +bool isAppleCompanionLockstepCore(String coreVersion) { + final core = _parse(coreVersion); + return core != null && _isLockstep(core); +} /// The pubspec constraint that resolves an Apple companion core -/// [coreVersion] pairs with, or `null` when there is none to name. +/// [coreVersion] accepts, or `null` when there is none to name. /// -/// From [appleCompanionLockstepStart] on, that is the core's own minor: -/// `^0.MINOR.0`, or `'>=MAJOR.MINOR.0 =FROM =${core.major}.${core.minor}.0 " - "<${core.major}.${core.minor + 1}.0'"; + if (!_isLockstep(core)) { + return firstPinningRelease == null ? null : '^$firstPinningRelease'; } - return firstPinningRelease == null ? null : '^$firstPinningRelease'; + final first = _parse(firstPinningRelease); + final from = + first != null && first.major == core.major && first.minor == core.minor + ? firstPinningRelease! + : '${core.major}.${core.minor}.0'; + return core.major == 0 + ? '^$from' + : "'>=$from <${core.major}.${core.minor + 1}.0'"; } /// The sentence an incompatible Apple companion build error uses to tell the /// app which [packageName] release to depend on, or `null` when /// [appleCompanionConstraint] names none. /// -/// [nativePin] is the `repository@tag` the core requires; an earlier core's -/// sentence names it. +/// [nativePin] is the `repository@tag` the core requires. String? appleCompanionRequirement({ required String packageName, required String? coreVersion, @@ -63,11 +86,11 @@ String? appleCompanionRequirement({ firstPinningRelease: firstPinningRelease, ); if (constraint == null) return null; - final core = _coreMinor(coreVersion)!; + final core = _parse(coreVersion)!; if (_isLockstep(core)) { - return 'Depend on `$packageName: $constraint`, the releases paired with ' - 'core ${core.major}.${core.minor}.x, in pubspec.yaml and rerun ' - 'flutter pub get.'; + return 'Depend on `$packageName: $constraint`, the core ' + '${core.major}.${core.minor}.x companion releases pinning $nativePin, ' + 'in pubspec.yaml and rerun flutter pub get.'; } return 'Depend on `$packageName: $constraint`, the first release pinning ' '$nativePin, in pubspec.yaml and rerun flutter pub get; a caret ' diff --git a/lib/src/hook/native_release_pins.dart b/lib/src/hook/native_release_pins.dart index e3a428f94..fc7399bae 100644 --- a/lib/src/hook/native_release_pins.dart +++ b/lib/src/hook/native_release_pins.dart @@ -10,10 +10,12 @@ const llamaCppTag = 'v0.6.0-3'; /// The first `llamadart_llama_cpp_flutter` release whose `Package.swift` pins /// [llamaCppTag]. /// -/// A core before `appleCompanionLockstepStart` names it in incompatible- -/// companion build errors, because a caret constraint on an earlier `0.0.x` -/// companion can never resolve it; a later core names its own minor instead. -/// The native pin sync sets it whenever it moves the companion pin. +/// Incompatible-companion build errors name it, because a caret constraint on +/// an earlier companion can never resolve it. A core from +/// `appleCompanionLockstepStart` on names it only when it shares the core's +/// `MAJOR.MINOR`, and its own minor's first release otherwise. The native pin +/// sync sets it to the companion's next release whenever it moves the +/// companion pin. const llamaCppAppleCompanionVersion = '0.0.23'; /// Earlier `leehack/llamadart-native` tags that a published Apple llama.cpp diff --git a/test/unit/hook/apple_companion_constraint_test.dart b/test/unit/hook/apple_companion_constraint_test.dart index 1244cc7f6..c9918b62e 100644 --- a/test/unit/hook/apple_companion_constraint_test.dart +++ b/test/unit/hook/apple_companion_constraint_test.dart @@ -27,13 +27,15 @@ void main() { } }); - test('a lockstep core names its own minor, never a 0.0.x release', () { + test('a lockstep core names its minor\'s first release when the pin ' + 'predates the minor', () { for (final (core, expected) in [ ('0.13.0', '^0.13.0'), ('0.13.4', '^0.13.0'), ('0.14.1', '^0.14.0'), ]) { - for (final firstPinning in [null, '0.0.23']) { + for (final firstPinning in [null, '0.0.23', '0.13.1']) { + if (firstPinning == '0.13.1' && core.startsWith('0.13.')) continue; expect( appleCompanionConstraint(core, firstPinningRelease: firstPinning), expected, @@ -43,8 +45,49 @@ void main() { } }); + test('a lockstep core names the first same-minor release pinning its ' + 'tag', () { + for (final (core, first) in [ + ('0.13.2', '0.13.1'), + ('0.13.1', '0.13.1'), + ('0.14.0', '0.14.0'), + ]) { + expect( + appleCompanionConstraint(core, firstPinningRelease: first), + '^$first', + reason: '$core with $first', + ); + } + }); + test('a 1.x core names a range a caret would widen', () { expect(appleCompanionConstraint('1.2.3'), "'>=1.2.0 <1.3.0'"); + expect( + appleCompanionConstraint('1.2.3', firstPinningRelease: '1.2.1'), + "'>=1.2.1 <1.3.0'", + ); + expect( + appleCompanionConstraint('1.2.3', firstPinningRelease: '1.1.4'), + "'>=1.2.0 <1.3.0'", + ); + }); + + test('a prerelease of the first lockstep core precedes lockstep', () { + expect( + appleCompanionConstraint('0.13.0-dev.1', firstPinningRelease: '0.0.23'), + '^0.0.23', + ); + for (final (core, expected) in [ + ('0.13.0+build.1', '^0.13.0'), + ('0.13.1-dev.1', '^0.13.0'), + ('0.14.0-dev.1', '^0.14.0'), + ]) { + expect( + appleCompanionConstraint(core, firstPinningRelease: '0.0.23'), + expected, + reason: core, + ); + } }); test('an unreadable core version names nothing', () { @@ -69,14 +112,18 @@ void main() { }); test('core 0.13.x names the companions of its minor', () { - for (final core in ['0.13.0', '0.13.2']) { - final requirement = _requirement(core, firstPinningRelease: '0.0.23'); + for (final (core, first, constraint) in [ + ('0.13.0', '0.0.23', '^0.13.0'), + ('0.13.2', '0.0.23', '^0.13.0'), + ('0.13.2', '0.13.1', '^0.13.1'), + ]) { + final requirement = _requirement(core, firstPinningRelease: first); expect( requirement, - 'Depend on `llamadart_llama_cpp_flutter: ^0.13.0`, the releases ' - 'paired with core 0.13.x, in pubspec.yaml and rerun flutter pub ' - 'get.', - reason: core, + 'Depend on `llamadart_llama_cpp_flutter: $constraint`, the core ' + '0.13.x companion releases pinning $_nativePin, in pubspec.yaml and ' + 'rerun flutter pub get.', + reason: '$core with $first', ); expect(requirement, isNot(contains('0.0.')), reason: core); } @@ -87,4 +134,13 @@ void main() { expect(_requirement(null, firstPinningRelease: '0.0.23'), isNull); }); }); + + test('isAppleCompanionLockstepCore follows semver precedence', () { + for (final core in ['0.13.0', '0.13.0+build.1', '0.13.1-dev.1', '1.0.0']) { + expect(isAppleCompanionLockstepCore(core), isTrue, reason: core); + } + for (final core in ['0.12.9', '0.13.0-dev.1', '0.0.23', 'latest', '']) { + expect(isAppleCompanionLockstepCore(core), isFalse, reason: core); + } + }); } diff --git a/test/unit/hook/build_hook_litert_lm_integration_test.dart b/test/unit/hook/build_hook_litert_lm_integration_test.dart index 81080da83..f247fbc61 100644 --- a/test/unit/hook/build_hook_litert_lm_integration_test.dart +++ b/test/unit/hook/build_hook_litert_lm_integration_test.dart @@ -404,7 +404,8 @@ void main() { checkoutCore, firstPinningRelease: llamaCppAppleCompanionVersion, )!, - '0.12.2': '^$llamaCppAppleCompanionVersion', + for (final core in ['0.12.2', '0.13.0-dev.1']) + core: '^$llamaCppAppleCompanionVersion', '0.13.0': '^0.13.0', '0.13.3': '^0.13.0', }; @@ -415,17 +416,18 @@ void main() { nativePin: 'leehack/llamadart-native@$llamaCppTag', firstPinningRelease: llamaCppAppleCompanionVersion, )!, - '0.12.2': - 'Depend on `llamadart_llama_cpp_flutter: ' - '^$llamaCppAppleCompanionVersion`, the first release pinning ' - 'leehack/llamadart-native@$llamaCppTag, in pubspec.yaml and rerun ' - 'flutter pub get; a caret constraint on an earlier 0.0.x release ' - 'never resolves it.', + for (final core in ['0.12.2', '0.13.0-dev.1']) + core: + 'Depend on `llamadart_llama_cpp_flutter: ' + '^$llamaCppAppleCompanionVersion`, the first release pinning ' + 'leehack/llamadart-native@$llamaCppTag, in pubspec.yaml and rerun ' + 'flutter pub get; a caret constraint on an earlier 0.0.x release ' + 'never resolves it.', for (final core in ['0.13.0', '0.13.3']) core: - 'Depend on `llamadart_llama_cpp_flutter: ^0.13.0`, the releases ' - 'paired with core 0.13.x, in pubspec.yaml and rerun flutter pub ' - 'get.', + 'Depend on `llamadart_llama_cpp_flutter: ^0.13.0`, the core 0.13.x ' + 'companion releases pinning leehack/llamadart-native@$llamaCppTag, ' + 'in pubspec.yaml and rerun flutter pub get.', }; String coreLabel(String? core) => core ?? 'checkout $checkoutCore'; diff --git a/test/unit/hook/build_hook_stable_diffusion_integration_test.dart b/test/unit/hook/build_hook_stable_diffusion_integration_test.dart index ec00f53a6..7b6e16043 100644 --- a/test/unit/hook/build_hook_stable_diffusion_integration_test.dart +++ b/test/unit/hook/build_hook_stable_diffusion_integration_test.dart @@ -817,9 +817,10 @@ dependencies: ), ( '0.13.0', - 'Depend on `llamadart_stable_diffusion_flutter: ^0.13.0`, the releases ' - 'paired with core 0.13.x, in pubspec.yaml and rerun flutter pub ' - 'get.', + 'Depend on `llamadart_stable_diffusion_flutter: ^0.13.0`, the core ' + '0.13.x companion releases pinning ' + 'leehack/stable-diffusion-native@$stableDiffusionReleaseTag, in ' + 'pubspec.yaml and rerun flutter pub get.', ), ]) { test('core $core: the stable_diffusion companion rejection names the ' diff --git a/test/unit/tooling/verify_release_docs_companion_core_constraint_test.dart b/test/unit/tooling/verify_release_docs_companion_core_constraint_test.dart index 9fa3d9cbd..0e69137a4 100644 --- a/test/unit/tooling/verify_release_docs_companion_core_constraint_test.dart +++ b/test/unit/tooling/verify_release_docs_companion_core_constraint_test.dart @@ -3,6 +3,7 @@ library; import 'dart:io'; +import 'package:llamadart/src/hook/apple_companion_constraint.dart'; import 'package:llamadart/src/hook/native_release_pins.dart'; import 'package:pub_semver/pub_semver.dart'; import 'package:test/test.dart'; @@ -413,6 +414,29 @@ void main() { ); }); + test('starts where the hook names a lockstep companion constraint', () { + final root = companionsAt({}); + + for (final core in [ + '0.12.9', + '0.13.0-dev.1', + '0.13.0', + '0.13.0+build.1', + '0.13.1-dev.1', + '1.0.0', + ]) { + expect( + checkCompanionVersionAlignment(root, Version.parse(core)).isEmpty, + !isAppleCompanionLockstepCore(core), + reason: core, + ); + } + expect( + checkCompanionVersionAlignment(root, Version.parse('0.13.0-dev.1')), + isEmpty, + ); + }); + test('accepts any companion patch within the core minor', () { final root = companionsAt({ _llamaCpp: '0.13.0', diff --git a/tool/native/test_sync_native_release_pins.py b/tool/native/test_sync_native_release_pins.py index 8af30d181..b5e3ba80c 100644 --- a/tool/native/test_sync_native_release_pins.py +++ b/tool/native/test_sync_native_release_pins.py @@ -3243,6 +3243,37 @@ def test_a_pin_move_clears_compatible_tags_and_records_the_companion( self.assertIn("cleared compatible Apple llama.cpp companion tags", result.stdout) self.assertIn("v0.0.1-1", result.stdout) + def test_a_lockstep_pin_move_records_the_next_same_minor_companion( + self, + ) -> None: + # From core 0.13.0 the hook names this constant when it shares the + # core MAJOR.MINOR, so a pin moved inside a minor must record the + # first companion release of that minor that pins it. + current = pins.read_hook_native_tag(self.pins.read_text(encoding="utf-8")) + upstream = pins.parse_native_release_tag(current).upstream_tag + build = int(current.rsplit("-", 1)[1]) if "-" in current else 0 + target = f"{upstream}-{build + 1}" + for extra in ((), ("--bump-companion-versions",)): + with self.subTest(extra=extra): + self.make_repo() + pubspec = self.repo_root / self.COMPANION / "pubspec.yaml" + pubspec.write_text( + pins.replace_pubspec_version( + pubspec.read_text(encoding="utf-8"), "0.13.0", pubspec + ), + encoding="utf-8", + ) + result = self.run_sync(target, *extra) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertIn( + "const llamaCppAppleCompanionVersion = '0.13.1';", + self.pins.read_text(encoding="utf-8"), + ) + self.assertIn( + f"version: {'0.13.1' if extra else '0.13.0'}\n", + pubspec.read_text(encoding="utf-8"), + ) + def test_a_same_tag_resync_keeps_compatible_tags(self) -> None: original = self.pins.read_text(encoding="utf-8") compatible = re.search( diff --git a/tool/testing/verify_release_docs_versions.dart b/tool/testing/verify_release_docs_versions.dart index 4e5b3e02f..59141e392 100644 --- a/tool/testing/verify_release_docs_versions.dart +++ b/tool/testing/verify_release_docs_versions.dart @@ -396,27 +396,18 @@ List checkCompanionCoreConstraints( return errors; } -/// The first core release whose companions share its `MAJOR.MINOR`. -/// -/// Earlier companions are numbered `0.0.x` and stay valid beside an earlier -/// core, so the check starts with the release that renumbers them. It is the -/// hook's [appleCompanionLockstepStart], so the companion constraint a build -/// error names always admits the companion this check aligns. -final Version companionVersionAlignmentStart = Version( - appleCompanionLockstepStart.major, - appleCompanionLockstepStart.minor, - 0, -); - /// Checks that every companion's `version` shares [coreVersion]'s -/// `MAJOR.MINOR`, from [companionVersionAlignmentStart] on. +/// `MAJOR.MINOR` once [isAppleCompanionLockstepCore] holds for it. /// -/// Companion patch numbers move independently of the core's. +/// Earlier companions are numbered `0.0.x` and stay valid beside an earlier +/// core. The hook decides with the same predicate, so the companion +/// constraint a build error names always admits the companion this check +/// aligns. Companion patch numbers move independently of the core's. List checkCompanionVersionAlignment( Directory repoRoot, Version coreVersion, ) { - if (coreVersion < companionVersionAlignmentStart) return const []; + if (!isAppleCompanionLockstepCore('$coreVersion')) return const []; final errors = []; final series = '${coreVersion.major}.${coreVersion.minor}'; for (final companion in companionSwiftPins) { From 3c4c6564b11c718e0e0262af85b0bc2183fd830c Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Thu, 15 Oct 2026 13:15:16 -0400 Subject: [PATCH 3/3] fix(hook): keep the stable_diffusion hint to its native pin No stable_diffusion companion release is recorded as the first to pin its native tag, and the sync can move that pin inside a minor, so a lockstep core must not claim ^M.m.0 pins it. Without a known first pinning release the hook keeps the tag-only guidance. --- CHANGELOG.md | 3 +- lib/src/hook/apple_companion_constraint.dart | 13 ++++--- .../hook/apple_companion_constraint_test.dart | 8 +++-- ...ook_stable_diffusion_integration_test.dart | 34 ++++++++----------- website/docs/changelog/recent-releases.md | 3 +- 5 files changed, 27 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index befbaa7f1..6d5bb55c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,7 @@ - From core `0.13.0`, the Flutter Apple build error or warning for a mismatched or earlier-build llama.cpp companion names the companion release of the core's own minor, such as `^0.13.0`, instead of the first `0.0.x` - release pinning the native runtime; the stable_diffusion companion error - names one too. + release pinning the native runtime. - With `llamadart_litert_lm_flutter` `0.0.15`, the Flutter macOS build now only warns to upgrade the companion to `0.0.16`, the release pinning `v0.18.0-1`, instead of claiming that the app cannot load LiteRT-LM and needs diff --git a/lib/src/hook/apple_companion_constraint.dart b/lib/src/hook/apple_companion_constraint.dart index b20f605e4..bf96fcbc7 100644 --- a/lib/src/hook/apple_companion_constraint.dart +++ b/lib/src/hook/apple_companion_constraint.dart @@ -49,21 +49,20 @@ bool isAppleCompanionLockstepCore(String coreVersion) { /// it shares the core's `MAJOR.MINOR`, because the pin moved within that /// minor, and otherwise the minor's first release: a caret on a 0.x release, /// or `'>=FROM =1.2.0 <1.3.0'"); expect( appleCompanionConstraint('1.2.3', firstPinningRelease: '1.2.1'), "'>=1.2.1 <1.3.0'", @@ -130,7 +129,10 @@ void main() { }); test('names nothing when no constraint is known', () { - expect(_requirement('0.12.2'), isNull); + for (final core in ['0.12.2', '0.13.0', '0.13.2', '1.2.3']) { + expect(appleCompanionConstraint(core), isNull, reason: core); + expect(_requirement(core), isNull, reason: core); + } expect(_requirement(null, firstPinningRelease: '0.0.23'), isNull); }); }); diff --git a/test/unit/hook/build_hook_stable_diffusion_integration_test.dart b/test/unit/hook/build_hook_stable_diffusion_integration_test.dart index 7b6e16043..ba47ffb2e 100644 --- a/test/unit/hook/build_hook_stable_diffusion_integration_test.dart +++ b/test/unit/hook/build_hook_stable_diffusion_integration_test.dart @@ -808,23 +808,15 @@ dependencies: ); } - for (final (core, requirement) in [ - ( - '0.12.2', - 'Resolve llamadart_stable_diffusion_flutter with a Package.swift pin ' - 'matching leehack/stable-diffusion-native@$stableDiffusionReleaseTag ' - 'and rerun flutter pub get.', - ), - ( - '0.13.0', - 'Depend on `llamadart_stable_diffusion_flutter: ^0.13.0`, the core ' - '0.13.x companion releases pinning ' - 'leehack/stable-diffusion-native@$stableDiffusionReleaseTag, in ' - 'pubspec.yaml and rerun flutter pub get.', - ), - ]) { + // No first stable_diffusion companion release pinning the tag is recorded, + // so even a lockstep core must not claim a constraint that pins it. + for (final core in ['0.12.2', '0.13.0', '0.13.2']) { + final requirement = + 'Resolve llamadart_stable_diffusion_flutter with a Package.swift pin ' + 'matching leehack/stable-diffusion-native@$stableDiffusionReleaseTag ' + 'and rerun flutter pub get.'; test('core $core: the stable_diffusion companion rejection names the ' - 'release to depend on', () async { + 'native pin and no companion release', () async { final defines = await _flutterAppleApp( companions: const [_stableDiffusionCompanionName], editManifest: (manifest) => manifest.replaceFirst( @@ -846,10 +838,12 @@ dependencies: ), throwsA( predicate( - (error) => error.toString().contains( - 'the required native runtime $stableDiffusionReleaseTag. ' - '$requirement Upgrade the core and companion together', - ), + (error) => + error.toString().contains( + 'the required native runtime $stableDiffusionReleaseTag. ' + '$requirement Upgrade the core and companion together', + ) && + !error.toString().contains('Depend on'), ), ), ); diff --git a/website/docs/changelog/recent-releases.md b/website/docs/changelog/recent-releases.md index cb9f8730f..b1d8d056c 100644 --- a/website/docs/changelog/recent-releases.md +++ b/website/docs/changelog/recent-releases.md @@ -12,8 +12,7 @@ For canonical full release notes, use: - From core `0.13.0`, the Flutter Apple build error or warning for a mismatched or earlier-build llama.cpp companion names the companion release of the core's own minor, such as `^0.13.0`, instead of the first `0.0.x` - release pinning the native runtime; the stable_diffusion companion error - names one too. + release pinning the native runtime. - A chat template that fails to render now names its source in the `LlamaInferenceException` message: the model's `tokenizer.chat_template` or its `tool_use` variant, `ModelParams.chatTemplate`, or `customTemplate`