scriptsave

package
v1.138.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package scriptsave is the one gate a managed script's source crosses on every save (#1913), for the manage_script tool and the portal editor alike: the formatter and the lint (internal/platform/scriptlint), the script's tests and the statements they reach (#1939, #1940), and what the new version does differently from the saved one (#1942).

A script is saved only with at least one test, every test passing, at least MinCoverage percent of its statements reached, and its tests reading every output their executions produce (#1952). A script saved before these rules keeps running as it is; its next version is held to all of them (#1965).

A new version of a saved script replays the script's recent recorded runs through both versions and compares what they produced, and compares what each reaches. A difference is a change in what the automation does, and the save then needs a plain-language summary of it and the agent's confirmation that the person the automation runs for agreed. A person approves behavior, never code: there is no second approver.

Index

Constants

View Source
const MinCoverage = 80.0

MinCoverage is the share of its statements a script's tests must reach.

View Source
const RecentRuns = 5

RecentRuns is how many of a script's latest recorded runs a save replays.

Variables

This section is empty.

Functions

func Readable

func Readable(m scriptrec.Meta, existing *script.Script, caller Caller) bool

Readable reports whether caller may read a recording, under the rules run history is read by: an administrator, and the current owner of existing when it recorded existing. A draft is also its author's, who ran it with their own access; a run is not its former owner's once the script moved.

Types

type Caller

type Caller struct {
	Email string
	Admin bool
}

Caller is who is saving.

type Gate

type Gate struct {
	// Recordings is where recordings are read from; nil reads none.
	Recordings scriptrec.Store
	// Destinations is the deployment's bucket destinations, which an export
	// a test or a replay reaches resolves against.
	Destinations []script.Destination
	// MaxMemoryBytes is the memory one test or replay may hold.
	MaxMemoryBytes int64
	// Contracts is what an answer a test declares is held to (#1953); nil
	// checks none.
	Contracts scripttest.Contracts
	// Libraries is where the libraries a source loads are read from
	// (#1941); nil refuses a source that loads any.
	Libraries scriptlib.Source
}

Gate holds what a save is checked against. The zero value checks the lint and the tests, with no recording a test names readable.

func (*Gate) Check

func (g *Gate) Check(ctx context.Context, req Request) Result

Check puts one save through every gate, stopping at the first that refuses.

func (*Gate) Keep

func (g *Gate) Keep(ctx context.Context, sc *script.Script, author string) error

Keep marks the recordings the saved source's tests name, so the retention sweep keeps them while this is the script's latest version.

func (*Gate) Loader

func (g *Gate) Loader(existing *script.Script, caller Caller) scripttest.Loader

Loader reads a recording a test names for caller: a recording is readable by an administrator, by the owner of the script it recorded, and a draft's by the person who ran it.

type Request

type Request struct {
	// Existing is the script saved into, nil for a new one.
	Existing *script.Script
	// Name labels the script in tracebacks.
	Name   string
	Source string
	Caller Caller
	// ChangeSummary is what the new version does differently, in plain
	// language, and Agreed the confirmation that the person the automation
	// runs for agreed to it.
	ChangeSummary string
	Agreed        bool
}

Request is one save.

type Result

type Result struct {
	// Lint is the formatter's and the lint's result; Lint.Source is what a
	// save stores.
	Lint scriptlint.Result `json:"-"`
	// Tests is the tests' report, nil when the save was refused before they
	// ran.
	Tests *scripttest.Report `json:"tests,omitempty"`
	// Differences is what the new version does differently. Replayed is the
	// recorded runs both versions replayed, and NotCompared the ones the
	// saved version itself could not replay.
	Differences []scriptbehavior.Difference `json:"differences"`
	Replayed    []string                    `json:"replayed"`
	NotCompared []string                    `json:"not_compared,omitempty"`
	// Refusal is why the save is refused, empty when it goes through.
	Refusal string `json:"refusal,omitempty"`
	// ChangeNeeded is true when the refusal is only that a behavior change
	// needs a summary and the person's agreement.
	ChangeNeeded bool `json:"change_needed,omitempty"`
	// ChangeSummary and ChangeAgreedBy are what the saved version carries,
	// empty when there is nothing.
	ChangeSummary  string `json:"-"`
	ChangeAgreedBy string `json:"-"`
}

Result is what the gate made of a save.

func (Result) Apply

func (r Result) Apply(sc *script.Script)

Apply sets the formatted source and the change the save carries on sc.

func (Result) Refused

func (r Result) Refused() bool

Refused reports whether the save is refused.

Jump to

Keyboard shortcuts

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