mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 11:07:10 +00:00
* feat(spec): add llm() action-backend marker * feat(spec): make llm marker inert on the JS picker * feat(spec): expose __sanderlingSampleInput__ corpus draw * feat(openrouter): minimal chat-completions client * test(openrouter): cover request shape, parse, and errors * feat(verifier): thread screenshot + capture corpus sampler * feat(verifier): LLM accessors — candidates, config, sampler * test(verifier): cover AllCandidates, LLMConfig, SampleInput * feat(trace): record action Source and LLMReasoning * feat(runner): thread step screenshot into PushSnapshot * feat(runner): llmSource selects actions via OpenRouter * feat(runner): wire llmSource selection and trace stamping * test(runner): cover llmSource selection, mapping, downscale * docs(folio): add llm action-backend example spec * docs(folio): document the LLM action backend run * feat(llmclient): support OPENAI_API_KEY, openrouter wins * refactor(runner): rename openrouter package to llmclient * docs: both api keys, example model gpt-5.4-nano * docs: add pr style rules to claude.md * fix(runner): explain action kinds in llm prompt to stop swipe loops * feat(trace): record llm ranked list and chosen rank * feat(runner): stamp llm ranked list and chosen rank on trace * fix(runner): tap by selector to survive layout shift after observe * revert(runner): drop selector-first tap; broke path/testTag selectors * feat(spec): llm() accepts optional instructions * feat(verifier): read llm instructions off config * feat(runner): append spec instructions to llm system prompt * docs(folio): describe app in llm spec instructions * feat(bundler): map generator export to globalThis.generator * feat(verifier): read llm config off globalThis.generator * feat(runner): gate llm source on --generator flag * feat(cmd): add --generator llm|seeded flag * test: cover --generator flag parsing and pickSources gating * feat(verifier): enumerate llm candidates by walking actionsRoot collect-walk the weighted action tree: recurse weighted branches accumulating selection probability, call authored leaves once for concrete actions, enumerate builtins per element. label controls by visible text (borrowing descendant text), fold gestures into directional scrolls over scrollable containers, drop disabled, dedup descriptions. * test(verifier): cover candidate enumeration walk * feat(verifier): add SetupAction to walk setup without the seeded root * test(verifier): cover SetupAction setup-only precedence * refactor(llmclient): make JSONSchema.Schema raw json for pinned field order * feat(trace): record llm choice number and chosen_action echo * feat(runner): llm picks one number from weighted candidates drop the seeded-root call for a setup-only precedence path, render a numbered weighted candidate list, pin a reasoning-first choice schema, strict-skip when chosen_action does not echo the numbered entry, and let the model supply typed values (corpus fallback when empty). * test(runner): cover choice schema, strict-skip, and setup precedence * refactor(verifier): drop the superseded AllCandidates enumeration * feat(folio): drive spec.ts under --generator llm; drop spec-llm.ts * fix(verifier): label editable fields by hint, not the typed value an editable field's own text is its transient content; prefer the hint so the field is named by purpose and the label stays stable. * test(runner): cover weight-suffixed echo and stripWeightSuffix * fix(runner): accept chosen_action echo that carries the weight suffix real runs showed the model copies the whole numbered line including the trailing (w34) weight annotation, so strict-skip rejected ~91% of picks and the llm was paralyzed. strip the weight suffix before comparing. also nudge the prompt to stress-test repeated submissions (idempotency). * fix(verifier): skip llm enumeration on cross-fade frames a navhost mid-transition carries >1 route *Screen in a collapsed coordinate space; acting on it taps garbage (soft keyboard). real runs showed the llm acting on 44% of steps being such frames. skip them so the llm re-observes a settled frame next step. * feat(folio): show current balance on the add-transaction screen renders the account's balance (testTag TxnCurrentBalance) below the account name, above the credit/debit toggle, so before/after screenshots carry comparison data. * fix(replay): derive device space from screen extent, not first node the first positive-bounds element is often a short status-bar node (320x24 on android); using it gave a 320/24 aspect ratio that squashed the screenshot overlay into a grey horizontal band. use the max extent across elements (like the runner's screenBounds) instead. * fix(folio): show balance as a compact one-line label per review: one line, account-name-sized, e.g. "Balance: $0.00" instead of a large balance card. * fix(folio): move balance into the header, one compact line under the account name * fix(replay): attribute deferred violations to the causing step, not detection * fix(replay): show a step's own violations in both panels, no next-step bleed * refactor(hierarchy): one Tree.Transitional, drop the duplicated cross-fade check * chore: ignore .playwright-mcp scratch output * docs: document the llm generator and --generator flag * docs(spec): correct the llm() comment; config reads off globalThis.generator * docs: add pr description rules
147 lines
5.1 KiB
Go
147 lines
5.1 KiB
Go
// Command sanderling is the CLI entry point for the property-based UI fuzzer.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"time"
|
|
)
|
|
|
|
// Version is stamped at build time via goreleaser ldflags.
|
|
// Default "dev" marks untagged local builds.
|
|
var Version = "dev"
|
|
|
|
type testOptions struct {
|
|
spec string
|
|
bundleID string
|
|
platform string
|
|
avd string
|
|
device string
|
|
iosDevice string
|
|
iosAppPath string
|
|
androidAppPath string
|
|
duration time.Duration
|
|
seed int64
|
|
output string
|
|
clearData bool
|
|
generator string
|
|
}
|
|
|
|
const topUsage = `sanderling is a property-based UI fuzzer for mobile apps.
|
|
|
|
Usage:
|
|
sanderling <command> [flags]
|
|
|
|
Commands:
|
|
test Run a spec against an app for a fixed duration.
|
|
replay Serve a local web UI for browsing runs/.
|
|
doctor Check that the host environment is ready to run sanderling.
|
|
version Print the sanderling version.
|
|
|
|
Run "sanderling <command> -h" for command-specific flags.
|
|
`
|
|
|
|
func parseTestArgs(args []string, stderr io.Writer) (testOptions, error) {
|
|
flagSet := flag.NewFlagSet("test", flag.ContinueOnError)
|
|
flagSet.SetOutput(stderr)
|
|
var options testOptions
|
|
flagSet.StringVar(&options.spec, "spec", "", "path to the TypeScript spec (required)")
|
|
flagSet.StringVar(&options.bundleID, "bundle-id", "", "target app bundle ID (required)")
|
|
flagSet.StringVar(&options.platform, "platform", "android", "target platform: android, ios, web")
|
|
flagSet.StringVar(&options.avd, "avd", "", "Android AVD name to boot if no device is connected")
|
|
flagSet.StringVar(&options.device, "device", "", "Android device serial (from `adb devices`) to target when several are connected")
|
|
flagSet.StringVar(&options.iosDevice, "ios-device", "", "iOS target: a simulator name/UDID to boot, or a connected device's name, UDID, or CoreDevice id")
|
|
flagSet.StringVar(&options.iosAppPath, "ios-app-path", "", "path to the .app bundle for iOS clear-state reinstall (simulator: simctl; device: devicectl)")
|
|
flagSet.StringVar(&options.androidAppPath, "android-app-path", "", "path to the .apk for Android clear-state reinstall; required to reset apps on OEM builds that deny `pm clear`")
|
|
flagSet.DurationVar(&options.duration, "duration", 5*time.Minute, "total test duration")
|
|
flagSet.Int64Var(&options.seed, "seed", 0, "RNG seed (0 = random)")
|
|
flagSet.StringVar(&options.output, "output", "./runs", "output directory for traces")
|
|
flagSet.BoolVar(&options.clearData, "clear-data", true, "clear app data before launching so each run starts from a fresh install; pass --clear-data=false to resume prior state")
|
|
flagSet.StringVar(&options.generator, "generator", "seeded", "action generator: seeded (weighted random) or llm (model picks from the same candidate set; requires generator = llm() in the spec)")
|
|
if err := flagSet.Parse(args); err != nil {
|
|
return testOptions{}, err
|
|
}
|
|
if options.spec == "" {
|
|
return testOptions{}, errors.New("--spec is required")
|
|
}
|
|
if options.bundleID == "" {
|
|
return testOptions{}, errors.New("--bundle-id is required")
|
|
}
|
|
switch options.platform {
|
|
case "android", "ios", "web":
|
|
default:
|
|
return testOptions{}, fmt.Errorf("unsupported platform: %q (android, ios, web)", options.platform)
|
|
}
|
|
switch options.generator {
|
|
case "seeded", "llm":
|
|
default:
|
|
return testOptions{}, fmt.Errorf("unsupported generator: %q (seeded, llm)", options.generator)
|
|
}
|
|
return options, nil
|
|
}
|
|
|
|
func runTest(options testOptions, stdout io.Writer) error {
|
|
// A signal-aware root context: on Ctrl-C the cancellation propagates into
|
|
// the drivers' process contexts, so spawned children (the iOS companion,
|
|
// the xcodebuild runner session) get their SIGTERM instead of outliving
|
|
// the run as orphans.
|
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
|
defer cancel()
|
|
return runTestPipeline(ctx, options, stdout)
|
|
}
|
|
|
|
func runDoctor(args []string, stdout, stderr io.Writer) error {
|
|
options, err := parseDoctorArgs(args, stderr)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
checks := doctorChecksFor(options.platform)
|
|
return runDoctorChecks(context.Background(), checks, stdout)
|
|
}
|
|
|
|
func run(args []string, stdout, stderr io.Writer) error {
|
|
if len(args) < 2 || args[1] == "-h" || args[1] == "--help" || args[1] == "help" {
|
|
fmt.Fprint(stdout, topUsage)
|
|
return nil
|
|
}
|
|
switch args[1] {
|
|
case "test":
|
|
options, err := parseTestArgs(args[2:], stderr)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return runTest(options, stdout)
|
|
case "replay":
|
|
options, err := parseReplayArgs(args[2:], stderr)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return runReplay(options, stdout)
|
|
case "doctor":
|
|
return runDoctor(args[2:], stdout, stderr)
|
|
case "version", "-v", "--version":
|
|
fmt.Fprintln(stdout, Version)
|
|
return nil
|
|
default:
|
|
return fmt.Errorf("unknown command: %q (try 'sanderling help')", args[1])
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
if err := run(os.Args, os.Stdout, os.Stderr); err != nil {
|
|
// flag.ErrHelp means -h/--help was requested; flag already printed
|
|
// usage to stderr, so exit 0 rather than treating it as a failure.
|
|
if errors.Is(err, flag.ErrHelp) {
|
|
return
|
|
}
|
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|