fix: separate run builders from generated workers

This commit is contained in:
npc0-hue
2026-07-28 11:05:38 +08:00
parent 2ae27bb746
commit e739dd9c79
10 changed files with 257 additions and 1 deletions
+67 -1
View File
@@ -172,7 +172,7 @@ func TestCoreServiceRunHelloRejectsStalePackageKeyAfterReset(t *testing.T) {
}
pkg := readGeneratedPackageConfig(t, svc, session, distribution.ArtifactID)
hello := validRunControlHello()
hello.RunEndpointID = instance.RunEndpointID
hello.RunEndpointID = distribution.RunEndpointID
hello.RegistrationToken = pkg.AuthKey
hello.ServerInstanceID = instance.ID
hello.PluginID = instance.PluginID
@@ -202,6 +202,72 @@ func TestCoreServiceRunHelloRejectsStalePackageKeyAfterReset(t *testing.T) {
}
}
func TestCoreServiceRunHelloRejectsGeneratedRunOnPromotedBuildEndpoint(t *testing.T) {
svc, session, instance := newDistributionTestFixture(t)
builderID := instance.RunEndpointID
instance.State = domain.ServerInstanceStateFailed
if err := svc.store.ServerInstances().Update(instance); err != nil {
t.Fatalf("mark legacy server failed: %v", err)
}
if _, err := svc.GenerateRunDistributionForSession(session, domain.RunDistributionGenerateRequest{ServerInstanceID: instance.ID, TargetOS: "windows", TargetArch: "amd64", IdempotencyKey: "promoted-hello-fence"}); err != nil {
t.Fatalf("generate promoted Run: %v", err)
}
migrated, err := svc.GetServerInstance(instance.ID)
if err != nil {
t.Fatalf("get migrated server: %v", err)
}
key, plainKey, err := svc.ensureActiveComponentKey(instance.ID, domain.DistributionComponentRun, "")
if err != nil {
t.Fatalf("get component key: %v", err)
}
hello := validRunControlHello()
hello.RunEndpointID = builderID
hello.RegistrationToken = plainKey
hello.ServerInstanceID = instance.ID
hello.PluginID = instance.PluginID
hello.ComponentKind = domain.DistributionComponentRun
hello.KeyGeneration = key.Generation
if _, err := svc.RegisterRunHello(hello); err == nil || !strings.Contains(err.Error(), "does not match") {
t.Fatalf("expected shared builder registration rejection, got %v", err)
}
hello.RunEndpointID = migrated.RunEndpointID
if result, err := svc.RegisterRunHello(hello); err != nil || !result.Accepted {
t.Fatalf("expected dedicated Run registration acceptance, result=%+v err=%v", result, err)
}
}
func TestCoreServiceComponentRunCannotClaimDistributionBuild(t *testing.T) {
svc, session, instance := newDistributionTestFixture(t)
distribution, err := svc.GenerateRunDistributionForSession(session, domain.RunDistributionGenerateRequest{ServerInstanceID: instance.ID, TargetOS: "windows", TargetArch: "amd64", IdempotencyKey: "component-build-claim"})
if err != nil {
t.Fatalf("generate legacy Run: %v", err)
}
packageConfig := readGeneratedPackageConfig(t, svc, session, distribution.ArtifactID)
hello := validRunControlHello()
hello.RunEndpointID = instance.RunEndpointID
hello.RegistrationToken = packageConfig.AuthKey
hello.ServerInstanceID = instance.ID
hello.PluginID = instance.PluginID
hello.ComponentKind = domain.DistributionComponentRun
hello.KeyGeneration = packageConfig.KeyGeneration
registered, err := svc.RegisterRunHello(hello)
if err != nil || !registered.Accepted {
t.Fatalf("register legacy package: result=%+v err=%v", registered, err)
}
storedSession, err := svc.store.RunControlSessions().Get(instance.RunEndpointID)
if err != nil || !storedSession.RequireSignedRequests {
t.Fatalf("expected component session to require signatures, session=%+v err=%v", storedSession, err)
}
if activeSession := svc.runSessions[instance.RunEndpointID]; !activeSession.RequireSignedRequests {
t.Fatalf("expected in-memory component session to require signatures, session=%+v", activeSession)
}
claim, err := svc.ClaimRunJob(domain.RunJobClaim{RunEndpointID: instance.RunEndpointID, SessionToken: registered.SessionToken, Capabilities: []string{domain.JobCapabilityDistributionBuild}, Capacity: domain.RunCapacity{MaxJobs: 1}})
if err != nil || claim.HasJob {
t.Fatalf("component Run must not claim distribution builds: claim=%+v err=%v", claim, err)
}
}
func TestCoreServiceRequestsCapabilityRefreshOnFingerprintDrift(t *testing.T) {
svc := newTestCoreService()
hello, err := svc.RegisterRunHello(validRunControlHello())