Files
cutdex/test/tool/local_environment_test.dart
T
lingjhf 152c051a29
Gitea CI / Check code and tests (pull_request) Failing after 8m56s
Gitea CI / Build Android APK (pull_request) Skipped
Gitea CI / Build Windows x64 app (pull_request) Skipped
Gitea CI / Audit and package Windows x64 (pull_request) Skipped
Gitea CI / Assemble and validate CI artifacts (pull_request) Skipped
Gitea CI / Gitea CI passed (pull_request) Failing after 4s
refactor(build): unify SDK configuration and release tooling
Pin Flutter with FVM and share local environment loading across IDE, Python, and Dart entrypoints. Keep CI on the verified preinstalled SDK and skip local overrides.

Extract common build presets, process execution, and file hashing. Propagate project roots through SDK selection and release commands, and migrate macOS release, signing, and DMG orchestration to Python.

Reuse local check suites in CI, support Android source overrides, and update documentation and regression tests.
2026-10-06 22:24:32 +08:00

106 lines
3.1 KiB
Dart

import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import '../../tool/src/local_environment.dart';
void main() {
late Directory root;
setUp(() => root = Directory.systemTemp.createTempSync('cutdex-env-test-'));
tearDown(() => root.deleteSync(recursive: true));
test('parses BOM, CRLF, quotes, comments and literal Windows paths', () {
expect(
parseLocalEnvironment(
'\uFEFF# local configuration\r\n'
'export CUTDEX_WINDOWS_PATH = "C:\\My SDK\\native" # source\r\n'
"CUTDEX_PROCESSING_ROOT='C:/workers #1'\r\n"
'CUTDEX_GITEA_TOKEN=literal#hash # comment\r\n'
'EMPTY=\r\n',
),
{
'CUTDEX_WINDOWS_PATH': r'C:\My SDK\native',
'CUTDEX_PROCESSING_ROOT': 'C:/workers #1',
'CUTDEX_GITEA_TOKEN': 'literal#hash',
'EMPTY': '',
},
);
});
test('values are not evaluated or expanded', () {
expect(
parseLocalEnvironment(r'VALUE=$(command) ${OTHER}\n')['VALUE'],
r'$(command) ${OTHER}\n',
);
});
test('invalid and duplicate assignments never expose their values', () {
for (final source in [
'this-is-a-secret',
'TOKEN="this-is-a-secret',
'TOKEN="this-is-a-secret" trailing',
'TOKEN=first\nTOKEN=this-is-a-secret',
]) {
try {
parseLocalEnvironment(source);
fail('Invalid configuration was accepted.');
} on FormatException catch (error) {
expect(error.message, isNot(contains('this-is-a-secret')));
}
}
});
test('explicit process values win, including empty values', () {
expect(
mergeLocalEnvironment(
{'TOKEN': 'explicit', 'EMPTY': ''},
{'TOKEN': 'file', 'EMPTY': 'file', 'LOCAL': 'file'},
windows: false,
),
{'TOKEN': 'explicit', 'EMPTY': '', 'LOCAL': 'file'},
);
});
test('Windows variable names are compared without case sensitivity', () {
expect(
mergeLocalEnvironment(
{'Path': 'explicit'},
{'PATH': 'file'},
windows: true,
),
{'Path': 'explicit'},
);
});
test('missing local file preserves the SDK defaults', () {
expect(loadLocalEnvironment(root, {'EXISTING': 'value'}, windows: false), {
'EXISTING': 'value',
});
});
test('loads the project root file without modifying parent variables', () {
File.fromUri(root.uri.resolve('.env.local'))
.writeAsStringSync('LOCAL=value');
final parent = <String, String>{'EXISTING': 'parent'};
expect(loadLocalEnvironment(root, parent, windows: false), {
'EXISTING': 'parent',
'LOCAL': 'value',
});
expect(parent, {'EXISTING': 'parent'});
});
test('CI never opens even an invalid local file', () {
File.fromUri(root.uri.resolve('.env.local'))
.writeAsStringSync('invalid file');
for (final key in ['CI', 'GITEA_ACTIONS', 'GITHUB_ACTIONS']) {
final parent = {key: 'true'};
expect(loadLocalEnvironment(root, parent, windows: false), parent);
}
});
test('a false CI flag still allows local development', () {
expect(isContinuousIntegration({'CI': 'false'}), isFalse);
expect(isContinuousIntegration({'CI': '1'}), isTrue);
});
}