rastrillo / fiesta Public

Hold shell.js's and transition.js's transition observers identical

Both files stay standalone, since a server sends their bytes as they are with no build step between. TestTheTwoTransitionObserversAreTheSame holds the WeakSet and the function identical but for its name, as strings_test.go holds the two fiestaWord copies, so an edit to one fails until the other matches.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev f8e7085b76b603248b57fedf48838e433afde6e4 parent 2e3ad9e
1 file changed, +31 −0
  • check/shell_test.go +31 −0
diff --git a/check/shell_test.go b/check/shell_test.go
index af28071..726e702 100644
--- a/check/shell_test.go
+++ b/check/shell_test.go
@@ -2,6 +2,7 @@ package check
import (
"encoding/json"
+ "strings"
"testing"
"amadan.net/rastrillo/fiesta/internal/nodetest"
@@ -60,3 +61,33 @@ func skippedTransitionsAreSwallowed(t *testing.T, script string) {
func TestTransitionJSSwallowsOnlyASkippedTransition(t *testing.T) {
skippedTransitionsAreSwallowed(t, "transition.js")
}
+
+// TestTheTwoTransitionObserversAreTheSame: shell.js and transition.js
+// each carry the code that swallows a skipped transition's rejection,
+// because each is a file a page loads on its own, with no build step
+// between this tree and the bytes a server sends. The price of two
+// copies is drift, so the two are held identical: the WeakSet and the
+// function, character for character, but for the function's name.
+func TestTheTwoTransitionObserversAreTheSame(t *testing.T) {
+ shell := transitionObserver(t, "shell.js", "observeTransition")
+ alone := transitionObserver(t, "transition.js", "observe")
+ renamed := strings.ReplaceAll(shell, "function observeTransition(", "function observe(")
+ if renamed != alone {
+ t.Errorf("the transition observer differs between shell.js and transition.js:\n--- shell.js\n%s\n--- transition.js\n%s", shell, alone)
+ }
+}
+
+// transitionObserver is one script's observer: the WeakSet declared
+// straight before it and the function itself. It fails the test when
+// the script has no such pair, so the comparison is never of nothing.
+func transitionObserver(t *testing.T, script, name string) string {
+ t.Helper()
+ const set = "var observed = new WeakSet();\n"
+ js := string(shippedScript(t, script))
+ body := functionBody(js, name)
+ at := strings.Index(js, set+strings.Repeat(" ", 2)+"function "+name+"(")
+ if body == "" || at < 0 {
+ t.Fatalf("%s has no %q followed by function %s", script, strings.TrimSpace(set), name)
+ }
+ return set + body
+}