chore: sync local project state
This commit is contained in:
@@ -6,12 +6,17 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"supply-intelligence/internal/app"
|
||||
"supply-intelligence/internal/domain"
|
||||
"supply-intelligence/internal/probe"
|
||||
)
|
||||
|
||||
func domainTime(ts int64) time.Time {
|
||||
return time.Unix(ts, 0).UTC()
|
||||
}
|
||||
|
||||
func TestApplicationServerRoutes(t *testing.T) {
|
||||
application := app.New()
|
||||
|
||||
@@ -41,8 +46,10 @@ func TestApplicationServerRoutes(t *testing.T) {
|
||||
|
||||
func TestPublishConsumeOnceListAppliedIntegration(t *testing.T) {
|
||||
application := app.New()
|
||||
application.Repo.UpsertDiscoveryCandidateContext(nil, domain.DiscoveryCandidate{CandidateID: "cand-integration-1", AccountID: 601, Platform: "openai", Model: "gpt-4.1-mini", Source: "admission", Status: domain.DiscoveryCandidateStatusTestPassed, DiscoveredAt: domainTime(100), UpdatedAt: domainTime(110), Version: 2})
|
||||
application.Repo.UpsertSupplyPackage(nil, domain.SupplyPackage{PackageID: 501, Platform: "openai", Model: "gpt-4.1-mini", Status: "draft", Source: "admission", UpdatedAt: domainTime(110), Version: 1})
|
||||
|
||||
publishReq := httptest.NewRequest(http.MethodPost, "/internal/supply-intelligence/publish/package-event", bytes.NewBufferString(`{"event_id":"evt-integration-1","package_id":501,"platform":"openai","model":"gpt-4.1-mini","version":9,"occurred_at":"2026-05-06T20:30:00Z"}`))
|
||||
publishReq := httptest.NewRequest(http.MethodPost, "/internal/supply-intelligence/publish/package-event", bytes.NewBufferString(`{"event_id":"evt-integration-1","platform":"openai","model":"gpt-4.1-mini","occurred_at":"2026-05-06T20:30:00Z"}`))
|
||||
publishRR := httptest.NewRecorder()
|
||||
application.Server.Routes().ServeHTTP(publishRR, publishReq)
|
||||
if publishRR.Code != http.StatusOK {
|
||||
@@ -72,7 +79,7 @@ func TestPublishConsumeOnceListAppliedIntegration(t *testing.T) {
|
||||
if len(listResp.Items) != 1 || listResp.Items[0].EventID != "evt-integration-1" {
|
||||
t.Fatalf("unexpected list items: %+v", listResp.Items)
|
||||
}
|
||||
if listResp.NextCursor != "1" {
|
||||
if listResp.NextCursor != "" {
|
||||
t.Fatalf("unexpected next cursor: %+v", listResp)
|
||||
}
|
||||
if listResp.Items[0].GatewaySyncStatus != domain.GatewaySyncStatusApplied {
|
||||
@@ -82,8 +89,10 @@ func TestPublishConsumeOnceListAppliedIntegration(t *testing.T) {
|
||||
|
||||
func TestPublishConsumeOnceListFailedIntegration(t *testing.T) {
|
||||
application := app.New()
|
||||
application.Repo.UpsertDiscoveryCandidateContext(nil, domain.DiscoveryCandidate{CandidateID: "cand-integration-failed", AccountID: 602, Platform: "openai", Model: "gpt-fail-model", Source: "admission", Status: domain.DiscoveryCandidateStatusTestPassed, DiscoveredAt: domainTime(100), UpdatedAt: domainTime(110), Version: 2})
|
||||
application.Repo.UpsertSupplyPackage(nil, domain.SupplyPackage{PackageID: 502, Platform: "openai", Model: "gpt-fail-model", Status: "draft", Source: "admission", UpdatedAt: domainTime(110), Version: 1})
|
||||
|
||||
publishReq := httptest.NewRequest(http.MethodPost, "/internal/supply-intelligence/publish/package-event", bytes.NewBufferString(`{"event_id":"evt-integration-failed","package_id":502,"platform":"openai","model":"gpt-fail-model","version":10,"occurred_at":"2026-05-06T20:31:00Z"}`))
|
||||
publishReq := httptest.NewRequest(http.MethodPost, "/internal/supply-intelligence/publish/package-event", bytes.NewBufferString(`{"event_id":"evt-integration-failed","platform":"openai","model":"gpt-fail-model","occurred_at":"2026-05-06T20:31:00Z"}`))
|
||||
publishRR := httptest.NewRecorder()
|
||||
application.Server.Routes().ServeHTTP(publishRR, publishReq)
|
||||
if publishRR.Code != http.StatusOK {
|
||||
@@ -113,7 +122,7 @@ func TestPublishConsumeOnceListFailedIntegration(t *testing.T) {
|
||||
if len(listResp.Items) != 1 || listResp.Items[0].EventID != "evt-integration-failed" {
|
||||
t.Fatalf("unexpected list items: %+v", listResp.Items)
|
||||
}
|
||||
if listResp.NextCursor != "1" {
|
||||
if listResp.NextCursor != "" {
|
||||
t.Fatalf("unexpected next cursor: %+v", listResp)
|
||||
}
|
||||
if listResp.Items[0].GatewaySyncStatus != domain.GatewaySyncStatusFailed {
|
||||
@@ -121,6 +130,54 @@ func TestPublishConsumeOnceListFailedIntegration(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublishEndpointDuplicateReplayReturnsStableAlreadyApplied(t *testing.T) {
|
||||
application := app.New()
|
||||
application.Repo.UpsertDiscoveryCandidateContext(nil, domain.DiscoveryCandidate{CandidateID: "cand-dup-stable", AccountID: 603, Platform: "openai", Model: "gpt-4.1-stable", Source: "admission", Status: domain.DiscoveryCandidateStatusTestPassed, DiscoveredAt: domainTime(100), UpdatedAt: domainTime(110), Version: 2})
|
||||
application.Repo.UpsertSupplyPackage(nil, domain.SupplyPackage{PackageID: 503, Platform: "openai", Model: "gpt-4.1-stable", Status: "draft", Source: "admission", UpdatedAt: domainTime(110), Version: 1})
|
||||
|
||||
body := `{"event_id":"evt-stable-1","platform":"openai","model":"gpt-4.1-stable","occurred_at":"2026-05-06T20:32:00Z"}`
|
||||
firstReq := httptest.NewRequest(http.MethodPost, "/internal/supply-intelligence/publish/package-event", bytes.NewBufferString(body))
|
||||
firstRR := httptest.NewRecorder()
|
||||
application.Server.Routes().ServeHTTP(firstRR, firstReq)
|
||||
if firstRR.Code != http.StatusOK {
|
||||
t.Fatalf("unexpected first publish status: %d body=%s", firstRR.Code, firstRR.Body.String())
|
||||
}
|
||||
|
||||
replayReq := httptest.NewRequest(http.MethodPost, "/internal/supply-intelligence/publish/package-event", bytes.NewBufferString(body))
|
||||
replayRR := httptest.NewRecorder()
|
||||
application.Server.Routes().ServeHTTP(replayRR, replayReq)
|
||||
if replayRR.Code != http.StatusConflict {
|
||||
t.Fatalf("unexpected replay status: %d body=%s", replayRR.Code, replayRR.Body.String())
|
||||
}
|
||||
var payload map[string]any
|
||||
if err := json.NewDecoder(replayRR.Body).Decode(&payload); err != nil {
|
||||
t.Fatalf("decode replay error: %v", err)
|
||||
}
|
||||
if payload["error"] != "publish_already_applied" {
|
||||
t.Fatalf("expected stable replay error publish_already_applied, got %+v", payload)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublishEndpointHalfAppliedStateReturnsStableAlreadyApplied(t *testing.T) {
|
||||
application := app.New()
|
||||
application.Repo.UpsertDiscoveryCandidateContext(nil, domain.DiscoveryCandidate{CandidateID: "cand-half-state", AccountID: 604, Platform: "openai", Model: "gpt-4.1-half-state", Source: "admission", Status: domain.DiscoveryCandidateStatusPublished, DiscoveredAt: domainTime(100), UpdatedAt: domainTime(110), Version: 2})
|
||||
application.Repo.UpsertSupplyPackage(nil, domain.SupplyPackage{PackageID: 504, Platform: "openai", Model: "gpt-4.1-half-state", Status: "draft", Source: "admission", UpdatedAt: domainTime(110), Version: 1})
|
||||
|
||||
req := httptest.NewRequest(http.MethodPost, "/internal/supply-intelligence/publish/package-event", bytes.NewBufferString(`{"event_id":"evt-half-state","platform":"openai","model":"gpt-4.1-half-state","occurred_at":"2026-05-06T20:33:00Z"}`))
|
||||
rr := httptest.NewRecorder()
|
||||
application.Server.Routes().ServeHTTP(rr, req)
|
||||
if rr.Code != http.StatusConflict {
|
||||
t.Fatalf("unexpected status: %d body=%s", rr.Code, rr.Body.String())
|
||||
}
|
||||
var payload map[string]any
|
||||
if err := json.NewDecoder(rr.Body).Decode(&payload); err != nil {
|
||||
t.Fatalf("decode half-applied error: %v", err)
|
||||
}
|
||||
if payload["error"] != "publish_already_applied" {
|
||||
t.Fatalf("expected stable half-applied error publish_already_applied, got %+v", payload)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiscoveryCandidateCreateAndListIntegration(t *testing.T) {
|
||||
application := app.New()
|
||||
|
||||
@@ -131,7 +188,7 @@ func TestDiscoveryCandidateCreateAndListIntegration(t *testing.T) {
|
||||
t.Fatalf("unexpected create status: %d body=%s", createRR.Code, createRR.Body.String())
|
||||
}
|
||||
|
||||
listReq := httptest.NewRequest(http.MethodGet, "/internal/supply-intelligence/discovery/candidates?status=pending_admission", nil)
|
||||
listReq := httptest.NewRequest(http.MethodGet, "/internal/supply-intelligence/discovery/candidates", nil)
|
||||
listRR := httptest.NewRecorder()
|
||||
application.Server.Routes().ServeHTTP(listRR, listReq)
|
||||
if listRR.Code != http.StatusOK {
|
||||
|
||||
Reference in New Issue
Block a user