docstest

package
v1.0.0-alpha.39 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package docstest reads the fenced blocks of the README and of docs/, for the tests that hold a block to what a command prints.

Index

Constants

View Source
const (
	ManifestFile   = "permissions.json"
	ManifestSchema = "permissions.schema.json"
)

ManifestFile and ManifestSchema are the manifest and its JSON Schema, from the repository's root.

Variables

This section is empty.

Functions

func At

func At(t testing.TB, root string, place Place) []string

At answers the body of each block at place, and fails the test when the page holds none there.

func Fills

func Fills(shown, printed string) bool

Fills reports whether printed is the line a page shows, with some text in place of each <placeholder> of the page's line and every other character the same.

func Page

func Page(t testing.TB, root, page string) string

Page answers the text of one page, named from the repository's root at root, for a test that holds the page's prose to the code.

func Rank

func Rank(level string) int

Rank orders the levels: none, read, then write.

Types

type Block

type Block struct {
	Place
	// Line is the line the fence opens on.
	Line int
	Body string
}

Block is one fenced block.

func Blocks

func Blocks(t testing.TB, root string) []Block

Blocks reads every fenced block of README.md and of each page of docs/ in the repository at root, in the order the pages hold them.

type Call

type Call struct {
	ID     string `json:"id"`
	Host   string `json:"host"`
	Base   string `json:"base"`
	Method string `json:"method"`
	Path   string `json:"path"`
	Access string `json:"access"`
	// Permissions maps each permission the call needs to its level.
	Permissions map[string]string `json:"permissions"`
	What        string            `json:"what"`
	Why         string            `json:"why"`
	// By names the code that sends the request, and Commands what a recipe
	// or a person runs that makes it.
	By       []string `json:"by"`
	Commands []string `json:"commands"`
	// Source is what the permissions rest on, or Unverified says why nothing
	// this file quotes states them.
	Source     *Source `json:"source,omitempty"`
	Unverified string  `json:"unverified,omitempty"`
}

Call is one method and path sent to a host.

func (Call) Matches

func (c Call) Matches(method, path string) bool

Matches reports whether a request of method to path, after the call's base and without its query, is this call.

type Grant

type Grant struct {
	Name  string `json:"name"`
	File  string `json:"file,omitempty"`
	Job   string `json:"job,omitempty"`
	Token string `json:"token"`
	Role  string `json:"role,omitempty"`
	// Runs names every command, script and step of the grant that makes a
	// call or needs a permission.
	Runs        []string           `json:"runs"`
	Permissions map[string]Granted `json:"permissions"`
}

Grant is what one recipe's job, or the GitHub App, asks of its token.

type Granted

type Granted struct {
	Level  string   `json:"level"`
	Calls  []string `json:"calls"`
	Steps  []string `json:"steps"`
	Excess string   `json:"excess,omitempty"`
}

Granted is one permission a grant asks for, and the calls and steps that need it. Excess says why the level is more than any of them needs.

type Held

type Held struct {
	Token       string            `json:"token"`
	Permissions map[string]string `json:"permissions"`
	Why         string            `json:"why"`
	Source      *Source           `json:"source"`
}

Held is what a token holds without asking for it, and what that rests on.

type Local

type Local struct {
	ID       string   `json:"id"`
	Command  string   `json:"command"`
	SignedIn bool     `json:"signed_in"`
	Access   string   `json:"access"`
	What     string   `json:"what"`
	Why      string   `json:"why"`
	By       []string `json:"by"`
	Commands []string `json:"commands"`
}

Local is a gh or git command Costroid runs on the machine it runs on, under the person's own sign-in or, for a public read, under none.

type Manifest

type Manifest struct {
	Calls  []Call  `json:"calls"`
	Steps  []Step  `json:"steps"`
	Local  []Local `json:"local_commands"`
	Held   []Held  `json:"held"`
	Grants []Grant `json:"grants"`
}

Manifest is permissions.json: every call Costroid makes to a host under a token, the steps of other publishers that need a permission, and what each recipe's job and the GitHub App ask of their tokens.

func Permissions

func Permissions(t testing.TB, root string) Manifest

Permissions reads permissions.json in the repository at root, and fails the test unless the file holds to its schema and names each call once.

func (Manifest) Call

func (m Manifest) Call(id string) (Call, bool)

Call answers the call whose id is id, and false when there is none.

func (Manifest) HeldBy

func (m Manifest) HeldBy(token string) map[string]string

HeldBy answers the permissions token holds without asking for them.

func (Manifest) Problems

func (m Manifest) Problems(grant Grant, host string, asked, held map[string]string) []string

Problems holds a grant to asked, what its recipe or the App asks of the token, and to the calls and steps under it, and answers each way they differ. held is what the token holds without asking, such as the metadata every workflow token reads.

func (Manifest) Under

func (m Manifest) Under(grant Grant, host string) ([]Call, []Step)

Under answers the calls on host and the steps that what a grant runs makes, in the manifest's order.

type Place

type Place struct{ Page, Heading, Language string }

Place names the blocks of one language under one heading of a page. Page is the file from the repository's root, Heading the nearest heading above the block without its marks, and Language the word after the fence, empty when the fence names none.

type Source

type Source struct {
	Kind string `json:"kind"`
	URL  string `json:"url,omitempty"`
	Run  string `json:"run,omitempty"`
	Read string `json:"read"`
	Says string `json:"says"`
}

Source is what a call's permissions rest on, and the day it was read: the publisher's own page, with its words, or a recorded GitHub Actions run, with what it answered.

type Step

type Step struct {
	Uses        string            `json:"uses"`
	Input       string            `json:"input,omitempty"`
	Permissions map[string]string `json:"permissions"`
	What        string            `json:"what"`
	Why         string            `json:"why"`
	Source      *Source           `json:"source,omitempty"`
	Unverified  string            `json:"unverified,omitempty"`
}

Step is a step from another publisher that needs a permission, when its Input is set or, with no Input, always.

Jump to

Keyboard shortcuts

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