Documentation
¶
Overview ¶
Package presettest is the preset validation harness.
It answers one question about a shipped preset: for a stated set of job parameters, what exactly does each task run? Capture answers it by driving the production pipeline (submit, build the assignment, resolve it as a worker does), and Render turns the answer into a reviewable golden file.
The harness models nothing. Every step is production code reached through its own package (internal/openjd, internal/scheduler, internal/worker/executor), because a harness that recomputes what it asserts agrees with itself rather than with the server. internal/scheduler/seam.go and internal/worker/executor/seam.go exist to expose that code to it.
A Tier-1 golden proves the template expands and resolves to a specific, reviewed command line. It does not prove that command line is what the vendor's application wants: that is documentation-derived, per preset, and presets/validation-tiers.yaml carries a caveat saying so.
Index ¶
- Constants
- Variables
- func ApplyChunkPatch(rawTemplate string, p ChunkPatch) (string, error)
- func ArgvSetDiff(want, got [][]string) []string
- func ArgvUnexpected(want, got [][]string) []string
- func BuildStub(ctx context.Context) (string, error)
- func CommandNames(s Snapshot) []string
- func CompareGolden(path, got string) error
- func InstallStub(dir string, names []string) error
- func PresetTemplate(source, name string) (string, error)
- func RecordOutcome(caseName string, skipped bool, reason string)
- func RemoveStub()
- func Render(s Snapshot) string
- func RepoRoot() (string, error)
- func RequiredApps(value string) ([]string, error)
- func StubInstallDir() (string, error)
- func Submit(ctx context.Context, rawTemplate string, opts Options) (*openjd.SubmitResult, error)
- func WriteGolden(path, content string) error
- type Case
- type ChunkPatch
- type Entry
- type FileSnapshot
- type Options
- type Outcome
- type Registry
- type Snapshot
- type StepSnapshot
- type TaskSnapshot
- type Tier1
- type TierExec
Constants ¶
const ( SourcePresets = "presets/sqi" SourceBuiltins = "internal/product/builtins" )
Source directories the tier registry and the harness know about: the shipped presets, and internal/product/builtins/, which holds the seven compiled-in products (script, script-powershell, python, container, and the three sequence built-ins) that are present with no preset-library install.
const ( StatusCompleted = string(store.JobStatusCompleted) StatusFailed = string(store.JobStatusFailed) )
Job statuses an outcome case may expect.
const RegistryPath = "presets/validation-tiers.yaml"
RegistryPath is the tier registry's location, relative to the repo root.
const RequireAppsEnv = "SQI_TEST_REQUIRE_APPS"
RequireAppsEnv names the environment variable that turns a skipped application-backed Tier-2 case into a registry failure. It holds a comma-separated list of KnownApps.
const StubPackage = "github.com/uberware/sqi/test/stubproc"
StubPackage is the import path of the recording stub binary.
const StubParent = "sqi-stubproc"
StubParent is the folder under the system temp folder that holds every copy of the stub: each process's build, Go's own build files for it (GOTMPDIR), and the folders StubInstallDir makes. Windows Defender flags the stub as malware, so excluding this one folder from scanning covers all of them.
Variables ¶
var ErrTemplateHasEnvironments = errors.New("presettest: template declares environments")
ErrTemplateHasEnvironments is returned by Capture for a template declaring job or step environments.
session.Manager.Create enters environments, which executes their onEnter actions. For a real preset that action is a vendor command ("setup-maya", a license checkout), which a snapshot must not run as a side effect. A preset that declares environments cannot be captured and needs observed-only verification.
var KnownApps = []string{"3delight", "blender", "houdini", "nuke", "renderman", "unreal"}
KnownApps are the vendor applications a Tier-2 case may need, by the name RequiresApp and RequireAppsEnv use.
Functions ¶
func ApplyChunkPatch ¶
func ApplyChunkPatch(rawTemplate string, p ChunkPatch) (string, error)
ApplyChunkPatch returns rawTemplate with p applied. The ChunkPatch type is declared in snapshot.go.
It edits the YAML node tree rather than the text, so that in a template with several steps only the named step's defaultTaskCount changes.
func ArgvSetDiff ¶
ArgvSetDiff compares two sets of argument vectors and returns one message per difference, sorted, or none when they are equal. Order is ignored, since tasks are leased concurrently and run in no fixed order, but both directions are checked: a missing argv and an unexpected one are different regressions. Arguments are joined on NUL, so "a b" never equals ["a", "b"].
func ArgvUnexpected ¶
ArgvUnexpected is the one-sided ArgvSetDiff: it reports only the argvs in got that are not in want, sorted. It suits a failed job, which need not have run every task, so an expected argv that never appeared is not an error there.
func BuildStub ¶
BuildStub compiles the stub binary once per process and returns its path.
The directory is not a testing.TempDir: the build is cached across every test in the run, so no single test may own it. Callers that want it removed should register RemoveStub in TestMain.
func CommandNames ¶
CommandNames returns the distinct basenames of every task's command in s, sorted. These are the names InstallStub must shadow for a Tier-3 run.
A command that is a materialized embedded-file path ("<WORKDIR>/main.sh") yields that file's basename, which cannot be shadowed on PATH; the caller checks for that and asserts on the script's inner invocations instead.
func CompareGolden ¶
CompareGolden returns nil when the file at path equals got, and an error describing the difference otherwise.
A missing golden is an error wrapping os.ErrNotExist. Treating an absent file as "nothing to compare" would turn a renamed preset, a mistyped case name or a lost testdata directory into a passing run.
func InstallStub ¶
InstallStub copies the built stub into dir once per name in names, so a worker with dir on its PATH resolves each of those commands to the stub.
Copies rather than symlinks: the stub identifies itself by argv[0]'s basename, and a symlink resolves differently across platforms and shells.
func PresetTemplate ¶
PresetTemplate returns the raw OpenJD template of one preset or built-in product. source must be SourcePresets or SourceBuiltins.
Both go through product.ParseDefinition, which is the same parse the server performs, so a preset that would be rejected on upload cannot be snapshotted as if it were valid.
func RecordOutcome ¶
RecordOutcome reports that caseName executed (or skipped) in this run.
Execution-tier tests call this first, including on the skip path, because a skipped test verifies nothing: the registry test needs to tell "skipped here, legitimately" from "this claim is backed by nothing".
func Render ¶
Render returns the golden-file text for s: a header naming the preset, the case, the bound parameters and any template patch, then every step, every task, the exact command and one indexed line per argument, then the full resolved body of each embedded file.
The embedded-file bodies are part of the golden because a script-shaped preset's argv is only "bash <WORKDIR>/main.sh"; the preset's decisions are in the script.
func RepoRoot ¶
RepoRoot returns the repository root, derived from this file's compile-time path. Tests run with the package directory as the working directory, so a relative path would be different for every caller package.
func RequiredApps ¶
RequiredApps parses the RequireAppsEnv value. An unknown name is an error: a typo would otherwise turn the requirement off silently.
func StubInstallDir ¶
StubInstallDir makes a new folder under StubParent for InstallStub. The caller removes it.
func Submit ¶
Submit runs the first stage of Capture alone: the template submitted under opts.Params to a fresh in-memory store, returning the jobs, steps and tasks it created. A test that needs only the expansion uses it to skip resolving every task.
func WriteGolden ¶
WriteGolden writes content to path, creating parent directories.
Types ¶
type Case ¶
type Case struct {
// Name identifies the case; it is part of the golden filename.
Name string `yaml:"name"`
// Params are the job parameter values. Defaults need not be restated.
Params map[string]string `yaml:"params"`
// Patch optionally raises one step's chunk task count. See [ChunkPatch]:
// it is the only permitted deviation from the shipped preset, and the
// golden header records it.
Patch *ChunkPatch `yaml:"template_patch"`
// StubInner selects which commands Tier 3 shadows on PATH.
//
// False (the default) shadows the task's own command, so the observed argv
// has a computed counterpart and assertObservedMatchesComputed applies.
//
// True shadows what that command invokes inside it instead: the shape of
// the `script` built-in, whose /bin/sh is an absolute path the worker execs
// without consulting PATH, and of `script-powershell`, where shadowing
// powershell itself would prove argv delivery and nothing else. For these
// the computed side is the shell's own argv, so the cross-check cannot
// apply and ExpectInvocations carries the whole claim.
//
// It is declared rather than inferred because filepath.IsAbs(command) is
// false on Windows for "/bin/sh": a POSIX path carries no volume name.
StubInner bool `yaml:"stub_inner"`
// ExpectTasks is the number of tasks this case must expand to. It is
// stated in the fixture rather than derived, so an expansion change fails
// the case instead of producing a different golden.
ExpectTasks int `yaml:"expect_tasks"`
// ExpectInvocations maps a stubbed command's basename to the exact number
// of times Tier 3 must observe it. Empty means Tier 3 asserts nothing
// beyond job success.
ExpectInvocations map[string]int `yaml:"expect_invocations"`
// ExpectInnerArgv is, for a StubInner case, the exact set of argument
// vectors the stub must record (order ignored). ExpectInvocations only
// counts invocations, which for a stub reached through a shell cannot show
// that a value (an environment variable the shell expanded) arrived.
// Legal only with StubInner: otherwise the observed-vs-computed cross-check
// already compares argv.
ExpectInnerArgv [][]string `yaml:"expect_inner_argv"`
// StubEnv is extra environment for the worker process, and so for the stub
// every task it runs: the case says what the "vendor application" does
// (SQI_STUB_EXIT, SQI_STUB_STDOUT, ...). Every key must start SQI_STUB_, so
// a fixture can configure the stub and nothing else (PATH, for one, is the
// harness's own).
StubEnv map[string]string `yaml:"stub_env"`
// ExpectStatus is the job status Tier 3 must observe: "completed" (the
// default when empty) or "failed". A case that sets it is an outcome case,
// which TestPresetOutcomes runs; it says what the job does, not what its
// argv is.
ExpectStatus string `yaml:"expect_status"`
// ExpectReason is a substring of the first task failure reason. Legal only
// with ExpectStatus "failed".
ExpectReason string `yaml:"expect_reason"`
}
Case is one parameter set a preset is snapshotted under.
type ChunkPatch ¶
type ChunkPatch struct {
Step string `yaml:"step"`
ChunksDefaultTaskCount int `yaml:"chunks_default_task_count"`
}
ChunkPatch raises one step's chunks.defaultTaskCount before submission.
It is the only permitted deviation from a shipped preset's bytes. Chunk size is a template field rather than a job parameter, and several presets ship defaultTaskCount 1, so without the patch their chunk goldens would have Frame.Start == Frame.End and the multi-frame "-s START -e END" substitution would go untested.
ApplyChunkPatch (patch.go) applies it; Render prints it in the golden header, so a patched golden is distinguishable from the shipped preset.
type Entry ¶
type Entry struct {
Name string `yaml:"name"`
Source string `yaml:"source"`
Tier int `yaml:"tier"`
Tier1 *Tier1 `yaml:"tier1"`
Tier2 *TierExec `yaml:"tier2"`
Tier3 *TierExec `yaml:"tier3"`
}
Entry is one preset's or built-in's record.
type FileSnapshot ¶
FileSnapshot is one resolved embedded file: its identifier, its on-disk name, and its body after format-string or expression resolution.
type Options ¶
type Options struct {
// Params are the job parameter values for this case. Parameters the
// template defaults are filled in by the real binding path, so a case need
// only state what it overrides.
Params map[string]string
// Format is the template format. The zero value means YAML, which is what
// every shipped preset uses.
Format store.TemplateFormat
}
Options bounds one Capture call.
type Outcome ¶
type Outcome struct {
// Ran is true once the case reported anything at all. A false Ran means the
// case never executed, which is what a registry claim with no test looks
// like.
Ran bool
// Skipped is true when the case reported that it declined to run.
Skipped bool
// Reason is the skip reason, for the failure message the registry test
// prints.
Reason string
}
Outcome is what happened to one execution-tier case in this test binary run.
func LookupOutcome ¶
LookupOutcome returns what happened to caseName; the zero value means it never reported.
type Registry ¶
type Registry struct {
Presets []Entry `yaml:"presets"`
}
Registry is the whole file.
func LoadRegistry ¶
LoadRegistry reads and validates the tier registry from the repo.
func ParseRegistry ¶
ParseRegistry parses and validates registry bytes. Exported so the loader's own rules can be tested without writing files.
type Snapshot ¶
type Snapshot struct {
Preset string
Case string
Params map[string]string
Patch *ChunkPatch
Steps []StepSnapshot
}
Snapshot is the whole answer for one preset and one case.
Preset, Case and Patch are metadata the caller sets for the golden header; Capture populates only Params and Steps.
func Capture ¶
Capture expands rawTemplate under opts.Params and returns the resolved command line of every task, in step and expansion order.
The pipeline is the production one, end to end:
- openjd.Submitter.Submit — parameter binding, parameter-space expansion, chunking, SQI_CHUNK_BOUNDS derivation, EXPR phase-2 substitution.
- scheduler.BuildAssignPayload — the real assignment for each task.
- session.Manager.Create + executor.ResolveAssignment — phase-3 resolution of the command, args and embedded-file bodies.
Nothing is reimplemented, so a golden built from this reflects the server and the worker.
type StepSnapshot ¶
type StepSnapshot struct {
Name string
Tasks []TaskSnapshot
// LogChecks is the step's SQI_LOG_CHECKS block as the real assignment
// carries it, or nil. It is a step property (every task of a step gets the
// same block), so it is read from the first task's assignment.
LogChecks *protocol.LogChecks
// LogProgress is the step's SQI_LOG_PROGRESS block as the real assignment
// carries it, or nil. Read from the first task's assignment like LogChecks.
LogProgress *protocol.LogProgress
}
StepSnapshot is one step and every task it expanded to, in expansion order.
type TaskSnapshot ¶
type TaskSnapshot struct {
Name string
Params map[string]string
Command string
Args []string
Files []FileSnapshot
}
TaskSnapshot is one task's fully resolved command line.
type Tier1 ¶
type Tier1 struct {
// Cases are the case names in this preset's fixture file. Each must have a
// golden on disk.
Cases []string `yaml:"cases"`
// Caveat states what this Tier-1 claim does not prove. A Tier-1 golden
// proves the template expands to a reviewed command line; it does not
// prove the vendor's application accepts it. Empty is an error.
Caveat string `yaml:"caveat"`
}
Tier1 records a preset's argv-snapshot coverage.
type TierExec ¶
type TierExec struct {
// Case is the full Go subtest name, e.g.
// "TestPresetTier3/maya-layer-render/default".
Case string `yaml:"case"`
// RequiredOn lists the GOOS values on which that case must run. If it
// skips on one of them, the registry verification fails, so a case cannot
// pass there while running nothing.
//
// It must name at least one platform; the loader rejects an empty list,
// because a claim required nowhere can never fail. A tier that cannot be run
// anywhere is recorded by omitting the block entirely.
RequiredOn []string `yaml:"required_on"`
// RequiresApp names a vendor application (one of KnownApps) the case needs
// installed. It replaces RequiredOn for a case CI cannot run on every
// host: the case skips when the application is absent, and that skip is a
// registry failure only when RequireAppsEnv lists the application. A run
// without it records the case as not proven rather than hiding the gap.
// Tier 2 only; exactly one of RequiredOn and RequiresApp is set.
RequiresApp string `yaml:"requires_app"`
}
TierExec records an execution tier (2 or 3) as a named test case.