Skip to content

Cover the ordering lock release in cfworkers - #1004

Open
Safal-Shrestha-SS wants to merge 1 commit into
fedify-dev:mainfrom
Safal-Shrestha-SS:test/cfworkers-lock-release
Open

Cover the ordering lock release in cfworkers#1004
Safal-Shrestha-SS wants to merge 1 commit into
fedify-dev:mainfrom
Safal-Shrestha-SS:test/cfworkers-lock-release

Conversation

@Safal-Shrestha-SS

@Safal-Shrestha-SS Safal-Shrestha-SS commented Aug 20, 2026

Copy link
Copy Markdown

Closes #880.

processMessage() hands back a release() callback once it takes an ordering
key lock, and nothing in the suite checked that calling it actually deletes the
lock. A release() that quietly stopped deleting would stall every ordered
queue and no test would notice.

The test takes the lock through processMessage(), asserts the KV entry exists,
calls release(), then asserts it is gone. It also pushes a second message
through the same ordering key afterwards and expects it to be processed —
asserting that a key vanished from a mock felt like thin evidence on its own,
and "the next message can run" is the behaviour that actually matters here.

One supporting change: MockKvNamespace.get() threw unless it was called in
JSON mode, but processMessage() reads the lock as a plain string. It now
returns the raw value for an untyped get() and parses only when
type === "json", which leaves the existing WorkersKvStore tests untouched.

Checks

  • mise run check-each cfworkers — passes
  • mise run test-each cfworkers — 42 tests pass across 3 files
  • Confirmed the test is not vacuous: stubbing release() into a no-op makes it
    fail with expected true to be false, and it passes again once reverted.

No changelog fragment, since this is test-only work; the commit carries
Changelog: none.

AI disclosure

Per AI_POLICY.md: this was written with Claude Code (claude-opus-5). It
drafted the test and ran the checks listed above. The commit carries the
Assisted-by: Claude Code:claude-opus-5 trailer.

That verification is done: the diff has been reviewed, test-each and
check-each re-run on this branch, and the mutation check above repeated to
confirm the test fails when release() stops deleting the lock.

Also: CONTRIBUTING asks contributors to comment on an issue and wait to be
assigned. I have opened this as a draft rather than commented, so if you would
rather hand #880 to someone else, say the word and I will close it.

processMessage() hands back a release() callback after it takes an
ordering key lock, and the point of that callback is to delete the lock
so the next message for the same key can run.  Nothing checked it, so a
release() that quietly stopped deleting would have stalled every ordered
queue without failing a test.

Rather than only asserting the key is gone, the test pushes a second
message through the same ordering key and expects it to be processed,
which is the behaviour users actually depend on.

MockKvNamespace.get() threw unless it was called in JSON mode, while
processMessage() reads the lock as a plain string, so the mock now
returns the raw value for an untyped get().

See fedify-dev#880

Changelog: none
Assisted-by: Claude Code:claude-opus-5
@netlify

netlify Bot commented Aug 20, 2026

Copy link
Copy Markdown

Deploy Preview for fedify-json-schema canceled.

Name Link
🔨 Latest commit b824b70
🔍 Latest deploy log https://app.netlify.com/projects/fedify-json-schema/deploys/6a866f9c5e30e2000891cec1

@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 443f7f34-0d76-4f6c-9976-8fb1ae0706af

📥 Commits

Reviewing files that changed from the base of the PR and between 1af9355 and b824b70.

📒 Files selected for processing (1)
  • packages/cfworkers/src/mod.test.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The change updates mock KV retrieval for raw values and adds coverage for releasing ordered message locks before processing the next message.

Changes

CFWorkers behavior tests

Layer / File(s) Summary
Mock KV and ordering-lock validation
packages/cfworkers/src/mod.test.ts
MockKvNamespace.get() returns stored strings for non-JSON requests. The queue test verifies that releasing an ordered message removes its lock and allows the next message with the same ordering key to process.

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

Merge Risk: ⚪ Minimal · up to b824b

This localized test-only change verifies ordering-lock release behavior and confirms that a subsequent message can proceed; no actionable merge-blocking risk remains after normal checks and review.

Possibly related issues

  • fedify-dev/fedify#879 — Covers related WorkersMessageQueue.processMessage() ordering-lock behavior in the same test module.

Possibly related PRs

Suggested reviewers: 2chanhaeng

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly identifies the main change: adding coverage for ordering lock release in cfworkers.
Description check ✅ Passed The description accurately explains the ordering lock test, the KV mock update, and the verification performed.
Linked Issues check ✅ Passed The description closes issue #880 and directly addresses its requested ordering lock release coverage.
Out of Scope Changes check ✅ Passed The KV mock update directly supports the new test, and no unrelated changes are reported.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@Safal-Shrestha-SS

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Safal-Shrestha-SS
Safal-Shrestha-SS marked this pull request as ready for review August 20, 2026 04:40
@dahlia dahlia self-assigned this Aug 21, 2026
@dahlia dahlia added the runtime/cfworkers Cloudflare Workers runtime related label Aug 21, 2026
@dahlia dahlia added this to the Fedify 2.4 milestone Aug 21, 2026
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.
see 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

runtime/cfworkers Cloudflare Workers runtime related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test ordering lock release in @fedify/cfworkers

2 participants