syncharness

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Harness

type Harness struct {
	ProjectDBs map[string]*sql.DB
	Clients    map[string]*SimulatedClient

	Validator tdsync.EntityValidator
	// contains filtered or unexported fields
}

Harness orchestrates multi-client sync testing.

func NewHarness

func NewHarness(t *testing.T, numClients int, projectID string) *Harness

NewHarness creates a test harness with numClients and one server DB for projectID.

func (*Harness) AssertConverged

func (h *Harness) AssertConverged(projectID string)

AssertConverged verifies all clients have identical entity data.

func (*Harness) CountEntities

func (h *Harness) CountEntities(clientID, entityType string) int

CountEntities returns the number of rows in an entity table for a client.

func (*Harness) Diff

func (h *Harness) Diff(clientA, clientB string) string

Diff returns a human-readable diff of entity tables between two clients.

func (*Harness) Mutate

func (h *Harness) Mutate(clientID, actionType, entityType, entityID string, data map[string]any) error

Mutate performs a local mutation on a client's database and records it in action_log. For "delete" action: uses soft-delete on tables with deleted_at column (issues, board_issue_positions), hard delete on tables without it (issue_dependencies, issue_files, work_session_issues).

func (*Harness) Pull

func (h *Harness) Pull(clientID, projectID string) (tdsync.PullResult, error)

Pull fetches new events from the server and applies them to the client.

func (*Harness) PullAll

func (h *Harness) PullAll(clientID, projectID string) (tdsync.PullResult, error)

PullAll fetches all new events from the server (including own device) and applies them. This ensures convergence by replaying events in server-seq order regardless of origin.

func (*Harness) Push

func (h *Harness) Push(clientID, projectID string) (tdsync.PushResult, error)

Push sends pending events from a client to the server.

func (*Harness) PushWithoutMark

func (h *Harness) PushWithoutMark(clientID, projectID string) (tdsync.PushResult, error)

PushWithoutMark sends pending events to the server but skips MarkEventsSynced. This simulates a crash after the server accepts events but before the client records the acks.

func (*Harness) QueryEntity

func (h *Harness) QueryEntity(clientID, entityType, entityID string) map[string]any

QueryEntity reads a single entity from a client's DB, returning nil if not found. For soft-delete tables (issues, board_issue_positions), filters out rows where deleted_at is set.

func (*Harness) QueryEntityRaw

func (h *Harness) QueryEntityRaw(clientID, entityType, entityID string) map[string]any

QueryEntityRaw reads a single entity from a client's DB without soft-delete filtering. Use this when you need to verify soft-deleted rows exist (e.g., checking deleted_at is set).

func (*Harness) Sync

func (h *Harness) Sync(clientID, projectID string) error

Sync pushes then pulls for a client.

func (*Harness) UndoLastAction

func (h *Harness) UndoLastAction(clientID string) error

UndoLastAction simulates `td undo` for the last non-undone action on a client. It marks the action as undone=1 and inserts a compensating event:

  • "create" action → soft_delete event
  • "soft_delete" action → restore event (clears deleted_at)
  • "update" action → update event with previous_data fields

This mirrors the behavior of cmd/undo.go.

type SimulatedClient

type SimulatedClient struct {
	DeviceID         string
	SessionID        string
	DB               *sql.DB
	LastPushedAction int64
	LastPulledSeq    int64
}

SimulatedClient represents a single sync client with its own database.

Jump to

Keyboard shortcuts

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