Skip to content

fix: harden flaky stories mark-watched integration test - #306

Open
itsmeadi wants to merge 1 commit into
mainfrom
fix/stories-mark-watched-ws-flake
Open

itsmeadi wants to merge 1 commit into
mainfrom
fix/stories-mark-watched-ws-flake

Conversation

@itsmeadi

@itsmeadi itsmeadi commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Hardens the flaky stories.test.ts mark-watched cases that timed out waiting for feeds.stories_feed.updated (seen on CI run 29350895100).
  • Adds markWatchedAndSync, which prefers the realtime event and falls back to getOrCreate({ watch: true }) when the event is dropped.
  • Allows an optional timeout on waitForEvent.

Test plan

  • Confirm CI lint-and-test passes on this PR
  • Optionally run locally: yarn workspace @stream-io/feeds-client run test stories.test.ts (requires Stream API credentials)

Made with Cursor

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability of watched-story synchronization, helping watched statuses update consistently across story feeds.
  • Tests

    • Expanded synchronization coverage for aggregated and direct story feeds.
    • Added fallback handling to keep watched-state updates dependable when real-time updates are delayed.

Prefer feeds.stories_feed.updated, but fall back to getOrCreate when the
WS event is intermittently dropped so CI does not fail spuriously.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Stories watch synchronization

Layer / File(s) Summary
Watched-state synchronization helper
packages/feeds-client/__integration-tests__/utils.ts
waitForEvent accepts a configurable timeout, and markWatchedAndSync waits for the story-feed update event with a getOrCreate({ watch: true }) fallback.
Stories test adoption
packages/feeds-client/__integration-tests__/stories.test.ts
Two tests use markWatchedAndSync instead of duplicating event waiting and watched-state updates; existing assertions remain unchanged.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: arnautov-anton, isekovanic, szuperaz

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description misses the required Ticket, Docs, Overview, and Implementation notes sections from the template. Add the template's Ticket and Docs links plus the Overview and Implementation notes sections, then fill them with the PR details.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately highlights the main change: hardening flaky stories mark-watched tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/stories-mark-watched-ws-flake

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/feeds-client/__integration-tests__/utils.ts`:
- Around line 124-134: Update the flow around feed.markActivity and eventPromise
to attach the existing fallback catch handler to the event waiter, then await
the API call and handled event promise concurrently with Promise.all. Preserve
the getOrCreate({ watch: true }) fallback when the event wait fails.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d3b68fb9-5c67-41f4-89e4-b2bd44052fed

📥 Commits

Reviewing files that changed from the base of the PR and between 88b2478 and d332b65.

📒 Files selected for processing (2)
  • packages/feeds-client/__integration-tests__/stories.test.ts
  • packages/feeds-client/__integration-tests__/utils.ts

Comment on lines +124 to +134
const eventPromise = waitForEvent(
feed,
'feeds.stories_feed.updated',
eventTimeoutMs,
);
await feed.markActivity({ mark_watched: activityIds });
try {
await eventPromise;
} catch {
await feed.getOrCreate({ watch: true });
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Await the API promise and the event waiter together using Promise.all.

As per coding guidelines, integration tests that trigger API calls and wait for real-time events must await both the API promise and the event using Promise.all to prevent unhandled rejections.

In the current implementation, if feed.markActivity throws an error, the function will exit immediately, leaving eventPromise without a catch handler. When it subsequently times out, it will cause an UnhandledPromiseRejection and crash the test suite.

You can fix this by attaching a catch handler to eventPromise and awaiting both promises concurrently.

🛠️ Proposed fix
-  const eventPromise = waitForEvent(
-    feed,
-    'feeds.stories_feed.updated',
-    eventTimeoutMs,
-  );
-  await feed.markActivity({ mark_watched: activityIds });
-  try {
-    await eventPromise;
-  } catch {
+  const eventPromise = waitForEvent(
+    feed,
+    'feeds.stories_feed.updated',
+    eventTimeoutMs,
+  ).catch(() => null);
+
+  const [, eventResult] = await Promise.all([
+    feed.markActivity({ mark_watched: activityIds }),
+    eventPromise,
+  ]);
+
+  if (eventResult === null) {
     await feed.getOrCreate({ watch: true });
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const eventPromise = waitForEvent(
feed,
'feeds.stories_feed.updated',
eventTimeoutMs,
);
await feed.markActivity({ mark_watched: activityIds });
try {
await eventPromise;
} catch {
await feed.getOrCreate({ watch: true });
}
const eventPromise = waitForEvent(
feed,
'feeds.stories_feed.updated',
eventTimeoutMs,
).catch(() => null);
const [, eventResult] = await Promise.all([
feed.markActivity({ mark_watched: activityIds }),
eventPromise,
]);
if (eventResult === null) {
await feed.getOrCreate({ watch: true });
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/feeds-client/__integration-tests__/utils.ts` around lines 124 - 134,
Update the flow around feed.markActivity and eventPromise to attach the existing
fallback catch handler to the event waiter, then await the API call and handled
event promise concurrently with Promise.all. Preserve the getOrCreate({ watch:
true }) fallback when the event wait fails.

Source: Coding guidelines

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.

1 participant