assembletest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package assembletest builds the synthetic inputs of bundle assembly tests: a git clone whose pull request exercises every kind of change, a fake GitHub that returns evidence for it, and a fake session source. Everything is made up and deterministic: commit dates and identities are fixed, so the commit ids, and the bundle built from them, are the same on every run.

Index

Constants

View Source
const (
	ImageSource   = "https://github.com/user-attachments/assets/0f3b8c1e-5a4d-4e6f-9a7b-1c2d3e4f5a6b"
	ImageFetchURL = "https://private-user-images.githubusercontent.com/1/2-0f3b8c1e-5a4d-4e6f-9a7b-1c2d3e4f5a6b.png?jwt=signed"
)

ImageSource is the description image's markdown source, and ImageFetchURL the signed URL GitHub renders for it.

View Source
const Number = 7

Number is the pull request's number.

View Source
const PlantedEmail = "ada.lovelace@example.com"

PlantedEmail is planted next to the secret.

Variables

View Source
var PNG = mustDecode("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==")

PNG is a 1x1 PNG, the description image's content.

View Source
var PlantedSecret = "hf_" + "nW2OPJ0rGsD6y4OUtEXQxmAa3BItWMoP6J"

PlantedSecret is a made-up Hugging Face token, planted in the pull request's settings file, body, a comment and a session prompt. It must never reach a bundle. It is kept in pieces so no source line reads as a credential.

View Source
var Repository = github.Repository{Host: "github.com", Owner: "acme", Name: "demo"}

Repository is the pull request's repository on GitHub.

Functions

func Git

func Git(t *testing.T, dir string, args ...string) string

Git runs git in dir and returns its trimmed output.

func SessionTree

func SessionTree() []bundle.Session

SessionTree is what the local session source returns for a top-level session whose second prompt spawned a subagent that spawned another: each prompt carries the paths the sessions it started, at any depth, touched. A second, earlier-starting session ran in the same pull request. Both carry the planted secret and e-mail address in their text.

func Write

func Write(t *testing.T, dir, name, content string)

Write writes a file of the clone.

Types

type GitHub

type GitHub struct {
	Evidence github.Evidence
	Err      error
	// Fetched records each pull request asked for.
	Fetched []github.Target
}

GitHub is a fake GitHub: it returns Evidence, or Err, for the pull request.

func (*GitHub) Fetch

func (g *GitHub) Fetch(_ context.Context, repo github.Repository, number int, _ github.FetchOptions) (github.Evidence, error)

Fetch implements assemble.GitHub.

type Options

type Options struct {
	// NoReviewMD leaves REVIEW.md out of the base commit.
	NoReviewMD bool
}

Options vary the fixture.

type Repo

type Repo struct {
	Dir string
	// Base is main's tip, Head the pull request's tip, MergeBase their merge
	// base, which is the commit before the pull request's work: main moved on
	// after the branch point, so the base is not the merge base.
	Base, Head, MergeBase string
	// Commits are the pull request's commits, oldest first.
	Commits []string
	// ShiftHead and ShiftBase are a second pull request making the same
	// change to src/shift.go as the first, against a base that has three more
	// lines above it: a context shift.
	ShiftHead, ShiftBase string
}

Repo is a clone with a pull request on branch "feature". The clone's HEAD is on main, as when a user reads a pull request they are not working on.

func NewRepo

func NewRepo(t *testing.T, opts Options) Repo

NewRepo creates the fixture clone in a temporary directory. The pull request, on branch feature, in two commits:

  • adds the same line twice to src/list.go (repeated hunks), adds config/settings.env holding PlantedSecret, edits src/shift.go, and adds a docs/ page;
  • renames docs/old-guide.md to docs/guide.md with one line changed (a rename), and changes assets/logo.bin (a binary change).

Main then gains a commit, so the base commit is not the merge base.

func (Repo) Dirty

func (r Repo) Dirty(t *testing.T)

Dirty leaves the clone with a modified tracked file, a staged change and an untracked file, so a test can tell whether anything touched them.

func (Repo) Evidence

func (r Repo) Evidence() github.Evidence

Evidence is what GitHub returns for the pull request at r's head: every part present, with a check run, a status, a conversation, a thread and a description image.

func (Repo) EvidenceMissing

func (r Repo) EvidenceMissing() github.Evidence

EvidenceMissing is the pull request with nothing but its header: no checks, conversation, threads or images, and every other part unreadable.

func (Repo) ShiftEvidence

func (r Repo) ShiftEvidence() github.Evidence

ShiftEvidence is the header of the context-shift pull request: the same change to src/shift.go as the main pull request's, against a base with three more lines above it.

func (Repo) State

func (r Repo) State(t *testing.T) string

State describes what a read must leave alone: the status, HEAD, every ref and the index's staged paths.

type Sessions

type Sessions struct {
	Found   []bundle.Session
	Err     error
	Commits []gitlocal.Commit
}

Sessions is a fake session source returning Found, or Err, whatever the commits, and recording the commits it was asked for.

func (*Sessions) Evidence

func (s *Sessions) Evidence(_ context.Context, commits []gitlocal.Commit, _, _ int) ([]bundle.Session, error)

Evidence implements assemble.Sessions.

Jump to

Keyboard shortcuts

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