Module: testDials

Server-side Test Dials — validation and AI prompt builder.

The frontend sends a structured config object. This module validates it against known option IDs and builds the prompt fragment injected into AI calls. Keeping this server-side means:

  1. The backend controls what text reaches the AI — no prompt injection risk.
  2. The same builder can be reused by backend-only flows (scheduled runs, API).
  3. Unknown / malicious option IDs are silently dropped.
  4. customInstructions is length-capped and stripped of injection markers.

Exports

  • validateDialsConfig — Validate and sanitise raw config from the frontend.
  • buildDialsPrompt — Build a prompt fragment from a validated config.
  • resolveDialsPrompt — Single entry-point for route handlers (validate + build).
  • resolveDialsConfig — Like resolveDialsPrompt but returns the config object.
  • Option arrays: APPROACH_OPTIONS, PERSPECTIVE_OPTIONS, QUALITY_OPTIONS, FORMAT_OPTIONS, LANGUAGES, TEST_COUNT_OPTIONS, EXPLORE_MODE_OPTIONS.
Source:

Methods

(static) buildDialsPrompt(cfg) → {string}

Build a prompt fragment from a validated Test Dials config. Returns "" when config is null or has no active dials.

Parameters:
Name Type Description
cfg DialsConfig | null

Validated config from validateDialsConfig.

Source:
Returns:

Prompt fragment ready to be injected into an AI call.

Type
string

(static) resolveDialsConfig(input) → {DialsConfig|null}

Like resolveDialsPrompt but returns the validated config object so callers can extract individual fields (e.g. testCount) directly.

Parameters:
Name Type Description
input Object | string | null

Raw config from request body.

Source:
Returns:

Validated config, or null if invalid/string.

Type
DialsConfig | null

(static) resolveDialsPrompt(input) → {string}

Single entry-point for route handlers — validates and builds the prompt in one call. Rejects raw strings to prevent prompt injection; only structured config objects accepted.

Parameters:
Name Type Description
input Object | string | null

Raw config from request body.

Source:
Returns:

Prompt fragment, or "" if input is invalid/string.

Type
string

(inner) clampInt()

Clamp a numeric value to [min, max], falling back to def if not a finite number.

Source:

Type Definitions

DialsConfig

Validate and sanitise a raw Test Dials config from the frontend. Drops unknown IDs silently. Caps customInstructions at 500 chars.

Type:
  • Object
Properties:
Name Type Description
approach string

Approach ID (e.g. "full_coverage").

perspectives Array.<string>

Array of perspective IDs.

quality Array.<string>

Array of quality check IDs.

format string

Format ID (e.g. "step_by_step").

language string

Language code (e.g. "en-US").

testCount string

Test count ID (e.g. "ai_decides").

exploreMode string

Explore mode ID ("crawl" or "state").

exploreMaxStates number

Max states to discover (5–100, default 30).

exploreMaxDepth number

Max exploration depth (1–10, default 3).

exploreMaxActions number

Max actions per state (1–20, default 8).

exploreActionTimeout number

Action timeout in ms (1000–15000, default 5000).

options Object

Boolean option flags.

customInstructions string

Free-text instructions (sanitised, max 500 chars).

Source: