Skip to content

test: add unit tests for pkg/graph context helpers#213

Open
mason5052 wants to merge 1 commit intovxcontrol:masterfrom
mason5052:test/graph-context-coverage
Open

test: add unit tests for pkg/graph context helpers#213
mason5052 wants to merge 1 commit intovxcontrol:masterfrom
mason5052:test/graph-context-coverage

Conversation

@mason5052
Copy link
Contributor

Description of the Change

Problem

backend/pkg/graph/context.go provides key context helper functions used throughout the graph layer (user ID, user type, permissions) but had no unit test coverage.

Solution

Add context_test.go with 20 focused unit tests covering all testable functions in the package.

Closes N/A

Type of Change

  • 🧪 Test update

Areas Affected

  • Core Services (Frontend UI/Backend API)

Testing and Verification

Test Configuration

os: linux
go: 1.24.1

Test Steps

  1. go test ./pkg/graph/... -count=1
  2. go test ./pkg/graph/... -count=1 -shuffle=on
  3. go vet ./pkg/graph/...

Test Results

=== RUN   TestGetUserID_Found
--- PASS: TestGetUserID_Found (0.00s)
=== RUN   TestGetUserID_Missing
--- PASS: TestGetUserID_Missing (0.00s)
=== RUN   TestGetUserID_WrongType
--- PASS: TestGetUserID_WrongType (0.00s)
=== RUN   TestSetUserID_Roundtrip
--- PASS: TestSetUserID_Roundtrip (0.00s)
=== RUN   TestGetUserType_Found
--- PASS: TestGetUserType_Found (0.00s)
=== RUN   TestGetUserType_Missing
--- PASS: TestGetUserType_Missing (0.00s)
=== RUN   TestGetUserType_WrongType
--- PASS: TestGetUserType_WrongType (0.00s)
=== RUN   TestSetUserType_Roundtrip
--- PASS: TestSetUserType_Roundtrip (0.00s)
=== RUN   TestGetUserPermissions_Found
--- PASS: TestGetUserPermissions_Found (0.00s)
=== RUN   TestGetUserPermissions_Missing
--- PASS: TestGetUserPermissions_Missing (0.00s)
=== RUN   TestGetUserPermissions_WrongType
--- PASS: TestGetUserPermissions_WrongType (0.00s)
=== RUN   TestSetUserPermissions_Roundtrip
--- PASS: TestSetUserPermissions_Roundtrip (0.00s)
=== RUN   TestValidateUserType
--- PASS: TestValidateUserType (0.00s)
=== RUN   TestValidatePermission
--- PASS: TestValidatePermission (0.00s)
PASS
ok  	pentagi/pkg/graph	4.026s

Security Considerations

No security implications. Test-only change covering authentication context helpers.

Performance Impact

None. Test-only change.

Documentation Updates

None required.

Deployment Notes

None. Test-only change.

Checklist

Code Quality

  • My code follows the project's coding standards
  • I have added/updated necessary documentation
  • I have added tests to cover my changes
  • All new and existing tests pass
  • I have run go fmt and go vet (for Go code)

Security

  • I have considered security implications
  • Changes maintain or improve the security model
  • Sensitive information has been properly handled

Compatibility

  • Changes are backward compatible
  • Breaking changes are clearly marked and documented
  • Dependencies are properly updated

Documentation

  • Documentation is clear and complete
  • Comments are added for non-obvious code
  • API changes are documented

Additional Notes

validatePermissionWithFlowID is intentionally excluded: it requires a database.Querier interface, which would need either a large mock or integration test infrastructure outside the scope of this narrow PR.

Add context_test.go with 20 tests covering GetUserID, SetUserID,
GetUserType, SetUserType, GetUserPermissions, SetUserPermissions,
validateUserType, and validatePermission. Includes table-driven tests
for validation functions and wrong-type assertion checks.
Copilot AI review requested due to automatic review settings March 18, 2026 02:49
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 unit test coverage for backend/pkg/graph/context.go context helper functions used across the graph layer (user ID, user type, permissions), addressing previously missing coverage.

Changes:

  • Introduces context_test.go with focused tests for Get/SetUserID, Get/SetUserType, and Get/SetUserPermissions
  • Adds table-driven tests for internal authorization helpers validateUserType and validatePermission

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

Comment on lines +97 to +103
tests := []struct {
name string
ctx context.Context
allowed []string
wantOK bool
wantErr string
}{
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