From 3197e64562615a88ed48565645bed47a330a63b5 Mon Sep 17 00:00:00 2001 From: PJ Date: Sat, 6 Jun 2026 12:45:22 +0530 Subject: [PATCH] test(cmd): smoke-test bundle-check resolves spec aliases --- cmd/internal-tools/bundle-check/main_test.go | 57 +++++++++++++++++++ .../bundle-check/testdata/spec.ts | 12 ++++ 2 files changed, 69 insertions(+) create mode 100644 cmd/internal-tools/bundle-check/main_test.go create mode 100644 cmd/internal-tools/bundle-check/testdata/spec.ts diff --git a/cmd/internal-tools/bundle-check/main_test.go b/cmd/internal-tools/bundle-check/main_test.go new file mode 100644 index 0000000..b963556 --- /dev/null +++ b/cmd/internal-tools/bundle-check/main_test.go @@ -0,0 +1,57 @@ +package main + +import ( + "os" + "path/filepath" + "testing" +) + +// repoSpecSrc walks up from the test's working directory to the repo root and +// returns pkg/spec/src. The bundle-check aliases once pointed at the +// non-existent pkg/spec-api/src, so esbuild resolved nothing and the tool +// silently emitted an empty bundle. +func repoSpecSrc(t *testing.T) string { + t.Helper() + dir, err := os.Getwd() + if err != nil { + t.Fatal(err) + } + for { + candidate := filepath.Join(dir, "pkg/spec/src") + if _, err := os.Stat(filepath.Join(candidate, "index.ts")); err == nil { + return candidate + } + parent := filepath.Dir(dir) + if parent == dir { + t.Fatal("pkg/spec/src/index.ts not found above test dir") + } + dir = parent + } +} + +func TestBundleSpec_ResolvesSpecAliases(t *testing.T) { + specSrc := repoSpecSrc(t) + entry, err := filepath.Abs(filepath.Join("testdata", "spec.ts")) + if err != nil { + t.Fatal(err) + } + + result, err := bundleSpec(specSrc, entry) + if err != nil { + t.Fatalf("bundle: %v", err) + } + if len(result.JavaScript) == 0 { + t.Fatal("empty bundle: aliases resolved to nothing") + } + if result.SHA256 == "" { + t.Fatal("missing bundle hash") + } + + second, err := bundleSpec(specSrc, entry) + if err != nil { + t.Fatal(err) + } + if result.SHA256 != second.SHA256 { + t.Errorf("unstable bundle hash: %s vs %s", result.SHA256, second.SHA256) + } +} diff --git a/cmd/internal-tools/bundle-check/testdata/spec.ts b/cmd/internal-tools/bundle-check/testdata/spec.ts new file mode 100644 index 0000000..6332cb2 --- /dev/null +++ b/cmd/internal-tools/bundle-check/testdata/spec.ts @@ -0,0 +1,12 @@ +import { Tap, actions } from "@sanderling/spec"; +import { noUncaughtExceptions } from "@sanderling/spec/defaults/properties"; +import * as defaults from "@sanderling/spec/defaults"; + +const tapPrimary = actions((state) => { + const button = state.ax.find("desc:primary"); + return button ? [Tap({ on: button })] : []; +}); + +export const properties = { noUncaughtExceptions }; +export const actionsRoot = tapPrimary; +export const defaultsKeys = Object.keys(defaults);