Skip to content

Commit a2ea8c8

Browse files
ci: fix dart format violations and secrets-in-if condition
- Format 9 test files (dart format lib/ test/) - Move PUB_CREDENTIALS check from if: condition into shell script (GitHub Actions does not allow secrets in if: expressions)
1 parent 835fb9c commit a2ea8c8

10 files changed

Lines changed: 75 additions & 46 deletions

‎.github/workflows/publish.yml‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,13 @@ jobs:
9393
run: flutter pub get
9494

9595
- name: Setup pub credentials (fallback when OIDC not configured)
96-
if: ${{ secrets.PUB_CREDENTIALS != '' }}
9796
env:
9897
PUB_CREDENTIALS: ${{ secrets.PUB_CREDENTIALS }}
9998
run: |
100-
mkdir -p ~/.pub-cache
101-
echo "$PUB_CREDENTIALS" > ~/.pub-cache/credentials.json
99+
if [ -n "$PUB_CREDENTIALS" ]; then
100+
mkdir -p ~/.pub-cache
101+
echo "$PUB_CREDENTIALS" > ~/.pub-cache/credentials.json
102+
fi
102103
103104
- name: Publish plugin
104105
run: dart pub publish --force
@@ -129,12 +130,13 @@ jobs:
129130
run: dart pub get
130131

131132
- name: Setup pub credentials (fallback when OIDC not configured)
132-
if: ${{ secrets.PUB_CREDENTIALS != '' }}
133133
env:
134134
PUB_CREDENTIALS: ${{ secrets.PUB_CREDENTIALS }}
135135
run: |
136-
mkdir -p ~/.pub-cache
137-
echo "$PUB_CREDENTIALS" > ~/.pub-cache/credentials.json
136+
if [ -n "$PUB_CREDENTIALS" ]; then
137+
mkdir -p ~/.pub-cache
138+
echo "$PUB_CREDENTIALS" > ~/.pub-cache/credentials.json
139+
fi
138140
139141
- name: Publish gen
140142
working-directory: native_workmanager_gen

‎test/unit/middleware_comprehensive_test.dart‎

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ void main() {
1818

1919
test('toMap contains all header entries', () {
2020
const m = HeaderMiddleware(
21-
headers: {'Authorization': 'Bearer tok', 'Content-Type': 'application/json'},
21+
headers: {
22+
'Authorization': 'Bearer tok',
23+
'Content-Type': 'application/json'
24+
},
2225
);
2326
final map = m.toMap();
2427
final headers = map['headers'] as Map;
@@ -52,7 +55,8 @@ void main() {
5255
headers: {'X-Custom': 'value with spaces & symbols = true'},
5356
);
5457
final map = m.toMap();
55-
expect((map['headers'] as Map)['X-Custom'], 'value with spaces & symbols = true');
58+
expect((map['headers'] as Map)['X-Custom'],
59+
'value with spaces & symbols = true');
5660
});
5761

5862
test('toMap has type, headers, urlPattern keys', () {
@@ -135,7 +139,8 @@ void main() {
135139
});
136140

137141
test('String value round-trips', () {
138-
const m = RemoteConfigMiddleware(values: {'baseUrl': 'https://prod.api.com'});
142+
const m =
143+
RemoteConfigMiddleware(values: {'baseUrl': 'https://prod.api.com'});
139144
expect((m.toMap()['values'] as Map)['baseUrl'], 'https://prod.api.com');
140145
});
141146

@@ -199,7 +204,8 @@ void main() {
199204
final middlewares = <Middleware>[
200205
const HeaderMiddleware(headers: {'X-Auth': 'Bearer tok'}),
201206
const LoggingMiddleware(logUrl: 'https://logs.io'),
202-
const RemoteConfigMiddleware(values: {'timeout': 30}, workerType: 'HttpDownload'),
207+
const RemoteConfigMiddleware(
208+
values: {'timeout': 30}, workerType: 'HttpDownload'),
203209
];
204210
final maps = middlewares.map((m) => m.toMap()).toList();
205211
expect(maps[0]['type'], 'header');
@@ -224,13 +230,15 @@ void main() {
224230

225231
test('LoggingMiddleware type key is stable across instances', () {
226232
const m1 = LoggingMiddleware(logUrl: 'https://logs1.example.com');
227-
const m2 = LoggingMiddleware(logUrl: 'https://logs2.example.com', includeConfig: true);
233+
const m2 = LoggingMiddleware(
234+
logUrl: 'https://logs2.example.com', includeConfig: true);
228235
expect(m1.toMap()['type'], m2.toMap()['type']);
229236
});
230237

231238
test('RemoteConfigMiddleware type key is stable across instances', () {
232239
const m1 = RemoteConfigMiddleware(values: {'a': 1});
233-
const m2 = RemoteConfigMiddleware(values: {'b': 2}, workerType: 'HttpDownload');
240+
const m2 =
241+
RemoteConfigMiddleware(values: {'b': 2}, workerType: 'HttpDownload');
234242
expect(m1.toMap()['type'], m2.toMap()['type']);
235243
});
236244

@@ -255,23 +263,28 @@ void main() {
255263
// ──────────────────────────────────────────────────────────────
256264
group('LoggingMiddleware – post-execution payload contract', () {
257265
test('toMap carries logUrl for native POST', () {
258-
const m = LoggingMiddleware(logUrl: 'https://telemetry.example.com/tasks');
266+
const m =
267+
LoggingMiddleware(logUrl: 'https://telemetry.example.com/tasks');
259268
expect(m.toMap()['logUrl'], 'https://telemetry.example.com/tasks');
260269
});
261270

262271
test('includeConfig=false does not include config in map keys', () {
263272
// The Dart map is the registration payload sent to native.
264273
// When includeConfig=false, the native side must NOT attach workerConfig.
265-
const m = LoggingMiddleware(logUrl: 'https://logs.io', includeConfig: false);
274+
const m =
275+
LoggingMiddleware(logUrl: 'https://logs.io', includeConfig: false);
266276
expect(m.toMap()['includeConfig'], isFalse);
267277
});
268278

269279
test('includeConfig=true is forwarded to native', () {
270-
const m = LoggingMiddleware(logUrl: 'https://logs.io', includeConfig: true);
280+
const m =
281+
LoggingMiddleware(logUrl: 'https://logs.io', includeConfig: true);
271282
expect(m.toMap()['includeConfig'], isTrue);
272283
});
273284

274-
test('type is "logging" so native skips applyMiddleware (pre-exec) correctly', () {
285+
test(
286+
'type is "logging" so native skips applyMiddleware (pre-exec) correctly',
287+
() {
275288
// applyMiddleware() on both platforms has a case "logging": break/skip.
276289
// This test documents the contract: type must be exactly "logging".
277290
const m = LoggingMiddleware(logUrl: 'https://x.com');

‎test/unit/native_workmanager_test.dart‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,8 @@ void main() {
570570

571571
test('getServerFilename throws StateError when not initialized', () {
572572
expect(
573-
() => NativeWorkManager.getServerFilename('https://example.com/file.pdf'),
573+
() =>
574+
NativeWorkManager.getServerFilename('https://example.com/file.pdf'),
574575
throwsA(isA<StateError>()),
575576
);
576577
});

‎test/unit/observability_dispatcher_test.dart‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,29 @@ void main() {
7575
final dispatcher = ObservabilityDispatcher(
7676
ObservabilityConfig(onTaskStart: (id, type) => receivedId = id),
7777
);
78-
dispatcher.dispatchEvent(_event(taskId: 'task-1', success: false, isStarted: true));
78+
dispatcher.dispatchEvent(
79+
_event(taskId: 'task-1', success: false, isStarted: true));
7980
expect(receivedId, 'task-1');
8081
});
8182

8283
test('isStarted event triggers onTaskStart with workerType', () {
8384
String? receivedType;
8485
final dispatcher = ObservabilityDispatcher(
85-
ObservabilityConfig(
86-
onTaskStart: (id, type) => receivedType = type),
86+
ObservabilityConfig(onTaskStart: (id, type) => receivedType = type),
8787
);
8888
dispatcher.dispatchEvent(
89-
_event(taskId: 't', success: false, isStarted: true, workerType: 'HttpDownloadWorker'),
89+
_event(
90+
taskId: 't',
91+
success: false,
92+
isStarted: true,
93+
workerType: 'HttpDownloadWorker'),
9094
);
9195
expect(receivedType, 'HttpDownloadWorker');
9296
});
9397

94-
test('isStarted event with null workerType passes empty string to onTaskStart', () {
98+
test(
99+
'isStarted event with null workerType passes empty string to onTaskStart',
100+
() {
95101
String? receivedType;
96102
final dispatcher = ObservabilityDispatcher(
97103
ObservabilityConfig(onTaskStart: (id, type) => receivedType = type),
@@ -107,7 +113,8 @@ void main() {
107113
final dispatcher = ObservabilityDispatcher(
108114
ObservabilityConfig(onTaskComplete: (_) => called = true),
109115
);
110-
dispatcher.dispatchEvent(_event(taskId: 't', success: true, isStarted: true));
116+
dispatcher
117+
.dispatchEvent(_event(taskId: 't', success: true, isStarted: true));
111118
expect(called, isFalse);
112119
});
113120

@@ -116,7 +123,8 @@ void main() {
116123
final dispatcher = ObservabilityDispatcher(
117124
ObservabilityConfig(onTaskFail: (_) => called = true),
118125
);
119-
dispatcher.dispatchEvent(_event(taskId: 't', success: false, isStarted: true));
126+
dispatcher
127+
.dispatchEvent(_event(taskId: 't', success: false, isStarted: true));
120128
expect(called, isFalse);
121129
});
122130

@@ -296,8 +304,8 @@ void main() {
296304
onTaskFail: (e) => log.add('fail'),
297305
),
298306
);
299-
dispatcher.dispatchEvent(
300-
_event(taskId: 't', success: false, isStarted: true));
307+
dispatcher
308+
.dispatchEvent(_event(taskId: 't', success: false, isStarted: true));
301309
dispatcher.dispatchEvent(_event(taskId: 't', success: false));
302310
expect(log, ['start', 'fail']);
303311
});

‎test/unit/remote_trigger_comprehensive_test.dart‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ void main() {
120120
expect(mappings.keys.toSet(), {'sync', 'download', 'upload'});
121121
});
122122

123-
test('worker URL template uses real URL (placeholder substituted at runtime)', () {
123+
test(
124+
'worker URL template uses real URL (placeholder substituted at runtime)',
125+
() {
124126
// URL validation requires http/https — templates are substituted on native side.
125127
// Test that the URL value round-trips as-is via toMap.
126128
final rule = RemoteTriggerRule(
@@ -133,7 +135,8 @@ void main() {
133135
},
134136
);
135137
final mappings = rule.toMap()['workerMappings'] as Map;
136-
final config = (mappings['download_update'] as Map)['workerConfig'] as Map;
138+
final config =
139+
(mappings['download_update'] as Map)['workerConfig'] as Map;
137140
expect(config['url'], 'https://cdn.example.com/update.zip');
138141
expect(config['savePath'], '/tmp/update.zip');
139142
});

‎test/unit/request_signing_test.dart‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ void main() {
188188
});
189189

190190
test('HttpRequestWorker without requestSigning has null in toMap', () {
191-
final worker =
192-
HttpRequestWorker(url: 'https://api.example.com');
191+
final worker = HttpRequestWorker(url: 'https://api.example.com');
193192
final map = worker.toMap();
194193
expect(map['requestSigning'], isNull);
195194
});

‎test/unit/task_graph_test.dart‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ void main() {
100100
});
101101

102102
test('nodes is unmodifiable', () {
103-
final g = TaskGraph(id: 'g')
104-
..add(TaskNode(id: 'a', worker: _workerA));
103+
final g = TaskGraph(id: 'g')..add(TaskNode(id: 'a', worker: _workerA));
105104
expect(
106105
() => g.nodes.add(TaskNode(id: 'x', worker: _workerB)),
107106
throwsUnsupportedError,

‎test/unit/worker_edge_cases_test.dart‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ void main() {
1616
});
1717

1818
test('httpDownload factory produces HttpDownloadWorker', () {
19-
final w = NativeWorker.httpDownload(
20-
url: 'https://x.com/f', savePath: '/tmp/f');
19+
final w =
20+
NativeWorker.httpDownload(url: 'https://x.com/f', savePath: '/tmp/f');
2121
expect(w, isA<HttpDownloadWorker>());
2222
expect(w.workerClassName, 'HttpDownloadWorker');
2323
});
@@ -41,12 +41,14 @@ void main() {
4141
// ──────────────────────────────────────────────────────────────
4242
group('HttpRequestWorker edge cases', () {
4343
test('POST method is serialized', () {
44-
final w = HttpRequestWorker(url: 'https://x.com', method: HttpMethod.post);
44+
final w =
45+
HttpRequestWorker(url: 'https://x.com', method: HttpMethod.post);
4546
expect(w.toMap()['method'], anyOf('post', 'POST'));
4647
});
4748

4849
test('DELETE method is serialized', () {
49-
final w = HttpRequestWorker(url: 'https://x.com', method: HttpMethod.delete);
50+
final w =
51+
HttpRequestWorker(url: 'https://x.com', method: HttpMethod.delete);
5052
expect(w.toMap()['method'], anyOf('delete', 'DELETE'));
5153
});
5254

@@ -80,14 +82,14 @@ void main() {
8082
url: 'https://x.com', timeout: const Duration(seconds: 5));
8183
final map = w.toMap();
8284
// timeout serialized as ms or Duration — check it's in the map
83-
expect(map.containsKey('timeout') || map.containsKey('timeoutMs'), isTrue);
85+
expect(
86+
map.containsKey('timeout') || map.containsKey('timeoutMs'), isTrue);
8487
});
8588

8689
test('URL with query string is preserved', () {
8790
final w = HttpRequestWorker(
8891
url: 'https://api.example.com/search?q=test&page=1');
89-
expect(w.toMap()['url'],
90-
'https://api.example.com/search?q=test&page=1');
92+
expect(w.toMap()['url'], 'https://api.example.com/search?q=test&page=1');
9193
});
9294
});
9395

@@ -105,13 +107,15 @@ void main() {
105107
});
106108

107109
test('skipExisting defaults to false', () {
108-
final w = HttpDownloadWorker(url: 'https://cdn.com/f', savePath: '/tmp/f');
110+
final w =
111+
HttpDownloadWorker(url: 'https://cdn.com/f', savePath: '/tmp/f');
109112
expect(w.toMap()['skipExisting'], isFalse);
110113
});
111114

112115
test('savePath is serialized', () {
113116
final w = HttpDownloadWorker(
114-
url: 'https://cdn.com/file.zip', savePath: '/data/downloads/file.zip');
117+
url: 'https://cdn.com/file.zip',
118+
savePath: '/data/downloads/file.zip');
115119
expect(w.toMap()['savePath'], '/data/downloads/file.zip');
116120
});
117121
});

‎test/workers/http_workers_test.dart‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ void main() {
116116

117117
test('empty filePath throws ArgumentError', () {
118118
expect(
119-
() =>
120-
NativeWorker.httpUpload(url: 'https://example.com', filePath: ''),
119+
() => NativeWorker.httpUpload(url: 'https://example.com', filePath: ''),
121120
throwsA(isA<ArgumentError>()),
122121
);
123122
});

‎test/workers/pdf_worker_test.dart‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ void main() {
156156

157157
test('empty inputPath throws ArgumentError', () {
158158
expect(
159-
() => NativeWorker.pdfCompress(inputPath: '', outputPath: '/tmp/out.pdf'),
159+
() =>
160+
NativeWorker.pdfCompress(inputPath: '', outputPath: '/tmp/out.pdf'),
160161
throwsA(isA<ArgumentError>()),
161162
);
162163
});
@@ -226,8 +227,8 @@ void main() {
226227

227228
test('empty imagePaths throws ArgumentError', () {
228229
expect(
229-
() =>
230-
NativeWorker.pdfFromImages(imagePaths: [], outputPath: '/tmp/out.pdf'),
230+
() => NativeWorker.pdfFromImages(
231+
imagePaths: [], outputPath: '/tmp/out.pdf'),
231232
throwsA(isA<ArgumentError>()),
232233
);
233234
});

0 commit comments

Comments
 (0)