testutil

package
v0.22.0 Latest Latest
Warning

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

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

Documentation

Overview

Package testutil is the shared test substrate for the cmd decomposition (mache-96c378 stage 1). Before it existed, every helper here lived in one cmd _test.go file and was used by dozens of others — which pinned all 108 test files into package cmd. Helpers take testing.TB and are exported; nothing here may import cmd or any package extracted from it, so the dependency arrow only ever points downward.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttachLeylineASTWalkerForTest

func AttachLeylineASTWalkerForTest(t testing.TB, dataSource string, engine *ingest.Engine) (*sql.DB, func(), error)

AttachLeylineASTWalkerForTest is the test-only sibling of the production leyline-walker attachment: it resolves the PINNED leyline WITHOUT downloading (ResolveBinary(false)) so offline CI skips instead of hanging, parses dataSource into an `_ast` db, and wires an ASTWalker onto the engine. Returns the open db, a cleanup, and an error (which callers turn into a Skip).

func BuildTestGraph

func BuildTestGraph(t testing.TB) *graph.MemoryStore

BuildTestGraph creates a MemoryStore with a predictable tree:

pkg/
  main/
    source       -> "func main() {}"
    context      -> "package main"
  util/
    helper/
      source     -> "func Helper() {}"
empty/

Refs: "Helper" -> ["pkg/util/helper"] Defs: "Helper" -> ["pkg/util/helper"]

func GoCallExtractorForTest

func GoCallExtractorForTest() graph.CallExtractor

GoCallExtractorForTest is a naive, pure-Go call extractor for tests that build synthetic MemoryStores from raw Go source bytes (node Data). ADR-0012 step 4 removed the in-process CGO tree-sitter extractor (newCallExtractor), and the production AST extractor reads a ley-line `_ast` db by source_id — it cannot parse ad-hoc Data byte slices. These composite/mount annotation tests only need *some* identifier-call to flow through the callees machinery, so a regex over `identifier(` suffices and keeps them CGO-free.

It is deliberately test-only and never part of production wiring.

func GoldenCorpusDir

func GoldenCorpusDir(t testing.TB) string

GoldenCorpusDir is the hand-written Go corpus whose projection is pinned byte-for-byte by internal/testfixtures. Resolved through the one seam rather than re-derived per package: two callers had each grown their own copy of the same runtime.Caller walk before this existed.

func MacheRepoRoot

func MacheRepoRoot(t testing.TB) string

MacheRepoRoot returns the absolute path of mache's source root. Derived from runtime.Caller so the test works regardless of which checkout the developer has cd'd into (~/remotes/art/mache vs ~/github/art/mache).

func MakeRequest

func MakeRequest(args map[string]any) mcp.CallToolRequest

MakeRequest constructs a CallToolRequest with the given arguments.

func PresetFixturesDir

func PresetFixturesDir(t testing.TB) string

PresetFixturesDir returns the absolute path of the shared per-language preset fixture tree (one tiny idiomatic source file per supported language). Hoisted out of cmd/testdata because its consumers end up in three different packages after the decomposition, and testdata/ is package-dir-relative.

func RequirePinnedLeyline

func RequirePinnedLeyline(t testing.TB)

RequirePinnedLeyline skips the test unless the exact-pinned leyline is already resolvable WITHOUT a network download (PATH or the ~/.mache/bin cache). LookPath alone is the wrong gate since the exact-version pin (mache-608a3c): a stale PATH leyline no longer satisfies the pin, and we don't want tests fetching from GitHub.

func ResultText

func ResultText(t testing.TB, result *mcp.CallToolResult) string

ResultText extracts the text from the first content item of a CallToolResult.

func WriteBindingLogForTest

func WriteBindingLogForTest(t testing.TB, dbPath, target, token, construct, refURI string)

WriteBindingLogForTest writes a single-record .bindings.capnp log next to dbPath for the test. Mirrors LLO's wire format (back-to-back capnp segment messages). Used by tests that need binding-fidelity rows in v_refs after mache-6bd4d8 retired the SQL _lsp_refs UNION arm.

func WriteMultiBindingLogForTest

func WriteMultiBindingLogForTest(t testing.TB, dbPath string, recs []BindingRec)

WriteMultiBindingLogForTest writes N records to one .bindings.capnp log next to dbPath. Used by tests that need the qualifier signal across multiple referrers (mache-6c0d07 fan_out_skew), where the single-record helper would overwrite each record.

Types

type BindingRec

type BindingRec struct {
	Target, Token, Construct, Qualifier string
}

BindingRec describes one record for WriteMultiBindingLogForTest. Fields use the same vocabulary as the BindingRecord schema; empty fields default per the schema-evolution invariant (Qualifier="" is the pre-T8.7 default and exercises the COALESCE fallback to token in the qualifier-aware fan_out_skew metric).

type SmellTestGraph

type SmellTestGraph struct {
	*graph.MemoryStore
	DB   *sql.DB
	Path string // optional: when set, exposed via DBPath() for capnp readthrough
	// ASTKinds, when set, answers graph.ASTKinder: normally a real
	// SQLiteGraph over the same database, so the kinds a test sees are the
	// ones production computes, not a copy of its query.
	ASTKinds graph.ASTKinder
}

SmellTestGraph is a tiny graph backend that delegates QueryRefs to a caller-supplied *sql.DB. It exists only for tests because spinning up a full SQLiteGraph just to run a SQL pattern is not worth it.

func (*SmellTestGraph) ASTKindChain

func (s *SmellTestGraph) ASTKindChain(id string) ([]string, bool, error)

ASTKindChain implements graph.ASTKinder through ASTKinds; with none set, the graph has no AST to report.

func (*SmellTestGraph) DBPath

func (s *SmellTestGraph) DBPath() string

DBPath implements graph.DBPathProvider when Path is set, opting this test graph into capnp readthrough (mache-190508 step 3 / mache-6bd4d8). Tests that don't set Path keep the legacy mention-only view shape.

func (*SmellTestGraph) QueryRefs

func (s *SmellTestGraph) QueryRefs(query string, args ...any) (*sql.Rows, error)

Jump to

Keyboard shortcuts

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