Skip to content

Commit 3f2b2f4

Browse files
authored
feat: cah.processWorkflow returns the hash (#4751)
1 parent 676dd10 commit 3f2b2f4

4 files changed

Lines changed: 34 additions & 14 deletions

File tree

app_dart/lib/src/service/content_aware_hash_service.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,14 @@ interface class ContentAwareHashService {
129129
}
130130

131131
/// Finds the hash status for [job] and updates any tracking docs.
132-
Future<MergeQueueHashStatus> processWorkflowJob(
132+
Future<ContentAwareHashStatus> processWorkflowJob(
133133
WorkflowJobEvent job, {
134134
@visibleForTesting RetryOptions retry = const RetryOptions(maxAttempts: 5),
135135
}) async {
136136
final hash = await hashFromWorkflowJobEvent(job);
137-
if (hash == null) return MergeQueueHashStatus.ignoreJob;
137+
if (hash == null) {
138+
return (status: MergeQueueHashStatus.ignoreJob, contentHash: '');
139+
}
138140

139141
final headSha = job.workflowJob!.headSha!;
140142

@@ -155,14 +157,14 @@ interface class ContentAwareHashService {
155157
rethrow;
156158
}
157159
});
158-
return result;
160+
return (status: result, contentHash: hash);
159161
} catch (e, s) {
160162
log.warn(
161163
'CAHS(headSha: $headSha, hash: $hash): multiple failures calling _updateFirestore',
162164
e,
163165
s,
164166
);
165-
return MergeQueueHashStatus.error;
167+
return (status: MergeQueueHashStatus.error, contentHash: '');
166168
}
167169
}
168170

@@ -337,3 +339,6 @@ interface class ContentAwareHashService {
337339
}
338340

339341
enum MergeQueueHashStatus { wait, build, complete, ignoreJob, error }
342+
343+
typedef ContentAwareHashStatus =
344+
({String contentHash, MergeQueueHashStatus status});

app_dart/lib/src/service/scheduler.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,11 +676,12 @@ $s
676676
// - .*: do nothing
677677
// FOR NOW: trigger builds for build/wait/completed because they are also
678678
// building for SHA.
679-
switch (artifactStatus) {
679+
switch (artifactStatus.status) {
680680
case MergeQueueHashStatus.build ||
681681
MergeQueueHashStatus.wait ||
682682
MergeQueueHashStatus.complete
683-
when _config.flags.contentAwareHashing.waitOnContentHash:
683+
when _config.flags.contentAwareHashing.waitOnContentHash &&
684+
artifactStatus.contentHash.isNotEmpty:
684685
// Note from codefu: We do not have the merge queue lock yet.
685686
// It was short-circuited if the waitOnContentHash is set. The
686687
// CAH document _has_ been created. In the future, "wait" will need

app_dart/test/service/content_aware_hash_service_test.dart

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ void main() {
156156

157157
final job = workflowJobTemplate(headSha: 'a' * 40).toWorkflowJob();
158158
final result = await cahs.processWorkflowJob(job);
159-
expect(result, MergeQueueHashStatus.build);
159+
expect(result, (
160+
status: MergeQueueHashStatus.build,
161+
contentHash: '1111111111111111111111111111111111111111',
162+
));
160163
expect(
161164
firestoreService,
162165
existsInStorage(ContentAwareHashBuilds.metadata, [
@@ -186,7 +189,10 @@ void main() {
186189

187190
final job = workflowJobTemplate(headSha: 'b' * 40).toWorkflowJob();
188191
final result = await cahs.processWorkflowJob(job);
189-
expect(result, MergeQueueHashStatus.complete);
192+
expect(result, (
193+
contentHash: '1111111111111111111111111111111111111111',
194+
status: MergeQueueHashStatus.complete,
195+
));
190196
});
191197

192198
test('stacks multiple builds in one doc', () async {
@@ -199,7 +205,10 @@ void main() {
199205

200206
job = workflowJobTemplate(headSha: 'b' * 40).toWorkflowJob();
201207
final result = await cahs.processWorkflowJob(job);
202-
expect(result, MergeQueueHashStatus.wait);
208+
expect(result, (
209+
contentHash: '1111111111111111111111111111111111111111',
210+
status: MergeQueueHashStatus.wait,
211+
));
203212

204213
expect(
205214
firestoreService,
@@ -224,7 +233,10 @@ void main() {
224233

225234
job = workflowJobTemplate(headSha: 'b' * 40).toWorkflowJob();
226235
final result = await cahs.processWorkflowJob(job);
227-
expect(result, MergeQueueHashStatus.wait);
236+
expect(result, (
237+
contentHash: '1111111111111111111111111111111111111111',
238+
status: MergeQueueHashStatus.wait,
239+
));
228240

229241
expect(
230242
firestoreService,
@@ -255,7 +267,7 @@ void main() {
255267
job,
256268
retry: const RetryOptions(maxAttempts: 5, maxDelay: Duration.zero),
257269
);
258-
expect(result, MergeQueueHashStatus.error);
270+
expect(result, (contentHash: '', status: MergeQueueHashStatus.error));
259271
});
260272
});
261273

app_dart/test/src/service/fake_content_aware_hash_service.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,17 @@ class FakeContentAwareHashService implements ContentAwareHashService {
4444
}
4545

4646
final processWorkflowJobs = <WorkflowJobEvent>[];
47-
MergeQueueHashStatus? nextStatusReturn;
47+
ContentAwareHashStatus? nextStatusReturn;
4848

4949
@override
50-
Future<MergeQueueHashStatus> processWorkflowJob(
50+
Future<ContentAwareHashStatus> processWorkflowJob(
5151
WorkflowJobEvent workflow, {
5252
RetryOptions? retry,
5353
}) {
5454
processWorkflowJobs.add(workflow);
55-
final status = nextStatusReturn ?? MergeQueueHashStatus.ignoreJob;
55+
final status =
56+
nextStatusReturn ??
57+
(status: MergeQueueHashStatus.ignoreJob, contentHash: '');
5658
nextStatusReturn = null;
5759
return Future.value(status);
5860
}

0 commit comments

Comments
 (0)