-
Notifications
You must be signed in to change notification settings - Fork 0
fix(app): make the Flutter SDK patcher fail loudly instead of lying #167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
leduckhc
wants to merge
2
commits into
main
Choose a base branch
from
feat/upgrade-dart-flutter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+599
−83
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,274 @@ | ||
| // Tests for tool/patch_flutter_sdk.sh — the in-place Flutter SDK patcher | ||
| // (FLUTTER-BUMP-HANDOUT.md §5). Runs the real script against fixture SDK trees. | ||
| // | ||
| // Why this exists: the script's job is to survive an SDK bump, and its most | ||
| // dangerous failure mode is not "crashed" but "reported success while doing | ||
| // nothing". 3.47.0 moved the #182400 call site one nesting level deeper, which | ||
| // made the literal anchor miss — and the script printed "already patched". | ||
| // The unpatched bug then only shows up as hundreds of lines of SkSL noise on | ||
| // someone's next macOS build. Every case below pins a *distinguishable* report. | ||
| import 'dart:io'; | ||
|
|
||
| import 'package:flutter_test/flutter_test.dart'; | ||
|
|
||
| /// The #182400 call site as it appears in Flutter 3.44.9 — the `else` block is | ||
| /// 8 spaces deep. | ||
| const _shader344 = r''' | ||
| class ShaderCompiler { | ||
| Future<bool> compileShader() async { | ||
| if (!retryResult.succeeded) { | ||
| _logger.printError('impellerc failure: ${retryResult.stderr}'); | ||
| return false; | ||
| } else { | ||
| _logger.printError( | ||
| 'warning: Shader `${input.path}` is incompatible with SkSL. This ' | ||
| 'shader will not load when running with the Skia backend.', | ||
| ); | ||
| _logger.printError('impellerc failure: ${result.stderr}'); | ||
| } | ||
| return true; | ||
| } | ||
| } | ||
| '''; | ||
|
|
||
| /// The same call site in Flutter 3.47.0 — one nesting level deeper (10 spaces). | ||
| /// Byte-identical logic, different indentation: the case that silently no-opped. | ||
| const _shader347 = r''' | ||
| class ShaderCompiler { | ||
| Future<bool> compileShader() async { | ||
| if (needsRetry) { | ||
| if (!retryResult.succeeded) { | ||
| _logger.printError('impellerc failure: ${retryResult.stderr}'); | ||
| return false; | ||
| } else { | ||
| _logger.printError( | ||
| 'warning: Shader `${input.path}` is incompatible with SkSL. This ' | ||
| 'shader will not load when running with the Skia backend.', | ||
| ); | ||
| _logger.printError('impellerc failure: ${result.stderr}'); | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| } | ||
| '''; | ||
|
|
||
| /// A plausible future refactor: the warning is gone entirely (upstream fixed it | ||
| /// their own way, or moved it elsewhere). The patch has nothing to attach to and | ||
| /// must say so instead of claiming success. | ||
| const _shaderRefactored = r''' | ||
| class ShaderCompiler { | ||
| Future<bool> compileShader() async { | ||
| if (!result.succeeded) { | ||
| _logger.printError('impellerc failure: ${result.stderr}'); | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| } | ||
| '''; | ||
|
|
||
| const _windowClasses = [ | ||
| '_WindowCreationRequest', | ||
| '_Size', | ||
| '_Offset', | ||
| '_Rect', | ||
| '_Constraints', | ||
| ]; | ||
|
|
||
| String _windowFile({List<String> classes = _windowClasses}) { | ||
| final buf = StringBuffer("import 'dart:ffi';\n\n"); | ||
| for (final name in classes) { | ||
| buf.writeln('final class $name extends Struct {'); | ||
| buf.writeln(' @Int64()'); | ||
| buf.writeln(' external int value;'); | ||
| buf.writeln('}'); | ||
| buf.writeln(); | ||
| } | ||
| return buf.toString(); | ||
| } | ||
|
|
||
| void main() { | ||
| // Tests run with CWD = app/, and the script is bash-only, so POSIX | ||
| // separators are correct here. | ||
| final script = '${Directory.current.path}/tool/patch_flutter_sdk.sh'; | ||
|
|
||
| late Directory sdk; | ||
| late File windowFile; | ||
| late File shaderFile; | ||
|
|
||
| setUp(() { | ||
| sdk = Directory.systemTemp.createTempSync('fake_flutter_sdk'); | ||
| windowFile = File( | ||
| '${sdk.path}/packages/flutter/lib/src/widgets/_window_macos.dart', | ||
| )..createSync(recursive: true); | ||
| shaderFile = File( | ||
| '${sdk.path}/packages/flutter_tools/lib/src/build_system/tools/' | ||
| 'shader_compiler.dart', | ||
| )..createSync(recursive: true); | ||
| windowFile.writeAsStringSync(_windowFile()); | ||
| shaderFile.writeAsStringSync(_shader344); | ||
| }); | ||
|
|
||
| tearDown(() => sdk.deleteSync(recursive: true)); | ||
|
|
||
| ProcessResult run() => Process.runSync( | ||
| 'bash', | ||
| [script], | ||
| environment: {'FLUTTER_ROOT': sdk.path}, | ||
| ); | ||
|
|
||
| group('#182400 — SkSL stderr dump', () { | ||
| test('patches the 3.44.9 call site', () { | ||
| final r = run(); | ||
| expect(r.exitCode, 0, reason: '${r.stdout}${r.stderr}'); | ||
| expect( | ||
| shaderFile.readAsStringSync(), | ||
| contains(r"_logger.printTrace('impellerc failure: ${result.stderr}');"), | ||
| ); | ||
| }); | ||
|
|
||
| test('patches the 3.47.0 call site, which is nested one level deeper', () { | ||
| shaderFile.writeAsStringSync(_shader347); | ||
| final r = run(); | ||
| expect(r.exitCode, 0, reason: '${r.stdout}${r.stderr}'); | ||
| final out = shaderFile.readAsStringSync(); | ||
| expect( | ||
| out, | ||
| contains(r"_logger.printTrace('impellerc failure: ${result.stderr}');"), | ||
| reason: 'indentation must not decide whether the patch applies', | ||
| ); | ||
| // The other two printError call sites are unrelated and must survive. | ||
| expect( | ||
| out, | ||
| contains( | ||
| r"_logger.printError('impellerc failure: ${retryResult.stderr}');", | ||
| ), | ||
| reason: 'only the call site after the Skia warning may be downgraded', | ||
| ); | ||
| }); | ||
|
|
||
| test('keeps the concise one-line warning', () { | ||
| final r = run(); | ||
| // Both guards matter: without them a script that died before touching the | ||
| // fixture leaves the warning in place, and this test passes for the one | ||
| // reason it is meant to rule out. | ||
| expect(r.exitCode, 0, reason: '${r.stdout}${r.stderr}'); | ||
| expect( | ||
| r.stdout, | ||
| contains('[182400] silenced'), | ||
| reason: 'the warning only survived something if the patch ran', | ||
| ); | ||
| expect( | ||
| shaderFile.readAsStringSync(), | ||
| contains('is incompatible with SkSL'), | ||
| ); | ||
| }); | ||
|
|
||
| test('is idempotent, and says so', () { | ||
| run(); | ||
| final afterFirst = shaderFile.readAsStringSync(); | ||
| final r = run(); | ||
| expect(r.exitCode, 0); | ||
| expect(r.stdout, contains('[182400] already patched')); | ||
| expect(shaderFile.readAsStringSync(), afterFirst); | ||
| }); | ||
|
|
||
| test( | ||
| 'fails loudly when the anchor is gone, rather than claiming success', | ||
| () { | ||
| shaderFile.writeAsStringSync(_shaderRefactored); | ||
| final r = run(); | ||
| expect( | ||
| r.exitCode, | ||
| isNot(0), | ||
| reason: | ||
| 'an unapplied patch must not exit 0 — §5 says stop and ' | ||
| 're-derive, which nobody does if the script prints OK', | ||
| ); | ||
| expect( | ||
| '${r.stdout}${r.stderr}', | ||
| contains('182400'), | ||
| reason: 'the report must name which fix stopped applying', | ||
| ); | ||
| expect( | ||
| r.stdout, | ||
| isNot(contains('[182400] already patched')), | ||
| reason: '"already patched" on an unpatched file is the actual bug', | ||
| ); | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| group('#188060 — AOT windowing structs', () { | ||
| test('patches all five structs', () { | ||
| final r = run(); | ||
| expect(r.exitCode, 0, reason: '${r.stdout}${r.stderr}'); | ||
| expect(r.stdout, contains('patched 5 class(es)')); | ||
| final out = windowFile.readAsStringSync(); | ||
| for (final name in _windowClasses) { | ||
| expect( | ||
| out, | ||
| contains("@pragma('vm:entry-point')\nfinal class $name"), | ||
| reason: '$name must be force-retained against the tree-shaker', | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| test('is idempotent', () { | ||
| run(); | ||
| final afterFirst = windowFile.readAsStringSync(); | ||
| final r = run(); | ||
| expect(r.exitCode, 0); | ||
| expect(r.stdout, contains('patched 0 class(es)')); | ||
| expect(windowFile.readAsStringSync(), afterFirst); | ||
| }); | ||
|
|
||
| test('distinguishes a renamed struct from an already-patched one', () { | ||
| // Upstream renames _Rect. "patched 4; 1 already patched" would be a lie | ||
| // that reads exactly like a clean re-run. | ||
| windowFile.writeAsStringSync( | ||
| _windowFile( | ||
| classes: const [ | ||
| '_WindowCreationRequest', | ||
| '_Size', | ||
| '_Offset', | ||
| '_Constraints', | ||
| ], | ||
| ), | ||
| ); | ||
| final r = run(); | ||
| expect( | ||
| r.exitCode, | ||
| isNot(0), | ||
| reason: 'a struct that no longer exists means the AOT crash is back', | ||
| ); | ||
| expect('${r.stdout}${r.stderr}', contains('_Rect')); | ||
| }); | ||
| }); | ||
|
|
||
| group('SDK layout', () { | ||
| // Naming the absent file is the whole value of the failure: "exited 1" is | ||
| // also what a typo in the script looks like. Each patch target is checked | ||
| // separately so neither branch can rot behind the other. | ||
| for (final (label, victim) in [ | ||
| ('shader_compiler.dart', () => shaderFile), | ||
| ('_window_macos.dart', () => windowFile), | ||
| ]) { | ||
| test('fails, naming the file, when $label is missing', () { | ||
| victim().deleteSync(); | ||
| final r = run(); | ||
| expect( | ||
| r.exitCode, | ||
| isNot(0), | ||
| reason: 'a missing file means the patch did not apply', | ||
| ); | ||
| expect( | ||
| '${r.stdout}${r.stderr}', | ||
| contains('$label not found'), | ||
| reason: 'the report must name the file that moved', | ||
| ); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.