@vypdev/copilot 3.5.3 → 3.5.5

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.
@@ -38159,6 +38159,27 @@ function runAtApplicationErrorBoundary(operation) {
38159
38159
  }
38160
38160
 
38161
38161
 
38162
+ /***/ }),
38163
+
38164
+ /***/ 72594:
38165
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
38166
+
38167
+ "use strict";
38168
+
38169
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
38170
+ exports.DeploymentMergeEffectError = void 0;
38171
+ const application_error_1 = __nccwpck_require__(75999);
38172
+ /** Semantic effect failure. Only a confirmed readiness rejection permits one new inspection. */
38173
+ class DeploymentMergeEffectError extends application_error_1.ApplicationError {
38174
+ constructor(action, readinessChanged, code, message, cause) {
38175
+ super(code, message, { cause });
38176
+ this.action = action;
38177
+ this.readinessChanged = readinessChanged;
38178
+ }
38179
+ }
38180
+ exports.DeploymentMergeEffectError = DeploymentMergeEffectError;
38181
+
38182
+
38162
38183
  /***/ }),
38163
38184
 
38164
38185
  /***/ 38313:
@@ -42276,7 +42297,7 @@ const resolved_message_catalog_policy_1 = __nccwpck_require__(55069);
42276
42297
  const merge_queue_message_catalog_1 = __nccwpck_require__(56033);
42277
42298
  const application_error_message_catalog_1 = __nccwpck_require__(64809);
42278
42299
  const SIMPLE_MESSAGE_KEYS = Object.freeze([
42279
- 'release', 'hotfix', 'currentStatus', 'noAction', 'actionRequired', 'progress',
42300
+ 'release', 'hotfix', 'currentStatus', 'noAction', 'completionNotice', 'actionRequired', 'progress',
42280
42301
  'currentTransition', 'whatNext', 'links', 'technical', 'alreadyPublished',
42281
42302
  'notPublished', 'productionUpdated', 'developmentSynchronized', 'yes', 'no',
42282
42303
  'from', 'to', 'state', 'compare', 'controlCenter', 'purpose', 'afterMerge',
@@ -42332,6 +42353,7 @@ exports.DEPLOYMENT_MESSAGE_IDS = Object.freeze([
42332
42353
  const ENGLISH_SIMPLE = Object.freeze({
42333
42354
  release: 'Release', hotfix: 'Hotfix', currentStatus: 'Current status',
42334
42355
  noAction: 'No action is required while GitHub owns the pending transition.', actionRequired: 'Action required',
42356
+ completionNotice: 'Deployment is complete. No further action is required.',
42335
42357
  progress: 'Progress', currentTransition: 'Current transition', whatNext: 'What happens next', links: 'Links',
42336
42358
  technical: 'Technical details', alreadyPublished: 'Package status: already published', notPublished: 'Package status: not published',
42337
42359
  productionUpdated: 'Production updated', developmentSynchronized: 'Development synchronized', yes: 'Yes', no: 'No',
@@ -42364,6 +42386,7 @@ const ENGLISH_SIMPLE = Object.freeze({
42364
42386
  const SPANISH_SIMPLE = Object.freeze({
42365
42387
  release: 'Release', hotfix: 'Hotfix', currentStatus: 'Estado actual',
42366
42388
  noAction: 'No se requiere ninguna acción mientras GitHub gestiona la transición pendiente.', actionRequired: 'Acción necesaria',
42389
+ completionNotice: 'El despliegue ha terminado. No se requiere ninguna acción adicional.',
42367
42390
  progress: 'Progreso', currentTransition: 'Transición actual', whatNext: 'Qué ocurrirá después', links: 'Enlaces',
42368
42391
  technical: 'Detalles técnicos', alreadyPublished: 'Estado del paquete: ya publicado', notPublished: 'Estado del paquete: no publicado',
42369
42392
  productionUpdated: 'Producción actualizada', developmentSynchronized: 'Desarrollo sincronizado', yes: 'Sí', no: 'No',
@@ -42911,6 +42934,8 @@ function nextDescription(operation, messages, catalog) {
42911
42934
  });
42912
42935
  }
42913
42936
  function deploymentAction(operation, messages) {
42937
+ if (operation.phase === 'completed')
42938
+ return { required: false, message: messages.completionNotice };
42914
42939
  const manual = (operation.selectedPrMode ?? operation.prMode) === 'create-only'
42915
42940
  && (operation.phase === 'promotion_pr_pending' || operation.phase === 'reconciliation_pending');
42916
42941
  if (manual)
@@ -51843,6 +51868,91 @@ function bindSddEvidenceReadPorts(ports) {
51843
51868
  }
51844
51869
 
51845
51870
 
51871
+ /***/ }),
51872
+
51873
+ /***/ 84387:
51874
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
51875
+
51876
+ "use strict";
51877
+
51878
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
51879
+ exports.DeploymentMergeEffects = void 0;
51880
+ const application_error_1 = __nccwpck_require__(75999);
51881
+ const deployment_merge_effect_error_1 = __nccwpck_require__(72594);
51882
+ const managed_pull_request_1 = __nccwpck_require__(95914);
51883
+ /** Applies current policy, with one bounded re-observation after a typed readiness rejection. */
51884
+ class DeploymentMergeEffects {
51885
+ constructor(pullRequests) {
51886
+ this.pullRequests = pullRequests;
51887
+ }
51888
+ async configure(operation, pullRequest, inspection, inspect, beforeApply) {
51889
+ await beforeApply(inspection.decision.mode);
51890
+ const action = selectAction(operation, inspection);
51891
+ try {
51892
+ await this.apply(action, pullRequest);
51893
+ return inspection.decision.mode;
51894
+ }
51895
+ catch (error) {
51896
+ if (!(error instanceof deployment_merge_effect_error_1.DeploymentMergeEffectError) || !error.readinessChanged || operation.prMode !== "auto")
51897
+ throw error;
51898
+ const current = await this.pullRequests.getPullRequest(pullRequest.number);
51899
+ assertSamePullRequest(pullRequest, current);
51900
+ if (current.merged)
51901
+ return inspection.decision.mode;
51902
+ if (current.state !== "open")
51903
+ throw new application_error_1.ApplicationError("provider.conflict", "The managed PR was closed without merging.");
51904
+ const refreshed = await inspect(current);
51905
+ if (refreshed.kind === "blocked")
51906
+ throw new application_error_1.ApplicationError("provider.conflict", refreshed.reason);
51907
+ const nextAction = selectAction(operation, refreshed);
51908
+ if (nextAction === action) {
51909
+ if (action === "enable-auto-merge" && current.autoMergeEnabled)
51910
+ return refreshed.decision.mode;
51911
+ throw error;
51912
+ }
51913
+ await beforeApply(refreshed.decision.mode);
51914
+ await this.apply(nextAction, current);
51915
+ return refreshed.decision.mode;
51916
+ }
51917
+ }
51918
+ async apply(action, pullRequest) {
51919
+ try {
51920
+ if (action === "merge") {
51921
+ await this.pullRequests.mergePullRequest(pullRequest.number, pullRequest.headSha);
51922
+ }
51923
+ else if (action === "enable-auto-merge" && !pullRequest.autoMergeEnabled) {
51924
+ await this.pullRequests.enableAutoMerge(pullRequest.nodeId, pullRequest.headSha);
51925
+ }
51926
+ else if (action === "merge-queue" && !await this.pullRequests.isPullRequestQueued(pullRequest.nodeId)) {
51927
+ await this.pullRequests.enqueuePullRequest(pullRequest.nodeId, pullRequest.headSha);
51928
+ }
51929
+ }
51930
+ catch (cause) {
51931
+ if (cause instanceof application_error_1.ApplicationError)
51932
+ throw cause;
51933
+ throw new application_error_1.ApplicationError("workflow.failed", `Automatic merge action ${action} failed with an unclassified provider rejection.`, { cause, retryable: true });
51934
+ }
51935
+ }
51936
+ }
51937
+ exports.DeploymentMergeEffects = DeploymentMergeEffects;
51938
+ function selectAction(operation, inspection) {
51939
+ if (inspection.decision.mode !== "auto-merge")
51940
+ return inspection.decision.mode;
51941
+ return operation.prMode === "auto" && inspection.capabilities.immediatelyMergeable ? "merge" : "enable-auto-merge";
51942
+ }
51943
+ function assertSamePullRequest(expected, current) {
51944
+ const marker = (0, managed_pull_request_1.parseManagedPullRequestMarker)(expected.body);
51945
+ const currentMarker = (0, managed_pull_request_1.parseManagedPullRequestMarker)(current.body);
51946
+ if (expected.number !== current.number || expected.nodeId !== current.nodeId
51947
+ || expected.repositoryFullName !== current.repositoryFullName || expected.baseBranch !== current.baseBranch
51948
+ || expected.headBranch !== current.headBranch || expected.headSha !== current.headSha
51949
+ || !marker || !currentMarker || marker.operationId !== currentMarker.operationId
51950
+ || marker.phase !== currentMarker.phase || marker.issue !== currentMarker.issue) {
51951
+ throw new application_error_1.ApplicationError("provider.conflict", "The managed PR identity or frozen head changed during merge setup.", { retryable: false });
51952
+ }
51953
+ }
51954
+
51955
+
51846
51956
  /***/ }),
51847
51957
 
51848
51958
  /***/ 77658:
@@ -51867,6 +51977,7 @@ const deployment_message_catalog_1 = __nccwpck_require__(79364);
51867
51977
  const deployment_operation_1 = __nccwpck_require__(92730);
51868
51978
  const merge_queue_readiness_1 = __nccwpck_require__(12515);
51869
51979
  const result_1 = __nccwpck_require__(73817);
51980
+ const deployment_merge_effects_1 = __nccwpck_require__(84387);
51870
51981
  exports.DEPLOYMENT_ORCHESTRATION_TASK_ID = "DeploymentOrchestrationUseCase";
51871
51982
  class DeploymentOrchestrationRuntime {
51872
51983
  constructor(dependencies, stateBoundary) {
@@ -51941,18 +52052,18 @@ class DeploymentOrchestrationRuntime {
51941
52052
  result: await this.block(context, operation, category, inspection.reason, true),
51942
52053
  };
51943
52054
  }
51944
- const managed = {
51945
- ...operation,
51946
- selectedPrMode: inspection.decision.mode,
51947
- };
51948
- await this.persist(context, managed);
52055
+ let managed = operation;
51949
52056
  try {
51950
- await this.applyMergeBehavior(context, operation, pullRequest, inspection);
52057
+ await new deployment_merge_effects_1.DeploymentMergeEffects(this.dependencies.pullRequests).configure(operation, pullRequest, inspection, (current) => this.inspectMergeBehavior(context, operation, current.baseBranch, targetRole, current.headSha, current.number), async (mode) => {
52058
+ managed = { ...operation, selectedPrMode: mode };
52059
+ await this.persist(context, managed);
52060
+ });
51951
52061
  }
51952
52062
  catch (cause) {
51953
- const message = `GitHub could not configure automatic merge for PR #${pullRequest.number}. Check the PR and retry the stored ${category} phase.`;
51954
- const error = new application_error_1.ApplicationError("provider.unavailable", message, { cause, retryable: true });
51955
- return { kind: "blocked", result: await this.block(context, managed, category, message, true, error) };
52063
+ const diagnostic = (0, application_error_1.toApplicationError)(cause, "workflow.failed", "Automatic merge setup failed with an unclassified provider rejection.", { retryable: true });
52064
+ const message = `GitHub could not configure automatic merge for PR #${pullRequest.number}. ${diagnostic.message} Check the PR and retry the stored ${category} phase.`;
52065
+ const error = new application_error_1.ApplicationError(diagnostic.code, message, { cause, retryable: diagnostic.retryable });
52066
+ return { kind: "blocked", result: await this.block(context, managed, category, message, error.retryable, error) };
51956
52067
  }
51957
52068
  await this.publishDashboard(context, managed);
51958
52069
  return { kind: "configured", operation: managed };
@@ -52007,27 +52118,6 @@ class DeploymentOrchestrationRuntime {
52007
52118
  // Preserve the original provider failure returned by the coordinator.
52008
52119
  }
52009
52120
  }
52010
- async applyMergeBehavior(context, operation, pullRequest, inspection) {
52011
- if (inspection.decision.mode === "auto-merge") {
52012
- await this.applyAutoMerge(context, operation, pullRequest, inspection.capabilities);
52013
- return;
52014
- }
52015
- if (inspection.decision.mode === "merge-queue") {
52016
- const queued = await this.dependencies.pullRequests.isPullRequestQueued(pullRequest.nodeId);
52017
- if (!queued) {
52018
- await this.dependencies.pullRequests.enqueuePullRequest(pullRequest.nodeId, pullRequest.headSha);
52019
- }
52020
- }
52021
- }
52022
- async applyAutoMerge(context, operation, pullRequest, capabilities) {
52023
- if (operation.prMode === "auto" && capabilities.immediatelyMergeable) {
52024
- await this.dependencies.pullRequests.mergePullRequest(pullRequest.number, pullRequest.headSha);
52025
- return;
52026
- }
52027
- if (!pullRequest.autoMergeEnabled) {
52028
- await this.dependencies.pullRequests.enableAutoMerge(pullRequest.nodeId);
52029
- }
52030
- }
52031
52121
  async unsupportedMergeBehavior(context, operation, targetRole, targetBranch, capabilities, decision) {
52032
52122
  const catalog = await this.presentationCatalog('issue', context, operation);
52033
52123
  if (capabilities.mergeQueueObservationProblems.length === 0) {
@@ -79339,6 +79429,47 @@ function isNotFound(error) {
79339
79429
  }
79340
79430
 
79341
79431
 
79432
+ /***/ }),
79433
+
79434
+ /***/ 30873:
79435
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
79436
+
79437
+ "use strict";
79438
+
79439
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
79440
+ exports.githubDeploymentMergeError = githubDeploymentMergeError;
79441
+ const deployment_merge_effect_error_1 = __nccwpck_require__(72594);
79442
+ /** Never copy provider messages, request objects, headers, or arbitrary error types into public state. */
79443
+ function githubDeploymentMergeError(action, cause) {
79444
+ const value = isRecord(cause) ? cause : {};
79445
+ const status = typeof value.status === "number" && Number.isInteger(value.status)
79446
+ && value.status >= 100 && value.status <= 599 ? value.status : undefined;
79447
+ const rawErrors = Array.isArray(value.errors) ? value.errors : [];
79448
+ const errors = rawErrors.filter(isRecord);
79449
+ const types = errors.map((error) => error.type);
79450
+ const denied = status === 401 || status === 403 || types.includes("FORBIDDEN") || types.includes("UNAUTHORIZED");
79451
+ const limited = status === 429 || types.includes("RATE_LIMITED");
79452
+ const unavailable = (status !== undefined && status >= 500) || types.includes("INTERNAL") || types.includes("SERVICE_UNAVAILABLE");
79453
+ const cleanRejection = rawErrors.length === 1 && errors.length === 1 && errors[0].type === "UNPROCESSABLE"
79454
+ && typeof errors[0].message === "string"
79455
+ && ["Pull request is in clean status", "Pull request Pull request is in clean status",
79456
+ "Pull request is in unstable status", "Pull request Pull request is in unstable status"].includes(errors[0].message);
79457
+ const readinessChanged = !denied && !limited && !unavailable
79458
+ && ((action === "merge" && status === 405) || (action === "enable-auto-merge" && (status === undefined || status === 200) && cleanRejection));
79459
+ const code = denied ? "authorization.denied"
79460
+ : limited ? "provider.rate-limited"
79461
+ : unavailable ? "provider.unavailable"
79462
+ : status === 404 || types.includes("NOT_FOUND") ? "provider.not-found"
79463
+ : status !== undefined || types.length > 0 ? "provider.conflict" : "workflow.failed";
79464
+ const reason = readinessChanged ? "readiness-changed" : code;
79465
+ const http = status === undefined ? "" : `; HTTP ${status}`;
79466
+ return new deployment_merge_effect_error_1.DeploymentMergeEffectError(action, readinessChanged, code, `GitHub rejected ${action} (${reason}${http}).`, cause);
79467
+ }
79468
+ function isRecord(value) {
79469
+ return typeof value === "object" && value !== null && !Array.isArray(value);
79470
+ }
79471
+
79472
+
79342
79473
  /***/ }),
79343
79474
 
79344
79475
  /***/ 96483:
@@ -79349,6 +79480,8 @@ function isNotFound(error) {
79349
79480
  Object.defineProperty(exports, "__esModule", ({ value: true }));
79350
79481
  exports.GithubManagedPullRequestRepository = void 0;
79351
79482
  const managed_pull_request_1 = __nccwpck_require__(95914);
79483
+ const github_deployment_merge_error_1 = __nccwpck_require__(30873);
79484
+ const deployment_merge_effect_error_1 = __nccwpck_require__(72594);
79352
79485
  class GithubManagedPullRequestRepository {
79353
79486
  constructor(clientProvider) {
79354
79487
  this.clientProvider = clientProvider;
@@ -79392,12 +79525,21 @@ class GithubManagedPullRequestRepository {
79392
79525
  });
79393
79526
  return mapPullRequest(data, owner, repository);
79394
79527
  }
79395
- async enableAutoMerge(owner, repository, pullRequestNodeId, token) {
79396
- await this.clientProvider.getClient(token).graphql(`mutation EnableDeploymentAutoMerge($pullRequestId: ID!) {
79397
- enablePullRequestAutoMerge(input: {pullRequestId: $pullRequestId, mergeMethod: MERGE}) {
79398
- pullRequest { id }
79528
+ async enableAutoMerge(_owner, _repository, pullRequestNodeId, expectedHeadSha, token) {
79529
+ let response;
79530
+ try {
79531
+ response = await this.clientProvider.getClient(token).graphql(`mutation EnableDeploymentAutoMerge($pullRequestId: ID!, $expectedHeadOid: GitObjectID!) {
79532
+ enablePullRequestAutoMerge(input: {pullRequestId: $pullRequestId, expectedHeadOid: $expectedHeadOid, mergeMethod: MERGE}) {
79533
+ pullRequest { id }
79534
+ }
79535
+ }`, { pullRequestId: pullRequestNodeId, expectedHeadOid: expectedHeadSha });
79536
+ }
79537
+ catch (cause) {
79538
+ throw (0, github_deployment_merge_error_1.githubDeploymentMergeError)("enable-auto-merge", cause);
79539
+ }
79540
+ if (response?.enablePullRequestAutoMerge?.pullRequest?.id !== pullRequestNodeId) {
79541
+ throw new deployment_merge_effect_error_1.DeploymentMergeEffectError("enable-auto-merge", false, "provider.contract-invalid", "GitHub did not confirm native auto-merge for the expected PR.");
79399
79542
  }
79400
- }`, { pullRequestId: pullRequestNodeId, owner, repository });
79401
79543
  }
79402
79544
  async isPullRequestQueued(owner, repository, pullRequestNodeId, token) {
79403
79545
  const response = await this.clientProvider.getClient(token).graphql(`query DeploymentPullRequestQueue($pullRequestId: ID!) {
@@ -79421,15 +79563,18 @@ class GithubManagedPullRequestRepository {
79421
79563
  }
79422
79564
  }
79423
79565
  async mergePullRequest(owner, repository, pullRequest, expectedHeadSha, token) {
79424
- const { data } = await this.clientProvider.getClient(token).rest.pulls.merge({
79425
- owner,
79426
- repo: repository,
79427
- pull_number: pullRequest,
79428
- merge_method: "merge",
79429
- sha: expectedHeadSha,
79430
- });
79431
- if (!data.merged || !data.sha)
79432
- throw new Error(data.message ?? `Pull request #${pullRequest} was not merged.`);
79566
+ let data;
79567
+ try {
79568
+ ({ data } = await this.clientProvider.getClient(token).rest.pulls.merge({
79569
+ owner, repo: repository, pull_number: pullRequest, merge_method: "merge", sha: expectedHeadSha,
79570
+ }));
79571
+ }
79572
+ catch (cause) {
79573
+ throw (0, github_deployment_merge_error_1.githubDeploymentMergeError)("merge", cause);
79574
+ }
79575
+ if (!data?.merged || typeof data.sha !== "string" || !/^[a-f0-9]{40}$/i.test(data.sha)) {
79576
+ throw new deployment_merge_effect_error_1.DeploymentMergeEffectError("merge", false, "provider.contract-invalid", "GitHub did not confirm a completed merge with a valid commit SHA.");
79577
+ }
79433
79578
  return data.sha;
79434
79579
  }
79435
79580
  }
@@ -92473,7 +92618,7 @@ function bindManagedPullRequests(port, binding) {
92473
92618
  findManagedPullRequests: (query) => port.findManagedPullRequests({ ...query, owner: binding.owner, repository: binding.repository, token: binding.token }),
92474
92619
  createManagedPullRequest: (command) => port.createManagedPullRequest({ ...command, owner: binding.owner, repository: binding.repository, token: binding.token }),
92475
92620
  getPullRequest: (pullRequest) => port.getPullRequest(binding.owner, binding.repository, pullRequest, binding.token),
92476
- enableAutoMerge: (pullRequestNodeId) => port.enableAutoMerge(binding.owner, binding.repository, pullRequestNodeId, binding.token),
92621
+ enableAutoMerge: (pullRequestNodeId, expectedHeadSha) => port.enableAutoMerge(binding.owner, binding.repository, pullRequestNodeId, expectedHeadSha, binding.token),
92477
92622
  isPullRequestQueued: (pullRequestNodeId) => port.isPullRequestQueued(binding.owner, binding.repository, pullRequestNodeId, binding.token),
92478
92623
  enqueuePullRequest: (pullRequestNodeId, expectedHeadSha) => port.enqueuePullRequest(binding.owner, binding.repository, pullRequestNodeId, expectedHeadSha, binding.token),
92479
92624
  mergePullRequest: (pullRequest, expectedHeadSha) => port.mergePullRequest(binding.owner, binding.repository, pullRequest, expectedHeadSha, binding.token),
@@ -38816,6 +38816,27 @@ function runAtApplicationErrorBoundary(operation) {
38816
38816
  }
38817
38817
 
38818
38818
 
38819
+ /***/ }),
38820
+
38821
+ /***/ 72594:
38822
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
38823
+
38824
+ "use strict";
38825
+
38826
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
38827
+ exports.DeploymentMergeEffectError = void 0;
38828
+ const application_error_1 = __nccwpck_require__(75999);
38829
+ /** Semantic effect failure. Only a confirmed readiness rejection permits one new inspection. */
38830
+ class DeploymentMergeEffectError extends application_error_1.ApplicationError {
38831
+ constructor(action, readinessChanged, code, message, cause) {
38832
+ super(code, message, { cause });
38833
+ this.action = action;
38834
+ this.readinessChanged = readinessChanged;
38835
+ }
38836
+ }
38837
+ exports.DeploymentMergeEffectError = DeploymentMergeEffectError;
38838
+
38839
+
38819
38840
  /***/ }),
38820
38841
 
38821
38842
  /***/ 61544:
@@ -43612,7 +43633,7 @@ const resolved_message_catalog_policy_1 = __nccwpck_require__(55069);
43612
43633
  const merge_queue_message_catalog_1 = __nccwpck_require__(56033);
43613
43634
  const application_error_message_catalog_1 = __nccwpck_require__(64809);
43614
43635
  const SIMPLE_MESSAGE_KEYS = Object.freeze([
43615
- 'release', 'hotfix', 'currentStatus', 'noAction', 'actionRequired', 'progress',
43636
+ 'release', 'hotfix', 'currentStatus', 'noAction', 'completionNotice', 'actionRequired', 'progress',
43616
43637
  'currentTransition', 'whatNext', 'links', 'technical', 'alreadyPublished',
43617
43638
  'notPublished', 'productionUpdated', 'developmentSynchronized', 'yes', 'no',
43618
43639
  'from', 'to', 'state', 'compare', 'controlCenter', 'purpose', 'afterMerge',
@@ -43668,6 +43689,7 @@ exports.DEPLOYMENT_MESSAGE_IDS = Object.freeze([
43668
43689
  const ENGLISH_SIMPLE = Object.freeze({
43669
43690
  release: 'Release', hotfix: 'Hotfix', currentStatus: 'Current status',
43670
43691
  noAction: 'No action is required while GitHub owns the pending transition.', actionRequired: 'Action required',
43692
+ completionNotice: 'Deployment is complete. No further action is required.',
43671
43693
  progress: 'Progress', currentTransition: 'Current transition', whatNext: 'What happens next', links: 'Links',
43672
43694
  technical: 'Technical details', alreadyPublished: 'Package status: already published', notPublished: 'Package status: not published',
43673
43695
  productionUpdated: 'Production updated', developmentSynchronized: 'Development synchronized', yes: 'Yes', no: 'No',
@@ -43700,6 +43722,7 @@ const ENGLISH_SIMPLE = Object.freeze({
43700
43722
  const SPANISH_SIMPLE = Object.freeze({
43701
43723
  release: 'Release', hotfix: 'Hotfix', currentStatus: 'Estado actual',
43702
43724
  noAction: 'No se requiere ninguna acción mientras GitHub gestiona la transición pendiente.', actionRequired: 'Acción necesaria',
43725
+ completionNotice: 'El despliegue ha terminado. No se requiere ninguna acción adicional.',
43703
43726
  progress: 'Progreso', currentTransition: 'Transición actual', whatNext: 'Qué ocurrirá después', links: 'Enlaces',
43704
43727
  technical: 'Detalles técnicos', alreadyPublished: 'Estado del paquete: ya publicado', notPublished: 'Estado del paquete: no publicado',
43705
43728
  productionUpdated: 'Producción actualizada', developmentSynchronized: 'Desarrollo sincronizado', yes: 'Sí', no: 'No',
@@ -44247,6 +44270,8 @@ function nextDescription(operation, messages, catalog) {
44247
44270
  });
44248
44271
  }
44249
44272
  function deploymentAction(operation, messages) {
44273
+ if (operation.phase === 'completed')
44274
+ return { required: false, message: messages.completionNotice };
44250
44275
  const manual = (operation.selectedPrMode ?? operation.prMode) === 'create-only'
44251
44276
  && (operation.phase === 'promotion_pr_pending' || operation.phase === 'reconciliation_pending');
44252
44277
  if (manual)
@@ -50157,6 +50182,91 @@ function bindSddEvidenceReadPorts(ports) {
50157
50182
  }
50158
50183
 
50159
50184
 
50185
+ /***/ }),
50186
+
50187
+ /***/ 84387:
50188
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
50189
+
50190
+ "use strict";
50191
+
50192
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
50193
+ exports.DeploymentMergeEffects = void 0;
50194
+ const application_error_1 = __nccwpck_require__(75999);
50195
+ const deployment_merge_effect_error_1 = __nccwpck_require__(72594);
50196
+ const managed_pull_request_1 = __nccwpck_require__(95914);
50197
+ /** Applies current policy, with one bounded re-observation after a typed readiness rejection. */
50198
+ class DeploymentMergeEffects {
50199
+ constructor(pullRequests) {
50200
+ this.pullRequests = pullRequests;
50201
+ }
50202
+ async configure(operation, pullRequest, inspection, inspect, beforeApply) {
50203
+ await beforeApply(inspection.decision.mode);
50204
+ const action = selectAction(operation, inspection);
50205
+ try {
50206
+ await this.apply(action, pullRequest);
50207
+ return inspection.decision.mode;
50208
+ }
50209
+ catch (error) {
50210
+ if (!(error instanceof deployment_merge_effect_error_1.DeploymentMergeEffectError) || !error.readinessChanged || operation.prMode !== "auto")
50211
+ throw error;
50212
+ const current = await this.pullRequests.getPullRequest(pullRequest.number);
50213
+ assertSamePullRequest(pullRequest, current);
50214
+ if (current.merged)
50215
+ return inspection.decision.mode;
50216
+ if (current.state !== "open")
50217
+ throw new application_error_1.ApplicationError("provider.conflict", "The managed PR was closed without merging.");
50218
+ const refreshed = await inspect(current);
50219
+ if (refreshed.kind === "blocked")
50220
+ throw new application_error_1.ApplicationError("provider.conflict", refreshed.reason);
50221
+ const nextAction = selectAction(operation, refreshed);
50222
+ if (nextAction === action) {
50223
+ if (action === "enable-auto-merge" && current.autoMergeEnabled)
50224
+ return refreshed.decision.mode;
50225
+ throw error;
50226
+ }
50227
+ await beforeApply(refreshed.decision.mode);
50228
+ await this.apply(nextAction, current);
50229
+ return refreshed.decision.mode;
50230
+ }
50231
+ }
50232
+ async apply(action, pullRequest) {
50233
+ try {
50234
+ if (action === "merge") {
50235
+ await this.pullRequests.mergePullRequest(pullRequest.number, pullRequest.headSha);
50236
+ }
50237
+ else if (action === "enable-auto-merge" && !pullRequest.autoMergeEnabled) {
50238
+ await this.pullRequests.enableAutoMerge(pullRequest.nodeId, pullRequest.headSha);
50239
+ }
50240
+ else if (action === "merge-queue" && !await this.pullRequests.isPullRequestQueued(pullRequest.nodeId)) {
50241
+ await this.pullRequests.enqueuePullRequest(pullRequest.nodeId, pullRequest.headSha);
50242
+ }
50243
+ }
50244
+ catch (cause) {
50245
+ if (cause instanceof application_error_1.ApplicationError)
50246
+ throw cause;
50247
+ throw new application_error_1.ApplicationError("workflow.failed", `Automatic merge action ${action} failed with an unclassified provider rejection.`, { cause, retryable: true });
50248
+ }
50249
+ }
50250
+ }
50251
+ exports.DeploymentMergeEffects = DeploymentMergeEffects;
50252
+ function selectAction(operation, inspection) {
50253
+ if (inspection.decision.mode !== "auto-merge")
50254
+ return inspection.decision.mode;
50255
+ return operation.prMode === "auto" && inspection.capabilities.immediatelyMergeable ? "merge" : "enable-auto-merge";
50256
+ }
50257
+ function assertSamePullRequest(expected, current) {
50258
+ const marker = (0, managed_pull_request_1.parseManagedPullRequestMarker)(expected.body);
50259
+ const currentMarker = (0, managed_pull_request_1.parseManagedPullRequestMarker)(current.body);
50260
+ if (expected.number !== current.number || expected.nodeId !== current.nodeId
50261
+ || expected.repositoryFullName !== current.repositoryFullName || expected.baseBranch !== current.baseBranch
50262
+ || expected.headBranch !== current.headBranch || expected.headSha !== current.headSha
50263
+ || !marker || !currentMarker || marker.operationId !== currentMarker.operationId
50264
+ || marker.phase !== currentMarker.phase || marker.issue !== currentMarker.issue) {
50265
+ throw new application_error_1.ApplicationError("provider.conflict", "The managed PR identity or frozen head changed during merge setup.", { retryable: false });
50266
+ }
50267
+ }
50268
+
50269
+
50160
50270
  /***/ }),
50161
50271
 
50162
50272
  /***/ 77658:
@@ -50181,6 +50291,7 @@ const deployment_message_catalog_1 = __nccwpck_require__(79364);
50181
50291
  const deployment_operation_1 = __nccwpck_require__(92730);
50182
50292
  const merge_queue_readiness_1 = __nccwpck_require__(12515);
50183
50293
  const result_1 = __nccwpck_require__(73817);
50294
+ const deployment_merge_effects_1 = __nccwpck_require__(84387);
50184
50295
  exports.DEPLOYMENT_ORCHESTRATION_TASK_ID = "DeploymentOrchestrationUseCase";
50185
50296
  class DeploymentOrchestrationRuntime {
50186
50297
  constructor(dependencies, stateBoundary) {
@@ -50255,18 +50366,18 @@ class DeploymentOrchestrationRuntime {
50255
50366
  result: await this.block(context, operation, category, inspection.reason, true),
50256
50367
  };
50257
50368
  }
50258
- const managed = {
50259
- ...operation,
50260
- selectedPrMode: inspection.decision.mode,
50261
- };
50262
- await this.persist(context, managed);
50369
+ let managed = operation;
50263
50370
  try {
50264
- await this.applyMergeBehavior(context, operation, pullRequest, inspection);
50371
+ await new deployment_merge_effects_1.DeploymentMergeEffects(this.dependencies.pullRequests).configure(operation, pullRequest, inspection, (current) => this.inspectMergeBehavior(context, operation, current.baseBranch, targetRole, current.headSha, current.number), async (mode) => {
50372
+ managed = { ...operation, selectedPrMode: mode };
50373
+ await this.persist(context, managed);
50374
+ });
50265
50375
  }
50266
50376
  catch (cause) {
50267
- const message = `GitHub could not configure automatic merge for PR #${pullRequest.number}. Check the PR and retry the stored ${category} phase.`;
50268
- const error = new application_error_1.ApplicationError("provider.unavailable", message, { cause, retryable: true });
50269
- return { kind: "blocked", result: await this.block(context, managed, category, message, true, error) };
50377
+ const diagnostic = (0, application_error_1.toApplicationError)(cause, "workflow.failed", "Automatic merge setup failed with an unclassified provider rejection.", { retryable: true });
50378
+ const message = `GitHub could not configure automatic merge for PR #${pullRequest.number}. ${diagnostic.message} Check the PR and retry the stored ${category} phase.`;
50379
+ const error = new application_error_1.ApplicationError(diagnostic.code, message, { cause, retryable: diagnostic.retryable });
50380
+ return { kind: "blocked", result: await this.block(context, managed, category, message, error.retryable, error) };
50270
50381
  }
50271
50382
  await this.publishDashboard(context, managed);
50272
50383
  return { kind: "configured", operation: managed };
@@ -50321,27 +50432,6 @@ class DeploymentOrchestrationRuntime {
50321
50432
  // Preserve the original provider failure returned by the coordinator.
50322
50433
  }
50323
50434
  }
50324
- async applyMergeBehavior(context, operation, pullRequest, inspection) {
50325
- if (inspection.decision.mode === "auto-merge") {
50326
- await this.applyAutoMerge(context, operation, pullRequest, inspection.capabilities);
50327
- return;
50328
- }
50329
- if (inspection.decision.mode === "merge-queue") {
50330
- const queued = await this.dependencies.pullRequests.isPullRequestQueued(pullRequest.nodeId);
50331
- if (!queued) {
50332
- await this.dependencies.pullRequests.enqueuePullRequest(pullRequest.nodeId, pullRequest.headSha);
50333
- }
50334
- }
50335
- }
50336
- async applyAutoMerge(context, operation, pullRequest, capabilities) {
50337
- if (operation.prMode === "auto" && capabilities.immediatelyMergeable) {
50338
- await this.dependencies.pullRequests.mergePullRequest(pullRequest.number, pullRequest.headSha);
50339
- return;
50340
- }
50341
- if (!pullRequest.autoMergeEnabled) {
50342
- await this.dependencies.pullRequests.enableAutoMerge(pullRequest.nodeId);
50343
- }
50344
- }
50345
50435
  async unsupportedMergeBehavior(context, operation, targetRole, targetBranch, capabilities, decision) {
50346
50436
  const catalog = await this.presentationCatalog('issue', context, operation);
50347
50437
  if (capabilities.mergeQueueObservationProblems.length === 0) {
@@ -71607,6 +71697,47 @@ function isNotFound(error) {
71607
71697
  }
71608
71698
 
71609
71699
 
71700
+ /***/ }),
71701
+
71702
+ /***/ 30873:
71703
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
71704
+
71705
+ "use strict";
71706
+
71707
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
71708
+ exports.githubDeploymentMergeError = githubDeploymentMergeError;
71709
+ const deployment_merge_effect_error_1 = __nccwpck_require__(72594);
71710
+ /** Never copy provider messages, request objects, headers, or arbitrary error types into public state. */
71711
+ function githubDeploymentMergeError(action, cause) {
71712
+ const value = isRecord(cause) ? cause : {};
71713
+ const status = typeof value.status === "number" && Number.isInteger(value.status)
71714
+ && value.status >= 100 && value.status <= 599 ? value.status : undefined;
71715
+ const rawErrors = Array.isArray(value.errors) ? value.errors : [];
71716
+ const errors = rawErrors.filter(isRecord);
71717
+ const types = errors.map((error) => error.type);
71718
+ const denied = status === 401 || status === 403 || types.includes("FORBIDDEN") || types.includes("UNAUTHORIZED");
71719
+ const limited = status === 429 || types.includes("RATE_LIMITED");
71720
+ const unavailable = (status !== undefined && status >= 500) || types.includes("INTERNAL") || types.includes("SERVICE_UNAVAILABLE");
71721
+ const cleanRejection = rawErrors.length === 1 && errors.length === 1 && errors[0].type === "UNPROCESSABLE"
71722
+ && typeof errors[0].message === "string"
71723
+ && ["Pull request is in clean status", "Pull request Pull request is in clean status",
71724
+ "Pull request is in unstable status", "Pull request Pull request is in unstable status"].includes(errors[0].message);
71725
+ const readinessChanged = !denied && !limited && !unavailable
71726
+ && ((action === "merge" && status === 405) || (action === "enable-auto-merge" && (status === undefined || status === 200) && cleanRejection));
71727
+ const code = denied ? "authorization.denied"
71728
+ : limited ? "provider.rate-limited"
71729
+ : unavailable ? "provider.unavailable"
71730
+ : status === 404 || types.includes("NOT_FOUND") ? "provider.not-found"
71731
+ : status !== undefined || types.length > 0 ? "provider.conflict" : "workflow.failed";
71732
+ const reason = readinessChanged ? "readiness-changed" : code;
71733
+ const http = status === undefined ? "" : `; HTTP ${status}`;
71734
+ return new deployment_merge_effect_error_1.DeploymentMergeEffectError(action, readinessChanged, code, `GitHub rejected ${action} (${reason}${http}).`, cause);
71735
+ }
71736
+ function isRecord(value) {
71737
+ return typeof value === "object" && value !== null && !Array.isArray(value);
71738
+ }
71739
+
71740
+
71610
71741
  /***/ }),
71611
71742
 
71612
71743
  /***/ 96483:
@@ -71617,6 +71748,8 @@ function isNotFound(error) {
71617
71748
  Object.defineProperty(exports, "__esModule", ({ value: true }));
71618
71749
  exports.GithubManagedPullRequestRepository = void 0;
71619
71750
  const managed_pull_request_1 = __nccwpck_require__(95914);
71751
+ const github_deployment_merge_error_1 = __nccwpck_require__(30873);
71752
+ const deployment_merge_effect_error_1 = __nccwpck_require__(72594);
71620
71753
  class GithubManagedPullRequestRepository {
71621
71754
  constructor(clientProvider) {
71622
71755
  this.clientProvider = clientProvider;
@@ -71660,12 +71793,21 @@ class GithubManagedPullRequestRepository {
71660
71793
  });
71661
71794
  return mapPullRequest(data, owner, repository);
71662
71795
  }
71663
- async enableAutoMerge(owner, repository, pullRequestNodeId, token) {
71664
- await this.clientProvider.getClient(token).graphql(`mutation EnableDeploymentAutoMerge($pullRequestId: ID!) {
71665
- enablePullRequestAutoMerge(input: {pullRequestId: $pullRequestId, mergeMethod: MERGE}) {
71666
- pullRequest { id }
71796
+ async enableAutoMerge(_owner, _repository, pullRequestNodeId, expectedHeadSha, token) {
71797
+ let response;
71798
+ try {
71799
+ response = await this.clientProvider.getClient(token).graphql(`mutation EnableDeploymentAutoMerge($pullRequestId: ID!, $expectedHeadOid: GitObjectID!) {
71800
+ enablePullRequestAutoMerge(input: {pullRequestId: $pullRequestId, expectedHeadOid: $expectedHeadOid, mergeMethod: MERGE}) {
71801
+ pullRequest { id }
71802
+ }
71803
+ }`, { pullRequestId: pullRequestNodeId, expectedHeadOid: expectedHeadSha });
71804
+ }
71805
+ catch (cause) {
71806
+ throw (0, github_deployment_merge_error_1.githubDeploymentMergeError)("enable-auto-merge", cause);
71807
+ }
71808
+ if (response?.enablePullRequestAutoMerge?.pullRequest?.id !== pullRequestNodeId) {
71809
+ throw new deployment_merge_effect_error_1.DeploymentMergeEffectError("enable-auto-merge", false, "provider.contract-invalid", "GitHub did not confirm native auto-merge for the expected PR.");
71667
71810
  }
71668
- }`, { pullRequestId: pullRequestNodeId, owner, repository });
71669
71811
  }
71670
71812
  async isPullRequestQueued(owner, repository, pullRequestNodeId, token) {
71671
71813
  const response = await this.clientProvider.getClient(token).graphql(`query DeploymentPullRequestQueue($pullRequestId: ID!) {
@@ -71689,15 +71831,18 @@ class GithubManagedPullRequestRepository {
71689
71831
  }
71690
71832
  }
71691
71833
  async mergePullRequest(owner, repository, pullRequest, expectedHeadSha, token) {
71692
- const { data } = await this.clientProvider.getClient(token).rest.pulls.merge({
71693
- owner,
71694
- repo: repository,
71695
- pull_number: pullRequest,
71696
- merge_method: "merge",
71697
- sha: expectedHeadSha,
71698
- });
71699
- if (!data.merged || !data.sha)
71700
- throw new Error(data.message ?? `Pull request #${pullRequest} was not merged.`);
71834
+ let data;
71835
+ try {
71836
+ ({ data } = await this.clientProvider.getClient(token).rest.pulls.merge({
71837
+ owner, repo: repository, pull_number: pullRequest, merge_method: "merge", sha: expectedHeadSha,
71838
+ }));
71839
+ }
71840
+ catch (cause) {
71841
+ throw (0, github_deployment_merge_error_1.githubDeploymentMergeError)("merge", cause);
71842
+ }
71843
+ if (!data?.merged || typeof data.sha !== "string" || !/^[a-f0-9]{40}$/i.test(data.sha)) {
71844
+ throw new deployment_merge_effect_error_1.DeploymentMergeEffectError("merge", false, "provider.contract-invalid", "GitHub did not confirm a completed merge with a valid commit SHA.");
71845
+ }
71701
71846
  return data.sha;
71702
71847
  }
71703
71848
  }
@@ -84907,7 +85052,7 @@ function bindManagedPullRequests(port, binding) {
84907
85052
  findManagedPullRequests: (query) => port.findManagedPullRequests({ ...query, owner: binding.owner, repository: binding.repository, token: binding.token }),
84908
85053
  createManagedPullRequest: (command) => port.createManagedPullRequest({ ...command, owner: binding.owner, repository: binding.repository, token: binding.token }),
84909
85054
  getPullRequest: (pullRequest) => port.getPullRequest(binding.owner, binding.repository, pullRequest, binding.token),
84910
- enableAutoMerge: (pullRequestNodeId) => port.enableAutoMerge(binding.owner, binding.repository, pullRequestNodeId, binding.token),
85055
+ enableAutoMerge: (pullRequestNodeId, expectedHeadSha) => port.enableAutoMerge(binding.owner, binding.repository, pullRequestNodeId, expectedHeadSha, binding.token),
84911
85056
  isPullRequestQueued: (pullRequestNodeId) => port.isPullRequestQueued(binding.owner, binding.repository, pullRequestNodeId, binding.token),
84912
85057
  enqueuePullRequest: (pullRequestNodeId, expectedHeadSha) => port.enqueuePullRequest(binding.owner, binding.repository, pullRequestNodeId, expectedHeadSha, binding.token),
84913
85058
  mergePullRequest: (pullRequest, expectedHeadSha) => port.mergePullRequest(binding.owner, binding.repository, pullRequest, expectedHeadSha, binding.token),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vypdev/copilot",
3
- "version": "3.5.3",
3
+ "version": "3.5.5",
4
4
  "packageManager": "pnpm@10.12.4",
5
5
  "pnpm": {
6
6
  "overrides": {