@atolis-hq/wake 0.4.95 → 0.4.97
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 +12 -1
- package/dist/src/activities/agent/agent-result.d.ts +1 -0
- package/dist/src/activities/agent/agent-result.js +1 -0
- package/dist/src/activities/contracts/activity.d.ts +7 -0
- package/dist/src/artifacts/application/delegation-artifacts.d.ts +29 -0
- package/dist/src/artifacts/application/delegation-artifacts.js +37 -0
- package/dist/src/artifacts/index.d.ts +1 -0
- package/dist/src/artifacts/index.js +1 -0
- package/dist/src/bootstrap/composition-root.d.ts +6 -1
- package/dist/src/bootstrap/composition-root.js +50 -12
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +3 -1
- package/dist/src/control-plane/application/activation-scheduler.js +28 -43
- package/dist/src/control-plane/application/advance-once-dispatch.d.ts +1 -14
- package/dist/src/control-plane/application/advance-once-dispatch.js +14 -26
- package/dist/src/control-plane/application/dispatch-resources.d.ts +4 -0
- package/dist/src/control-plane/application/dispatch-resources.js +13 -0
- package/dist/src/control-plane/application/in-process-scheduler-serialiser.d.ts +1 -0
- package/dist/src/control-plane/application/in-process-scheduler-serialiser.js +15 -0
- package/dist/src/control-plane/application/runner-quota-outcome.d.ts +13 -0
- package/dist/src/control-plane/application/runner-quota-outcome.js +23 -0
- package/dist/src/execution/application/execution-service.js +27 -5
- package/dist/src/execution/application/execution-validation.d.ts +6 -1
- package/dist/src/execution/application/execution-validation.js +29 -11
- package/dist/src/execution/application/repository-assignments.d.ts +11 -0
- package/dist/src/execution/application/repository-assignments.js +18 -0
- package/dist/src/execution/application/run-lifecycle.d.ts +1 -0
- package/dist/src/execution/application/run-lifecycle.js +30 -10
- package/dist/src/execution/contracts/commands.d.ts +2 -0
- package/dist/src/execution/contracts/events.d.ts +20 -0
- package/dist/src/execution/contracts/events.js +9 -0
- package/dist/src/execution/contracts/repository-assignment.d.ts +17 -0
- package/dist/src/execution/contracts/repository-assignment.js +9 -0
- package/dist/src/execution/contracts/views.d.ts +5 -0
- package/dist/src/execution/contracts/workspace.d.ts +6 -0
- package/dist/src/execution/domain/run.js +9 -0
- package/dist/src/execution/index.d.ts +3 -0
- package/dist/src/execution/index.js +3 -0
- package/dist/src/execution/infrastructure/workspace/git-source.d.ts +6 -0
- package/dist/src/execution/infrastructure/workspace/git-source.js +35 -0
- package/dist/src/execution/infrastructure/workspace/git-workspace.d.ts +5 -0
- package/dist/src/execution/infrastructure/workspace/git-workspace.js +50 -3
- package/dist/src/integrations/application/artifact-registration-reactor.d.ts +6 -0
- package/dist/src/integrations/application/artifact-registration-reactor.js +35 -11
- package/dist/src/integrations/application/artifact-source.d.ts +9 -0
- package/dist/src/integrations/application/artifact-source.js +12 -0
- package/dist/src/integrations/application/delegation-outputs.d.ts +15 -0
- package/dist/src/integrations/application/delegation-outputs.js +118 -0
- package/dist/src/integrations/contracts/provider.d.ts +3 -0
- package/dist/src/integrations/fake/external-source.d.ts +1 -0
- package/dist/src/integrations/fake/inbound-translator.js +1 -0
- package/dist/src/integrations/fake/provider.d.ts +1 -0
- package/dist/src/integrations/fake/provider.js +11 -2
- package/dist/src/integrations/github/provider.js +7 -1
- package/dist/src/integrations/index.d.ts +1 -0
- package/dist/src/integrations/index.js +1 -0
- package/dist/src/orchestration/application/accept-signal.d.ts +3 -1
- package/dist/src/orchestration/application/accept-signal.js +2 -0
- package/dist/src/orchestration/application/advance-workflow.d.ts +0 -1
- package/dist/src/orchestration/application/advance-workflow.js +0 -4
- package/dist/src/orchestration/application/deferred-signals.d.ts +21 -0
- package/dist/src/orchestration/application/deferred-signals.js +119 -0
- package/dist/src/orchestration/application/delegated-work.d.ts +60 -0
- package/dist/src/orchestration/application/delegated-work.js +456 -0
- package/dist/src/orchestration/application/delegation-gate.d.ts +17 -0
- package/dist/src/orchestration/application/delegation-gate.js +31 -0
- package/dist/src/orchestration/application/delegation-ledger.d.ts +28 -0
- package/dist/src/orchestration/application/delegation-ledger.js +79 -0
- package/dist/src/orchestration/application/delegation-reservation.d.ts +15 -0
- package/dist/src/orchestration/application/delegation-reservation.js +77 -0
- package/dist/src/orchestration/application/expire-timed-out-waits.d.ts +1 -1
- package/dist/src/orchestration/application/expire-timed-out-waits.js +2 -2
- package/dist/src/orchestration/application/orchestration-projection.js +5 -1
- package/dist/src/orchestration/application/orchestration-repository.d.ts +5 -0
- package/dist/src/orchestration/application/orchestration-repository.js +69 -11
- package/dist/src/orchestration/application/orchestration-service.d.ts +43 -3
- package/dist/src/orchestration/application/orchestration-service.js +73 -20
- package/dist/src/orchestration/application/resource-transition-matching.js +11 -6
- package/dist/src/orchestration/application/start-workflow.js +4 -2
- package/dist/src/orchestration/application/workflow-definition-registry.d.ts +5 -1
- package/dist/src/orchestration/application/workflow-definition-registry.js +16 -3
- package/dist/src/orchestration/contracts/commands.d.ts +1 -0
- package/dist/src/orchestration/contracts/delegation-ports.d.ts +19 -0
- package/dist/src/orchestration/contracts/delegation-ports.js +1 -0
- package/dist/src/orchestration/contracts/delegation.d.ts +143 -0
- package/dist/src/orchestration/contracts/delegation.js +115 -0
- package/dist/src/orchestration/contracts/event-decoder.js +19 -0
- package/dist/src/orchestration/contracts/event-factory.js +16 -0
- package/dist/src/orchestration/contracts/events.d.ts +39 -0
- package/dist/src/orchestration/contracts/events.js +8 -0
- package/dist/src/orchestration/contracts/views.d.ts +8 -0
- package/dist/src/orchestration/contracts/vocabulary.d.ts +3 -0
- package/dist/src/orchestration/contracts/vocabulary.js +1 -0
- package/dist/src/orchestration/domain/workflow-completion.d.ts +3 -0
- package/dist/src/orchestration/domain/workflow-completion.js +9 -0
- package/dist/src/orchestration/domain/workflow-instance-events.d.ts +2 -0
- package/dist/src/orchestration/domain/workflow-instance-events.js +37 -0
- package/dist/src/orchestration/index.d.ts +2 -0
- package/dist/src/orchestration/index.js +1 -0
- package/dist/src/work/application/work-projection.js +3 -0
- package/dist/src/work/application/work-service.js +16 -0
- package/dist/src/work/contracts/commands.d.ts +6 -0
- package/dist/src/work/contracts/events.d.ts +2 -1
- package/dist/src/work/contracts/events.js +8 -0
- package/dist/src/work/contracts/views.d.ts +2 -1
- package/dist/src/work/domain/work-item.js +3 -0
- package/package.json +1 -1
|
@@ -313,11 +313,20 @@ async function completeRun(runtime, currentRunId, activation, context, startedAt
|
|
|
313
313
|
...(resumeSessionId === undefined ? {} : { resumeSessionId }),
|
|
314
314
|
...(resumeStartedAt === undefined ? {} : { resumeStartedAt }),
|
|
315
315
|
...(usageBaseline === undefined ? {} : { usageBaseline }),
|
|
316
|
-
...(lease === undefined
|
|
316
|
+
...(lease === undefined
|
|
317
|
+
? {}
|
|
318
|
+
: {
|
|
319
|
+
workspace: {
|
|
320
|
+
path: lease.path,
|
|
321
|
+
mode: lease.mode,
|
|
322
|
+
checkoutRevision: lease.checkoutRevision,
|
|
323
|
+
repository: context.repositoryAssignment,
|
|
324
|
+
},
|
|
325
|
+
}),
|
|
317
326
|
reportRunnerStarted,
|
|
318
327
|
});
|
|
319
328
|
await stopRenewal();
|
|
320
|
-
await settleRunSuccess(runtime, currentRunId, activation, context, outcome);
|
|
329
|
+
await settleRunSuccess(runtime, currentRunId, activation, context, outcome, lease);
|
|
321
330
|
}
|
|
322
331
|
catch (error) {
|
|
323
332
|
try {
|
|
@@ -337,17 +346,19 @@ async function completeRun(runtime, currentRunId, activation, context, startedAt
|
|
|
337
346
|
});
|
|
338
347
|
}
|
|
339
348
|
}
|
|
340
|
-
async function settleRunSuccess(runtime, currentRunId, activation, context, outcome) {
|
|
349
|
+
async function settleRunSuccess(runtime, currentRunId, activation, context, outcome, lease) {
|
|
341
350
|
if (await shutdownCancellationSucceeded(runtime, currentRunId)) {
|
|
342
351
|
await confirmCancellation(runtime.repository, runtime.dependencies.clock, currentRunId);
|
|
343
352
|
return;
|
|
344
353
|
}
|
|
354
|
+
const workspaceRevision = await lease?.readRevision?.();
|
|
345
355
|
await recordRunSuccess({
|
|
346
356
|
dependencies: runLifecycleDependencies(runtime),
|
|
347
357
|
runId: currentRunId,
|
|
348
358
|
activation,
|
|
349
359
|
context,
|
|
350
360
|
outcome,
|
|
361
|
+
...(workspaceRevision === undefined ? {} : { workspaceRevision }),
|
|
351
362
|
});
|
|
352
363
|
}
|
|
353
364
|
async function settleRunFailure(runtime, currentRunId, activation, context, error) {
|
|
@@ -597,8 +608,19 @@ async function claimActivationForAttempt(runtime, activation, currentRunId, owne
|
|
|
597
608
|
occurredAt,
|
|
598
609
|
});
|
|
599
610
|
}
|
|
600
|
-
function acquireAttemptWorkspace(runtime, activation, context, currentRunId, signal) {
|
|
601
|
-
|
|
611
|
+
async function acquireAttemptWorkspace(runtime, activation, context, currentRunId, signal) {
|
|
612
|
+
const previous = context.repositoryAssignment === undefined
|
|
613
|
+
? undefined
|
|
614
|
+
: (await runtime.repository.list())
|
|
615
|
+
.filter((run) => run.orchestrationGroupId === context.orchestrationGroupId &&
|
|
616
|
+
run.workspace?.mode === WorkspaceMode.Branch &&
|
|
617
|
+
run.status === RunStatus.Succeeded)
|
|
618
|
+
.at(-1);
|
|
619
|
+
return acquireWorkspace(currentRunId, activation.execution?.workspace ?? WorkspaceMode.None, context.workItemId, context.resources, runtime.dependencies.workspaces, {
|
|
620
|
+
signal,
|
|
621
|
+
assignment: context.repositoryAssignment,
|
|
622
|
+
reviewRevision: previous?.workspaceRevision,
|
|
623
|
+
});
|
|
602
624
|
}
|
|
603
625
|
function existingRun(runs, clock, owner) {
|
|
604
626
|
const completed = runs.find((run) => run.status === RunStatus.Succeeded);
|
|
@@ -2,7 +2,12 @@ import { type ResourceRequirement } from '../../activities/index.js';
|
|
|
2
2
|
import { type ResourceView } from '../../resources/index.js';
|
|
3
3
|
import type { WorkItemId } from '../../work/index.js';
|
|
4
4
|
import type { RunId } from '../contracts/identifiers.js';
|
|
5
|
+
import type { RepositoryAssignment } from '../contracts/repository-assignment.js';
|
|
5
6
|
import { WorkspaceMode } from '../contracts/vocabulary.js';
|
|
6
7
|
import type { WorkspaceLease, WorkspaceProvider } from '../contracts/workspace.js';
|
|
7
|
-
export declare function acquireWorkspace(runId: RunId, mode: typeof WorkspaceMode.None | typeof WorkspaceMode.ReadOnly | typeof WorkspaceMode.Branch, workItemId: WorkItemId, resources: readonly ResourceView[], provider?: WorkspaceProvider,
|
|
8
|
+
export declare function acquireWorkspace(runId: RunId, mode: typeof WorkspaceMode.None | typeof WorkspaceMode.ReadOnly | typeof WorkspaceMode.Branch, workItemId: WorkItemId, resources: readonly ResourceView[], provider?: WorkspaceProvider, options?: {
|
|
9
|
+
readonly signal?: AbortSignal | undefined;
|
|
10
|
+
readonly assignment?: RepositoryAssignment | undefined;
|
|
11
|
+
readonly reviewRevision?: string | undefined;
|
|
12
|
+
}): Promise<WorkspaceLease | undefined>;
|
|
8
13
|
export declare function validateResourceRequirements(requirements: readonly ResourceRequirement[], resources: readonly ResourceView[]): void;
|
|
@@ -1,33 +1,40 @@
|
|
|
1
1
|
import { ActivityResourceCardinality } from '../../activities/index.js';
|
|
2
2
|
import { BuiltInResourceKind } from '../../resources/index.js';
|
|
3
3
|
import { WorkspaceMode } from '../contracts/vocabulary.js';
|
|
4
|
-
export async function acquireWorkspace(runId, mode, workItemId, resources, provider,
|
|
4
|
+
export async function acquireWorkspace(runId, mode, workItemId, resources, provider, options = {}) {
|
|
5
|
+
const { signal = new AbortController().signal, assignment, reviewRevision } = options;
|
|
5
6
|
if (mode === WorkspaceMode.None)
|
|
6
7
|
return undefined;
|
|
7
8
|
if (provider === undefined)
|
|
8
9
|
throw new Error('Workspace provider is required');
|
|
9
|
-
const repositoryResource = resources
|
|
10
|
-
resources.find((resource) => resource.kind === BuiltInResourceKind.PullRequest) ??
|
|
11
|
-
resources.find((resource) => resource.kind === BuiltInResourceKind.Issue);
|
|
10
|
+
const repositoryResource = selectWorkspaceResource(resources, assignment);
|
|
12
11
|
if (repositoryResource === undefined)
|
|
13
12
|
throw new Error('Repository Resource is required');
|
|
14
13
|
signal.throwIfAborted();
|
|
15
|
-
const
|
|
16
|
-
const checkoutRevision = repositoryResource.kind === BuiltInResourceKind.Repository ||
|
|
17
|
-
(repositoryResource.kind === BuiltInResourceKind.PullRequest &&
|
|
18
|
-
revision !== undefined &&
|
|
19
|
-
/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i.test(revision))
|
|
20
|
-
? revision
|
|
21
|
-
: undefined;
|
|
14
|
+
const checkoutRevision = checkoutTarget(repositoryResource, mode, assignment, reviewRevision);
|
|
22
15
|
return provider.acquire({
|
|
23
16
|
runId,
|
|
24
17
|
signal,
|
|
25
18
|
mode,
|
|
26
19
|
workItemId,
|
|
27
20
|
repositoryResource,
|
|
21
|
+
...(assignment === undefined ? {} : { assignment }),
|
|
28
22
|
...(checkoutRevision === undefined ? {} : { checkoutRevision }),
|
|
29
23
|
});
|
|
30
24
|
}
|
|
25
|
+
function checkoutTarget(resource, mode, assignment, reviewRevision) {
|
|
26
|
+
if (assignment !== undefined)
|
|
27
|
+
return mode === WorkspaceMode.ReadOnly
|
|
28
|
+
? (reviewRevision ?? assignment.sourceRevision)
|
|
29
|
+
: assignment.sourceRevision;
|
|
30
|
+
if (resource.kind === BuiltInResourceKind.Repository)
|
|
31
|
+
return resource.revision;
|
|
32
|
+
if (resource.kind === BuiltInResourceKind.PullRequest &&
|
|
33
|
+
resource.revision !== undefined &&
|
|
34
|
+
/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i.test(resource.revision))
|
|
35
|
+
return resource.revision;
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
31
38
|
export function validateResourceRequirements(requirements, resources) {
|
|
32
39
|
for (const requirement of requirements) {
|
|
33
40
|
const count = resources.filter((resource) => resource.capabilities.includes(requirement.capability)).length;
|
|
@@ -39,3 +46,14 @@ export function validateResourceRequirements(requirements, resources) {
|
|
|
39
46
|
throw new Error(`Activity allows at most one ${requirement.capability} Resource`);
|
|
40
47
|
}
|
|
41
48
|
}
|
|
49
|
+
function selectWorkspaceResource(resources, assignment) {
|
|
50
|
+
const repositoryResource = assignment === undefined
|
|
51
|
+
? (resources.find((resource) => resource.kind === BuiltInResourceKind.Repository) ??
|
|
52
|
+
resources.find((resource) => resource.kind === BuiltInResourceKind.PullRequest) ??
|
|
53
|
+
resources.find((resource) => resource.kind === BuiltInResourceKind.Issue))
|
|
54
|
+
: resources.find((resource) => resource.resourceId === assignment.resourceId &&
|
|
55
|
+
resource.kind === BuiltInResourceKind.Repository);
|
|
56
|
+
if (assignment !== undefined && repositoryResource === undefined)
|
|
57
|
+
throw new Error('Assigned Repository Resource ' + assignment.resourceId + ' is unavailable');
|
|
58
|
+
return repositoryResource;
|
|
59
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ResourceService } from '../../resources/index.js';
|
|
2
|
+
import type { WorkItemId } from '../../work/index.js';
|
|
3
|
+
import type { RepositoryAssignment, RepositoryAssignmentRequest } from '../contracts/repository-assignment.js';
|
|
4
|
+
/** Correlations are the parent's explicit repository authority, not the provider catalogue. */
|
|
5
|
+
export declare function createRepositoryAssignments(resources: ResourceService, resolveSource: (request: RepositoryAssignmentRequest) => Promise<RepositoryAssignment>, inherited: (workItemId: string) => Promise<{
|
|
6
|
+
readonly resourceId: string;
|
|
7
|
+
} | undefined>): {
|
|
8
|
+
resolve(parent: {
|
|
9
|
+
readonly workItemId: WorkItemId;
|
|
10
|
+
}, request: RepositoryAssignmentRequest): Promise<RepositoryAssignment>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BuiltInResourceKind, resourceId } from '../../resources/index.js';
|
|
2
|
+
/** Correlations are the parent's explicit repository authority, not the provider catalogue. */
|
|
3
|
+
export function createRepositoryAssignments(resources, resolveSource, inherited) {
|
|
4
|
+
return {
|
|
5
|
+
async resolve(parent, request) {
|
|
6
|
+
const repository = await resources.get(resourceId(request.resourceId));
|
|
7
|
+
if (repository === null || repository.kind !== BuiltInResourceKind.Repository)
|
|
8
|
+
throw new Error(`Repository Resource ${request.resourceId} is unavailable; select an existing Repository Resource`);
|
|
9
|
+
const correlations = await resources.correlationsForWork(parent.workItemId);
|
|
10
|
+
const scope = await inherited(parent.workItemId);
|
|
11
|
+
if (scope === undefined
|
|
12
|
+
? !correlations.some((entry) => entry.resourceId === repository.resourceId)
|
|
13
|
+
: scope.resourceId !== repository.resourceId)
|
|
14
|
+
throw new Error(`Repository ${request.resourceId} is outside the parent assignment; explicitly authorize the repository before delegating`);
|
|
15
|
+
return resolveSource(request);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -50,6 +50,7 @@ export declare function recordRunSuccess(input: {
|
|
|
50
50
|
readonly activation: ExecutionActivation;
|
|
51
51
|
readonly context: ExecutionAttemptContext;
|
|
52
52
|
readonly outcome: ActivityOutcome;
|
|
53
|
+
readonly workspaceRevision?: string;
|
|
53
54
|
}): Promise<void>;
|
|
54
55
|
export declare function recordRunFailure(input: {
|
|
55
56
|
readonly dependencies: RunLifecycleDependencies;
|
|
@@ -53,15 +53,7 @@ export async function startRun(input) {
|
|
|
53
53
|
payload: {
|
|
54
54
|
...runPreparationPayload(activation, context, attempt, runner),
|
|
55
55
|
startedAt,
|
|
56
|
-
...(lease
|
|
57
|
-
? {}
|
|
58
|
-
: {
|
|
59
|
-
workspace: {
|
|
60
|
-
mode: lease.mode,
|
|
61
|
-
path: lease.path,
|
|
62
|
-
...(lease.branch === undefined ? {} : { branch: lease.branch }),
|
|
63
|
-
},
|
|
64
|
-
}),
|
|
56
|
+
...workspacePayload(lease),
|
|
65
57
|
},
|
|
66
58
|
}),
|
|
67
59
|
]);
|
|
@@ -76,6 +68,9 @@ export async function startRun(input) {
|
|
|
76
68
|
}
|
|
77
69
|
function runPreparationPayload(activation, context, attempt, runner) {
|
|
78
70
|
return {
|
|
71
|
+
...(context.repositoryAssignment === undefined
|
|
72
|
+
? {}
|
|
73
|
+
: { repositoryAssignment: context.repositoryAssignment }),
|
|
79
74
|
activationId: activation.activationId,
|
|
80
75
|
activity: activation.activity,
|
|
81
76
|
...(activation.stage === undefined ? {} : { stage: activation.stage }),
|
|
@@ -124,7 +119,13 @@ export async function recordRunSuccess(input) {
|
|
|
124
119
|
occurredAt: finishedAt,
|
|
125
120
|
correlationId: context.orchestrationGroupId,
|
|
126
121
|
causationId: activation.activationId,
|
|
127
|
-
payload: {
|
|
122
|
+
payload: {
|
|
123
|
+
outcome,
|
|
124
|
+
finishedAt,
|
|
125
|
+
...(input.workspaceRevision === undefined
|
|
126
|
+
? {}
|
|
127
|
+
: { workspaceRevision: input.workspaceRevision }),
|
|
128
|
+
},
|
|
128
129
|
}),
|
|
129
130
|
]);
|
|
130
131
|
}
|
|
@@ -181,3 +182,22 @@ function requireRunEventData(event) {
|
|
|
181
182
|
return event;
|
|
182
183
|
}
|
|
183
184
|
}
|
|
185
|
+
function workspacePayload(lease) {
|
|
186
|
+
return {
|
|
187
|
+
...(lease === undefined
|
|
188
|
+
? {}
|
|
189
|
+
: {
|
|
190
|
+
workspace: {
|
|
191
|
+
mode: lease.mode,
|
|
192
|
+
...(lease.repositoryResourceId === undefined
|
|
193
|
+
? {}
|
|
194
|
+
: { repositoryResourceId: lease.repositoryResourceId }),
|
|
195
|
+
...(lease.checkoutRevision === undefined
|
|
196
|
+
? {}
|
|
197
|
+
: { checkoutRevision: lease.checkoutRevision }),
|
|
198
|
+
path: lease.path,
|
|
199
|
+
...(lease.branch === undefined ? {} : { branch: lease.branch }),
|
|
200
|
+
},
|
|
201
|
+
}),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ActivationId, ActivityName, ActivityOrchestrationGroupId, ActivityWorkflowInstanceId } from '../../activities/index.js';
|
|
2
2
|
import type { ResourceView } from '../../resources/index.js';
|
|
3
3
|
import type { WorkItemId } from '../../work/index.js';
|
|
4
|
+
import type { RepositoryAssignment } from './repository-assignment.js';
|
|
4
5
|
import type { WorkspaceMode } from './vocabulary.js';
|
|
5
6
|
export interface ExecutionActivation {
|
|
6
7
|
readonly activationId: ActivationId;
|
|
@@ -20,6 +21,7 @@ export interface ExecutionAttemptContext {
|
|
|
20
21
|
readonly workflowInstanceId: ActivityWorkflowInstanceId;
|
|
21
22
|
readonly orchestrationGroupId: ActivityOrchestrationGroupId;
|
|
22
23
|
readonly resources: readonly ResourceView[];
|
|
24
|
+
readonly repositoryAssignment?: RepositoryAssignment;
|
|
23
25
|
readonly owner?: string;
|
|
24
26
|
/** Runner names currently quota-paused; unset means none. */
|
|
25
27
|
readonly ineligibleRunners?: ReadonlySet<string>;
|
|
@@ -3,6 +3,7 @@ import { z } from 'zod';
|
|
|
3
3
|
import { type ActivationId, type ActivityName, type ActivityOrchestrationGroupId, type ActivityOutcome, type ActivityWorkflowInstanceId } from '../../activities/index.js';
|
|
4
4
|
import { runId } from './identifiers.js';
|
|
5
5
|
import type { Cancellation, ExternalExecutionReference, Lease } from './liveness.js';
|
|
6
|
+
import { type RepositoryAssignment } from './repository-assignment.js';
|
|
6
7
|
import type { ExecutionFailure, RecordedRunnerResult, RecoveredRunResult } from './results.js';
|
|
7
8
|
import { type ActivationStreamRef, type RunStreamRef } from './streams.js';
|
|
8
9
|
import { WorkspaceMode } from './vocabulary.js';
|
|
@@ -12,6 +13,12 @@ export declare const runStartedPayloadSchema: z.ZodObject<{
|
|
|
12
13
|
stage: z.ZodOptional<z.ZodString>;
|
|
13
14
|
workflowInstanceId: z.ZodPipe<z.ZodString, z.ZodTransform<ActivityWorkflowInstanceId, string>>;
|
|
14
15
|
orchestrationGroupId: z.ZodPipe<z.ZodString, z.ZodTransform<ActivityOrchestrationGroupId, string>>;
|
|
16
|
+
repositoryAssignment: z.ZodOptional<z.ZodObject<{
|
|
17
|
+
resourceId: z.ZodString;
|
|
18
|
+
sourceRef: z.ZodString;
|
|
19
|
+
sourceRevision: z.ZodString;
|
|
20
|
+
pullRequestBase: z.ZodString;
|
|
21
|
+
}, z.core.$strict>>;
|
|
15
22
|
attempt: z.ZodNumber;
|
|
16
23
|
startedAt: z.ZodISODateTime;
|
|
17
24
|
runner: z.ZodOptional<z.ZodObject<{
|
|
@@ -28,6 +35,8 @@ export declare const runStartedPayloadSchema: z.ZodObject<{
|
|
|
28
35
|
}>;
|
|
29
36
|
path: z.ZodString;
|
|
30
37
|
branch: z.ZodOptional<z.ZodString>;
|
|
38
|
+
repositoryResourceId: z.ZodOptional<z.ZodString>;
|
|
39
|
+
checkoutRevision: z.ZodOptional<z.ZodString>;
|
|
31
40
|
}, z.core.$strict>>;
|
|
32
41
|
}, z.core.$strict>;
|
|
33
42
|
export declare const runPreparationStartedPayloadSchema: z.ZodObject<{
|
|
@@ -36,6 +45,12 @@ export declare const runPreparationStartedPayloadSchema: z.ZodObject<{
|
|
|
36
45
|
stage: z.ZodOptional<z.ZodString>;
|
|
37
46
|
workflowInstanceId: z.ZodPipe<z.ZodString, z.ZodTransform<ActivityWorkflowInstanceId, string>>;
|
|
38
47
|
orchestrationGroupId: z.ZodPipe<z.ZodString, z.ZodTransform<ActivityOrchestrationGroupId, string>>;
|
|
48
|
+
repositoryAssignment: z.ZodOptional<z.ZodObject<{
|
|
49
|
+
resourceId: z.ZodString;
|
|
50
|
+
sourceRef: z.ZodString;
|
|
51
|
+
sourceRevision: z.ZodString;
|
|
52
|
+
pullRequestBase: z.ZodString;
|
|
53
|
+
}, z.core.$strict>>;
|
|
39
54
|
attempt: z.ZodNumber;
|
|
40
55
|
startedAt: z.ZodISODateTime;
|
|
41
56
|
runner: z.ZodOptional<z.ZodObject<{
|
|
@@ -106,6 +121,7 @@ export interface RunStartedPayload {
|
|
|
106
121
|
readonly stage?: string | undefined;
|
|
107
122
|
readonly workflowInstanceId: ActivityWorkflowInstanceId;
|
|
108
123
|
readonly orchestrationGroupId: ActivityOrchestrationGroupId;
|
|
124
|
+
readonly repositoryAssignment?: RepositoryAssignment | undefined;
|
|
109
125
|
readonly attempt: number;
|
|
110
126
|
readonly startedAt: string;
|
|
111
127
|
readonly runner?: {
|
|
@@ -119,6 +135,8 @@ export interface RunStartedPayload {
|
|
|
119
135
|
readonly mode: typeof WorkspaceMode.ReadOnly | typeof WorkspaceMode.Branch;
|
|
120
136
|
readonly path: string;
|
|
121
137
|
readonly branch?: string | undefined;
|
|
138
|
+
readonly repositoryResourceId?: string | undefined;
|
|
139
|
+
readonly checkoutRevision?: string | undefined;
|
|
122
140
|
} | undefined;
|
|
123
141
|
}
|
|
124
142
|
export interface RunPreparationStartedPayload {
|
|
@@ -127,6 +145,7 @@ export interface RunPreparationStartedPayload {
|
|
|
127
145
|
readonly stage?: string | undefined;
|
|
128
146
|
readonly workflowInstanceId: ActivityWorkflowInstanceId;
|
|
129
147
|
readonly orchestrationGroupId: ActivityOrchestrationGroupId;
|
|
148
|
+
readonly repositoryAssignment?: RepositoryAssignment | undefined;
|
|
130
149
|
readonly attempt: number;
|
|
131
150
|
readonly startedAt: string;
|
|
132
151
|
readonly runner?: {
|
|
@@ -145,6 +164,7 @@ export interface RunExecutionEventPayloads {
|
|
|
145
164
|
readonly [ExecutionEventType.RunPreparationStarted]: RunPreparationStartedPayload;
|
|
146
165
|
readonly [ExecutionEventType.RunStarted]: RunStartedPayload;
|
|
147
166
|
readonly [ExecutionEventType.RunSucceeded]: {
|
|
167
|
+
readonly workspaceRevision?: string | undefined;
|
|
148
168
|
readonly outcome: ActivityOutcome;
|
|
149
169
|
readonly finishedAt: string;
|
|
150
170
|
};
|
|
@@ -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 { runId } from './identifiers.js';
|
|
6
|
+
import { repositoryAssignmentSchema } from './repository-assignment.js';
|
|
6
7
|
import { ExecutionStreamKind } from './streams.js';
|
|
7
8
|
import { ExecutionCancellationReason, ExecutionFailureCode, RunStatus, WorkspaceMode, } from './vocabulary.js';
|
|
8
9
|
export const runStartedPayloadSchema = z
|
|
@@ -12,6 +13,7 @@ export const runStartedPayloadSchema = z
|
|
|
12
13
|
stage: z.string().min(1).optional(),
|
|
13
14
|
workflowInstanceId: brandedStringSchema(activityWorkflowInstanceId),
|
|
14
15
|
orchestrationGroupId: brandedStringSchema(activityOrchestrationGroupId),
|
|
16
|
+
repositoryAssignment: repositoryAssignmentSchema.optional(),
|
|
15
17
|
attempt: z.number().int().positive(),
|
|
16
18
|
startedAt: offsetIsoTimestampSchema,
|
|
17
19
|
runner: z
|
|
@@ -29,6 +31,8 @@ export const runStartedPayloadSchema = z
|
|
|
29
31
|
mode: z.enum([WorkspaceMode.ReadOnly, WorkspaceMode.Branch]),
|
|
30
32
|
path: z.string().min(1),
|
|
31
33
|
branch: z.string().min(1).optional(),
|
|
34
|
+
repositoryResourceId: z.string().min(1).optional(),
|
|
35
|
+
checkoutRevision: z.string().min(1).optional(),
|
|
32
36
|
})
|
|
33
37
|
.strict()
|
|
34
38
|
.optional(),
|
|
@@ -41,6 +45,7 @@ export const runPreparationStartedPayloadSchema = z
|
|
|
41
45
|
stage: z.string().min(1).optional(),
|
|
42
46
|
workflowInstanceId: brandedStringSchema(activityWorkflowInstanceId),
|
|
43
47
|
orchestrationGroupId: brandedStringSchema(activityOrchestrationGroupId),
|
|
48
|
+
repositoryAssignment: repositoryAssignmentSchema.optional(),
|
|
44
49
|
attempt: z.number().int().positive(),
|
|
45
50
|
startedAt: offsetIsoTimestampSchema,
|
|
46
51
|
runner: z
|
|
@@ -158,6 +163,10 @@ const runEventSchema = eventEnvelopeSchema.extend({
|
|
|
158
163
|
eventType: z.literal(ExecutionEventType.RunSucceeded),
|
|
159
164
|
payload: z
|
|
160
165
|
.object({
|
|
166
|
+
workspaceRevision: z
|
|
167
|
+
.string()
|
|
168
|
+
.regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i)
|
|
169
|
+
.optional(),
|
|
161
170
|
outcome: z.object({ kind: z.string().min(1), data: z.unknown().optional() }).strict(),
|
|
162
171
|
finishedAt: offsetIsoTimestampSchema,
|
|
163
172
|
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const repositoryAssignmentSchema: z.ZodObject<{
|
|
3
|
+
resourceId: z.ZodString;
|
|
4
|
+
sourceRef: z.ZodString;
|
|
5
|
+
sourceRevision: z.ZodString;
|
|
6
|
+
pullRequestBase: z.ZodString;
|
|
7
|
+
}, z.core.$strict>;
|
|
8
|
+
/** Durable source and logical delivery base are independent Git identities. */
|
|
9
|
+
export interface RepositoryAssignment {
|
|
10
|
+
readonly resourceId: string;
|
|
11
|
+
readonly sourceRef: string;
|
|
12
|
+
readonly sourceRevision: string;
|
|
13
|
+
readonly pullRequestBase: string;
|
|
14
|
+
}
|
|
15
|
+
export type RepositoryAssignmentRequest = Omit<RepositoryAssignment, 'sourceRevision'> & {
|
|
16
|
+
readonly sourceRevision?: string | undefined;
|
|
17
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const repositoryAssignmentSchema = z
|
|
3
|
+
.object({
|
|
4
|
+
resourceId: z.string().min(1),
|
|
5
|
+
sourceRef: z.string().min(1),
|
|
6
|
+
sourceRevision: z.string().regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i),
|
|
7
|
+
pullRequestBase: z.string().min(1),
|
|
8
|
+
})
|
|
9
|
+
.strict();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ActivationId, ActivityName, ActivityOrchestrationGroupId, ActivityOutcome, ActivityWorkflowInstanceId } from '../../activities/index.js';
|
|
2
2
|
import type { RunId } from './identifiers.js';
|
|
3
3
|
import type { Cancellation, ExternalExecutionReference, Lease } from './liveness.js';
|
|
4
|
+
import type { RepositoryAssignment } from './repository-assignment.js';
|
|
4
5
|
import type { ExecutionFailure } from './results.js';
|
|
5
6
|
import type { AgentRunResponse } from './runner.js';
|
|
6
7
|
import type { WorkspaceMode } from './vocabulary.js';
|
|
@@ -11,6 +12,7 @@ export interface RunView {
|
|
|
11
12
|
readonly contextScope: string;
|
|
12
13
|
readonly revisionId: string | null;
|
|
13
14
|
};
|
|
15
|
+
readonly repositoryAssignment?: RepositoryAssignment | undefined;
|
|
14
16
|
readonly runId: RunId;
|
|
15
17
|
readonly activationId: ActivationId;
|
|
16
18
|
readonly activity: ActivityName;
|
|
@@ -32,12 +34,15 @@ export interface RunView {
|
|
|
32
34
|
readonly cli?: string | undefined;
|
|
33
35
|
} | undefined;
|
|
34
36
|
readonly finishedAt?: string;
|
|
37
|
+
readonly workspaceRevision?: string | undefined;
|
|
35
38
|
readonly outcome?: ActivityOutcome;
|
|
36
39
|
readonly failure?: ExecutionFailure;
|
|
37
40
|
readonly workspace?: {
|
|
38
41
|
readonly mode: typeof WorkspaceMode.ReadOnly | typeof WorkspaceMode.Branch;
|
|
39
42
|
readonly path: string;
|
|
40
43
|
readonly branch?: string | undefined;
|
|
44
|
+
readonly repositoryResourceId?: string | undefined;
|
|
45
|
+
readonly checkoutRevision?: string | undefined;
|
|
41
46
|
};
|
|
42
47
|
readonly lease?: Lease;
|
|
43
48
|
readonly externalExecution?: ExternalExecutionReference;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ResourceView } from '../../resources/index.js';
|
|
2
2
|
import type { WorkItemId } from '../../work/index.js';
|
|
3
3
|
import type { RunId } from './identifiers.js';
|
|
4
|
+
import type { RepositoryAssignment } from './repository-assignment.js';
|
|
4
5
|
import type { RunView } from './views.js';
|
|
5
6
|
import type { WorkspaceMode } from './vocabulary.js';
|
|
6
7
|
export interface WorkspaceRequest {
|
|
@@ -11,6 +12,7 @@ export interface WorkspaceRequest {
|
|
|
11
12
|
readonly repositoryResource: ResourceView;
|
|
12
13
|
/** Git checkout target, independent of the resource observation revision. */
|
|
13
14
|
readonly checkoutRevision?: string;
|
|
15
|
+
readonly assignment?: RepositoryAssignment;
|
|
14
16
|
}
|
|
15
17
|
export interface WorkspaceLease {
|
|
16
18
|
readonly workspaceId: string;
|
|
@@ -18,7 +20,11 @@ export interface WorkspaceLease {
|
|
|
18
20
|
/** Branch actually checked out for this lease, when the provider can attest it. */
|
|
19
21
|
readonly branch?: string | undefined;
|
|
20
22
|
readonly mode: WorkspaceRequest['mode'];
|
|
23
|
+
readonly repositoryResourceId?: string;
|
|
24
|
+
readonly checkoutRevision?: string;
|
|
25
|
+
readonly assignment?: RepositoryAssignment;
|
|
21
26
|
/** Ends this Run's use of the workspace; workspace disposal is WorkItem-scoped recovery. */
|
|
27
|
+
readRevision?(): Promise<string>;
|
|
22
28
|
release(): Promise<void>;
|
|
23
29
|
}
|
|
24
30
|
export interface WorkspaceProvider {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EventActorKind } from '@atolis-hq/eventing';
|
|
2
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
3
|
import { ExecutionEventType } from '../contracts/events.js';
|
|
3
4
|
import { ExecutionFailureCode, isActiveRunStatus, RunStatus } from '../contracts/vocabulary.js';
|
|
4
5
|
export function foldRun(events) {
|
|
@@ -14,6 +15,9 @@ export function foldRun(events) {
|
|
|
14
15
|
throw invalidRunStream(creation.stream.id, 'RunPreparationStarted must be the first event');
|
|
15
16
|
const startedFromPreparation = creationEvent.eventType === ExecutionEventType.RunPreparationStarted;
|
|
16
17
|
const state = {
|
|
18
|
+
...(creationEvent.payload.repositoryAssignment === undefined
|
|
19
|
+
? {}
|
|
20
|
+
: { repositoryAssignment: creationEvent.payload.repositoryAssignment }),
|
|
17
21
|
runId: creation.stream.id,
|
|
18
22
|
activationId: creationEvent.payload.activationId,
|
|
19
23
|
activity: creationEvent.payload.activity,
|
|
@@ -88,6 +92,8 @@ function validateRunStart(state, event) {
|
|
|
88
92
|
validateRunStartField(state.runId, state.workflowInstanceId, event.payload.workflowInstanceId, 'workflowInstanceId');
|
|
89
93
|
validateRunStartField(state.runId, state.orchestrationGroupId, event.payload.orchestrationGroupId, 'orchestrationGroupId');
|
|
90
94
|
validateRunStartField(state.runId, state.attempt, event.payload.attempt, 'attempt');
|
|
95
|
+
if (!isDeepStrictEqual(state.repositoryAssignment, event.payload.repositoryAssignment))
|
|
96
|
+
throw invalidRunStream(state.runId, 'RunStarted contradicts repository assignment');
|
|
91
97
|
if (!sameRunner(state.runner, event.payload.runner))
|
|
92
98
|
throw invalidRunStream(state.runId, 'RunStarted contradicts RunPreparationStarted runner');
|
|
93
99
|
}
|
|
@@ -107,6 +113,9 @@ function applyTerminalEvent(state, event) {
|
|
|
107
113
|
status: RunStatus.Succeeded,
|
|
108
114
|
finishedAt: event.payload.finishedAt,
|
|
109
115
|
outcome: event.payload.outcome,
|
|
116
|
+
...(event.payload.workspaceRevision === undefined
|
|
117
|
+
? {}
|
|
118
|
+
: { workspaceRevision: event.payload.workspaceRevision }),
|
|
110
119
|
escalated: false,
|
|
111
120
|
});
|
|
112
121
|
return;
|
|
@@ -34,3 +34,6 @@ export * from './infrastructure/workspace/fake-workspace.js';
|
|
|
34
34
|
export * from './infrastructure/workspace/git-workspace.js';
|
|
35
35
|
export * from './application/run-reports.js';
|
|
36
36
|
export { createLocalProcessInspector } from './infrastructure/local-process-inspector.js';
|
|
37
|
+
export { resolveGitSource } from './infrastructure/workspace/git-source.js';
|
|
38
|
+
export * from './contracts/repository-assignment.js';
|
|
39
|
+
export { createRepositoryAssignments } from './application/repository-assignments.js';
|
|
@@ -34,3 +34,6 @@ export * from './infrastructure/workspace/fake-workspace.js';
|
|
|
34
34
|
export * from './infrastructure/workspace/git-workspace.js';
|
|
35
35
|
export * from './application/run-reports.js';
|
|
36
36
|
export { createLocalProcessInspector } from './infrastructure/local-process-inspector.js';
|
|
37
|
+
export { resolveGitSource } from './infrastructure/workspace/git-source.js';
|
|
38
|
+
export * from './contracts/repository-assignment.js';
|
|
39
|
+
export { createRepositoryAssignments } from './application/repository-assignments.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RepositoryAssignment } from '../../contracts/repository-assignment.js';
|
|
2
|
+
import type { RepositoryCloneResolver } from './git-workspace.js';
|
|
3
|
+
/** Fetching into an empty repository proves availability in the selected source. */
|
|
4
|
+
export declare function resolveGitSource(resolver: RepositoryCloneResolver, request: Omit<RepositoryAssignment, 'sourceRevision'> & {
|
|
5
|
+
readonly sourceRevision?: string | undefined;
|
|
6
|
+
}): Promise<RepositoryAssignment>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
6
|
+
const exec = promisify(execFile);
|
|
7
|
+
/** Fetching into an empty repository proves availability in the selected source. */
|
|
8
|
+
export async function resolveGitSource(resolver, request) {
|
|
9
|
+
const signal = AbortSignal.timeout(60_000);
|
|
10
|
+
const locator = await resolver.cloneLocator(request.resourceId, signal);
|
|
11
|
+
const path = await mkdtemp(join(tmpdir(), 'wake-source-'));
|
|
12
|
+
try {
|
|
13
|
+
await exec('git', ['init', '--bare', path], { signal });
|
|
14
|
+
await exec('git', [
|
|
15
|
+
'-C',
|
|
16
|
+
path,
|
|
17
|
+
'fetch',
|
|
18
|
+
'--no-tags',
|
|
19
|
+
'--',
|
|
20
|
+
locator,
|
|
21
|
+
request.sourceRevision ?? request.sourceRef,
|
|
22
|
+
], { signal });
|
|
23
|
+
const revision = (await exec('git', ['-C', path, 'rev-parse', '--verify', 'FETCH_HEAD^{commit}'], { signal })).stdout.trim();
|
|
24
|
+
if (!/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i.test(revision) ||
|
|
25
|
+
(request.sourceRevision !== undefined && revision !== request.sourceRevision))
|
|
26
|
+
throw new Error('Source did not resolve to the requested commit');
|
|
27
|
+
return { ...request, sourceRevision: revision };
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
throw new Error(`Repository ${request.resourceId} source ${request.sourceRevision ?? request.sourceRef} is unavailable; publish the source to the selected repository`, { cause: error });
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
await rm(path, { recursive: true, force: true });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type RepositoryAssignment } from '../../contracts/repository-assignment.js';
|
|
1
2
|
import type { RunView } from '../../contracts/views.js';
|
|
2
3
|
import type { WorkspaceLockProvider, WorkspaceProvider, WorkspaceRecovery, WorkspaceRecoveryOptions, WorkspaceRecoveryResult, WorkspaceRequest } from '../../contracts/workspace.js';
|
|
3
4
|
import { type WorkspacePrepareHook } from './prepare-workspace.js';
|
|
@@ -22,9 +23,13 @@ export declare class GitWorkspaceProvider implements WorkspaceProvider, Workspac
|
|
|
22
23
|
acquire(request: WorkspaceRequest): Promise<{
|
|
23
24
|
release: () => Promise<void>;
|
|
24
25
|
branch?: string;
|
|
26
|
+
assignment?: RepositoryAssignment;
|
|
25
27
|
workspaceId: string;
|
|
26
28
|
path: string;
|
|
27
29
|
mode: "read-only" | "branch";
|
|
30
|
+
readRevision: () => Promise<string>;
|
|
31
|
+
repositoryResourceId: import("../../../resources/index.js").ResourceId;
|
|
32
|
+
checkoutRevision: string;
|
|
28
33
|
}>;
|
|
29
34
|
private releaseWorkspaceLock;
|
|
30
35
|
private prepareCheckout;
|