Skip to content

test: add unit tests for pkg/config package#199

Open
mason5052 wants to merge 2 commits intovxcontrol:masterfrom
mason5052:test/config-package-coverage
Open

test: add unit tests for pkg/config package#199
mason5052 wants to merge 2 commits intovxcontrol:masterfrom
mason5052:test/config-package-coverage

Conversation

@mason5052
Copy link
Contributor

Description of Change

Problem: The pkg/config package has no unit test coverage. This package handles all environment variable parsing, default values, URL parsing, and installation ID management for the entire application.

Solution: Add 14 unit tests covering NewConfig defaults, environment variable overrides, URL parsing, provider server URL defaults, summarizer settings, search engine defaults, and all ensureInstallationID code paths (UUID generation, file read/write, invalid value handling).

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Security update
  • Test update
  • Documentation update
  • Configuration change

Areas Affected

  • Core Services (Frontend UI / Backend API)
  • AI Agents (Researcher / Developer / Executor)
  • Security Tools Integration
  • Memory System (Vector Store / Knowledge Base)
  • Monitoring Stack (Grafana / OpenTelemetry)
  • Analytics & Reporting
  • External Integrations (LLM Providers / Search Engines / Security APIs)
  • Documentation
  • Infrastructure / DevOps

Testing and Verification

Test Configuration

  • PentAGI Version: v1.2.0 (master)
  • Go Version: 1.24.1
  • Host OS: Windows 11

Test Steps

  1. Run go test ./pkg/config/... -v

Test Results

=== RUN   TestNewConfig_Defaults
--- PASS: TestNewConfig_Defaults (0.00s)
=== RUN   TestNewConfig_EnvOverride
--- PASS: TestNewConfig_EnvOverride (0.00s)
=== RUN   TestNewConfig_ProviderDefaults
--- PASS: TestNewConfig_ProviderDefaults (0.00s)
=== RUN   TestNewConfig_StaticURL
--- PASS: TestNewConfig_StaticURL (0.00s)
=== RUN   TestNewConfig_StaticURL_Empty
--- PASS: TestNewConfig_StaticURL_Empty (0.00s)
=== RUN   TestNewConfig_SummarizerDefaults
--- PASS: TestNewConfig_SummarizerDefaults (0.00s)
=== RUN   TestNewConfig_SearchEngineDefaults
--- PASS: TestNewConfig_SearchEngineDefaults (0.00s)
=== RUN   TestEnsureInstallationID_GeneratesNewUUID
--- PASS: TestEnsureInstallationID_GeneratesNewUUID (0.02s)
=== RUN   TestEnsureInstallationID_ReadsExistingFile
--- PASS: TestEnsureInstallationID_ReadsExistingFile (0.01s)
=== RUN   TestEnsureInstallationID_KeepsValidEnvValue
--- PASS: TestEnsureInstallationID_KeepsValidEnvValue (0.00s)
=== RUN   TestEnsureInstallationID_ReplacesInvalidEnvValue
--- PASS: TestEnsureInstallationID_ReplacesInvalidEnvValue (0.00s)
=== RUN   TestEnsureInstallationID_ReplacesInvalidFileContent
--- PASS: TestEnsureInstallationID_ReplacesInvalidFileContent (0.01s)
=== RUN   TestNewConfig_CorsOrigins
--- PASS: TestNewConfig_CorsOrigins (0.00s)
=== RUN   TestNewConfig_OllamaDefaults
--- PASS: TestNewConfig_OllamaDefaults (0.00s)
PASS
ok  	pentagi/pkg/config	3.855s

Checklist

  • Code follows project coding standards
  • Tests added for changes
  • All tests pass
  • go fmt and go vet run
  • Changes are backward compatible

Add comprehensive unit tests for NewConfig defaults, environment variable
overrides, URL parsing, provider server URL defaults, summarizer defaults,
search engine defaults, and ensureInstallationID logic including UUID
generation, file persistence, and invalid value handling.
Copilot AI review requested due to automatic review settings March 12, 2026 17:56
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds initial unit test coverage for backend/pkg/config, focusing on NewConfig() default/env parsing behavior and ensureInstallationID() persistence/validation behavior.

Changes:

  • Add unit tests for NewConfig() defaults and selected env var overrides (URLs, provider defaults, summarizer/search defaults, CORS, Ollama).
  • Add unit tests for ensureInstallationID() covering generation, reading existing IDs, and invalid-value replacement paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +14 to +17
// Unset env vars that would override defaults
t.Setenv("DATABASE_URL", "")
t.Setenv("LICENSE_KEY", "")

Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests call NewConfig(), which reads environment variables (and godotenv.Load() may load a local .env) and also may read/write ./data/installation_id via ensureInstallationID(). Setting vars to "" does not actually unset them. To make the defaults tests hermetic and avoid side effects/flakes across dev/CI environments, consider (a) t.Chdir(t.TempDir()) before calling NewConfig() and/or (b) explicitly os.Unsetenv (with cleanup restore) for the env vars whose defaults you assert, rather than t.Setenv(key, "").

Copilot uses AI. Check for mistakes.
Add clearConfigEnv helper that clears all Config struct env vars via
t.Setenv, and use t.Chdir(t.TempDir()) to isolate filesystem side
effects from godotenv.Load() and ensureInstallationID(). Tests now
pass regardless of environment variables set in the calling shell.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants