[PR #230] [MERGED] test: add unit tests for key server/models validation types #251

Closed
opened 2026-06-06 22:09:53 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/vxcontrol/pentagi/pull/230
Author: @mason5052
Created: 3/31/2026
Status: Merged
Merged: 4/7/2026
Merged by: @asdek

Base: mainHead: test/server-models-validation


📝 Commits (3)

  • 5d4638e test: add unit tests for server/models validation functions
  • 62dbefd test: fill coverage gaps in server/models validation tests
  • 1b2681c test: shadow loop variable to prevent parallel subtest capture

📊 Changes

7 files changed (+2261 additions, -0 deletions)

View changed files

backend/pkg/server/models/api_tokens_test.go (+255 -0)
backend/pkg/server/models/assistants_test.go (+211 -0)
backend/pkg/server/models/flows_test.go (+711 -0)
backend/pkg/server/models/init_test.go (+250 -0)
backend/pkg/server/models/prompts_test.go (+111 -0)
backend/pkg/server/models/providers_test.go (+161 -0)
backend/pkg/server/models/users_test.go (+562 -0)

📄 Description

What

Add unit tests for validation logic across key server/models types: users, providers, API tokens, flows, tasks, containers, assistants, prompts, roles, and custom validators.

This does not cover every exported validator in the package (log models, analytics, msgchains, screenshots, and vecstore models are not included).

Why

These model types contain security-sensitive validation functions (password strength, OAuth scope, JWT claims, API token TTL bounds) and core domain validation (enum status types, struct field requirements, nested model validation). None had test coverage.

Test Files

File Tested Types
users_test.go UserStatus, UserType, Login, Password, User, UserPassword, AuthCallback, UserRole, UserRolePrivileges, UserPreferences
providers_test.go ProviderType (10 types), Provider, CreateProvider, PatchProvider, ProviderInfo
api_tokens_test.go TokenStatus, APIToken, APITokenWithSecret, CreateAPITokenRequest, UpdateAPITokenRequest, APITokenClaims
flows_test.go FlowStatus, TaskStatus, SubtaskStatus, ContainerStatus, ContainerType, Flow, FlowTasksSubtasks, FlowContainers, Task, TaskSubtasks, Subtask, Container, Role, Privilege, RolePrivileges, PatchFlow
init_test.go Custom validators (stpass, vmail, oauth_min_scope, solid, semver, semverex), scanFromJSON
assistants_test.go AssistantStatus, Assistant, CreateAssistant, PatchAssistant, AssistantFlow
prompts_test.go PromptType, Prompt, PatchPrompt

Test Approach

  • All tests use t.Parallel() for fast execution
  • Table-driven tests for enum validation with valid and invalid cases
  • Boundary testing for numeric constraints (TTL min=60, max=94608000)
  • Cross-field validation (Password confirm mismatch, current != new)
  • Nested struct validation (AssistantFlow, FlowTasksSubtasks, FlowContainers, TaskSubtasks, UserRolePrivileges)
  • Same-package testing for access to unexported validate and scanFromJSON

Verification

cd backend && go test ./pkg/server/models/ -count=1 -v
# 347 test cases pass

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/vxcontrol/pentagi/pull/230 **Author:** [@mason5052](https://github.com/mason5052) **Created:** 3/31/2026 **Status:** ✅ Merged **Merged:** 4/7/2026 **Merged by:** [@asdek](https://github.com/asdek) **Base:** `main` ← **Head:** `test/server-models-validation` --- ### 📝 Commits (3) - [`5d4638e`](https://github.com/vxcontrol/pentagi/commit/5d4638e79d638ebab214455e9a5f33ceb54ac29c) test: add unit tests for server/models validation functions - [`62dbefd`](https://github.com/vxcontrol/pentagi/commit/62dbefdd2535d43d1ce50c1c9bc682e03904c1f2) test: fill coverage gaps in server/models validation tests - [`1b2681c`](https://github.com/vxcontrol/pentagi/commit/1b2681cd99597a9839ede9cd74703ed8b7aa185c) test: shadow loop variable to prevent parallel subtest capture ### 📊 Changes **7 files changed** (+2261 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `backend/pkg/server/models/api_tokens_test.go` (+255 -0) ➕ `backend/pkg/server/models/assistants_test.go` (+211 -0) ➕ `backend/pkg/server/models/flows_test.go` (+711 -0) ➕ `backend/pkg/server/models/init_test.go` (+250 -0) ➕ `backend/pkg/server/models/prompts_test.go` (+111 -0) ➕ `backend/pkg/server/models/providers_test.go` (+161 -0) ➕ `backend/pkg/server/models/users_test.go` (+562 -0) </details> ### 📄 Description ## What Add unit tests for validation logic across key `server/models` types: users, providers, API tokens, flows, tasks, containers, assistants, prompts, roles, and custom validators. This does not cover every exported validator in the package (log models, analytics, msgchains, screenshots, and vecstore models are not included). ## Why These model types contain security-sensitive validation functions (password strength, OAuth scope, JWT claims, API token TTL bounds) and core domain validation (enum status types, struct field requirements, nested model validation). None had test coverage. ## Test Files | File | Tested Types | |------|-------------| | `users_test.go` | UserStatus, UserType, Login, Password, User, UserPassword, AuthCallback, UserRole, UserRolePrivileges, UserPreferences | | `providers_test.go` | ProviderType (10 types), Provider, CreateProvider, PatchProvider, ProviderInfo | | `api_tokens_test.go` | TokenStatus, APIToken, APITokenWithSecret, CreateAPITokenRequest, UpdateAPITokenRequest, APITokenClaims | | `flows_test.go` | FlowStatus, TaskStatus, SubtaskStatus, ContainerStatus, ContainerType, Flow, FlowTasksSubtasks, FlowContainers, Task, TaskSubtasks, Subtask, Container, Role, Privilege, RolePrivileges, PatchFlow | | `init_test.go` | Custom validators (stpass, vmail, oauth_min_scope, solid, semver, semverex), scanFromJSON | | `assistants_test.go` | AssistantStatus, Assistant, CreateAssistant, PatchAssistant, AssistantFlow | | `prompts_test.go` | PromptType, Prompt, PatchPrompt | ## Test Approach - All tests use `t.Parallel()` for fast execution - Table-driven tests for enum validation with valid and invalid cases - Boundary testing for numeric constraints (TTL min=60, max=94608000) - Cross-field validation (Password confirm mismatch, current != new) - Nested struct validation (AssistantFlow, FlowTasksSubtasks, FlowContainers, TaskSubtasks, UserRolePrivileges) - Same-package testing for access to unexported `validate` and `scanFromJSON` ## Verification ```bash cd backend && go test ./pkg/server/models/ -count=1 -v # 347 test cases pass ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-06 22:09:53 -04:00
yindo closed this issue 2026-06-06 22:09:53 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vxcontrol/pentagi#251