[PR #171] [MERGED] test: add unit tests for agent context and tool registry #212

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

📋 Pull Request Information

Original PR: https://github.com/vxcontrol/pentagi/pull/171
Author: @mason5052
Created: 3/2/2026
Status: Merged
Merged: 3/2/2026
Merged by: @asdek

Base: feature/next_releaseHead: test/context-registry-unit-tests


📝 Commits (2)

  • 8768ea3 test: add unit tests for agent context management and tool registry
  • 2fd6949 test: add t.Parallel() to copy-safety tests and bidirectional completeness

📊 Changes

2 files changed (+283 additions, -0 deletions)

View changed files

backend/pkg/tools/context_test.go (+108 -0)
backend/pkg/tools/registry_test.go (+175 -0)

📄 Description

Description

Add unit tests for two core infrastructure modules in backend/pkg/tools/:

  • context.go - Agent context management (PutAgentContext/GetAgentContext)
  • registry.go - Tool type mapping, registry definitions, and type filtering

Type of Change

  • New tests (no production code changes)

Areas Affected

  • backend/pkg/tools/context_test.go (new file)
  • backend/pkg/tools/registry_test.go (new file)

Testing

All tests are self-contained, table-driven where appropriate, and use t.Parallel().

context_test.go (5 test functions):

  • TestGetAgentContextEmpty - empty context returns false
  • TestPutAgentContextFirst - first call sets both parent and current to same agent
  • TestPutAgentContextChaining - second call promotes current to parent, sets new current
  • TestPutAgentContextTriple - triple chaining verifies parent tracks previous current
  • TestPutAgentContextIsolation - independent context trees do not interfere

registry_test.go (6 test functions):

  • TestToolTypeString - all 8 ToolType enum values map to correct string representations
  • TestGetToolType - known tool names map to correct types, unknown returns NoneToolType
  • TestGetToolTypeMappingCompleteness - all mapped tools resolve to non-None type
  • TestGetToolTypeMappingCopySafety - GetToolTypeMapping returns a copy (mutation does not affect original)
  • TestGetToolsByType - filters tools correctly by type, empty result for unused types
  • TestToolTypeMappingRegistryConsistency - every tool in type mapping exists in registry definitions

Security Considerations

No security impact - test-only changes.

Checklist

  • My code follows the existing code style of this project
  • I have performed a self-review of my own code
  • New tests added for the changes
  • Tests follow project conventions (table-driven, t.Parallel(), same package)

🔄 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/171 **Author:** [@mason5052](https://github.com/mason5052) **Created:** 3/2/2026 **Status:** ✅ Merged **Merged:** 3/2/2026 **Merged by:** [@asdek](https://github.com/asdek) **Base:** `feature/next_release` ← **Head:** `test/context-registry-unit-tests` --- ### 📝 Commits (2) - [`8768ea3`](https://github.com/vxcontrol/pentagi/commit/8768ea3c0340c56eeb52717bca7992d455301824) test: add unit tests for agent context management and tool registry - [`2fd6949`](https://github.com/vxcontrol/pentagi/commit/2fd69494af603f1d0ce2a07e6510ccfa79aa686c) test: add t.Parallel() to copy-safety tests and bidirectional completeness ### 📊 Changes **2 files changed** (+283 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `backend/pkg/tools/context_test.go` (+108 -0) ➕ `backend/pkg/tools/registry_test.go` (+175 -0) </details> ### 📄 Description ## Description Add unit tests for two core infrastructure modules in `backend/pkg/tools/`: - `context.go` - Agent context management (PutAgentContext/GetAgentContext) - `registry.go` - Tool type mapping, registry definitions, and type filtering ## Type of Change - [x] New tests (no production code changes) ## Areas Affected - `backend/pkg/tools/context_test.go` (new file) - `backend/pkg/tools/registry_test.go` (new file) ## Testing All tests are self-contained, table-driven where appropriate, and use `t.Parallel()`. **context_test.go (5 test functions):** - `TestGetAgentContextEmpty` - empty context returns false - `TestPutAgentContextFirst` - first call sets both parent and current to same agent - `TestPutAgentContextChaining` - second call promotes current to parent, sets new current - `TestPutAgentContextTriple` - triple chaining verifies parent tracks previous current - `TestPutAgentContextIsolation` - independent context trees do not interfere **registry_test.go (6 test functions):** - `TestToolTypeString` - all 8 ToolType enum values map to correct string representations - `TestGetToolType` - known tool names map to correct types, unknown returns NoneToolType - `TestGetToolTypeMappingCompleteness` - all mapped tools resolve to non-None type - `TestGetToolTypeMappingCopySafety` - GetToolTypeMapping returns a copy (mutation does not affect original) - `TestGetToolsByType` - filters tools correctly by type, empty result for unused types - `TestToolTypeMappingRegistryConsistency` - every tool in type mapping exists in registry definitions ## Security Considerations No security impact - test-only changes. ## Checklist - [x] My code follows the existing code style of this project - [x] I have performed a self-review of my own code - [x] New tests added for the changes - [x] Tests follow project conventions (table-driven, t.Parallel(), same package) --- <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:43 -04:00
yindo closed this issue 2026-06-06 22:09:43 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vxcontrol/pentagi#212