check

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package check runs aicoded check on the apps of a workspace: for each app, the precheck of the lint package, generate, the check of the snapshots it holds, the check of its schema-change draft, go build, go vet, the rules of the lint package and go test, with a test database for an app that declares sqldb.

Index

Constants

View Source
const EnvTestDB = "AICODED_TEST_DB"

EnvTestDB is the variable that holds, for an app's tests, the DSN of the data user of its test database, or "" when it has none.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Name string `json:"name"`
	Dir  string `json:"dir"`
	// Changed lists the generated files generate wrote, or with Frozen the ones out of date.
	Changed  []string          `json:"changed,omitempty"`
	Warnings []string          `json:"warnings,omitempty"`
	Problems []problem.Problem `json:"problems,omitempty"`
	// Notes are what lint reports without failing the app, such as E-DATA-001, once lint has
	// read its code.
	Notes []problem.Problem `json:"notes,omitempty"`
	// Surface is the app's size, once lint has read its code.
	Surface *surface.Surface `json:"surface,omitempty"`
}

App is what aicoded check found in one app.

type Options

type Options struct {
	// Frozen writes nothing; every generated file that would change is an E-CHK-001 problem.
	Frozen bool
	// App limits the check to one app; "" checks every app. An unknown name is E-DEV-014.
	App string
	// FrameworkDir is the framework checkout this aicoded was installed from, or "" for a
	// released aicoded. Lint lets an app's go.mod replace the framework with this folder only
	// (E-LINT-011).
	FrameworkDir string
	// NoTests skips the tests and the probe of -race.
	NoTests bool
	// MySQL returns the admin DSN of the MySQL server in dev.yaml, or ""; nil is "". aicoded check
	// asks for it once, and only when the tests of an app that declares sqldb run. With a server,
	// each such app gets a new test database, which aicoded check makes as aicoded dev makes a dev
	// database and drops after the tests; the tests find the data user's DSN in AICODED_TEST_DB.
	// An error of MySQL, or a DSN that is not valid (E-DEV-007), stops the whole check.
	MySQL func() (string, error)
	// Platform gives the migrations each app published, applied to its test database before its
	// draft; with nil, they come from the app's cache.
	Platform migrations.Platform
}

Options says what aicoded check checks.

func WithDatabase

func WithDatabase(dir string, opts Options) (Options, error)

WithDatabase returns opts with the MySQL server that dev.yaml names for the workspace of dir, or of a folder above it, read only when an app needs it, and the platform that AICODED_PLATFORM names, which give each app that declares sqldb its test database. With NoTests, it returns opts as they are.

type Report

type Report struct {
	Apps   []App `json:"apps"`
	Frozen bool  `json:"frozen,omitempty"`
	// NoTests is set when the tests did not run.
	NoTests bool     `json:"no_tests,omitempty"`
	Race    bool     `json:"race"`
	Notes   []string `json:"notes,omitempty"`
}

Report is what aicoded check found.

func Run

func Run(ctx context.Context, dir string, opts Options) (Report, error)

Run checks the apps under dir. Its error is one of the whole workspace: no app, a permission list that does not load, two apps with one name, an unknown Options.App, no go command, a package that lint cannot load once the app builds, or ctx ending. Everything else is a problem of an app, such as E-CHK-007 when lint cannot run with this go command. Lint's precheck of GOFLAGS and the vendor folder runs for every app before any other go command, since both decide what the go command builds and runs; -race is then probed in the first app that passed it, unless Options.NoTests skips the tests. A step that fails skips the later steps of its app, and every app is checked.

func (Report) OK

func (r Report) OK() bool

OK reports whether no app has a problem.

func (Report) WriteText

func (r Report) WriteText(w io.Writer) error

WriteText writes the report as aicoded check prints it: a block per app, with its problems and notes, the notes of the whole check, a line that sums it up, and a last line when the tests did not run. Notes never fail an app.

Jump to

Keyboard shortcuts

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