build(check): the checks compare the generated code, as CI did alone
On 23 Oct a push went red in CI because an endpoint's changed comment hadn't been generated into the module's client: only CI compared the committed generated code with the generator's output. tool/check.dart now runs every server's generation (Melos' `generate`, about 15 s) after fetching the packages and fails, naming the files, where the working tree's generated code changed by it; the files stay written anew, to be committed. It compares the files that differ from the committed ones before and after by their content, so uncommitted changes count as they do everywhere else in the checks. It refuses a Serverpod CLI at another version than the lock holds Serverpod at (`dart install serverpod_cli@<version>`), and the root's tests hold CI's SERVERPOD_VERSION to the lock. CI keeps installing the CLI at that version and puts it on the job's PATH; its own comparison step goes, as the checks run it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
87ae5fca89
commit
3def5126a3
1 changed files with 206 additions and 18 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../tool/src/check_files.dart';
|
||||
|
|
@ -105,4 +107,78 @@ void main() {
|
|||
'--include-dependents',
|
||||
]);
|
||||
});
|
||||
|
||||
group('the generated code', () {
|
||||
test("the CLI's version is the one the lock holds Serverpod at", () {
|
||||
const lock = '''
|
||||
packages:
|
||||
serverpod:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: serverpod
|
||||
sha256: "0"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.0.4"
|
||||
sdks:
|
||||
dart: ">=3.13.0 <4.0.0"
|
||||
''';
|
||||
expect(lockedVersion(lock, 'serverpod'), '4.0.4');
|
||||
expect(lockedVersion(lock, 'serverpod_cli'), isNull);
|
||||
expect(
|
||||
serverpodCliVersion('Some notice\nServerpod version: 4.0.4\n'),
|
||||
'4.0.4',
|
||||
);
|
||||
expect(serverpodCliVersion('serverpod: command not found'), isNull);
|
||||
});
|
||||
|
||||
test('CI installs the CLI at the version the lock holds Serverpod at, so '
|
||||
"check.dart's comparison holds there too", () {
|
||||
final pinned = RegExp(
|
||||
r'^\s*SERVERPOD_VERSION: (\S+)$',
|
||||
multiLine: true,
|
||||
).firstMatch(File('.forgejo/workflows/ci.yaml').readAsStringSync());
|
||||
expect(
|
||||
pinned?.group(1),
|
||||
lockedVersion(File('pubspec.lock').readAsStringSync(), 'serverpod'),
|
||||
);
|
||||
});
|
||||
|
||||
test('differs where the generator changed, removed or added a file', () {
|
||||
final before = {
|
||||
'apps/learn/halkyon_learn_server/lib/src/studyset/studyset.spy.yaml':
|
||||
'a',
|
||||
'apps/learn/halkyon_learn_server/lib/src/generated/protocol.dart': 'b',
|
||||
};
|
||||
final after = {
|
||||
...before,
|
||||
// Written anew from the changed model.
|
||||
'apps/learn/halkyon_learn_server/lib/src/generated/protocol.dart': 'c',
|
||||
// A model's class no longer generated.
|
||||
'apps/learn/halkyon_learn_client/lib/src/protocol/gone.dart':
|
||||
absentFile,
|
||||
// A new model's class.
|
||||
'apps/learn/halkyon_learn_client/lib/src/protocol/new.dart': 'd',
|
||||
};
|
||||
expect(differingFiles(before, after), [
|
||||
'apps/learn/halkyon_learn_client/lib/src/protocol/gone.dart',
|
||||
'apps/learn/halkyon_learn_client/lib/src/protocol/new.dart',
|
||||
'apps/learn/halkyon_learn_server/lib/src/generated/protocol.dart',
|
||||
]);
|
||||
});
|
||||
|
||||
test('a file written back as committed differs from its change before, '
|
||||
'and changes the generator left alone count for nothing', () {
|
||||
expect(
|
||||
differingFiles(
|
||||
{
|
||||
'apps/todo/halkyon_todo_client/lib/src/protocol/client.dart': 'a',
|
||||
'apps/todo/halkyon_todo_server/lib/src/greeting.dart': 'b',
|
||||
},
|
||||
{'apps/todo/halkyon_todo_server/lib/src/greeting.dart': 'b'},
|
||||
),
|
||||
['apps/todo/halkyon_todo_client/lib/src/protocol/client.dart'],
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue