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

test: add non regression tests for domain imports #1497

Merged

Conversation

nas-tabchiche
Copy link
Contributor

@nas-tabchiche nas-tabchiche commented Feb 12, 2025

  • Add data-testid on RowCount component
  • Write simple non regression test for domain import
  • Fix regression in domain import form
  • Set backend version and build in e2e tests script
  • Add debug log for uploaded file path
  • Tidy tests

Summary by CodeRabbit

  • Refactor

    • Improved cache management during form updates to enhance performance.
    • Streamlined form data processing for the import functionality.
  • New Features

    • Added accessibility attributes for improved testing in the row count display.
    • Introduced new helper functions for dismissing modals and navigating folders in tests.
  • Tests

    • Expanded test coverage for domain import and demo data loading functionalities, ensuring expected application behavior.
    • Added new test cases for importing domains from .bak files and loading demo data.

@nas-tabchiche nas-tabchiche changed the title CA 864 add non regression tests for domain imports test: add non regression tests for domain imports Feb 12, 2025
Copy link
Contributor

coderabbitai bot commented Feb 12, 2025

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

💤 Files selected but had no reviewable changes (2)
  • backend/fixtures/dummy-domain.bak
  • frontend/tests/utils/sample-domain-schema-1.bak

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This pull request makes targeted adjustments across the frontend codebase. The changes modify cache handling in the form update function of a Svelte component, add a testing attribute to another UI component, and update form data processing in a server route. In addition, the end-to-end test script has been reformatted with new environment variable exports, and a new functional test suite for domain import and demo data loading has been added.

Changes

Files Change Summary
frontend/src/lib/components/Forms/ModelForm.svelte
frontend/src/lib/components/ModelTable/RowCount.svelte
ModelForm.svelte: Removed createModalCache.deleteCache(model.urlModel); from the redirect branch in the onUpdated function.
RowCount.svelte: Added data-testid="row-count" attribute to the <aside> element.
frontend/src/routes/(app)/(internal)/[model=urlmodel]/+page.server.ts Modified the importFolder action by replacing direct conversion of form data with deferred conversion using Object.fromEntries(formData), changing how the file is extracted.
frontend/tests/e2e-tests.sh
frontend/tests/functional/domain-import.test.ts
e2e-tests.sh: Standardized indentation and added environment variable exports.
domain-import.test.ts: Introduced a new functional test suite with helper functions for domain import and demo data loading.
.github/workflows/functional-tests.yml Added environment variable assignments for CISO_ASSISTANT_VERSION and CISO_ASSISTANT_BUILD in the GitHub Actions workflow.

Possibly related PRs

Suggested reviewers

  • ab-smith
  • eric-intuitem
  • Mohamed-Hacene

Poem

I'm a bunny hopping through the code so light,
Digging in changes from morning to night.
Cache or no cache, the logic's clear and neat,
Testing paths and flows, all coming up sweet.
With whiskers twitching at each debug delight,
I celebrate these changes with a carrot bite!
🥕🐰


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>, please review it.
    • 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 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 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 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. (Beta)
  • @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.

Copy link
Contributor

@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

🧹 Nitpick comments (3)
frontend/tests/functional/domain-import.test.ts (3)

4-18: LGTM! Consider adding error handling.

The modal dismissal logic is well-structured and includes a good defensive fallback. Consider adding try-catch blocks to handle potential failures gracefully.

 async function dismissBlockingModals(page: Page) {
+  try {
     const modalBackdrop = page.getByTestId('modal-backdrop');
     if (await modalBackdrop.isVisible()) {
       await modalBackdrop.press('Escape');
       await expect(modalBackdrop).toBeHidden();
     }
     const dummyElement = page.locator('#driver-dummy-element');
     if (await dummyElement.isVisible()) {
       await page.locator('.driver-popover-close-btn').first().click();
       await expect(dummyElement).toBeHidden();
     }
     // Ensure no lingering modals remain.
     await page.locator('body').press('Escape');
+  } catch (error) {
+    console.error('Failed to dismiss modals:', error);
+    throw error;
+  }
 }

28-34: Consider enhancing the row count extraction logic.

The current implementation could be more robust:

  1. The regex pattern could be more specific to match the expected format
  2. Add validation for the extracted number
 async function getRowCount(page: Page) {
   const rowCountText = await page.getByTestId('row-count').innerText();
-  const match = rowCountText.match(/\d+$/);
+  const match = rowCountText.match(/Total:\s*(\d+)/i);
+  if (!match) {
+    console.warn(`Unexpected row count format: ${rowCountText}`);
+    return 0;
+  }
-  return match ? parseInt(match[0], 10) : 0;
+  const count = parseInt(match[1], 10);
+  return isNaN(count) ? 0 : count;
 }

36-100: LGTM! Consider adding more assertions.

The test cases are well-structured with clear steps and proper verifications. Consider adding:

  1. Assertions for the domain name in the UI after import
  2. Verification of the demo data content
 await test.step('Import sample domain', async () => {
   // ... existing code ...
   await expect(toast).toHaveText(/successfully imported/i);
+  // Verify domain name appears in the UI
+  await expect(page.getByText(domainName)).toBeVisible();
   // ... existing code ...
 });

 await test.step('Load demo data', async () => {
   // ... existing code ...
   await expect(toast).toHaveText(/successfully imported/i);
+  // Verify demo data content
+  await expect(page.getByText('Demo Organization')).toBeVisible();
   // ... existing code ...
 });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 87ffbea and c73a25b.

📒 Files selected for processing (5)
  • frontend/src/lib/components/Forms/ModelForm.svelte (0 hunks)
  • frontend/src/lib/components/ModelTable/RowCount.svelte (1 hunks)
  • frontend/src/routes/(app)/(internal)/[model=urlmodel]/+page.server.ts (1 hunks)
  • frontend/tests/e2e-tests.sh (4 hunks)
  • frontend/tests/functional/domain-import.test.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • frontend/src/lib/components/Forms/ModelForm.svelte
✅ Files skipped from review due to trivial changes (1)
  • frontend/src/lib/components/ModelTable/RowCount.svelte
🧰 Additional context used
🪛 Shellcheck (0.10.0)
frontend/tests/e2e-tests.sh

[error] 49-49: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).

(SC2199)


[error] 49-49: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).

(SC2199)


[error] 106-106: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).

(SC2199)


[error] 111-111: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).

(SC2199)


[error] 157-157: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).

(SC2199)


[warning] 184-184: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 185-185: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 187-187: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)


[error] 220-220: Argument mixes string and array. Use * or separate argument.

(SC2145)


[error] 225-225: Argument mixes string and array. Use * or separate argument.

(SC2145)


[error] 238-238: Argument mixes string and array. Use * or separate argument.

(SC2145)


[error] 240-240: Argument mixes string and array. Use * or separate argument.

(SC2145)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: functional-tests (3.12, chromium)
  • GitHub Check: enterprise-functional-tests (3.12, chromium)
🔇 Additional comments (2)
frontend/tests/functional/domain-import.test.ts (1)

20-26: LGTM! Navigation helper is well-implemented.

The function uses appropriate selectors and includes proper verification steps.

frontend/src/routes/(app)/(internal)/[model=urlmodel]/+page.server.ts (1)

75-83: LGTM! Form data handling is improved.

The changes correctly handle form data extraction and file processing.

frontend/tests/e2e-tests.sh Outdated Show resolved Hide resolved
Comment on lines +238 to 241
pnpm playwright test ./tests/functional/"${TEST_PATHS[@]}" --project=chromium "${SCRIPT_LONG_ARGS[@]}" "${SCRIPT_SHORT_ARGS[@]}"
else
pnpm playwright test ./tests/functional/"${TEST_PATHS[@]}" "${SCRIPT_LONG_ARGS[@]}" "${SCRIPT_SHORT_ARGS[@]}"
pnpm playwright test ./tests/functional/"${TEST_PATHS[@]}" "${SCRIPT_LONG_ARGS[@]}" "${SCRIPT_SHORT_ARGS[@]}"
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Fix array argument handling in test commands.

Use proper array expansion to avoid argument mixing issues.

-  pnpm playwright test ./tests/functional/"${TEST_PATHS[@]}" --project=chromium "${SCRIPT_LONG_ARGS[@]}" "${SCRIPT_SHORT_ARGS[@]}"
+  pnpm playwright test ./tests/functional/"${TEST_PATHS[*]}" --project=chromium "${SCRIPT_LONG_ARGS[*]}" "${SCRIPT_SHORT_ARGS[*]}"
-  pnpm playwright test ./tests/functional/"${TEST_PATHS[@]}" "${SCRIPT_LONG_ARGS[@]}" "${SCRIPT_SHORT_ARGS[@]}"
+  pnpm playwright test ./tests/functional/"${TEST_PATHS[*]}" "${SCRIPT_LONG_ARGS[*]}" "${SCRIPT_SHORT_ARGS[*]}"
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pnpm playwright test ./tests/functional/"${TEST_PATHS[@]}" --project=chromium "${SCRIPT_LONG_ARGS[@]}" "${SCRIPT_SHORT_ARGS[@]}"
else
pnpm playwright test ./tests/functional/"${TEST_PATHS[@]}" "${SCRIPT_LONG_ARGS[@]}" "${SCRIPT_SHORT_ARGS[@]}"
pnpm playwright test ./tests/functional/"${TEST_PATHS[@]}" "${SCRIPT_LONG_ARGS[@]}" "${SCRIPT_SHORT_ARGS[@]}"
fi
pnpm playwright test ./tests/functional/"${TEST_PATHS[*]}" --project=chromium "${SCRIPT_LONG_ARGS[*]}" "${SCRIPT_SHORT_ARGS[*]}"
else
pnpm playwright test ./tests/functional/"${TEST_PATHS[*]}" "${SCRIPT_LONG_ARGS[*]}" "${SCRIPT_SHORT_ARGS[*]}"
fi
🧰 Tools
🪛 Shellcheck (0.10.0)

[error] 238-238: Argument mixes string and array. Use * or separate argument.

(SC2145)


[error] 240-240: Argument mixes string and array. Use * or separate argument.

(SC2145)

Comment on lines +184 to +185
export CISO_ASSISTANT_VERSION=$(git describe --tags --always)
export CISO_ASSISTANT_BUILD=$(git rev-parse --short HEAD)
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Fix variable declaration and assignment.

Separate declaration and assignment to avoid masking return values.

-export CISO_ASSISTANT_VERSION=$(git describe --tags --always)
-export CISO_ASSISTANT_BUILD=$(git rev-parse --short HEAD)
+CISO_ASSISTANT_VERSION=""
+CISO_ASSISTANT_BUILD=""
+CISO_ASSISTANT_VERSION=$(git describe --tags --always)
+CISO_ASSISTANT_BUILD=$(git rev-parse --short HEAD)
+export CISO_ASSISTANT_VERSION
+export CISO_ASSISTANT_BUILD
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export CISO_ASSISTANT_VERSION=$(git describe --tags --always)
export CISO_ASSISTANT_BUILD=$(git rev-parse --short HEAD)
CISO_ASSISTANT_VERSION=""
CISO_ASSISTANT_BUILD=""
CISO_ASSISTANT_VERSION=$(git describe --tags --always)
CISO_ASSISTANT_BUILD=$(git rev-parse --short HEAD)
export CISO_ASSISTANT_VERSION
export CISO_ASSISTANT_BUILD
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 184-184: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 185-185: Declare and assign separately to avoid masking return values.

(SC2155)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@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

🧹 Nitpick comments (2)
frontend/tests/e2e-tests.sh (2)

229-235: Consider using git hash for frontend cache invalidation.

Instead of using md5sum which can be slow for large codebases, consider using git hash:

-FRONTEND_HASH=$(find "$APP_DIR/frontend/src" -type f \( -name "*.ts" -o -name "*.svelte" \) -print0 | xargs -0 md5sum | md5sum)
+FRONTEND_HASH=$(git hash-object $(find "$APP_DIR/frontend/src" -type f \( -name "*.ts" -o -name "*.svelte" \)))

171-183: Consider using a .env file for environment variables.

The large number of environment variables could be better managed using a .env file.

Consider moving these environment variables to a .env.test file and sourcing it:

# .env.test
CISO_ASSISTANT_URL=http://localhost:4173
ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0
...

Then in the script:

source "$APP_DIR/frontend/tests/.env.test"
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c73a25b and 076454c.

📒 Files selected for processing (1)
  • frontend/tests/e2e-tests.sh (4 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
frontend/tests/e2e-tests.sh

[error] 49-49: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).

(SC2199)


[error] 49-49: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).

(SC2199)


[error] 106-106: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).

(SC2199)


[error] 111-111: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).

(SC2199)


[error] 157-157: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).

(SC2199)


[warning] 184-184: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 185-185: Declare and assign separately to avoid masking return values.

(SC2155)


[error] 220-220: Argument mixes string and array. Use * or separate argument.

(SC2145)


[error] 225-225: Argument mixes string and array. Use * or separate argument.

(SC2145)


[error] 238-238: Argument mixes string and array. Use * or separate argument.

(SC2145)


[error] 240-240: Argument mixes string and array. Use * or separate argument.

(SC2145)

⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: startup-docker-compose-test
  • GitHub Check: enterprise-startup-functional-test (3.12)
  • GitHub Check: enterprise-startup-docker-compose-test
  • GitHub Check: functional-tests (3.12, chromium)
  • GitHub Check: enterprise-functional-tests (3.12, chromium)
  • GitHub Check: startup-functional-test (3.12)
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
frontend/tests/e2e-tests.sh (3)

15-47: LGTM! Argument handling is well-structured.

The argument parsing logic is clear and handles all cases appropriately with proper validation.


184-185: Fix variable declaration and assignment to avoid masking return values.

The current export with inline assignment can mask return values from the git commands.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 184-184: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 185-185: Declare and assign separately to avoid masking return values.

(SC2155)


237-241: Fix array argument handling in test commands.

The current array expansion can lead to argument mixing issues.

🧰 Tools
🪛 Shellcheck (0.10.0)

[error] 238-238: Argument mixes string and array. Use * or separate argument.

(SC2145)


[error] 240-240: Argument mixes string and array. Use * or separate argument.

(SC2145)

SCRIPT_SHORT_ARGS+=("$arg")
elif [[ $arg != -* ]]; then
TEST_PATHS+=("$arg")
fi
done

if [[ " ${SCRIPT_SHORT_ARGS[@]} " =~ " -h " ]] || [[ " ${SCRIPT_LONG_ARGS[@]} " =~ " --help " ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Fix array concatenation in conditional check.

The current array concatenation in the conditional statement can lead to unexpected behavior.

-if [[ " ${SCRIPT_SHORT_ARGS[@]} " =~ " -h " ]] || [[ " ${SCRIPT_LONG_ARGS[@]} " =~ " --help " ]]; then
+if printf '%s\n' "${SCRIPT_SHORT_ARGS[@]}" | grep -q '^-h$' || printf '%s\n' "${SCRIPT_LONG_ARGS[@]}" | grep -q '^--help$'; then
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [[ " ${SCRIPT_SHORT_ARGS[@]} " =~ " -h " ]] || [[ " ${SCRIPT_LONG_ARGS[@]} " =~ " --help " ]]; then
if printf '%s\n' "${SCRIPT_SHORT_ARGS[@]}" | grep -q '^-h$' || printf '%s\n' "${SCRIPT_LONG_ARGS[@]}" | grep -q '^--help$'; then
🧰 Tools
🪛 Shellcheck (0.10.0)

[error] 49-49: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).

(SC2199)


[error] 49-49: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).

(SC2199)

Comment on lines 104 to 117
for PORT in $MAILER_WEB_SERVER_PORT $MAILER_SMTP_SERVER_PORT; do
if python3 -c "import socket;exit(0 if 0 == socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex(('localhost',$PORT)) else 1)"; then
if [[ ! " ${SCRIPT_SHORT_ARGS[@]} " =~ " -m " ]]; then
echo "The port $PORT is already in use!"
echo "Please stop the running process using the port or change the mailer port and try again."
exit 1
fi
elif [[ " ${SCRIPT_SHORT_ARGS[@]} " =~ " -m " ]]; then
echo "No mailer service is running on port $PORT!"
echo "Please start a mailer service on port $PORT or change the mailer port using --mailer=PORT/PORT and try again."
echo "You can also use the isolated test mailer service by removing the -m option."
exit 1
fi
if python3 -c "import socket;exit(0 if 0 == socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex(('localhost',$PORT)) else 1)"; then
if [[ ! " ${SCRIPT_SHORT_ARGS[@]} " =~ " -m " ]]; then
echo "The port $PORT is already in use!"
echo "Please stop the running process using the port or change the mailer port and try again."
exit 1
fi
elif [[ " ${SCRIPT_SHORT_ARGS[@]} " =~ " -m " ]]; then
echo "No mailer service is running on port $PORT!"
echo "Please start a mailer service on port $PORT or change the mailer port using --mailer=PORT/PORT and try again."
echo "You can also use the isolated test mailer service by removing the -m option."
exit 1
fi
done
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve port checking logic.

The port checking logic has similar array concatenation issues in the conditionals.

-  if [[ ! " ${SCRIPT_SHORT_ARGS[@]} " =~ " -m " ]]; then
+  if ! printf '%s\n' "${SCRIPT_SHORT_ARGS[@]}" | grep -q '^-m$'; then

Also, consider adding a timeout to the port check to avoid hanging:

-  if python3 -c "import socket;exit(0 if 0 == socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex(('localhost',$PORT)) else 1)"; then
+  if python3 -c "
+import socket
+s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+s.settimeout(1)
+exit(0 if 0 == s.connect_ex(('localhost',$PORT)) else 1)
+"; then
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for PORT in $MAILER_WEB_SERVER_PORT $MAILER_SMTP_SERVER_PORT; do
if python3 -c "import socket;exit(0 if 0 == socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex(('localhost',$PORT)) else 1)"; then
if [[ ! " ${SCRIPT_SHORT_ARGS[@]} " =~ " -m " ]]; then
echo "The port $PORT is already in use!"
echo "Please stop the running process using the port or change the mailer port and try again."
exit 1
fi
elif [[ " ${SCRIPT_SHORT_ARGS[@]} " =~ " -m " ]]; then
echo "No mailer service is running on port $PORT!"
echo "Please start a mailer service on port $PORT or change the mailer port using --mailer=PORT/PORT and try again."
echo "You can also use the isolated test mailer service by removing the -m option."
exit 1
fi
if python3 -c "import socket;exit(0 if 0 == socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex(('localhost',$PORT)) else 1)"; then
if [[ ! " ${SCRIPT_SHORT_ARGS[@]} " =~ " -m " ]]; then
echo "The port $PORT is already in use!"
echo "Please stop the running process using the port or change the mailer port and try again."
exit 1
fi
elif [[ " ${SCRIPT_SHORT_ARGS[@]} " =~ " -m " ]]; then
echo "No mailer service is running on port $PORT!"
echo "Please start a mailer service on port $PORT or change the mailer port using --mailer=PORT/PORT and try again."
echo "You can also use the isolated test mailer service by removing the -m option."
exit 1
fi
done
for PORT in $MAILER_WEB_SERVER_PORT $MAILER_SMTP_SERVER_PORT; do
if python3 -c "
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
exit(0 if 0 == s.connect_ex(('localhost',$PORT)) else 1)
"; then
if ! printf '%s\n' "${SCRIPT_SHORT_ARGS[@]}" | grep -q '^-m$'; then
echo "The port $PORT is already in use!"
echo "Please stop the running process using the port or change the mailer port and try again."
exit 1
fi
elif [[ " ${SCRIPT_SHORT_ARGS[@]} " =~ " -m " ]]; then
echo "No mailer service is running on port $PORT!"
echo "Please start a mailer service on port $PORT or change the mailer port using --mailer=PORT/PORT and try again."
echo "You can also use the isolated test mailer service by removing the -m option."
exit 1
fi
done
🧰 Tools
🪛 Shellcheck (0.10.0)

[error] 106-106: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).

(SC2199)


[error] 111-111: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).

(SC2199)

Copy link
Contributor

@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

🧹 Nitpick comments (2)
.github/workflows/functional-tests.yml (2)

97-98: Consider using dynamic version and centralizing configuration.

The version is hardcoded while the build uses a git command. Consider:

  1. Using $(git describe --tags --always) for version to match e2e-tests.sh
  2. Moving these values to workflow-level env variables for better maintainability
-          echo CISO_ASSISTANT_VERSION=v4.2.0 >> .env
+          echo CISO_ASSISTANT_VERSION=$(git describe --tags --always) >> .env

Or better yet, move to workflow-level env:

 env:
   BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
   GITHUB_WORKFLOW: github_actions
+  CISO_ASSISTANT_VERSION: ${{ steps.version.outputs.version }}
+  CISO_ASSISTANT_BUILD: ${{ steps.build.outputs.build }}
   backend-directory: ./backend
   ...

 jobs:
   functional-tests:
     steps:
+      - id: version
+        run: echo "version=$(git describe --tags --always)" >> $GITHUB_OUTPUT
+      - id: build
+        run: echo "build=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

209-210: Remove duplicated configuration.

This configuration is identical to the one in the functional-tests job. If you move the version and build to workflow-level env variables as suggested above, this duplication can be eliminated.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 076454c and de04713.

📒 Files selected for processing (1)
  • .github/workflows/functional-tests.yml (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: startup-functional-test (3.12)
  • GitHub Check: startup-docker-compose-test
  • GitHub Check: functional-tests (3.12, chromium)
  • GitHub Check: enterprise-startup-functional-test (3.12)
  • GitHub Check: enterprise-functional-tests (3.12, chromium)
  • GitHub Check: enterprise-startup-docker-compose-test
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (javascript-typescript)

Copy link
Collaborator

@Mohamed-Hacene Mohamed-Hacene left a comment

Choose a reason for hiding this comment

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

0k

@Mohamed-Hacene Mohamed-Hacene merged commit 2592fe5 into main Feb 13, 2025
21 checks passed
@Mohamed-Hacene Mohamed-Hacene deleted the CA-864-add-non-regression-tests-for-domain-imports branch February 13, 2025 13:09
@github-actions github-actions bot locked and limited conversation to collaborators Feb 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants