ace-lab 0.5.2 → 0.7.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/lib/ace/lab/cli/commands/service.rb +147 -4
- data/lib/ace/lab/cli.rb +3 -1
- data/lib/ace/lab/molecules/forge_merge_config.rb +127 -0
- data/lib/ace/lab/molecules/forgejo_merge_adapter.rb +150 -0
- data/lib/ace/lab/molecules/grant_resolver.rb +15 -13
- data/lib/ace/lab/molecules/ordinary_admission_resolver.rb +112 -0
- data/lib/ace/lab/molecules/ordinary_ff_merge.rb +86 -0
- data/lib/ace/lab/molecules/ordinary_listener.rb +238 -0
- data/lib/ace/lab/molecules/ordinary_receiver_config.rb +86 -0
- data/lib/ace/lab/molecules/ordinary_socket.rb +129 -0
- data/lib/ace/lab/molecules/service_policy.rb +71 -0
- data/lib/ace/lab/organisms/ordinary_merge_receiver.rb +663 -0
- data/lib/ace/lab/organisms/ordinary_merge_request.rb +422 -0
- data/lib/ace/lab/version.rb +1 -1
- metadata +29 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d3799161a4575055b78e316deb18a4fa952fb1d84fa9fb10cd6e5c081a36acee
|
|
4
|
+
data.tar.gz: dd2d0fa5764e5bce423396e93e4fd1751fddd880649219d6a130306d0ec49667
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1556efc67f0fa45a412b40430570355578c7e61000bda7af07982345631f023c3f56c709d2d02a25c3faf84495b510d6fb171a904d8f910e7c336b4b8113cd44
|
|
7
|
+
data.tar.gz: a78076debb811ce94046ff8cb056648b6455f8dbe30514a5d575ac417bcf98adce21bb42c3f6f712f0d0e2d6d4bbb3c67ba3764dfb9e4138cb6eb17e6dd6a113
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.7.0] - 2026-10-16
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Run the ordinary merge listener and receiver through `service listen`, with authenticated admission, canonical Assign acknowledgement/status/receipts, restart reconciliation and bounded fixed execution.
|
|
15
|
+
- Invoke and inspect real Forgejo merges under the installed scoped service identity; revalidate authorization per request and bind the provider mutation to the approved candidate head.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- Require ace-assign 0.69 and ace-git-forgejo 0.7 for the receiver record-listing and scoped provider APIs.
|
|
20
|
+
|
|
21
|
+
- Move the Forgejo merge provider ownership out of ace-lab (xz9.5): `ForgejoMergeAdapter` is now a thin delegation to the `ace-git-forgejo` provider (`Ace::Git::Forgejo::PullRequestApi` over its `HttpClient`, under the host-installed scoped service identity) — HTTP transport, authentication, payload shape, and failure classification live in the provider package, while the adapter keeps the receiver's closed outcome translation (`:invoked`/`:refused`/`:ambiguous`/`Unavailable`), the exact-head binding guard, and the normalized readback/nil-absence contract unchanged.
|
|
22
|
+
|
|
23
|
+
## [0.6.0] - 2026-10-14
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- Add the ordinary fixed merge producer mode (`ace-lab service request/status --mode ordinary-merge`) per xz9.4: durable-once admission that issues the opaque reference only through the committed journal record, canonical SHA-256 request digests over the full eight-field binding, identical-replay acknowledgment, authorization/binding conflict refusals, read-only status, and terminal receipts bound to the admitted record and its execution identity.
|
|
28
|
+
|
|
10
29
|
## [0.5.2] - 2026-10-11
|
|
11
30
|
|
|
12
31
|
### Changed
|
|
@@ -2,8 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
require "json"
|
|
4
4
|
require "ace/support/cli"
|
|
5
|
+
require "ace/assign"
|
|
5
6
|
require_relative "support"
|
|
6
7
|
require_relative "../../organisms/protected_service_request"
|
|
8
|
+
require_relative "../../organisms/ordinary_merge_request"
|
|
9
|
+
require_relative "../../organisms/ordinary_merge_receiver"
|
|
10
|
+
require_relative "../../molecules/ordinary_listener"
|
|
11
|
+
require_relative "../../molecules/ordinary_receiver_config"
|
|
7
12
|
|
|
8
13
|
module Ace
|
|
9
14
|
module Lab
|
|
@@ -20,7 +25,7 @@ module Ace
|
|
|
20
25
|
end
|
|
21
26
|
|
|
22
27
|
def protected_refusal(error)
|
|
23
|
-
code = error.is_a?(ArgumentError) || error.is_a?(SecurityError) ? "protected_service_refused" : "protected_service_unavailable"
|
|
28
|
+
code = (error.is_a?(ArgumentError) || error.is_a?(SecurityError)) ? "protected_service_refused" : "protected_service_unavailable"
|
|
24
29
|
message = error.is_a?(JSON::ParserError) ? "protected installed selection unavailable" : error.message.to_s.scrub[0, 512]
|
|
25
30
|
emit({"status" => "error", "error" => {"code" => code, "message" => message}})
|
|
26
31
|
end
|
|
@@ -49,6 +54,8 @@ module Ace
|
|
|
49
54
|
option :authorization, type: :string, required: true, desc: "Exact authorization reference"
|
|
50
55
|
option :request_id, type: :string, required: true, desc: "Idempotency key"
|
|
51
56
|
option :dry_run, type: :boolean, desc: "Validate without claiming or executing"
|
|
57
|
+
option :mode, type: :string, desc: "ordinary-merge selects the ordinary fixed merge producer"
|
|
58
|
+
option :queue_entry, type: :string, desc: "Original queue entry (ordinary merge)"
|
|
52
59
|
|
|
53
60
|
option :mapping, type: :string, desc: "Original protected mapping ID"
|
|
54
61
|
option :scope, type: :string, desc: "Original hierarchical prepared scope"
|
|
@@ -59,6 +66,26 @@ module Ace
|
|
|
59
66
|
|
|
60
67
|
def call(project:, assignment:, attempt:, operation:, input:, authorization:, request_id:, **options)
|
|
61
68
|
reject_identity_flags!(options)
|
|
69
|
+
mode = options[:mode]
|
|
70
|
+
if mode && mode != Organisms::OrdinaryMergeRequest::MODE
|
|
71
|
+
return emit(Organisms::OrdinaryMergeRequest.refusal_envelope("ordinary_merge_invalid_request",
|
|
72
|
+
"unknown service mode", request_id: request_id, input_digest: nil))
|
|
73
|
+
end
|
|
74
|
+
if mode
|
|
75
|
+
begin
|
|
76
|
+
return emit(ordinary_request(project: project, assignment: assignment, attempt: attempt,
|
|
77
|
+
queue_entry: options[:queue_entry], operation: operation, input: input,
|
|
78
|
+
authorization: authorization, request_id: request_id, **options))
|
|
79
|
+
rescue Ace::Assign::AttemptErrors::EvidenceUnavailable, Ace::Lab::InvalidConfigurationError => e
|
|
80
|
+
# Infra failures (unreadable canonical evidence, malformed
|
|
81
|
+
# installed configuration, unavailable topology) are the
|
|
82
|
+
# caller-side blocker, never a raw crash and never a durable
|
|
83
|
+
# reference (review r1 finding B).
|
|
84
|
+
return emit(Organisms::OrdinaryMergeRequest.refusal_envelope(
|
|
85
|
+
"ordinary_merge_unavailable", e.message, request_id: request_id, input_digest: nil
|
|
86
|
+
))
|
|
87
|
+
end
|
|
88
|
+
end
|
|
62
89
|
selected = protected_service.selected?(options)
|
|
63
90
|
if selected
|
|
64
91
|
return emit(protected_service.request(project: project, assignment: assignment, attempt: attempt,
|
|
@@ -68,9 +95,21 @@ module Ace
|
|
|
68
95
|
operation: operation, input_path: input, authorization: authorization,
|
|
69
96
|
request_id: request_id, dry_run: options[:dry_run]))
|
|
70
97
|
rescue ArgumentError, Ace::Assign::Error, Ace::Git::Error, Ace::Runtime::RuntimeUnavailableError, JSON::ParserError, SecurityError, KeyError, SystemCallError => error
|
|
71
|
-
raise if selected == false
|
|
98
|
+
raise if selected == false || mode
|
|
72
99
|
protected_refusal(error)
|
|
73
100
|
end
|
|
101
|
+
|
|
102
|
+
private
|
|
103
|
+
|
|
104
|
+
def ordinary_producer
|
|
105
|
+
@ordinary_producer ||= Organisms::OrdinaryMergeRequest.new
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# The ordinary refusal envelope is emitted exactly as received;
|
|
109
|
+
# it is classified for the non-zero exit like every refusal.
|
|
110
|
+
def ordinary_request(**arguments)
|
|
111
|
+
ordinary_producer.request(**arguments)
|
|
112
|
+
end
|
|
74
113
|
end
|
|
75
114
|
|
|
76
115
|
class Status < Ace::Support::Cli::Command
|
|
@@ -81,6 +120,9 @@ module Ace
|
|
|
81
120
|
desc "Read the authoritative outcome of a service request"
|
|
82
121
|
option :request, type: :string, required: true, desc: "Request ID"
|
|
83
122
|
option :format, type: :string, desc: "Output format (json only)"
|
|
123
|
+
option :mode, type: :string, desc: "ordinary-merge selects the read-only ordinary status"
|
|
124
|
+
option :reference, type: :string, desc: "Opaque ordinary merge reference"
|
|
125
|
+
option :queue_entry, type: :string, desc: "Original queue entry (ordinary merge)"
|
|
84
126
|
|
|
85
127
|
option :project, type: :string, desc: "Original project ID"
|
|
86
128
|
option :assignment, type: :string, desc: "Original assignment ID"
|
|
@@ -95,16 +137,117 @@ module Ace
|
|
|
95
137
|
|
|
96
138
|
def call(request:, **options)
|
|
97
139
|
reject_identity_flags!(options)
|
|
98
|
-
|
|
140
|
+
mode = options[:mode]
|
|
141
|
+
if mode && mode != Organisms::OrdinaryMergeRequest::MODE
|
|
142
|
+
return emit(Organisms::OrdinaryMergeRequest.refusal_envelope("ordinary_merge_invalid_request",
|
|
143
|
+
"unknown service mode", request_id: request, input_digest: nil,
|
|
144
|
+
schema: Ace::Assign::Atoms::FixedMergeSchemas::STATUS_ERROR_SCHEMA_ID))
|
|
145
|
+
end
|
|
146
|
+
if mode
|
|
147
|
+
ensure_json_format!(options)
|
|
148
|
+
begin
|
|
149
|
+
return emit(ordinary_producer.status(project: options[:project], assignment: options[:assignment],
|
|
150
|
+
attempt: options[:attempt], queue_entry: options[:queue_entry], reference: options[:reference],
|
|
151
|
+
request: request, input_digest: options[:input_digest], **options))
|
|
152
|
+
rescue Ace::Assign::AttemptErrors::EvidenceUnavailable, Ace::Lab::InvalidConfigurationError => e
|
|
153
|
+
return emit(Organisms::OrdinaryMergeRequest.refusal_envelope(
|
|
154
|
+
"ordinary_merge_unavailable", e.message, request_id: request, input_digest: nil,
|
|
155
|
+
schema: Ace::Assign::Atoms::FixedMergeSchemas::STATUS_ERROR_SCHEMA_ID
|
|
156
|
+
))
|
|
157
|
+
end
|
|
158
|
+
end
|
|
99
159
|
selected = protected_service.selected?(options)
|
|
100
160
|
if selected
|
|
101
161
|
return emit(protected_service.status(request_id: request, **options))
|
|
102
162
|
end
|
|
103
163
|
emit(service.status(request_id: request))
|
|
104
164
|
rescue ArgumentError, Ace::Assign::Error, Ace::Git::Error, Ace::Runtime::RuntimeUnavailableError, JSON::ParserError, SecurityError, KeyError, SystemCallError => error
|
|
105
|
-
raise if selected == false
|
|
165
|
+
raise if selected == false || mode
|
|
106
166
|
protected_refusal(error)
|
|
107
167
|
end
|
|
168
|
+
|
|
169
|
+
private
|
|
170
|
+
|
|
171
|
+
def ordinary_producer
|
|
172
|
+
@ordinary_producer ||= Organisms::OrdinaryMergeRequest.new
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# The ordinary receiver serve entrypoint (spec 8x3.t.xz9.4
|
|
177
|
+
# execution clauses; 8x3.t.xz9.5 integration handoff): binds the
|
|
178
|
+
# configured unix socket, mutually authenticates every connection
|
|
179
|
+
# through SO_PEERCRED, admits through the canonical Assign
|
|
180
|
+
# coordinator, executes the authorized fixed operation — one REAL
|
|
181
|
+
# Forgejo merge under the scoped host-installed service identity —
|
|
182
|
+
# and settles the exact terminal receipt proven by real forge
|
|
183
|
+
# readback. Configuration is one explicit deployment-owned file
|
|
184
|
+
# plus the host-installed authorization and forge-merge documents;
|
|
185
|
+
# the host owns their placement and credentials. Blocks until
|
|
186
|
+
# stopped.
|
|
187
|
+
class Listen < Ace::Support::Cli::Command
|
|
188
|
+
include Ace::Support::Cli::Base
|
|
189
|
+
include Output
|
|
190
|
+
|
|
191
|
+
desc "Serve the ordinary fixed merge receiver on its configured socket"
|
|
192
|
+
option :mode, type: :string, required: true,
|
|
193
|
+
desc: "ordinary-merge selects the ordinary fixed merge receiver"
|
|
194
|
+
option :project, type: :string, required: true, desc: "Project stable ID"
|
|
195
|
+
option :config, type: :string, required: true,
|
|
196
|
+
desc: "Deployment-owned receiver configuration file (YAML)"
|
|
197
|
+
|
|
198
|
+
def call(mode:, project:, config:, **options)
|
|
199
|
+
unless options.empty?
|
|
200
|
+
return emit(Organisms::OrdinaryMergeRequest.refusal_envelope(
|
|
201
|
+
"ordinary_merge_invalid_request",
|
|
202
|
+
"unknown listen selector: #{options.keys.sort.join(", ")}",
|
|
203
|
+
request_id: "unknown", input_digest: nil
|
|
204
|
+
))
|
|
205
|
+
end
|
|
206
|
+
unless mode == Organisms::OrdinaryMergeRequest::MODE
|
|
207
|
+
return emit(Organisms::OrdinaryMergeRequest.refusal_envelope(
|
|
208
|
+
"ordinary_merge_invalid_request", "unknown service mode",
|
|
209
|
+
request_id: "unknown", input_digest: nil
|
|
210
|
+
))
|
|
211
|
+
end
|
|
212
|
+
receiver_config = Molecules::OrdinaryReceiverConfig.load(config)
|
|
213
|
+
unless receiver_config.project == project
|
|
214
|
+
return emit(Organisms::OrdinaryMergeRequest.refusal_envelope(
|
|
215
|
+
"ordinary_merge_selection_mismatch",
|
|
216
|
+
"configured project does not match the requested project",
|
|
217
|
+
request_id: "unknown", input_digest: nil
|
|
218
|
+
))
|
|
219
|
+
end
|
|
220
|
+
policy_document = Molecules::GrantResolver.trusted_document(
|
|
221
|
+
receiver_config.policy_path
|
|
222
|
+
)
|
|
223
|
+
# The ONE canonical Assign journal: the coordinator binds the
|
|
224
|
+
# evidence ref of the canonical repository the receiver is
|
|
225
|
+
# installed for (config repo_path — the producer project's
|
|
226
|
+
# canonical checkout, the same authoritative journal the
|
|
227
|
+
# producer coordinator uses). Never an integration-checkout
|
|
228
|
+
# duplicate; the service identity's reviewed permissions are
|
|
229
|
+
# journal ref read/append, evidence checkout and no-effect
|
|
230
|
+
# attestation writes inside that repository.
|
|
231
|
+
coordinator = Ace::Assign::Organisms::AttemptCoordinator.new(
|
|
232
|
+
repo_root: receiver_config.repo_path
|
|
233
|
+
)
|
|
234
|
+
receiver = Organisms::OrdinaryMergeReceiver.new(
|
|
235
|
+
config: receiver_config, coordinator: coordinator,
|
|
236
|
+
policy_document: policy_document
|
|
237
|
+
)
|
|
238
|
+
listener = Molecules::OrdinaryListener.new(
|
|
239
|
+
socket_path: receiver_config.socket_path,
|
|
240
|
+
peer_uid: receiver_config.principal_uid,
|
|
241
|
+
handler: receiver
|
|
242
|
+
)
|
|
243
|
+
receiver.recover_pending!
|
|
244
|
+
listener.serve
|
|
245
|
+
rescue Ace::Lab::InvalidConfigurationError, Ace::Assign::AttemptErrors::EvidenceUnavailable => e
|
|
246
|
+
emit(Organisms::OrdinaryMergeRequest.refusal_envelope(
|
|
247
|
+
"ordinary_merge_unavailable", e.message,
|
|
248
|
+
request_id: "unknown", input_digest: nil
|
|
249
|
+
))
|
|
250
|
+
end
|
|
108
251
|
end
|
|
109
252
|
end
|
|
110
253
|
end
|
data/lib/ace/lab/cli.rb
CHANGED
|
@@ -26,7 +26,8 @@ module Ace
|
|
|
26
26
|
["resolve", "Resolve one lab entry by exact stable ID"],
|
|
27
27
|
["route", "Select a configured capable service in a project"],
|
|
28
28
|
["service request", "Request one authorized service operation"],
|
|
29
|
-
["service status", "Read a service request outcome"]
|
|
29
|
+
["service status", "Read a service request outcome"],
|
|
30
|
+
["service listen", "Serve the ordinary fixed merge receiver on its configured socket"]
|
|
30
31
|
].freeze
|
|
31
32
|
|
|
32
33
|
HELP_EXAMPLES = [
|
|
@@ -52,6 +53,7 @@ module Ace
|
|
|
52
53
|
register "route", CLI::Commands::Route.new
|
|
53
54
|
register "service request", CLI::Commands::Service::Request.new
|
|
54
55
|
register "service status", CLI::Commands::Service::Status.new
|
|
56
|
+
register "service listen", CLI::Commands::Service::Listen.new
|
|
55
57
|
|
|
56
58
|
# Register version command
|
|
57
59
|
version_cmd = Ace::Support::Cli::VersionCommand.build(
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "yaml"
|
|
4
|
+
require_relative "../errors"
|
|
5
|
+
require_relative "grant_resolver"
|
|
6
|
+
|
|
7
|
+
module Ace
|
|
8
|
+
module Lab
|
|
9
|
+
module Molecules
|
|
10
|
+
# The host-installed forge merge configuration for the ordinary merge
|
|
11
|
+
# receiver (spec 8x3.t.xz9.5 integration handoff). The scoped service
|
|
12
|
+
# identity that may merge pull requests is provisioned by the HOST in
|
|
13
|
+
# one root-owned file at a fixed path; this loader reads it through the
|
|
14
|
+
# same trusted-storage verification as the authorization grants and
|
|
15
|
+
# fails closed on anything else. An absent file is an immediate
|
|
16
|
+
# actionable refusal naming the path and its owner — never a silent
|
|
17
|
+
# local fallback and never an invented credential: a receiver without
|
|
18
|
+
# the host-installed identity cannot merge and must say so.
|
|
19
|
+
#
|
|
20
|
+
# Contract (host installs, root-owned 0640, service-readable):
|
|
21
|
+
#
|
|
22
|
+
# base_url: https://forgejo.example.net
|
|
23
|
+
# owner: cs3b
|
|
24
|
+
# repo: ace
|
|
25
|
+
# token: <scoped: PR read + PR merge + PR comment on that repo only>
|
|
26
|
+
# merge_timeout_seconds: 900
|
|
27
|
+
# escalation_owner: host-integrator
|
|
28
|
+
# review_attachment:
|
|
29
|
+
# enabled: true
|
|
30
|
+
class ForgeMergeConfig
|
|
31
|
+
DEFAULT_PATH = "/etc/lab/ace-lab/forge-merge.yml"
|
|
32
|
+
DEFAULT_ESCALATION_OWNER = "host-integrator"
|
|
33
|
+
KEYS = %w[base_url owner repo token merge_timeout_seconds escalation_owner
|
|
34
|
+
review_attachment].freeze
|
|
35
|
+
|
|
36
|
+
# @raise [Ace::Lab::InvalidConfigurationError] absent file ⇒ the
|
|
37
|
+
# actionable `config missing:` message naming the path and owner;
|
|
38
|
+
# every other trust/shape failure also fails closed.
|
|
39
|
+
def self.load(path = DEFAULT_PATH)
|
|
40
|
+
content = GrantResolver.read_verified(path)
|
|
41
|
+
unless content
|
|
42
|
+
raise Ace::Lab::InvalidConfigurationError,
|
|
43
|
+
"config missing: #{path} (owner: #{DEFAULT_ESCALATION_OWNER} — install the " \
|
|
44
|
+
"root-owned 0640 forge merge configuration for the scoped service identity)"
|
|
45
|
+
end
|
|
46
|
+
document = YAML.safe_load(content, permitted_classes: [Date], aliases: false)
|
|
47
|
+
new(document, source: path)
|
|
48
|
+
rescue Psych::Exception
|
|
49
|
+
raise Ace::Lab::InvalidConfigurationError,
|
|
50
|
+
"invalid lab configuration: forge merge configuration #{path} could not be parsed"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
attr_reader :base_url, :owner, :repo, :token, :merge_timeout_seconds, :escalation_owner,
|
|
54
|
+
:review_attachment_enabled, :source
|
|
55
|
+
|
|
56
|
+
def initialize(document, source: nil)
|
|
57
|
+
unless document.is_a?(Hash) && (document.keys - KEYS).empty? &&
|
|
58
|
+
(KEYS - document.keys).empty?
|
|
59
|
+
raise Ace::Lab::InvalidConfigurationError,
|
|
60
|
+
"forge merge configuration must contain exactly: #{KEYS.join(", ")}"
|
|
61
|
+
end
|
|
62
|
+
@source = source
|
|
63
|
+
@base_url = base_url!(document.fetch("base_url"))
|
|
64
|
+
@owner = name!(document.fetch("owner"), "owner")
|
|
65
|
+
@repo = name!(document.fetch("repo"), "repo")
|
|
66
|
+
@token = token!(document.fetch("token"))
|
|
67
|
+
@merge_timeout_seconds = timeout!(document.fetch("merge_timeout_seconds"))
|
|
68
|
+
@escalation_owner = name!(document.fetch("escalation_owner"), "escalation_owner")
|
|
69
|
+
attachment = document.fetch("review_attachment")
|
|
70
|
+
unless attachment.is_a?(Hash) && attachment.keys == %w[enabled] &&
|
|
71
|
+
[true, false].include?(attachment.fetch("enabled"))
|
|
72
|
+
raise Ace::Lab::InvalidConfigurationError,
|
|
73
|
+
"forge merge review_attachment must be exactly {enabled: true|false}"
|
|
74
|
+
end
|
|
75
|
+
@review_attachment_enabled = attachment.fetch("enabled")
|
|
76
|
+
freeze
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# The token is a live credential: never rendered, never logged.
|
|
80
|
+
def inspect
|
|
81
|
+
"#<#{self.class.name} base_url=#{@base_url} owner=#{@owner} repo=#{@repo} " \
|
|
82
|
+
"token=[REDACTED] merge_timeout_seconds=#{@merge_timeout_seconds} " \
|
|
83
|
+
"escalation_owner=#{@escalation_owner} " \
|
|
84
|
+
"review_attachment_enabled=#{@review_attachment_enabled}>"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
def base_url!(value)
|
|
90
|
+
uri = URI.parse(value.to_s)
|
|
91
|
+
unless uri.is_a?(URI::HTTPS) && uri.host && uri.path.empty? && uri.to_s == value
|
|
92
|
+
raise Ace::Lab::InvalidConfigurationError,
|
|
93
|
+
"forge merge base_url must be an https origin without path, query or fragment"
|
|
94
|
+
end
|
|
95
|
+
value
|
|
96
|
+
rescue URI::Error
|
|
97
|
+
raise Ace::Lab::InvalidConfigurationError,
|
|
98
|
+
"forge merge base_url must be an https origin without path, query or fragment"
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def name!(value, name)
|
|
102
|
+
unless value.is_a?(String) && !value.empty? && value.length <= 256 &&
|
|
103
|
+
value.match?(%r{\A[A-Za-z0-9._-]+\z})
|
|
104
|
+
raise Ace::Lab::InvalidConfigurationError, "forge merge #{name} is invalid"
|
|
105
|
+
end
|
|
106
|
+
value
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def token!(value)
|
|
110
|
+
unless value.is_a?(String) && value.length.between?(8, 512) &&
|
|
111
|
+
value.match?(%r{\A[A-Za-z0-9._~+/=-]+\z})
|
|
112
|
+
raise Ace::Lab::InvalidConfigurationError, "forge merge token is invalid"
|
|
113
|
+
end
|
|
114
|
+
value
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def timeout!(value)
|
|
118
|
+
unless value.is_a?(Integer) && value.positive? && value <= 86_400
|
|
119
|
+
raise Ace::Lab::InvalidConfigurationError,
|
|
120
|
+
"forge merge merge_timeout_seconds must be a positive integer"
|
|
121
|
+
end
|
|
122
|
+
value
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "ace/git/forgejo"
|
|
4
|
+
|
|
5
|
+
module Ace
|
|
6
|
+
module Lab
|
|
7
|
+
module Molecules
|
|
8
|
+
# The receiver's forge merge boundary (spec 8x3.t.xz9.5 integration
|
|
9
|
+
# handoff): a THIN delegation to the `ace-git-forgejo` provider, which
|
|
10
|
+
# owns every Forgejo API/PR/review/merge/readback responsibility —
|
|
11
|
+
# HTTP transport, authentication, payload shape, and failure
|
|
12
|
+
# classification live behind `Ace::Git::Forgejo::PullRequestApi` and
|
|
13
|
+
# its `HttpClient`. This molecule holds no HTTP stack of its own: it
|
|
14
|
+
# binds the host-installed scoped service identity from
|
|
15
|
+
# {ForgeMergeConfig} to a repository-scoped provider client and
|
|
16
|
+
# translates the provider's closed outcomes into the receiver's
|
|
17
|
+
# closed outcome set (`:invoked`/`:refused`/`:ambiguous`/`Unavailable`).
|
|
18
|
+
#
|
|
19
|
+
# The receiver's one authorized effect is a real pull request merge on
|
|
20
|
+
# the real forge, invoked under the scoped service identity, and every
|
|
21
|
+
# terminal outcome is proven by a real readback — a local git effect is
|
|
22
|
+
# never presented as a forge result.
|
|
23
|
+
#
|
|
24
|
+
# Outcome translation (provider closed world → receiver closed world):
|
|
25
|
+
#
|
|
26
|
+
# - `2xx` mutation outcome → `:invoked`; a provider refusal outcome
|
|
27
|
+
# (404/405/409/422 — including the server-side exact-head refusal
|
|
28
|
+
# for a moved head) → `:refused`; an authentication error (the
|
|
29
|
+
# provider raises the shared taxonomy for 401/403) → `:refused` —
|
|
30
|
+
# a definitive refusal can never have merged.
|
|
31
|
+
# - An unknown mutation outcome (5xx responses and transport failures
|
|
32
|
+
# on the POST — the forge may or may not have processed it) →
|
|
33
|
+
# `:ambiguous`; the receiver reconciles by readback, never by
|
|
34
|
+
# repeating the merge.
|
|
35
|
+
# - Every unverifiable read outcome (unreachable forge, malformed
|
|
36
|
+
# evidence, misrouted payload, unusable endpoint) raises
|
|
37
|
+
# `Unavailable`, because the true state cannot be proven. The token
|
|
38
|
+
# is never rendered in any error (provider-sanitized messages only).
|
|
39
|
+
#
|
|
40
|
+
# The exact-head contract is carried by the provider's native merge
|
|
41
|
+
# signature: the POST body binds `head_commit_id` to the approved
|
|
42
|
+
# candidate server-side, so a race between the state readback and the
|
|
43
|
+
# merge POST can never merge an unreviewed head. This molecule never
|
|
44
|
+
# substitutes another merge strategy and validates the binding before
|
|
45
|
+
# the provider is constructed.
|
|
46
|
+
class ForgejoMergeAdapter
|
|
47
|
+
# The single authorized merge strategy on the wire.
|
|
48
|
+
MERGE_METHOD = "fast-forward-only"
|
|
49
|
+
|
|
50
|
+
class Unavailable < ::StandardError; end
|
|
51
|
+
|
|
52
|
+
# outcome: :invoked | :refused | :ambiguous; status: Integer|nil;
|
|
53
|
+
# reason: closed refuse/ambiguity detail (token-free).
|
|
54
|
+
Result = Struct.new(:outcome, :status, :reason, keyword_init: true)
|
|
55
|
+
|
|
56
|
+
def initialize(base_url:, token:, timeout_seconds: 900)
|
|
57
|
+
@base_url = base_url.to_s.sub(%r{/+\z}, "")
|
|
58
|
+
@token = token
|
|
59
|
+
@timeout_seconds = timeout_seconds
|
|
60
|
+
freeze
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Invoke the eligible merge bound to the approved candidate head.
|
|
64
|
+
# `head_commit_id` is required and validated (full 40-character hex
|
|
65
|
+
# sha) BEFORE any provider construction: the forge server-side
|
|
66
|
+
# refuses to merge any head other than the bound one. Returns a
|
|
67
|
+
# Result; never raises for HTTP outcomes (ambiguity is a result, not
|
|
68
|
+
# an exception).
|
|
69
|
+
def merge_pull_request!(owner:, repo:, index:, head_commit_id:)
|
|
70
|
+
unless head_commit_id.is_a?(String) && head_commit_id.match?(/\A[0-9a-f]{40}\z/)
|
|
71
|
+
raise ArgumentError,
|
|
72
|
+
"head_commit_id must be a full 40-character lowercase hex sha " \
|
|
73
|
+
"(got: #{head_commit_id.inspect})"
|
|
74
|
+
end
|
|
75
|
+
translate_mutation do
|
|
76
|
+
provider(owner, repo).merge_pull_request(index,
|
|
77
|
+
do_method: MERGE_METHOD, head_commit_id: head_commit_id)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# The PR state readback, normalized to the receiver's closed
|
|
82
|
+
# PR-state shape (`merged`, `merge_commit_sha`, head/base shas) or
|
|
83
|
+
# nil when the forge definitively reports the PR absent (404 — the
|
|
84
|
+
# provider raises the absence taxonomy). Raises Unavailable for
|
|
85
|
+
# every unverifiable outcome.
|
|
86
|
+
def pull_request(owner:, repo:, index:)
|
|
87
|
+
payload = provider(owner, repo).pull_request(index)
|
|
88
|
+
{
|
|
89
|
+
"merged" => payload["merged"] == true,
|
|
90
|
+
"merge_commit_sha" => payload["merge_commit_sha"].is_a?(String) ?
|
|
91
|
+
payload["merge_commit_sha"] : nil,
|
|
92
|
+
"head" => {"sha" => payload.dig("head", "sha").is_a?(String) ?
|
|
93
|
+
payload.dig("head", "sha") : nil},
|
|
94
|
+
"base" => {"sha" => payload.dig("base", "sha").is_a?(String) ?
|
|
95
|
+
payload.dig("base", "sha") : nil}
|
|
96
|
+
}
|
|
97
|
+
rescue Ace::Git::ProviderObjectNotFoundError
|
|
98
|
+
nil
|
|
99
|
+
rescue Ace::Git::Error => e
|
|
100
|
+
raise Unavailable, e.message
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Attach one comment to the PR (the independent final-head review
|
|
104
|
+
# body handed over by the request — never the executor's own
|
|
105
|
+
# approval).
|
|
106
|
+
def create_comment(owner:, repo:, index:, body:)
|
|
107
|
+
translate_mutation do
|
|
108
|
+
provider(owner, repo).create_comment(index, body)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
private
|
|
113
|
+
|
|
114
|
+
# One repository-scoped provider client per exchange: the origin is
|
|
115
|
+
# narrowed with the forge identity this receiver already pinned
|
|
116
|
+
# against the host-installed configuration, and the scoped token
|
|
117
|
+
# rides the provider transport instead of any local credential.
|
|
118
|
+
def provider(owner, repo)
|
|
119
|
+
Ace::Git::Forgejo::PullRequestApi.new(
|
|
120
|
+
server: Ace::Git::ResolvedServer.new(name: "lab-forge-merge",
|
|
121
|
+
provider: :forgejo, url: "#{@base_url}/#{owner}/#{repo}"),
|
|
122
|
+
timeout: @timeout_seconds, token: @token
|
|
123
|
+
)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Closed mutation translation: the provider returns an outcome only
|
|
127
|
+
# for statuses whose meaning is endpoint-specific (2xx success and
|
|
128
|
+
# the refusal family); everything else it raises as the shared
|
|
129
|
+
# taxonomy, which maps to :refused (authentication — a definitive
|
|
130
|
+
# refusal), :ambiguous (unknown outcome), or Unavailable (a read
|
|
131
|
+
# classified as unreachable).
|
|
132
|
+
def translate_mutation
|
|
133
|
+
outcome = yield
|
|
134
|
+
if (200..299).cover?(outcome.status)
|
|
135
|
+
Result.new(outcome: :invoked, status: outcome.status, reason: nil)
|
|
136
|
+
else
|
|
137
|
+
Result.new(outcome: :refused, status: outcome.status,
|
|
138
|
+
reason: outcome.message || "HTTP #{outcome.status}")
|
|
139
|
+
end
|
|
140
|
+
rescue Ace::Git::ProviderAuthenticationError => e
|
|
141
|
+
Result.new(outcome: :refused, status: nil, reason: e.message)
|
|
142
|
+
rescue Ace::Git::ProviderUnknownOutcomeError => e
|
|
143
|
+
Result.new(outcome: :ambiguous, status: nil, reason: e.message)
|
|
144
|
+
rescue Ace::Git::Error => e
|
|
145
|
+
raise Unavailable, e.message
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
@@ -64,19 +64,13 @@ module Ace
|
|
|
64
64
|
parse_grants(content, trusted_path)
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
# Read the grants document only after proving the deployment owns
|
|
76
|
-
# the storage along the original path. Genuine absence is nil
|
|
77
|
-
# (nobody authorized); every other filesystem failure — including
|
|
78
|
-
# races between lstat and open — classifies fail-closed
|
|
79
|
-
# (review rounds 6-7, F2).
|
|
67
|
+
# Read a deployment-owned file only after proving the deployment
|
|
68
|
+
# owns the storage along the original path (same trust rules as
|
|
69
|
+
# `resolve`). Genuine absence is nil; every other filesystem
|
|
70
|
+
# failure — including races between lstat and open — classifies
|
|
71
|
+
# fail-closed (review rounds 6-7, F2). Public so other trusted
|
|
72
|
+
# host-installed documents (e.g. the forge merge service identity)
|
|
73
|
+
# read through the same verification.
|
|
80
74
|
# @return [String, nil] file content, or nil when absent
|
|
81
75
|
def read_verified(path)
|
|
82
76
|
candidate = begin
|
|
@@ -104,6 +98,14 @@ module Ace
|
|
|
104
98
|
end
|
|
105
99
|
end
|
|
106
100
|
|
|
101
|
+
private
|
|
102
|
+
|
|
103
|
+
def verify_error(path)
|
|
104
|
+
"invalid lab configuration: trusted authorization file #{path} failed the deployment " \
|
|
105
|
+
"ownership verification or could not be read; failing closed " \
|
|
106
|
+
"(required: every traversed element root-owned and not group/world-writable)"
|
|
107
|
+
end
|
|
108
|
+
|
|
107
109
|
# Walk the ORIGINAL path component by component. Symlinks are
|
|
108
110
|
# followed only when the link itself is root-owned (a caller-writable
|
|
109
111
|
# redirect is rejected); symlink permission bits are ignored because
|