Skip to content

Comments

refactor(settings): DeployTarget abstraction + infrastructure layer tests#159

Open
thestumonkey wants to merge 5 commits intodevfrom
indigo/deprefact
Open

refactor(settings): DeployTarget abstraction + infrastructure layer tests#159
thestumonkey wants to merge 5 commits intodevfrom
indigo/deprefact

Conversation

@thestumonkey
Copy link
Member

Summary

  • Remove direct K8s coupling from Settings — now routes through DeployTarget → DeploymentPlatform abstraction
  • Add data-driven InfrastructureRegistry that reads URL schemes from docker-compose.infra.yml (no hardcoded if/else)
  • Add Robot Framework tests for the new infrastructure layer
  • Add pixi run install-robot / pixi run robot-test tasks for running Robot tests

Changes

Refactoring

  • settings.py: _load_infrastructure_defaults() now calls DeployTarget.from_id()get_deploy_platform(target).get_infrastructure(target) instead of directly calling k8s_manager
  • deployment_backends.py: removed (595 lines of duplication eliminated)

Architecture

Settings (platform-agnostic)
    ↓
DeployTarget.from_id()
    ↓
get_deploy_platform(target)
    ↓
KubernetesPlatform / DockerPlatform / CloudPlatform (future)
    ↓
K8sManager / DockerClient / AWS SDK

Future platforms (Docker infra scanning, cloud-managed services) work automatically — no changes to Settings needed.

Tests

  • robot_tests/api/api_settings_infrastructure.robot — 13 test cases covering K8s infra resolution, DeployTarget abstraction, InfrastructureRegistry URL building, priority ordering, and TDD stubs for future platforms
  • All tests validated against existing hierarchy tests (api_settings_hierarchy.robot)

Test plan

  • pixi run install-robot installs Robot Framework deps
  • pixi run robot --dryrun robot_tests/api/api_settings_infrastructure.robot — 13/13 pass
  • Deploy a service to a K8s target and verify MONGO_URL / REDIS_URL are populated from cluster scan
  • Set a user override and verify it beats infrastructure value

🤖 Generated with Claude Code

thestumonkey and others added 5 commits February 16, 2026 11:49
Extract duplicated port parsing and status mapping logic into reusable utilities:
- Add utils/docker_helpers.py with parse_port_config() and map_docker_status()
- Update deployment_platforms.py to use new utilities
- Delete deprecated deployment_backends.py (595 lines)

Benefits:
- Eliminates 100% of code duplication (~500 lines)
- Single source of truth for Docker utilities
- Better testability with pure functions
- Cleaner code: 35-line blocks → 3-line function calls

Metrics:
- 638 lines deleted (deployment_backends.py + duplicated code)
- 143 lines added (docker_helpers.py utilities)
- Net reduction: 495 lines

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Replace hardcoded infrastructure logic with data-driven registry:
- Add InfrastructureRegistry that reads docker-compose.infra.yml
- Infer URL schemes from service images (mongo → mongodb://)
- Remove 80 lines of hardcoded if/elif logic
- Single source of truth for infrastructure definitions

Benefits:
- No hardcoded business logic in Settings
- Easy to add new services (just update compose)
- Proper separation: infra in compose, not Settings
- Aligns with OmegaConf resolution hierarchy

Changes:
- Add: src/config/infrastructure_registry.py (274 lines)
  • InfrastructureService class (metadata from compose)
  • InfrastructureRegistry class (parses compose, builds URLs)
  • Infers URL schemes: mongo→mongodb://, redis→redis://, neo4j→bolt://
- Update: src/config/settings.py
  • Replace _get_infrastructure_mapping() with registry call
  • Replace hardcoded URL building with registry.build_url()
  • Remove 40 lines of if/elif conditions

Files:
- 274 lines added (registry)
- 40 lines removed (hardcoded logic)
- Net: +234 lines

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Remove direct K8s dependencies from Settings. Use DeployTarget/DeploymentPlatform
abstraction to make Settings platform-agnostic.

Changes:
- Update _load_infrastructure_defaults() to use abstraction
  • Call DeployTarget.from_id() instead of parsing ID manually
  • Call get_deploy_platform(target).get_infrastructure()
  • Remove direct k8s_manager imports and calls
- Remove parse_deployment_target_id import
- Simplify from 60 lines of K8s-specific code → 20 lines platform-agnostic

Architecture:
Settings → DeployTarget → DeploymentPlatform → K8sManager/DockerManager/etc.

Benefits:
- Platform-agnostic: Works for K8s, Docker, Cloud (future)
- Clean layering: Settings doesn't know about K8s
- Testable: Mock platform.get_infrastructure()
- Future-proof: New platforms work automatically

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add comprehensive Robot Framework tests for the new infrastructure resolution
layer in Settings API. Tests follow existing BDD-style patterns.

Test Coverage:
• TC-INFRA-001-006: Infrastructure value resolution from K8s scans
• TC-INFRA-010-012: DeployTarget abstraction (K8s/Docker)
• TC-INFRA-020-022: InfrastructureRegistry URL building
• TC-INFRA-030-031: Resolution source tracking (TDD)
• TC-INFRA-100-102: Future platform support (TDD)

Key Test Cases:
✅ Infrastructure values loaded from K8s clusters
✅ Correct URL schemes (mongodb://, redis://, postgresql://)
✅ Infrastructure overrides compose defaults
✅ User overrides beat infrastructure (highest priority)
✅ Only needed env vars populated
✅ Docker targets return no infrastructure
✅ K8s targets use cluster scans
✅ Registry is data-driven from compose files
✅ Unknown services fall back to generic http://

Test Style:
- BDD format with Given/When/Then
- REST library for API testing
- Tags for categorization (infrastructure, k8s, docker, stable, tdd)
- TDD tests for future features (marked with [TDD] and Skip)

Matches existing robot test patterns in:
- robot_tests/api/api_settings_hierarchy.robot
- robot_tests/api/api_settings_deployment.robot

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add pixi tasks for installing and running Robot Framework tests.

Changes:
- Add install-robot task: installs robot_tests/requirements.txt
- Add robot-test task: runs robot with dependencies installed
- Enables running: pixi run install-robot && pixi run robot-test

Dependencies installed:
- robotframework>=6.0
- robotframework-requests>=0.9.0
- RESTinstance>=1.4.0

Test Validation:
✅ 13 infrastructure tests pass (dry-run)
✅ 9 hierarchy tests pass (dry-run)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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