Help us shape the future of Go! Take the 2026 Go Developer Survey

integration

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package integration provides integration testing utilities for staghorn.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplySetup

func ApplySetup(env *TestEnv, setup FixtureSetup) error

ApplySetup applies the fixture setup to a test environment.

Types

type Asserter

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

Asserter provides assertion helpers for CLAUDE.md output.

func NewAsserter

func NewAsserter(t *testing.T, content string) *Asserter

NewAsserter creates an asserter for the given content.

func (*Asserter) ContainsSection

func (a *Asserter) ContainsSection(header string) bool

ContainsSection checks if a ## section header exists.

func (*Asserter) ContainsText

func (a *Asserter) ContainsText(text string) bool

ContainsText checks if the content contains a substring.

func (*Asserter) GetContent

func (a *Asserter) GetContent() string

GetContent returns the raw content.

func (*Asserter) HasManagedHeader

func (a *Asserter) HasManagedHeader() bool

HasManagedHeader checks for "<!-- Managed by staghorn" header.

func (*Asserter) HasProvenanceMarker

func (a *Asserter) HasProvenanceMarker(source string) bool

HasProvenanceMarker checks for a specific provenance marker.

func (*Asserter) HasSourceRepo

func (a *Asserter) HasSourceRepo(repo string) bool

HasSourceRepo checks if the header contains the expected source repo.

func (*Asserter) ProvenanceOrder

func (a *Asserter) ProvenanceOrder() []string

ProvenanceOrder returns the layers in order of appearance.

func (*Asserter) RunAssertions

func (a *Asserter) RunAssertions(assertions FixtureAssertions)

RunAssertions runs all assertions from a fixture definition.

type ConfigSetup

type ConfigSetup struct {
	Version   int             `yaml:"version"`
	Source    interface{}     `yaml:"source"` // Can be string or SourceConfigSetup
	Languages *LanguagesSetup `yaml:"languages"`
}

ConfigSetup defines the staghorn config.yaml content.

func (*ConfigSetup) ToConfig

func (c *ConfigSetup) ToConfig() *config.Config

ToConfig converts fixture config setup to a config.Config. It logs warnings for malformed or missing fields in the source configuration.

type Fixture

type Fixture struct {
	Name        string            `yaml:"name"`
	Description string            `yaml:"description"`
	Setup       FixtureSetup      `yaml:"setup"`
	Assertions  FixtureAssertions `yaml:"assertions"`
}

Fixture represents a test scenario loaded from YAML.

func LoadAllFixtures

func LoadAllFixtures(dir string) ([]*Fixture, error)

LoadAllFixtures loads all fixtures from a directory.

func LoadFixture

func LoadFixture(path string) (*Fixture, error)

LoadFixture loads a fixture from a YAML file.

func (*Fixture) Validate

func (f *Fixture) Validate() error

Validate checks that the fixture has all required fields.

type FixtureAssertions

type FixtureAssertions struct {
	OutputExists bool             `yaml:"output_exists"`
	Header       *HeaderAssertion `yaml:"header"`
	Provenance   *ProvenanceCheck `yaml:"provenance"`
	Contains     []string         `yaml:"contains"`
	NotContains  []string         `yaml:"not_contains"`
	Sections     []string         `yaml:"sections"`
	Languages    []LanguageCheck  `yaml:"languages"`
}

FixtureAssertions defines what to verify.

type FixtureSetup

type FixtureSetup struct {
	Team        *TeamSetup        `yaml:"team"`
	MultiSource []MultiSourceRepo `yaml:"multi_source,omitempty"`
	Personal    *PersonalSetup    `yaml:"personal"`
	Config      *ConfigSetup      `yaml:"config"`
}

FixtureSetup defines the test environment setup.

type HeaderAssertion

type HeaderAssertion struct {
	ManagedBy  bool   `yaml:"managed_by"`
	SourceRepo string `yaml:"source_repo"`
}

HeaderAssertion checks the staghorn header.

type LanguageCheck

type LanguageCheck struct {
	Name               string   `yaml:"name"`
	HasTeamContent     bool     `yaml:"has_team_content"`
	HasPersonalContent bool     `yaml:"has_personal_content"`
	Contains           []string `yaml:"contains"`
}

LanguageCheck verifies language section content.

type LanguagesSetup

type LanguagesSetup struct {
	Enabled  []string `yaml:"enabled"`
	Disabled []string `yaml:"disabled"`
}

LanguagesSetup defines language configuration.

type MultiSourceRepo

type MultiSourceRepo struct {
	Source    string            `yaml:"source"`
	ClaudeMD  string            `yaml:"claude_md,omitempty"`
	Languages map[string]string `yaml:"languages,omitempty"`
	Commands  map[string]string `yaml:"commands,omitempty"`
}

MultiSourceRepo defines content from a specific repository in multi-source setup.

type PersonalSetup

type PersonalSetup struct {
	PersonalMD string            `yaml:"personal_md"`
	Languages  map[string]string `yaml:"languages"`
}

PersonalSetup defines personal config files.

type ProvenanceCheck

type ProvenanceCheck struct {
	HasTeam     bool     `yaml:"has_team"`
	HasPersonal bool     `yaml:"has_personal"`
	Order       []string `yaml:"order"`
}

ProvenanceCheck verifies provenance markers.

type SourceConfigSetup

type SourceConfigSetup struct {
	Default   string            `yaml:"default"`
	Base      string            `yaml:"base,omitempty"`
	Languages map[string]string `yaml:"languages,omitempty"`
	Commands  map[string]string `yaml:"commands,omitempty"`
}

SourceConfigSetup defines multi-source configuration in fixtures.

type TeamSetup

type TeamSetup struct {
	Source    string            `yaml:"source"`
	ClaudeMD  string            `yaml:"claude_md"`
	Languages map[string]string `yaml:"languages"`
}

TeamSetup simulates the team repo content.

type TestEnv

type TestEnv struct {
	RootDir   string        // t.TempDir() root
	HomeDir   string        // Simulated $HOME
	ConfigDir string        // ~/.config/staghorn
	CacheDir  string        // ~/.cache/staghorn
	ClaudeDir string        // ~/.claude
	Paths     *config.Paths // Configured paths pointing to temp dirs
	// contains filtered or unexported fields
}

TestEnv provides an isolated test environment with overridden paths.

func NewTestEnv

func NewTestEnv(t *testing.T) *TestEnv

NewTestEnv creates an isolated test environment. All paths are configured to use temporary directories.

func (*TestEnv) Cleanup

func (e *TestEnv) Cleanup()

Cleanup is a no-op retained for API compatibility. Temporary directories are automatically cleaned up by t.TempDir().

func (*TestEnv) GetClaudeRulesDir

func (e *TestEnv) GetClaudeRulesDir() string

GetClaudeRulesDir returns the path to ~/.claude/rules.

func (*TestEnv) GetClaudeSkillsDir

func (e *TestEnv) GetClaudeSkillsDir() string

GetClaudeSkillsDir returns the path to ~/.claude/skills.

func (*TestEnv) GetOutputPath

func (e *TestEnv) GetOutputPath() string

GetOutputPath returns the path to ~/.claude/CLAUDE.md.

func (*TestEnv) ReadClaudeRule

func (e *TestEnv) ReadClaudeRule(relPath string) (string, error)

ReadClaudeRule reads a rule from ~/.claude/rules.

func (*TestEnv) ReadClaudeSkill

func (e *TestEnv) ReadClaudeSkill(skillName string) (string, error)

ReadClaudeSkill reads SKILL.md from ~/.claude/skills/<name>/.

func (*TestEnv) ReadClaudeSkillFile

func (e *TestEnv) ReadClaudeSkillFile(skillName, relPath string) (string, error)

ReadClaudeSkillFile reads a supporting file from a Claude skill directory.

func (*TestEnv) ReadOutput

func (e *TestEnv) ReadOutput() (string, error)

ReadOutput reads the final CLAUDE.md output.

func (*TestEnv) RunMultiSourceSync

func (e *TestEnv) RunMultiSourceSync(cfg *config.Config) error

RunMultiSourceSync executes the merge for multi-source configurations. It reads the base config from the base repo and languages from their respective repos.

func (*TestEnv) RunSync

func (e *TestEnv) RunSync(owner, repo string, cfg *config.Config) error

RunSync executes the merge and write operation with the current test environment. This replicates the core logic of applyConfig without the interactive prompts.

func (*TestEnv) RunSyncRules

func (e *TestEnv) RunSyncRules(owner, repo string) (int, error)

RunSyncRules syncs rules from team/personal sources to Claude rules directory.

func (*TestEnv) RunSyncSkills

func (e *TestEnv) RunSyncSkills(owner, repo string) (int, error)

RunSyncSkills syncs skills from team/personal sources to Claude skills directory.

func (*TestEnv) RunSyncSkillsMultiSource

func (e *TestEnv) RunSyncSkillsMultiSource(cfg *config.Config) (int, error)

RunSyncSkillsMultiSource syncs skills from multiple source repos.

func (*TestEnv) SetupConfig

func (e *TestEnv) SetupConfig(cfg *config.Config) error

SetupConfig writes config.yaml.

func (*TestEnv) SetupExistingClaudeSkill

func (e *TestEnv) SetupExistingClaudeSkill(skillName, skillMD string) error

SetupExistingClaudeSkill creates a skill in ~/.claude/skills that is NOT managed by staghorn. Used for testing collision detection.

func (*TestEnv) SetupPersonalConfig

func (e *TestEnv) SetupPersonalConfig(content string) error

SetupPersonalConfig writes personal.md.

func (*TestEnv) SetupPersonalLanguage

func (e *TestEnv) SetupPersonalLanguage(lang, content string) error

SetupPersonalLanguage writes a personal language config.

func (*TestEnv) SetupPersonalRule

func (e *TestEnv) SetupPersonalRule(relPath, content string) error

SetupPersonalRule writes a personal rule.

func (*TestEnv) SetupPersonalSkill

func (e *TestEnv) SetupPersonalSkill(skillName, skillMD string) error

SetupPersonalSkill writes a personal skill.

func (*TestEnv) SetupTeamCommand

func (e *TestEnv) SetupTeamCommand(owner, repo, cmd, content string) error

SetupTeamCommand writes a team command to cache.

func (*TestEnv) SetupTeamConfig

func (e *TestEnv) SetupTeamConfig(owner, repo, content string) error

SetupTeamConfig writes team CLAUDE.md to cache (simulates fetch).

func (*TestEnv) SetupTeamLanguage

func (e *TestEnv) SetupTeamLanguage(owner, repo, lang, content string) error

SetupTeamLanguage writes a team language config to cache.

func (*TestEnv) SetupTeamRule

func (e *TestEnv) SetupTeamRule(owner, repo, relPath, content string) error

SetupTeamRule writes a team rule to cache.

func (*TestEnv) SetupTeamSkill

func (e *TestEnv) SetupTeamSkill(owner, repo, skillName, skillMD string) error

SetupTeamSkill writes a team skill to cache. The skill is a directory containing SKILL.md and optional supporting files.

func (*TestEnv) SetupTeamSkillWithFiles

func (e *TestEnv) SetupTeamSkillWithFiles(owner, repo, skillName, skillMD string, files map[string]string) error

SetupTeamSkillWithFiles writes a team skill with supporting files.

Jump to

Keyboard shortcuts

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