@atolis-hq/wake 0.4.96 → 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 +5 -2
- package/dist/src/artifacts/application/delegation-artifacts.js +5 -1
- package/dist/src/bootstrap/composition-root.d.ts +6 -1
- package/dist/src/bootstrap/composition-root.js +40 -15
- 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/advance-once-dispatch.d.ts +1 -1
- package/dist/src/control-plane/application/advance-once-dispatch.js +4 -2
- 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/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/delegated-work.d.ts +10 -1
- package/dist/src/orchestration/application/delegated-work.js +41 -5
- package/dist/src/orchestration/application/delegation-reservation.d.ts +2 -2
- package/dist/src/orchestration/application/delegation-reservation.js +34 -11
- package/dist/src/orchestration/application/orchestration-service.d.ts +16 -1
- package/dist/src/orchestration/application/orchestration-service.js +4 -0
- package/dist/src/orchestration/contracts/delegation-ports.d.ts +6 -1
- package/dist/src/orchestration/contracts/delegation.d.ts +52 -7
- package/dist/src/orchestration/contracts/delegation.js +47 -2
- package/dist/src/orchestration/contracts/vocabulary.d.ts +3 -0
- package/dist/src/orchestration/contracts/vocabulary.js +1 -0
- package/dist/src/orchestration/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import { execFile } from 'node:child_process';
|
|
3
3
|
import { access, mkdir, readdir, readFile, realpath, rename, rm, rmdir, unlink, writeFile, } from 'node:fs/promises';
|
|
4
4
|
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
5
|
-
import { promisify } from 'node:util';
|
|
5
|
+
import { isDeepStrictEqual, promisify } from 'node:util';
|
|
6
|
+
import { repositoryAssignmentSchema, } from '../../contracts/repository-assignment.js';
|
|
6
7
|
import { isActiveRunStatus, RunStatus, WorkspaceMode } from '../../contracts/vocabulary.js';
|
|
7
8
|
import { prepareWorkspace } from './prepare-workspace.js';
|
|
8
9
|
const exec = promisify(execFile);
|
|
@@ -54,6 +55,10 @@ export class GitWorkspaceProvider {
|
|
|
54
55
|
workspaceId: name,
|
|
55
56
|
path,
|
|
56
57
|
mode: request.mode,
|
|
58
|
+
readRevision: () => readCheckoutRevision(path, this.git, signal),
|
|
59
|
+
repositoryResourceId: request.repositoryResource.resourceId,
|
|
60
|
+
checkoutRevision: await readCheckoutRevision(path, this.git, signal),
|
|
61
|
+
...(request.assignment === undefined ? {} : { assignment: request.assignment }),
|
|
57
62
|
...(branch === undefined ? {} : { branch }),
|
|
58
63
|
release: async () => {
|
|
59
64
|
if (released)
|
|
@@ -82,6 +87,7 @@ export class GitWorkspaceProvider {
|
|
|
82
87
|
async prepareCheckout(request, locator, name, path, markerPath) {
|
|
83
88
|
const { signal } = request;
|
|
84
89
|
const previousMarker = await readMarker(markerPath);
|
|
90
|
+
assertAssignment(previousMarker, request);
|
|
85
91
|
if (await exists(join(this.markerRoot, `${name}.lock`), signal))
|
|
86
92
|
throw new Error('Legacy workspace lock requires recovery before acquisition');
|
|
87
93
|
let initialRevision = previousMarker?.initialRevision;
|
|
@@ -95,6 +101,7 @@ export class GitWorkspaceProvider {
|
|
|
95
101
|
workspaceId: name,
|
|
96
102
|
path,
|
|
97
103
|
checkoutReady,
|
|
104
|
+
...(request.assignment === undefined ? {} : { assignment: request.assignment }),
|
|
98
105
|
...(initialRevision === undefined ? {} : { initialRevision }),
|
|
99
106
|
}, signal);
|
|
100
107
|
const existingWorkspace = await this.reuseCheckout(previousMarker, markerPath, path, request.mode, signal);
|
|
@@ -113,7 +120,14 @@ export class GitWorkspaceProvider {
|
|
|
113
120
|
initialRevision = await readCheckoutRevision(path, this.git, signal);
|
|
114
121
|
const branch = request.mode === WorkspaceMode.Branch ? request.workItemId : undefined;
|
|
115
122
|
if (branch !== undefined) {
|
|
116
|
-
|
|
123
|
+
initialRevision = await initializeBranch({
|
|
124
|
+
path,
|
|
125
|
+
branch,
|
|
126
|
+
// Only repository assignments pin a new branch; direct workflows keep the clone default.
|
|
127
|
+
revision: request.assignment === undefined ? undefined : request.checkoutRevision,
|
|
128
|
+
initialRevision,
|
|
129
|
+
existing: existingWorkspace,
|
|
130
|
+
}, this.git, signal);
|
|
117
131
|
}
|
|
118
132
|
checkoutReady = true;
|
|
119
133
|
await writeMarker();
|
|
@@ -344,7 +358,9 @@ function isOwnershipMarker(value) {
|
|
|
344
358
|
hasValidCheckoutState(marker));
|
|
345
359
|
}
|
|
346
360
|
function hasValidCheckoutState(marker) {
|
|
347
|
-
return ((marker.
|
|
361
|
+
return ((marker.assignment === undefined ||
|
|
362
|
+
repositoryAssignmentSchema.safeParse(marker.assignment).success) &&
|
|
363
|
+
(marker.initialRevision === undefined || typeof marker.initialRevision === 'string') &&
|
|
348
364
|
(marker.checkoutReady === undefined || typeof marker.checkoutReady === 'boolean'));
|
|
349
365
|
}
|
|
350
366
|
async function isOwnedWorkspace(scope, markerPath, marker, fileSystem) {
|
|
@@ -486,3 +502,34 @@ function slug(value) {
|
|
|
486
502
|
.replace(/[^a-z0-9]+/g, '-')
|
|
487
503
|
.replace(/^-|-$/g, '');
|
|
488
504
|
}
|
|
505
|
+
function assertAssignment(previousMarker, request) {
|
|
506
|
+
// Direct workflows legitimately move from an issue to its PR resource in one clone, so
|
|
507
|
+
// resource identity is only binding for assignment-bound workspaces.
|
|
508
|
+
if (previousMarker !== null &&
|
|
509
|
+
(previousMarker.assignment !== undefined || request.assignment !== undefined) &&
|
|
510
|
+
previousMarker.repositoryResourceId !== request.repositoryResource.resourceId)
|
|
511
|
+
throw new Error('Workspace belongs to a different Repository Resource');
|
|
512
|
+
if (previousMarker?.assignment !== undefined &&
|
|
513
|
+
!isDeepStrictEqual(previousMarker.assignment, request.assignment))
|
|
514
|
+
throw new Error('Workspace repository assignment changed; reconcile the existing branch before retrying');
|
|
515
|
+
}
|
|
516
|
+
async function initializeBranch(input, git, signal) {
|
|
517
|
+
const { path, branch, revision, existing } = input;
|
|
518
|
+
let { initialRevision } = input;
|
|
519
|
+
if (!existing && revision !== undefined) {
|
|
520
|
+
await git(['-C', path, 'fetch', 'origin', revision], signal);
|
|
521
|
+
const fetched = await readGitRevision(path, 'FETCH_HEAD^{commit}', git, signal);
|
|
522
|
+
if (/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i.test(revision) && fetched !== revision)
|
|
523
|
+
throw new Error('Fetched source differs from the pinned checkout revision');
|
|
524
|
+
initialRevision = fetched;
|
|
525
|
+
}
|
|
526
|
+
await git([
|
|
527
|
+
'-C',
|
|
528
|
+
path,
|
|
529
|
+
'switch',
|
|
530
|
+
...(existing ? [] : ['--create']),
|
|
531
|
+
branch,
|
|
532
|
+
...(!existing && revision !== undefined ? [initialRevision] : []),
|
|
533
|
+
], signal);
|
|
534
|
+
return initialRevision;
|
|
535
|
+
}
|
|
@@ -10,6 +10,11 @@ interface ArtifactRegistrationDependencies {
|
|
|
10
10
|
readonly maxAmbiguityReconciliationAttempts?: number;
|
|
11
11
|
readonly runs: {
|
|
12
12
|
list(activationId?: string): Promise<readonly {
|
|
13
|
+
readonly repositoryAssignment?: {
|
|
14
|
+
readonly resourceId: string;
|
|
15
|
+
readonly pullRequestBase: string;
|
|
16
|
+
} | undefined;
|
|
17
|
+
readonly workspaceRevision?: string | undefined;
|
|
13
18
|
readonly workspace?: {
|
|
14
19
|
readonly branch?: string | undefined;
|
|
15
20
|
};
|
|
@@ -24,6 +29,7 @@ export declare class ArtifactRegistrationReactor {
|
|
|
24
29
|
private register;
|
|
25
30
|
reconcileOnce(): Promise<void>;
|
|
26
31
|
private verifyAndRegister;
|
|
32
|
+
private verificationSource;
|
|
27
33
|
private registerVerified;
|
|
28
34
|
private recordUnresolved;
|
|
29
35
|
private branchFor;
|
|
@@ -74,25 +74,49 @@ export class ArtifactRegistrationReactor {
|
|
|
74
74
|
const provider = this.dependencies.providers.find((candidate) => candidate.adapter === record.artifact.externalKey.adapter);
|
|
75
75
|
if (provider === undefined)
|
|
76
76
|
return;
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
const source = await this.verificationSource(record.activationId, branch);
|
|
78
|
+
if (source === null) {
|
|
79
|
+
await this.recordUnresolved(provider, record, ArtifactVerificationResult.NotFound, attempt);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const verified = await provider.verifyArtifact(record.artifact.kind, record.artifact.externalKey, source);
|
|
80
83
|
if (typeof verified === 'string') {
|
|
81
84
|
await this.recordUnresolved(provider, record, verified, attempt);
|
|
82
85
|
return;
|
|
83
86
|
}
|
|
84
87
|
await this.registerVerified(record, verified, workItemId);
|
|
85
88
|
}
|
|
89
|
+
async verificationSource(activationId, branch) {
|
|
90
|
+
const run = (await this.dependencies.runs.list(activationId)).at(-1);
|
|
91
|
+
const assignment = run?.repositoryAssignment;
|
|
92
|
+
const repository = assignment === undefined
|
|
93
|
+
? undefined
|
|
94
|
+
: await this.dependencies.resources.get(resourceId(assignment.resourceId));
|
|
95
|
+
if (repository === null)
|
|
96
|
+
return null;
|
|
97
|
+
// Direct workflows keep branch-only verification; head and base are exact only for assignments.
|
|
98
|
+
if (assignment === undefined)
|
|
99
|
+
return { workspaceBranch: branch };
|
|
100
|
+
if (repository === undefined || run?.workspaceRevision === undefined)
|
|
101
|
+
return null;
|
|
102
|
+
return {
|
|
103
|
+
workspaceBranch: branch,
|
|
104
|
+
repository: repository.externalKey,
|
|
105
|
+
workspaceRevision: run.workspaceRevision,
|
|
106
|
+
pullRequestBase: assignment.pullRequestBase,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
86
109
|
async registerVerified(record, verified, workItemId) {
|
|
87
110
|
const existing = await this.dependencies.resources.findByExternalKey(verified.externalKey);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
111
|
+
// Re-discover an existing resource so a re-report records its newly verified head.
|
|
112
|
+
const resource = await this.dependencies.resources.discover({
|
|
113
|
+
resourceId: existing?.resourceId ??
|
|
114
|
+
resourceId(this.dependencies.ids.next(ResourceStreamKind.Resource)),
|
|
115
|
+
kind: verified.kind,
|
|
116
|
+
externalKey: verified.externalKey,
|
|
117
|
+
capabilities: verified.capabilities,
|
|
118
|
+
...(verified.revision === undefined ? {} : { revision: verified.revision }),
|
|
119
|
+
}, context(record.causationId, record.correlationId, record.occurredAt));
|
|
96
120
|
try {
|
|
97
121
|
await this.dependencies.resources.correlate(resource.resourceId, workItemId, ResourceCorrelationRole.Primary, context(record.causationId, record.correlationId, record.occurredAt), ResourceCorrelationProvenance.AgentReported);
|
|
98
122
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ExternalResourceKey } from '../../resources/index.js';
|
|
2
|
+
import type { ProviderInstance } from '../contracts/provider.js';
|
|
3
|
+
/** Compare typed provider facts with the recorded producing Run. */
|
|
4
|
+
export declare function matchesArtifactSource(externalKey: ExternalResourceKey, observed: {
|
|
5
|
+
readonly repository: string;
|
|
6
|
+
readonly branch: string;
|
|
7
|
+
readonly revision?: string | undefined;
|
|
8
|
+
readonly base?: string | undefined;
|
|
9
|
+
}, context: Parameters<ProviderInstance['verifyArtifact']>[2]): boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Compare typed provider facts with the recorded producing Run. */
|
|
2
|
+
export function matchesArtifactSource(externalKey, observed, context) {
|
|
3
|
+
if (observed.branch !== context.workspaceBranch)
|
|
4
|
+
return false;
|
|
5
|
+
if (context.repository !== undefined &&
|
|
6
|
+
(context.repository.adapter !== externalKey.adapter ||
|
|
7
|
+
context.repository.key.toLowerCase() !== observed.repository.toLowerCase()))
|
|
8
|
+
return false;
|
|
9
|
+
if (context.workspaceRevision !== undefined && context.workspaceRevision !== observed.revision)
|
|
10
|
+
return false;
|
|
11
|
+
return context.pullRequestBase === undefined || context.pullRequestBase === observed.base;
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type PullRequestService } from '../../activities/index.js';
|
|
2
|
+
import { type RunView } from '../../execution/index.js';
|
|
3
|
+
import type { DelegationArtifacts } from '../../orchestration/index.js';
|
|
4
|
+
import { type ResourceService } from '../../resources/index.js';
|
|
5
|
+
import type { ProviderInstance } from '../contracts/provider.js';
|
|
6
|
+
interface OutputDependencies {
|
|
7
|
+
readonly artifacts: DelegationArtifacts;
|
|
8
|
+
readonly resources: ResourceService;
|
|
9
|
+
readonly pullRequests: PullRequestService;
|
|
10
|
+
readonly runs: () => Promise<readonly RunView[]>;
|
|
11
|
+
readonly providers: () => Promise<readonly ProviderInstance[]>;
|
|
12
|
+
}
|
|
13
|
+
/** Select exact provider-verified results owned by the producing child. */
|
|
14
|
+
export declare function createDelegationOutputs(input: OutputDependencies): DelegationArtifacts;
|
|
15
|
+
export {};
|