A Go client library for communicating with the Harness Test Intelligence (TI) service. This client is designed to be imported and used by other Harness codebases such as harness-core and lite-engine, where binaries like lite-engine communicate with the ti-service backend.
The ti-client provides a comprehensive interface for interacting with the TI service, enabling test intelligence features such as:
- Intelligent Test Selection: Automatically select tests to run based on code changes
- Callgraph Management: Upload and manage code callgraphs to track test dependencies
- Test Result Reporting: Write test execution results back to the TI service
- ML-Based Test Selection: Leverage machine learning models for optimized test selection
- Time Savings Tracking: Track and report time savings from various intelligence features
- Agent Management: Download test intelligence agent artifacts
The TI service (located in the harness-ti repository) provides the backend API, while this client library enables Go applications to interact with it. The client is typically used by:
- lite-engine: The execution engine that runs CI/CD steps
- harness-core: Core Harness platform components
ti-client/
├── client/ # HTTP client implementation
│ ├── client.go # Client interface definition
│ └── http.go # HTTP client implementation with retry logic, mTLS support
├── types/ # Core type definitions
│ ├── types.go # Test cases, selection requests/responses, telemetry
│ ├── savings.go # Savings tracking types (build cache, TI, DLC)
│ └── cache/ # Cache-related types (buildcache, dlc, gradle, maven)
├── chrysalis/ # V2 API types (newer API version)
│ └── types/ # V2 types for uploadcg, skip tests, etc.
└── clientUtils/ # Utility functions
└── telemetryUtils/ # Telemetry helper functions
- SelectTests: Intelligently select tests to run based on source code changes, new tests, updated tests, and previous failures
- MLSelectTests: Use machine learning models for advanced test selection
- GetSkipTests: Determine which tests can be skipped based on file checksums
- UploadCg: Upload Avro-encoded callgraphs to track code dependencies
- UploadCgV2: Upload JSON-encoded callgraphs using the newer V2 API
- UploadCgFailedTest: Upload callgraphs for failed tests without updating last successful commit
- Write: Write test execution results to the TI service
- GetTestCases: Retrieve test cases executed in a build with pagination and filtering
- Summary: Get test execution summary (total, passed, failed, skipped tests)
- GetTestTimes: Retrieve historical test timing data
- WriteSavings: Track time savings from various intelligence features:
- Build Cache
- Test Intelligence
- Docker Layer Caching (DLC)
- DownloadLink: Get download links for TI agent artifacts
- CommitInfo: Get commit information for the last successful commit with callgraph
- Healthz: Health check endpoint for service availability
- DownloadAgent: Download agent files from remote storage
The client supports several security configurations:
-
mTLS (Mutual TLS): Client certificate authentication
- Supports base64-encoded certificates or file paths
- Default paths:
/etc/mtls/client.crtand/etc/mtls/client.key
-
Custom Root CAs: Load additional root certificates from a directory
-
TLS Verification: Configurable TLS verification (useful for development/testing)
The client includes built-in retry logic with exponential backoff for:
- Network errors
- Server errors (5xx status codes)
- Configurable maximum elapsed time per operation
Different operations have different retry timeouts:
- Test selection: 10 minutes
- Callgraph upload: 45 minutes
- Test result writing: 10 minutes
- Agent download: 5 minutes
The client expects the following environment variables (defined in types/types.go):
HARNESS_ACCOUNT_ID: Harness account IDHARNESS_ORG_ID: Organization IDHARNESS_PROJECT_ID: Project IDHARNESS_PIPELINE_ID: Pipeline IDHARNESS_STAGE_ID: Stage IDHARNESS_STEP_ID: Step IDHARNESS_BUILD_ID: Build IDHARNESS_TI_SERVICE_ENDPOINT: TI service endpoint URLHARNESS_TI_SERVICE_TOKEN: Authentication token for TI service
github.com/cenkalti/backoff: Exponential backoff for retriesgithub.com/cespare/xxhash/v2: Hashing utilitiesgo.mongodb.org/mongo-driver: MongoDB driver (for BSON types in chrysalis)
- harness-ti: The TI service backend that this client communicates with
- harness-core: Core Harness platform (uses this client)
- lite-engine: Execution engine (uses this client)