@atolis-hq/wake 0.4.106 → 0.4.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/activities/agent/agent-activity.js +4 -0
- package/dist/src/activities/agent/agent-result.js +1 -0
- package/dist/src/activities/contracts/activity.d.ts +6 -0
- package/dist/src/activities/pr/application.js +23 -9
- package/dist/src/activities/pr/approve.js +1 -1
- package/dist/src/activities/pr/merge.js +1 -1
- package/dist/src/activities/pr/parent-scope.d.ts +8 -2
- package/dist/src/activities/pr/parent-scope.js +7 -1
- package/dist/src/activities/pr/parent-target.d.ts +2 -2
- package/dist/src/activities/pr/parent-target.js +1 -0
- package/dist/src/bootstrap/composition-root.js +1 -1
- package/dist/src/bootstrap/config/root-schema.d.ts +14 -0
- package/dist/src/bootstrap/delivery-integration.js +7 -4
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +10 -0
- package/dist/src/control-plane/application/advance-once-dispatch.js +3 -5
- package/dist/src/control-plane/application/dispatch-resources.d.ts +10 -0
- package/dist/src/control-plane/application/dispatch-resources.js +9 -0
- package/dist/src/conversations/application/conversation-repository.d.ts +1 -1
- package/dist/src/conversations/application/conversation-repository.js +3 -1
- package/dist/src/execution/application/change-output-workspaces.d.ts +20 -0
- package/dist/src/execution/application/change-output-workspaces.js +123 -0
- package/dist/src/execution/application/execution-service.js +15 -2
- package/dist/src/execution/application/maintenance-workspaces.js +20 -12
- package/dist/src/execution/application/run-lifecycle.d.ts +2 -0
- package/dist/src/execution/application/run-lifecycle.js +2 -0
- package/dist/src/execution/application/run-repository.js +27 -10
- package/dist/src/execution/contracts/change-output.d.ts +15 -0
- package/dist/src/execution/contracts/change-output.js +12 -0
- package/dist/src/execution/contracts/commands.d.ts +5 -0
- package/dist/src/execution/contracts/events.d.ts +16 -0
- package/dist/src/execution/contracts/events.js +4 -0
- package/dist/src/execution/contracts/runner.d.ts +1 -0
- package/dist/src/execution/contracts/views.d.ts +3 -0
- package/dist/src/execution/contracts/workspace.d.ts +4 -0
- package/dist/src/execution/domain/run.js +3 -0
- package/dist/src/execution/index.d.ts +1 -0
- package/dist/src/execution/index.js +1 -0
- package/dist/src/execution/infrastructure/workspace/git-workspace.js +14 -3
- package/dist/src/integrations/application/artifact-registration-reactor.d.ts +2 -11
- package/dist/src/integrations/application/artifact-registration-reactor.js +16 -36
- package/dist/src/integrations/application/artifact-verification-source.d.ts +26 -0
- package/dist/src/integrations/application/artifact-verification-source.js +36 -0
- package/dist/src/integrations/application/delegation-outputs.js +56 -20
- package/dist/src/integrations/application/latest-unresolved-artifacts.d.ts +3 -0
- package/dist/src/integrations/application/latest-unresolved-artifacts.js +16 -0
- package/dist/src/integrations/contracts/artifact-events.d.ts +1 -0
- package/dist/src/integrations/contracts/artifact-events.js +1 -0
- package/dist/src/integrations/github/application/comment-history-reader.d.ts +1 -1
- package/dist/src/integrations/github/application/comment-history-reader.js +56 -39
- package/dist/src/node_modules/@atolis-hq/eventing/dist/index.d.ts +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/index.d.ts.map +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/index.js +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.d.ts +14 -0
- package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.d.ts.map +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/projections/projection-processor.js +31 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.d.ts +22 -0
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.d.ts.map +1 -0
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/journal-view.js +60 -0
- package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.d.ts +2 -0
- package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.d.ts.map +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing-filesystem/dist/file-event-journal.js +82 -15
- package/dist/src/orchestration/application/advance-workflow.js +7 -2
- package/dist/src/orchestration/application/deferred-signals.js +2 -6
- package/dist/src/orchestration/application/delegated-work.d.ts +18 -0
- package/dist/src/orchestration/application/delegated-work.js +30 -3
- package/dist/src/orchestration/application/delegation-commands.d.ts +16 -0
- package/dist/src/orchestration/application/delegation-reservation.js +33 -5
- package/dist/src/orchestration/application/delivery-integration-service.js +5 -18
- package/dist/src/orchestration/application/orchestration-repository.d.ts +14 -9
- package/dist/src/orchestration/application/orchestration-repository.js +139 -64
- package/dist/src/orchestration/application/orchestration-service.d.ts +34 -0
- package/dist/src/orchestration/application/orchestration-service.js +6 -1
- package/dist/src/orchestration/contracts/config.d.ts +15 -0
- package/dist/src/orchestration/contracts/config.js +8 -1
- package/dist/src/orchestration/contracts/delegation.d.ts +33 -9
- package/dist/src/orchestration/contracts/delegation.js +11 -5
- package/dist/src/orchestration/contracts/vocabulary.d.ts +2 -0
- package/dist/src/orchestration/contracts/vocabulary.js +2 -0
- package/dist/src/orchestration/domain/assignment-output-requirements.d.ts +5 -0
- package/dist/src/orchestration/domain/assignment-output-requirements.js +23 -0
- package/dist/src/orchestration/domain/compiler.js +1 -0
- package/dist/src/orchestration/domain/delivery-facts.d.ts +9 -1
- package/dist/src/orchestration/domain/delivery-facts.js +4 -2
- package/dist/src/orchestration/domain/delivery-integration-target.d.ts +8 -0
- package/dist/src/orchestration/domain/delivery-integration-target.js +37 -0
- package/dist/src/orchestration/domain/delivery-replacement.js +11 -6
- package/dist/src/orchestration/domain/delivery-selection.js +2 -1
- package/dist/src/resources/application/resource-lookup.d.ts +2 -1
- package/dist/src/resources/application/resource-lookup.js +3 -11
- package/dist/src/resources/application/resource-repository.js +10 -10
- package/package.json +1 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.d.ts +0 -16
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.d.ts.map +0 -1
- package/dist/src/node_modules/@atolis-hq/eventing/dist/runtime/cached-journal-view.js +0 -79
|
@@ -12,6 +12,11 @@ const createFileSystemWatcher = async (directory, notify) => watch(directory, {
|
|
|
12
12
|
// tick would leave it identical. Younger stamps are re-listed, never trusted.
|
|
13
13
|
const unchangedStampMinAgeMs = 2_500;
|
|
14
14
|
const statBatchSize = 256;
|
|
15
|
+
// Reads may skip the directory listing while a probe for the next segment finds
|
|
16
|
+
// nothing, but never for longer than this: a full listing still bounds how long
|
|
17
|
+
// an unexpected change (a removed segment, an odd clock) can go unnoticed.
|
|
18
|
+
const maxProbeOnlyMs = 5_000;
|
|
19
|
+
const maxProbedDays = 8;
|
|
15
20
|
export class FileEventJournal {
|
|
16
21
|
root;
|
|
17
22
|
clock;
|
|
@@ -53,6 +58,7 @@ export class FileEventJournal {
|
|
|
53
58
|
runningListing;
|
|
54
59
|
queuedListing;
|
|
55
60
|
temporariesReclaimed = false;
|
|
61
|
+
lastFullListingMs = 0;
|
|
56
62
|
async appendToStream(stream, expectedSequence, drafts) {
|
|
57
63
|
if (drafts.length === 0)
|
|
58
64
|
throw new Error('appendToStream requires at least one event');
|
|
@@ -61,7 +67,8 @@ export class FileEventJournal {
|
|
|
61
67
|
await reclaimStaleSegmentTemps(join(this.root, 'events'));
|
|
62
68
|
this.temporariesReclaimed = true;
|
|
63
69
|
}
|
|
64
|
-
|
|
70
|
+
// Positions are assigned from this snapshot, so it must come from a full listing.
|
|
71
|
+
const snapshot = await this.scan(await this.currentEntries({ exhaustive: true }));
|
|
65
72
|
const current = snapshot.events;
|
|
66
73
|
const streamEvents = snapshot.eventsByStream.get(key(stream)) ?? [];
|
|
67
74
|
if (streamEvents.length !== expectedSequence)
|
|
@@ -357,31 +364,73 @@ export class FileEventJournal {
|
|
|
357
364
|
// call. A listing already running may have read the directory before the
|
|
358
365
|
// call, so it cannot answer it; every caller arriving while one runs shares a
|
|
359
366
|
// single follow-up listing. Any number of concurrent reads cost at most two.
|
|
360
|
-
currentEntries() {
|
|
367
|
+
currentEntries(options = {}) {
|
|
368
|
+
if (options.exhaustive === true) {
|
|
369
|
+
const running = this.runningListing;
|
|
370
|
+
return (running === undefined ? Promise.resolve() : running.then(noop, noop)).then(() => this.startListing(true));
|
|
371
|
+
}
|
|
361
372
|
if (this.queuedListing !== undefined)
|
|
362
373
|
return this.queuedListing;
|
|
363
374
|
const running = this.runningListing;
|
|
364
375
|
if (running === undefined)
|
|
365
|
-
return this.startListing();
|
|
376
|
+
return this.startListing(false);
|
|
366
377
|
const queued = running
|
|
367
378
|
.catch(() => undefined)
|
|
368
379
|
.then(() => {
|
|
369
380
|
this.queuedListing = undefined;
|
|
370
|
-
return this.startListing();
|
|
381
|
+
return this.startListing(false);
|
|
371
382
|
});
|
|
372
383
|
this.queuedListing = queued;
|
|
373
384
|
return queued;
|
|
374
385
|
}
|
|
375
|
-
startListing() {
|
|
376
|
-
const run = this.listSegments().finally(() => {
|
|
386
|
+
startListing(exhaustive) {
|
|
387
|
+
const run = this.listSegments(exhaustive).finally(() => {
|
|
377
388
|
if (this.runningListing === run)
|
|
378
389
|
this.runningListing = undefined;
|
|
379
390
|
});
|
|
380
391
|
this.runningListing = run;
|
|
381
392
|
return run;
|
|
382
393
|
}
|
|
383
|
-
|
|
394
|
+
// Segments are immutable, contiguous, and named by the global position of
|
|
395
|
+
// their first event (the first segment of a day is `<day>.jsonl`). When the
|
|
396
|
+
// cache holds L events and is the newest listing, nothing newer exists exactly
|
|
397
|
+
// when no segment for position L+1 exists, which costs a few stats instead of
|
|
398
|
+
// a directory listing proportional to the whole history.
|
|
399
|
+
async nothingNewerThanCache() {
|
|
400
|
+
const cached = this.cached;
|
|
401
|
+
const last = cached?.entries.at(-1);
|
|
402
|
+
if (cached === undefined || last === undefined)
|
|
403
|
+
return false;
|
|
404
|
+
if (Date.now() - this.lastFullListingMs > maxProbeOnlyMs)
|
|
405
|
+
return false;
|
|
406
|
+
if (!sameEntries(cached.entries, this.latestEntries))
|
|
407
|
+
return false;
|
|
408
|
+
const next = String(cached.events.length + 1).padStart(20, '0');
|
|
409
|
+
// A writer names a segment from its own clock, so cover every day between the
|
|
410
|
+
// newest cached segment (or yesterday, for a clock running behind) and
|
|
411
|
+
// tomorrow. A wider gap cannot be probed cheaply, so list the directory.
|
|
412
|
+
const dayMs = 24 * 60 * 60 * 1000;
|
|
413
|
+
const lastDay = Date.parse(`${last.file.slice(0, 10)}T00:00:00Z`);
|
|
414
|
+
const firstDay = Math.min(lastDay, Date.UTC(...utcDayParts(Date.now() - dayMs)));
|
|
415
|
+
const lastProbedDay = Date.UTC(...utcDayParts(Date.now() + dayMs));
|
|
416
|
+
if (!Number.isFinite(lastDay) || (lastProbedDay - firstDay) / dayMs > maxProbedDays)
|
|
417
|
+
return false;
|
|
418
|
+
const days = [];
|
|
419
|
+
for (let at = firstDay; at <= lastProbedDay; at += dayMs)
|
|
420
|
+
days.push(new Date(at).toISOString().slice(0, 10));
|
|
421
|
+
const candidates = days.flatMap((d) => [`${d}~${next}.jsonl`, `${d}.jsonl`]);
|
|
422
|
+
const unknown = candidates.filter((name) => !this.knownSegments.has(name));
|
|
423
|
+
const found = await Promise.all(unknown.map((name) => stat(join(this.root, 'events', name)).then(() => true, (error) => {
|
|
424
|
+
if (error.code === 'ENOENT')
|
|
425
|
+
return false;
|
|
426
|
+
throw error;
|
|
427
|
+
})));
|
|
428
|
+
return !found.some(Boolean);
|
|
429
|
+
}
|
|
430
|
+
async listSegments(exhaustive) {
|
|
384
431
|
const directory = join(this.root, 'events');
|
|
432
|
+
if (!exhaustive && (await this.nothingNewerThanCache()))
|
|
433
|
+
return this.latestEntries;
|
|
385
434
|
const startedAtMs = Date.now();
|
|
386
435
|
let stamp;
|
|
387
436
|
try {
|
|
@@ -403,15 +452,27 @@ export class FileEventJournal {
|
|
|
403
452
|
this.latestEntries.length === this.knownSegments.size)
|
|
404
453
|
return this.latestEntries;
|
|
405
454
|
// The stamp is taken before the listing so a change during it cannot be hidden.
|
|
406
|
-
|
|
407
|
-
|
|
455
|
+
// One pass over the directory: names already known are only counted, and
|
|
456
|
+
// the set of present names is built only if a known segment has gone missing.
|
|
457
|
+
const listed = await readdir(directory);
|
|
458
|
+
const unseen = [];
|
|
459
|
+
let knownPresent = 0;
|
|
460
|
+
for (const name of listed) {
|
|
461
|
+
if (this.knownSegments.has(name))
|
|
462
|
+
knownPresent += 1;
|
|
463
|
+
else if (segmentName.test(name))
|
|
464
|
+
unseen.push(name);
|
|
465
|
+
}
|
|
408
466
|
let removed = false;
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
467
|
+
if (knownPresent !== this.knownSegments.size) {
|
|
468
|
+
const present = new Set(listed);
|
|
469
|
+
for (const name of this.knownSegments.keys())
|
|
470
|
+
if (!present.has(name)) {
|
|
471
|
+
this.knownSegments.delete(name);
|
|
472
|
+
removed = true;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
unseen.sort();
|
|
415
476
|
for (let index = 0; index < unseen.length; index += statBatchSize)
|
|
416
477
|
await Promise.all(unseen.slice(index, index + statBatchSize).map(async (file) => {
|
|
417
478
|
try {
|
|
@@ -424,6 +485,7 @@ export class FileEventJournal {
|
|
|
424
485
|
}
|
|
425
486
|
}));
|
|
426
487
|
this.listing = { stamp, startedAtMs };
|
|
488
|
+
this.lastFullListingMs = startedAtMs;
|
|
427
489
|
const added = unseen.flatMap((file) => this.knownSegments.get(file) ?? []);
|
|
428
490
|
const last = this.latestEntries.at(-1);
|
|
429
491
|
const consistent = this.latestEntries.length + added.length === this.knownSegments.size;
|
|
@@ -593,6 +655,11 @@ function sameEntries(a, b) {
|
|
|
593
655
|
return (entry.file === other.file && entry.size === other.size && entry.mtimeMs === other.mtimeMs);
|
|
594
656
|
})));
|
|
595
657
|
}
|
|
658
|
+
function utcDayParts(ms) {
|
|
659
|
+
const date = new Date(ms);
|
|
660
|
+
return [date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()];
|
|
661
|
+
}
|
|
662
|
+
function noop() { }
|
|
596
663
|
const key = (stream) => `${stream.kind}:${stream.id}`;
|
|
597
664
|
function indexEventsByStream(events) {
|
|
598
665
|
const indexed = new Map();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventSourceKind } from '@atolis-hq/eventing';
|
|
2
2
|
import { OrchestrationEventType } from '../contracts/events.js';
|
|
3
3
|
import { commandName } from '../contracts/identifiers.js';
|
|
4
|
-
import { WorkflowStatus } from '../contracts/vocabulary.js';
|
|
4
|
+
import { ActivityActivationStatus, WorkflowStatus } from '../contracts/vocabulary.js';
|
|
5
5
|
import { workflowEventData } from '../domain/decision-events.js';
|
|
6
6
|
import { requestChangesResume as decideChangesResume, requestFreshOperatorRetry as decideFreshOperatorRetry, requestOperatorRetry as decideOperatorRetry, requestSupplementalActivity as decideSupplementalActivity, isNeedsClarificationResumeEligible, requestRunnerQuotaRetry, } from '../domain/interpreter.js';
|
|
7
7
|
import { isAuthorisedActor } from '../domain/supplemental-policy.js';
|
|
@@ -50,7 +50,12 @@ export class AdvanceWorkflow {
|
|
|
50
50
|
}
|
|
51
51
|
async markActivationStarted(id, activationId, context) {
|
|
52
52
|
const loaded = await this.repository.load(id);
|
|
53
|
-
|
|
53
|
+
const pending = loaded.view?.pendingActivation;
|
|
54
|
+
if (pending?.activationId !== activationId)
|
|
55
|
+
return loaded.view;
|
|
56
|
+
// Dispatch marks before every attempt; a retried tick must not append a new
|
|
57
|
+
// fact for an activation whose recorded state already says it is running.
|
|
58
|
+
if (pending.status === ActivityActivationStatus.Running)
|
|
54
59
|
return loaded.view;
|
|
55
60
|
const event = workflowEventData({
|
|
56
61
|
eventId: `${context.commandId}:${OrchestrationEventType.ActivityStarted}`,
|
|
@@ -64,15 +64,11 @@ export class DeferredSignals {
|
|
|
64
64
|
return view;
|
|
65
65
|
}
|
|
66
66
|
async hasDeferred() {
|
|
67
|
-
return (await this.repository.
|
|
67
|
+
return (await this.repository.instancesWithDeferredSignals()).size > 0;
|
|
68
68
|
}
|
|
69
69
|
async reconcile(context) {
|
|
70
70
|
// Only instances holding a deferred signal have anything to replay.
|
|
71
|
-
const
|
|
72
|
-
for (const entry of await this.repository.events())
|
|
73
|
-
if (entry.event.eventType === OrchestrationEventType.SignalDeferred)
|
|
74
|
-
deferred.add(entry.stream.id);
|
|
75
|
-
const ids = [...deferred];
|
|
71
|
+
const ids = [...(await this.repository.instancesWithDeferredSignals())];
|
|
76
72
|
if (ids.length === 0)
|
|
77
73
|
return;
|
|
78
74
|
const fenced = await this.fencedAmong(ids);
|
|
@@ -83,9 +83,17 @@ export declare class DelegatedWork {
|
|
|
83
83
|
outputs: ({
|
|
84
84
|
name: string;
|
|
85
85
|
path: string;
|
|
86
|
+
required?: boolean | undefined;
|
|
86
87
|
} | {
|
|
87
88
|
name: string;
|
|
88
89
|
kind: "change";
|
|
90
|
+
required?: boolean | undefined;
|
|
91
|
+
repository?: {
|
|
92
|
+
resourceId: string;
|
|
93
|
+
sourceRef: string;
|
|
94
|
+
pullRequestBase: string;
|
|
95
|
+
sourceRevision?: string | undefined;
|
|
96
|
+
} | undefined;
|
|
89
97
|
requireReview?: boolean | undefined;
|
|
90
98
|
requireChecks?: boolean | undefined;
|
|
91
99
|
})[];
|
|
@@ -126,6 +134,16 @@ export declare class DelegatedWork {
|
|
|
126
134
|
}[]>;
|
|
127
135
|
runLimit(id: WorkItemId): Promise<number | undefined>;
|
|
128
136
|
repositoryScope(workItemId: string): Promise<string[] | undefined>;
|
|
137
|
+
changeOutputAssignments(workItemId: string): Promise<{
|
|
138
|
+
name: string;
|
|
139
|
+
isolated: boolean;
|
|
140
|
+
repository: {
|
|
141
|
+
resourceId: string;
|
|
142
|
+
sourceRef: string;
|
|
143
|
+
sourceRevision: string;
|
|
144
|
+
pullRequestBase: string;
|
|
145
|
+
};
|
|
146
|
+
}[] | undefined>;
|
|
129
147
|
repositoryFor(workItemId: string): Promise<{
|
|
130
148
|
resourceId: string;
|
|
131
149
|
sourceRef: string;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { assertConfiguredOutputs, hasRequiredOutputs, } from '../domain/assignment-output-requirements.js';
|
|
1
2
|
/* eslint-disable max-lines */
|
|
2
3
|
import { WrongExpectedSequenceError } from '@atolis-hq/eventing';
|
|
3
4
|
import { activationId } from '../../activities/index.js';
|
|
4
|
-
import { WorkspaceMode } from '../../execution/index.js';
|
|
5
|
+
import { repositoryAssignmentSchema, WorkspaceMode } from '../../execution/index.js';
|
|
5
6
|
import { WorkStatus } from '../../work/index.js';
|
|
6
7
|
import { DelegationConflictError } from '../contracts/delegation.js';
|
|
7
8
|
import { OrchestrationEventType } from '../contracts/events.js';
|
|
@@ -100,6 +101,22 @@ export class DelegatedWork {
|
|
|
100
101
|
return (child.repositoryResourceIds ??
|
|
101
102
|
(child.repository === undefined ? [] : [child.repository.resourceId]));
|
|
102
103
|
}
|
|
104
|
+
async changeOutputAssignments(workItemId) {
|
|
105
|
+
const child = (await this.ledger.reservations())
|
|
106
|
+
.flatMap((entry) => entry.children)
|
|
107
|
+
.find((entry) => entry.workItemId === workItemId);
|
|
108
|
+
const repository = await this.repositoryFor(workItemId);
|
|
109
|
+
return child?.outputs.flatMap((output) => 'kind' in output
|
|
110
|
+
? [
|
|
111
|
+
{
|
|
112
|
+
name: output.name,
|
|
113
|
+
isolated: child.outputs.filter((entry) => 'kind' in entry).length > 1 ||
|
|
114
|
+
output.repository !== undefined,
|
|
115
|
+
repository: repositoryAssignmentSchema.parse(output.repository ?? repository),
|
|
116
|
+
},
|
|
117
|
+
]
|
|
118
|
+
: []);
|
|
119
|
+
}
|
|
103
120
|
async repositoryFor(workItemId) {
|
|
104
121
|
const inputs = await this.prerequisites.inputs(workItemId);
|
|
105
122
|
if (inputs?.repository !== undefined)
|
|
@@ -190,6 +207,16 @@ export class DelegatedWork {
|
|
|
190
207
|
return {
|
|
191
208
|
...assignment,
|
|
192
209
|
repository: await this.repositories.resolve(parent, assignment.repository),
|
|
210
|
+
outputs: await Promise.all(assignment.outputs.map(async (output) => {
|
|
211
|
+
if (!('kind' in output) || output.repository === undefined)
|
|
212
|
+
return output;
|
|
213
|
+
if (output.repository.resourceId !== assignment.repository.resourceId)
|
|
214
|
+
throw new Error('Change outputs must use the assigned repository');
|
|
215
|
+
return {
|
|
216
|
+
...output,
|
|
217
|
+
repository: await this.repositories.resolve(parent, output.repository),
|
|
218
|
+
};
|
|
219
|
+
})),
|
|
193
220
|
};
|
|
194
221
|
}));
|
|
195
222
|
}
|
|
@@ -292,6 +319,7 @@ export class DelegatedWork {
|
|
|
292
319
|
if (current.fingerprint !== child.workflowFingerprint)
|
|
293
320
|
throw new Error('Delegation workflow fingerprint must match current configuration');
|
|
294
321
|
const definition = current.definition;
|
|
322
|
+
assertConfiguredOutputs(definition.outputs, child.outputs);
|
|
295
323
|
if (child.repository === undefined &&
|
|
296
324
|
Object.values(definition.stages).some((stage) => stage.execution?.workspace === WorkspaceMode.Branch ||
|
|
297
325
|
stage.execution?.workspace === WorkspaceMode.ReadOnly))
|
|
@@ -533,8 +561,7 @@ export class DelegatedWork {
|
|
|
533
561
|
await this.missingOutputs(root, reservation, child, context);
|
|
534
562
|
return;
|
|
535
563
|
}
|
|
536
|
-
const satisfied =
|
|
537
|
-
child.outputs.every((required) => outputs.filter((output) => output.name === required.name && output.reference.workItemId === child.workItemId).length === 1);
|
|
564
|
+
const satisfied = hasRequiredOutputs(child, outputs);
|
|
538
565
|
if (!satisfied) {
|
|
539
566
|
await this.failChild(reservation, child, 'Invalid qualifying output contract', context);
|
|
540
567
|
return;
|
|
@@ -39,9 +39,17 @@ export declare class DelegationCommands {
|
|
|
39
39
|
outputs: ({
|
|
40
40
|
name: string;
|
|
41
41
|
path: string;
|
|
42
|
+
required?: boolean | undefined;
|
|
42
43
|
} | {
|
|
43
44
|
name: string;
|
|
44
45
|
kind: "change";
|
|
46
|
+
required?: boolean | undefined;
|
|
47
|
+
repository?: {
|
|
48
|
+
resourceId: string;
|
|
49
|
+
sourceRef: string;
|
|
50
|
+
pullRequestBase: string;
|
|
51
|
+
sourceRevision?: string | undefined;
|
|
52
|
+
} | undefined;
|
|
45
53
|
requireReview?: boolean | undefined;
|
|
46
54
|
requireChecks?: boolean | undefined;
|
|
47
55
|
})[];
|
|
@@ -138,9 +146,17 @@ export declare class DelegationCommands {
|
|
|
138
146
|
outputs: ({
|
|
139
147
|
name: string;
|
|
140
148
|
path: string;
|
|
149
|
+
required?: boolean | undefined;
|
|
141
150
|
} | {
|
|
142
151
|
name: string;
|
|
143
152
|
kind: "change";
|
|
153
|
+
required?: boolean | undefined;
|
|
154
|
+
repository?: {
|
|
155
|
+
resourceId: string;
|
|
156
|
+
sourceRef: string;
|
|
157
|
+
pullRequestBase: string;
|
|
158
|
+
sourceRevision?: string | undefined;
|
|
159
|
+
} | undefined;
|
|
144
160
|
requireReview?: boolean | undefined;
|
|
145
161
|
requireChecks?: boolean | undefined;
|
|
146
162
|
})[];
|
|
@@ -11,11 +11,13 @@ export function buildReservation(parent, caller, cohortId, assignments, limits)
|
|
|
11
11
|
if (new Set(parsed.map((assignment) => assignment.assignmentId)).size !== parsed.length)
|
|
12
12
|
throw new Error('Duplicate assignment identity');
|
|
13
13
|
for (const assignment of parsed) {
|
|
14
|
-
if (assignment.outputs.filter((output) => 'kind' in output && output.kind === DelegationOutputKind.Change).length > 1)
|
|
15
|
-
throw new Error('One change output per child is currently supported');
|
|
16
14
|
if (assignment.outputs.some((output) => 'kind' in output && output.kind === DelegationOutputKind.Change) &&
|
|
17
15
|
assignment.repository === undefined)
|
|
18
16
|
throw new Error('Change outputs require an explicit repository assignment');
|
|
17
|
+
if (assignment.outputs.some((output) => 'kind' in output &&
|
|
18
|
+
output.repository !== undefined &&
|
|
19
|
+
output.repository.resourceId !== assignment.repository?.resourceId))
|
|
20
|
+
throw new Error('Change outputs must use the assigned repository');
|
|
19
21
|
if (new Set(assignment.outputs.map((output) => output.name)).size !== assignment.outputs.length)
|
|
20
22
|
throw new Error('Duplicate named output');
|
|
21
23
|
}
|
|
@@ -49,12 +51,38 @@ export function assertWithinRootLimits(existing, reservation, limits) {
|
|
|
49
51
|
}
|
|
50
52
|
/** A replay of a branch request retains the originally resolved commit. */
|
|
51
53
|
export function matchesAssignments(reservation, assignments) {
|
|
52
|
-
if (assignments.some((assignment) => assignment.
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
if (assignments.some((assignment) => assignment.outputs.some((output) => {
|
|
55
|
+
if (!('kind' in output) || output.repository?.sourceRevision === undefined)
|
|
56
|
+
return false;
|
|
57
|
+
const recorded = reservation.children
|
|
58
|
+
.find((child) => child.assignmentId === assignment.assignmentId)
|
|
59
|
+
?.outputs.find((entry) => entry.name === output.name);
|
|
60
|
+
return (recorded === undefined ||
|
|
61
|
+
!('kind' in recorded) ||
|
|
62
|
+
recorded.repository?.sourceRevision !== output.repository.sourceRevision);
|
|
63
|
+
})) ||
|
|
64
|
+
assignments.some((assignment) => assignment.repository?.sourceRevision !== undefined &&
|
|
65
|
+
reservation.children.find((child) => child.assignmentId === assignment.assignmentId)
|
|
66
|
+
?.repository?.sourceRevision !== assignment.repository.sourceRevision))
|
|
55
67
|
return false;
|
|
56
68
|
return isDeepStrictEqual(reservation.children.map(({ workItemId: _w, workflowInstanceId: _i, grantId: _g, prerequisiteWorkItemIds: _p, ...assignment }) => ({
|
|
57
69
|
...assignment,
|
|
70
|
+
outputs: assignment.outputs.map((output) => {
|
|
71
|
+
if (!('kind' in output) || output.repository === undefined)
|
|
72
|
+
return output;
|
|
73
|
+
const requested = assignments
|
|
74
|
+
.find((entry) => entry.assignmentId === assignment.assignmentId)
|
|
75
|
+
?.outputs.find((entry) => entry.name === output.name);
|
|
76
|
+
return {
|
|
77
|
+
...output,
|
|
78
|
+
repository: {
|
|
79
|
+
...output.repository,
|
|
80
|
+
sourceRevision: requested !== undefined && 'kind' in requested
|
|
81
|
+
? requested.repository?.sourceRevision
|
|
82
|
+
: undefined,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}),
|
|
58
86
|
...(assignment.repository === undefined
|
|
59
87
|
? {}
|
|
60
88
|
: {
|
|
@@ -5,6 +5,7 @@ import { OrchestrationEventType } from '../contracts/events.js';
|
|
|
5
5
|
import { DeliveryCompletion, DeliveryRejection, IntegrationState, QaVerdict, } from '../contracts/vocabulary.js';
|
|
6
6
|
import { currentSelection, isChange, outputKey, } from '../domain/delivery-facts.js';
|
|
7
7
|
import { targetRequirements } from '../domain/delivery-integration-policy.js';
|
|
8
|
+
import { selectIntegrationTarget } from '../domain/delivery-integration-target.js';
|
|
8
9
|
import { known, sameRevision } from '../domain/delivery-integration.js';
|
|
9
10
|
import { deliveryState } from '../domain/delivery-qa.js';
|
|
10
11
|
import { readDeliveryFacts } from './delivery-facts-reader.js';
|
|
@@ -47,9 +48,10 @@ export class DeliveryIntegrationService {
|
|
|
47
48
|
const assessment = await this.reader.assess(facts);
|
|
48
49
|
if (assessment.complete)
|
|
49
50
|
return { kind: 'fully-integrated' };
|
|
50
|
-
const
|
|
51
|
-
if (
|
|
52
|
-
return denied(
|
|
51
|
+
const selected = selectIntegrationTarget(assessment, request.output);
|
|
52
|
+
if ('reason' in selected)
|
|
53
|
+
return denied(selected.reason);
|
|
54
|
+
const next = selected.target;
|
|
53
55
|
if (!(await this.verifySelected(facts, next.output, request.action)))
|
|
54
56
|
return denied(PullRequestDenialCode.DeliveryNotReady);
|
|
55
57
|
const context = {
|
|
@@ -211,18 +213,3 @@ function replayPlan(recorded, command) {
|
|
|
211
213
|
draft: undefined,
|
|
212
214
|
};
|
|
213
215
|
}
|
|
214
|
-
function blockReason(blocking) {
|
|
215
|
-
switch (blocking?.state) {
|
|
216
|
-
case IntegrationState.Held:
|
|
217
|
-
return PullRequestDenialCode.TargetHeld;
|
|
218
|
-
case IntegrationState.MaintenanceRequired:
|
|
219
|
-
case IntegrationState.AwaitingLowerLayer:
|
|
220
|
-
return PullRequestDenialCode.MaintenanceRequired;
|
|
221
|
-
case IntegrationState.Closed:
|
|
222
|
-
return PullRequestDenialCode.Closed;
|
|
223
|
-
case IntegrationState.Unobserved:
|
|
224
|
-
return PullRequestDenialCode.MissingResource;
|
|
225
|
-
default:
|
|
226
|
-
return PullRequestDenialCode.DeliveryNotReady;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
@@ -2,29 +2,35 @@ import { type EventJournal } from '@atolis-hq/eventing';
|
|
|
2
2
|
import type { DeliveryCompletionBlock } from '../contracts/delivery.js';
|
|
3
3
|
import type { WorkflowOrchestrationEvent, WorkflowOrchestrationEventData } from '../contracts/events.js';
|
|
4
4
|
import type { WorkflowInstanceView } from '../contracts/views.js';
|
|
5
|
-
type ListedInstance = {
|
|
5
|
+
export type ListedInstance = {
|
|
6
6
|
readonly sequence: number;
|
|
7
7
|
readonly view: WorkflowInstanceView | null;
|
|
8
8
|
};
|
|
9
|
+
export interface OrchestrationSnapshot {
|
|
10
|
+
readonly instances: readonly ListedInstance[];
|
|
11
|
+
readonly events: readonly WorkflowOrchestrationEvent[];
|
|
12
|
+
readonly inherited: ReadonlyMap<string, readonly WorkflowOrchestrationEvent[]>;
|
|
13
|
+
readonly deferredInstanceIds: ReadonlySet<string>;
|
|
14
|
+
}
|
|
9
15
|
export declare class OrchestrationRepository {
|
|
10
16
|
private readonly journal;
|
|
11
17
|
private readonly completionBlock?;
|
|
12
|
-
private readonly
|
|
18
|
+
private readonly state;
|
|
13
19
|
constructor(journal: EventJournal, completionBlock?: ((id: string) => Promise<DeliveryCompletionBlock | undefined>) | undefined);
|
|
14
20
|
load(id: string): Promise<{
|
|
15
21
|
sequence: number;
|
|
16
22
|
view: WorkflowInstanceView | null;
|
|
17
23
|
}>;
|
|
18
|
-
snapshot(): Promise<
|
|
19
|
-
instances: readonly ListedInstance[];
|
|
20
|
-
events: readonly WorkflowOrchestrationEvent[];
|
|
21
|
-
inherited: ReadonlyMap<string, readonly WorkflowOrchestrationEvent[]>;
|
|
22
|
-
}>;
|
|
24
|
+
snapshot(): Promise<OrchestrationSnapshot>;
|
|
23
25
|
events(): Promise<readonly WorkflowOrchestrationEvent[]>;
|
|
26
|
+
/** Workflow instances that hold at least one deferred signal. */
|
|
27
|
+
instancesWithDeferredSignals(): Promise<ReadonlySet<string>>;
|
|
24
28
|
history(id: string): Promise<{
|
|
25
29
|
sequence: number;
|
|
26
|
-
events: WorkflowOrchestrationEvent[];
|
|
30
|
+
events: readonly WorkflowOrchestrationEvent[];
|
|
27
31
|
}>;
|
|
32
|
+
/** The state for reads that span every instance, which fail while any instance is malformed. */
|
|
33
|
+
private healthyState;
|
|
28
34
|
loadRequired(id: string): Promise<{
|
|
29
35
|
sequence: number;
|
|
30
36
|
view: WorkflowInstanceView;
|
|
@@ -32,4 +38,3 @@ export declare class OrchestrationRepository {
|
|
|
32
38
|
append(id: string, sequence: number, drafts: readonly WorkflowOrchestrationEventData[]): Promise<readonly WorkflowOrchestrationEvent[]>;
|
|
33
39
|
list(): Promise<readonly ListedInstance[]>;
|
|
34
40
|
}
|
|
35
|
-
export {};
|