Truncate project codes by rune instead of byte to prevent invalid PostgreSQL UTF-8 sequences from mixed CJK and ASCII slugs. test(server): add PG pi-agent governance E2E and Phase 5 acceptance matrix Cover Chinese HTTP project create, pi-agent intake after workflow activate, authz negatives, activate idempotency, and migration version gate. Co-authored-by: Cursor <cursoragent@cursor.com>
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package server_test
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"unicode/utf8"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
|
|
"chat-agent-system/internal/projectworkflow"
|
|
)
|
|
|
|
func TestProjectCreate_PG_ChineseNameViaHTTP(t *testing.T) {
|
|
pool := openPGPoolWithMigrations(t)
|
|
if pool == nil {
|
|
return
|
|
}
|
|
defer pool.Close()
|
|
|
|
handler, _ := setupPGGovernanceServer(t, pool)
|
|
token := loginTestUser(t, handler, "zhanggong", "123456")
|
|
|
|
body, _ := json.Marshal(projectworkflow.CreateProjectInput{
|
|
Name: "PG Phase5 治理链中文名称测试",
|
|
DeviceType: "超声手术设备",
|
|
IntendedUse: "软组织切除",
|
|
TargetMarket: "NMPA 三类",
|
|
})
|
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/projects", bytes.NewReader(body))
|
|
withBearerAuth(req, token)
|
|
rec := httptest.NewRecorder()
|
|
handler.ServeHTTP(rec, req)
|
|
if rec.Code != http.StatusCreated {
|
|
t.Fatalf("create project with Chinese name: %d %s", rec.Code, rec.Body.String())
|
|
}
|
|
var proj projectworkflow.Project
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &proj); err != nil {
|
|
t.Fatalf("decode project: %v", err)
|
|
}
|
|
if !utf8.ValidString(proj.Code) {
|
|
t.Fatalf("project code invalid UTF-8: %q", proj.Code)
|
|
}
|
|
t.Cleanup(func() {
|
|
cleanupProject(t, pool, proj.ID)
|
|
})
|
|
}
|
|
|
|
func cleanupProject(t *testing.T, pool *pgxpool.Pool, projectID int64) {
|
|
t.Helper()
|
|
if pool == nil || projectID <= 0 {
|
|
return
|
|
}
|
|
_, _ = pool.Exec(t.Context(), `DELETE FROM projects WHERE id = $1`, projectID)
|
|
}
|