feat(batch): add live reuse admin verification flow
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
)
|
||||
|
||||
type ReuseInput struct {
|
||||
ProviderMatched bool
|
||||
ProviderID string
|
||||
CanonicalModelFamilies []string
|
||||
MatchedAccountID int64
|
||||
@@ -36,7 +37,7 @@ func DecideReuse(input ReuseInput) ReuseDecision {
|
||||
decision.MatchedAccountState = MatchedAccountStateNone
|
||||
}
|
||||
|
||||
if !sameProvider(input.ProviderID, input.ExistingProviderID) || !decision.FamilyCovered {
|
||||
if !providerMatched(input) || !decision.FamilyCovered {
|
||||
return decision
|
||||
}
|
||||
|
||||
@@ -93,3 +94,10 @@ func canonicalFamiliesCovered(requested []string, existing []string) bool {
|
||||
func sameProvider(left, right string) bool {
|
||||
return strings.TrimSpace(left) != "" && strings.TrimSpace(left) == strings.TrimSpace(right)
|
||||
}
|
||||
|
||||
func providerMatched(input ReuseInput) bool {
|
||||
if input.ProviderMatched {
|
||||
return true
|
||||
}
|
||||
return sameProvider(input.ProviderID, input.ExistingProviderID)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ func TestDecideReuse(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
decision := DecideReuse(ReuseInput{
|
||||
ProviderMatched: true,
|
||||
ProviderID: "api-deepseek-12345678",
|
||||
CanonicalModelFamilies: []string{"kimi-k2.6"},
|
||||
MatchedAccountID: 101,
|
||||
@@ -38,6 +39,7 @@ func TestDecideReuse(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
decision := DecideReuse(ReuseInput{
|
||||
ProviderMatched: true,
|
||||
ProviderID: "api-kimi-12345678",
|
||||
CanonicalModelFamilies: []string{"kimi-k2.6"},
|
||||
MatchedAccountID: 202,
|
||||
@@ -61,6 +63,7 @@ func TestDecideReuse(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
brokenProvider := DecideReuse(ReuseInput{
|
||||
ProviderMatched: true,
|
||||
ProviderID: "api-deepseek-12345678",
|
||||
CanonicalModelFamilies: []string{"deepseek-v4-pro"},
|
||||
MatchedAccountState: MatchedAccountStateActive,
|
||||
@@ -76,6 +79,7 @@ func TestDecideReuse(t *testing.T) {
|
||||
}
|
||||
|
||||
brokenAccount := DecideReuse(ReuseInput{
|
||||
ProviderMatched: true,
|
||||
ProviderID: "api-deepseek-12345678",
|
||||
CanonicalModelFamilies: []string{"deepseek-v4-pro"},
|
||||
MatchedAccountState: MatchedAccountStateBroken,
|
||||
@@ -95,6 +99,7 @@ func TestDecideReuse(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
decision := DecideReuse(ReuseInput{
|
||||
ProviderMatched: true,
|
||||
ProviderID: "api-kimi-12345678",
|
||||
CanonicalModelFamilies: []string{"kimi-k2.6"},
|
||||
MatchedAccountState: MatchedAccountStateActive,
|
||||
@@ -110,4 +115,26 @@ func TestDecideReuse(t *testing.T) {
|
||||
t.Fatal("FamilyCovered = false, want true")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("base url matched legacy provider is reused even when provider ids differ", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
decision := DecideReuse(ReuseInput{
|
||||
ProviderMatched: true,
|
||||
ProviderID: "api-53hk-42797c06",
|
||||
CanonicalModelFamilies: []string{"minimax-m2.7-highspeed"},
|
||||
MatchedAccountID: 101,
|
||||
MatchedAccountState: MatchedAccountStateActive,
|
||||
ExistingProviderID: "minimax-53hk",
|
||||
ExistingAccessStatus: AccessStatusActive,
|
||||
ExistingCanonicalFamilys: []string{"minimax-m2.5-highspeed", "minimax-m2.7-highspeed"},
|
||||
})
|
||||
|
||||
if !decision.ProvisionReused {
|
||||
t.Fatal("ProvisionReused = false, want true")
|
||||
}
|
||||
if decision.AccountResolution != AccountResolutionReused {
|
||||
t.Fatalf("AccountResolution = %q, want %q", decision.AccountResolution, AccountResolutionReused)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -53,12 +53,14 @@ type ReuseLookupInput struct {
|
||||
}
|
||||
|
||||
type ReuseLookupResult struct {
|
||||
ProviderMatched bool
|
||||
ExistingProviderID string
|
||||
ExistingAccessStatus AccessStatus
|
||||
ExistingCanonicalFamilys []string
|
||||
MatchedAccountID int64
|
||||
MatchedAccountState MatchedAccountState
|
||||
ExistingModelMapping map[string]string
|
||||
LegacyBatchID *int64
|
||||
}
|
||||
|
||||
type ProvisionRequest struct {
|
||||
@@ -201,6 +203,7 @@ func (s BatchImportService) StartRun(ctx context.Context, req BatchImportRunRequ
|
||||
}
|
||||
|
||||
reuseDecision := DecideReuse(ReuseInput{
|
||||
ProviderMatched: reuseLookup.ProviderMatched,
|
||||
ProviderID: providerID,
|
||||
CanonicalModelFamilies: canonicalFamilies,
|
||||
MatchedAccountID: reuseLookup.MatchedAccountID,
|
||||
@@ -231,6 +234,8 @@ func (s BatchImportService) StartRun(ctx context.Context, req BatchImportRunRequ
|
||||
ProvisionReused: reuseDecision.ProvisionReused,
|
||||
ReusedFromProviderID: reuseDecision.ReusedFromProviderID,
|
||||
ReusedFromAccountID: int64PtrIfSet(reuseDecision.ReusedFromAccountID),
|
||||
LegacyBatchID: reuseLookup.LegacyBatchID,
|
||||
LegacyProviderID: strings.TrimSpace(reuseLookup.ExistingProviderID),
|
||||
}
|
||||
|
||||
if reuseDecision.ProvisionReused {
|
||||
|
||||
Reference in New Issue
Block a user