Skip to content

Latest commit

 

History

History
149 lines (119 loc) · 5.02 KB

development.md

File metadata and controls

149 lines (119 loc) · 5.02 KB

Development

Build and test

make build         # Build binary to bin/marmot
make test          # Run all tests with race detector
make test-v        # Verbose test output
make test-cover    # Generate coverage report
make vet           # Run go vet
make fmt           # Format code
make tidy          # Tidy go.mod

Run integration tests:

go test -race -tags integration -count=1 ./internal/

End-to-end tests

The e2e/ package exercises the built binary against a static fixture vault (e2e/fixture/): CLI flows (index, status, query, verify, sdk, staleness detection), the MCP server over stdio JSON-RPC (all six tools), and the embedded web UI over HTTP.

make e2e         # Go e2e suite (builds the binary itself)
make e2e-ui      # Playwright browser validation of the graph UI
make e2e-all     # Both

The e2e gates are behind the e2e build tag. Every file in e2e/ starts with //go:build e2e, so go test ./... (and make test, which is go test -race -count=1 ./...) does not compile them --- the package reports as having no test files and every end-to-end gate is silently skipped. Verifying a change end to end requires make e2e, or go test -tags e2e -count=1 ./e2e/ directly. The same applies to the integration tier at the top of internal/ (//go:build integration, run with -tags integration).

Browser tests need one-time setup:

cd web && npm install && npx playwright install chromium

The Playwright suite (web/e2e/ui.spec.ts) starts a UI server on a temp copy of the fixture vault via web/e2e/serve.sh, then validates graph rendering, node detail interaction, and search — failing on any console or page error.

Node Format

Nodes are markdown files with YAML frontmatter:

---
id: auth/login
type: function
namespace: default
status: active
tags:
  - auth
  - security
source:
  path: src/auth/login.ts
  lines: [1, 35]
  hash: a3f8b2c1
edges:
  - target: auth/validate_token
    relation: calls
  - target: db/users
    relation: reads
---

Authenticates a user with email and password.

## Relationships

- **calls** [[auth/validate_token]]
- **reads** [[db/users]]

## Context

// typescript
export async function login(email: string, password: string) { ... }

Edge provenance fields

Edges may carry optional, server-owned provenance fields:

edges:
  - target: auth/validate_token
    relation: calls
    origin: indexer                  # which subsystem stamped the edge (e.g. indexer, agent)
    ref_name: s.auth.ValidateToken   # the code reference that produced it
    ref_kind: call

All three are omitempty and excluded from content identity (verify.ComputeNodeHash). Erosion note: older marmot binaries parse nodes carrying these fields fine, but strip them on their next save of the node.

Edge types

Structural (acyclic --- enforced): contains, imports, extends, implements

Behavioral (cycles allowed): calls, reads, writes, references, cross_project, associated

On-disk artifacts

Beyond node .md files, a vault's .marmot-data/ carries:

  • embeddings.db --- embeddings plus the lexical search substrate: a node_fts FTS5 table and its node_fts_state companion (rowid + staleness-hash bookkeeping). The FTS row is written in the same transaction as every embedding upsert, so the BM25 shadow never commits separately from the vector it shadows.
  • refs.db --- unresolved-reference parking sidecar (internal/refs). Records code references the static indexers couldn't resolve; retried at the end of every index run, with resolutions materialized as provenance-stamped edges. Deliberately a separate file: it survives marmot index --force / reembed (which delete embeddings.db), and the warren copier excludes it from imports and burrows.
  • indexer-repair/<namespace-hash>.json --- source-indexer write-ahead repair intent. It is written before a source-derived node save and removed only after refs, embedding, and superseded-target status side effects converge, so watcher election retries and process restarts cannot mistake an unchanged source hash for a fully indexed node.
  • watch.lock --- long-lived writer lease. marmot watch holds it exclusively (it is THE vault writer while running); long-lived engines (serve daemon owner, standalone serve, ui) and marmot index runs hold it shared --- each side refuses the other instead of double-writing.

A vault's .marmot-locks/namespaces/ carries hashed, persistent lock files for namespace mutations. The files contain no payload; their stable inodes let independent engines and processes serialize load-modify-save cycles with BSD flock or Windows LockFileEx. The directory is runtime coordination state: marmot init gitignores it, source/index walks skip it, and Warren imports/burrows/proposals and den contributions exclude it. Existing vaults also get a self-ignoring .marmot-locks/.gitignore on first mutation, so the runtime tree stays out of ordinary git status without rewriting project-owned ignore files.