@apralabs/apra-fleet 0.4.1 → 0.4.2
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/README.md +16 -8
- package/dist/agents/backlog-groomer.md +17 -21
- package/dist/agents/ci-watcher.md +3 -0
- package/dist/agents/deployer.md +22 -44
- package/dist/agents/doer.md +131 -132
- package/dist/agents/harvester.md +20 -32
- package/dist/agents/integ-test-runner.md +81 -113
- package/dist/agents/kb-reconciler.md +31 -42
- package/dist/agents/plan-reviewer.md +32 -44
- package/dist/agents/planner.md +51 -63
- package/dist/agents/regression-test-runner.md +65 -80
- package/dist/agents/reviewer.md +56 -83
- package/dist/agents/schemas/integ-test-runner-output.json +1 -1
- package/dist/agents/schemas/regression-test-runner-output.json +4 -17
- package/dist/cli/auth.d.ts.map +1 -1
- package/dist/cli/auth.js +1 -2
- package/dist/cli/auth.js.map +1 -1
- package/dist/cli/config.d.ts +3 -3
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +4 -13
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/install.d.ts.map +1 -1
- package/dist/cli/install.js +5 -39
- package/dist/cli/install.js.map +1 -1
- package/dist/cli/register-member.js +1 -1
- package/dist/cli/start.d.ts.map +1 -1
- package/dist/cli/start.js +7 -0
- package/dist/cli/start.js.map +1 -1
- package/dist/cli/uninstall.d.ts.map +1 -1
- package/dist/cli/uninstall.js +5 -3
- package/dist/cli/uninstall.js.map +1 -1
- package/dist/cli/watch.d.ts +26 -3
- package/dist/cli/watch.d.ts.map +1 -1
- package/dist/cli/watch.js +41 -9
- package/dist/cli/watch.js.map +1 -1
- package/dist/os/git-bash-candidates.d.ts +35 -0
- package/dist/os/git-bash-candidates.d.ts.map +1 -0
- package/dist/os/git-bash-candidates.js +46 -0
- package/dist/os/git-bash-candidates.js.map +1 -0
- package/dist/os/index.d.ts +13 -4
- package/dist/os/index.d.ts.map +1 -1
- package/dist/os/index.js +17 -2
- package/dist/os/index.js.map +1 -1
- package/dist/os/linux.js +1 -1
- package/dist/os/linux.js.map +1 -1
- package/dist/os/os-commands.d.ts +7 -0
- package/dist/os/os-commands.d.ts.map +1 -1
- package/dist/os/os-commands.js.map +1 -1
- package/dist/os/windows-gitbash.d.ts +93 -0
- package/dist/os/windows-gitbash.d.ts.map +1 -0
- package/dist/os/windows-gitbash.js +244 -0
- package/dist/os/windows-gitbash.js.map +1 -0
- package/dist/os/windows.d.ts.map +1 -1
- package/dist/os/windows.js +27 -5
- package/dist/os/windows.js.map +1 -1
- package/dist/providers/agy.d.ts +3 -2
- package/dist/providers/agy.d.ts.map +1 -1
- package/dist/providers/agy.js +11 -2
- package/dist/providers/agy.js.map +1 -1
- package/dist/providers/claude.d.ts +3 -2
- package/dist/providers/claude.d.ts.map +1 -1
- package/dist/providers/claude.js +22 -3
- package/dist/providers/claude.js.map +1 -1
- package/dist/providers/codex.d.ts +3 -2
- package/dist/providers/codex.d.ts.map +1 -1
- package/dist/providers/codex.js +5 -2
- package/dist/providers/codex.js.map +1 -1
- package/dist/providers/copilot.d.ts +3 -2
- package/dist/providers/copilot.d.ts.map +1 -1
- package/dist/providers/copilot.js +7 -2
- package/dist/providers/copilot.js.map +1 -1
- package/dist/providers/index.d.ts +0 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +0 -3
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/none.d.ts +3 -2
- package/dist/providers/none.d.ts.map +1 -1
- package/dist/providers/none.js +5 -2
- package/dist/providers/none.js.map +1 -1
- package/dist/providers/opencode.d.ts +3 -2
- package/dist/providers/opencode.d.ts.map +1 -1
- package/dist/providers/opencode.js +5 -2
- package/dist/providers/opencode.js.map +1 -1
- package/dist/providers/provider.d.ts +16 -7
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/provider.js +2 -2
- package/dist/providers/provider.js.map +1 -1
- package/dist/services/agent-provisioner.js +2 -2
- package/dist/services/agent-provisioner.js.map +1 -1
- package/dist/services/cloud/activity.js +2 -2
- package/dist/services/cloud/activity.js.map +1 -1
- package/dist/services/context-admission.d.ts.map +1 -1
- package/dist/services/context-admission.js +9 -7
- package/dist/services/context-admission.js.map +1 -1
- package/dist/services/credential-cleanup.d.ts.map +1 -1
- package/dist/services/credential-cleanup.js +22 -3
- package/dist/services/credential-cleanup.js.map +1 -1
- package/dist/services/member-home.d.ts +1 -1
- package/dist/services/member-home.d.ts.map +1 -1
- package/dist/services/member-home.js +15 -12
- package/dist/services/member-home.js.map +1 -1
- package/dist/services/model-pricing.d.ts.map +1 -1
- package/dist/services/model-pricing.js +0 -5
- package/dist/services/model-pricing.js.map +1 -1
- package/dist/services/orphan-recovery.d.ts +6 -3
- package/dist/services/orphan-recovery.d.ts.map +1 -1
- package/dist/services/orphan-recovery.js +17 -14
- package/dist/services/orphan-recovery.js.map +1 -1
- package/dist/services/preflight-check.js +2 -2
- package/dist/services/preflight-check.js.map +1 -1
- package/dist/services/shell-probe.d.ts +131 -0
- package/dist/services/shell-probe.d.ts.map +1 -0
- package/dist/services/shell-probe.js +210 -0
- package/dist/services/shell-probe.js.map +1 -0
- package/dist/services/singleton.d.ts +2 -0
- package/dist/services/singleton.d.ts.map +1 -1
- package/dist/services/singleton.js +1 -1
- package/dist/services/singleton.js.map +1 -1
- package/dist/services/ssh.js +2 -2
- package/dist/services/ssh.js.map +1 -1
- package/dist/services/stall/find-log-file.d.ts.map +1 -1
- package/dist/services/stall/find-log-file.js +22 -16
- package/dist/services/stall/find-log-file.js.map +1 -1
- package/dist/services/stall/read-log-tail.d.ts.map +1 -1
- package/dist/services/stall/read-log-tail.js +6 -5
- package/dist/services/stall/read-log-tail.js.map +1 -1
- package/dist/services/stall/stall-poller.d.ts.map +1 -1
- package/dist/services/stall/stall-poller.js +35 -42
- package/dist/services/stall/stall-poller.js.map +1 -1
- package/dist/services/strategy.d.ts +9 -0
- package/dist/services/strategy.d.ts.map +1 -1
- package/dist/services/strategy.js +40 -6
- package/dist/services/strategy.js.map +1 -1
- package/dist/services/user-config.js +1 -1
- package/dist/services/user-config.js.map +1 -1
- package/dist/services/vcs/azure-devops.d.ts +1 -1
- package/dist/services/vcs/azure-devops.d.ts.map +1 -1
- package/dist/services/vcs/azure-devops.js +105 -10
- package/dist/services/vcs/azure-devops.js.map +1 -1
- package/dist/services/vcs/bitbucket.d.ts.map +1 -1
- package/dist/services/vcs/bitbucket.js +16 -0
- package/dist/services/vcs/bitbucket.js.map +1 -1
- package/dist/services/vcs/github.d.ts.map +1 -1
- package/dist/services/vcs/github.js +24 -0
- package/dist/services/vcs/github.js.map +1 -1
- package/dist/services/vcs/types.d.ts +123 -2
- package/dist/services/vcs/types.d.ts.map +1 -1
- package/dist/skills/fleet-sprint-cli/SKILL.md +2 -1
- package/dist/skills/pm/SKILL.md +0 -1
- package/dist/skills/pm/cost.md +0 -1
- package/dist/skills/pm/fleet-addendum.md +0 -1
- package/dist/tools/check-status.js +3 -3
- package/dist/tools/check-status.js.map +1 -1
- package/dist/tools/cloud-control.js +2 -2
- package/dist/tools/cloud-control.js.map +1 -1
- package/dist/tools/compose-permissions.d.ts.map +1 -1
- package/dist/tools/compose-permissions.js +37 -24
- package/dist/tools/compose-permissions.js.map +1 -1
- package/dist/tools/execute-command.d.ts.map +1 -1
- package/dist/tools/execute-command.js +28 -12
- package/dist/tools/execute-command.js.map +1 -1
- package/dist/tools/execute-prompt.d.ts.map +1 -1
- package/dist/tools/execute-prompt.js +55 -18
- package/dist/tools/execute-prompt.js.map +1 -1
- package/dist/tools/list-members.d.ts.map +1 -1
- package/dist/tools/list-members.js +6 -2
- package/dist/tools/list-members.js.map +1 -1
- package/dist/tools/member-detail.d.ts.map +1 -1
- package/dist/tools/member-detail.js +5 -3
- package/dist/tools/member-detail.js.map +1 -1
- package/dist/tools/member-reservation.d.ts.map +1 -1
- package/dist/tools/member-reservation.js +13 -1
- package/dist/tools/member-reservation.js.map +1 -1
- package/dist/tools/monitor-task.d.ts.map +1 -1
- package/dist/tools/monitor-task.js +17 -2
- package/dist/tools/monitor-task.js.map +1 -1
- package/dist/tools/provision-auth.js +5 -5
- package/dist/tools/provision-auth.js.map +1 -1
- package/dist/tools/provision-vcs-auth.d.ts +5 -2
- package/dist/tools/provision-vcs-auth.d.ts.map +1 -1
- package/dist/tools/provision-vcs-auth.js +58 -52
- package/dist/tools/provision-vcs-auth.js.map +1 -1
- package/dist/tools/register-member.d.ts +18 -12
- package/dist/tools/register-member.d.ts.map +1 -1
- package/dist/tools/register-member.js +42 -4
- package/dist/tools/register-member.js.map +1 -1
- package/dist/tools/remove-member.js +2 -2
- package/dist/tools/remove-member.js.map +1 -1
- package/dist/tools/revoke-vcs-auth.js +2 -2
- package/dist/tools/revoke-vcs-auth.js.map +1 -1
- package/dist/tools/setup-ssh-key.d.ts.map +1 -1
- package/dist/tools/setup-ssh-key.js +2 -1
- package/dist/tools/setup-ssh-key.js.map +1 -1
- package/dist/tools/stop-prompt.js +2 -2
- package/dist/tools/stop-prompt.js.map +1 -1
- package/dist/tools/update-agent-cli.js +2 -2
- package/dist/tools/update-agent-cli.js.map +1 -1
- package/dist/tools/update-member.d.ts +18 -12
- package/dist/tools/update-member.d.ts.map +1 -1
- package/dist/tools/update-member.js +18 -1
- package/dist/tools/update-member.js.map +1 -1
- package/dist/types.d.ts +11 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/agent-helpers.d.ts +36 -0
- package/dist/utils/agent-helpers.d.ts.map +1 -1
- package/dist/utils/agent-helpers.js +39 -1
- package/dist/utils/agent-helpers.js.map +1 -1
- package/dist/utils/platform.d.ts +7 -0
- package/dist/utils/platform.d.ts.map +1 -1
- package/dist/utils/platform.js +11 -1
- package/dist/utils/platform.js.map +1 -1
- package/dist/utils/workspace-trust.d.ts.map +1 -1
- package/dist/utils/workspace-trust.js +5 -1
- package/dist/utils/workspace-trust.js.map +1 -1
- package/dist/workflows/auto-sprint.js +4 -17
- package/package.json +2 -2
- package/packages/apra-fleet-client/src/client/api.mjs +92 -3
- package/packages/apra-fleet-se/apra-pm/agents/backlog-groomer.md +17 -21
- package/packages/apra-fleet-se/apra-pm/agents/ci-watcher.md +3 -0
- package/packages/apra-fleet-se/apra-pm/agents/deployer.md +22 -44
- package/packages/apra-fleet-se/apra-pm/agents/doer.md +131 -132
- package/packages/apra-fleet-se/apra-pm/agents/harvester.md +20 -32
- package/packages/apra-fleet-se/apra-pm/agents/integ-test-runner.md +81 -113
- package/packages/apra-fleet-se/apra-pm/agents/kb-reconciler.md +31 -42
- package/packages/apra-fleet-se/apra-pm/agents/plan-reviewer.md +32 -44
- package/packages/apra-fleet-se/apra-pm/agents/planner.md +51 -63
- package/packages/apra-fleet-se/apra-pm/agents/regression-test-runner.md +65 -80
- package/packages/apra-fleet-se/apra-pm/agents/reviewer.md +56 -83
- package/packages/apra-fleet-se/apra-pm/agents/schemas/integ-test-runner-output.json +1 -1
- package/packages/apra-fleet-se/apra-pm/agents/schemas/regression-test-runner-output.json +4 -17
- package/packages/apra-fleet-se/apra-pm/skills/pm/SKILL.md +0 -1
- package/packages/apra-fleet-se/apra-pm/skills/pm/cost.md +0 -1
- package/packages/apra-fleet-se/apra-pm/skills/pm/fleet-addendum.md +0 -1
- package/packages/apra-fleet-se/bin/cli.mjs +132 -3
- package/packages/apra-fleet-se/bin/serve.mjs +36 -1
- package/packages/apra-fleet-se/fleet-sprint/contracts.mjs +151 -33
- package/packages/apra-fleet-se/fleet-sprint/docs/README.md +22 -7
- package/packages/apra-fleet-se/fleet-sprint/docs/dolt-manual-recovery-verified.md +10 -8
- package/packages/apra-fleet-se/fleet-sprint/docs/dolt-sync-redesign.md +9 -4
- package/packages/apra-fleet-se/fleet-sprint/docs/escalate-to-llm-design.md +2 -2
- package/packages/apra-fleet-se/fleet-sprint/docs/shared-orchestrator-reservation-design.md +12 -12
- package/packages/apra-fleet-se/fleet-sprint/docs/stabilization-log.md +14 -4
- package/packages/apra-fleet-se/fleet-sprint/dolt-settle.mjs +275 -99
- package/packages/apra-fleet-se/fleet-sprint/dolt-sync.mjs +67 -16
- package/packages/apra-fleet-se/fleet-sprint/errors.mjs +41 -0
- package/packages/apra-fleet-se/fleet-sprint/runner.js +1140 -209
- package/packages/apra-fleet-se/fleet-sprint/se-os-commands.mjs +134 -0
- package/packages/apra-fleet-se/fleet-sprint/se-posix.mjs +154 -0
- package/packages/apra-fleet-se/fleet-sprint/se-windows-gitbash.mjs +97 -0
- package/packages/apra-fleet-se/fleet-sprint/se-windows.mjs +143 -0
- package/packages/apra-fleet-se/fleet-sprint/skills/fleet-sprint-cli/SKILL.md +2 -1
- package/packages/apra-fleet-se/fleet-sprint/vcs-module.mjs +51 -0
- package/packages/apra-fleet-se/fleet-sprint/vcs-providers/azure-devops.mjs +657 -12
- package/packages/apra-fleet-se/fleet-sprint/vcs-providers/dolt.mjs +33 -4
- package/packages/apra-fleet-se/fleet-sprint/vcs-providers/github.mjs +60 -43
- package/packages/apra-fleet-se/fleet-sprint/vcs-providers/index.mjs +205 -2
- package/packages/apra-fleet-se/fleet-sprint/vcs-providers/shell-helpers.mjs +164 -0
- package/packages/apra-fleet-se/fleet-sprint/viewer-extensions.mjs +92 -37
- package/packages/apra-fleet-workflow/src/viewer/index.mjs +167 -1
- package/packages/apra-fleet-workflow/src/workflow/index.mjs +435 -31
- package/skills/fleet/SKILL.md +20 -9
- package/skills/fleet/auth-azdevops.md +44 -5
- package/skills/fleet/auth-bitbucket.md +3 -3
- package/skills/fleet/auth-github.md +2 -2
- package/skills/fleet/beads-conflict-resolution.md +141 -0
- package/skills/fleet/beads.md +16 -12
- package/skills/fleet/onboarding.md +4 -4
- package/skills/fleet/permissions.md +6 -6
- package/skills/fleet/skill-matrix.md +1 -1
- package/skills/fleet/troubleshooting.md +2 -1
- package/version.json +1 -1
- package/dist/providers/gemini.d.ts +0 -52
- package/dist/providers/gemini.d.ts.map +0 -1
- package/dist/providers/gemini.js +0 -236
- package/dist/providers/gemini.js.map +0 -1
- package/packages/apra-fleet-se/fleet-sprint/docs/coach-role-design.md +0 -23
|
@@ -8,14 +8,17 @@
|
|
|
8
8
|
* new provider had to also edit.
|
|
9
9
|
*
|
|
10
10
|
* No auth-mode axis of its own (a single PAT token field at
|
|
11
|
-
* provision_vcs_auth time, same as Bitbucket -- see ./bitbucket.mjs)
|
|
12
|
-
* REST create-pull-request/comment builders
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
11
|
+
* provision_vcs_auth time, same as Bitbucket -- see ./bitbucket.mjs).
|
|
12
|
+
* apra-fleet-lzfv.2 adds the REST create-pull-request/comment builders (see
|
|
13
|
+
* buildAzureDevOpsCreatePrCommand/buildAzureDevOpsCommentCommand below);
|
|
14
|
+
* capabilitiesForHost()'s canOpenPullRequest is now true (apra-fleet-lzfv.5),
|
|
15
|
+
* once runner.js's publish path could actually dispatch them (see that
|
|
16
|
+
* function's doc comment). Any action WITHOUT a builder still fails closed
|
|
17
|
+
* with a clear ASCII
|
|
18
|
+
* "ERROR: ... does not yet implement action ..." from buildVcsCommand()
|
|
19
|
+
* instead of a silently wrong command. Declaring `defaultAuthMode` (even as
|
|
20
|
+
* `null`) is what makes 'azure-devops' part of resolveProvider()'s known
|
|
21
|
+
* vocabulary -- see ./index.mjs's isAuthBackend().
|
|
19
22
|
*
|
|
20
23
|
* Extends GenericGitVCS for stderr classification. Azure DevOps' own
|
|
21
24
|
* TF-numbered error codes (e.g. TF401019) previously were NOT added as a
|
|
@@ -37,32 +40,674 @@
|
|
|
37
40
|
* with vcs-classify-failure.test.mjs's own AC1 example provider, which models
|
|
38
41
|
* TF401019 the same way.
|
|
39
42
|
*
|
|
43
|
+
* apra-fleet-5co8.1.1 adds the host/URL axis: matchesHost(),
|
|
44
|
+
* capabilitiesForHost() and parseRepoRef(). All three are descriptor hooks
|
|
45
|
+
* dispatched from shared code (./index.mjs's resolveVcsProviderForHost(),
|
|
46
|
+
* vcs-module.mjs's capabilities()), so no Azure DevOps conditional leaks into
|
|
47
|
+
* a shared file. capabilitiesForHost() now reports canOpenPullRequest:true
|
|
48
|
+
* (apra-fleet-lzfv.5) -- runner.js's publish path (raiseVcsPrForMember) is
|
|
49
|
+
* provider-aware now, resolving the member's own registered provider instead
|
|
50
|
+
* of hardcoding 'github', so this host can actually reach `builders` above.
|
|
51
|
+
*
|
|
52
|
+
* apra-fleet-5co8.4.1 adds two more additive rules on top of the bare
|
|
53
|
+
* TF401019 AUTH_DENIED rule above (which stays exactly as-is): a REST 401 /
|
|
54
|
+
* TF400813 both mean the PAT itself is expired or revoked (AUTH_EXPIRED --
|
|
55
|
+
* re-minting the token is the fix), while a REST 403 is a missing-scope
|
|
56
|
+
* refusal (AUTH_DENIED -- widening the PAT's scopes is the fix, per
|
|
57
|
+
* skills/fleet/auth-azdevops.md's role/scope table). See the AUTH_EXPIRED /
|
|
58
|
+
* AUTH_DENIED doc comments below for the exact texts and why each is
|
|
59
|
+
* additive only, with no verdict moved for the pre-existing TF401019 case.
|
|
60
|
+
*
|
|
61
|
+
* apra-fleet-5co8.4.2 declares `authRemedy` (see its own doc comment below):
|
|
62
|
+
* an auth-classified failure here can never be fixed by the shared reactive
|
|
63
|
+
* self-heal alone, because a PAT is stored/redeployed, never re-minted --
|
|
64
|
+
* runner.js prints this provider's remedy text via that generic descriptor
|
|
65
|
+
* field rather than a provider-name conditional of its own.
|
|
66
|
+
*
|
|
40
67
|
* ASCII only.
|
|
41
68
|
*/
|
|
42
69
|
|
|
43
70
|
import { VCS_FAILURE_KINDS as K } from '../errors.mjs';
|
|
71
|
+
import { shQuote, shQuoteJson, curlBinary, assertToken } from './shell-helpers.mjs';
|
|
72
|
+
|
|
73
|
+
/** Credential no longer good -- re-minting a PAT (skills/fleet/auth-azdevops.md
|
|
74
|
+
* "401 Unauthorized -> Create new PAT and re-deploy") is the remedy, so
|
|
75
|
+
* AUTH_EXPIRED, same split GenericGitVCS/GitHubVCS already use for a 401 vs a
|
|
76
|
+
* 403.
|
|
77
|
+
*
|
|
78
|
+
* apra-fleet-5co8.4.1: two independent signals both mean "the PAT itself is
|
|
79
|
+
* expired/revoked", not "wrong scope":
|
|
80
|
+
* - A bare trailing REST status line of '401'. VCSModule's curl builders
|
|
81
|
+
* append `-w '\n%{http_code}'` (see ./github.mjs's identical convention),
|
|
82
|
+
* so a REST call's own stdout ends in a status-code-only line; anchored
|
|
83
|
+
* to end-of-string/line so an inline "401" mentioned mid-sentence (which
|
|
84
|
+
* says nothing about THIS call's own outcome) is never matched.
|
|
85
|
+
* azure-devops.mjs's own REST builders (added apra-fleet-lzfv.2, below)
|
|
86
|
+
* append it too, and classifyFailure() is reachable standalone (see
|
|
87
|
+
* vcs-classify-failure.test.mjs AC1/'providers listed as known but
|
|
88
|
+
* unimplemented ... still classify'), and PAT validation elsewhere in
|
|
89
|
+
* the fleet already shells a curl+`-w '\n%{http_code}'` call against this
|
|
90
|
+
* same REST API (skills/fleet/auth-azdevops.md's own `curl -sf` Test
|
|
91
|
+
* section) whose failure text this rule must classify correctly today.
|
|
92
|
+
* - TF400813, whose text is a generic "resource not available" refusal
|
|
93
|
+
* that Azure DevOps also emits for an expired/revoked PAT (the org-URL
|
|
94
|
+
* misconfiguration case in the troubleshooting table above resolves
|
|
95
|
+
* through the SAME message; re-minting -- which also forces a fresh
|
|
96
|
+
* provision_vcs_auth pass where the org URL is re-checked -- is still the
|
|
97
|
+
* correct first remedy, per the design recorded on the parent
|
|
98
|
+
* apra-fleet-5co8.4 goal). */
|
|
99
|
+
const AUTH_EXPIRED = [
|
|
100
|
+
/(?:^|\n)\s*401\s*$/,
|
|
101
|
+
/TF400813/,
|
|
102
|
+
];
|
|
44
103
|
|
|
104
|
+
/** Identity understood, PAT itself still valid, access refused -- re-minting
|
|
105
|
+
* the SAME credential cannot fix either of these; the remedy is a broader
|
|
106
|
+
* scope (skills/fleet/auth-azdevops.md's role/scope table) or -- for
|
|
107
|
+
* TF401019 specifically -- the repo/permission grant itself. AUTH_DENIED.
|
|
108
|
+
*
|
|
109
|
+
* apra-fleet-5co8.4.1:
|
|
110
|
+
* - A bare trailing REST status line of '403' (skills/fleet/auth-
|
|
111
|
+
* azdevops.md "403 Forbidden -> Create PAT with broader scopes"). Same
|
|
112
|
+
* anchored shape and same rationale as the 401 rule above -- mirrors it
|
|
113
|
+
* exactly, just the denied half of the 401/403 HTTP split.
|
|
114
|
+
* - TF401019 (unchanged from before this task -- see the module doc
|
|
115
|
+
* comment above and vcs-nongithub-auth-selfheal.test.mjs's real-bd
|
|
116
|
+
* end-to-end assertion through withGitSync, which this rule must keep
|
|
117
|
+
* passing verbatim): "does not exist, or you do not have permission" is
|
|
118
|
+
* Azure DevOps' deliberately ambiguous repo-not-found-or-no-access
|
|
119
|
+
* message; re-minting the identical PAT cannot fix either case. */
|
|
45
120
|
const AUTH_DENIED = [
|
|
121
|
+
/(?:^|\n)\s*403\s*$/,
|
|
46
122
|
/TF401019/,
|
|
47
123
|
];
|
|
48
124
|
|
|
49
125
|
/** Best-effort Azure DevOps TF-numbered error code, purely DIAGNOSTIC: never
|
|
50
|
-
* branch on it -- branch on `kind`.
|
|
126
|
+
* branch on it -- branch on `kind`. Falls back to a bare trailing REST status
|
|
127
|
+
* line (the `-w '\n%{http_code}'` convention -- see ./github.mjs's
|
|
128
|
+
* extractProviderCode for the same fallback), so a REST 401/403 with no
|
|
129
|
+
* TF-numbered code still surfaces its status for diagnostics. */
|
|
51
130
|
function extractProviderCode(raw) {
|
|
52
131
|
const text = String(raw == null ? '' : raw);
|
|
53
|
-
const
|
|
54
|
-
|
|
132
|
+
const tf = text.match(/\b(TF\d{6})\b/);
|
|
133
|
+
if (tf) return tf[1];
|
|
134
|
+
const trailing = text.match(/(?:^|\n)\s*(\d{3})\s*$/);
|
|
135
|
+
return trailing ? trailing[1] : null;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** The three Azure DevOps host forms, ANCHORED (never a substring test -- see
|
|
139
|
+
* the lookalike cases in test/vcs-azure-devops-repo-ref.test.mjs):
|
|
140
|
+
* - dev.azure.com https remotes
|
|
141
|
+
* - ssh.dev.azure.com the v3 ssh remotes
|
|
142
|
+
* - <org>.visualstudio.com the legacy host, plus bare visualstudio.com
|
|
143
|
+
* Contrast GitHubVCS.matchesHost(), which is deliberately a substring test
|
|
144
|
+
* because GitHub Enterprise Server hosts have no fixed domain; Azure DevOps
|
|
145
|
+
* is a hosted-only service with exactly these domains, so anchoring costs
|
|
146
|
+
* nothing and keeps `dev.azure.com.evil.example` from being claimed. */
|
|
147
|
+
const HOST_RE = /^(?:dev\.azure\.com|ssh\.dev\.azure\.com|(?:[a-z0-9-]+\.)*visualstudio\.com)$/i;
|
|
148
|
+
|
|
149
|
+
/** Host-recognition for VCSModule.capabilities() and
|
|
150
|
+
* resolveVcsProviderForHost() (see ./index.mjs). */
|
|
151
|
+
function matchesHost(host) {
|
|
152
|
+
return typeof host === 'string' && HOST_RE.test(host.trim());
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** TRUE (apra-fleet-lzfv.5), now that `builders` (apra-fleet-lzfv.2) is
|
|
156
|
+
* reachable through a publish path that actually knows how to dispatch them
|
|
157
|
+
* -- honouring the lockstep rule in ./index.mjs's REQUIRED EXPORT SHAPE: a
|
|
158
|
+
* host never ADVERTISES a pull request it cannot actually deliver. Before
|
|
159
|
+
* this flip, Azure DevOps genuinely could not: runner.js's publish path
|
|
160
|
+
* (raiseVcsPrForMember) called buildCreatePrCommand with a HARDCODED
|
|
161
|
+
* `provider: 'github'` and a two-part 'owner/name' repo, so an Azure DevOps
|
|
162
|
+
* remote reaching it died inside GitHubVCS's assertRepo on the three-part
|
|
163
|
+
* org/project/repo canonical ("invalid repo ... expected \"owner/name\"")
|
|
164
|
+
* instead of building this file's command -- measured, not assumed:
|
|
165
|
+
* test/mock-sprint-azure-devops-vcs-preflight.test.mjs failed 2 of 3 with the
|
|
166
|
+
* flip alone and passed 3 of 3 without it. raiseVcsPrForMember now resolves
|
|
167
|
+
* the member's own registered provider (VCSModule.resolveProvider(), never
|
|
168
|
+
* hardcoded) and reads the provider-owned repoRef/response-mapping
|
|
169
|
+
* descriptors instead of a GitHub literal, which is what makes this flip
|
|
170
|
+
* safe. */
|
|
171
|
+
function capabilitiesForHost(_host) {
|
|
172
|
+
return { canOpenPullRequest: true };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Percent-decode one path segment; an invalid escape (e.g. a bare '%') is
|
|
176
|
+
* left as-is rather than throwing, because parseRepoRef must never throw. */
|
|
177
|
+
function decodeSegment(segment) {
|
|
178
|
+
try {
|
|
179
|
+
return decodeURIComponent(segment);
|
|
180
|
+
} catch {
|
|
181
|
+
return segment;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Split `path` into non-empty, percent-decoded segments with any trailing
|
|
186
|
+
* '.git' stripped off the LAST one. */
|
|
187
|
+
function pathSegments(path) {
|
|
188
|
+
const raw = String(path).split('/').filter((part) => part !== '');
|
|
189
|
+
if (raw.length === 0) return raw;
|
|
190
|
+
raw[raw.length - 1] = raw[raw.length - 1].replace(/\.git$/i, '');
|
|
191
|
+
return raw.map(decodeSegment);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** Split a remote URL into { host, path } for BOTH shapes git speaks: a real
|
|
195
|
+
* scheme'd URL (https/ssh, with optional userinfo and port) and the scp-like
|
|
196
|
+
* shorthand `git@host:path` that `new URL()` cannot parse at all. */
|
|
197
|
+
function splitRemote(url) {
|
|
198
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(url)) {
|
|
199
|
+
let parsed;
|
|
200
|
+
try {
|
|
201
|
+
parsed = new URL(url);
|
|
202
|
+
} catch {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
if (!parsed.hostname) return null;
|
|
206
|
+
return { host: parsed.hostname.toLowerCase(), path: parsed.pathname };
|
|
207
|
+
}
|
|
208
|
+
const scp = /^(?:[^@\s/]+@)?([^:\s/]+):(.*)$/.exec(url);
|
|
209
|
+
if (!scp) return null;
|
|
210
|
+
return { host: scp[1].toLowerCase(), path: `/${scp[2]}` };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function makeRef(org, project, repo) {
|
|
214
|
+
if (!org || !project || !repo) return null;
|
|
215
|
+
return {
|
|
216
|
+
org,
|
|
217
|
+
project,
|
|
218
|
+
repo,
|
|
219
|
+
canonical: `${org}/${project}/${repo}`,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Parse an Azure DevOps git remote URL into its { org, project, repo,
|
|
225
|
+
* canonical } coordinates -- the identity every Azure DevOps REST call needs
|
|
226
|
+
* (https://dev.azure.com/{org}/{project}/_apis/git/repositories/{repo}/...).
|
|
227
|
+
*
|
|
228
|
+
* Recognized shapes:
|
|
229
|
+
* https://[user@]dev.azure.com/ORG/PROJECT/_git/REPO[.git][/]
|
|
230
|
+
* https://[user@]dev.azure.com/ORG/_git/REPO (project == repo)
|
|
231
|
+
* git@ssh.dev.azure.com:v3/ORG/PROJECT/REPO[.git]
|
|
232
|
+
* ssh://git@ssh.dev.azure.com[:22]/v3/ORG/PROJECT/REPO[.git]
|
|
233
|
+
* https://ORG.visualstudio.com/[DefaultCollection/]PROJECT/_git/REPO[.git]
|
|
234
|
+
* https://ORG.visualstudio.com/_git/REPO (project == repo)
|
|
235
|
+
*
|
|
236
|
+
* The project-omitted shorthand is how Azure DevOps itself renders a repo
|
|
237
|
+
* whose name equals its project's, so taking the repo name as the project is
|
|
238
|
+
* the correct expansion, not a guess.
|
|
239
|
+
*
|
|
240
|
+
* Percent-encoded project names (the common case -- Azure DevOps allows
|
|
241
|
+
* spaces in project names) are decoded in EVERY returned field, so `canonical`
|
|
242
|
+
* is a display/identity key, not a URL fragment: re-encode per segment before
|
|
243
|
+
* building a request URL from it.
|
|
244
|
+
*
|
|
245
|
+
* NEVER throws and NEVER partially guesses: anything that is not one of the
|
|
246
|
+
* shapes above -- including a non-Azure host and a lookalike like
|
|
247
|
+
* `dev.azure.com.evil.example` -- returns null, so the caller can raise its
|
|
248
|
+
* own typed ERROR naming the expected shape (apra-fleet-5co8.1.2) instead of
|
|
249
|
+
* proceeding with half-parsed coordinates.
|
|
250
|
+
*
|
|
251
|
+
* @param {unknown} remoteUrl
|
|
252
|
+
* @returns {{ org: string, project: string, repo: string, canonical: string }|null}
|
|
253
|
+
*/
|
|
254
|
+
function parseRepoRef(remoteUrl) {
|
|
255
|
+
if (typeof remoteUrl !== 'string') return null;
|
|
256
|
+
const url = remoteUrl.trim();
|
|
257
|
+
if (!url) return null;
|
|
258
|
+
|
|
259
|
+
const split = splitRemote(url);
|
|
260
|
+
if (!split || !matchesHost(split.host)) return null;
|
|
261
|
+
|
|
262
|
+
const segments = pathSegments(split.path);
|
|
263
|
+
if (segments.length === 0) return null;
|
|
264
|
+
|
|
265
|
+
// ssh v3 form: exactly v3/ORG/PROJECT/REPO -- no _git marker, no
|
|
266
|
+
// project-omitted shorthand (Azure DevOps always emits all three).
|
|
267
|
+
if (segments[0].toLowerCase() === 'v3') {
|
|
268
|
+
if (segments.length !== 4) return null;
|
|
269
|
+
return makeRef(segments[1], segments[2], segments[3]);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// https forms: the '_git' marker separates the org/project prefix from
|
|
273
|
+
// the single repo segment. Requiring the marker to be second-from-last is
|
|
274
|
+
// what rejects both a missing repo and any extra trailing segment.
|
|
275
|
+
const marker = segments.indexOf('_git');
|
|
276
|
+
if (marker === -1 || marker !== segments.length - 2) return null;
|
|
277
|
+
const repo = segments[segments.length - 1];
|
|
278
|
+
let prefix = segments.slice(0, marker);
|
|
279
|
+
|
|
280
|
+
const legacy = /visualstudio\.com$/i.test(split.host);
|
|
281
|
+
if (legacy) {
|
|
282
|
+
// Legacy host: the org is the HOSTNAME label, not a path segment, and
|
|
283
|
+
// an explicit collection segment (historically 'DefaultCollection')
|
|
284
|
+
// may precede the project.
|
|
285
|
+
const org = split.host.split('.')[0];
|
|
286
|
+
if (!org || org.toLowerCase() === 'visualstudio') return null;
|
|
287
|
+
if (prefix.length > 0 && prefix[0].toLowerCase() === 'defaultcollection') prefix = prefix.slice(1);
|
|
288
|
+
if (prefix.length > 1) return null;
|
|
289
|
+
return makeRef(org, prefix[0] || repo, repo);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (prefix.length < 1 || prefix.length > 2) return null;
|
|
293
|
+
return makeRef(prefix[0], prefix[1] || repo, repo);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** The documented default credential-store entry holding an Azure DevOps PAT
|
|
297
|
+
* (skills/fleet/auth-azdevops.md, "Storing tokens for reuse":
|
|
298
|
+
* `credential_store_set name=azdevops_pat`).
|
|
299
|
+
* A per-sprint override is passed via runner.js args and threaded
|
|
300
|
+
* through buildProvisionArgs (apra-fleet-5co8.2.3); when unset, this
|
|
301
|
+
* default is used. */
|
|
302
|
+
const DEFAULT_PAT_SECRET = 'azdevops_pat';
|
|
303
|
+
|
|
304
|
+
/** The canonical remote shape parseRepoRef() expects, quoted into every
|
|
305
|
+
* operator-facing remedy this module produces (see `repoRefHint` below). */
|
|
306
|
+
const REPO_REF_HINT = 'https://dev.azure.com/ORG/PROJECT/_git/REPO';
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Build the provision_vcs_auth argument object for an Azure DevOps member
|
|
310
|
+
* (apra-fleet-5co8.2.1).
|
|
311
|
+
*
|
|
312
|
+
* WHY A HOOK: the shared argument shape (`git_access` + a `repos` allowlist)
|
|
313
|
+
* is GitHub-App vocabulary. Azure DevOps has no App/installation model at all
|
|
314
|
+
* -- a PAT is minted by a human against an ORG, so what provision_vcs_auth
|
|
315
|
+
* needs here is `org_url` plus the token, and `git_access`/`repos` are
|
|
316
|
+
* meaningless. Expressing that as a descriptor hook keeps the difference in
|
|
317
|
+
* this file instead of adding a provider branch to the shared caller.
|
|
318
|
+
*
|
|
319
|
+
* SECRET TRANSPORT: the PAT is passed as a `{{secure.NAME}}` PLACEHOLDER, never
|
|
320
|
+
* a value. Resolution happens hub-side inside the fleet server; the orchestrator
|
|
321
|
+
* process that calls this hook never holds, logs or transports the plaintext,
|
|
322
|
+
* and a remote member (which has no secret store of its own) never has to.
|
|
323
|
+
* That is also why a missing store entry is a TYPED ERROR rather than a prompt:
|
|
324
|
+
* an unattended preflight/self-heal has no operator attached, and an
|
|
325
|
+
* out-of-band prompt there would stall the sprint instead of failing it.
|
|
326
|
+
*
|
|
327
|
+
* @param {{ base: object, repoRef: ({ org: string }|null|undefined),
|
|
328
|
+
* availableSecrets: string[]|null, secretName?: string }} ctx
|
|
329
|
+
* `base` is the shared argument object the caller would otherwise send;
|
|
330
|
+
* `repoRef` is this provider's own parseRepoRef() output for the member's
|
|
331
|
+
* remote; `availableSecrets` is the credential-store entry names the caller
|
|
332
|
+
* observed (null when it could not be read -- then the check is skipped
|
|
333
|
+
* rather than guessed, and a genuinely missing secret still fails loudly
|
|
334
|
+
* server-side).
|
|
335
|
+
* @returns {{ args: object }|{ error: string }}
|
|
336
|
+
*/
|
|
337
|
+
function buildProvisionArgs(ctx) {
|
|
338
|
+
const { base = {}, repoRef, availableSecrets, secretName } = ctx || {};
|
|
339
|
+
const org = repoRef && typeof repoRef.org === 'string' ? repoRef.org.trim() : '';
|
|
340
|
+
if (!org) {
|
|
341
|
+
return {
|
|
342
|
+
error: `ERROR: cannot provision Azure DevOps auth for member '${base.member_name}': no organization could be derived from the member's git remote; expected a remote of the shape ${REPO_REF_HINT}`,
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const name = (typeof secretName === 'string' && secretName.trim()) ? secretName.trim() : DEFAULT_PAT_SECRET;
|
|
347
|
+
if (Array.isArray(availableSecrets) && !availableSecrets.includes(name)) {
|
|
348
|
+
return {
|
|
349
|
+
error: `ERROR: cannot provision Azure DevOps auth for member '${base.member_name}': the credential store has no entry named '${name}'. Store the PAT first with: credential_store_set name=${name}`,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
return {
|
|
354
|
+
args: {
|
|
355
|
+
member_name: base.member_name,
|
|
356
|
+
provider: base.provider,
|
|
357
|
+
// Base org URL with no trailing path -- see auth-azdevops.md's
|
|
358
|
+
// "Org URL must be base URL without trailing path" note and the
|
|
359
|
+
// TF400813 troubleshooting row, which is what a wrong org URL
|
|
360
|
+
// surfaces as.
|
|
361
|
+
org_url: `https://dev.azure.com/${org}`,
|
|
362
|
+
// Placeholder, NOT a value. See SECRET TRANSPORT above.
|
|
363
|
+
pat: `{{secure.${name}}}`,
|
|
364
|
+
},
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// ---------------------------------------------------------------------------
|
|
369
|
+
// REST command builders (apra-fleet-lzfv.2)
|
|
370
|
+
// ---------------------------------------------------------------------------
|
|
371
|
+
//
|
|
372
|
+
// PARAMETER CONTRACT (the shape buildVcsCommand() hands a builder, and what
|
|
373
|
+
// apra-fleet-lzfv.3's golden tests and apra-fleet-lzfv.4's response mapping
|
|
374
|
+
// read as this provider's contract):
|
|
375
|
+
//
|
|
376
|
+
// provider 'azure-devops'
|
|
377
|
+
// repoRef OPTIONAL { org, project, repo } -- parseRepoRef()'s own output,
|
|
378
|
+
// passed straight through. Individual org/project/repo params
|
|
379
|
+
// take PRECEDENCE over the matching repoRef field, so a caller can
|
|
380
|
+
// override one coordinate without rebuilding the object.
|
|
381
|
+
// org/project/repo the three coordinates every Azure DevOps REST call
|
|
382
|
+
// needs. All three are required after the repoRef merge; a missing
|
|
383
|
+
// one is a typed ERROR naming the expected remote shape, never a
|
|
384
|
+
// half-built URL.
|
|
385
|
+
// base/head branch names, in GitHub's OWN vocabulary deliberately (`base` =
|
|
386
|
+
// the branch merged INTO -> targetRefName, `head` = the branch
|
|
387
|
+
// merged FROM -> sourceRefName). Keeping github.mjs's field names
|
|
388
|
+
// is what lets runner.js stay provider-agnostic -- see
|
|
389
|
+
// ./index.mjs's "NO OTHER FILE under fleet-sprint/ changes".
|
|
390
|
+
// title/body PR title and description.
|
|
391
|
+
// pull_request_id (comment only) the PR to annotate.
|
|
392
|
+
// token the PAT. REQUIRED -- assertToken() throws the shared typed ERROR.
|
|
393
|
+
// os resolveMemberOs()'s value ('windows'/'linux'/'darwin'). Selects
|
|
394
|
+
// the curl BINARY token via curlBinary() (curl.exe on Windows,
|
|
395
|
+
// which stays OS-keyed because curl.exe is equally resolvable from
|
|
396
|
+
// PowerShell and from Git-for-Windows bash), and is the fallback
|
|
397
|
+
// input to the quoting dialect when `shell` is unresolved.
|
|
398
|
+
// shell the member's registered COMMAND SHELL as resolved by runner.js's
|
|
399
|
+
// resolveMemberTarget() -- 'gitbash' | 'pwsh7' | 'powershell5' |
|
|
400
|
+
// '' -- and the primary input to shQuote()'s quoting DIALECT:
|
|
401
|
+
// gitbash -> POSIX even on Windows, pwsh7/powershell5 -> PowerShell
|
|
402
|
+
// doubling, unresolved + windows -> PowerShell doubling (the
|
|
403
|
+
// historical fallback, byte-identical). Distinct from `os`: a
|
|
404
|
+
// Windows member running gitbash needs curl.exe with POSIX quoting.
|
|
405
|
+
//
|
|
406
|
+
// AUTH: Azure DevOps' REST API takes a PAT as HTTP Basic with an EMPTY
|
|
407
|
+
// username (`-u :PAT`), NOT a bearer token -- the exact form skills/fleet/
|
|
408
|
+
// auth-azdevops.md already documents for its connectivity Test call. The PAT
|
|
409
|
+
// therefore appears in `command` ONLY; `logSafeCommand` is built by the same
|
|
410
|
+
// closure with REDACTED substituted, so no field other than `command` can
|
|
411
|
+
// carry it.
|
|
412
|
+
//
|
|
413
|
+
// URL ENCODING: parseRepoRef() percent-DECODES every field it returns (Azure
|
|
414
|
+
// DevOps project names commonly contain spaces), so each coordinate is
|
|
415
|
+
// re-encoded per segment here -- see parseRepoRef's own doc note.
|
|
416
|
+
|
|
417
|
+
/** api-version pinned to 7.1, matching skills/fleet/auth-azdevops.md's own
|
|
418
|
+
* REST calls. Pinned, never floating: an unversioned Azure DevOps REST call
|
|
419
|
+
* is rejected outright. */
|
|
420
|
+
const API_VERSION = '7.1';
|
|
421
|
+
|
|
422
|
+
/** Same fixed marker github.mjs uses, so a log scrubber/assertion looking for
|
|
423
|
+
* a redacted VCS command matches identically across providers. */
|
|
424
|
+
const REDACTED = '***REDACTED***';
|
|
425
|
+
|
|
426
|
+
/** Merge a `repoRef` object with any explicit org/project/repo overrides and
|
|
427
|
+
* require all three. Throws the typed ERROR (quoting REPO_REF_HINT, the same
|
|
428
|
+
* remedy text repoRefHint publishes) rather than building a partial URL.
|
|
429
|
+
*
|
|
430
|
+
* apra-fleet-5co8.11: an explicit param takes precedence over the matching
|
|
431
|
+
* repoRef field (see the PARAMETER CONTRACT doc block above), but a caller
|
|
432
|
+
* can hand this a three-part canonical (parseRepoRef()'s own
|
|
433
|
+
* `org/project/repo` string, or github.mjs's two-part `owner/name`) as a
|
|
434
|
+
* SINGLE coordinate -- most plausibly `repo` -- instead of splitting it
|
|
435
|
+
* first. repoApiBase() would then percent-encode the whole slash-bearing
|
|
436
|
+
* string into one URL segment, building a silently wrong URL (a 404 at
|
|
437
|
+
* request time) rather than failing at build time. Reject a '/' inside
|
|
438
|
+
* `org` or `repo` with the same typed ERROR raised for a missing
|
|
439
|
+
* coordinate, so the mistake surfaces immediately instead of round-tripping
|
|
440
|
+
* through a live REST call first. `project` is EXCLUDED from this check: an
|
|
441
|
+
* Azure DevOps project name is decoded free-form by parseRepoRef() and a
|
|
442
|
+
* literal '/' inside it is a legitimate value re-encoded per segment by
|
|
443
|
+
* repoApiBase() below (pinned by "each coordinate is percent-encoded per URL
|
|
444
|
+
* segment" in vcs-azure-devops-builders.test.mjs), not a coordinate-mixing
|
|
445
|
+
* mistake -- org and repo, by contrast, are never expected to contain one. */
|
|
446
|
+
function assertRepoCoords(params, action) {
|
|
447
|
+
const ref = (params && typeof params.repoRef === 'object' && params.repoRef) ? params.repoRef : {};
|
|
448
|
+
const pick = (key) => {
|
|
449
|
+
const own = params && params[key] != null ? params[key] : ref[key];
|
|
450
|
+
return String(own ?? '').trim();
|
|
451
|
+
};
|
|
452
|
+
const org = pick('org');
|
|
453
|
+
const project = pick('project');
|
|
454
|
+
const repo = pick('repo');
|
|
455
|
+
const missing = [['org', org], ['project', project], ['repo', repo]].filter(([, v]) => !v).map(([k]) => k);
|
|
456
|
+
if (missing.length > 0) {
|
|
457
|
+
throw new Error(`ERROR: VCSModule: azure-devops "${action}" needs org, project and repo (missing: ${missing.join(', ')}) -- pass them explicitly or as the repoRef parsed from a remote of the shape ${REPO_REF_HINT}.`);
|
|
458
|
+
}
|
|
459
|
+
const slashed = [['org', org], ['repo', repo]].filter(([, v]) => v.includes('/'));
|
|
460
|
+
if (slashed.length > 0) {
|
|
461
|
+
throw new Error(`ERROR: VCSModule: azure-devops "${action}" got a '/' inside ${slashed.map(([k]) => k).join(', ')} -- pass the three org/project/repo coordinates SEPARATELY, not a combined "org/project/repo" string, per the remote shape ${REPO_REF_HINT}.`);
|
|
462
|
+
}
|
|
463
|
+
return { org, project, repo };
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/** The org/project/repo REST prefix, each coordinate re-encoded per segment. */
|
|
467
|
+
function repoApiBase({ org, project, repo }) {
|
|
468
|
+
return `https://dev.azure.com/${encodeURIComponent(org)}/${encodeURIComponent(project)}/_apis/git/repositories/${encodeURIComponent(repo)}`;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/** Azure DevOps' pullrequests endpoint takes FULL ref names
|
|
472
|
+
* ('refs/heads/main'), not the bare branch names GitHub's API takes, and
|
|
473
|
+
* rejects a bare name outright. An input that already carries a 'refs/'
|
|
474
|
+
* prefix is passed through untouched so a caller holding a real ref (e.g.
|
|
475
|
+
* 'refs/heads/feat/x') is never double-prefixed. */
|
|
476
|
+
function toFullRef(branch) {
|
|
477
|
+
const value = String(branch).trim();
|
|
478
|
+
return /^refs\//i.test(value) ? value : `refs/heads/${value}`;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Build the Azure DevOps REST "create pull request" curl command.
|
|
483
|
+
* POST {org}/{project}/_apis/git/repositories/{repo}/pullrequests?api-version=7.1
|
|
484
|
+
* -- see https://learn.microsoft.com/rest/api/azure/devops/git/pull-requests/create
|
|
485
|
+
*/
|
|
486
|
+
function buildAzureDevOpsCreatePrCommand(params) {
|
|
487
|
+
const { base, head, title, body, token, os, shell } = params || {};
|
|
488
|
+
const coords = assertRepoCoords(params, 'create-pull-request');
|
|
489
|
+
const safeToken = assertToken(token);
|
|
490
|
+
if (!base) throw new Error('ERROR: VCSModule: "base" branch is required to build a create-pull-request command.');
|
|
491
|
+
if (!head) throw new Error('ERROR: VCSModule: "head" branch is required to build a create-pull-request command.');
|
|
492
|
+
if (!title) throw new Error('ERROR: VCSModule: "title" is required to build a create-pull-request command.');
|
|
493
|
+
|
|
494
|
+
const payload = {
|
|
495
|
+
sourceRefName: toFullRef(head),
|
|
496
|
+
targetRefName: toFullRef(base),
|
|
497
|
+
title,
|
|
498
|
+
};
|
|
499
|
+
if (body !== undefined) payload.description = body;
|
|
500
|
+
const payloadJson = JSON.stringify(payload);
|
|
501
|
+
const url = `${repoApiBase(coords)}/pullrequests?api-version=${API_VERSION}`;
|
|
502
|
+
|
|
503
|
+
const buildCurl = (authToken) => [
|
|
504
|
+
`${curlBinary(os)} -sS -X POST`,
|
|
505
|
+
`-u ${shQuote(`:${authToken}`, os, shell)}`,
|
|
506
|
+
`-H ${shQuote('Content-Type: application/json', os, shell)}`,
|
|
507
|
+
`-H ${shQuote('Accept: application/json', os, shell)}`,
|
|
508
|
+
`-d ${shQuoteJson(payloadJson, os, shell)}`,
|
|
509
|
+
`-w ${shQuote('\n%{http_code}', os, shell)}`,
|
|
510
|
+
url,
|
|
511
|
+
].join(' ');
|
|
512
|
+
|
|
513
|
+
return {
|
|
514
|
+
provider: 'azure-devops',
|
|
515
|
+
action: 'create-pull-request',
|
|
516
|
+
command: buildCurl(safeToken),
|
|
517
|
+
logSafeCommand: buildCurl(REDACTED),
|
|
518
|
+
// Interpretation contract, same field NAMES github.mjs uses so a
|
|
519
|
+
// consumer reads it generically:
|
|
520
|
+
// - 2xx -> success; body has .pullRequestId
|
|
521
|
+
// - 409 + TF401179 -> an active PR for this source/target
|
|
522
|
+
// pair already exists, which is the
|
|
523
|
+
// idempotent re-run case, so success
|
|
524
|
+
// - anything else -> error
|
|
525
|
+
interpret: {
|
|
526
|
+
successStatusRange: [200, 299],
|
|
527
|
+
alreadyExistsStatus: 409,
|
|
528
|
+
alreadyExistsPattern: 'TF401179',
|
|
529
|
+
},
|
|
530
|
+
};
|
|
55
531
|
}
|
|
56
532
|
|
|
533
|
+
/**
|
|
534
|
+
* Build the Azure DevOps REST "comment on a pull request" curl command, used
|
|
535
|
+
* to annotate an existing PR when a sprint aborts after the PR was already
|
|
536
|
+
* raised (rather than opening a second PR for the same source branch).
|
|
537
|
+
* POST .../pullrequests/{id}/threads?api-version=7.1 -- Azure DevOps has no
|
|
538
|
+
* bare "PR comment" resource: a comment is one entry in a THREAD, so a single
|
|
539
|
+
* text comment is posted as a new active thread carrying exactly one comment.
|
|
540
|
+
* See https://learn.microsoft.com/rest/api/azure/devops/git/pull-request-threads/create
|
|
541
|
+
*/
|
|
542
|
+
function buildAzureDevOpsCommentCommand(params) {
|
|
543
|
+
const { pull_request_id: pullRequestId, body, token, os, shell } = params || {};
|
|
544
|
+
const coords = assertRepoCoords(params, 'comment');
|
|
545
|
+
const safeToken = assertToken(token);
|
|
546
|
+
if (!pullRequestId) throw new Error('ERROR: VCSModule: "pull_request_id" is required to build an azure-devops comment command.');
|
|
547
|
+
if (!body) throw new Error('ERROR: VCSModule: "body" is required to build a comment command.');
|
|
548
|
+
|
|
549
|
+
const payloadJson = JSON.stringify({
|
|
550
|
+
comments: [{ parentCommentId: 0, content: body, commentType: 'text' }],
|
|
551
|
+
status: 'active',
|
|
552
|
+
});
|
|
553
|
+
const url = `${repoApiBase(coords)}/pullrequests/${encodeURIComponent(String(pullRequestId))}/threads?api-version=${API_VERSION}`;
|
|
554
|
+
|
|
555
|
+
const buildCurl = (authToken) => [
|
|
556
|
+
`${curlBinary(os)} -sS -X POST`,
|
|
557
|
+
`-u ${shQuote(`:${authToken}`, os, shell)}`,
|
|
558
|
+
`-H ${shQuote('Content-Type: application/json', os, shell)}`,
|
|
559
|
+
`-H ${shQuote('Accept: application/json', os, shell)}`,
|
|
560
|
+
`-d ${shQuoteJson(payloadJson, os, shell)}`,
|
|
561
|
+
`-w ${shQuote('\n%{http_code}', os, shell)}`,
|
|
562
|
+
url,
|
|
563
|
+
].join(' ');
|
|
564
|
+
|
|
565
|
+
return {
|
|
566
|
+
provider: 'azure-devops',
|
|
567
|
+
action: 'comment',
|
|
568
|
+
command: buildCurl(safeToken),
|
|
569
|
+
logSafeCommand: buildCurl(REDACTED),
|
|
570
|
+
interpret: {
|
|
571
|
+
successStatusRange: [200, 299],
|
|
572
|
+
},
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// ---------------------------------------------------------------------------
|
|
577
|
+
// Pull-request RESPONSE mapping (apra-fleet-lzfv.4)
|
|
578
|
+
// ---------------------------------------------------------------------------
|
|
579
|
+
//
|
|
580
|
+
// Azure DevOps' create-pull-request 2xx body speaks a DIFFERENT dialect than
|
|
581
|
+
// GitHub's: the identifier is `pullRequestId` (not `number`), and the body
|
|
582
|
+
// carries NO browsable web URL at all -- its `url` field is the REST resource
|
|
583
|
+
// (.../_apis/git/repositories/{id}/pullRequests/{id}), which is not a page an
|
|
584
|
+
// operator can open. The browsable URL therefore has to be CONSTRUCTED from
|
|
585
|
+
// the same org/project/repo coordinates the request was built from plus the
|
|
586
|
+
// returned id. Declaring both here (rather than teaching the caller either
|
|
587
|
+
// dialect) is the whole point of the contract -- see ./index.mjs and
|
|
588
|
+
// ./github.mjs's mirror-image declaration.
|
|
589
|
+
|
|
590
|
+
const PR_ID_FIELD = 'pullRequestId';
|
|
591
|
+
|
|
592
|
+
/** The browsable pull request page Azure DevOps renders for a PR -- the shape
|
|
593
|
+
* the web UI itself uses:
|
|
594
|
+
* https://dev.azure.com/{org}/{project}/_git/{repo}/pullrequest/{id}
|
|
595
|
+
* (the same org/project/_git/repo prefix as the clone URL REPO_REF_HINT
|
|
596
|
+
* quotes). Published as a template string so a consumer that must mirror this
|
|
597
|
+
* contract elsewhere (canonical VCS types / fleet client) can restate it
|
|
598
|
+
* without re-deriving it. */
|
|
599
|
+
const PR_WEB_URL_TEMPLATE = 'https://dev.azure.com/{org}/{project}/_git/{repo}/pullrequest/{id}';
|
|
600
|
+
|
|
601
|
+
/** Soft coordinate pick for the response mapping: unlike assertRepoCoords()
|
|
602
|
+
* (which is building a request URL and MUST fail loudly), a response mapping
|
|
603
|
+
* never throws -- a missing coordinate simply yields `url: null`, so a caller
|
|
604
|
+
* reporting an otherwise successful PR is never turned into a crash. */
|
|
605
|
+
function softRepoCoords(ctx) {
|
|
606
|
+
const source = (ctx && typeof ctx === 'object') ? ctx : {};
|
|
607
|
+
const ref = (source.repoRef && typeof source.repoRef === 'object') ? source.repoRef : {};
|
|
608
|
+
const pick = (key) => String((source[key] != null ? source[key] : ref[key]) ?? '').trim();
|
|
609
|
+
return { org: pick('org'), project: pick('project'), repo: pick('repo') };
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/** Map an Azure DevOps create-pull-request response body to { id, url }.
|
|
613
|
+
* Reads the DECLARED id field above, and builds the web URL from `ctx`'s
|
|
614
|
+
* org/project/repo (each segment re-encoded, same reason repoApiBase() does).
|
|
615
|
+
* `ctx` accepts either explicit org/project/repo or a `repoRef` object -- the
|
|
616
|
+
* same shape the builders take. */
|
|
617
|
+
function mapPullRequestResponse(body, ctx) {
|
|
618
|
+
const source = (body && typeof body === 'object') ? body : {};
|
|
619
|
+
const rawId = source[PR_ID_FIELD];
|
|
620
|
+
let id = null;
|
|
621
|
+
if (typeof rawId === 'number' && Number.isFinite(rawId)) id = rawId;
|
|
622
|
+
else if (typeof rawId === 'string' && /^\d+$/.test(rawId.trim())) id = Number(rawId.trim());
|
|
623
|
+
if (id === null) return { id: null, url: null };
|
|
624
|
+
|
|
625
|
+
const { org, project, repo } = softRepoCoords(ctx);
|
|
626
|
+
if (!org || !project || !repo) return { id, url: null };
|
|
627
|
+
const url = `https://dev.azure.com/${encodeURIComponent(org)}/${encodeURIComponent(project)}/_git/${encodeURIComponent(repo)}/pullrequest/${encodeURIComponent(String(id))}`;
|
|
628
|
+
return { id, url };
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
const pullRequestResponse = Object.freeze({
|
|
632
|
+
idField: PR_ID_FIELD,
|
|
633
|
+
// No web-URL field exists in the body -- it is constructed, see above.
|
|
634
|
+
webUrlField: null,
|
|
635
|
+
webUrlTemplate: PR_WEB_URL_TEMPLATE,
|
|
636
|
+
map: mapPullRequestResponse,
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
// ---------------------------------------------------------------------------
|
|
640
|
+
// Auth self-heal remedy (apra-fleet-5co8.4.2)
|
|
641
|
+
// ---------------------------------------------------------------------------
|
|
642
|
+
//
|
|
643
|
+
// Unlike a GitHub App installation token (minted fresh, server-side, on every
|
|
644
|
+
// provision_vcs_auth call), an Azure DevOps PAT is a long-lived secret the
|
|
645
|
+
// fleet only ever STORES and REDEPLOYS -- it never mints one. The Azure
|
|
646
|
+
// DevOps PAT lifecycle management API requires an Entra (Azure AD) OAuth
|
|
647
|
+
// token with admin consent the fleet does not hold (skills/fleet/
|
|
648
|
+
// auth-azdevops.md's "PAT Lifetime and Expiry" section). So when the
|
|
649
|
+
// REACTIVE self-heal (runner.js's createVcsAuthSelfHealCallback) fires on an
|
|
650
|
+
// auth-classified failure, calling provision_vcs_auth again just redeploys
|
|
651
|
+
// the SAME dead secret and is expected to fail again -- serverSideReMintable
|
|
652
|
+
// is false, and `hint` is the exact operator-facing remedy runner.js prints
|
|
653
|
+
// alongside the (still-attempted, still-logged) self-heal call, covering
|
|
654
|
+
// both AUTH_EXPIRED (401/TF400813 -- the PAT itself is dead) and AUTH_DENIED
|
|
655
|
+
// (403 -- the PAT is valid but scoped too narrowly; TF401019 is a
|
|
656
|
+
// repo/permission grant, not a scope, and has no PAT-rotation remedy) since
|
|
657
|
+
// the self-heal callback is never told which kind fired -- see
|
|
658
|
+
// ./index.mjs's authRemedy doc.
|
|
659
|
+
const AUTH_REMEDY_HINT =
|
|
660
|
+
'Azure DevOps PATs cannot be re-minted server-side. If the PAT expired or ' +
|
|
661
|
+
'was revoked: create a new PAT at https://dev.azure.com/ORG/_settings/tokens, ' +
|
|
662
|
+
'then credential_store_set the fleet secret and re-run provision_vcs_auth. ' +
|
|
663
|
+
'If access was denied for insufficient scope: create a PAT with broader ' +
|
|
664
|
+
'scopes per the role/scope table in skills/fleet/auth-azdevops.md, then ' +
|
|
665
|
+
'credential_store_set the fleet secret and re-run provision_vcs_auth.';
|
|
666
|
+
|
|
667
|
+
const authRemedy = Object.freeze({
|
|
668
|
+
serverSideReMintable: false,
|
|
669
|
+
hint: AUTH_REMEDY_HINT,
|
|
670
|
+
});
|
|
671
|
+
|
|
57
672
|
export const AzureDevOpsVCS = Object.freeze({
|
|
58
673
|
name: 'azure-devops',
|
|
59
674
|
extends: 'generic-git',
|
|
60
675
|
rules: Object.freeze({
|
|
676
|
+
[K.AUTH_EXPIRED]: AUTH_EXPIRED,
|
|
61
677
|
[K.AUTH_DENIED]: AUTH_DENIED,
|
|
62
678
|
}),
|
|
63
679
|
extractProviderCode,
|
|
680
|
+
matchesHost,
|
|
681
|
+
capabilitiesForHost,
|
|
682
|
+
// apra-fleet-5co8.1.1: remote-URL -> { org, project, repo, canonical }.
|
|
683
|
+
// An OPTIONAL descriptor hook (see ./index.mjs's REQUIRED EXPORT SHAPE):
|
|
684
|
+
// only providers whose REST identity is not the portable "owner/name"
|
|
685
|
+
// pair need it, which is why it lives here rather than in shared code.
|
|
686
|
+
parseRepoRef,
|
|
687
|
+
// apra-fleet-5co8.1.2: the remedy text for a remote this provider claims
|
|
688
|
+
// but parseRepoRef() rejects. Lives here, not in the caller, so runner.js
|
|
689
|
+
// can raise a provider-specific preflight ERROR with no Azure DevOps
|
|
690
|
+
// literal (or conditional) of its own. The canonical https shape is the
|
|
691
|
+
// one an operator copies out of the Azure DevOps "Clone" dialog; the ssh
|
|
692
|
+
// and legacy visualstudio.com shapes parseRepoRef also accepts are
|
|
693
|
+
// deliberately NOT listed, to keep the remedy a single copyable form.
|
|
694
|
+
repoRefHint: REPO_REF_HINT,
|
|
695
|
+
// apra-fleet-5co8.2.1: OPTIONAL descriptor hook -- see ./index.mjs.
|
|
696
|
+
buildProvisionArgs,
|
|
64
697
|
defaultAuthMode: null,
|
|
65
|
-
|
|
698
|
+
// apra-fleet-lzfv.4: this provider's create-pull-request response dialect
|
|
699
|
+
// (pullRequestId + a CONSTRUCTED web URL) -- see above.
|
|
700
|
+
pullRequestResponse,
|
|
701
|
+
// apra-fleet-5co8.4.2: PATs are never re-minted server-side -- see above.
|
|
702
|
+
authRemedy,
|
|
703
|
+
// apra-fleet-lzfv.2: the REST builders. capabilitiesForHost() above now
|
|
704
|
+
// reports canOpenPullRequest:true (apra-fleet-lzfv.5) -- the publish path
|
|
705
|
+
// can dispatch them. Any action not listed here still fails closed with
|
|
706
|
+
// buildVcsCommand()'s typed ERROR.
|
|
707
|
+
builders: Object.freeze({
|
|
708
|
+
'create-pull-request': buildAzureDevOpsCreatePrCommand,
|
|
709
|
+
comment: buildAzureDevOpsCommentCommand,
|
|
710
|
+
}),
|
|
66
711
|
});
|
|
67
712
|
|
|
68
713
|
export default AzureDevOpsVCS;
|