Skip to content

Test expired KV entries in @fedify/cfworkers - #1021

Merged
dahlia merged 3 commits into
fedify-dev:mainfrom
Jae-Hyuk-Jang:test/cfworkers-kv-expiry
Sep 3, 2026
Merged

Test expired KV entries in @fedify/cfworkers#1021
dahlia merged 3 commits into
fedify-dev:mainfrom
Jae-Hyuk-Jang:test/cfworkers-kv-expiry

Conversation

@Jae-Hyuk-Jang

Copy link
Copy Markdown
Contributor

Closes #876

Background

@fedify/cfworkers's WorkersKvStore applies its own expiry check via a metadata.expires field, independent of Workers KV's native TTL (Workers KV enforces a 60-second minimum TTL and doesn't expire entries immediately).
src/mod.test.ts already had unit tests for this against a hand-written mock namespace (added in #987), but the miniflare-backed integration suite in test/kv.test.ts — which exercises the real KV binding — only tested that set() with a TTL stores the metadata, not that an expired entry is actually excluded when read back.

Changes

Add tests in packages/cfworkers/test/kv.test.ts that seed an already-expired entry directly via env.KV1.put() (bypassing set()'s 60-second TTL floor) and verify:

  • get() excludes an expired entry.
  • get() still returns an entry whose expiry is in the future.
  • list() excludes expired entries, for both the exact-prefix key and matching children.

Testing

  • pnpm --filter @fedify/cfworkers test (all 47 tests pass, including the 3 new ones)

AI disclosure

Tests were written by me. Claude Code (claude-sonnet-5) helped me find the gap between the mocked unit coverage and the real-binding integration suite, explained the pattern for seeding an already-expired entry via a direct put() call, and pointed out a couple of formatting issues and one test-assertion bug (comparing an array to a bare object) that I then fixed myself.

WorkersKvStore.get() applies expiry via a metadata.expires field
independent of Workers KV's own TTL, but the miniflare-backed
integration suite (test/kv.test.ts) only tested that set() with a
TTL stores that metadata, not that an expired entry is actually
excluded when read through the real KV binding.  The mocked unit
suite in src/mod.test.ts already covered this (added in fedify-dev#987), but
not against the real binding.

Changelog: none
Assisted-by: Claude Code:claude-sonnet-5
Complements the previous commit's expired-entry test: verifies that
an entry whose metadata.expires is still in the future is returned
normally by get(), not just excluded when it isn't.

Changelog: none
Assisted-by: Claude Code:claude-sonnet-5
Completes the expiry coverage in test/kv.test.ts: list() applies the
same metadata.expires check as get(), skipping both the exact-prefix
key and matching children when they're expired.  Matches the mocked
coverage already in src/mod.test.ts (added in fedify-dev#987), now verified
against the real KV binding.

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

netlify Bot commented Sep 3, 2026

Copy link
Copy Markdown

Deploy Preview for fedify-json-schema canceled.

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

@coderabbitai

coderabbitai Bot commented Sep 3, 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: Team

Run ID: 6dd88b2e-5efd-4d07-b6a7-c43638b05236

📥 Commits

Reviewing files that changed from the base of the PR and between 34f78df and 49a8609.

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

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


📝 Walkthrough

Walkthrough

Added tests for WorkersKvStore.get() and list() expiration filtering. The tests verify that expired metadata is excluded and unexpired entries remain available.

Changes

KV expiration filtering

Layer / File(s) Summary
Expiration filtering coverage
packages/cfworkers/test/kv.test.ts
Added get() tests for expired and unexpired entries. Added a list() test that excludes expired root and child keys while returning a fresh child key.

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

Merge Risk: 🟡 Moderate · up to 49a86

The added expiration tests improve KV coverage, but a reported duplicate declaration may prevent the test file from compiling. Confirm and remove the duplicate before merging.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the added expired-entry tests for @fedify/cfworkers and matches the main change.
Description check ✅ Passed The description explains the expiry behavior, test coverage, implementation approach, and test results. It is directly related to the changeset.
Linked Issues check ✅ Passed The PR covers the primary requirements in issue #876. It verifies that get() excludes expired metadata, returns future-expiry entries, and that list() excludes expired exact-prefix and child entries. …
Out of Scope Changes check ✅ Passed The changes add only tests for expired KV entry handling in @fedify/cfworkers. No unrelated code or scope expansion is present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Full details: Linked Issues check

Explanation

The PR covers the primary requirements in issue #876. It verifies that get() excludes expired metadata, returns future-expiry entries, and that list() excludes expired exact-prefix and child entries. The tests use the real KV-backed integration suite rather than the file suggested in the issue.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1 files.

✨ 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.

@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

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

@dahlia dahlia self-assigned this Sep 3, 2026
@dahlia dahlia added component/kv Key–value store related runtime/cfworkers Cloudflare Workers runtime related labels Sep 3, 2026
@dahlia dahlia added this to the Fedify 2.4 milestone Sep 3, 2026
@dahlia
dahlia merged commit 065da80 into fedify-dev:main Sep 3, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/kv Key–value store related runtime/cfworkers Cloudflare Workers runtime related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test expired KV entries in @fedify/cfworkers

2 participants