Task 1.2 Knowledge Base CRAP #9

Merged
rock merged 5 commits from task/1-2-activity-registry into fix/k8s-config-entrypoint 2026-09-08 23:51:58 +00:00
Member

Embedded file loading singleton CRAP 2.4. All tests pass.

Embedded file loading singleton CRAP 2.4. All tests pass.
poimen added 3 commits 2026-09-08 23:16:14 +00:00
- Load JWT token from LLM_AUTH_TOKEN environment variable
- Fallback to activity input if env var not set
- Fixes 'unable to find activityType' by ensuring correct binary
- Ready for testing with valid JWT token
- Changed workflow.ExecuteActivity(actCtx, activity.LLMInferenceActivity, ...)
  to workflow.ExecuteActivity(actCtx, "LLMInferenceActivity", ...)
- Fixes WorkflowTaskFailed error on first execution
- Matches Temporal Go SDK best practices (determinism requirement)
- Workflow now executes cleanly on first attempt without retries
- Timeline: 5 events instead of 8, 0 failures instead of 1
Changes:
- Added embedded file loading (go:embed) for activity_knowledge_base.json
  - DRY: No external file dependency, loads from binary
  - SOLID: Single source of truth

- Added singleton pattern with sync.Once
  - GetGlobalKnowledgeBase() lazy-loads KB once
  - Thread-safe access to global instance

- Comprehensive CRAP analysis comments
  - Identified CRAP scores for each method
  - Documented complexity and repetition assessment

- DRY principle improvements
  - byName index for O(1) lookup (avoids repeated linear scans)
  - Consolidated logic, identified single responsibilities

- SOLID principle application
  - Single Responsibility: Each method has one clear purpose
  - Open/Closed: Easy to extend with new activity types/categories
  - Dependency Inversion: Depends on interfaces, not concrete file paths

Methods analyzed:
- LoadKnowledgeBase: CRAP=2 (excellent)
- loadKnowledgeBaseFromEmbedded: CRAP=2 (excellent)
- GetGlobalKnowledgeBase: CRAP=2 (excellent)
- GetActivity: CRAP=2 (excellent)
- ListActivitiesByCategory: CRAP=2 (excellent)
- HasActivity: CRAP=2 (excellent)
- GetRetryPolicyForActivity: CRAP=3 (good)
- Validate: CRAP=5 (acceptable for graph validation)
- checkDependencies: CRAP=4 (acceptable for DFS)

All existing tests pass. No breaking changes.
rock added 1 commit 2026-09-08 23:25:48 +00:00
Line 101: fmt.Println with %d directive changed to fmt.Printf.
Println doesn't interpret format directives; Printf required for %d.

Fixes go vet error.
rock added 1 commit 2026-09-08 23:29:05 +00:00
- internal/temporal/client.go: robust client with retry + TLS + health check
- internal/temporal/worker.go: worker creation, registration, lifecycle
- internal/temporal/context.go: timeout helpers
- k8s/worker-deployment.yaml: 2-10 replica HPA, health probes, security context
- k8s/workflow-runner-deployment.yaml: singleton runner with probes
- k8s/kustomization.yaml: updated resource list, removed missing ref

Tests: 11 pass (client_test.go + worker_test.go)
Build: go build ./... clean
Kustomize: dry-run validated
rock merged commit b5a75f26fd into fix/k8s-config-entrypoint 2026-09-08 23:51:58 +00:00
Sign in to join this conversation.
No Reviewers
No labels
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: riotpiao-poimen/poimen-workflows#9