mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
* refactor: rename examples/sample-app to examples/folio Directory-level rename and path references in Go tests, bundle-check, top-level README, and getting-started docs. Package declarations, Gradle config, iOS bundle IDs, and class names follow in later commits. * refactor(folio): rename Kotlin package dev.uatu.sample to app.folio Moves source dirs and sqldelight schema from dev/uatu/sample to app/folio, updates package declarations and imports, and switches Android namespace/applicationId, iOS binaryOption bundleId, and sqldelight database packageName to the new identifier. * refactor(folio): rename SampleApplication to FolioApplication Android manifest now points at .FolioApplication with label 'Folio' instead of 'Uatu Sample'. * refactor(folio): set iOS bundle id and display name to Folio bundleIdPrefix + PRODUCT_BUNDLE_IDENTIFIER -> app.folio. CFBundleName + CFBundleDisplayName -> 'Folio'. * refactor(folio): update demo email to [email protected] * refactor(folio): point justfile at app.folio bundle id Updates xcrun simctl launch target, uatu test --bundle-id, and the build/uninstall comments to reference folio instead of sample. * test: update fixture package ids to app.folio Sidecar activity-resolver test and verifier spec-integration XML fixtures referenced the old dev.uatu.sample Android package. Updates them to match the folio app's real package id so the tests stay representative of what the CLI sees on-device. * test(verifier): rename SampleApp identifiers to Folio Renames TestSampleAppSpec* functions, bundleSampleAppSpec helper, and sampleAppHierarchyXML const (now loginHierarchyXML for consistency with the other per-screen fixtures). Updates trailing sample-app mentions in comments and assertion messages. * refactor(folio): rename Gradle/npm/wasm project identifiers to folio settings.gradle.kts rootProject.name, package.json + package-lock.json name, and the WasmJS index.html <title> all still read 'uatu-sample' / 'Uatu Sample'. Realigns them with the Folio brand. * docs(folio): rewrite README title + getting-started bundle id examples/folio/README.md is now titled 'Folio' with the Kotlin source paths corrected to app/folio. Getting-started example uses --bundle-id app.folio. Harness launch message is now generic ('app under test') since uatu-sample-harness is not specific to folio. * chore(folio): drop trailing 'sample' reference in gradle.properties * refactor(folio): rename LoginPage composable to LoginScreen Align with KMP/Android industry convention (NowInAndroid, Cash App, JetBrains samples use Screen, not Page). * refactor(folio): rename HomePage composable to HomeScreen * refactor(folio): rename AddAccountPage composable to AddAccountScreen * refactor(folio): rename LedgerPage composable to LedgerScreen * refactor(folio): rename AddTransactionPage composable to AddTransactionScreen * refactor(folio): split Models.kt into app.folio.data package Account, Transaction (with TxnType), and Session move into their own files under app.folio.data, matching NowInAndroid-style per-type organization. * refactor(folio): move data layer into app.folio.data package Repository, LedgerStore (expect + interface), SqlLedgerStore, WebLedgerStore, DriverFactory (expect + actuals), AndroidLedgerContext, and Snapshot move into app.folio.data. Update all consumer imports. * refactor(folio): move Navigation into app.folio.navigation package Split the former Navigation.kt into Route.kt (sealed interface) and Navigator.kt (singleton). Update consumer imports across screens, App.kt, and FolioApplication. * refactor(folio): move Platform and Format into app.folio.platform Both files carry expect declarations (Platform object, formatDate); grouping them into a dedicated platform package makes the KMP seam obvious and mirrors the structure used by JetBrains samples. * refactor(folio): move login into feature/auth package Create app.folio.feature.auth with LoginScreen + LoginUiState. Inline the former Auth.kt (DEMO_EMAIL, DEMO_PASSWORD, checkCredentials) into LoginScreen since it is the sole caller. * refactor(folio): move HomeScreen into feature/home package * refactor(folio): move account creation into feature/account package AddAccountScreen gets its own AddAccountUiState colocated with the screen, replacing the shared UiState.addAccountError. * refactor(folio): move ledger screens into feature/ledger package LedgerScreen and AddTransactionScreen move into app.folio.feature.ledger with AddTransactionUiState (txnError, txnFormType) colocated. The former catch-all UiState.kt is removed now that each screen owns its state alongside its UI. * refactor(folio): split Theme.kt; move theme and icons to subpackages Theme split into Theme.kt (tokens, layout dims, LedgerTheme) and Type.kt (typography) under app.folio.ui.theme. Icons moves to app.folio.ui.icon. Update every consumer's imports to match. * refactor(folio): split ui components into per-file under ui/component Former Widgets.kt and Components.kt become 10 focused files: AppButton, Card, EmptyState, ErrorText, FieldLabel, Header, IconButton (w/ BackButton), Screen, Segmented, TextInput. Matches NowInAndroid style of one composable per file in a designsystem/component package. * chore(folio): consolidate uatu testing files under uatu/ folder Move spec.ts, package.json, package-lock.json into examples/folio/uatu so all uatu-specific testing artifacts live in one place. runs/ and node_modules/ follow the same convention (both remain gitignored). Update justfile, README, and the two Go consumers (bundle-check tool + verifier/trace tests) that referenced the old path. * refactor(trace): drop folio path in writer test Round-trip only needs a non-empty string; neutralize to keep the library free of folio references. * refactor(sidecar): neutralize ResolveActivity test fixtures Swap app.folio for com.example.app in the fixture strings so the sidecar tests don't reference the example app by name. * refactor(bundle-check): take spec path as argument Previously the tool hardcoded examples/folio/uatu/spec.ts. Accept a positional spec path instead so the tool works for any example and leaves no folio reference in the library surface. * test(verifier): add neutral integration spec and hierarchy fixtures Adds testdata/integration_spec.ts with two routes ("list", "form"), an InputText on text_field, a Tap on primary/secondary_action, a safety property (itemCountNonNegative), and a liveness property (submitEventually). Adds hierarchies_test.go with matching XML fixtures. Constants intentionally go in a _test.go at package root rather than testdata/hierarchies.go because go skips .go files under testdata/. * refactor(verifier): replace folio integration tests with neutral ones Renames bundleFolioSpec -> bundleIntegrationSpec and the three Test* entry points to TestIntegrationSpec*. Uses the synthetic spec and hierarchies added in the previous commit so the library's test suite no longer references examples/folio at all. Folio-specific coverage remains covered by examples/folio/justfile's 'just test' which exercises the real spec on device/emulator. * chore: remove cmd/uatu-sample-harness Not referenced by Makefile, docs, CI, or any script. Duplicates the adb reverse helpers already in cmd/uatu/test_run.go, and its name implies ownership by the sample app which violates the library/ example decoupling. If a bare-protocol debugging tool is later needed it belongs inside cmd/uatu/. * docs(folio): drop Layout section and KMP layout paragraph; fix AVD override syntax The directory-tree Layout section rots faster than the code and duplicates what ls shows for free. The expect/actual paragraph in Stack was the same kind of filler. The README also claimed 'just AVD=Pixel_7 test' but the justfile reads AVD as an env var via env_var_or_default, so the correct invocation is 'AVD=Pixel_7 just test'.
200 lines
4.9 KiB
Go
200 lines
4.9 KiB
Go
package trace
|
|
|
|
import (
|
|
"bufio"
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestWriteMeta_RoundTrip(t *testing.T) {
|
|
directory := t.TempDir()
|
|
writer, err := NewWriter(directory)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer writer.Close()
|
|
|
|
meta := Meta{
|
|
Seed: 42,
|
|
SpecPath: "spec.ts",
|
|
BundleSHA256: "deadbeef",
|
|
Platform: "android",
|
|
BundleID: "in.okcredit.merchant",
|
|
StartedAt: time.Date(2026, 4, 17, 22, 30, 0, 0, time.UTC),
|
|
UatuVersion: "0.0.1",
|
|
}
|
|
if err := writer.WriteMeta(meta); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
body, err := os.ReadFile(filepath.Join(directory, "meta.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var got Meta
|
|
if err := json.Unmarshal(body, &got); err != nil {
|
|
t.Fatalf("meta.json is not valid JSON: %v\n%s", err, body)
|
|
}
|
|
if got != meta {
|
|
t.Errorf("meta round-trip mismatch:\n got: %+v\nwant: %+v", got, meta)
|
|
}
|
|
}
|
|
|
|
func TestWriteStep_AppendsOneJsonLine(t *testing.T) {
|
|
directory := t.TempDir()
|
|
writer, err := NewWriter(directory)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer writer.Close()
|
|
|
|
step := Step{
|
|
Index: 1,
|
|
Timestamp: time.Now().UTC(),
|
|
Screen: "customer_ledger",
|
|
Snapshots: map[string]json.RawMessage{
|
|
"ledger.balance": json.RawMessage(`1500`),
|
|
},
|
|
Action: &Action{Kind: "tap", X: 100, Y: 200},
|
|
Violations: []string{"ledgerBalanceMatchesTxns"},
|
|
}
|
|
if err := writer.WriteStep(step); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
lines := readLines(t, filepath.Join(directory, "trace.jsonl"))
|
|
if len(lines) != 1 {
|
|
t.Fatalf("expected 1 line, got %d", len(lines))
|
|
}
|
|
var got Step
|
|
if err := json.Unmarshal([]byte(lines[0]), &got); err != nil {
|
|
t.Fatalf("invalid JSONL line: %v\n%s", err, lines[0])
|
|
}
|
|
if got.Index != 1 || got.Screen != "customer_ledger" || got.Action.X != 100 || got.Violations[0] != "ledgerBalanceMatchesTxns" {
|
|
t.Errorf("step round-trip wrong: %+v", got)
|
|
}
|
|
}
|
|
|
|
func TestWriteStep_MultipleStepsAppend(t *testing.T) {
|
|
directory := t.TempDir()
|
|
writer, err := NewWriter(directory)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer writer.Close()
|
|
|
|
for index := 1; index <= 3; index++ {
|
|
if err := writer.WriteStep(Step{Index: index, Screen: "s"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
lines := readLines(t, filepath.Join(directory, "trace.jsonl"))
|
|
if len(lines) != 3 {
|
|
t.Fatalf("expected 3 lines, got %d", len(lines))
|
|
}
|
|
}
|
|
|
|
func TestWriteStep_ViolationsAreGreppable(t *testing.T) {
|
|
directory := t.TempDir()
|
|
writer, _ := NewWriter(directory)
|
|
defer writer.Close()
|
|
|
|
_ = writer.WriteStep(Step{Index: 1})
|
|
_ = writer.WriteStep(Step{Index: 2, Violations: []string{"prop1"}})
|
|
_ = writer.WriteStep(Step{Index: 3})
|
|
|
|
body, err := os.ReadFile(filepath.Join(directory, "trace.jsonl"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(string(body), `"violations":["prop1"]`) {
|
|
t.Errorf("violations not in expected JSON shape: %s", body)
|
|
}
|
|
}
|
|
|
|
func TestWriteScreenshot_CreatesPaddedFilenames(t *testing.T) {
|
|
directory := t.TempDir()
|
|
writer, _ := NewWriter(directory)
|
|
defer writer.Close()
|
|
|
|
pngBytes := []byte{0x89, 0x50, 0x4e, 0x47}
|
|
if err := writer.WriteScreenshot(7, pngBytes); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := writer.WriteScreenshot(2024, pngBytes); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
got, err := os.ReadFile(filepath.Join(directory, "screenshots", "step-00007.png"))
|
|
if err != nil {
|
|
t.Fatalf("step-00007 missing: %v", err)
|
|
}
|
|
if string(got) != string(pngBytes) {
|
|
t.Errorf("screenshot bytes wrong")
|
|
}
|
|
if _, err := os.Stat(filepath.Join(directory, "screenshots", "step-02024.png")); err != nil {
|
|
t.Errorf("step-02024 missing: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestWriteScreenshot_EmptyByteSliceIsNoop(t *testing.T) {
|
|
directory := t.TempDir()
|
|
writer, _ := NewWriter(directory)
|
|
defer writer.Close()
|
|
|
|
if err := writer.WriteScreenshot(1, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(directory, "screenshots")); !os.IsNotExist(err) {
|
|
t.Errorf("screenshots dir should not exist after empty write")
|
|
}
|
|
}
|
|
|
|
func TestWriteAfterClose_Errors(t *testing.T) {
|
|
directory := t.TempDir()
|
|
writer, _ := NewWriter(directory)
|
|
if err := writer.Close(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
err := writer.WriteStep(Step{Index: 1})
|
|
if err == nil || !strings.Contains(err.Error(), "closed") {
|
|
t.Errorf("expected closed-writer error, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestNewWriter_CreatesNestedDirectory(t *testing.T) {
|
|
parent := t.TempDir()
|
|
target := filepath.Join(parent, "runs", "2026-04-17T22-30-00")
|
|
writer, err := NewWriter(target)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer writer.Close()
|
|
if _, err := os.Stat(target); err != nil {
|
|
t.Errorf("nested directory was not created: %v", err)
|
|
}
|
|
}
|
|
|
|
func readLines(t *testing.T, path string) []string {
|
|
t.Helper()
|
|
file, err := os.Open(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer file.Close()
|
|
|
|
var lines []string
|
|
scanner := bufio.NewScanner(file)
|
|
for scanner.Scan() {
|
|
lines = append(lines, scanner.Text())
|
|
}
|
|
if err := scanner.Err(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return lines
|
|
}
|