# About

## Welcome to Redefine 👋🏽

Redefine is a CI optimization platform that accelerates software development and cuts CI costs with just one click.

## Who can benefit from Redefine? 🧑🏽‍💻

Redefine is designed for developers looking to save time and money by running only the relevant tests based on their code change.

## What is Redefine?⏳

Redefine analyzes code changes, coding patterns, and test results to determine which tests are relevant for each testing cycle. This reduces the number of tests needed per testing run; allows you to detect bugs earlier; and to deploy updated, higher-quality code in a fraction of the time.

## How does Redefine work? 🧠&#x20;

Redefine utilizes a machine learning (ML) model to optimize the CI process by selectively running tests based on their relevancy. The platform learns from code changes and test results to train a test selection model that predicts the most relevant tests for each new code change.

For additional information, please refer to the [documentation page](/welcome-to-redefine/how-does-it-work).

<figure><img src="https://47263957-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuwbuslmLp28ROGViWkou%2Fuploads%2Fd6yVE7SiOi4iOgnDAXUj%2Fezgif.com-video-to-gif%20(1).gif?alt=media&amp;token=780c4d3a-ed87-4792-bc28-897439e90bb6" alt=""><figcaption></figcaption></figure>


# Quick Start ⏱️

<div align="left"><figure><img src="https://47263957-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuwbuslmLp28ROGViWkou%2Fuploads%2FWwK5N4ZSaCoreVLZNdRM%2Fimage.png?alt=media&amp;token=a5458c8f-d00c-41c8-9d93-08a7ae6d32cb" alt=""><figcaption></figcaption></figure></div>

## Install <a href="#install" id="install"></a>

Set up the Redefine CLI tool in your CI environment by copy-pasting the code below.

{% tabs %}
{% tab title="Pip Package Installer" %}

```bash
pip install -U redefine
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
The Redefine CLI tool supports Python 3.6+ and is currently only available for CI environments, not the local developer's environment.
{% endhint %}

## Configure

#### Set up the authentication key

Store the Redefine authentication key in your CI system by following the recommended best practices for your specific CI platform: [GitHub Actions](https://docs.github.com/en/actions/security-guides/encrypted-secrets), [GitLab CI](https://docs.gitlab.com/ee/ci/secrets/#use-vault-secrets-in-a-ci-job), [Jenkins](https://www.jenkins.io/doc/developer/security/secrets/), [CircleCI](https://circleci.com/docs/security-recommendations/?utm_source=google\&utm_medium=sem\&utm_campaign=sem-google-dg--emea-en-dsa-tROAS-auth-brand\&utm_term=g_-c__dsa\&utm_content=\&gclid=CjwKCAjwo7iiBhAEEiwAsIxQEa7XGK25SIOM9uF6QmG77SjFOvDx-bFpR12qn1d_aXJ3ZxC2d_l5ThoCcBsQAvD_BwE), [Buildkite](https://buildkite.com/docs/pipelines/secrets), or [TeamCity](https://www.jetbrains.com/help/teamcity/security-notes.html#Recommended+Security+Practices). Once stored, you can export the authentication key to the Redefine CLI by setting the environment variable as `REDEFINE_AUTH`. This ensures that the CLI can access the authentication key securely and use it for authentication purposes.

{% hint style="info" %}
If you haven't received your Redefine credentials yet, please reach out to us at <help@redefine.dev>, We'd be happy to assist you!
{% endhint %}

#### Additional Configurations

{% hint style="info" %}
Check out [Configuration Parameters](/configuration/configuration-parameters) for additional configuration options.
{% endhint %}

## Verify

Once Redefine has been installed and configured, make sure that everything is working properly by running the `verify` command. This command verifies whether your CI environment is compatible with Redefine, and returns a success message if all is good or an error message detailing any issues that need fixing. To run the command, follow these steps:

{% tabs %}
{% tab title="Pytest" %}

```bash
redefine verify --pytest
```

{% endtab %}

{% tab title="Cypress" %}

```bash
redefine verify --cypress
```

{% endtab %}

{% tab title="Mocha" %}

```bash
redefine verify --mocha
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
For more information on successful verification output and examples of failure cases, check out [Verification Examples](/welcome-to-redefine/quick-start/verification-examples).
{% endhint %}

{% hint style="info" %}
For a full list of error messages and resolutions, see [Verify Troubleshooting](/troubleshooting/verify-troubleshooting).
{% endhint %}

## Run in Discover Mode

With Discover mode, Redefine analyzes your coding patterns and test results to create the initial test optimization model. To start the discovery process, simply replace the `verify` command from the previous step with the following command:

{% tabs %}
{% tab title="Pytest" %}

```bash
redefine install --discover --pytest
```

{% endtab %}

{% tab title="Cypress" %}

```bash
redefine install --discover --cypress
```

{% hint style="info" %}
If you are running Cypress using the flags `--project` or `--config-file`, Please add it to the 'redefine start' command as well.

For example:

```bash
redefine install --discover --cypress --project /path/to/project
redefine install --discover --cypress --config-file /path/to/file
```

{% endhint %}
{% endtab %}

{% tab title="Mocha" %}

```
redefine install --discover --mocha
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
For more information about selection modes, please see [Selection Modes](/configuration/selection-modes).
{% endhint %}

## Examples

The following examples show the final Redefine for development environments setup using `pytest`. This gives an idea of what your configuration should look like once everything is in place.

{% tabs %}
{% tab title="Github Actions" %}

```
- name: Redefine GitHub Action
    id: run_redefine
    uses: redefinedev/redefine-action@main
    with:
        auth: ${{ secrets.REDEFINE_AUTH_KEY }}
        testing-framework: pytest
        mode: discover
- name: Test with pytest  
    id: pytest 
    run: pytest tests
```

For all the GitHub Action options see the action's [docs](https://github.com/marketplace/actions/redefine-action).
{% endtab %}

{% tab title="Jenkins" %}

<pre class="language-bash"><code class="lang-bash">    stages {
        stage('run pytest with redefine') {
            environment {
                REDEFINE_AUTH=credentials('REDEFINE_AUTH_KEY')
            }
            steps {
                <a data-footnote-ref href="#user-content-fn-1">sh </a>'''
                pip install -U redefine
<strong>                redefine install --discover --pytest 
</strong>                pytest tests
                '''
            }
        }
</code></pre>

{% endtab %}

{% tab title="CircleCI" %}

```yaml
    name: run Redefine
    command: |
        pip install -U redefine
        redefine install --discover --pytest
    environment:
        REDEFINE_AUTH: $REDEFINE_AUTH_KEY
- run:
    name: test with pytest
    command: pytest tests
```

{% endtab %}

{% tab title="TeamCity" %}

<pre class="language-bash"><code class="lang-bash">export REDEFINE_AUTH=%secure:REDEFINE_AUTH_KEY%
<strong>export TEAMCITY_GIT_PATH=%teamcity.build.checkoutDir%
</strong>export TEAMCITY_HEAD_COMMIT_HASH=%build.vcs.number%
export TEAMCITY_PIPELINE_NAME=%teamcity.project.id%
export TEAMCITY_JOB_NAME=%system.teamcity.buildConfName%
export TEAMCITY_GIT_ACTION=%teamcity.pullRequest.branch.pullrequests%
export TEAMCITY_SOURCE_BRANCH=%teamcity.pullRequest.source.branch%
export TEAMCITY_TARGET_BRANCH=%teamcity.pullRequest.target.branch%

pip install -U redefine
redefine install --discover --pytest
pytest tests
</code></pre>

{% endtab %}

{% tab title="Gitlab CI" %}

```yaml
  id_tokens:
    VAULT_ID_TOKEN:
      aud: https://gitlab.com
  secrets:
    REDEFINE_AUTH:
      vault: production/redefine/auth_key@ops
      token: $REDEFINE_AUTH
  stage: test
  script:
    - pip install -U redefine
    - redefine install --discover --pytest 
    - pytest tests
```

{% endtab %}

{% tab title="Buildkite" %}

```yaml
steps:
  - label: "run pytest tests with redefine"
    command: | 
      # redefine expects an environment variable named REDEDINE_AUTH 
      # check the documentation on how to use a secret in buildkite: https://buildkite.com/docs/pipelines/secrets
      export REDEFINE_AUTH=<your-secret>
      pip install -U redefine
      redefine install --discover --pytest 
      pytest tests
```

{% endtab %}
{% endtabs %}

{% hint style="success" %}
**Tracking the discovery progress**

Monitor the progress of the discovery process and verify the data using the [Redefine Onboarding Wizard](https://app.redefine.dev/onboarding), which offers a user-friendly way to track the process and ensure accurate results.
{% endhint %}

[^1]:


# Verification Examples

The example below shows a successful run of the Redefine `verify` command, as well as two failure cases to give you an idea of what might go wrong during the verification process:

{% tabs %}
{% tab title="Successful" %}

```bash
==================================================
                Redefine Verifier                 
==================================================
➤ Environment Verifications:
	✓ OS: linux
	i CI Platform: JENKINS
		✓ CI Type: ci_run_id (env name: BUILD_TAG): build-tag=123
		✓ CI Type: pipeline_name (env name: JOB_NAME): job-name
		✓ CI Type: job_name (env name: STAGE_NAME): stage-name
		✓ CI Type: git_path (env name: WORKSPACE): /home/user/project
		✓ CI Type: source_branch (env name: GIT_BRANCH): my_git_branch
	✓ Redefine Auth: Successfully generated authentication token
	✓ Server Access: Successfully connected to redefine server
➤ Python Verifications:
	✓ Python Version: 3.10.6
	✓ Pytest Version: 7.0.1
	✓ Python Packages: Found 349 packages installed
	i Python Packages:
		~ Python Packages: Package `pytest-6` is not officially supported
		~ Python Packages: Package `pytest-durations` is not officially supported
	i Redefine Requirement:
		i Redefine Requirements: Redefine pytest plugin will install coralogix-logger version: <3.0.0,>=2.0.5
	~ Coralogix Requirements: Found the python package `coralogix-logger` is installed,if you encounter any issues, make sure to set `redefine config set pytest_coralogix_disabled=true`
➤ Git Verifications:
	✓ Git: Git: Successfully found git
	✓ Git Repository: /home/user/project
	✓ Git Remote: Single remote found - origin
	✓ Git Stable Branch: Stable Branch: main
	✓ Git: Environment git verification passed for git repo: /home/user/project
```

{% endtab %}

{% tab title="Pytest Version Issue " %}

```bash
==================================================
                Redefine Verifier                 
==================================================
➤ Environment Verifications:
	✓ OS: linux
	i CI Platform: JENKINS
		✓ CI Type: ci_run_id (env name: BUILD_TAG): build-tag=123
		✓ CI Type: pipeline_name (env name: JOB_NAME): job-name
		✓ CI Type: job_name (env name: STAGE_NAME): stage-name
		✓ CI Type: git_path (env name: WORKSPACE): /home/user/project
		✓ CI Type: source_branch (env name: GIT_BRANCH): my_git_branch
	✓ Redefine Auth: Successfully generated authentication token
	✓ Server Access: Successfully connected to redefine server
➤ Python Verifications:
	✓ Python Version: 3.10.6
	✗ Pytest Version: Pytest is not installed or cannot be imported. The supported versions are 5.4.0 or higher.
	! Pytest Version: Stopping after failure of check Pytest Version, next checks will not be executed not all checks were executed
➤ Git Verifications:
	✓ Git: Git: Successfully found git
	✓ Git Repository: /home/user/project
	✓ Git Remote: Single remote found - origin
	✓ Git Stable Branch: Stable Branch: main
	✓ Git: Environment git verification passed for git repo: /home/user/project
```

{% endtab %}

{% tab title="Missing Stable Branch" %}

```bash
==================================================
                Redefine Verifier                 
==================================================
➤ Environment Verifications:
	✓ OS: linux
	i CI Platform: JENKINS
		✓ CI Type: ci_run_id (env name: BUILD_TAG): build-tag=123
		✓ CI Type: pipeline_name (env name: JOB_NAME): job-name
		✓ CI Type: job_name (env name: STAGE_NAME): stage-name
		✓ CI Type: git_path (env name: WORKSPACE): /home/user/project
		✓ CI Type: source_branch (env name: GIT_BRANCH): my_git_branch
	✓ Redefine Auth: Successfully generated authentication token
	✓ Server Access: Successfully connected to redefine server
➤ Python Verifications:
	✓ Python Version: 3.10.6
	✓ Pytest Version: 7.0.1
	✓ Python Packages: Found 349 packages installed
	i Python Packages:
		~ Python Packages: Package `pytest-6` is not officially supported
		~ Python Packages: Package `pytest-durations` is not officially supported
	i Redefine Requirement:
		i Redefine Requirements: Redefine pytest plugin will install coralogix-logger version: <3.0.0,>=2.0.5
	~ Coralogix Requirements: Found the python package `coralogix-logger` is installed,if you encounter any issues, make sure to set `redefine config set pytest_coralogix_disabled=true`
➤ Git Verifications:
	✓ Git: Git: Successfully found git
	✓ Git Repository: /home/user/project
	✓ Git Remote: Single remote found - origin
	✗ Git Stable Branch: No stable branches specified in config - Set the stable branch by running `redefine config set stable_branch=<branch_name>`
	! Git Stable Branch: Stopping after failure of check Git Stable Branch, next checks will not be executed not all checks were executed

```

{% endtab %}

{% tab title="Missing REDEFINE\_AUTH - Cypress" %}

```
==================================================
                Redefine Verifier                 
==================================================
➤ Environment Verifications:
	✓ OS: linux
	i CI Platform: JENKINS
		✓ CI Type: ci_run_id (env name: BUILD_TAG): build-tag=123
		✓ CI Type: pipeline_name (env name: JOB_NAME): job-name
		✓ CI Type: job_name (env name: STAGE_NAME): stage-name
		✓ CI Type: git_path (env name: WORKSPACE): /home/user/project
		✓ CI Type: source_branch (env name: GIT_BRANCH): my_git_branch
	✗ Redefine Auth: REDEFINE_AUTH environment variable not set - Make sure to export it correctly - Make sure to set it with the API_KEY you were provided by Redefine.dev If you haven't, please contact us at support@redefine.dev
        ✗ Server Access: Unable to connect to redefine server - Make sure you have access to redefine.dev and its sub-domains, and outgoing rule for port 50500
➤ Git Verifications:
	✓ Git: Git: Successfully found git
	✓ Git Repository: /home/user/project
	✓ Git Remote: Single remote found - origin
	✓ Git Stable Branch: Stable Branch: main
	✓ Git: Environment git verification passed for git repo: /home/user/project
➤ Node Verifications:
        ✓ Node Version: 20.1.0
        ✓ Npm Version: 9.6.4
        ✓ Npx Version: 9.6.4
        ✓ Cypress Version: 12.12.0
               i Cypress Packages:
                       ✓ Cypress plugins: All discovered cypress plugins are supported.
```

{% endtab %}
{% endtabs %}


# How Does It Work? 🔬

Redefine uses a machine learning model to prioritize tests, a process grounded in the innovative research of Predictive Test Selection. For further details on Predictive Test Selection, please see the [case study by Meta](https://engineering.fb.com/2018/11/21/developer-tools/predictive-test-selection/).

**Redefine's model is trained daily on more than 100 unique features (attributes)**, such as the specific **code changes**, the **author of the changes**, and their **relationship to each test**.\ <br>

<figure><img src="https://47263957-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuwbuslmLp28ROGViWkou%2Fuploads%2FpRsz4pnlTSkaROkJEILn%2Fimage.png?alt=media&amp;token=9fdd820d-42bb-41ce-ba9d-4fecf4b22eb0" alt=""><figcaption><p>Bipartite graph illustrating file-test correlations</p></figcaption></figure>

### Decision Rules

Beyond its model, Redefine's decision engine also implements a set of rules to ensure an optimal developer experience, irrespective of the decisions made by the model.

#### Rerun Failed Tests Rule&#x20;

To ensure an optimal debugging process of failed tests, any tests that failed on a specific git branch will be automatically included in the subsequent build. This approach is implemented to prioritize the best possible developer experience.

#### Skip Failures from the Main Branch Rule

To prevent feature branches from being blocked by failed tests that accidentally made their way into the main branch, Redefine will automatically ignore these tests until they pass. This is done by considering the starting point (base commit) of the feature branch. It's important to note that different failed tests may be considered based on whether the base commit is older or newer. By adapting in this way, Redefine ensures a smoother testing process and prevents feature branches from being blocked.

This is enabled by default in [Optimize](/configuration/selection-modes/optimize) mode, while in [Prioritize](/configuration/selection-modes/prioritize) and [Fail-Fast](/configuration/selection-modes/fail-fast) this rule is disabled by default. To change the default setting use the [skip\_known\_failures ](/configuration/configuration-parameters#skip_known_failures)configuration.

#### Skip Flaky Test Rule

To improve your developer experience and reduce flakiness in your CI, you can manually set up a rule to handle flaky tests. By using the [flaky\_filter\_threshold](/configuration/configuration-parameters#flaky_filter_threshold) configuration, you can specify a threshold above which tests that tend to be unreliable will be skipped.

If you want to see how each test is rated for its flakiness, you can visit the [Test Inspection Dashboard](https://app.redefine.dev/test_inspection). There, you can explore your tests and find out their respective flakiness scores.

#### Exploration Rule

Given that the test selection model is trained on historical test outcomes, any new tests will be automatically executed for up to several dozen builds. This exploration process is crucial for our model to gather sufficient information about the test, enabling it to predict its relevance with high accuracy.

{% hint style="warning" %}
**Test or Test-File Renaming/Moving**

When a test is renamed or moved to a different file, it will be treated as a new test. Consequently, Redefine will automatically execute the test without utilizing the test selection model.\
Therefore, it is important to exercise caution when dealing with large refactors. In such cases, it is highly recommended to switch Redefine mode to [Discover](/configuration/selection-modes/discover) before implementing a large-scale refactor that alters test signatures.
{% endhint %}

#### Test File Changed Rule

In case a test file is changed, it will automatically run in the next builds, even if other rules say to skip it. This ensures you can fix any issues with the test. So, even if there is a [#skip-failures-from-the-main-branch-rule](#skip-failures-from-the-main-branch-rule "mention") or a [#skip-flaky-test-rule](#skip-flaky-test-rule "mention"), this one takes priority to make sure tests are fixed and reliable.


# Install Command

The `redefine install` command is used to install the redefine plugin and enable redefine's functionality. It's important to note that the start command should be executed prior to running the tests.

### **Testing Framework**

The testing framework flag is a required field for successful redefine installation. It specifies the testing framework to be used for test execution.

To see the list of supported testing frameworks, refer to the documentation [Supported Technologies](/integrations/supported-technologies)

For example, running the following command would make use of the `pytest` testing framework:

```bash
redefine install --pytest --<selection-mode>
```

### Selection Mode

The selection mode flag is a mandatory parameter for the start command. It specifies the relevant selection mode for the test execution.

The available selection modes are:

[`--optimize`](/configuration/selection-modes/optimize) , [`--discover`](/configuration/selection-modes/discover) , [`--prioritize`](/configuration/selection-modes/prioritize) , [`--fail-fast`](/configuration/selection-modes/fail-fast) , [`--worker`](/configuration/parallel-test-execution#workers)

For instance, executing the following command would employ the `discover` mode:

```bash
redefine install --<testing-framework> --discover
```

### Exit code

The `--exit-code` flag enhances error handling during installations by modifying the behavior of the start command to provide clear feedback in the event of issues.

By default, redefine allows pipelines and tests to continue running even in the presence of installation issues. However, this approach can lead to unintended outcomes, such as running all tests in the orchestrator within a remote-workers architecture or executing tests despite not aligning with the user's preferred timeframe.

To use the `--exit-code` flag, include it in the redefine start command as follows:

```bash
redefine install --<testing-framework> --<selection-mode> --exit-code
```

### Remote workers architecture specific flags

Certain flags are specifically relevant to the remote workers' architecture. These flags provide functionality tailored to this architecture.

To learn more about these flags and their usage, refer to the relevant documentation available at [Parallel Test Execution](/configuration/parallel-test-execution)


# Configuration Parameters

### confidence

The `confidence` configuration setting ensures test reliability by defining the level of confidence required before Redefine can stop the run. By tailoring the confidence level, you can effectively manage the trade-off between test completeness and time efficiency. Selecting a lower confidence level may reduce testing time but could increase risk, whereas a higher level is safer and has a lesser chance of missing a failed test but demands more time. Redefine recommends using the default setting.

**Type:** `enum`

**Options:** `high` / `normal` / `low`

**Default value:** `normal` - This setting offers a balanced approach between test thoroughness and time efficiency.

To set the confidence level, use the following command:

```bash
redefine config set confidence=<confidence_level>
```

### min\_accuracy

The `min_accuracy` configuration acts as a safety measure against drops in accuracy. It ensures continuous test execution until the desired accuracy is achieved. This helps prevent scenarios of extended test duration or sudden infrastructure changes causing inadequate test coverage.

**Type:** `float` the range is \[0, 1]

**Default value:** `0` meaning do not use `min_accuracy`

To set the minimum accuracy, use the following command:

```bash
redefine config set min_accuracy=<min_accuracy>
```

### time\_limit

The time limit represents the maximum clock time for an optimized run, measured in seconds. It defines the overall duration of the testing phase from start to end. For example, to set a time limit of exactly 5 minutes, configure the value as 300 seconds.

Unlike the time budget, the time limit refers to the precise start-to-end time. If a run is expected to take 5 minutes with 3 parallel processes, the configured time limit should still be 300 seconds.

**Type:** `float`&#x20;

**Default value:** `0`

To set the time limit, use the following command:

```bash
redefine config set time_limit=<time_limit_in_seconds>
```

### **flaky\_filter\_threshold**

The `flaky_filter_threshold` config is used to skip tests with a high flake rate, which is defined as the percentage of test runs in the last 30 days that were flaky. To skip tests based on flakiness, set the value of the`flaky_filter_threshold` to a number between 0.01 and 1, representing the maximum allowable flake rate as a percentage. For example, setting it to 0.15 would skip tests with a flake rate of 15% or higher.

**Type:** `float` the range is \[0, 1]

**Default value:** `1.0` meaning don't skip any tests

To set the value of the `flaky_filter_threshold`, run the following command:

```bash
redefine config set flaky_filter_threshold=<threshold_value>
```

### report\_tests\_metadata

This config determines whether Redefine should send non-anonymized test metadata to the server. The test metadata includes information such as test and file names, and its purpose is to provide insights into the Test Inspection Dashboard. If this config is set to false, the test metadata will be anonymized and will not be sent to the server.

Note that this metadata is sent only for the tests and not for the code.

**Default value:** `true` (Tests metadata will be sent to Redefine's server for analysis).

To set the value of this config, use the following command:

```bash
redefine config set report_tests_metadata=<true/false>
```

### slack\_bot\_enabled&#x20;

To enable AI Slack Notifications, you should configure Redefine's Slack integration to send the messages from the CI.&#x20;

**Type:** `boolean`

**Default value:** `false`

Run the following command before starting Redefine in your CI workflow:

```bash
redefine config set slack_bot_enabled=true
```

### disable\_openai

To disable the OpenAI integration within the AI Slack Notifications, you may configure the Slack bot to now share information with OpenAI.&#x20;

**Type:** `boolean`

**Default value:** `false`

Run the following command before starting Redefine in your CI workflow:

```bash
redefine config set disable_openai=true
```

### file\_based\_prediction

To ensure the test execution order within each test file remains consistent, configure redefine to predict according to it.

**Type:** `boolean`

**Default value:** `false`

Run the following command before starting Redefine in your CI workflow:

```bash
redefine config set file_based_prediction=true
```

### skip\_known\_failures

To reduce developer friction and prevent all changes from being blocked until the failed tests are fixed, we should skip tests that have already failed on the main branch. This approach will streamline the development process and allow continuous progress even while addressing the failed tests.

**Type:** `boolean`

**Default value:** `true` for **Optimize Mode**&#x20;

**Default value:** `false` for **Fail-Fast Mode**&#x20;

**Default value:** `false` for **Prioritize Mode**&#x20;

To set the value of this config, use the following command:

```bash
redefine config set skip_known_failures=true
```

### auto\_uninstall

By default, Redefine automatically uninstalls after the first test executions to avoid impact for unrelated test executions. However, in certain scenarios, it may be necessary to keep the installation continuous for multiple consecutive test executions to ensure a valid Redefine installation. In such cases, it is recommended to modify the default behavior and set the `auto_uninstall` value to false.

**Type:** `boolean`

**default value:** `true`

```bash
redefine config set auto_uninstall=false
```

### run\_tests\_on\_file\_change

This configuration controls whether Redefine automatically executes tests within a changed test file. By default, this configuration is enabled (true) to ensure running tests after changing them.

**Type:** boolean

**Default value:** true\
\
To set the value of this config, use the following command:

```bash
redefine config set run_tests_on_file_change=false
```

### stable\_branch

The stable branch is the name of the main working branch in the repository. For example, you can use `main` as the stable branch name.

**Type:** `string`

To set the stable branch, run the following command:

```bash
redefine config set stable_branch=<stable_branch_name>
```


# Parallel Test Execution

Parallel test execution is a widely adopted strategy designed to speed up the execution of large test suites that otherwise would require considerable time to execute.

When running tests in parallel, organizations will spin up multiple CI machines, distribute the tests across these instances and run the tests using the testing framework of choice.

For example, consider the following code running pytest in parallel on 8 machines in GitHub Actions using the `pytest-split` plugin:

```yaml
name: Redefine

on:
  pull_request:
    branches: [ "main" ]

jobs:
  worker:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        # Running 8 workers
        index: [1,1,1,1,1,1,1,1]
    steps:
      - uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: 3.11

      - name: Install dependencies
        run: pip install -r requirements.txt

      - name: Run pytest
        run: pytest --splits ${{ strategy.job-total }} --group ${{ strategy.job-index }} -n auto tests/
```

Running tests in parallel means organizations can cut their testing time, but it also means running additional machines which increases the CI costs significantly.

## Redefine

Redefine enhances parallel test execution efficiency, yielding not only time savings for developers but also substantial reductions in CI-related costs. There are multiple supported parallel testing modes:

* [Redefine Parallel](/configuration/parallel-test-execution/redefine-parallel) - Optimal test distribution among parallel workers, delivered by Redefine.
* [Remote Workers](/configuration/parallel-test-execution/remote-workers) - an Orchestrator + Remote workers architecture, where the Orchestrator runs the prediction first, and the user distributes the tests to the testing machines.


# Redefine Parallel

Redefine Parallel is Redefine's method of optimizing test distribution across multiple machines. It allows you to run tests as though they are being executed on a single machine while Redefine manages the distribution.

This approach utilizes test duration and failure probability to ensure that the most relevant tests are always running in parallel.

## Install

Follow the instructions in the [Quick Start ⏱️](/welcome-to-redefine/quick-start)guide to install Redefine.

## Configure

### Configure a shared session ID

To use Redefine Parallel, it is important to configure a shared session ID between all testing machines. This allows Redefine to connect the prediction and the execution of the tests.

Follow these steps to configure the shared Session ID:

1. It is crucial to generate the session ID once and provide it to all testing machines, to avoid misalignment. &#x20;
2. You can use the CLI command `redefine get session_id` to generate the session ID, which represents the current session.
3. Export the environment variable REDEFINE\_SESSION\_ID with the same value on all test-runners.

## Verify

Make sure that the verify command ends with success on all testing machines -

```bash
redefine verify --<testing-framework>
```

Follow the [Quick Start ⏱️](/welcome-to-redefine/quick-start#verify) guide for instructions and troubleshooting.

## Run

When executing the `redefine install` command, you need to pass the number of machines and the index of each machine to the Redefine command in the following format:

{% tabs %}
{% tab title="Pytest" %}

```bash
redefine install --pytest --<selection_mode> --splits <number of machines> --group <machine index>
pytest -n auto tests/
```

{% endtab %}

{% tab title="Cypress" %}

```bash
redefine install --cypress --<selection_mode> --splits <number of machines> --group <machine index>
npx run cypress
```

{% endtab %}

{% tab title="Mocha" %}

```bash
redefine install --mocha --<selection_mode> --splits <number of machines> --group <machine index>
npm run test
```

{% endtab %}
{% endtabs %}


# Remote Workers

The Remote Workers Configuration is a parallelism technique in Continuous Integration (CI) testing environment, where testing operations are not performed on the main **orchestrator**, but are delegated across various worker nodes. These worker nodes act as remote workers, enabling the simultaneous execution of multiple tests, thereby reducing feedback time.

In this configuration, the **orchestrator** (main node) is responsible for distributing tests among the **worker nodes**. Each worker node independently executes the assigned tests, ensuring quicker CI test execution.

## Install

Follow the instructions in the [Quick Start ⏱️](/welcome-to-redefine/quick-start)guide to install Redefine.

## Configure

### Basic Configurations

Configure the relevant configurations on the orchestrator following the instructions in the quick start guide. Note that configuration changes on worker nodes are not required for this process.

### Configure a shared session ID

To use Redefine with the remote worker architecture, it is important to configure a shared session ID between the orchestrator and the worker nodes. This allows Redefine to connect the prediction and the execution of the tests.

Follow these steps to configure the shared Session ID:

1. It is crucial to generate the session ID once and provide it to both the orchestrator and worker nodes, to avoid misalignment between the orchestrator and the workers. &#x20;
2. You can use the CLI command `redefine get session_id` to generate the session ID, which represents the current session.
3. Export the environment variable REDEFINE\_SESSION\_ID with the same value on both the orchestrator and each worker node.<br>

```bash
export REDEFINE_SESSION_ID=$(redefine get session_id)
```

## Verify

Make sure that the verify command ends with success both for the orchestrator and the worker nodes, that will help ensure that the CI environment is valid for installation.&#x20;

{% tabs %}
{% tab title="Orchestrator" %}

```bash
redefine verify --<testing-framework>
```

{% endtab %}

{% tab title="Worker" %}

```bash
redefine verify --<testing-framework> --worker
```

{% endtab %}
{% endtabs %}

Follow the [Quick Start ⏱️](/welcome-to-redefine/quick-start#verify) guide for instructions and troubleshooting.

## Run

### Orchestrator

Execute the redefine predict command to receive an ordered list of tests, which would be saved to a file in the desired path without actually running the tests. Once you have the list, you should distribute the tests in the existing logic, ensuring you follow the specified order.

{% tabs %}
{% tab title="Pytest" %}

```bash
redefine predict --pytest --<selection_mode> --output-path="/file/path" --command="pytest tests"
export OPTIMAL_TESTS_LIST=$(cat /file/path)

# Use OPTIMAL_TESTS_LIST in your existing test distribution logic
# All specs will be ordered by priority in <output_path>,
# separated with a new-line ('\n').
```

{% endtab %}

{% tab title="Cypress" %}

```bash
redefine predict --cypress --<selection_mode> --output-path="/file/path" --command="cypress run"
export OPTIMAL_TESTS_LIST=$(cat /file/path)

# Use OPTIMAL_TESTS_LIST in your existing test distribution logic
# All specs will be ordered by priority in <output_path>,
# separated with a new-line ('\n').
```

{% endtab %}

{% tab title="Mocha" %}

```bash
redefine predict --mocha --<selection_mode> --output-path="/file/path" --command="npx mocha"
export OPTIMAL_TESTS_LIST=$(cat /file/path)

# Use OPTIMAL_TESTS_LIST in your existing test distribution logic
# All specs will be ordered by priority in <output_path>,
# separated with a new-line ('\n').
```

{% endtab %}
{% endtabs %}

### Workers

Run the `redefine install` command to run redefine using `--worker` as the selection mode.\
\
Following this, you can execute the specified tests that have been assigned to the worker.

{% tabs %}
{% tab title="Pytest" %}

```bash
redefine install --pytest --worker

# Run the tests assigned to the current worker 
# based on the existing tests distribution logic
```

{% endtab %}

{% tab title="Cypress" %}

```bash
redefine install --cypress --worker

# Run the tests assigned to the current worker 
# based on the existing tests distribution logic
```

{% endtab %}

{% tab title="Mocha" %}

```bash
redefine install --mocha --worker

# Run the tests assigned to the current worker 
# based on the existing tests distribution logic
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}

#### **Maintain the test execution order**

After the orchestrator completes, an optimized test execution order is provided. This test execution order is a crucial part of our orchestrator's function. The orchestrator creates an optimized list that maps out how the tests should be run for the most efficient workflow. Change this order, and you could see a significant drop in efficiency and potential miss of important tests.\
\
Keep in mind, modifying the test order does more than just reduce efficiency — it could also compromise the accuracy of our test predictions. Therefore, it's essential to adhere to the initial order.
{% endhint %}

### Session check command

In Redefine, tests will only be executed until the [Broken mention](broken://pages/ukeQo52y77NM3cuhDJos) is reached. Any remaining tests will be automatically skipped. However, it's important to be aware that the setup and teardown processes may impose a significant overhead.

To mitigate this overhead, it is highly recommended to periodically check if the test execution exceeds the time limit. If the time limit is exceeded, no more tests should be executed.

To determine if the time limit is exceeded, use the following command:

{% tabs %}
{% tab title="Pytest" %}

```bash
# Make sure REDEFINE_SESSION_ID is available
if redefine get session_check; then
    redefine install --pytest --worker
    # Run the tests assigned to the current worker 
fi
```

{% endtab %}

{% tab title="Cypress" %}

```bash
# Make sure REDEFINE_SESSION_ID is available
if redefine get session_check; then
    redefine install --cypress --worker
    # Run the tests assigned to the current worker 
fi
```

{% endtab %}

{% tab title="Mocha" %}

```bash
# Make sure REDEFINE_SESSION_ID is available
if redefine get session_check; then
    redefine install --mocha --worker
    # Run the tests assigned to the current worker 
fi
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
This is especially important when iterating over a large list of tests, as the overhead may increase dramatically.
{% endhint %}

## Example

The example below shows a complete run with `pytest` running in [Optimize](/configuration/selection-modes/optimize) mode.

{% tabs %}
{% tab title="Orchestrator" %}

```bash
export REDEFINE_SESSION_ID=<new_session_id>
redefine config set time_limit=300
redefine predict --pytest --optimize --output-path="/file/path" --command="pytest tests"
export OPTIMAL_TESTS_LIST=$(cat /file/path)

# Use OPTIMAL_TESTS_LIST in your existing tests distribution logic
```

{% endtab %}

{% tab title="Worker" %}

```bash
export REDEFINE_SESSION_ID=<new_session_id>
redefine install --pytest --worker

# Run the tests assigned to the current worker 
# based on the existing tests distribution logic
```

{% endtab %}
{% endtabs %}


# Delayed Workers and Reruns

The startup time of CI machines may experience delays due to the unavailability of machines or infrastructure issues. The worker that has been delayed will have a considerably shorter effective [Broken mention](broken://pages/ukeQo52y77NM3cuhDJos) compared to other workers. Consequently, there is a risk of important tests being missed.

Repeating the execution of a single worker can yield similar results.

### Worker Identifier

To address the issue of delays and potential missed tests due to CI machine unavailability or infrastructure issues, you can utilize the `worker_id` optional parameter.

To implement this solution, use the following command:

{% tabs %}
{% tab title="Pytest" %}

```bash
redefine install --pytest --worker --worker-id=$WORKER_ID
```

{% endtab %}

{% tab title="Cypress" %}

```bash
redefine install --cypress --worker --worker-id=$WORKER_ID
```

{% endtab %}

{% tab title="Mocha" %}

```bash
redefine install --mocha --worker --worker-id=$WORKER_ID
```

{% endtab %}
{% endtabs %}

Ensure that the `WORKER_ID` environment variable contains the worker identifier specific to your CI system.

#### Handling worker rerun

it's important to note that if you have repeated executions of a single worker without re-running the orchestrator, the effective time limit for each subsequent execution may be reduced to zero. To prevent this, you can include the rerun attempt as part of the `worker_id`.&#x20;

Here's an example:

{% tabs %}
{% tab title="Pytest" %}

```bash
redefine install --pytest --worker --worker-id="${WORKER_ID}_${ATTEMPT}"
```

{% endtab %}

{% tab title="Cypress" %}

```bash
redefine install --cypress --worker --worker-id="${WORKER_ID}_${ATTEMPT}"
```

{% endtab %}

{% tab title="Mocha" %}

```bash
redefine install --mocha --worker --worker-id="${WORKER_ID}_${ATTEMPT}"
```

{% endtab %}
{% endtabs %}

In this case, make sure to set the `ATTEMPT` environment variable to the rerun attempt counter. This approach guarantees that each attempt is assigned a unique identifier, avoiding a zero effective time limit for repeated executions.

By implementing these strategies, you can mitigate delays, manage worker execution, and minimize the risk of missing important tests in your CI workflow.


# Selection Modes

Redefine offers four selection modes to optimize testing:

1. [Discover](/configuration/selection-modes/discover) mode collects data for improved predictions.
2. [Optimize](/configuration/selection-modes/optimize) mode runs relevant tests within a time budget.
3. [Fail-Fast](/configuration/selection-modes/fail-fast) mode stops CI runs if tests fail within the budget, or runs all tests if they pass.
4. [Prioritize](/configuration/selection-modes/prioritize) mode reorders tests for faster feedback, especially when integrated with Redefine Slack or a first-fail testing framework.

{% hint style="info" %}
To enhance your developer experience, we strongly recommend the use of [AI Slack Notifications](/integrations/ai-slack-notifications).
{% endhint %}


# Discover

In Discover mode, Redefine focuses on collecting data about your coding patterns and test results without altering test execution. This data is then used to enhance the accuracy of predictions in the machine learning model.

```bash
redefine install --discover --<testing_framework>
```


# Optimize

In Optimize mode, Redefine optimizes your CI builds by selectively running tests that are related to code changes. This results in much quicker feedback from your CI processes and significantly better resource utilization. You can configure the desired [Configuration Parameters](/configuration/configuration-parameters#confidence) for the run; if it is not configured, Redefine will use the default confidence level.

```bash
redefine install --optimize --<testing_framework>
```

{% hint style="warning" %}

#### **Optimize mode requires feedback**

In order to use the Redefine Optimize mode, the tests need to receive feedback from a Discover mode run at least once a day. This is because Optimize mode relies on the feedback collected by the Discover mode to validate its predictions. Without regular feedback from Discover mode, Optimize mode may not perform optimally, which could result in inaccurate predictions.
{% endhint %}


# Fail-Fast

In Fail-Fast mode, Redefine optimizes your CI builds by selectively running tests related to the code changes, similar to Optimize mode. These tests are executed until the specified [Configuration Parameters](/configuration/configuration-parameters#confidence) is reached. If the confidence level is not configured, Redefine will use the default level. If none of these tests fail within the given confidence level, the CI build proceeds to run the entire test suite to ensure full coverage. However, if any of the tests fail before reaching the confidence level, the build is halted immediately, providing early feedback on the introduced code changes.

\
This approach is suitable for those who cannot overlook even the slightest chance of missing a failed test. This leads to quicker feedback time on test failures with better resource utilization on failed CI builds. However, compared to Optimize Mode, resource utilization may not be as optimal.

```bash
redefine install --fail-fast --<testing_framework>
```


# Prioritize

In Prioritize mode, Redefine reorders the tests based on their relevance, enabling faster feedback when used in conjunction with the [AI Slack Notifications](/integrations/ai-slack-notifications). This prioritization ensures that critical or high-priority tests are executed earlier in the testing process, which results in quicker feedback time for developers.

```bash
redefine install --prioritize --<testing_framework>
```


# CI Platforms

Redefine Supports the following CI Platforms:

<table data-view="cards"><thead><tr><th></th><th></th></tr></thead><tbody><tr><td>GitHub Actions</td><td>✅</td></tr><tr><td>Jenkins</td><td>✅</td></tr><tr><td>CircleCI</td><td>✅</td></tr><tr><td>TeamCity</td><td>✅</td></tr><tr><td>GitLab CI</td><td>✅</td></tr><tr><td>Buildkite</td><td>✅</td></tr></tbody></table>

Please make sure the following environment variables are available when running Redefine in your CI -

{% tabs %}
{% tab title="Github Actions" %}

* `GITHUB_RUN_ID`
* `GITHUB_RUN_ATTEMPT`
* `GITHUB_WORKFLOW`
* `GITHUB_JOB`
* `GITHUB_WORKSPACE`
* `GITHUB_REF_NAME`
* `GITHUB_HEAD_REF`
* `GITHUB_EVENT_PATH`
* `GITHUB_EVENT_NAME`
* `GITHUB_REPOSITORY`
* `GITHUB_SERVER_URL`
  {% endtab %}

{% tab title="Jenkins" %}

* `WORKSPACE`
* `BUILD_TAG`
* `JOB_NAME`
* `STAGE_NAME`
* `GIT_BRANCH`
* `GIT_COMMIT`
* `GIT_URL`
  {% endtab %}

{% tab title="CircleCI" %}

* `CIRCLE_WORKING_DIRECTORY`
* `CIRCLE_WORKFLOW_ID`
* `CIRCLE_JOB`
* `CIRCLE_BRANCH`
* `CIRCLE_SHA1`
* `CIRCLE_REPOSITORY_URL`
  {% endtab %}

{% tab title="TeamCity" %}

<pre class="language-bash"><code class="lang-bash">export REDEFINE_AUTH=%secure:REDEFINE_AUTH_KEY%
<strong>export TEAMCITY_GIT_PATH=%teamcity.build.checkoutDir%
</strong>export TEAMCITY_HEAD_COMMIT_HASH=%build.vcs.number%
export TEAMCITY_PIPELINE_NAME=%teamcity.project.id%
export TEAMCITY_JOB_NAME=%system.teamcity.buildConfName%
export TEAMCITY_GIT_ACTION=%teamcity.pullRequest.branch.pullrequests%
export TEAMCITY_SOURCE_BRANCH=%teamcity.pullRequest.source.branch%
export TEAMCITY_TARGET_BRANCH=%teamcity.pullRequest.target.branch%
</code></pre>

{% endtab %}

{% tab title="GitLab CI" %}

* `CI_PROJECT_DIR`
* `CI_PIPELINE_ID`
* `CI_JOB_NAME`
* `CI_JOB_STAGE`
* `CI_COMMIT_REF_NAME`
* `CI_COMMIT_SHA`
* `CI_REPOSITORY_URL`
  {% endtab %}

{% tab title="Buildkite" %}

* `BUILDKITE_BUILD_CHECKOUT_PATH`
* `BUILDKITE_BUILD_ID`
* `BUILDKITE_PIPELINE_NAME`
* `BUILDKITE_LABEL`
* `BUILDKITE_BRANCH`
* `BUILDKITE_COMMIT`
* `BUILDKITE_BUILD_URL`
* `BUILDKITE_JOB_ID`
* `BUILDKITE_REPO`
* `BUILDKITE_RETRY_COUNT`
  {% endtab %}
  {% endtabs %}


# Redefine Flow

Redefine Flow presents the valid runs that are expected to be executed within Redefine. Each flow is associated with a distinct test suite and contains rules that define what constitutes valid runs in that specific flow.

## Why is Redefine Flow configuration required?

Redefine learns from the history of runs over time. It is crucial to ensure that the data from which Redefine learns contains only relevant runs. Customers might install Redefine in a few unexpected places, or there could be changes in the CI over time that affect Redefine's learning process. It is therefore essential that the Redefine model learns only from relevant data to yield the best results.

The flows are differentiated by test suites to provide flow-specific predictions and to allow monitoring of performance by flow in the dashboard.

## How to update the flow configuration?

New customers will configure their flows during the onboarding process. Existing customers can view and update their flow configuration on the [settings page](https://app.redefine.dev/onboarding/learning#settings/flows-control).

## Flow Properties

Each flow is defined by a unique name and includes one or more rules. Each rule represents a specific type of run. In scenarios where multiple rules are employed, one rule may pertain to the optimized run (for example, the optimized pull request run), while another may be associated with the corresponding feedback run (such as the passive discover run).

The properties of each rule within a flow include:

1. **Mode:** This property indicates the selection mode employed within the flow. To view the flow's selection mode, use the Redefine installation command: `redefine install --<selection mode>`
2. **Run Type:** This property allows you to determine whether the rule applies to runs that are either pull requests or post-merge commits. Usually, runs optimized by Redefine are pull request runs, while learning runs are based on post-merge commits.
3. **Pipeline:** This property designates the pipeline name associated with the valid runs within the flow, ensuring precise run association.
4. **Job:** This property defines the job name(s) relevant to the valid runs within the flow. If there are multiple valid job names, a multi-select feature can be used, or you can select "all current and future jobs" for comprehensive inclusion.

## Examples

Let's suppose a company has two components: a web app with E2E tests and an API. Here's how its flows would be configured:

1. **If the company uses Redefine in Optimize mode:**

   <figure><img src="https://47263957-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuwbuslmLp28ROGViWkou%2Fuploads%2FxkHx68x1sSuZ2fILp7i3%2FFlow-optimize%20example.png?alt=media&amp;token=fe07d816-66f7-4f5a-8274-5f9bf7f5dfac" alt=""><figcaption></figcaption></figure>

   Each flow has an optimize rule and a discover rule for post-merge learning (Feedback).
2. **If the company is planning to install in Optimize mode but is still in the learning phase:**

   <figure><img src="https://47263957-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuwbuslmLp28ROGViWkou%2Fuploads%2FMJ076rdG8s5jIqEtCzdY%2FFlow-learning%20example.png?alt=media&amp;token=72199cb8-7731-41de-837a-7aaebbcf52bb" alt=""><figcaption></figcaption></figure>

   Each flow has two rules in discover mode since Redefine is still gathering data in discover mode. At the end of the learning phase, the pull request's selection mode will be switched to Optimize.
3. **If the company uses Redefine in Fail-Fast mode:**<br>

   <figure><img src="https://47263957-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuwbuslmLp28ROGViWkou%2Fuploads%2Ft74z27l7FQl6iPomZr3V%2FFlow-fail%20fast%20example.png?alt=media&amp;token=03fa3c3c-9edc-48f2-89bc-d4a252c1db25" alt=""><figcaption></figcaption></figure>

   In this case, Redefine is configured in Fail-Fast mode and, as such, does not require a feedback phase for installation.


# Verify Troubleshooting

The Verify command may return one or more error messages, indicating an issue with the CI environment running redefine. Here you can find detailed explanations and suggested remedies.

Examples -

* **Missing Authentication Key** - See [Redefine Key Missing](https://docs.redefine.dev/troubleshooting/verify-troubleshooting/environment-troubleshooting#redefine-key-missing)&#x20;
* **CI Platform not detected** - See [CI Platform not Detected](https://docs.redefine.dev/troubleshooting/verify-troubleshooting/environment-troubleshooting#ci-platform-not-detected)
* **Current directory is not a git repository** - See [Can't Find Git Repository](https://docs.redefine.dev/troubleshooting/verify-troubleshooting/git-troubleshooting#cant-find-git-repository)
* **Branch {branch} is missing, failed fetch** - See [Can't Fetch Branch](https://docs.redefine.dev/troubleshooting/verify-troubleshooting/git-troubleshooting#cant-fetch-branch)
* **Testing Framework is not installed or cannot be imported** - See [Cypress](https://docs.redefine.dev/troubleshooting/verify-troubleshooting/testing-frameworks/cypress-troubleshooting#cypress-is-not-installed-or-cannot-be-imported.) & [Pytest](https://docs.redefine.dev/troubleshooting/verify-troubleshooting/testing-frameworks/pytest-troubleshooting#python-installation-problem)
* **Failed to send report to Redefine's server** - See [Unable to connet to Redefine Server](https://docs.redefine.dev/troubleshooting/verify-troubleshooting/environment-troubleshooting#unable-to-connet-to-redefine-server)

For more go to any of the sub-pages.


# Environment Troubleshooting

## Environment Requirements

#### Incompatible Operating System

> *Incompatible operating system, the current OS is: {SYS\_PLATFORM}, the required OS are: macOS, Linux or Windows.*

Redefine does not support the machine's operating system.\
You can find the list of supported OS here: [Supported Technologies](/integrations/supported-technologies#supported-operating-systems)

#### Package Version Unsupported

> *Package `{name}` version is {version} - the minimal supported version is {supported\_version}*

Redefine supports the package indicated in the above message only from the minimum written version. If it is possible, please upgrade the version to {} and above. Otherwise, please contact Redefine customer support.

#### CI Platform not Detected

> CI Platform not detected! The supported CI platforms are: \[...]

Redefine could not detect your CI platform. This could mean one of the following -

* Redefine was executed outside of a CI Platform - this is not currently supported
* Redefine did not have access to the CI Environment variables, see further details and solution in [#ci-environment-variables-missing](#ci-environment-variables-missing "mention")
* Redefine was executed in an unsupported CI Platform. Check [Supported Technologies](/integrations/supported-technologies) for detailed list of supported CI Platforms.

If this is not one of the cases above, please contact us at <support@redefine.dev>

#### CI Environment Variables Missing

> *CI platform-specific environment variables are missing - Make sure to you are running Redefine in your CI platform and it has access to the CI's environment variables*

Redefine relies on environment variables delivered from the CI platform. Depending on your CI architecture, this may not be automatically available, for example -

* Running docker container in your CI - you will have to pass the environment variables from your CI platform to your docker image - see
* Running redefine in a process with clean environment variables - make sure to pass the parent's environment variables to the process running redefine"

Please make sure your CI is supported [Supported Technologies](/integrations/supported-technologies)

#### Package is not Officially Supported

> *Package {plugin} is not officially supported*

Currently, the package is not officially supported or tested in Redefine. It is not expected to cause issues, but we recommend being aware of it and contacting us at <support@redefine.dev> in case of any problem.

#### Stable Branch Not Configured

> *Stable branch is not configured, can't verify git - Make sure to configure stable branch using `Redefine config set stable_branch=<your_branch>`*

You did not configure your Redefine stable branch, please make sure to configure it by running `Redefine config set stable_branch=<your_stable_branch>`\
For more information see [Broken mention](broken://pages/sI3tiZbByHpV9KnDjxNi#set-stable-branch)

#### Can't Detect Branch From CI

> *Can't detect branch from CI environment variables, cannot verify git!*

Redefine relies on environment variables delivered from the CI platform. Depending on your CI architecture, this may not be automatically available, for example -

* Running docker container in your CI - You will have to propagate the environment variables from your CI platform to your docker image - See [docker run with env](https://docs.docker.com/engine/reference/commandline/run/#env).
* Running redefine in a process with clean environment variables - Make sure to pass the parent's environment variables to the process running redefine

Please make sure your CI is supported [Supported Technologies](/integrations/supported-technologies)

#### Missing CI Parameter

> {param} (env name: {env}): Missing!

A param named {param\_name} is missing and could not be auto-detected. for example: source\_branch, source\_commit, git\_repo, job\_name, pipeline\_name, ci\_run\_id. make sure you are running on a valid CI platform.

## Redefine Authorization

#### Redefine Key Missing

> *REDEFINE\_AUTH environment variable not set - Make sure to export it correctly, Make sure to set it with the API\_KEY you were provided by Redefine.dev If you haven't, please contact us at <support@Redefine.dev>*

Redefine requires a `REDEFINE_AUTH` env to be exported for authentication.

* The required format for the variable is: `<client_id>::<client_secret>`
* for secrets storing best practices see [GitHub Actions](https://docs.github.com/en/actions/security-guides/encrypted-secrets) | [GitLab CI](https://docs.gitlab.com/ee/ci/secrets/) | [Jenkins](https://www.jenkins.io/doc/developer/security/secrets/) | [CircleCI](https://circleci.com/docs/security-recommendations/?utm_source=google\&utm_medium=sem\&utm_campaign=sem-google-dg--emea-en-dsa-tROAS-auth-brand\&utm_term=g_-c__dsa\&utm_content=\&gclid=CjwKCAjwo7iiBhAEEiwAsIxQEa7XGK25SIOM9uF6QmG77SjFOvDx-bFpR12qn1d_aXJ3ZxC2d_l5ThoCcBsQAvD_BwE) | [TeamCity](https://www.jetbrains.com/help/teamcity/security-notes.html#Recommended+Security+Practices)
* If you haven’t received Redefine credentials, contact us at <https://www.redefine.dev/demo>.

#### Authorization Variable Improperly Formatted

> *REDEFINE\_AUTH environment variable is not in the format `client_id::client_secret`*

Redefine requires a `REDEFINE_AUTH` env to be exported with the format: \<client\_id>::\<client\_secret>, please make sure to export it in the correct format, or contact support if you don't know what is your Redefine auth

#### Failed to Authenticate

> *Failed to generate authentication token, please contact Redefine support at `support@Redefine.dev`*

If Redefine fails to authenticate for an unknown reason, contact Redefine support

## Server Connection Issues

#### Unable to connet to Redefine Server

> *Unable to connect to Redefine server - Make sure you have access to Redefine.dev and its sub-domains, and outgoing rule for port 443/50500*

Redefine uses ports 443/50500 to perform gRPC access to the Redefine Cloud. If this access is blocked, Redefine will not be able to operate. Please make sure the access isn't blocked by a firewall or other means.


# Git Troubleshooting

## Git Configuration

#### Can't Find Git Repository

> *Current directory ({current\_directory}) is not a git repository.*

The current directory is not a git repository, please make sure you run the verify command inside your git repository.

#### Commit is Invalid

> *{commit} is not a valid commit*

Please make sure the checked-out commit is a valid commit in your git history

#### Can't Find Commit

> *Can't find commit {commit} - Make sure it exists in the repository*

Please make sure the checked-out commit is a valid commit in your git history

#### Commit is Shallow

> *Commit {commit} is shallow - Make sure the commit's branch has sufficient history*

For Redefine to perform test prediction, it needs to perform git operations that require sufficient git history. If your commit is shallow (depth=1) or doesn't have sufficient depth (<100) redefine will not be able to perform quality test prediction.

To fix the issue, please make sure `git clone` is not shallow. if --depth is used, it has to be >100"

#### Can't Get Commit Depth

> *Can't get depth of commit {commit} - Make sure it exists in the repository*

For Redefine to perform test prediction, it needs to perform git operations that require sufficient git history. If your commit is shallow (depth=1) or doesn't have sufficient depth (<100) redefine will not be able to perform quality test prediction.

To fix the issue, please make sure `git clone` is not shallow. if --depth is used, it has to be >100"

#### Can't Find Remote Branches

> *Can't find remote branches for repository {git\_repo} - Make sure the repository is valid and has remote*

Please make sure your current machine has permission to the remote repository, and you can fetch the remote repository.

#### Can't Fetch Branch

> *Branch {branch} is {missing/shallow}, failed fetch - Make sure the branch has sufficient history*

Please make sure your current machine has sufficient credentials to the remote repository, and you can fetch the remote branch.

To test for sufficient credentials, run `git fetch {remote} {branch}:{branch}` from the CI machine, for example `git fetch origin main:main`&#x20;

#### Stable Branch Missing

> *Stable branch {branch} is missing - Make sure it exists in the repository*

Please make sure your current machine has permission to the remote repository, and you can fetch the configured stable branch

#### Problem Fetching Stable Branch

> *Stable branch {branch} is {missing/shallow}, failed fetch - Make sure the branch has sufficient history*

Please make sure your current machine has permission to the remote repository, and you can fetch the configured stable branch.

#### Stable Branch Depth Problem

> *Can't get depth of stable branch - Make sure it exists in the repository*

Please make sure your current machine has permission to the remote repository, and the configured stable branch exists.

#### No Merge Base Found

> *No merge base found between any {source} and {stable\_branch\_str} - Make sure the branches have a common ancestor*

For Redefine to perform test prediction, it needs to perform git operations based on the changes you've performed in your branch. If no merge base is found between your branch and the stable branch, that could be due to the following:

* Your branch hasn't originated from the stable branch (Ex. Branched out of main when the stable is defined to develop)
* Your branch is too far from the stable branch - Currently, redefine supports a depth range of up to 100. This is usually due to running redefine on a separate long-running branch without adapting the stable branch configuration (i.e, running redefine on dev itself when a stable branch is configured for main)

#### Multiple Stable Branches Defined

> *More than one stable branch specified in config - Please specify only one by running `Redefine config set stable_branch=<branch_name>`"*

Redefine does not support multiple stable branches, please make sure you have only 1 configured stable branch

#### Multiple Remote Origins

> *More than one remote found*

Redefine uses the git remote to verify that it performs git operations on the latest version of a branch. By having more than one git remote, redefine will not be able to determine which remote to work with. Please contact us at <support@redefine.dev> for solutions.

#### Git Remote Name Invalid

> *Git remote name is invalid*

Please make sure your [git remote is valid](https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes).

#### Unable to Find Remote

> *Unable to find remote*

Redefine was unable to find a configured git remote, please make sure you have a valid configured git remote (see <https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes>)


# Testing Frameworks


# Cypress Troubleshooting

## Version Compatibility Issues

### Node version not found

> *No node versions found*

This can be an issue due to one of the following:

* Node is not installed on the machine
* Node is not configured in the path environment variable

### npm/npx not installed

> npm is not installed or cannot be imported / npx is not installed or cannot be imported

npm/npx is not installed, please make sure you have the binary installed in your environment, using a package manager, i.e. by running `sudo apt install npm.`

### Incompatible Cypress Version

> Incompatible cypress version. *The current* Cypress *version is {cypress\_version} - the supported versions are 10.7.0 or higher.*

Redefine supports Cypress version 10.7.0 and above, please make sure to install Cypress with version 10.7.0 or higher.

### Cypress is not installed or cannot be imported

> Cypress is not installed or cannot be imported.

Cypress is not installed, run `npm install cypress --save-dev` to install Cypress.


# Pytest Troubleshooting

## Python Or Pytest Not Supported

#### Python version not found

> *No python versions found.*

Possible explanations for this issue include:&#x20;

* Python is not configured in the path environment variable.
* Redefine was run outside of a virtual environment. If this is the case, make sure to run from the virtual environment shell or use your favorite virtual environment command line tool to run redefine via Python, i.e., `poetry run python -m redefine <cmd>`.
* Python is not installed on the machine.

#### Python Version Problem

> *All python versions found {versions} are not supported - The minimal supported Python version is 3.6*

Redefine supports only Python version 3.6 and above. Please ensure a python version higher or equal to 3.6 is installed.

#### Python Installation Problem

> *Pytest is not installed or cannot be imported, the supported versions are 5.4.0 or higher.*

Possible causes for this issue include:

* Redefine was run outside of a virtual environment. If this is the case, make sure to run from the virtual environment shell or use your favorite virtual environment command line tool to run redefine via Python, i.e., `poetry run python -m redefine <cmd>`
* Pytest is not installed in the current environment. Redefine pytest integration requires pytest to run. Please make sure you are installing pytest in your ci (via pip install pytest or other methods such as requirements.txt file

#### Incompatible Pytest Version

*The current Pytest version is {pytest\_version} - the supported versions are 5.4.0 or higher.*

Redefine supports pytest version 5.4.0 and above. Please ensure pytest version 5.4.0 or higher is installed.

#### Pip Installation Problem

> *Pip is not installed or cannot be imported*

Pip is not installed. Please ensure pip is installed in your environment (by running `python3 -m pip` or `python -m pip`)

#### Pip Version Problem

> *Incompatible Pip version. The current Pip version is {pip\_version} - The supported versions are 9.0.1 or higher.*

The pip version is incompatible, Redefine supports pip versions 9.0.1 or higher., Please upgrade your pip by running `pip install -U pip`.

#### Pytest Plugin Problem

> *Redefine pytest plugin requires {requirement.name} ({requirement.specifier}), upgrading the current version: {version}*

Redefine requires a higher versioned package, and will upgrade it to version {version} when Redefine is installed.

#### Coralogix Configuration Issue

> *Found the python package `coralogix-logger` is installed, if you encounter any issues, make sure to set `Redefine config set pytest_coralogix_disabled=true`*

Redefine detected that the `coralogix-logger` package is installed, which can conflict with your current logger. If you are running one and do experience these issues, please make sure to run `Redefine config set pytest_coralogix_disabled=true`.


# Supported Technologies

## Supported Testing Frameworks

<table data-view="cards"><thead><tr><th></th><th></th></tr></thead><tbody><tr><td>Pytest (Python)</td><td>✅</td></tr><tr><td>Jest (JS)</td><td>🕚 Coming soon</td></tr><tr><td>JUnit (Java)</td><td>🕚 Coming soon</td></tr><tr><td>Cypress (JS)</td><td>✅</td></tr><tr><td>GoTest (GoLang)</td><td>🕚 Coming soon</td></tr><tr><td>Mocha (JS)</td><td>✅</td></tr></tbody></table>

## Supported Operating Systems

<table data-view="cards"><thead><tr><th></th><th></th></tr></thead><tbody><tr><td>Linux</td><td>✅</td></tr><tr><td>MacOS</td><td>✅</td></tr><tr><td>Windows</td><td>✅</td></tr></tbody></table>

### Architectures

<table data-view="cards"><thead><tr><th></th><th></th></tr></thead><tbody><tr><td>x86</td><td>✅</td></tr><tr><td>ARM</td><td>✅</td></tr></tbody></table>


# AI Slack Notifications

Get alerted to issues in real time with instant Slack notifications that include a full stack trace when a test fails. Quickly troubleshoot and rerun CI, without having to wait through time-consuming testing cycles. Effortlessly regain momentum by clicking "Suggest a Fix" to receive an AI-generated solution based on the advanced GPT model. Optimize your development workflow and reduce downtime with our cutting-edge capabilities.

## Install 📦 <a href="#install" id="install"></a>

To install the Redefine Integration for Slack, navigate to <https://redefinedev.slack.com/apps/A04QB70PD2B-redefinedev> and click on the "Open in Slack" button.

<figure><img src="https://47263957-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuwbuslmLp28ROGViWkou%2Fuploads%2F3MyzyRi94s41wyw60R9e%2Fimage.png?alt=media&amp;token=b17455b7-7e8c-4484-b279-4b076592fdb8" alt=""><figcaption><p>Slack Installation Page</p></figcaption></figure>

## Enable Slack Configuration ⚙️&#x20;

To enable AI Slack Notifications, you also need to configure Redefine tool to send the messages from the CI. Run the following command before starting Redefine in your CI workflow:

```bash
redefine config set slack_bot_enabled=true
```

## Subscribe ✍🏽 <a href="#install" id="install"></a>

Upon successful installation in your workspace, a subscription prompt will appear. Enter your email address and press the 'enter' key. You will then receive a verification email. Follow the instructions in the email to complete the subscription process, and you will be subscribed to the Redefine integration for Slack.

<figure><img src="https://47263957-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuwbuslmLp28ROGViWkou%2Fuploads%2FGVHBjT22lqmM2SQ8Uwp8%2Fimage.png?alt=media&amp;token=04aa7fcf-0861-41bd-bc85-db4b63cc1027" alt=""><figcaption><p>Subscription Prompt</p></figcaption></figure>

Developers who wish to subscribe can do so by executing one of the following commands:

1. `/redefine-subscribe` - Opens the subscription dialog.
2. `/redefine-invite` - This command sends a personal invitation to subscribe to each member in the channel. For private channels, make sure you've added Redefine's app to the channel first.

## Enjoy 🔔 <a href="#install" id="install"></a>

After subscribing, you will automatically receive notifications for any failures in your Redefine testing sessions as they occur within the Continuous Integration (CI) environment. Notifications include a stack trace, information about the commit, branch, and test, as well as the Redefine + OpenAI "Suggest a Fix" feature, which offers a potential solution to the specific failure.

<br>

<figure><img src="https://47263957-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuwbuslmLp28ROGViWkou%2Fuploads%2FoJr57tadwCedeFH0LBbT%2Fslack_example.png?alt=media&amp;token=d346ef90-5bbf-4b78-a829-cff41fe42d38" alt=""><figcaption></figcaption></figure>


