betagouv / preuve-covoiturage

Registre de preuve de covoiturage
https://app.covoiturage.beta.gouv.fr
Apache License 2.0
32 stars 12 forks source link

units -> integration #2510

Closed jonathanfallon closed 2 months ago

jonathanfallon commented 2 months ago

renommage des fichiers de tests appelés *.unit.spec.ts en *.integration.spec.ts quand les tests comportent des dépendances à des connexions Postgres / Redis ou des accès au système de fichiers.

Summary by CodeRabbit

coderabbitai[bot] commented 2 months ago

[!WARNING]

Review failed

Failed to post review comments.

Configuration used: CodeRabbit UI Review profile: CHILL

Commits Files that changed from the base of the PR and between 63d60f06ba3fca246714c852607a4bb049d56cf1 and 61bbac431f7cadaf90283f67c741c3325f6f3fc6.
Files ignored due to path filters (2) * `api/deno.lock` is excluded by `!**/*.lock` * `api/package-lock.json` is excluded by `!**/package-lock.json`
Files selected for processing (12) * .github/workflows/analysis.yml (5 hunks) * .github/workflows/deploy-backends.yml (1 hunks) * .vscode/extensions.json (1 hunks) * .vscode/launch.json (1 hunks) * .vscode/settings.json (1 hunks) * api/deno.json (1 hunks) * api/justfile (3 hunks) * api/src/config/connections.ts (3 hunks) * api/src/db/README.md (1 hunks) * api/src/db/index.ts (1 hunks) * api/src/db/main.ts (1 hunks) * api/src/db/migrations/20190101100000-schemas.sql (1 hunks)
Files not summarized due to errors (1) * api/src/db/migrations/20190101100000-schemas.sql: Error: Message exceeds token limit
Files not reviewed due to errors (2) * .vscode/launch.json (no review received) * .vscode/settings.json (no review received)
Files skipped from review due to trivial changes (3) * .github/workflows/deploy-backends.yml * .vscode/extensions.json * api/deno.json
Additional context used
LanguageTool
api/src/db/README.md
[uncategorized] ~8-~8: Une espace doit être ajoutée entre ces deux mots ou intégrez ce nouveau mot à votre dictionnaire personnel. (MOTS_COLLES3) Context: ... db-migrate db-migrate-pg ``` ### Geo 7zip doit être installé afin de créer la tab...
Markdownlint
api/src/db/README.md
7-7: null (MD018, no-missing-space-atx) No space after hash on atx style heading --- 15-15: null (MD025, single-title, single-h1) Multiple top-level headings in the same document --- 3-3: null (MD040, fenced-code-language) Fenced code blocks should have a language specified --- 11-11: null (MD040, fenced-code-language) Fenced code blocks should have a language specified
Additional comments not posted (16)
api/src/db/main.ts (1)
`1-1`: Ensure `process` is properly imported from "@/deps.ts" to handle environment variables correctly.
Verification successful --- The import statement for `process` from "@/deps.ts" is correctly present in the file `api/src/db/main.ts`. -
Scripts executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Description: Verify the correct import of `process`. # Test: Search for the correct import statement in the file. rg --type typescript $'import { process } from "@/deps.ts"' api/src/db/main.ts ``` Length of output: 206 --- --- Script: ```shell #!/bin/bash # Description: Verify the correct import of `process`. # Test: Search for the correct import statement in the file. rg --type typescript 'import \{ process \} from "@/deps\.ts"' api/src/db/main.ts ``` Length of output: 117 --- --- Script: ```shell #!/bin/bash # Description: Verify the correct import of `process`. # Test: Search for the correct import statement in the file. rg --type ts 'import \{ process \} from "@/deps\.ts"' api/src/db/main.ts ``` Length of output: 111
api/src/config/connections.ts (3)
`15-17`: Ensure proper handling of default values in `unnestRedisConnectionString`. This ensures robustness by providing fallbacks when certain properties are not specified in the URL. --- `37-39`: Review the spread operator usage in `redisTls` and `redis` configurations. This use of the spread operator ensures that TLS configurations are correctly applied if they exist. Also applies to: 44-44 --- `27-29`: Check the handling of environment variables in `tlsSetup`. Ensure that environment variables are correctly set and accessible.
Verification successful --- The `tlsSetup` function in `api/src/config/connections.ts` correctly handles environment variables by checking for their presence and appropriately reading their values. The function looks for both the direct environment variable (`asVarEnvName`) and a file path variable (`asPathEnvName`), ensuring that the certificate content is obtained correctly. - The function first checks if `asVarEnvName` is in `process.env` and replaces any escaped newline characters. - If `asVarEnvName` is not found, it checks for `asPathEnvName` and reads the certificate from the file. - If neither is found, it returns an empty object. Thus, the handling of environment variables in the `tlsSetup` function appears to be correct.
Scripts executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Description: Verify the correct handling of environment variables for TLS setup. env | grep APP_REDIS_CA ``` Length of output: 25 --- --- Script: ```shell #!/bin/bash # Locate the implementation of the `tlsSetup` function ast-grep --lang typescript --pattern 'function tlsSetup($_) { $$$ }' ``` Length of output: 70 --- --- Script: ```shell #!/bin/bash # Search for any function or variable related to TLS setup rg -i 'tls' --type ts ``` Length of output: 1333 --- --- Script: ```shell #!/bin/bash # Display the implementation of the `tlsSetup` function in `api/src/config/connections.ts` ast-grep --lang typescript --pattern 'function tlsSetup(key: string, baseEnvKey: string): { [k: string]: string } { $$$ }' api/src/config/connections.ts ``` Length of output: 1058
api/src/db/index.ts (3)
`14-24`: Review the process of fetching SQL migration files. This function correctly filters and maps SQL files for migrations, ensuring that only `.sql` files are considered. --- `26-30`: Ensure idempotence of `createMigrationTable`. Using `CREATE TABLE IF NOT EXISTS` ensures that the migration table is created only if it does not already exist, which is crucial for idempotence. --- `72-96`: Review the conditional execution of migrations based on environment variables. This approach allows for flexible execution of migrations based on the environment, which can be useful for different deployment scenarios.
api/justfile (2)
`11-21`: Review the test commands and Docker service management. The commands are well-defined and cover a wide range of test scenarios and Docker service management tasks. --- `96-99`: Check the CI integration and unit test commands. These commands are crucial for ensuring that the continuous integration pipeline runs the necessary tests and setups.
.github/workflows/analysis.yml (3)
`12-24`: Review the changes in the lint job configuration. The transition to Deno from Node.js is reflected well in the workflow configuration changes, aligning with the project's shift in technology stack. --- `69-79`: Check the test job configuration. The configuration correctly sets up Deno and handles potential errors with `continue-on-error`, which can be useful for non-blocking CI pipelines. --- Line range hint `118-155`: Evaluate the integration test job configuration. The setup for integration tests is comprehensive, ensuring that all necessary services and environment variables are configured properly.
api/src/db/migrations/20190101100000-schemas.sql (4)
`1-2`: Ensure that the required PostgreSQL extensions are installed. These statements are standard for enabling extensions in PostgreSQL. Ensure that the `uuid-ossp` and `postgis` extensions are available in your PostgreSQL installation to avoid runtime errors. --- `3-20`: Creation of multiple schemas. Each `CREATE SCHEMA` statement is correctly formatted. This will organize the database into logical groups, which is good for maintenance and scalability. --- `21-26`: Define various ENUM types and composite types. The ENUM and composite types are well-defined with appropriate data types and constraints. These will enforce data integrity and provide clear structure for various entities in the database. Also applies to: 27-32, 33-39, 45-52, 53-57, 58-63, 64-67, 68-72, 73-78, 79-83, 84-90, 91-96, 97-100, 101-111, 112-116, 117-127, 128-141, 142-149 --- `289-290`: Setting default tablespace and access method. Setting the default tablespace and table access method at the end of the migration script is a good practice to ensure that all tables created use these defaults unless specified otherwise.
Comments failed to post (6)
api/src/db/migrations/20190101100000-schemas.sql
150-164: Creation of functions. The functions are generally well-defined. However, consider using more descriptive variable names instead of `_ti` and `bc`, which could improve readability and maintainability. ```diff - CREATE FUNCTION fraudcheck.result_to_json(_ti fraudcheck.result) RETURNS json + CREATE FUNCTION fraudcheck.result_to_json(result_record fraudcheck.result) RETURNS json ``` Also applies to: 165-180, 181-191, 193-206, 207-220, 221-231, 234-241, 242-273, 275-288
api/src/config/connections.ts
48-50: Validate the SSL configuration logic in `postgres`. ```diff - ...(Object.keys(postgresTls).length ? { ssl: { ...postgresTls, host: env.or_fail("APP_POSTGRES_HOST") } } : {}), + ...(Object.keys(postgresTls).length ? { ssl: { ...postgresTls, host: env.or_fail("APP_POSTGRES_HOST") } } : { ssl: false }), ``` Consider explicitly setting `ssl` to `false` when no TLS configurations are provided to avoid potential connection issues. Also applies to: 54-59
api/src/db/main.ts
4-4: > [!TIP] > Codebase Verification There is no error handling around the `migrate` function call in `api/src/db/main.ts`. - `migrate(process.env.APP_POSTGRES_URL);`
Analysis chain Check for error handling around the `migrate` function call.
Scripts executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Description: Verify error handling for `migrate` function. # Test: Search for error handling in the file. rg --type typescript $'try {.*migrate.*} catch' api/src/db/main.ts ``` Length of output: 178 --- --- Script: ```shell #!/bin/bash # Description: Verify error handling for `migrate` function. # Test: Search for error handling in the file using a corrected regex pattern. rg --type typescript 'try\s*{[^}]*migrate[^}]*}\s*catch' api/src/db/main.ts ``` Length of output: 200 --- --- Script: ```shell #!/bin/bash # Description: Verify error handling for `migrate` function. # Test: Search for error handling in the file using a simplified regex pattern. rg --type typescript 'try\s*{[^}]*migrate[^}]*}\s*catch\s*{[^}]*}' api/src/db/main.ts ``` Length of output: 220 --- --- Script: ```shell #!/bin/bash # Description: Verify error handling for `migrate` function. # Step 1: Locate the `migrate` function call in the file. rg --type typescript 'migrate' api/src/db/main.ts # Step 2: Check for any try-catch blocks around the identified `migrate` function call. rg --type typescript 'try\s*{[^}]*}\s*catch\s*{[^}]*}' api/src/db/main.ts ``` Length of output: 281 --- --- Script: ```shell #!/bin/bash # Description: Verify error handling for `migrate` function. # Step 1: Locate the `migrate` function call in the file. rg 'migrate' api/src/db/main.ts # Step 2: Check for any try-catch blocks around the identified `migrate` function call. rg 'try\s*{[^}]*}\s*catch\s*{[^}]*}' api/src/db/main.ts ``` Length of output: 287 --- --- Script: ```shell #!/bin/bash # Description: Verify error handling for `migrate` function. # Step 1: Locate the `migrate` function call in the file and show surrounding lines. rg -C 5 'migrate' api/src/db/main.ts ``` Length of output: 151
api/src/db/README.md
15-15: Avoid multiple top-level headings in the same document. ```diff -# Usage +## Usage ```
Committable suggestion > :bangbang: **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. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion ## Usage `````
Tools
Markdownlint
15-15: null (MD025, single-title, single-h1) Multiple top-level headings in the same document
--- 7-7: Add space after hash for correct Markdown formatting. ```diff -### Geo +### Geo ```
Committable suggestion > :bangbang: **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. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion ### Geo `````
Tools
Markdownlint
7-7: null (MD018, no-missing-space-atx) No space after hash on atx style heading
api/src/db/index.ts
39-70: Check the logic for running migrations. Consider encapsulating the migration logic into smaller, more manageable functions to improve readability and maintainability.

Walkthrough

The project has undergone significant updates, with a focus on transitioning from NodeJS to Deno for development and tooling. This included modifying GitHub workflows, VSCode configurations, and some API source files to adapt to Deno's environment. Notable changes include updating linting and testing commands, altering Docker paths, adjusting VSCode settings for Deno, and refining database migration scripts. Additionally, various formatting and import paths were standardized across the project.

Changes

Files Change Summary
.github/workflows/analysis.yml Renamed Lint job, switched to Deno setup, updated lint command to deno lint, removed Docker steps, added continue-on-error.
.github/workflows/deploy-backends.yml Changed Dockerfile path for the api service from ./docker/api/prod/Dockerfile to ./docker/api/Dockerfile.
.vscode/extensions.json Added "denoland.vscode-deno" extension.
.vscode/launch.json Removed AVA-related configs, added Deno launch configs and debug settings.
.vscode/settings.json Updated formatters and file exclusions, enabled Deno support, organized imports on save, adjusted TypeScript preferences.
api/deno.json New configuration file for Deno settings including imports, decorators, and metadata emission.
api/justfile Restructured test commands, updated test command, refined api command for Deno, adjusted CI test commands.
api/src/config/connections.ts Updated imports, adjusted string quotes and object keys, added workaround comment for PostgreSQL.
api/src/db/README.md Fixed typo in French text, reformatted usage examples for clarity.
api/src/db/index.ts New file introducing functions for database migration handling with PostgreSQL.
api/src/db/main.ts New file executing migrate function using APP_POSTGRES_URL environment variable.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant GH as GitHub Actions
    participant Deno as Deno Environment
    participant DB as Database

    Dev->>+GH: Push code changes
    GH->>+Deno: Setup Deno environment
    Deno->>Deno: Run deno lint, continue on error
    Deno->>Deno: Run deno test, continue on error
    Note right of Deno: Linting and testing steps can continue even if errors are encountered
    GH->>DB: Deploy Docker image with new Dockerfile path
    DB->>-GH: Deployment complete

Poem

🐇 In the realm of Deno's light, Tools and syntax shining bright, NodeJS steps out, Deno steps in, Lint and test, the code shall win. With workflows smoother, clean as air, Debugging shines beyond compare! 🌟


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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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.` - `@coderabbitai help me debug CodeRabbit configuration file.` 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 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 resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@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. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.