[PR #153] [MERGED] test: add unit tests for perplexity and google search tools #195

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

📋 Pull Request Information

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

Base: feature/next_releaseHead: test/add-search-tool-coverage


📝 Commits (3)

  • ddd0b0e test: add unit tests for perplexity and google search tools
  • c538b80 test: address review feedback on search tool tests
  • 61a34c2 fix: use context.Background() instead of t.Context() for consistency

📊 Changes

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

View changed files

backend/pkg/tools/google_test.go (+172 -0)
backend/pkg/tools/perplexity_test.go (+349 -0)

📄 Description

Description

Problem

The perplexity.go and google.go search tools had zero test coverage. This makes it harder to catch regressions and verify behavior during refactoring.

Solution

Add comprehensive unit tests for both tools, following the same patterns established in tavily_test.go and traversaal_test.go (from PR #151).

perplexity_test.go (10 test functions, 20 sub-tests):

  • TestPerplexityIsAvailable: API key presence check
  • TestPerplexityNewDefaults: verifies default model, temperature, topP, maxTokens, timeout
  • TestPerplexityNewCustomValues: verifies custom parameter passthrough
  • TestPerplexityHandleErrorResponse: all 10 HTTP status codes (400-504) + unknown code (418)
  • TestPerplexityFormatResponse: empty choices, with/without citations, nil/empty citations pointer
  • TestPerplexityGetSummarizePrompt: template rendering with and without citations
  • TestPerplexitySearchHTTPErrors: verifies error propagation when endpoint is unreachable
  • TestPerplexitySearchCreatesNewClientWithProxy: verifies proxy client creation without panic

google_test.go (4 test functions, 8 sub-tests):

  • TestGoogleIsAvailable: requires both apiKey and cxKey
  • TestGoogleParseSearchResult: empty, single, multiple results, special characters preserved
  • TestGoogleNewSearchServiceWithoutProxy: service creation succeeds
  • TestGoogleNewSearchServiceWithProxy: service creation succeeds with proxy configured

Type of Change

  • Test coverage improvement (no production code changes)

Areas Affected

  • Core Services (Backend API / Workers)
  • External Integrations (Perplexity, Google search APIs)

Testing

Configuration

  • Go 1.26.0 on Windows 11
  • go test ./pkg/tools/ -run "TestPerplexity|TestGoogle" -v -count=1

Test Results

All 24 tests pass:

ok      pentagi/pkg/tools       4.009s

Security Considerations

  • No production code changes; test-only additions
  • No new dependencies introduced
  • Test API keys are fake placeholder values

Checklist

  • My code follows the project's coding standards
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective
  • New and existing tests pass with my changes
  • My changes generate no new warnings
  • I have checked my code for potential security vulnerabilities
  • My changes are backward compatible

🔄 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/153 **Author:** [@mason5052](https://github.com/mason5052) **Created:** 2/27/2026 **Status:** ✅ Merged **Merged:** 3/2/2026 **Merged by:** [@asdek](https://github.com/asdek) **Base:** `feature/next_release` ← **Head:** `test/add-search-tool-coverage` --- ### 📝 Commits (3) - [`ddd0b0e`](https://github.com/vxcontrol/pentagi/commit/ddd0b0e16e168abafa48bac04909201ce95f30f8) test: add unit tests for perplexity and google search tools - [`c538b80`](https://github.com/vxcontrol/pentagi/commit/c538b803dcd39c34e37f1b17d783d2767e3f044e) test: address review feedback on search tool tests - [`61a34c2`](https://github.com/vxcontrol/pentagi/commit/61a34c2c0eea2eeacbd875b9dfb74e7994d2801a) fix: use context.Background() instead of t.Context() for consistency ### 📊 Changes **2 files changed** (+521 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `backend/pkg/tools/google_test.go` (+172 -0) ➕ `backend/pkg/tools/perplexity_test.go` (+349 -0) </details> ### 📄 Description ## Description ### Problem The `perplexity.go` and `google.go` search tools had zero test coverage. This makes it harder to catch regressions and verify behavior during refactoring. ### Solution Add comprehensive unit tests for both tools, following the same patterns established in `tavily_test.go` and `traversaal_test.go` (from PR #151). **`perplexity_test.go`** (10 test functions, 20 sub-tests): - `TestPerplexityIsAvailable`: API key presence check - `TestPerplexityNewDefaults`: verifies default model, temperature, topP, maxTokens, timeout - `TestPerplexityNewCustomValues`: verifies custom parameter passthrough - `TestPerplexityHandleErrorResponse`: all 10 HTTP status codes (400-504) + unknown code (418) - `TestPerplexityFormatResponse`: empty choices, with/without citations, nil/empty citations pointer - `TestPerplexityGetSummarizePrompt`: template rendering with and without citations - `TestPerplexitySearchHTTPErrors`: verifies error propagation when endpoint is unreachable - `TestPerplexitySearchCreatesNewClientWithProxy`: verifies proxy client creation without panic **`google_test.go`** (4 test functions, 8 sub-tests): - `TestGoogleIsAvailable`: requires both `apiKey` and `cxKey` - `TestGoogleParseSearchResult`: empty, single, multiple results, special characters preserved - `TestGoogleNewSearchServiceWithoutProxy`: service creation succeeds - `TestGoogleNewSearchServiceWithProxy`: service creation succeeds with proxy configured ## Type of Change - [x] Test coverage improvement (no production code changes) ## Areas Affected - [x] Core Services (Backend API / Workers) - [x] External Integrations (Perplexity, Google search APIs) ## Testing ### Configuration - Go 1.26.0 on Windows 11 - `go test ./pkg/tools/ -run "TestPerplexity|TestGoogle" -v -count=1` ### Test Results All 24 tests pass: ``` ok pentagi/pkg/tools 4.009s ``` ## Security Considerations - No production code changes; test-only additions - No new dependencies introduced - Test API keys are fake placeholder values ## Checklist - [x] My code follows the project's coding standards - [x] I have performed a self-review of my code - [x] I have added tests that prove my fix is effective - [x] New and existing tests pass with my changes - [x] My changes generate no new warnings - [x] I have checked my code for potential security vulnerabilities - [x] My changes are backward compatible --- <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:39 -04:00
yindo closed this issue 2026-06-06 22:09:39 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vxcontrol/pentagi#195