api

package
v0.1.49 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultBaseURL is the default Tusk Cloud API URL
	DefaultBaseURL = "https://api.usetusk.ai"

	TestRunServiceAPIPath    = "/api/drift/test_run_service"
	ClientServiceAPIPath     = "/api/drift/client_service"
	SpanExportServiceAPIPath = "/api/drift/tusk.drift.backend.v1.SpanExportService"
)

Variables

View Source
var (
	ErrFetchTraceTests          = errors.New("unable to fetch tests from Tusk Cloud")
	ErrFetchTraceTestIDs        = errors.New("unable to fetch test IDs from Tusk Cloud and no cache available")
	ErrFetchNewTraceTests       = errors.New("unable to fetch new tests from Tusk Cloud")
	ErrFetchPreAppStartSpanIDs  = errors.New("unable to fetch pre-app-start span IDs from Tusk Cloud and no cache available")
	ErrFetchNewPreAppStartSpans = errors.New("unable to fetch new pre-app-start spans from Tusk Cloud")
	ErrFetchPreAppStartSpans    = errors.New("unable to fetch pre-app-start spans from Tusk Cloud")
	ErrFetchGlobalSpanIDs       = errors.New("unable to fetch global span IDs from Tusk Cloud and no cache available")
	ErrFetchNewGlobalSpans      = errors.New("unable to fetch new global spans from Tusk Cloud")
	ErrFetchGlobalSpans         = errors.New("unable to fetch global spans from Tusk Cloud")
)

Functions

func FetchAllGlobalSpans added in v0.1.49

func FetchAllGlobalSpans(
	ctx context.Context,
	client *TuskClient,
	auth AuthOptions,
	serviceID string,
) ([]*core.Span, error)

FetchAllGlobalSpans fetches all global spans without caching (fallback).

func FetchAllPreAppStartSpans added in v0.1.49

func FetchAllPreAppStartSpans(
	ctx context.Context,
	client *TuskClient,
	auth AuthOptions,
	serviceID string,
) ([]*core.Span, error)

FetchAllPreAppStartSpans fetches all pre-app-start spans without caching (fallback).

func FetchAllTraceTests added in v0.1.43

func FetchAllTraceTests(
	ctx context.Context,
	client *TuskClient,
	auth AuthOptions,
	serviceID string,
	opts *FetchAllTraceTestsOptions,
) ([]*backend.TraceTest, error)

FetchAllTraceTests fetches all trace tests from the cloud with a progress bar. This is the shared implementation used by both `tusk list -c` and `tusk run -c`.

func FetchAllTraceTestsWithCache added in v0.1.49

func FetchAllTraceTestsWithCache(
	ctx context.Context,
	client *TuskClient,
	auth AuthOptions,
	serviceID string,
	interactive bool,
	quiet bool,
) ([]*backend.TraceTest, error)

FetchAllTraceTestsWithCache fetches trace tests using ID-based cache diffing. It only fetches new traces and removes deleted ones from cache. On network error, it falls back to cached data if available.

func FetchDriftRunTraceTests added in v0.1.43

func FetchDriftRunTraceTests(
	ctx context.Context,
	client *TuskClient,
	auth AuthOptions,
	driftRunID string,
	opts *FetchAllTraceTestsOptions,
) ([]*backend.TraceTest, error)

FetchDriftRunTraceTests fetches trace tests for a specific drift run with a progress bar.

func FetchGlobalSpansWithCache added in v0.1.49

func FetchGlobalSpansWithCache(
	ctx context.Context,
	client *TuskClient,
	auth AuthOptions,
	serviceID string,
	interactive bool,
	quiet bool,
) ([]*core.Span, error)

FetchGlobalSpansWithCache fetches global spans using ID-based cache diffing. It only fetches new spans and removes deleted ones from cache. On network error, it falls back to cached data if available.

func FetchPreAppStartSpansWithCache added in v0.1.49

func FetchPreAppStartSpansWithCache(
	ctx context.Context,
	client *TuskClient,
	auth AuthOptions,
	serviceID string,
	interactive bool,
	quiet bool,
) ([]*core.Span, error)

FetchPreAppStartSpansWithCache fetches pre-app-start spans using ID-based cache diffing. It only fetches new spans and removes deleted ones from cache. On network error, it falls back to cached data if available.

func GetBaseURL added in v0.1.23

func GetBaseURL() string

GetBaseURL returns the API base URL with the following priority: 1. TUSK_CLOUD_API_URL environment variable 2. tusk_api.url from .tusk/config.yaml 3. Default URL (https://api.usetusk.ai)

func IsNoSeatError added in v0.1.47

func IsNoSeatError(err error) bool

IsNoSeatError checks if an error is a NoSeatError

func IsPausedByLabelError added in v0.1.49

func IsPausedByLabelError(err error) bool

IsPausedByLabelError checks if an error is a PausedByLabelError

func SetupCloud

func SetupCloud(ctx context.Context, requireServiceID bool) (*TuskClient, AuthOptions, *config.Config, error)

Types

type AuthOptions

type AuthOptions struct {
	APIKey       string
	BearerToken  string
	TuskClientID string
}

type Deviation

type Deviation struct {
	Type        string `json:"type"`
	Field       string `json:"field"`
	Expected    any    `json:"expected"`
	Actual      any    `json:"actual"`
	Description string `json:"description"`
	Severity    string `json:"severity"`
}

type FetchAllTraceTestsOptions added in v0.1.43

type FetchAllTraceTestsOptions struct {
	// Message to show in the progress bar
	Message string
	// PageSize for pagination (default 25)
	PageSize int32
}

FetchAllTraceTestsOptions configures the fetch behavior

type MockInteraction

type MockInteraction struct {
	Service   string           `json:"service"`
	Request   RecordedRequest  `json:"request"`
	Response  RecordedResponse `json:"response"`
	Order     int              `json:"order"`
	Timestamp time.Time        `json:"timestamp"`
}

type NoSeatError added in v0.1.47

type NoSeatError struct {
	Message string
}

NoSeatError is returned when the PR creator doesn't have a Tusk Cloud seat

func (*NoSeatError) Error added in v0.1.47

func (e *NoSeatError) Error() string

type PausedByLabelError added in v0.1.49

type PausedByLabelError struct {
	Message string
}

PausedByLabelError is returned when the PR has the "Tusk - Pause For Current PR" label

func (*PausedByLabelError) Error added in v0.1.49

func (e *PausedByLabelError) Error() string

type RecordedRequest

type RecordedRequest struct {
	Method  string              `json:"method"`
	Path    string              `json:"path"`
	Headers map[string][]string `json:"headers"`
	Body    any                 `json:"body,omitempty"`
	Query   map[string][]string `json:"query,omitempty"`
}

type RecordedResponse

type RecordedResponse struct {
	Status  int                 `json:"status"`
	Headers map[string][]string `json:"headers"`
	Body    any                 `json:"body,omitempty"`
}

type RetryConfig added in v0.1.14

type RetryConfig struct {
	MaxRetries  int
	BaseBackoff time.Duration
	MaxBackoff  time.Duration
	JitterMin   float64
	JitterMax   float64
}

func DefaultRetryConfig added in v0.1.14

func DefaultRetryConfig(maxRetries int) RetryConfig

DefaultRetryConfig returns normal retry configuration

func FastRetryConfig added in v0.1.14

func FastRetryConfig(maxRetries int) RetryConfig

FastRetryConfig returns retry configuration for testing

type TestRecording

type TestRecording struct {
	ID        string            `json:"id"`
	ServiceID string            `json:"service_id"`
	TraceID   string            `json:"trace_id"`
	Method    string            `json:"method"`
	Path      string            `json:"path"`
	Request   RecordedRequest   `json:"request"`
	Response  RecordedResponse  `json:"response"`
	Mocks     []MockInteraction `json:"mocks"`
	Timestamp time.Time         `json:"timestamp"`
	Metadata  map[string]any    `json:"metadata"`
}

type TestResult

type TestResult struct {
	TestID      string      `json:"test_id"`
	ServiceID   string      `json:"service_id"`
	Passed      bool        `json:"passed"`
	Duration    int         `json:"duration_ms"`
	Deviations  []Deviation `json:"deviations,omitempty"`
	Error       string      `json:"error,omitempty"`
	ExecutedAt  time.Time   `json:"executed_at"`
	Environment string      `json:"environment"`
}

type TuskClient

type TuskClient struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(baseURL, apiKey string) *TuskClient

func (*TuskClient) CreateApiKey added in v0.1.19

func (*TuskClient) CreateDriftRun

func (c *TuskClient) CreateDriftRun(ctx context.Context, in *backend.CreateDriftRunRequest, auth AuthOptions) (string, error)

func (*TuskClient) CreateObservableService added in v0.1.19

func (*TuskClient) ExportSpans added in v0.1.46

ExportSpans uploads spans to Tusk Cloud

func (*TuskClient) GetAllGlobalSpanIds added in v0.1.49

GetAllGlobalSpanIds fetches all global span IDs for a service (lightweight, no pagination).

func (*TuskClient) GetAllPreAppStartSpanIds added in v0.1.49

GetAllPreAppStartSpanIds fetches all pre-app-start span IDs for a service (lightweight, no pagination).

func (*TuskClient) GetAllTraceTestIds added in v0.1.49

GetAllTraceTestIds fetches all trace test IDs for a service (lightweight, no pagination).

func (*TuskClient) GetAuthInfo added in v0.1.17

func (*TuskClient) GetGlobalSpansByIds added in v0.1.49

GetGlobalSpansByIds fetches global spans by their IDs (batch fetch).

func (*TuskClient) GetObservableServiceInfo added in v0.1.31

GetObservableServiceInfo fetches observable service info including default branch

func (*TuskClient) GetPreAppStartSpansByIds added in v0.1.49

GetPreAppStartSpansByIds fetches pre-app-start spans by their IDs (batch fetch).

func (*TuskClient) GetTraceTestsByIds added in v0.1.49

GetTraceTestsByIds fetches trace tests by their IDs (batch fetch).

func (*TuskClient) GetValidationTraceTests added in v0.1.31

GetValidationTraceTests fetches traces for validation (both DRAFT and IN_SUITE)

func (*TuskClient) UpdateDriftRunCIStatus

func (c *TuskClient) UpdateDriftRunCIStatus(ctx context.Context, in *backend.UpdateDriftRunCIStatusRequest, auth AuthOptions) error

func (*TuskClient) UploadTraceTestResults

func (c *TuskClient) UploadTraceTestResults(ctx context.Context, in *backend.UploadTraceTestResultsRequest, auth AuthOptions) error

func (*TuskClient) VerifyRepoAccess added in v0.1.19

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL