Skip to content

test(tree): add tree change event ordering tests - #27852

Merged
Jenn (jenn-le) merged 7 commits into
microsoft:mainfrom
jenn-le:jenn-le-tree-event-ordering-tests
Aug 11, 2026
Merged

test(tree): add tree change event ordering tests#27852
Jenn (jenn-le) merged 7 commits into
microsoft:mainfrom
jenn-le:jenn-le-tree-event-ordering-tests

Conversation

@jenn-le

Copy link
Copy Markdown
Contributor

Description

Adds tests that assert the ordering guarantees of SharedTree's change events (nodeChanged, treeChanged, rootChanged) and their interaction with withBufferedTreeEvents. These tests document and lock in the following behaviors:

  • nodeChanged fires before treeChanged on the same node
  • Events propagate bottom-up through the tree hierarchy
  • rootChanged fires after nodeChanged/treeChanged (via afterBatch)
  • withBufferedTreeEvents inverts rootChanged relative to buffered node events
  • Node events respect ordering within buffered flushes

Also updates a TODO comment in treeChangeEvents.ts to document the confirmed bottom-up ordering behavior.

Reviewer Guidance

Reviewer Guidance Wiki

The test file is self-contained. The only production code change is replacing a TODO with documentation (line 69 of treeChangeEvents.ts).

Copilot AI lite review requested due to automatic review settings August 4, 2026 22:30
@jenn-le
Jenn (jenn-le) requested a review from a team as a code owner August 4, 2026 22:30
@github-actions github-actions Bot added area: tools area: dds Issues related to distributed data structures area: repo Repo related work area: website area: dds: tree base: main PRs targeted against main branch labels Aug 4, 2026
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Hi! Thank you for opening this PR. Want me to review it?

Based on the diff (518 lines, 2 files), I've queued these reviewers:

  • Correctness — logic errors, race conditions, lifecycle issues
  • Security — vulnerabilities, secret exposure, injection
  • API Compatibility — breaking changes, release tags, type design
  • Performance — algorithmic regressions, memory leaks
  • Testing — coverage gaps, hollow tests

How this works

  • Adjust the reviewer set by ticking/unticking boxes above. Reviewer toggles alone don't trigger anything.

  • Tick Start review below to dispatch the review fleet.

  • After review finishes, tick Start review again to request another run — it auto-resets after each dispatch.

  • This comment updates as new commits land; your reviewer selections are preserved.

  • Start review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

@jenn-le Jenn (jenn-le) changed the title test(tree): add comprehensive tree change event ordering tests test(tree): add tree change event ordering tests Aug 4, 2026
@jenn-le
Jenn (jenn-le) requested a review from a team as a code owner August 7, 2026 01:01
@github-actions github-actions Bot added area: examples Changes that focus on our examples area: framework Framework is a tag for issues involving the developer framework. Eg Aqueduct area: runtime Runtime related issues area: driver Driver related issues area: build Build related issues area: dds: sharedstring area: tests Tests to add, test infrastructure improvements, etc public api change Changes to a public API changeset-present labels Aug 7, 2026
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🔗 No broken links found! ✅

Your attention to detail is admirable.

linkcheck output

1: starting server using command "npm run serve -- --no-open"
and when url "[ 'http://127.0.0.1:3000' ]" is responding with HTTP status code 200
running tests using command "npm run check-links"


> fluid-framework-website@0.0.0 serve
> docusaurus serve --no-open

[SUCCESS] Serving "build" directory at: http://localhost:3000/

> fluid-framework-website@0.0.0 check-links
> linkcheck http://localhost:3000 --skip-file skipped-urls.txt

Crawling...

Stats:
  309092 links
    1963 destination URLs
    2219 URLs ignored
       0 warnings
       0 errors


@Josmithr

Copy link
Copy Markdown
Contributor

Jenn (@jenn-le) Looks like this PR has some extraneous changes FYI

Jenn (jenn-le) and others added 4 commits August 10, 2026 11:33
Add a new test file (treeChangeEventOrdering.spec.ts) that validates the
ordering guarantees of nodeChanged, treeChanged, and rootChanged events:

- Single node: nodeChanged fires before treeChanged on the same node
- Parent+child: bottom-up ordering with nodeChanged before treeChanged
  at each level, tested with 2-level and 3-level hierarchies
- rootChanged: fires after nodeChanged/treeChanged (afterBatch listener)
- withBufferedTreeEvents: documents that rootChanged fires during the
  callback (not buffered by KernelEventBuffer) while node events are
  buffered and flushed after, inverting the normal ordering
- Buffered events preserve nodeChanged-before-treeChanged on flush

Also replaces the TODO comment in treeChangeEvents.ts with documentation
of the bottom-up event ordering behavior.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Factor the repeated TreeBeta.on(node, 'nodeChanged'/treeChanged', ...)
pattern into a subscribeToNodeEvents(node, log, prefix?) helper function,
reducing boilerplate across all test cases.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…d test

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…adability

Replace index-based and loop-based assertions with direct deepEqual
comparisons of the full expected event log. This makes the expected
ordering immediately visible while also being future-proof — any
unexpected extra or reordered events will cause a clear failure.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@jenn-le
Jenn (jenn-le) force-pushed the jenn-le-tree-event-ordering-tests branch from fc55d51 to 7eb201d Compare August 10, 2026 18:34
@github-actions github-actions Bot removed the area: examples Changes that focus on our examples label Aug 10, 2026
@github-actions github-actions Bot removed area: framework Framework is a tag for issues involving the developer framework. Eg Aqueduct area: runtime Runtime related issues area: driver Driver related issues area: build Build related issues area: dds: sharedstring area: tests Tests to add, test infrastructure improvements, etc public api change Changes to a public API changeset-present labels Aug 10, 2026
// Both parent and child change in the same buffered batch
withBufferedTreeEvents(() => {
root.child.value = 42;
root.ownProp = "world";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried running this test with the edit order switched, and the test failed, so we may have to find a different way to test this (which I don't know either). I chatted with Craig about this a while ago, so I think he may have some good ideas on how to test this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I made a mistake, it still orders nodeChanged before treeChanged, so this test is good :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added another test and clarified some docs showing that the event order is based on edit order but nodeChanged comes before treeChanged for each node

When both parent and child are directly edited in a buffered batch,
events fire in the order nodes were first edited — not strictly
bottom-up by tree depth. Updates the doc comment in treeChangeEvents.ts
to reflect this more accurate description.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@jenn-le
Jenn (jenn-le) enabled auto-merge (squash) August 10, 2026 22:21
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

Bundle size comparison

Base commit: 7c161bef46c3679c2b494a6798616f5a9d1bf25e
Head commit: cf3ecb904d459bdeb9deef8abdc84ab63e0660d7

Notable changes

No bundles changed by ≥ 500 bytes parsed.

Per-bundle deltas

@fluid-example/bundle-size-tests

  • fluidFrameworkAllAlpha.js: parsed 780911 → 780953 (+42), gzip 214191 → 214228 (+37)
  • azureClient.js: parsed 624465 → 624521 (+56), gzip 166500 → 166545 (+45)
  • odspClient.js: parsed 596753 → 596809 (+56), gzip 159641 → 159685 (+44)
  • aqueduct.js: parsed 530843 → 530878 (+35), gzip 141979 → 142008 (+29)
  • fluidFramework.js: parsed 399466 → 399487 (+21), gzip 113434 → 113450 (+16)
  • sharedTree.js: parsed 388870 → 388884 (+14), gzip 110880 → 110889 (+9)
  • containerRuntime.js: parsed 308960 → 308974 (+14), gzip 84482 → 84488 (+6)
  • sharedString.js: parsed 176457 → 176464 (+7), gzip 49807 → 49815 (+8)
  • experimentalSharedTree.js: parsed 160677 → 160677 (0), gzip 46276 → 46276 (0)
  • matrix.js: parsed 160302 → 160309 (+7), gzip 45800 → 45807 (+7)
  • loader.js: parsed 145700 → 145714 (+14), gzip 39284 → 39300 (+16)
  • odspDriver.js: parsed 103906 → 103927 (+21), gzip 32404 → 32411 (+7)
  • directory.js: parsed 67110 → 67117 (+7), gzip 18859 → 18866 (+7)
  • 578.js: parsed 58686 → 58686 (0), gzip 17657 → 17657 (0)
  • map.js: parsed 47205 → 47212 (+7), gzip 14455 → 14462 (+7)
  • odspPrefetchSnapshot.js: parsed 45635 → 45649 (+14), gzip 15242 → 15250 (+8)
  • 252.js: parsed 44371 → 44371 (0), gzip 13732 → 13732 (0)
  • summarizerDelayLoadedModule.js: parsed 30717 → 30717 (0), gzip 7716 → 7716 (0)
  • socketModule.js: parsed 26469 → 26476 (+7), gzip 7896 → 7904 (+8)
  • createNewModule.js: parsed 12454 → 12454 (0), gzip 4797 → 4797 (0)
  • summaryModule.js: parsed 3789 → 3789 (0), gzip 1857 → 1857 (0)
  • connectionState.js: parsed 909 → 909 (0), gzip 500 → 500 (0)
  • sharedTreeAttributes.js: parsed 847 → 854 (+7), gzip 499 → 508 (+9)
  • debugAssert.js: parsed 429 → 429 (0), gzip 299 → 299 (0)
  • FluidFramework-HashFallback.js: parsed 419 → 419 (0), gzip 313 → 313 (0)

@jenn-le
Jenn (jenn-le) merged commit 086df40 into microsoft:main Aug 11, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: dds: tree area: dds Issues related to distributed data structures area: repo Repo related work area: tools area: website base: main PRs targeted against main branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants