Skip to content

fix(test): dispatch posted work to the app graph on targets - #563

Merged
houko merged 5 commits into
mainfrom
fix/test-post-engine
Nov 18, 2026
Merged

houko merged 5 commits into
mainfrom
fix/test-post-engine

Conversation

@houko

@houko houko commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #549.

App.Post(func() { signal.Set(value) }) worked headless but panicked on a target because the test goroutine does not own the real app's reactive graph. On a target, App.Post now hands its function to the scope the host renders the app under, so it runs on the engine goroutine, and the step's engine barrier waits for it. Internal storage and model callbacks keep running on the test's separate graph on the test goroutine.

  • A step on a target counts handed posts as activity and keeps settling while posts are queued after its last barrier, so a function that posts another (even a long chain of posts that changes nothing visible until the last) settles in the same step.
  • The scope App.Post uses is set by the engine goroutine (after Open returns on Windows and Android), so it is read and written under the target's lock; a post before the platform rendered the app fails the test with a message instead of a nil dereference.
  • tsx/tsxtest runs its goja VM's work (network route functions, host handler promises) on the test goroutine, which owns the VM. It used App.Post, which no longer runs there on a target, so it now uses an unexported hook nsgotest sets in internal/testhost (PostToTest). The layering test allows tsx/tsxtest to import internal/testhost, which nsgotest already imports, and docs/architecture/layers.md names the edge.
  • App.Post's doc says which goroutine fn runs on and that it takes no steps and does not call t.Fatal. The English and Chinese testing guides, the architecture testing doc and the skill reference say the same.

Targets

  • Shared nsgotest target dispatch; every backend uses the same scope-post path.
  • macOS, Windows, Linux and web run TestPostsRunOnTheAppGraph on the real target (see Verification).
  • CI already runs the whole internal/testhost/testdata/press package on Linux, macOS, Windows, web and the Android emulator, so the regression runs there without workflow changes.
  • iOS uses the same shared path; no device run (the test iPhone is unavailable).

Screenshots

None: graph ownership and test scheduling.

Verification

  • TestPostsRunOnTheAppGraph fails on main on a real target (Linux under Xvfb: core: the reactive graph belongs to another goroutine; use Scope.Post) and passes with this PR.
  • TestTargetPostsRunOnTheEngineAndSettleWhatTheyPost (nsgotest unit test, fake engine goroutine owning the graph) fails without the settle change (the step ran 13 of 41 chained posts) and passes with it.
  • Real targets, TestPostsRunOnTheAppGraph and TestPressModifiersReachTheApp: macOS (test binary run on a Mac desktop session), Windows 11 (interactive session), Linux (-target linux under Xvfb, whole press package) and web (-target web, whole press package): all passed.
  • Ubuntu: go build ./...; vets of nsgotest, tsx/tsxtest and internal/testhost for windows, linux and android/arm64; js/wasm build; go tool nsgo check -target all; go tool nsgo test of ./nsgotest, ./tsx/tsxtest, ./internal/testhost, ./internal/testhost/testdata/press, ./internal/moduletest, ./examples/tsx and -run 'Layer|Skills|Doc' .; the post regressions and target unit tests with -- -race -count=5: all passed. Every commit builds.
  • darwin and ios/arm64 vets on macOS: passed.
  • Review run on main at 4637dda: go tool nsgo test -target macos ./internal/testhost/testdata/press on a Mac desktop passed (10/10), and with main's nsgotest/tsxtest TestPostsRunOnTheAppGraph panics there with the graph-ownership check, which is the issue's acceptance.

Checklist

  • Conventional Commit title.
  • Public testing documentation (English and Chinese), architecture docs and skill reference updated; CHANGELOG untouched while it is frozen.
  • No new dependencies or third-party assets.

@github-actions github-actions Bot added size/S bug Something isn't working documentation Improvements or additions to documentation ci labels Nov 17, 2026
@houko
houko force-pushed the fix/test-post-engine branch from 8265ac6 to b789ea7 Compare November 17, 2026 14:22
@github-actions github-actions Bot added tsx size/S size/M conflict Conflicts with the base branch; resolve it first and removed size/S labels Nov 17, 2026
@houko
houko force-pushed the fix/test-post-engine branch from b789ea7 to 84524f2 Compare November 17, 2026 23:14
@github-actions github-actions Bot removed conflict Conflicts with the base branch; resolve it first size/S labels Nov 17, 2026
@houko
houko force-pushed the fix/test-post-engine branch 2 times, most recently from 1e96e3c to 53896e4 Compare November 18, 2026 01:10
A step on a target took the engine's barrier as the end of the work, but a posted function that posts another queues it on the test while the barrier runs, and posts handed to the engine did not count as activity, so a chain of posts longer than the quiet time left the step before the last one ran. Count handed posts as activity and keep settling while any are queued after the barrier. App.Post's doc says that fn takes no steps and does not call t.Fatal, as on a target it runs on the engine's goroutine, and the Chinese testing page mirrors the English one. nsgotest keeps a post to the test goroutine for tsxtest (testhost.PostToTest).
Network route functions and host handler promises run in the test's goja VM, which the test goroutine owns. They were posted with nsgotest.App.Post, which now runs its function on the engine's goroutine on a target; post them with testhost.PostToTest instead, which runs on the test goroutine headless and on a target alike.
…hook import

The engine's goroutine renders the app, on Windows and Android after Open returns, so the scope App.Post hands work to is set and read under the target's lock, and a post before the platform rendered the app fails the test instead of dereferencing nil. tsx/tsxtest reaches nsgotest's PostToTest hook through internal/testhost, which nsgotest already imports, so the layering test allows that edge and the layers doc names it.
A fake engine goroutine owns the app's graph and runs posts and barriers in order, so the test fails when a posted function runs off the engine or when a step returns before the posts a posted function made have run.
@houko
houko force-pushed the fix/test-post-engine branch from 53896e4 to a2dadc2 Compare November 18, 2026 01:52
@houko

houko commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

Reviewed. Rebased onto current main (now d55b37b, no conflicts at any step) and checked independently; every commit builds and vets after each rebase, and nsgotest, tsxtest, testhost, the press package, moduletest and the root doc tests pass headless on the final head.

Code: on a target App.Post wraps fn so the test goroutine hands it to the app scope (Scope.Post, which goes through the engine's FIFO message queue), so it runs before the barrier that Engine.Sync pushes after it. The app scope is recorded inside Open under the target lock, so platforms that render after Open returns are covered, and a post before render fails with a message. Handed posts count as activity and the final barrier re-checks queued posts, so post chains settle in one step. tsxtest keeps its goja VM work on the test goroutine through testhost.PostToTest; the layering test and docs/architecture/layers.md name that edge. Existing App.Post callers (ui, core, examples/orbit, cmd/nsgo/testdata/canvaszoom) only set signals or call refs, which is valid on the engine goroutine. Docs (en, zh, architecture, skill reference) match the behaviour. CHANGELOG untouched, no hard wraps, no unrelated changes.

Fails without the fix:

  • macOS target (this Mac's desktop, go tool nsgo test -target macos): with main's nsgotest/tsxtest, TestPostsRunOnTheAppGraph panics with the graph-ownership check in Signal.Update from target.runPosts; with the PR the whole press package passes (10/10).
  • TestTargetPostsRunOnTheEngineAndSettleWhatTheyPost fails with the settle change removed ("the step ran 13 of 41 chained posts") and passes with it.

Verification on the rebased head:

  • Ubuntu: go build ./...; every commit builds and vets; vets for windows/amd64, linux/amd64, android/arm64; js/wasm build; go tool nsgo test of ./nsgotest (79 passed), ./tsx/tsxtest, ./internal/testhost, ./internal/testhost/testdata/press, ./internal/moduletest, ./examples/tsx, ./ui (184), ./core (694) and the Layer/Skills/Doc root tests (35): all passed. -race -count=5 on the target unit tests and -race -count=3 on the press regression: passed.
  • Linux target (Xvfb) and web target (headless Chrome): TestPostsRunOnTheAppGraph and TestPressModifiersReachTheApp passed; web press package and ./tsx/pkg fully passed.
  • macOS: darwin and ios/arm64 vets passed; press package on the real desktop target passed.
  • Two failures seen during the run are pre-existing on main and identical with and without this PR: web TestNestedZoomedCanvasIsSharp (also failing in main's own CI) and, only on our Ubuntu Xvfb host, Linux TestOverflowPressLeavesItsContainersPressable (passes in CI).
  • Not device-checked here: Windows and Android (covered by this PR's CI jobs on the press package) and iOS (same shared path; no device available).
  • PR CI on the previous head (53896e4, main 4637dda): android, windows, apple, Gallery (macos/web), Build and vet and Build and vet (Apple) passed. The test job failed only on TestNestedZoomedCanvasIsSharp (failing on main too), and apple-simulator failed on TestSimulatorProcessResults timing ("the test took over 30s" for an empty TestFast), which other unrelated branches hit in the same window.

@houko

houko commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

Reviewed. The only CI failures are unrelated to this change: TestNestedZoomedCanvasIsSharp, fixed on main by #631, and the hosted runner's slow simulator boot, addressed by #634.

@houko
houko marked this pull request as ready for review November 18, 2026 04:15
@houko
houko merged commit 42afb74 into main Nov 18, 2026
18 of 19 checks passed
@houko
houko deleted the fix/test-post-engine branch November 18, 2026 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ci documentation Improvements or additions to documentation size/M tsx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nsgotest: App.Post runs its function on the test goroutine, which does not own the app's reactive graph on a target

1 participant