Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): add starting tutorial.md #1859

Merged
merged 9 commits into from
Mar 30, 2024
Merged

chore(docs): add starting tutorial.md #1859

merged 9 commits into from
Mar 30, 2024

Conversation

drazisil
Copy link
Collaborator

@drazisil drazisil commented Mar 30, 2024

chore(docs): add starting tutorial.md

Summary by CodeRabbit

  • New Features
    • Enhanced route handlers in the gateway service for improved file handling.
    • Introduced test cases for handling certificate, registry, and key retrieval in a web context.
    • Updated file reading operations to asynchronous in the shard service.

also delete some type files commited in error
Copy link

coderabbitai bot commented Mar 30, 2024

Warning

Rate Limit Exceeded

@drazisil has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 50 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 6769ba4 and dc9016a.

Walkthrough

The recent updates involve version downgrading, transitioning to asynchronous file handling using readFile, and enhancing web route functionality for the "rusty-motors" game server project, aimed at boosting performance and security.

Changes

Files Change Summary
package.json, packages/gateway/src/web.ts Version downgraded to "0.5.0"; /cert, /key, /registry handlers now use async for file ops.
packages/shard/src/index.ts Updated to use readFile for async file operations for cert, registry, and key retrieval.
packages/gateway/test/web.test.ts Added test cases for cert, registry, key retrieval in web context using vitest.

🐰✨

In the server's realm, where codes align,

Async whispers through each file and line.

Certificates fetched, keys securely bound,

Tests dance with joy, in vitest they're found.

With promises sworn, and routes anew,

The server evolves under the sky's azure hue.

🌌🔒

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

codecov bot commented Mar 30, 2024

Codecov Report

Attention: Patch coverage is 27.27273% with 16 lines in your changes are missing coverage. Please review.

Project coverage is 36.72%. Comparing base (50b10c6) to head (2003c90).

❗ Current head 2003c90 differs from pull request most recent head dc9016a. Consider uploading reports for the commit dc9016a to get more accurate results

✅ All tests successful. No failed tests found ☺️

Files Patch % Lines
packages/gateway/src/web.ts 6.25% 15 Missing ⚠️
packages/gateway/src/GatewayServer.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1859      +/-   ##
==========================================
+ Coverage   35.62%   36.72%   +1.09%     
==========================================
  Files         127      125       -2     
  Lines       12063    11955     -108     
  Branches      175      159      -16     
==========================================
+ Hits         4298     4390      +92     
+ Misses       7765     7565     -200     
Flag Coverage Δ
core 100.00% <ø> (ø)
database 14.00% <ø> (ø)
gateway 41.47% <5.88%> (+3.86%) ⬆️
lobby 26.48% <ø> (ø)
login 21.30% <ø> (ø)
patch 53.09% <ø> (ø)
persona 21.94% <ø> (ø)
shard 90.18% <100.00%> (+33.50%) ⬆️
transactions 45.32% <ø> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

deepsource-io bot commented Mar 30, 2024

Here's the code health analysis summary for commits 50b10c6..dc9016a. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource JavaScript LogoJavaScript❌ Failure
❗ 8 occurences introduced
🎯 9 occurences resolved
View Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 50b10c6 and 5bc493a.
Files selected for processing (5)
  • STARTING.md (1 hunks)
  • package.json (1 hunks)
  • packages/gateway/src/web.ts (1 hunks)
  • packages/shard/src/index.ts (4 hunks)
  • pull_nginx_image.sh (1 hunks)
Additional Context Used
GitHub Check Runs (2)
codecov/patch failure (6)

packages/gateway/src/web.ts: [warning] 117-117: packages/gateway/src/web.ts#L117
Added line #L117 was not covered by tests


packages/gateway/src/web.ts: [warning] 122-125: packages/gateway/src/web.ts#L122-L125
Added lines #L122 - L125 were not covered by tests


packages/gateway/src/web.ts: [warning] 128-128: packages/gateway/src/web.ts#L128
Added line #L128 was not covered by tests


packages/gateway/src/web.ts: [warning] 133-136: packages/gateway/src/web.ts#L133-L136
Added lines #L133 - L136 were not covered by tests


packages/gateway/src/web.ts: [warning] 139-139: packages/gateway/src/web.ts#L139
Added line #L139 was not covered by tests


packages/gateway/src/web.ts: [warning] 144-147: packages/gateway/src/web.ts#L144-L147
Added lines #L144 - L147 were not covered by tests

Trunk Check failure (4)

STARTING.md: [notice] 56-56: markdownlint(MD003)
[new] Heading style


STARTING.md: [notice] 56-56: markdownlint(MD026)
[new] Trailing punctuation in heading


STARTING.md: [failure] 1-1: prettier
Incorrect formatting, autoformat by running 'trunk fmt'


packages/shard/src/index.ts: [failure] 1-1: prettier
Incorrect formatting, autoformat by running 'trunk fmt'

Additional comments not posted (7)
pull_nginx_image.sh (1)

1-4: Consider adding error handling to the script to ensure robustness. For example, check if wget successfully downloads the file before proceeding to unzip and load it. Additionally, verify the integrity of the downloaded file to ensure security. Lastly, ensure Docker is installed and the user has the necessary permissions to execute docker load.

package.json (1)

3-3: The version of the "rusty-motors" game server project has been changed from "1.0.1" to "0.5.0". Ensure that this version change does not negatively impact any dependencies or consumers of the project. Consider the implications of this significant downgrade, which could indicate a major change in the project's direction or a correction of the versioning scheme.

packages/shard/src/index.ts (1)

44-44: The handleGetRegistry function correctly generates a registry configuration file without needing asynchronous file operations.

packages/gateway/src/web.ts (3)

117-125: The asynchronous operations in the /cert route handler are correctly implemented. However, consider adding test coverage for these new changes to ensure they work as expected.


128-136: Similar to the /cert route handler, the /key route handler's asynchronous operations are correctly implemented. Adding test coverage for these changes is recommended.


139-147: The /registry route handler correctly implements asynchronous operations. Adding test coverage for these changes is recommended to ensure they work as expected.

STARTING.md (1)

1-87: The tutorial document contains several areas for improvement:

  • Correct typographical and grammatical errors, such as "Documention" should be "Documentation", and ensure consistent use of technical terms like "Node.js" instead of "NodeJS".
  • Address potential security warnings explicitly, especially when instructing users to perform actions that Windows warns against.
  • Consider adding links to installation documents for the listed requirements to aid users in setting up their environment.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5bc493a and 6dcfd11.
Files selected for processing (2)
  • packages/gateway/test/web.test.ts (1 hunks)
  • packages/shard/src/index.ts (4 hunks)
Additional Context Used
GitHub Check Runs (2)
codecov/patch failure (9)

packages/shard/src/index.ts: [warning] 28-28: packages/shard/src/index.ts#L28
Added line #L28 was not covered by tests


packages/shard/src/index.ts: [warning] 33-33: packages/shard/src/index.ts#L33
Added line #L33 was not covered by tests


packages/shard/src/index.ts: [warning] 90-90: packages/shard/src/index.ts#L90
Added line #L90 was not covered by tests

Trunk Check failure (4)

packages/gateway/test/web.test.ts: [failure] 22-22: eslint
[new] Parsing error: Unexpected token )

Additional comments not posted (4)
packages/gateway/test/web.test.ts (3)

20-27: The dynamic import mocking strategy is complex and might be causing parsing issues. Consider simplifying the mocking approach for better readability and maintainability. Additionally, ensure that the syntax is correct as parsing errors can lead to runtime issues.


33-38: This test case is well-implemented and checks for specific output strings, ensuring that handleGetRegistry behaves as expected.


40-43: The test case for handleGetKey is correctly implemented, ensuring the function returns the expected result.

packages/shard/src/index.ts (1)

44-46: The handleGetRegistry function is correctly implemented and does not involve asynchronous operations. It generates the registry configuration string as expected.

Comment on lines 28 to 33
export async function handleGetCert(config: Configuration): Promise<string> {
if (config.certificateFile === undefined) {
throw new Error("Certificate file not defined");
}
try {
const cert = readFileSync(config.certificateFile, "utf8");
return cert;
return readFile(config.certificateFile, "utf8");
Copy link

Choose a reason for hiding this comment

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

The readFile method returns a promise, which should be awaited to ensure the file is read before proceeding. Additionally, consider adding test coverage for this function to ensure its behavior is as expected.

-        return readFile(config.certificateFile, "utf8");
+        return await readFile(config.certificateFile, "utf8");

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.

Suggested change
export async function handleGetCert(config: Configuration): Promise<string> {
if (config.certificateFile === undefined) {
throw new Error("Certificate file not defined");
}
try {
const cert = readFileSync(config.certificateFile, "utf8");
return cert;
return readFile(config.certificateFile, "utf8");
export async function handleGetCert(config: Configuration): Promise<string> {
if (config.certificateFile === undefined) {
throw new Error("Certificate file not defined");
}
try {
return await readFile(config.certificateFile, "utf8");

Comment on lines 85 to 90
export async function handleGetKey(config: Configuration): Promise<string> {
if (config.publicKeyFile === undefined) {
throw new Error("Public key file not defined");
}
try {
const key = readFileSync(config.publicKeyFile, "utf8");
return key;
return readFile(config.publicKeyFile, "utf8");
Copy link

Choose a reason for hiding this comment

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

Similar to handleGetCert, the handleGetKey function should await the promise returned by readFile to ensure the file is read before proceeding. Also, consider adding test coverage for this function.

-        return readFile(config.publicKeyFile, "utf8");
+        return await readFile(config.publicKeyFile, "utf8");

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.

Suggested change
export async function handleGetKey(config: Configuration): Promise<string> {
if (config.publicKeyFile === undefined) {
throw new Error("Public key file not defined");
}
try {
const key = readFileSync(config.publicKeyFile, "utf8");
return key;
return readFile(config.publicKeyFile, "utf8");
export async function handleGetKey(config: Configuration): Promise<string> {
if (config.publicKeyFile === undefined) {
throw new Error("Public key file not defined");
}
try {
return await readFile(config.publicKeyFile, "utf8");

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6dcfd11 and 7d2a3e1.
Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !pnpm-lock.yaml
Files selected for processing (1)
  • package.json (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • package.json
Additional Context Used

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7d2a3e1 and 6769ba4.
Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !pnpm-lock.yaml
Files selected for processing (3)
  • packages/gateway/src/web.ts (2 hunks)
  • packages/gateway/test/web.test.ts (1 hunks)
  • packages/shard/src/index.ts (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • packages/gateway/test/web.test.ts
  • packages/shard/src/index.ts
Additional Context Used
GitHub Check Runs (1)
codecov/patch failure (5)

packages/gateway/src/web.ts: [warning] 117-117: packages/gateway/src/web.ts#L117
Added line #L117 was not covered by tests


packages/gateway/src/web.ts: [warning] 122-125: packages/gateway/src/web.ts#L122-L125
Added lines #L122 - L125 were not covered by tests


packages/gateway/src/web.ts: [warning] 128-128: packages/gateway/src/web.ts#L128
Added line #L128 was not covered by tests


packages/gateway/src/web.ts: [warning] 133-136: packages/gateway/src/web.ts#L133-L136
Added lines #L133 - L136 were not covered by tests


packages/gateway/src/web.ts: [warning] 145-147: packages/gateway/src/web.ts#L145-L147
Added lines #L145 - L147 were not covered by tests

Comment on lines +117 to +125
webServer.get("/cert", async (_request, reply) => {
const config = getServerConfiguration({});
if (typeof config.host === "undefined") {
throw new Error("No host defined in config");
}
return reply.send(handleGetCert(config));
const certFile = await handleGetCert(config);
reply.header("Content-Type", "text/plain");
reply.header("Content-Disposition", "attachment; filename=cert.crt");
reply.send(certFile);
Copy link

Choose a reason for hiding this comment

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

The async implementation for the /cert route handler is well done. However, consider adding error handling for the handleGetCert function to manage potential failures gracefully. Additionally, it's important to ensure this new code path is covered by tests to maintain code quality and reliability.

    webServer.get("/cert", async (_request, reply) => {
        const config = getServerConfiguration({});
        if (typeof config.host === "undefined") {
            throw new Error("No host defined in config");
        }
+       try {
        const certFile = await handleGetCert(config);
        reply.header("Content-Type", "text/plain");
        reply.header("Content-Disposition", "attachment; filename=cert.crt");
        reply.send(certFile);
+       } catch (error) {
+           reply.status(500).send('Internal Server Error');
+       }
    });

Would you like assistance in creating unit tests for this route handler?


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.

Suggested change
webServer.get("/cert", async (_request, reply) => {
const config = getServerConfiguration({});
if (typeof config.host === "undefined") {
throw new Error("No host defined in config");
}
return reply.send(handleGetCert(config));
const certFile = await handleGetCert(config);
reply.header("Content-Type", "text/plain");
reply.header("Content-Disposition", "attachment; filename=cert.crt");
reply.send(certFile);
webServer.get("/cert", async (_request, reply) => {
const config = getServerConfiguration({});
if (typeof config.host === "undefined") {
throw new Error("No host defined in config");
}
try {
const certFile = await handleGetCert(config);
reply.header("Content-Type", "text/plain");
reply.header("Content-Disposition", "attachment; filename=cert.crt");
reply.send(certFile);
} catch (error) {
reply.status(500).send('Internal Server Error');
}

Comment on lines +128 to +136
webServer.get("/key", async (_request, reply) => {
const config = getServerConfiguration({});
if (typeof config.host === "undefined") {
throw new Error("No host defined in config");
}
return reply.send(handleGetKey(config));
const keyFile = await handleGetKey(config);
reply.header("Content-Type", "text/plain");
reply.header("Content-Disposition", "attachment; filename=pub.key");
reply.send(keyFile);
Copy link

Choose a reason for hiding this comment

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

Similar to the /cert handler, the /key route handler's async implementation is good. However, adding error handling for the handleGetKey function would improve robustness. Ensuring test coverage for this part of the code is also crucial.

    webServer.get("/key", async (_request, reply) => {
        const config = getServerConfiguration({});
        if (typeof config.host === "undefined") {
            throw new Error("No host defined in config");
        }
+       try {
        const keyFile = await handleGetKey(config);
        reply.header("Content-Type", "text/plain");
        reply.header("Content-Disposition", "attachment; filename=pub.key");
        reply.send(keyFile);
+       } catch (error) {
+           reply.status(500).send('Internal Server Error');
+       }
    });

Would you like help in creating unit tests for this route handler?


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.

Suggested change
webServer.get("/key", async (_request, reply) => {
const config = getServerConfiguration({});
if (typeof config.host === "undefined") {
throw new Error("No host defined in config");
}
return reply.send(handleGetKey(config));
const keyFile = await handleGetKey(config);
reply.header("Content-Type", "text/plain");
reply.header("Content-Disposition", "attachment; filename=pub.key");
reply.send(keyFile);
webServer.get("/key", async (_request, reply) => {
const config = getServerConfiguration({});
if (typeof config.host === "undefined") {
throw new Error("No host defined in config");
}
try {
const keyFile = await handleGetKey(config);
reply.header("Content-Type", "text/plain");
reply.header("Content-Disposition", "attachment; filename=pub.key");
reply.send(keyFile);
} catch (error) {
reply.status(500).send('Internal Server Error');
}
});

Comment on lines +144 to +147
const regFile = handleGetRegistry(config);
reply.header("Content-Type", "text/plain");
reply.header("Content-Disposition", "attachment; filename=client.reg");
reply.send(regFile);
Copy link

Choose a reason for hiding this comment

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

The /registry route handler is not async, unlike the /cert and /key handlers. For consistency and to leverage async file handling, consider updating this handler to be async as well. Also, ensure this part of the code is covered by tests.

    webServer.get("/registry", (_request, reply) => {
        const config = getServerConfiguration({});
        if (typeof config.host === "undefined") {
            throw new Error("No host defined in config");
        }
+       try {
-        const regFile = handleGetRegistry(config);
+        const regFile = await handleGetRegistry(config);
        reply.header("Content-Type", "text/plain");
        reply.header("Content-Disposition", "attachment; filename=client.reg");
        reply.send(regFile);
+       } catch (error) {
+           reply.status(500).send('Internal Server Error');
+       }
    });

Would you like help in creating unit tests for this route handler?


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.

Suggested change
const regFile = handleGetRegistry(config);
reply.header("Content-Type", "text/plain");
reply.header("Content-Disposition", "attachment; filename=client.reg");
reply.send(regFile);
try {
const regFile = await handleGetRegistry(config);
reply.header("Content-Type", "text/plain");
reply.header("Content-Disposition", "attachment; filename=client.reg");
reply.send(regFile);
} catch (error) {
reply.status(500).send('Internal Server Error');
}

@drazisil drazisil merged commit 20636c6 into main Mar 30, 2024
9 of 11 checks passed
@drazisil drazisil deleted the start-tutorial branch March 30, 2024 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant