Skip to content

refactor(webui): Migrate example tests to new Fastify architecture. - #1099

Merged
davemarco merged 2 commits into
y-scope:mainfrom
davemarco:testmove
Jul 14, 2025
Merged

refactor(webui): Migrate example tests to new Fastify architecture.#1099
davemarco merged 2 commits into
y-scope:mainfrom
davemarco:testmove

Conversation

@davemarco

@davemarco davemarco commented Jul 11, 2025

Copy link
Copy Markdown
Contributor

Description

PR moves example tests into new fastify architecture. This is a chain of PRs which started with #1027

I removed building the app from the test, since we are only testing the route.

I left some unused test helpers since they are new(after refactor), and may be useful for future integration tests.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

Tests pass

Summary by CodeRabbit

  • Refactor
    • Updated internal route handling and plugin registration for improved consistency.
  • Tests
    • Adjusted test setup for example routes without changing test behaviour or outcomes.

@coderabbitai

coderabbitai Bot commented Jul 11, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes remove the registration of the example API route from the main Fastify application, refactor the example route plugin for improved type safety, and update the associated test to directly register the route. No other routes or plugin configurations are affected.

Changes

File(s) Change Summary
components/webui/server/src/app.ts Removed import and registration of exampleRoutes from the Fastify app.
components/webui/server/src/fastify-v2/routes/api/example/index.ts Refactored route plugin: updated type imports, renamed function, changed export, improved type usage.
components/webui/server/src/test/example.test.ts Updated test setup to use Fastify directly and register routes manually; removed unused code.

Suggested reviewers

  • hoophalab

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5d4c676 and 67f0a1d.

📒 Files selected for processing (3)
  • components/webui/server/src/app.ts (0 hunks)
  • components/webui/server/src/fastify-v2/routes/api/example/index.ts (2 hunks)
  • components/webui/server/src/test/example.test.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • components/webui/server/src/app.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}

Instructions used from:

Sources:
⚙️ CodeRabbit Configuration File

🧠 Learnings (3)
📓 Common learnings
Learnt from: junhaoliao
PR: y-scope/clp#939
File: components/package-template/src/etc/clp-config.yml:64-64
Timestamp: 2025-06-22T04:01:43.409Z
Learning: The new webui architecture uses Fastify with Pino logging instead of the previous Winston-based logging system that was removed during the webui refactoring.
Learnt from: haiqi96
PR: y-scope/clp#523
File: components/core/src/clp/clp/FileCompressor.hpp:58-78
Timestamp: 2024-10-24T14:25:17.978Z
Learning: When reviewing legacy code refactors, avoid suggesting changes that would extend the scope of the PR.
Learnt from: gibber9809
PR: y-scope/clp#504
File: components/core/src/clp_s/search/kql/CMakeLists.txt:29-29
Timestamp: 2024-10-22T15:36:04.655Z
Learning: When reviewing pull requests, focus on the changes within the PR and avoid commenting on issues outside the scope of the PR.
Learnt from: davemarco
PR: y-scope/clp#1015
File: components/log-viewer-webui/server/src/routes/static.ts:65-70
Timestamp: 2025-06-16T13:05:27.349Z
Learning: In components/log-viewer-webui/server/src/routes/static.ts, when decorateReply is set to true in fastifyStatic configuration, the reply.sendFile() method automatically uses the root directory configured in the static plugin registration, eliminating the need to pass the root directory as a second parameter.
components/webui/server/src/test/example.test.ts (3)
Learnt from: junhaoliao
PR: y-scope/clp#939
File: components/package-template/src/etc/clp-config.yml:64-64
Timestamp: 2025-06-22T04:01:43.409Z
Learning: The new webui architecture uses Fastify with Pino logging instead of the previous Winston-based logging system that was removed during the webui refactoring.
Learnt from: davemarco
PR: y-scope/clp#1015
File: components/log-viewer-webui/server/src/routes/static.ts:65-70
Timestamp: 2025-06-16T13:05:27.349Z
Learning: In components/log-viewer-webui/server/src/routes/static.ts, when decorateReply is set to true in fastifyStatic configuration, the reply.sendFile() method automatically uses the root directory configured in the static plugin registration, eliminating the need to pass the root directory as a second parameter.
Learnt from: junhaoliao
PR: y-scope/clp#596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In `components/log-viewer-webui/client/src/api/query.js`, the `ExtractJsonResp` type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.
components/webui/server/src/fastify-v2/routes/api/example/index.ts (2)
Learnt from: junhaoliao
PR: y-scope/clp#596
File: components/log-viewer-webui/client/src/api/query.js:16-23
Timestamp: 2024-11-21T15:51:33.203Z
Learning: In `components/log-viewer-webui/client/src/api/query.js`, the `ExtractJsonResp` type definition is accurate as-is and does not require modification. When suggesting changes to type definitions, ensure they align with the server-side definitions, referencing the source code if necessary.
Learnt from: davemarco
PR: y-scope/clp#1015
File: components/log-viewer-webui/server/src/routes/static.ts:65-70
Timestamp: 2025-06-16T13:05:27.349Z
Learning: In components/log-viewer-webui/server/src/routes/static.ts, when decorateReply is set to true in fastifyStatic configuration, the reply.sendFile() method automatically uses the root directory configured in the static plugin registration, eliminating the need to pass the root directory as a second parameter.
🔇 Additional comments (6)
components/webui/server/src/fastify-v2/routes/api/example/index.ts (3)

1-1: Excellent migration to improved TypeBox integration.

The import change from TypeBoxTypeProvider to FastifyPluginAsyncTypebox enhances type safety and follows current Fastify best practices.


8-10: Well-executed function refactor with consistent naming.

The changes improve code clarity:

  • Parameter name fastify follows Fastify conventions
  • Function name plugin is more descriptive than routes
  • The FastifyPluginAsyncTypebox type provides better type safety

32-32: Export update is consistent with function name change.

The export statement correctly reflects the function name change from routes to plugin.

components/webui/server/src/test/example.test.ts (3)

1-1: Proper import addition for direct Fastify instance creation.

Adding the fastify import is necessary for the new testing architecture and follows standard Fastify testing patterns.


5-5: Import update is consistent with plugin export changes.

The import change from a custom build function to the routes plugin aligns with the architectural migration and maintains consistency between files.


9-10: Clean migration to direct Fastify instance management.

The test setup change from using a custom build() function to direct Fastify instance creation and explicit plugin registration is excellent:

  • Follows standard Fastify testing patterns
  • Provides better control over test setup
  • Maintains the same test functionality while improving clarity
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@davemarco
davemarco requested a review from hoophalab July 11, 2025 20:17
@davemarco
davemarco marked this pull request as ready for review July 11, 2025 20:17
@davemarco
davemarco requested a review from a team as a code owner July 11, 2025 20:17

@hoophalab hoophalab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm. No validation is needed because currently the test code is a place holder and doesn't test anything.

Comment on lines 12 to 13
let resp = await server.inject({
method: "GET",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

github cannot comment on unchanged lines, but the url below this line should be "/api/example/get/Alice" right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

annoyingly no because the route is imported directly, i believe fastify only takes the directory structure if you use the auto import method we are using in app.ts.

So this is correct

@davemarco

Copy link
Copy Markdown
Contributor Author

fyi u can test with npm run test. u should see all pass

@junhaoliao junhaoliao 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.

lgtm. deferring to @hoophalab 's review

@davemarco
davemarco merged commit 2a92184 into y-scope:main Jul 14, 2025
junhaoliao pushed a commit to junhaoliao/clp that referenced this pull request May 17, 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