feat(spec): reject an unknown object-selector key in the web runtime

Same rule and the same message as the native side: a key no element can
carry throws instead of matching nothing. The accepted list is one list,
committed as a fixture both suites assert, so a spec cannot be accepted
by one runtime and rejected by the other.
This commit is contained in:
pj committed 2026-08-13 00:38:40 +05:30
1 parent 1332471b72
commit 269574706d
5 files changed
+239 -10

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
package hierarchy
import (
"encoding/json"
"os"
"path/filepath"
"slices"
"testing"
)
// Both runtimes reject an object-selector key they do not know, so the two key
// lists have to be one list. Were they to drift, a spec would be accepted by
// the runtime that lists the key and fail the run on the one that does not, and
// the difference would only show on the platform nobody ran first.
// pkg/spec/test/selector-keys.test.ts asserts the SAME file from the web side.
func TestSelectorKeysMatchTheCrossRuntimeList(t *testing.T) {
path, err := filepath.Abs("../../pkg/spec/test/fixtures/selector-keys.json")
if err != nil {
t.Fatal(err)
}
body, err := os.ReadFile(path)
if err != nil {
t.Fatalf("read selector keys: %v", err)
}
var want []string
if err := json.Unmarshal(body, &want); err != nil {
t.Fatalf("decode selector keys: %v", err)
}
if got := SelectorKeys(); !slices.Equal(got, want) {
t.Errorf("native key list\n got=%v\nwant=%v", got, want)
}
}
func TestSelectorKeysAreSorted(t *testing.T) {
keys := SelectorKeys()
if !slices.IsSorted(keys) {
t.Errorf("keys must stay sorted so the two lists compare readably: %v", keys)
}
}