upload

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIClient

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

APIClient handles communication with the QA backend server. It's responsible for creating run records and requesting presigned URLs.

func NewAPIClient

func NewAPIClient(baseURL, authToken, projectID string) *APIClient

NewAPIClient constructs a client for the QA backend API.

func (*APIClient) ConfirmUpload

func (c *APIClient) ConfirmUpload(ctx context.Context, remoteRunID string, artifact core.Artifact) error

ConfirmUpload tells the backend that an artifact was successfully uploaded. Note: Backend expects batch format, so we wrap the single artifact in an array.

func (*APIClient) CreateRun

func (c *APIClient) CreateRun(ctx context.Context, run *core.Run) (string, error)

CreateRun registers a new run with the QA backend and returns the server-assigned ID.

func (*APIClient) GetPresignedURL

func (c *APIClient) GetPresignedURL(ctx context.Context, remoteRunID string, artifact core.Artifact) (*ArtifactPresignResponse, error)

GetPresignedURL requests a presigned URL for uploading a single artifact. Note: Backend expects batch format, so we wrap the single artifact in an array.

type ArtifactConfirmRequest

type ArtifactConfirmRequest struct {
	ArtifactID     string    `json:"artifact_id"` // Backend-assigned ULID (required!)
	Filename       string    `json:"filename"`    // Changed from file_name to match backend
	ChecksumSHA256 string    `json:"checksum_sha256"`
	UploadedAt     time.Time `json:"uploaded_at"`
}

ArtifactConfirmRequest represents a single artifact in the confirm request.

type ArtifactPresignRequest

type ArtifactPresignRequest struct {
	Filename       string `json:"filename"` // Changed from file_name to match backend
	Role           string `json:"role"`     // Required by backend (manifest, data, log, etc.)
	ContentType    string `json:"content_type"`
	SizeBytes      int64  `json:"size_bytes"`
	ChecksumSHA256 string `json:"checksum_sha256"`
	Source         string `json:"source,omitempty"` // Optional, defaults to "cli"
}

ArtifactPresignRequest represents a single artifact in the presign request.

type ArtifactPresignResponse

type ArtifactPresignResponse struct {
	ArtifactID string            `json:"artifact_id"`          // Backend-assigned ULID
	URL        string            `json:"url,omitempty"`        // Presigned URL (empty if existing)
	Method     string            `json:"method,omitempty"`     // Usually "PUT"
	Headers    map[string]string `json:"headers,omitempty"`    // Additional headers required
	ExpiresAt  string            `json:"expires_at,omitempty"` // ISO timestamp
	Status     string            `json:"status,omitempty"`     // "existing" if artifact already uploaded
}

ArtifactPresignResponse represents a single artifact in the presign response.

type Client

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

Client orchestrates the full upload process: 1. Load run metadata from disk 2. Create run record on server 3. Request presigned URLs for each artifact 4. Upload files with retry 5. Confirm successful uploads 6. Update local state

func NewClient

func NewClient(cfg Config) *Client

NewClient constructs an upload client from configuration.

func (*Client) UploadRun

func (c *Client) UploadRun(ctx context.Context, runID string) error

UploadRun uploads a single run and all its artifacts to the server.

type Config

type Config struct {
	APIURL     string
	AuthToken  string
	ProjectID  string
	CacheRoot  string
	MaxRetries int
}

Config holds the settings needed to create an upload client.

type ConfirmUploadRequest

type ConfirmUploadRequest struct {
	Artifacts []ArtifactConfirmRequest `json:"artifacts"`
}

ConfirmUploadRequest notifies the backend that artifact uploads completed (batch format).

type CreateRunRequest

type CreateRunRequest struct {
	ProjectID    string               `json:"project_id"`
	Manifest     core.Manifest        `json:"manifest"`
	Source       core.SourceMeta      `json:"source"`
	Capture      core.CaptureSettings `json:"capture"`
	StartedAt    time.Time            `json:"started_at"`
	Completed    *time.Time           `json:"completed_at,omitempty"`
	RecordsCount uint64               `json:"records_count"`
}

CreateRunRequest is sent to the backend to initialize a new run record.

type CreateRunResponse

type CreateRunResponse struct {
	RunID string `json:"run_id"`
}

CreateRunResponse contains the server-assigned run ID.

type MockUploadCall

type MockUploadCall struct {
	RunID string
	Error error
}

MockUploadCall records a single call to UploadRun

type MockUploadClient

type MockUploadClient struct {

	// UploadFunc is called when UploadRun is invoked
	// If nil, returns success by default
	UploadFunc func(ctx context.Context, runID string) error

	// Calls tracks all calls to UploadRun
	Calls []MockUploadCall

	// Results maps runID to predetermined results
	// Useful for testing specific scenarios
	Results map[string]error
	// contains filtered or unexported fields
}

MockUploadClient is a mock implementation of UploadClient for testing. It allows developers to simulate upload success, failure, and delays.

func NewMockUploadClient

func NewMockUploadClient() *MockUploadClient

NewMockUploadClient creates a new mock upload client.

func (*MockUploadClient) CallCount

func (m *MockUploadClient) CallCount() int

CallCount returns the number of times UploadRun was called.

func (*MockUploadClient) CalledWith

func (m *MockUploadClient) CalledWith(runID string) bool

CalledWith returns true if UploadRun was called with the given runID.

func (*MockUploadClient) Reset

func (m *MockUploadClient) Reset()

Reset clears all recorded calls.

func (*MockUploadClient) SetError

func (m *MockUploadClient) SetError(runID string, errMsg string)

SetError is a convenience method to set an error result.

func (*MockUploadClient) SetResult

func (m *MockUploadClient) SetResult(runID string, err error)

SetResult configures a predetermined result for a specific runID.

func (*MockUploadClient) SetSuccess

func (m *MockUploadClient) SetSuccess(runID string)

SetSuccess is a convenience method to set a success result.

func (*MockUploadClient) UploadRun

func (m *MockUploadClient) UploadRun(ctx context.Context, runID string) error

UploadRun implements UploadClient.

type PresignedURLRequest

type PresignedURLRequest struct {
	Artifacts []ArtifactPresignRequest `json:"artifacts"`
}

PresignedURLRequest asks the server for presigned URLs (batch format).

type PresignedURLResponse

type PresignedURLResponse struct {
	Artifacts []ArtifactPresignResponse `json:"artifacts"`
}

PresignedURLResponse contains the batch response from the backend.

type UploadClient

type UploadClient interface {
	UploadRun(ctx context.Context, runID string) error
}

UploadClient defines the interface for uploading runs. This allows for easy mocking in tests.

type UploadResult

type UploadResult struct {
	Artifact   core.Artifact
	Success    bool
	Attempts   int
	Error      error
	UploadedAt *time.Time
}

UploadResult tracks the outcome of an upload attempt.

type Uploader

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

Uploader handles the actual file upload to presigned URLs with retry logic.

func NewUploader

func NewUploader(maxRetries int) *Uploader

NewUploader creates an uploader with configurable retry behavior.

func (*Uploader) Upload

func (u *Uploader) Upload(ctx context.Context, artifact core.Artifact, presignedURL *ArtifactPresignResponse) (*UploadResult, error)

Upload uploads a single file to a presigned URL with automatic retry and exponential backoff. This is where the "resilience" happens - network failures are expected and handled gracefully.

Jump to

Keyboard shortcuts

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