@atolis-hq/wake 0.4.107 → 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/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/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/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/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 +9 -22
- 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/contracts/artifact-events.d.ts +1 -0
- package/dist/src/integrations/contracts/artifact-events.js +1 -0
- 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-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/package.json +1 -1
|
@@ -2,6 +2,7 @@ import { type EventDataUnion, type EventEnvelope, type EventUnion } from '@atoli
|
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { type ActivationId, type ActivityName, type ActivityOrchestrationGroupId, type ActivityOutcome, type ActivityWorkflowInstanceId } from '../../activities/index.js';
|
|
4
4
|
import { type PreparedCandidate } from './candidate.js';
|
|
5
|
+
import { type ChangeOutputWorkspace } from './change-output.js';
|
|
5
6
|
import { runId } from './identifiers.js';
|
|
6
7
|
import type { Cancellation, ExternalExecutionReference, Lease } from './liveness.js';
|
|
7
8
|
import { type PreparedMaintenance } from './maintenance.js';
|
|
@@ -59,6 +60,18 @@ export declare const runStartedPayloadSchema: z.ZodObject<{
|
|
|
59
60
|
reason: z.ZodOptional<z.ZodString>;
|
|
60
61
|
}, z.core.$strict>>;
|
|
61
62
|
}, z.core.$strict>>;
|
|
63
|
+
changeOutputs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
64
|
+
name: z.ZodString;
|
|
65
|
+
path: z.ZodString;
|
|
66
|
+
branch: z.ZodString;
|
|
67
|
+
repository: z.ZodObject<{
|
|
68
|
+
resourceId: z.ZodString;
|
|
69
|
+
sourceRef: z.ZodString;
|
|
70
|
+
sourceRevision: z.ZodString;
|
|
71
|
+
pullRequestBase: z.ZodString;
|
|
72
|
+
}, z.core.$strict>;
|
|
73
|
+
revision: z.ZodString;
|
|
74
|
+
}, z.core.$strict>>>;
|
|
62
75
|
}, z.core.$strict>>;
|
|
63
76
|
}, z.core.$strict>;
|
|
64
77
|
export declare const runPreparationStartedPayloadSchema: z.ZodObject<{
|
|
@@ -107,6 +120,7 @@ export declare const runnerResultPayloadSchema: z.ZodObject<{
|
|
|
107
120
|
}>;
|
|
108
121
|
displayBody: z.ZodString;
|
|
109
122
|
artifacts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
123
|
+
name: z.ZodOptional<z.ZodString>;
|
|
110
124
|
kind: z.ZodString;
|
|
111
125
|
externalKey: z.ZodObject<{
|
|
112
126
|
adapter: z.ZodString;
|
|
@@ -161,6 +175,7 @@ export interface RunStartedPayload {
|
|
|
161
175
|
readonly checkoutRevision?: string | undefined;
|
|
162
176
|
readonly candidate?: PreparedCandidate | undefined;
|
|
163
177
|
readonly maintenance?: PreparedMaintenance | undefined;
|
|
178
|
+
readonly changeOutputs?: readonly ChangeOutputWorkspace[] | undefined;
|
|
164
179
|
} | undefined;
|
|
165
180
|
}
|
|
166
181
|
export interface RunPreparationStartedPayload {
|
|
@@ -188,6 +203,7 @@ export interface RunExecutionEventPayloads {
|
|
|
188
203
|
readonly [ExecutionEventType.RunPreparationStarted]: RunPreparationStartedPayload;
|
|
189
204
|
readonly [ExecutionEventType.RunStarted]: RunStartedPayload;
|
|
190
205
|
readonly [ExecutionEventType.RunSucceeded]: {
|
|
206
|
+
readonly changeOutputs?: readonly ChangeOutputWorkspace[] | undefined;
|
|
191
207
|
readonly workspaceRevision?: string | undefined;
|
|
192
208
|
readonly outcome: ActivityOutcome;
|
|
193
209
|
readonly finishedAt: string;
|
|
@@ -3,6 +3,7 @@ import { z } from 'zod';
|
|
|
3
3
|
import { activationId, activityName, activityOrchestrationGroupId, activityWorkflowInstanceId, ExternalExecutionKind, } from '../../activities/index.js';
|
|
4
4
|
import { brandedStringSchema, offsetIsoTimestampSchema } from '../../kernel/index.js';
|
|
5
5
|
import { preparedCandidateSchema } from './candidate.js';
|
|
6
|
+
import { changeOutputWorkspaceSchema } from './change-output.js';
|
|
6
7
|
import { runId } from './identifiers.js';
|
|
7
8
|
import { preparedMaintenanceSchema } from './maintenance.js';
|
|
8
9
|
import { repositoryAssignmentSchema } from './repository-assignment.js';
|
|
@@ -37,6 +38,7 @@ export const runStartedPayloadSchema = z
|
|
|
37
38
|
checkoutRevision: z.string().min(1).optional(),
|
|
38
39
|
candidate: preparedCandidateSchema.optional(),
|
|
39
40
|
maintenance: preparedMaintenanceSchema.optional(),
|
|
41
|
+
changeOutputs: z.array(changeOutputWorkspaceSchema).optional(),
|
|
40
42
|
})
|
|
41
43
|
.strict()
|
|
42
44
|
.optional(),
|
|
@@ -89,6 +91,7 @@ export const runnerResultPayloadSchema = z
|
|
|
89
91
|
artifacts: z
|
|
90
92
|
.array(z
|
|
91
93
|
.object({
|
|
94
|
+
name: z.string().min(1).optional(),
|
|
92
95
|
kind: z.string().min(1),
|
|
93
96
|
externalKey: z
|
|
94
97
|
.object({ adapter: z.string().min(1), key: z.string().min(1) })
|
|
@@ -167,6 +170,7 @@ const runEventSchema = eventEnvelopeSchema.extend({
|
|
|
167
170
|
eventType: z.literal(ExecutionEventType.RunSucceeded),
|
|
168
171
|
payload: z
|
|
169
172
|
.object({
|
|
173
|
+
changeOutputs: z.array(changeOutputWorkspaceSchema).optional(),
|
|
170
174
|
workspaceRevision: z
|
|
171
175
|
.string()
|
|
172
176
|
.regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i)
|
|
@@ -38,6 +38,7 @@ export interface AgentRunResponse {
|
|
|
38
38
|
readonly outcome: AgentRunOutcome;
|
|
39
39
|
readonly displayBody: string;
|
|
40
40
|
readonly artifacts?: readonly {
|
|
41
|
+
readonly name?: string | undefined;
|
|
41
42
|
readonly kind: string;
|
|
42
43
|
readonly externalKey: {
|
|
43
44
|
readonly adapter: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ActivationId, ActivityName, ActivityOrchestrationGroupId, ActivityOutcome, ActivityWorkflowInstanceId } from '../../activities/index.js';
|
|
2
2
|
import type { PreparedCandidate } from './candidate.js';
|
|
3
|
+
import type { ChangeOutputWorkspace } from './change-output.js';
|
|
3
4
|
import type { RunId } from './identifiers.js';
|
|
4
5
|
import type { Cancellation, ExternalExecutionReference, Lease } from './liveness.js';
|
|
5
6
|
import type { PreparedMaintenance } from './maintenance.js';
|
|
@@ -36,6 +37,7 @@ export interface RunView {
|
|
|
36
37
|
readonly cli?: string | undefined;
|
|
37
38
|
} | undefined;
|
|
38
39
|
readonly finishedAt?: string;
|
|
40
|
+
readonly changeOutputs?: readonly ChangeOutputWorkspace[] | undefined;
|
|
39
41
|
readonly workspaceRevision?: string | undefined;
|
|
40
42
|
readonly outcome?: ActivityOutcome;
|
|
41
43
|
readonly failure?: ExecutionFailure;
|
|
@@ -47,6 +49,7 @@ export interface RunView {
|
|
|
47
49
|
readonly checkoutRevision?: string | undefined;
|
|
48
50
|
readonly candidate?: PreparedCandidate | undefined;
|
|
49
51
|
readonly maintenance?: PreparedMaintenance | undefined;
|
|
52
|
+
readonly changeOutputs?: readonly ChangeOutputWorkspace[] | undefined;
|
|
50
53
|
};
|
|
51
54
|
readonly lease?: Lease;
|
|
52
55
|
readonly externalExecution?: ExternalExecutionReference;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { ResourceView } from '../../resources/index.js';
|
|
2
2
|
import type { WorkItemId } from '../../work/index.js';
|
|
3
3
|
import type { PreparedCandidate } from './candidate.js';
|
|
4
|
+
import type { ChangeOutputWorkspace } from './change-output.js';
|
|
4
5
|
import type { RunId } from './identifiers.js';
|
|
5
6
|
import type { PreparedMaintenance } from './maintenance.js';
|
|
6
7
|
import type { RepositoryAssignment } from './repository-assignment.js';
|
|
7
8
|
import type { RunView } from './views.js';
|
|
8
9
|
import type { WorkspaceMode } from './vocabulary.js';
|
|
9
10
|
export interface WorkspaceRequest {
|
|
11
|
+
readonly outputName?: string;
|
|
10
12
|
readonly runId: RunId;
|
|
11
13
|
readonly signal: AbortSignal;
|
|
12
14
|
readonly mode: typeof WorkspaceMode.ReadOnly | typeof WorkspaceMode.Branch;
|
|
@@ -18,6 +20,8 @@ export interface WorkspaceRequest {
|
|
|
18
20
|
readonly assignment?: RepositoryAssignment;
|
|
19
21
|
}
|
|
20
22
|
export interface WorkspaceLease {
|
|
23
|
+
readonly changeOutputs?: readonly ChangeOutputWorkspace[];
|
|
24
|
+
readChangeOutputs?(): Promise<readonly ChangeOutputWorkspace[]>;
|
|
21
25
|
readonly candidate?: PreparedCandidate;
|
|
22
26
|
readonly maintenance?: PreparedMaintenance;
|
|
23
27
|
readonly workspaceId: string;
|
|
@@ -113,6 +113,9 @@ function applyTerminalEvent(state, event) {
|
|
|
113
113
|
status: RunStatus.Succeeded,
|
|
114
114
|
finishedAt: event.payload.finishedAt,
|
|
115
115
|
outcome: event.payload.outcome,
|
|
116
|
+
...(event.payload.changeOutputs === undefined
|
|
117
|
+
? {}
|
|
118
|
+
: { changeOutputs: event.payload.changeOutputs }),
|
|
116
119
|
...(event.payload.workspaceRevision === undefined
|
|
117
120
|
? {}
|
|
118
121
|
: { workspaceRevision: event.payload.workspaceRevision }),
|
|
@@ -15,6 +15,7 @@ export * from './contracts/results.js';
|
|
|
15
15
|
export * from './contracts/streams.js';
|
|
16
16
|
export * from './contracts/views.js';
|
|
17
17
|
export * from './contracts/vocabulary.js';
|
|
18
|
+
export * from './contracts/change-output.js';
|
|
18
19
|
export * from './contracts/workspace.js';
|
|
19
20
|
export * from './domain/run-result.js';
|
|
20
21
|
export * from './domain/run.js';
|
|
@@ -15,6 +15,7 @@ export * from './contracts/results.js';
|
|
|
15
15
|
export * from './contracts/streams.js';
|
|
16
16
|
export * from './contracts/views.js';
|
|
17
17
|
export * from './contracts/vocabulary.js';
|
|
18
|
+
export * from './contracts/change-output.js';
|
|
18
19
|
export * from './contracts/workspace.js';
|
|
19
20
|
export * from './domain/run-result.js';
|
|
20
21
|
export * from './domain/run.js';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable max-lines */
|
|
2
2
|
import { execFile } from 'node:child_process';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
3
4
|
import { access, mkdir, readdir, readFile, realpath, rename, rm, rmdir, unlink, writeFile, } from 'node:fs/promises';
|
|
4
5
|
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
5
6
|
import { isDeepStrictEqual, promisify } from 'node:util';
|
|
@@ -45,7 +46,7 @@ export class GitWorkspaceProvider {
|
|
|
45
46
|
}
|
|
46
47
|
const locator = await this.resolver.cloneLocator(request.repositoryResource.resourceId, signal);
|
|
47
48
|
signal.throwIfAborted();
|
|
48
|
-
const name = `${request
|
|
49
|
+
const name = `${workspaceBranch(request)}-${request.mode}-${slug(locator)}`;
|
|
49
50
|
const path = resolve(this.root, name);
|
|
50
51
|
const markerPath = join(this.markerRoot, `${name}.json`);
|
|
51
52
|
const lockPath = join(this.markerRoot, `${name}.lease`);
|
|
@@ -128,7 +129,7 @@ export class GitWorkspaceProvider {
|
|
|
128
129
|
}
|
|
129
130
|
if (initialRevision === undefined)
|
|
130
131
|
initialRevision = await readCheckoutRevision(path, this.git, signal);
|
|
131
|
-
const branch = request.mode === WorkspaceMode.Branch ? request
|
|
132
|
+
const branch = request.mode === WorkspaceMode.Branch ? workspaceBranch(request) : undefined;
|
|
132
133
|
if (branch !== undefined) {
|
|
133
134
|
initialRevision = await initializeBranch({
|
|
134
135
|
path,
|
|
@@ -314,7 +315,10 @@ function protectsWorkspace(run) {
|
|
|
314
315
|
}
|
|
315
316
|
async function reclaimUnlockedMarker(input, markerPath, marker) {
|
|
316
317
|
if (input.runs.some((run) => (isActiveRunStatus(run.status) || run.status === RunStatus.Ambiguous) &&
|
|
317
|
-
(run.runId === marker.runId ||
|
|
318
|
+
(run.runId === marker.runId ||
|
|
319
|
+
run.workspace?.path === marker.path ||
|
|
320
|
+
run.workspace?.changeOutputs?.some((entry) => entry.path === marker.path) === true ||
|
|
321
|
+
run.workspace?.maintenance?.targets.some((entry) => entry.path === marker.path) === true)))
|
|
318
322
|
return emptyRecovery();
|
|
319
323
|
if ((await input.options.retainWorkItem?.(marker.workItemId)) === true)
|
|
320
324
|
return emptyRecovery();
|
|
@@ -544,3 +548,10 @@ async function initializeBranch(input, git, signal) {
|
|
|
544
548
|
], signal);
|
|
545
549
|
return initialRevision;
|
|
546
550
|
}
|
|
551
|
+
function workspaceBranch(request) {
|
|
552
|
+
return request.outputName === undefined
|
|
553
|
+
? request.workItemId
|
|
554
|
+
: request.workItemId +
|
|
555
|
+
'-output-' +
|
|
556
|
+
createHash('sha256').update(request.outputName).digest('hex');
|
|
557
|
+
}
|
|
@@ -2,6 +2,7 @@ import { type EventJournal, type EventProcessor } from '@atolis-hq/eventing';
|
|
|
2
2
|
import { type IdGenerator } from '../../kernel/index.js';
|
|
3
3
|
import { type ResourceService } from '../../resources/index.js';
|
|
4
4
|
import type { ProviderInstance } from '../contracts/provider.js';
|
|
5
|
+
import { type ArtifactSourceRun } from './artifact-verification-source.js';
|
|
5
6
|
interface ArtifactRegistrationDependencies {
|
|
6
7
|
readonly journal: EventJournal;
|
|
7
8
|
readonly resources: ResourceService;
|
|
@@ -9,16 +10,7 @@ interface ArtifactRegistrationDependencies {
|
|
|
9
10
|
readonly providers: readonly ProviderInstance[];
|
|
10
11
|
readonly maxAmbiguityReconciliationAttempts?: number;
|
|
11
12
|
readonly runs: {
|
|
12
|
-
list(activationId?: string): Promise<readonly
|
|
13
|
-
readonly repositoryAssignment?: {
|
|
14
|
-
readonly resourceId: string;
|
|
15
|
-
readonly pullRequestBase: string;
|
|
16
|
-
} | undefined;
|
|
17
|
-
readonly workspaceRevision?: string | undefined;
|
|
18
|
-
readonly workspace?: {
|
|
19
|
-
readonly branch?: string | undefined;
|
|
20
|
-
};
|
|
21
|
-
}[]>;
|
|
13
|
+
list(activationId?: string): Promise<readonly ArtifactSourceRun[]>;
|
|
22
14
|
};
|
|
23
15
|
}
|
|
24
16
|
export declare class ArtifactRegistrationReactor {
|
|
@@ -29,7 +21,6 @@ export declare class ArtifactRegistrationReactor {
|
|
|
29
21
|
private register;
|
|
30
22
|
reconcileOnce(): Promise<void>;
|
|
31
23
|
private verifyAndRegister;
|
|
32
|
-
private verificationSource;
|
|
33
24
|
private registerVerified;
|
|
34
25
|
private recordUnresolved;
|
|
35
26
|
private branchFor;
|
|
@@ -6,6 +6,7 @@ import { createArtifactEventData } from '../contracts/artifact-event-factory.js'
|
|
|
6
6
|
import { ArtifactEventType } from '../contracts/artifact-events.js';
|
|
7
7
|
import { ArtifactVerificationResult, ArtifactVerificationStatus, } from '../contracts/artifact-vocabulary.js';
|
|
8
8
|
import { integrationStream } from '../contracts/streams.js';
|
|
9
|
+
import { artifactVerificationSource, } from './artifact-verification-source.js';
|
|
9
10
|
import { extendLatestUnresolved } from './latest-unresolved-artifacts.js';
|
|
10
11
|
export class ArtifactRegistrationReactor {
|
|
11
12
|
dependencies;
|
|
@@ -78,7 +79,7 @@ export class ArtifactRegistrationReactor {
|
|
|
78
79
|
const provider = this.dependencies.providers.find((candidate) => candidate.adapter === record.artifact.externalKey.adapter);
|
|
79
80
|
if (provider === undefined)
|
|
80
81
|
return;
|
|
81
|
-
const source = await this.
|
|
82
|
+
const source = await artifactVerificationSource((await this.dependencies.runs.list(record.activationId)).at(-1), branch, record.artifact.name, this.dependencies.resources);
|
|
82
83
|
if (source === null) {
|
|
83
84
|
await this.recordUnresolved(provider, record, ArtifactVerificationResult.NotFound, attempt);
|
|
84
85
|
return;
|
|
@@ -90,26 +91,6 @@ export class ArtifactRegistrationReactor {
|
|
|
90
91
|
}
|
|
91
92
|
await this.registerVerified(record, verified, workItemId);
|
|
92
93
|
}
|
|
93
|
-
async verificationSource(activationId, branch) {
|
|
94
|
-
const run = (await this.dependencies.runs.list(activationId)).at(-1);
|
|
95
|
-
const assignment = run?.repositoryAssignment;
|
|
96
|
-
const repository = assignment === undefined
|
|
97
|
-
? undefined
|
|
98
|
-
: await this.dependencies.resources.get(resourceId(assignment.resourceId));
|
|
99
|
-
if (repository === null)
|
|
100
|
-
return null;
|
|
101
|
-
// Direct workflows keep branch-only verification; head and base are exact only for assignments.
|
|
102
|
-
if (assignment === undefined)
|
|
103
|
-
return { workspaceBranch: branch };
|
|
104
|
-
if (repository === undefined || run?.workspaceRevision === undefined)
|
|
105
|
-
return null;
|
|
106
|
-
return {
|
|
107
|
-
workspaceBranch: branch,
|
|
108
|
-
repository: repository.externalKey,
|
|
109
|
-
workspaceRevision: run.workspaceRevision,
|
|
110
|
-
pullRequestBase: assignment.pullRequestBase,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
94
|
async registerVerified(record, verified, workItemId) {
|
|
114
95
|
const existing = await this.dependencies.resources.findByExternalKey(verified.externalKey);
|
|
115
96
|
// Re-discover an existing resource so a re-report records its newly verified head.
|
|
@@ -177,7 +158,13 @@ function reportedArtifacts(value) {
|
|
|
177
158
|
return artifacts
|
|
178
159
|
.map((artifact) => reportedArtifactSchema.safeParse(artifact))
|
|
179
160
|
.flatMap((result) => result.success
|
|
180
|
-
? [
|
|
161
|
+
? [
|
|
162
|
+
{
|
|
163
|
+
...(result.data.name === undefined ? {} : { name: result.data.name }),
|
|
164
|
+
kind: resourceKind(result.data.kind),
|
|
165
|
+
externalKey: result.data.externalKey,
|
|
166
|
+
},
|
|
167
|
+
]
|
|
181
168
|
: []);
|
|
182
169
|
}
|
|
183
170
|
function context(commandId, correlationId, occurredAt) {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ChangeOutputWorkspace } from '../../execution/index.js';
|
|
2
|
+
import { type ResourceService } from '../../resources/index.js';
|
|
3
|
+
export interface ArtifactSourceRun {
|
|
4
|
+
readonly repositoryAssignment?: {
|
|
5
|
+
readonly resourceId: string;
|
|
6
|
+
readonly pullRequestBase: string;
|
|
7
|
+
} | undefined;
|
|
8
|
+
readonly workspaceRevision?: string | undefined;
|
|
9
|
+
readonly changeOutputs?: readonly ChangeOutputWorkspace[] | undefined;
|
|
10
|
+
readonly workspace?: {
|
|
11
|
+
readonly branch?: string | undefined;
|
|
12
|
+
readonly changeOutputs?: readonly ChangeOutputWorkspace[] | undefined;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/** Resolve a claim name only against Execution's durable snapshot, including ambiguity retries. */
|
|
16
|
+
export declare function artifactVerificationSource(run: ArtifactSourceRun | undefined, branch: string, name: string | undefined, resources: ResourceService): Promise<{
|
|
17
|
+
workspaceBranch: string;
|
|
18
|
+
repository?: never;
|
|
19
|
+
workspaceRevision?: never;
|
|
20
|
+
pullRequestBase?: never;
|
|
21
|
+
} | {
|
|
22
|
+
workspaceBranch: string;
|
|
23
|
+
repository: import("../../resources/index.js").ExternalResourceKey;
|
|
24
|
+
workspaceRevision: string;
|
|
25
|
+
pullRequestBase: string;
|
|
26
|
+
} | null>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { resourceId } from '../../resources/index.js';
|
|
2
|
+
/** Resolve a claim name only against Execution's durable snapshot, including ambiguity retries. */
|
|
3
|
+
export async function artifactVerificationSource(run, branch, name, resources) {
|
|
4
|
+
const source = namedSource(run, branch, name);
|
|
5
|
+
if (source === null)
|
|
6
|
+
return null;
|
|
7
|
+
const assignment = source.repositoryAssignment;
|
|
8
|
+
// Direct workflows retain branch-only verification.
|
|
9
|
+
if (assignment === undefined)
|
|
10
|
+
return { workspaceBranch: source.branch };
|
|
11
|
+
const repository = await resources.get(resourceId(assignment.resourceId));
|
|
12
|
+
if (repository === null || source.workspaceRevision === undefined)
|
|
13
|
+
return null;
|
|
14
|
+
return {
|
|
15
|
+
workspaceBranch: source.branch,
|
|
16
|
+
repository: repository.externalKey,
|
|
17
|
+
workspaceRevision: source.workspaceRevision,
|
|
18
|
+
pullRequestBase: assignment.pullRequestBase,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function namedSource(run, branch, name) {
|
|
22
|
+
if (run?.workspace?.changeOutputs === undefined)
|
|
23
|
+
return {
|
|
24
|
+
branch,
|
|
25
|
+
repositoryAssignment: run?.repositoryAssignment,
|
|
26
|
+
workspaceRevision: run?.workspaceRevision,
|
|
27
|
+
};
|
|
28
|
+
const output = run.changeOutputs?.find((entry) => entry.name === name);
|
|
29
|
+
return output === undefined
|
|
30
|
+
? null
|
|
31
|
+
: {
|
|
32
|
+
branch: output.branch,
|
|
33
|
+
repositoryAssignment: output.repository,
|
|
34
|
+
workspaceRevision: output.revision,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { decidePullRequestOutputAuthority, PullRequestState, reportedArtifactSchema, } from '../../activities/index.js';
|
|
2
|
+
import { ActivityOutcomeKind, decidePullRequestOutputAuthority, PullRequestState, reportedArtifactSchema, } from '../../activities/index.js';
|
|
3
3
|
import { RunStatus, WorkspaceMode } from '../../execution/index.js';
|
|
4
4
|
import { DelegationPrerequisiteCondition as Condition } from '../../orchestration/index.js';
|
|
5
5
|
import { BuiltInResourceKind, ResourceCorrelationProvenance, ResourceCorrelationRole, resourceId, } from '../../resources/index.js';
|
|
@@ -19,15 +19,26 @@ export function createDelegationOutputs(input) {
|
|
|
19
19
|
return qualifyingChange(input, child, output, condition);
|
|
20
20
|
},
|
|
21
21
|
async qualifyingOutputs(child, outputs) {
|
|
22
|
-
const
|
|
23
|
-
const references = artifacts.length === 0 ? [] : await input.artifacts.qualifyingOutputs(child, artifacts);
|
|
24
|
-
if (references === null)
|
|
25
|
-
return null;
|
|
22
|
+
const references = [];
|
|
26
23
|
for (const output of outputs) {
|
|
27
|
-
if (
|
|
24
|
+
if ('path' in output) {
|
|
25
|
+
const selected = await input.artifacts.qualifyingOutputs(child, [output]);
|
|
26
|
+
if (selected === null) {
|
|
27
|
+
if (output.required !== false)
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
else
|
|
31
|
+
references.push(...selected);
|
|
28
32
|
continue;
|
|
33
|
+
}
|
|
29
34
|
const change = await qualifyingChange(input, child, output);
|
|
30
|
-
if (change === null)
|
|
35
|
+
if (change === null) {
|
|
36
|
+
if (output.required !== false)
|
|
37
|
+
return null;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (references.some((entry) => 'resourceId' in entry.reference &&
|
|
41
|
+
entry.reference.resourceId === change.reference.resourceId))
|
|
31
42
|
return null;
|
|
32
43
|
references.push(change);
|
|
33
44
|
}
|
|
@@ -35,17 +46,22 @@ export function createDelegationOutputs(input) {
|
|
|
35
46
|
},
|
|
36
47
|
};
|
|
37
48
|
}
|
|
49
|
+
/** Latest run's claim for a name; identical repeats collapse, conflicting repeats yield no claim. */
|
|
38
50
|
function reportedChange(runs, name) {
|
|
39
|
-
|
|
40
|
-
.flatMap((run) => {
|
|
51
|
+
const claims = runs.flatMap((run) => {
|
|
41
52
|
const data = reportsSchema.safeParse(run.outcome?.data);
|
|
42
|
-
|
|
43
|
-
? data.data.reportedArtifacts
|
|
44
|
-
.filter((entry) => entry.name === name && entry.kind === BuiltInResourceKind.PullRequest)
|
|
45
|
-
.map((report) => ({ run, report }))
|
|
53
|
+
const reports = data.success
|
|
54
|
+
? data.data.reportedArtifacts.filter((entry) => entry.name === name && entry.kind === BuiltInResourceKind.PullRequest)
|
|
46
55
|
: [];
|
|
47
|
-
|
|
48
|
-
|
|
56
|
+
return reports.length === 0 ? [] : [{ run, reports }];
|
|
57
|
+
});
|
|
58
|
+
const latest = claims.at(-1);
|
|
59
|
+
const report = latest?.reports[0];
|
|
60
|
+
if (latest === undefined || report === undefined)
|
|
61
|
+
return undefined;
|
|
62
|
+
const conflicting = latest.reports.some((entry) => entry.externalKey.adapter !== report.externalKey.adapter ||
|
|
63
|
+
entry.externalKey.key !== report.externalKey.key);
|
|
64
|
+
return conflicting ? undefined : { run: latest.run, report };
|
|
49
65
|
}
|
|
50
66
|
async function verifiedChange(input, report, source) {
|
|
51
67
|
const { assignment, branch, revision } = source;
|
|
@@ -74,14 +90,18 @@ async function verifiedChange(input, report, source) {
|
|
|
74
90
|
async function qualifyingChange(input, child, output, condition) {
|
|
75
91
|
const runs = (await input.runs()).filter((run) => run.workflowInstanceId === child.workflowInstanceId &&
|
|
76
92
|
run.status === RunStatus.Succeeded &&
|
|
93
|
+
hasSuccessfulOutcome(run) &&
|
|
77
94
|
child.acceptedOutcomes.includes(run.activationId));
|
|
78
95
|
const latest = reportedChange(runs, output.name);
|
|
79
96
|
if (latest === undefined)
|
|
80
97
|
return null;
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
98
|
+
// A revision run may omit the report, but only this output's own branch may refresh it.
|
|
99
|
+
const run = runs
|
|
100
|
+
.filter((entry) => entry.workspace?.mode === WorkspaceMode.Branch &&
|
|
101
|
+
(latest.run.workspace?.changeOutputs === undefined ||
|
|
102
|
+
entry.changeOutputs?.some((source) => source.name === output.name) === true))
|
|
103
|
+
.at(-1);
|
|
104
|
+
const source = run === undefined ? undefined : runSource(run, output.name);
|
|
85
105
|
if (run === undefined || source === undefined)
|
|
86
106
|
return null;
|
|
87
107
|
const { assignment, branch, revision } = source;
|
|
@@ -144,7 +164,17 @@ async function hasOutputAuthority(input, child, output, id, revision) {
|
|
|
144
164
|
return false;
|
|
145
165
|
return true;
|
|
146
166
|
}
|
|
147
|
-
function runSource(run) {
|
|
167
|
+
function runSource(run, name) {
|
|
168
|
+
if (run.workspace?.changeOutputs !== undefined) {
|
|
169
|
+
const output = run.changeOutputs?.find((entry) => entry.name === name);
|
|
170
|
+
return output === undefined
|
|
171
|
+
? undefined
|
|
172
|
+
: {
|
|
173
|
+
assignment: output.repository,
|
|
174
|
+
branch: output.branch,
|
|
175
|
+
revision: output.revision,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
148
178
|
const assignment = run.repositoryAssignment;
|
|
149
179
|
const branch = run.workspace?.branch;
|
|
150
180
|
const revision = run.workspaceRevision;
|
|
@@ -152,3 +182,9 @@ function runSource(run) {
|
|
|
152
182
|
return undefined;
|
|
153
183
|
return { assignment, branch, revision };
|
|
154
184
|
}
|
|
185
|
+
function hasSuccessfulOutcome(run) {
|
|
186
|
+
return (run.outcome !== undefined &&
|
|
187
|
+
run.outcome.kind !== ActivityOutcomeKind.Failed &&
|
|
188
|
+
run.outcome.kind !== ActivityOutcomeKind.Blocked &&
|
|
189
|
+
run.outcome.kind !== ActivityOutcomeKind.Rejected);
|
|
190
|
+
}
|
|
@@ -12,6 +12,7 @@ export interface ArtifactVerificationUnresolvedPayload {
|
|
|
12
12
|
readonly workflowInstanceId: ReturnType<typeof workflowInstanceId>;
|
|
13
13
|
readonly activationId: ReturnType<typeof activationId>;
|
|
14
14
|
readonly artifact: {
|
|
15
|
+
readonly name?: string | undefined;
|
|
15
16
|
readonly kind: ResourceKind;
|
|
16
17
|
readonly externalKey: {
|
|
17
18
|
readonly adapter: AdapterId;
|
|
@@ -20,6 +20,7 @@ const schema = eventEnvelopeSchema
|
|
|
20
20
|
activationId: brandedStringSchema(activationId),
|
|
21
21
|
artifact: z
|
|
22
22
|
.object({
|
|
23
|
+
name: z.string().min(1).optional(),
|
|
23
24
|
kind: brandedStringSchema(resourceKind),
|
|
24
25
|
externalKey: z
|
|
25
26
|
.object({ adapter: brandedStringSchema(adapterId), key: z.string().min(1) })
|
|
@@ -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
|
})[];
|