Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions experiments/g01-scaleset/livecanary/ack_command_fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (f *ackCommandFixture) brokerWire(r *http.Request) {
v3 := f.base.a.GroupPolicy.Version == 2
primary := []string{"GET " + workflowRunFixturePath(f.transport), "GET /app", "GET /orgs/fixture-org/installation", "GET " + workflowRunFixturePath(f.transport), "POST /app/installations/12/access_tokens", "GET /installation/repositories", "GET /repos/fixture-org/canary", "GET /orgs/fixture-org/actions/runner-groups/3", "GET /orgs/fixture-org/actions/runner-groups/3/repositories"}
if v3 {
primary = []string{"GET " + workflowRunFixturePath(f.transport), "GET /app", "GET /orgs/fixture-org/installation", "POST /app/installations/12/access_tokens", "GET /installation/repositories", "GET /repos/fixture-org/canary", "GET /orgs/fixture-org/actions/runner-groups/3", "GET /orgs/fixture-org/actions/runner-groups/3/repositories", "DELETE /installation/token", "GET " + workflowRunFixturePath(f.transport), "POST /app/installations/12/access_tokens", "GET /installation/repositories", "GET /repos/fixture-org/canary", "GET /orgs/fixture-org/actions/runner-groups/3", "GET /orgs/fixture-org/actions/runner-groups/3/repositories", "GET " + workflowRunFixturePath(f.transport)}
primary = []string{"GET " + workflowRunFixturePath(f.transport), "GET /app", "GET /orgs/fixture-org/installation", "POST /app/installations/12/access_tokens", "GET /installation/repositories", "GET /repos/fixture-org/canary", "GET /orgs/fixture-org/actions/runner-groups/3", "GET /orgs/fixture-org/actions/runner-groups/3/repositories", "DELETE /installation/token", "GET " + workflowRunFixturePath(f.transport), "POST /app/installations/12/access_tokens", "GET /installation/repositories", "GET /repos/fixture-org/canary", "GET /orgs/fixture-org/actions/runner-groups/3", "GET /orgs/fixture-org/actions/runner-groups/3/repositories", "GET " + workflowRunFixturePath(f.transport), "DELETE /installation/token"}
}
position := len(f.brokerAttempts) - 1 // shared lock held; already counted before drain
fresh := f.transport.attempt == f.attempt+"-fresh"
Expand Down Expand Up @@ -359,6 +359,9 @@ func (f *ackCommandFixture) brokerWire(r *http.Request) {
token = "synthetic-process-read-installation-token"
} else if v3 && r.URL.Path == "/installation/token" {
token = "synthetic-process-read-installation-token"
if position == len(primary)-1 {
token = "synthetic-process-installation-token"
}
}
if auth != "Bearer "+token {
t.Error("ACK broker distinct observation/verification/installation authority differs")
Expand Down Expand Up @@ -602,7 +605,7 @@ func (f *ackCommandFixture) assertBroker() {
want := []string{"GET " + workflowRunFixturePath(f.transport), "GET /app", "GET /orgs/fixture-org/installation", "GET " + workflowRunFixturePath(f.transport), "POST /app/installations/12/access_tokens", "GET /installation/repositories", "GET /repos/fixture-org/canary", "GET /orgs/fixture-org/actions/runner-groups/3", "GET /orgs/fixture-org/actions/runner-groups/3/repositories"}
v3 := f.base.a.GroupPolicy.Version == 2
if v3 {
want = []string{"GET " + workflowRunFixturePath(f.transport), "GET /app", "GET /orgs/fixture-org/installation", "POST /app/installations/12/access_tokens", "GET /installation/repositories", "GET /repos/fixture-org/canary", "GET /orgs/fixture-org/actions/runner-groups/3", "GET /orgs/fixture-org/actions/runner-groups/3/repositories", "DELETE /installation/token", "GET " + workflowRunFixturePath(f.transport), "POST /app/installations/12/access_tokens", "GET /installation/repositories", "GET /repos/fixture-org/canary", "GET /orgs/fixture-org/actions/runner-groups/3", "GET /orgs/fixture-org/actions/runner-groups/3/repositories", "GET " + workflowRunFixturePath(f.transport)}
want = []string{"GET " + workflowRunFixturePath(f.transport), "GET /app", "GET /orgs/fixture-org/installation", "POST /app/installations/12/access_tokens", "GET /installation/repositories", "GET /repos/fixture-org/canary", "GET /orgs/fixture-org/actions/runner-groups/3", "GET /orgs/fixture-org/actions/runner-groups/3/repositories", "DELETE /installation/token", "GET " + workflowRunFixturePath(f.transport), "POST /app/installations/12/access_tokens", "GET /installation/repositories", "GET /repos/fixture-org/canary", "GET /orgs/fixture-org/actions/runner-groups/3", "GET /orgs/fixture-org/actions/runner-groups/3/repositories", "GET " + workflowRunFixturePath(f.transport), "DELETE /installation/token"}
}
if !reflect.DeepEqual(f.brokerAttempts, f.transport.calls) {
f.t.Error("ACK broker server-entry counts differ from dispatched calls")
Expand All @@ -611,7 +614,7 @@ func (f *ackCommandFixture) assertBroker() {
f.t.Errorf("ACK actual broker exact trace differs: calls=%v want=%v", f.transport.calls, want)
}
if v3 {
if f.transport.mints != 2 || f.transport.readOnlyMints != 1 || f.transport.managementMints != 1 || f.transport.revocations != 1 {
if f.transport.mints != 2 || f.transport.readOnlyMints != 1 || f.transport.managementMints != 1 || f.transport.revocations != 2 || f.transport.readOnlyRevocations != 1 || f.transport.managementRevocations != 1 {
f.t.Errorf("ACK actual broker issuance lifecycle differs: mints=%d read-only=%d management=%d revocations=%d", f.transport.mints, f.transport.readOnlyMints, f.transport.managementMints, f.transport.revocations)
}
} else if f.transport.mints != 1 {
Expand Down Expand Up @@ -670,11 +673,11 @@ func (f *ackCommandFixture) assertBroker() {
f.t.Errorf("ACK workflow provenance lifecycle events=%d, want none or a start/confirmation pair", workflowEvents)
}
if v3 {
wantLedger += 2 // read-token lifecycle start and confirmation surround completion.
wantLedger += 4 // read and management lifecycle starts and confirmations surround completion.
}
completionIndex := claimIndex + 1
if v3 {
completionIndex += 2
completionIndex += 4
}
if len(ledger) != wantLedger || claimIndex >= len(ledger) {
f.t.Errorf("ACK exact broker claim/completion count differs: events=%d want=%d claim-index=%d", len(ledger), wantLedger, claimIndex)
Expand Down Expand Up @@ -707,6 +710,10 @@ func (f *ackCommandFixture) assertBroker() {
if json.Unmarshal(ledger[readTokenStartIndex], &started) != nil || json.Unmarshal(ledger[readTokenStartIndex+1], &confirmed) != nil || started.Kind != "read_token_lifecycle_started" || confirmed.Kind != "read_token_lifecycle_confirmed" || started.Slot != claimIdentity.Slot || confirmed.Slot != claimIdentity.Slot || !bytes.Equal(started.Attempt, claimIdentity.Attempt) || !bytes.Equal(started.Journal, claimIdentity.Journal) || !bytes.Equal(confirmed.Attempt, claimIdentity.Attempt) || !bytes.Equal(confirmed.Journal, claimIdentity.Journal) {
f.t.Error("ACK read-token lifecycle claim identity differs")
}
managementTokenStartIndex := claimIndex + 3
if json.Unmarshal(ledger[managementTokenStartIndex], &started) != nil || json.Unmarshal(ledger[managementTokenStartIndex+1], &confirmed) != nil || started.Kind != "management_token_lifecycle_started" || confirmed.Kind != "management_token_lifecycle_confirmed" || started.Slot != claimIdentity.Slot || confirmed.Slot != claimIdentity.Slot || !bytes.Equal(started.Attempt, claimIdentity.Attempt) || !bytes.Equal(started.Journal, claimIdentity.Journal) || !bytes.Equal(confirmed.Attempt, claimIdentity.Attempt) || !bytes.Equal(confirmed.Journal, claimIdentity.Journal) {
f.t.Error("ACK management-token lifecycle claim identity differs")
}
}
if wantComplete == 1 {
var claim, completion map[string]any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,11 @@ func newCommandQualificationFixture(t *testing.T, controller, broker, variant, p
if os.WriteFile(f.brokerApprovalPath, raw, 0600) != nil {
t.Fatal("broker approval write")
}
f.transport = &processBrokerHTTP{t: t, attempt: f.attempt, approval: &f.base.a}
verificationAuthorization := "Bearer " + f.base.api.credentials.VerificationToken
f.transport = &processBrokerHTTP{
t: t, attempt: f.attempt, approval: &f.base.a,
expectedWorkflowAuthorizations: []string{"Bearer synthetic-observation-credential", verificationAuthorization, verificationAuthorization},
}
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
f.brokerMu.Lock()
defer f.brokerMu.Unlock()
Expand Down Expand Up @@ -791,8 +795,9 @@ func (f *acquireLossCommandFixture) guardControlsForPhase(events []Event, phase
f.brokerMu.Lock()
replayCalls, replayMints := len(f.transport.calls), f.transport.mints
replayReadOnlyMints, replayManagementMints, replayRevocations := f.transport.readOnlyMints, f.transport.managementMints, f.transport.revocations
replayReadOnlyRevocations, replayManagementRevocations := f.transport.readOnlyRevocations, f.transport.managementRevocations
f.brokerMu.Unlock()
if !bytes.Equal(brokerBefore, brokerAfter) || replayCalls != originalCalls || replayMints != 2 || replayReadOnlyMints != 1 || replayManagementMints != 1 || replayRevocations != 1 {
if !bytes.Equal(brokerBefore, brokerAfter) || replayCalls != originalCalls || replayMints != 2 || replayReadOnlyMints != 1 || replayManagementMints != 1 || replayRevocations != 2 || replayReadOnlyRevocations != 1 || replayManagementRevocations != 1 {
t.Error("exact broker-attempt replay changed history or crossed API/mint boundary")
}
claimPath := filepath.Join(f.admission, "broker-admission.jsonl")
Expand Down Expand Up @@ -845,6 +850,8 @@ func (f *acquireLossCommandFixture) guardControlsForPhase(events []Event, phase
readOnlyMintsBefore := f.transport.readOnlyMints
managementMintsBefore := f.transport.managementMints
revocationsBefore := f.transport.revocations
readOnlyRevocationsBefore := f.transport.readOnlyRevocations
managementRevocationsBefore := f.transport.managementRevocations
f.transport.attempt = fresh
f.brokerMu.Unlock()
f.run(f.broker, f.brokerArgs(fresh), inputs...)
Expand All @@ -854,12 +861,14 @@ func (f *acquireLossCommandFixture) guardControlsForPhase(events []Event, phase
readOnlyMintsAfter := f.transport.readOnlyMints
managementMintsAfter := f.transport.managementMints
revocationsAfter := f.transport.revocations
readOnlyRevocationsAfter := f.transport.readOnlyRevocations
managementRevocationsAfter := f.transport.managementRevocations
f.brokerMu.Unlock()
wantCalls := []string{"GET " + workflowRunFixturePath(f.transport)}
if workflowGETAccounted {
wantCalls = nil
}
if !reflect.DeepEqual(calls, wantCalls) || mintsAfter != mintsBefore || readOnlyMintsAfter != readOnlyMintsBefore || managementMintsAfter != managementMintsBefore || revocationsAfter != revocationsBefore {
if !reflect.DeepEqual(calls, wantCalls) || mintsAfter != mintsBefore || readOnlyMintsAfter != readOnlyMintsBefore || managementMintsAfter != managementMintsBefore || revocationsAfter != revocationsBefore || readOnlyRevocationsAfter != readOnlyRevocationsBefore || managementRevocationsAfter != managementRevocationsBefore {
t.Error("fresh occupied-phase broker attempt crossed the expected provider or token boundary")
}
snapshotPath := filepath.Join(fresh, "controller-approval.json")
Expand Down Expand Up @@ -900,12 +909,14 @@ func TestExperimentalAcquireLossCommand(t *testing.T) {
managementMints := f.transport.managementMints
readOnlyMints := f.transport.readOnlyMints
revocations := f.transport.revocations
readOnlyRevocations := f.transport.readOnlyRevocations
managementRevocations := f.transport.managementRevocations
calls := append([]string(nil), f.transport.calls...)
f.brokerMu.Unlock()
if managementMints != 1 {
t.Fatalf("actual broker management issuance did not mint exactly once: total=%d read-only=%d management=%d revocations=%d calls=%v", mints, readOnlyMints, managementMints, revocations, calls)
}
if mints != 2 || readOnlyMints != 1 || revocations != 1 {
if mints != 2 || readOnlyMints != 1 || revocations != 2 || readOnlyRevocations != 1 || managementRevocations != 1 {
t.Fatalf("actual broker issuance lifecycle differs: total=%d read-only=%d management=%d revocations=%d calls=%v", mints, readOnlyMints, managementMints, revocations, calls)
}
events := f.assertRetained(variant)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

"github.com/1XP-AI/gh-runnerd/experiments/g01-scaleset/liveworker"
"github.com/1XP-AI/gh-runnerd/experiments/g02-auth/handoff"
)

const pairFixtureJIT = "c3ludGhldGljLXByaXZhdGUtaml0LWNvbmZpZw=="
Expand All @@ -39,10 +40,11 @@ type pairedIntegrationFixture struct {
}

type pairedFixtureConfiguration struct {
controllerCreate func(*FileJournal, Approval)
workerPhases []string
controllerPhases []string
controllerResponse func(string, any) any
controllerCreate func(*FileJournal, Approval)
controllerGroupPolicy *handoff.GroupPolicy
workerPhases []string
controllerPhases []string
controllerResponse func(string, any) any
}

func newPairedIntegrationFixture(t *testing.T) *pairedIntegrationFixture {
Expand All @@ -52,6 +54,9 @@ func newPairedIntegrationFixtureConfigured(t *testing.T, config *pairedFixtureCo
t.Helper()
f := &pairedIntegrationFixture{}
a := approval()
if config != nil && config.controllerGroupPolicy != nil {
a.GroupPolicy = *config.controllerGroupPolicy
}
if config != nil && config.controllerPhases != nil {
a.Phases = append([]string(nil), config.controllerPhases...)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"testing"

"github.com/1XP-AI/gh-runnerd/experiments/g01-scaleset/liveworker"
"github.com/1XP-AI/gh-runnerd/experiments/g02-auth/handoff"
)

type terminalFixture struct {
Expand Down Expand Up @@ -46,6 +47,10 @@ func newTerminalFixtureWithControllerPhases(t *testing.T, phases, controllerPhas
return newTerminalFixtureWithCreate(t, phases, controllerPhases, nil)
}
func newTerminalFixtureWithCreate(t *testing.T, phases, controllerPhases []string, create func(*FileJournal, Approval)) *terminalFixture {
return newTerminalFixtureWithControllerGroupPolicy(t, phases, controllerPhases, create, nil)
}

func newTerminalFixtureWithControllerGroupPolicy(t *testing.T, phases, controllerPhases []string, create func(*FileJournal, Approval), groupPolicy *handoff.GroupPolicy) *terminalFixture {
t.Helper()
f := &terminalFixture{setETag: `"fixture-v1"`}
config := &pairedFixtureConfiguration{controllerResponse: func(stage string, value any) any {
Expand All @@ -61,6 +66,7 @@ func newTerminalFixtureWithCreate(t *testing.T, phases, controllerPhases []strin
}
return value
}}
config.controllerGroupPolicy = groupPolicy
config.controllerCreate = create
config.workerPhases = phases
config.controllerPhases = controllerPhases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func observedHandoffInputs(t *testing.T, f controllerHandoffFixture) (enrollment
grant := enrollment.WorkflowGrantForFixture{Request: request, OrganizationID: 101, RepositoryID: f.approval.RepositoryID, ExpiresAt: f.now.Add(time.Hour)}
repo := enrollment.WorkflowRepositoryForFixture{ID: grant.RepositoryID, FullName: request.Repository, Private: true}
repo.Owner.ID, repo.Owner.Login = grant.OrganizationID, f.approval.Organization
run := enrollment.WorkflowRunForFixture{ID: request.WorkflowRunID, HeadSHA: request.WorkflowSHA, HeadBranch: "main", Event: "workflow_dispatch", Path: request.WorkflowPath, RunAttempt: 1, Repository: repo, HeadRepository: repo}
run := enrollment.WorkflowRunForFixture{ID: request.WorkflowRunID, HeadSHA: request.WorkflowSHA, HeadBranch: "main", Event: "workflow_dispatch", Status: "in_progress", Path: request.WorkflowPath, RunAttempt: 1, Repository: repo, HeadRepository: repo}
return grant, run
}

Expand Down
Loading