[PR #231] [MERGED] test: add unit tests for schema package JSON Schema validation #252

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/231
Author: @mason5052
Created: 3/31/2026
Status: Merged
Merged: 4/2/2026
Merged by: @asdek

Base: mainHead: test/schema-validation


📝 Commits (2)

  • cc0260b test: add unit tests for schema package JSON Schema validation
  • 8ddc25f test: add failure-path coverage for schema validation

📊 Changes

1 file changed (+527 additions, -0 deletions)

View changed files

backend/pkg/schema/schema_test.go (+527 -0)

📄 Description

What

Add unit test coverage for the pkg/schema package JSON Schema Draft 7 validation.

Why

The schema package implements JSON Schema validation used for tool input/output validation across PentAGI. It had no test coverage despite handling schema compilation, document validation, database serialization, and custom JSON marshaling with extended properties.

Tests Added (schema_test.go)

Test Function Coverage
TestSchemaValid Schema validation for string, object, array, integer, boolean, number types; invalid schema failure path
TestSchemaGetValidator JSON Schema Draft 7 compiler returns valid validator objects; invalid schema returns error
TestSchemaValidateString String validation with minLength/maxLength constraints, invalid JSON handling
TestSchemaValidateBytes Byte validation with integer range constraints, type mismatch, malformed JSON input
TestSchemaValidateGo Go object validation with required fields, wrong types
TestSchemaValueScan Database serialization round-trip (Value/Scan), string and bytes input, unsupported type, invalid JSON
TestTypeMarshalJSON Object auto-adds properties/required, ExtProps inclusion
TestTypeUnmarshalJSON ExtProps extraction from unknown fields, marshal/unmarshal round-trip
TestSchemaValidateObjectWithEnum Enum constraint validation
TestSchemaValidateWithPattern Regex pattern constraint validation
TestSchemaValidateArray Array minItems/maxItems/items type constraints
TestScanFromJSON Helper function with string, bytes, unsupported type, invalid JSON

Test Approach

  • All tests use t.Parallel() for fast execution
  • Validates both valid and invalid inputs for each schema type
  • Tests JSON Schema Draft 7 specific features (enum, pattern, array constraints)
  • Verifies custom Type marshaling preserves ExtProps through round-trips
  • Tests database serialization edge cases (unsupported types, invalid JSON)
  • Covers failure paths for schema compilation and malformed input

Verification

cd backend && go test ./pkg/schema/ -count=1 -v
# 60 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/231 **Author:** [@mason5052](https://github.com/mason5052) **Created:** 3/31/2026 **Status:** ✅ Merged **Merged:** 4/2/2026 **Merged by:** [@asdek](https://github.com/asdek) **Base:** `main` ← **Head:** `test/schema-validation` --- ### 📝 Commits (2) - [`cc0260b`](https://github.com/vxcontrol/pentagi/commit/cc0260b205ffbfa196edf415849b0c80a38ba7b6) test: add unit tests for schema package JSON Schema validation - [`8ddc25f`](https://github.com/vxcontrol/pentagi/commit/8ddc25f4116b2272f267f0c5cb9287b1bf9be24d) test: add failure-path coverage for schema validation ### 📊 Changes **1 file changed** (+527 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `backend/pkg/schema/schema_test.go` (+527 -0) </details> ### 📄 Description ## What Add unit test coverage for the `pkg/schema` package JSON Schema Draft 7 validation. ## Why The schema package implements JSON Schema validation used for tool input/output validation across PentAGI. It had no test coverage despite handling schema compilation, document validation, database serialization, and custom JSON marshaling with extended properties. ## Tests Added (schema_test.go) | Test Function | Coverage | |--------------|----------| | `TestSchemaValid` | Schema validation for string, object, array, integer, boolean, number types; invalid schema failure path | | `TestSchemaGetValidator` | JSON Schema Draft 7 compiler returns valid validator objects; invalid schema returns error | | `TestSchemaValidateString` | String validation with minLength/maxLength constraints, invalid JSON handling | | `TestSchemaValidateBytes` | Byte validation with integer range constraints, type mismatch, malformed JSON input | | `TestSchemaValidateGo` | Go object validation with required fields, wrong types | | `TestSchemaValueScan` | Database serialization round-trip (Value/Scan), string and bytes input, unsupported type, invalid JSON | | `TestTypeMarshalJSON` | Object auto-adds properties/required, ExtProps inclusion | | `TestTypeUnmarshalJSON` | ExtProps extraction from unknown fields, marshal/unmarshal round-trip | | `TestSchemaValidateObjectWithEnum` | Enum constraint validation | | `TestSchemaValidateWithPattern` | Regex pattern constraint validation | | `TestSchemaValidateArray` | Array minItems/maxItems/items type constraints | | `TestScanFromJSON` | Helper function with string, bytes, unsupported type, invalid JSON | ## Test Approach - All tests use `t.Parallel()` for fast execution - Validates both valid and invalid inputs for each schema type - Tests JSON Schema Draft 7 specific features (enum, pattern, array constraints) - Verifies custom Type marshaling preserves ExtProps through round-trips - Tests database serialization edge cases (unsupported types, invalid JSON) - Covers failure paths for schema compilation and malformed input ## Verification ```bash cd backend && go test ./pkg/schema/ -count=1 -v # 60 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:54 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vxcontrol/pentagi#252