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 ¶
const MinCoverage = 80.0
MinCoverage is the share of its statements a script's tests must reach.
const RecentRuns = 5
RecentRuns is how many of a script's latest recorded runs a save replays.
const RulePassthroughConnection = "passthrough-connection"
RulePassthroughConnection names the warning a source gets for each connection it names that a saved script's run cannot call (#2086).
Variables ¶
This section is empty.
Functions ¶
func Readable ¶
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.
func TestReport ¶ added in v1.138.1
func TestReport(r *scripttest.Report) *testreport.Report
TestReport is the part of the tests' report a saved version keeps (#1972): each test's outcome and the statements they reach. Nil in, nil out.
Types ¶
type Caller ¶
Caller is who is saving. A run of the version they save presents their roles, so the persona and roles they hold now are what a library the source writes to is checked against (#2080).
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
// Resources reads the managed-resource files a source loads as text,
// which a save pins (#2113); nil refuses a source that loads any.
Resources *scriptsrc.Reader
// CannotServe reports whether a saved script's run cannot call a
// connection, which the source is warned of for each one it names
// (#2086); nil warns of none.
CannotServe func(connection string) bool
}
Gate holds what a save is checked against. The zero value checks the lint and the tests, with no recording a test names readable.
type PassthroughConnections ¶ added in v1.144.0
PassthroughConnections answers, over a registry's toolkits at the moment it is asked, whether a saved script's run cannot call a connection.
func (PassthroughConnections) CannotServe ¶ added in v1.144.0
func (p PassthroughConnections) CannotServe(connection string) bool
CannotServe reports whether any toolkit serves connection by forwarding the caller's token to an upstream that checks 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:"-"`
// ResourcePins is the version of each file the source loads (#2113).
ResourcePins map[string]script.ResourcePin `json:"-"`
}
Result is what the gate made of a save.