Skip to content

Add an async context data test for @fedify/express - #985

Open
Jae-Hyuk-Jang wants to merge 4 commits into
fedify-dev:mainfrom
Jae-Hyuk-Jang:test/express-async-context-data
Open

Add an async context data test for @fedify/express#985
Jae-Hyuk-Jang wants to merge 4 commits into
fedify-dev:mainfrom
Jae-Hyuk-Jang:test/express-async-context-data

Conversation

@Jae-Hyuk-Jang

@Jae-Hyuk-Jang Jae-Hyuk-Jang commented Aug 7, 2026

Copy link
Copy Markdown

Summary

integrateFederation()'s contextDataFactory may return a plain value or a Promise, but only the synchronous path had test coverage.
This adds a regression test for the async path, verifying the middleware waits for the factory to resolve and passes the resolved value to federation.fetch().

Also adds the missing test script (package.json) and test task (deno.json) for @fedify/express so the suite actually runs under mise run test:node / test-each.

Fixes #855

Test plan

  • mise run check-each express
  • deno test --allow-all (packages/express)
  • node --experimental-transform-types --test (packages/express)

AI disclosure

This change was written with assistance from Claude Code (claude-sonnet-5), reviewed and verified by me.

integrateFederation() accepts a contextDataFactory that may return
either a plain value or a Promise, but only the synchronous path was
covered. Add a test that verifies the middleware waits for an async
factory to resolve and passes the resolved value to federation.fetch().

Also wire up the test script/task in package.json and deno.json so
mise run test:node and test-each actually run it.

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

netlify Bot commented Aug 7, 2026

Copy link
Copy Markdown

Deploy Preview for fedify-json-schema canceled.

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

@coderabbitai

coderabbitai Bot commented Aug 7, 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: 50d84419-ee79-4d26-ae0c-c021e2d334d9

📥 Commits

Reviewing files that changed from the base of the PR and between 9e6c38a and cd288b2.

📒 Files selected for processing (1)
  • packages/express/src/index.test.ts
💤 Files with no reviewable changes (1)
  • packages/express/src/index.test.ts

📝 Walkthrough

Walkthrough

The Express package adds Deno, Node, and Bun test commands. New middleware tests verify that integrateFederation() awaits asynchronous context data, passes the resolved value to federation.fetch(), writes the response, and does not call next().

Changes

Express async context test

Layer / File(s) Summary
Async context middleware validation
packages/express/src/index.test.ts, packages/express/deno.json, packages/express/package.json
The test adds mock request and response helpers, verifies asynchronous context resolution and federation fetch input, captures the response, and confirms that next() is not called. Deno, Node, and Bun commands run the package test suite.

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

Possibly related issues

Possibly related PRs

  • fedify-dev/fedify#988 — Adds a comparable asynchronous context-data integration test for the Fresh adapter.

Suggested labels: component/integration

Suggested reviewers: dahlia

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the added asynchronous context data test for @fedify/express.
Description check ✅ Passed The description explains the async regression test, added test commands, validation steps, and linked issue.
Linked Issues check ✅ Passed The PR adds the required async contextDataFactory test and verifies resolution before federation.fetch() receives the value [#855].
Out of Scope Changes check ✅ Passed The changes are limited to the requested regression test and package test configuration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@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/express/src/index.test.ts`:
- Around line 65-88: Update the async contextDataFactory test to use a deferred
promise and track federation.fetch invocation; assert fetch remains uncalled
before resolving the promise, then resolve it and verify the existing response
and middleware behavior after completion.
🪄 Autofix

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: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 67407354-e127-4371-939c-d560137a9e46

📥 Commits

Reviewing files that changed from the base of the PR and between 15ad151 and 64bcda0.

📒 Files selected for processing (3)
  • packages/express/deno.json
  • packages/express/package.json
  • packages/express/src/index.test.ts

Comment thread packages/express/src/index.test.ts
The previous test only checked the resolved value, not that
federation.fetch() stays uncalled until the async contextDataFactory
promise resolves. Use a deferred promise to assert the ordering
directly, per CodeRabbit's review on fedify-dev#985.

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

@sij411 sij411 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since integrateFederation() only assigns send, json, and removeHeader and never calls their existing implementations, could these methods be omitted from the initial response mock?

@2chanhaeng 2chanhaeng left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution! Please check my comment.

Comment thread packages/express/package.json Outdated
"prepack": "pnpm build",
"prepublish": "pnpm build"
"prepublish": "pnpm build",
"test": "node --experimental-transform-types --test"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add test:bun script.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added, thanks!

The package had a Node test script but no Bun equivalent, so the
suite never ran under Bun. Mirror the elysia package's pattern.

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

@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/express/package.json`:
- Line 62: Add an engines.node declaration in packages/express/package.json
covering the Node versions that support --experimental-transform-types, or
replace that flag with a test command compatible with the package’s declared
Node support baseline. Keep the test script’s behavior unchanged for supported
runtimes.
🪄 Autofix

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: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 06c7d757-01e1-434f-a281-caebe31bfec5

📥 Commits

Reviewing files that changed from the base of the PR and between a59ed13 and 9e6c38a.

📒 Files selected for processing (1)
  • packages/express/package.json

"prepack": "pnpm build",
"prepublish": "pnpm build"
"prepublish": "pnpm build",
"test": "node --experimental-transform-types --test",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

mapfile -t files < <(
  fd -HI -t f \
    -g 'package.json' \
    -g '.nvmrc' \
    -g '.node-version' \
    -g '.tool-versions' \
    -g '*.yml' \
    -g '*.yaml' \
    .
)

for file in "${files[@]}"; do
  rg -n '"engines"|"node"|node-version|setup-node|NODE_VERSION|experimental-transform-types' "$file" || true
done

Repository: fedify-dev/fedify

Length of output: 486


🏁 Script executed:

#!/bin/bash
set -eu pipefail

printf 'Repository files matching Node/version/test config names:\n'
git ls-files | grep -Ei '(^|/)(package\.json$|\.nvmrc$|\.node-version$|\.tool-versions$|\.node-versionrc$|\.nvvmrc$|\.yml$|\.yaml$|README(\.|$)|deno\.json$|bun\.lock$|pnpm-workspace\.yaml$)' | sort

printf '\nRelevant Node/version/test config references:\n'
git ls-files | grep -Ei '(^|/)(package\.json$|\.nvmrc$|\.node-version$|\.tool-versions$|\.node-versionrc$|\.nvvmrc$|\.yml$|\.yaml$|README(\.|$)|deno\.json$|bun\.lock$|pnpm-workspace\.yaml$)' | while IFS= read -r file; do
  if rg -n '"engines"|"node"|"nodejs"|node-version|nodeversion|setup-node|NODE_VERSION|experimental-transform-types|--experimental-transform-types|^test:|^test:' "$file" >/tmp/rgmatch 2>/dev/null; then
    printf '\n--- %s ---\n' "$file"
    cat /tmp/rgmatch
  fi
done

printf '\npackages/express/package.json relevant sections:\n'
python3 - <<'PY'
import json, pathlib
p=pathlib.Path('packages/express/package.json')
data=json.loads(p.read_text())
for key in ['name', 'engines', 'scripts']:
    print(f'{key}: {json.dumps(data.get(key, "<missing>"), indent=2)}')
PY

printf '\nRoot package.json engines/scripts context:\n'
python3 - <<'PY'
import json, pathlib
for p in [pathlib.Path('package.json'), pathlib.Path('pnpm-workspace.yaml'), pathlib.Path('.github/workflows')]
    pass
PY

# A minimal, focused search for any Node version declarations.
printf '\nFocused search for Node version declarations and transform flag:\n'
rg -n --glob '!**/.git/**' '(^|[^a-zA-Z0-9.])(node(\s*=>|-?[~^>=<][0-9]|@\d+)|NODE_VERSION|node-version|setup-node|engines|experimental-transform-types|--experimental-transform-types)' .

Repository: fedify-dev/fedify

Length of output: 9194


🌐 Web query:

Node.js --experimental-transform-types added removed version 22.7.0 26.0.0

💡 Result:

The --experimental-transform-types flag was added to Node.js in version 22.7.0 [1][2][3]. It was subsequently removed in version 26.0.0 [1][4]. The removal was implemented via pull request #61803, which was merged on February 27, 2026 [5][6].

Citations:


🏁 Script executed:

#!/bin/bash
set -e

printf 'Root package.json and express package metadata:\n'
python3 - <<'PY'
import json, pathlib
for p in ["package.json", "pnpm-workspace.yaml", "packages/express/package.json"]:
    path=pathlib.Path(p)
    print(f"\n--- {p} ---")
    if p.endswith(".json"):
        data=json.loads(path.read_text())
        for key in ["name", "type", "packageManager", "engines", "scripts"]:
            print(f"{key}: {json.dumps(data.get(key, "<missing>"), indent=2)}")
    else:
        print(path.read_text().strip())
PY

printf '\nGitHub workflow Node version pins:\n'
git ls-files '.github/workflows/*.yml' '.github/workflows/*.yaml' | sort | while IFS= read -r file; do
  echo "### $file"
  rg -n 'node-version:|setup-node|engines|actions/setup-node|uses: .*setup-node|matrix|nodejs|NODE_VERSION' "$file" || true
done

printf '\nAll Node declaration files excluding generated lock artifacts:\n'
git ls-files | grep -Ei '(^|/)(\.nvmrc$|\.node-version$|\.tool-versions$|package\.json$|pnpm-workspace\.yaml$)' | sort | while IFS= read -r file; do
  if rg -n '"engines"|"pnpm"|"volta"|node-version|NODE_VERSION|setup-node|experimental-transform-types' "$file" >/tmp/rgmatch; then
    echo "### $file"
    cat /tmp/rgmatch
  fi
done

Repository: fedify-dev/fedify

Length of output: 385


🌐 Web query:

fedify-dev fedify package.json packageManager package.json engines node pnpm-workspace.yaml fedify

💡 Result:

Fedify is a TypeScript-based framework designed for building federated server applications, supporting multiple runtimes (Node.js, Deno, Bun) and various package managers [1][2][3]. The technical configuration details regarding the requested files are as follows: pnpm-workspace.yaml The Fedify repository is a monorepo that utilizes pnpm workspaces to manage its various packages (e.g., core, web framework integrations, CLI) [1][4][5]. The pnpm-workspace.yaml file defines the packages included in the workspace and employs the pnpm catalog feature to manage dependencies centrally [4][6]. When adding a new package or updating existing ones, dependencies in individual package.json files reference these catalog versions using the catalog: protocol rather than hardcoded version numbers [6]. package.json and packageManager Fedify's CLI includes a fedify init command that scaffolds new projects [2]. This command allows users to specify a package manager (options include deno, pnpm, bun, yarn, or npm) [7][8]. The scaffolder generates a package.json file for Node.js-based projects, which includes essential metadata such as "type": "module" and project-specific npm scripts [9]. While the CLI dynamically manages dependency installation based on the chosen runtime and package manager, it does not mandate a specific packageManager field in the generated package.json [10][9]. Historically, issues regarding the CLI's detection of local package managers (e.g., pnpm) have been addressed in maintenance updates [11]. engines node Fedify-based projects are generally compatible with standard Node.js environments. For example, specific implementations, such as the federated microblog example, require Node.js 20.0.0 or later [3]. While developers may define an engines field in their project-level package.json to enforce Node.js version compatibility, this is standard practice for Node.js projects rather than a specific requirement enforced by the Fedify framework itself. Overall, Fedify is designed to be runtime-agnostic and modular, allowing users to integrate it into their preferred Node.js frameworks (e.g., Express, Fastify, Next.js) using the appropriate integration package [12][2].

Citations:


Scope the Node command to a supported runtime.

This package does not declare Node version support, while --experimental-transform-types exists only for Node 22.7.0 through 25. Add engines.node for the supported range or use a Node configuration that is compatible with the declared support baseline.

🤖 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/express/package.json` at line 62, Add an engines.node declaration in
packages/express/package.json covering the Node versions that support
--experimental-transform-types, or replace that flag with a test command
compatible with the package’s declared Node support baseline. Keep the test
script’s behavior unchanged for supported runtimes.

integrateFederation() only overwrites send, json, and removeHeader
with no-ops; it never calls their existing implementations, so the
mock response doesn't need them.

Changelog: none
Assisted-by: Claude Code:claude-sonnet-5
@Jae-Hyuk-Jang

Copy link
Copy Markdown
Author

Since integrateFederation() only assigns send, json, and removeHeader and never calls their existing implementations, could these methods be omitted from the initial response mock?

Good catch, removed them — thanks!

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.

Add an async context data test for @fedify/express

3 participants