Skip to content

Test coverage improvements, global elimination, E2E tests, and bug fixes#218

Merged
bartcode merged 8 commits into
mainfrom
test-coverage-and-cleanup
May 11, 2026
Merged

Test coverage improvements, global elimination, E2E tests, and bug fixes#218
bartcode merged 8 commits into
mainfrom
test-coverage-and-cleanup

Conversation

@bartcode
Copy link
Copy Markdown
Collaborator

@bartcode bartcode commented May 10, 2026

Summary

  • Eliminate remaining mutable package-level globals: globalResolver → Fiber Locals middleware + ServiceRegistry; startTimeMonitoringHandler.startTime field; signedURLRateLimiterStorageHandler.signedURLLimiter field
  • Add unit tests for internal/tenantdb/ (0% → ~50%): declarative service, bootstrap keys, backfill helpers
  • Add unit tests for internal/mcp/tools/knowledge_graph.go (0% → ~60%): all 3 graph tools with metadata, schema, and execute guard tests
  • Add unit tests for internal/storage/log_elasticsearch.go (0% → ~70%): 55+ tests for ES/OS constructors, write, query, health, stats + fix double-close panic in bulk indexer
  • Add middleware tenant tests (48 tests): context getters, RequireTenantRole, RequireInstanceAdmin, CtxWithTenant
  • Add E2E test for job retry with exponential backoff: verifies retry_count increments, scheduled_at backoff doubling, retry exhaustion
  • Add E2E test for SSRF protection: verifies AWS/GCP/K8s metadata endpoints blocked from Deno functions
  • Add E2E test for realtime WebSocket tenant isolation: 10 tests for broadcast, presence, subscription, and global broadcast tenant filtering

Test plan

  • go test -short ./internal/... — all pass
  • go build -tags integration ./test/e2e/... — compiles clean
  • go vet -tags integration ./test/e2e/... — clean
  • CI checks pass

bartcode added 8 commits May 10, 2026 22:26
- Replace globalResolver with Fiber Locals middleware + ServiceRegistry
- Move startTime from package-level var to MonitoringHandler.startTime field
- Move signedURLRateLimiter from package-level var to StorageHandler.signedURLLimiter field
…ill)

- declarative_test.go: 28 tests for DeclarativeService (config, paths, fingerprinting,
  plan guards, apply guards, status, temp file writing, content application, dump)
- bootstrap_keys_test.go: 15 tests for defaultScopes, defaultRateLimit, isNoRowsError
- backfill_test.go: 5 tests for buildJoinCondition (single/multi/triple column with spaces)
…ob retry

- knowledge_graph_test.go: tests for all 3 graph tools (metadata, schemas, execute guards)
- log_elasticsearch_test.go: 55+ tests for ES/OS constructors, write, query, health, stats
- log_elasticsearch.go: fix double-close panic in writeV8/writeV9 bulk indexer
- job_retry_test.go: E2E tests for exponential backoff, admin retry API, backoff doubling
…tenant tests

- ssrf_protection_test.go: 5 tests verifying blocked domains (AWS/GCP/K8s metadata)
  are unreachable from Deno functions, with public URL control test
- realtime_tenant_isolation_test.go: 10 tests for WebSocket broadcast/presence/
  subscription tenant filtering, REST endpoint scoping, global broadcast isolation
- tenant_test.go: 48 tests for TenantMiddleware context getters, RequireTenantRole,
  RequireInstanceAdmin, CtxWithTenant with header/JWT/default sources
…licate submitTestJob

- Rewrite realtime_tenant_isolation_test.go to use actual Manager API
  (AddConnection, Subscribe, BroadcastToChannel with sent count)
- Rename submitTestJob to submitRetryJob in job_retry_test.go to fix
  redeclaration conflict with jobs_get_test.go
- Fix job retry test to use correct endpoint /api/v1/jobs/submit
- Apply gofumpt formatting to storage_handler.go and knowledge_graph_test.go
… allowlist

- Fix markJobRunning to use worker_id=NULL instead of gen_random_uuid()
  which violated the fk_queue_worker foreign key constraint
- Rewrite SSRF protection tests to test the actual mechanism: when
  AllowedDomains is set, blocked domains are excluded from --allow-net
- Remove AWS/GCP metadata endpoint tests that fail in cloud CI where
  those endpoints are actually reachable
- Add test for explicit AllowedDomains allowlist enforcement
- Remove test that relied on AllowedDomains for edge functions (not
  supported — functions only use boolean allow_net, not per-domain)
- Add test for allow_net=false blocking network access
- Keep public URL control test that verifies normal fetch works
Edge functions always get --allow-net when SDK tokens are present
(UserToken/ServiceToken), regardless of the allow_net setting. SSRF
protection via BlockedDomains only works with explicit AllowedDomains
which edge functions don't support. The unit tests in
internal/runtime/types_test.go already cover this logic correctly.
@bartcode bartcode merged commit 3101d6f into main May 11, 2026
13 checks passed
@bartcode bartcode deleted the test-coverage-and-cleanup branch May 11, 2026 07:59
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.

1 participant