conflicttest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package conflicttest provides conflict scenario runners built on pkg/sync and pkg/conflict for tests.

Scenario wires two synctest.Device nodes, a synctest.MemHub with stale-base detection enabled, and conflict.NewDefaultEngine().

Typical flows:

  • Evaluate — run Detect and Merge for a local/base/current triple without sync I/O
  • RunStaleBaseConflict — seed a hub-side current version and assert AckConflicted + conflict records
  • RunTwoNodeStaleBaseConflict — push node B first, then assert node A conflicts on stale base
  • RunAutoMergeResolution — process a sync.conflict_processing job, resubmit the merged update, and assert the canonical event was created

DefaultConcurrentPatientEdits returns a standard non-overlapping patient edit triple (telecom vs address) suitable for auto-merge scenarios.

EnvelopeFromFields and LocalUpdate are low-level helpers for building conflict inputs without importing sync event types into unrelated tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnvelopeFromFields

func EnvelopeFromFields(resourceType, id, version string, fields map[string]any) (*types.ResourceEnvelope, error)

EnvelopeFromFields builds a normalized envelope from a field map.

func LocalUpdate

func LocalUpdate(resourceType, id, baseVersion, localVersion string, after *types.ResourceEnvelope) conflict.LocalEvent

LocalUpdate builds a conflict.LocalEvent for evaluation.

func StoreBackend

func StoreBackend(d *synctest.Device) *storetest.Backend

StoreBackend exposes storetest backend helpers for assertions.

Types

type EditNodes

type EditNodes struct {
	Base   *types.ResourceEnvelope
	LocalA *types.ResourceEnvelope
	LocalB *types.ResourceEnvelope
	Cloud  *types.ResourceEnvelope
}

EditNodes holds the two concurrent edit envelopes for a conflict scenario.

func DefaultConcurrentPatientEdits

func DefaultConcurrentPatientEdits() (EditNodes, error)

DefaultConcurrentPatientEdits returns a standard non-overlapping edit triple.

type Result

type Result struct {
	DetectResult    conflict.Result
	MergeResult     conflict.MergeResult
	PushSummary     *hasync.PushResultSummary
	Conflicts       []store.ConflictRecord
	CanonicalEvents []hasync.CanonicalEvent
	ResolutionPush  []hasync.PushResult
	CanonicalCount  int
	AuditRecords    []store.AuditRecord
	AutoMerged      bool
	NeedsReview     bool
}

Result captures conflict evaluation and sync artifacts.

type Scenario

type Scenario struct {
	Hub      *synctest.MemHub
	DeviceA  *synctest.Device
	DeviceB  *synctest.Device
	Engine   *conflict.Engine
	Clock    hasync.Clock
	TenantID string
}

Scenario runs conflict detection and optional resolution through sync + conflict.

func NewScenario

func NewScenario(tenantID string, clock hasync.Clock) *Scenario

NewScenario creates a conflict test scenario with stale-base detection enabled.

func (*Scenario) Evaluate

func (s *Scenario) Evaluate(local conflict.LocalEvent, base, current *types.ResourceEnvelope) Result

Evaluate runs conflict.Detect and conflict.Merge for a local edit triple.

func (*Scenario) RunAutoMergeResolution

func (s *Scenario) RunAutoMergeResolution(ctx context.Context, edits EditNodes) (*Result, error)

RunAutoMergeResolution processes a conflict job when the engine auto-merges.

func (*Scenario) RunStaleBaseConflict

func (s *Scenario) RunStaleBaseConflict(ctx context.Context, edits EditNodes) (*Result, error)

RunStaleBaseConflict seeds node A's edit against a newer hub version and pushes.

func (*Scenario) RunTwoNodeStaleBaseConflict

func (s *Scenario) RunTwoNodeStaleBaseConflict(ctx context.Context, edits EditNodes) (*Result, error)

RunTwoNodeStaleBaseConflict simulates the full two-device flow: node B edits and pushes first, then node A pushes a stale-base edit and conflicts.

Jump to

Keyboard shortcuts

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