checkjs

package
v0.0.0-...-cf44c5a Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: AGPL-3.0 Imports: 45 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 checkjs provides custom JavaScript script execution checks.

Index

Constants

View Source
const (
	StepStatusOK      = "ok"
	StepStatusFailed  = "failed"
	StepStatusSkipped = "skipped"
)

Step statuses reported in the result output's "steps" list.

View Source
const OutputKeyRedirectBodyWithheld = "redirect_body_withheld"

OutputKeyRedirectBodyWithheld is true in a check's output when an http.* request got a cross-origin 307/308 that would have replayed its body: the hop was not followed and the redirect response was returned (spec 2026-11-14-02).

View Source
const OutputKeyRedirectDroppedSecretHeaders = "redirect_dropped_secret_headers"

OutputKeyRedirectDroppedSecretHeaders lists the header names (never their values) a cross-origin redirect hop dropped from a check holding secrets — the http checker's key, so a broken check is diagnosed the same way.

View Source
const OutputKeyRepairRefused = "aiRepairHostRefused"

OutputKeyRepairRefused flags the result of a repair-applied script that tried to reach a host outside its repair allowlist. The result pipeline flips the check back to `repair: propose` on it.

View Source
const OutputKeySteps = "steps"

OutputKeySteps is the result output key holding the named steps of a script that used step(): a list of {name, status, durationMs, error?, screenshot?}.

Variables

View Source
var OpenBrowser = func(ctx context.Context) (BrowserSession, error) {
	session, err := checkbrowser.Open(ctx)
	if err != nil {

		return nil, err
	}

	return session, nil
}

OpenBrowser is the seam `browser.open()` goes through. Production points at checkbrowser.Open — the same slot, pre-flight, isolated context and eager allocation the `browser` check type uses. Tests replace it with a fake.

Functions

func WithStoredRepairHold

func WithStoredRepairHold(ctx context.Context, stored map[string]any) context.Context

WithStoredRepairHold decides on the STORED config map, before its `${…}` references are resolved, whether the run is held to a repair grant (spec 2026-10-25-01), and carries the answer to Execute. A resolved reference changes the script or env text, so deciding on the run's config would let a `${var:uuid}` lift the grant.

Types

type BrowserSession

type BrowserSession interface {
	Navigate(ctx context.Context, url string) (checkbrowser.NavResult, error)
	BasicAuth(ctx context.Context, username, password, origin string) error
	WaitVisible(ctx context.Context, sel string) error
	Click(ctx context.Context, sel string) error
	Fill(ctx context.Context, sel, text string) error
	Press(ctx context.Context, sel, key string) error
	Check(ctx context.Context, sel string) error
	Uncheck(ctx context.Context, sel string) error
	Select(ctx context.Context, sel, option string) error
	Submit(ctx context.Context, sel string) error
	Text(ctx context.Context, sel string) (string, error)
	Evaluate(ctx context.Context, expr string) (any, error)
	URL(ctx context.Context) (string, error)
	Cookies(ctx context.Context) ([]checkbrowser.Cookie, error)
	Screenshot(ctx context.Context) (checkbrowser.Capture, error)
	Close()
}

BrowserSession is the slice of checkbrowser.Session the `browser` bindings drive.

It exists as an interface for exactly one reason: CI's backend job has no Chrome (only the E2E jobs install one), so every binding test runs against a fake through the OpenBrowser seam below. Production always gets the real *checkbrowser.Session.

One method per documented page API call; a smaller interface would just be a worse mirror of what a script can do.

type CheckerResolver

type CheckerResolver func(checkType checkerdef.CheckType) (checkerdef.Checker, checkerdef.Config, bool)

CheckerResolver is a function type that resolves a check type to a checker and checkconfig. It is set by the registry package during init to break the import cycle.

var ResolveChecker CheckerResolver //nolint:gochecknoglobals // Required to break import cycle

ResolveChecker is the function used to resolve checkers for sub-checks. Must be set before executing JS checks that use solidping.check().

type DeploymentGateFunc

type DeploymentGateFunc func(checkType checkerdef.CheckType, cfg checkerdef.Config) string

DeploymentGateFunc returns a non-empty refusal when THIS process must not run checkType as a sub-check for a deployment reason (not because the operator disabled the type), or "" to let it through. cfg is the sub-check's parsed config, nil on the first, type-only pass: a config can make a check host-local (a Unix socket target, spec 2026-11-24-01).

var DeploymentGate DeploymentGateFunc //nolint:gochecknoglobals // Mirrors TypeEnabled: same import-cycle break

DeploymentGate is the deployment-level gate consulted before a sub-check runs, after TypeEnabled. It is separate from TypeEnabled so its refusal reads as what it is — "docker checks are not available on this deployment" on a SaaS shared worker (spec 2026-10-16-09) — rather than "disabled on this server". Wired, like TypeEnabled, in checkworker.newCheckWorker, and in the API process for the script-authoring runner (app.buildAIChecks), both from checkworker.NewDeploymentGate over the same config.

nil means "no deployment gate": every type passes.

type IsolationSettings

type IsolationSettings struct {
	// Enabled runs each script in a child process. Off runs it in this
	// process, as before the spec (SP_JS_ISOLATION=off).
	Enabled bool
	// MemoryLimit is the child's memory limit, in bytes
	// (SP_JS_MEMORY_LIMIT_MB).
	MemoryLimit int64
	// CgroupDir is a delegated cgroup v2 directory each child gets its own
	// sub-cgroup of, with memory.max set (SP_JS_CGROUP). Linux only; empty
	// means none.
	CgroupDir string
	// Executable is the binary started as the child; empty means this one.
	Executable string
}

IsolationSettings decides how scripts run.

func Isolation

func Isolation() IsolationSettings

Isolation returns the settings scripts run with.

func SetIsolation

func SetIsolation(settings IsolationSettings) IsolationSettings

SetIsolation replaces the settings and returns the previous ones.

type JSChecker

type JSChecker struct{}

JSChecker implements the Checker interface for JavaScript checks.

func (*JSChecker) Execute

func (c *JSChecker) Execute(ctx context.Context, config checkerdef.Config) (*checkerdef.Result, error)

Execute performs the JavaScript check and returns the result.

func (*JSChecker) GetSampleConfigs

func (c *JSChecker) GetSampleConfigs(_ *checkerdef.ListSampleOptions) []checkerdef.CheckSpec

GetSampleConfigs returns sample JavaScript check configurations.

func (*JSChecker) Type

func (c *JSChecker) Type() checkerdef.CheckType

Type returns the check type identifier.

func (*JSChecker) Validate

func (c *JSChecker) Validate(spec *checkerdef.CheckSpec) error

Validate checks if the configuration is valid. Every rule lives in the light `config` sub-package so an offline validator (`sp checks validate`) can run it without linking this checker's execution client.

type JSConfig

type JSConfig = checkconfig.JSConfig

JSConfig is this check's configuration. It lives in the light `config` sub-package; this alias keeps every existing `checkjs.JSConfig` call site compiling.

type TypeEnabledFunc

type TypeEnabledFunc func(checkType checkerdef.CheckType) bool

TypeEnabledFunc reports whether a check type is enabled at the SERVER level (`checkers.enabled` / `checkers.disabled` / `checkers.enabled_labels`).

It deliberately takes no org: the JS runtime has no org identity (see the gate in jsRuntime.check), so per-org overrides cannot be answered here and the signature says so rather than pretending otherwise.

var TypeEnabled TypeEnabledFunc //nolint:gochecknoglobals // Mirrors ResolveChecker: same import-cycle break

TypeEnabled is the server-level activation gate consulted before a sub-check runs. It mirrors the ResolveChecker indirection above — checkjs cannot import registry or config-derived resolvers without an import cycle — and is wired in checkworker.newCheckWorker, the one constructor both the embedded worker and the standalone agent funnel through.

nil means "no gate configured": every type is allowed. That keeps this package usable standalone and in unit tests, and keeps the JS checker's behavior unchanged for any caller that never installs a gate.

Directories

Path Synopsis
Package config holds the js check's configuration: the struct, its map parsing and serialization, its key constants and the whole offline rule set (ValidateSpec).
Package config holds the js check's configuration: the struct, its map parsing and serialization, its key constants and the whole offline rule set (ValidateSpec).

Jump to

Keyboard shortcuts

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