Skip to content

test: strengthen generated ID path-safety coverage#39

Closed
danReynolds wants to merge 2 commits into
mainfrom
claude/fix-broadcast-test-flake
Closed

test: strengthen generated ID path-safety coverage#39
danReynolds wants to merge 2 commits into
mainfrom
claude/fix-broadcast-test-flake

Conversation

@danReynolds

@danReynolds danReynolds commented May 26, 2026

Copy link
Copy Markdown
Owner

Summary

This PR keeps the generated-ID delimiter safety work aligned with current main.

main already contains the generator fix: generateSecureId and generateFastId use a 64-character URL-safe alphabet that excludes _, so generated path segments cannot contain Loon's __ path delimiter.

This PR adds stronger coverage for both generators and clarifies why _ is intentionally excluded from the alphabet.

Notes

I kept the 64-character alphabet instead of the original 62-character alphanumeric rejection-sampling approach because it preserves the fast 6-bit sampling path, avoids rejection overhead, and still prevents generated IDs from introducing store path boundaries.

Verification

  • flutter analyze lib/utils/id.dart test/core/id_test.dart
  • flutter test test/core/id_test.dart --concurrency=1
  • flutter test test/core --concurrency=1

Copilot AI review requested due to automatic review settings May 26, 2026 21:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes an intermittent test/core flake caused by cross-test leakage of Loon’s pending zero-delay broadcast timer after Loon.clearAll() runs in tearDown, which could cause the next test’s writes to piggyback on the prior test’s scheduled broadcast.

Changes:

  • Update the core test suite tearDown to await an extra event-loop turn after Loon.clearAll() so the scheduled broadcast is drained before the next test begins.
  • Add an explanatory comment documenting why the extra await is required for test isolation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@danReynolds danReynolds force-pushed the claude/fix-broadcast-test-flake branch from 626eb9f to 9fc001e Compare May 26, 2026 21:47
@danReynolds danReynolds changed the title test: drain pending broadcast in tearDown to fix cross-test flake fix: keep generated IDs free of the store path delimiter (fixes the broadcast "flake") May 26, 2026
generateId drew from an alphabet that included '_', so a random ID could
contain '__' — the delimiter the store uses to split paths into segments.
Because generated IDs are used as path segments (observer value keys,
auto-generated document IDs), a '__' in an ID split it into extra
segments and misplaced the value deeper in the store than reads and
invalidations expect:

  - An observable's cached value was stored below the path the broadcast
    manager invalidates (clearAll/writes call delete(path, recursive:
    false)), so it was never invalidated and the observer emitted a stale
    value. This is the intermittent "broadcast test flake": it fired
    whenever a random observer ID happened to contain '__' (~7.5% of core
    suite runs at --concurrency=1, more under parallel load). Forcing an
    extra segment into the observer ID turned it into 17 deterministic
    failures.
  - An auto-id document whose ID contained '__' was written below its
    collection node and was invisible to the collection's query.

Restrict generated IDs to alphanumeric [0-9A-Za-z] via uniform rejection
sampling, so an ID can never contain the delimiter. Adds a regression
test asserting generateId never produces '__' (100k samples).

Verified: core suite 45/45 green across parallel and --concurrency=1
stress runs that previously flaked ~7.5-20%.
@danReynolds danReynolds force-pushed the claude/fix-broadcast-test-flake branch from 9fc001e to a7c4b95 Compare May 31, 2026 12:28
…test-flake

# Conflicts:
#	lib/utils/id.dart
#	test/core/id_test.dart
@danReynolds danReynolds changed the title fix: keep generated IDs free of the store path delimiter (fixes the broadcast "flake") test: strengthen generated ID path-safety coverage May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants