fix(backend): harden final MVP invariants

This commit is contained in:
2026-07-22 01:24:41 +08:00
parent 251b212e06
commit 78d4845688
26 changed files with 977 additions and 175 deletions

View File

@@ -39,8 +39,8 @@ func NewHandler(service *SessionService) *Handler {
}
func (h *Handler) Register(router gin.IRouter) {
router.GET("/projects/:projectId/ai-sessions", h.list)
router.POST("/projects/:projectId/ai-sessions", h.create)
router.GET("/projects/:id/ai-sessions", h.list)
router.POST("/projects/:id/ai-sessions", h.create)
}
func (h *Handler) list(c *gin.Context) {
@@ -84,7 +84,7 @@ func aiRequestContext(c *gin.Context) (uint, string, bool) {
httpx.Error(c, http.StatusUnauthorized, "unauthorized", "未登录或登录已失效")
return 0, "", false
}
projectIdentity, ok := httpx.IdentityParam(c, "projectId")
projectIdentity, ok := httpx.IdentityParam(c, "id")
if !ok {
return 0, "", false
}

View File

@@ -1,3 +1,5 @@
//go:build integration
package ai
import (
@@ -16,10 +18,8 @@ import (
)
func TestPostgresReserveRateLimitIsAtomicAcrossConcurrentConnections(t *testing.T) {
dsn := os.Getenv("DATABASE_URL")
if dsn == "" {
t.Skip("DATABASE_URL is not configured; skipping PostgreSQL AI rate reservation test")
}
dsn := os.Getenv("TEST_DATABASE_URL")
require.NotEmpty(t, dsn, "TEST_DATABASE_URL is required for integration tests and must point to an isolated database")
database, err := gorm.Open(postgres.Open(dsn), &gorm.Config{TranslateError: true, Logger: logger.Default.LogMode(logger.Silent)})
require.NoError(t, err)
require.NoError(t, models.AutoMigrate(database))