|
| 1 | +# test-companion |
| 2 | + |
| 3 | +Ask BrowserStack Test Companion for test work from a pull request. |
| 4 | + |
| 5 | +Comment `@browserstack test this PR` and it reads the change, proposes the |
| 6 | +tests it would write, and writes them once someone replies `go`. The result |
| 7 | +comes back as one comment and one check. |
| 8 | + |
| 9 | +## Quick start |
| 10 | + |
| 11 | +1. Add two secrets: `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY`. |
| 12 | +2. Copy [`starter-workflow.yml`](starter-workflow.yml) to |
| 13 | + `.github/workflows/test-companion.yml` in your repository, as-is. |
| 14 | + |
| 15 | +Which jobs run, on which events and with which limits is set in |
| 16 | +`testcompanion-pipeline.yml` in your repository, not in the workflow file. |
| 17 | + |
| 18 | +**Runner requirements:** Linux (GitHub's `ubuntu-latest` works as is), Node 20 |
| 19 | +or later, `gh` installed system-wide (`/usr/bin` or `/usr/local/bin`), and |
| 20 | +password-free `sudo` for the job. |
| 21 | + |
| 22 | +`sudo` keeps your tokens away from the AI agent. The agent runs as a separate |
| 23 | +user with no admin rights that cannot read this job's tokens, secrets or temp |
| 24 | +files. Its `gh` can only read from GitHub, through a relay; every write is made |
| 25 | +by the Action after the run. Without password-free `sudo` the run stops and |
| 26 | +says why, unless you set `allow-unisolated: true`. |
| 27 | + |
| 28 | +Use the starter file rather than writing your own. It includes safeguards that |
| 29 | +are easy to miss: |
| 30 | + |
| 31 | +- a filter so comments not meant for Test Companion don't start a job; |
| 32 | +- `persist-credentials: false` on checkout, so the workflow token is not left |
| 33 | + in `.git/config` where the agent could read it; |
| 34 | +- concurrency rules that keep one run per pull request and let closing a pull |
| 35 | + request cancel its run. |
| 36 | + |
| 37 | +## Pin the CLI version |
| 38 | + |
| 39 | +Without a pin the CLI upgrades itself on a release day, so two runs a day apart |
| 40 | +may not run the same software. Set `cli-version` and `cli-sha256` together, |
| 41 | +from the release you tested; a version without a checksum is refused. |
| 42 | + |
| 43 | +```yaml |
| 44 | + - uses: browserstack/github-actions/test-companion@v1.1.0 |
| 45 | + with: |
| 46 | + username: ${{ secrets.BROWSERSTACK_USERNAME }} |
| 47 | + access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} |
| 48 | + cli-version: "1.2.0" |
| 49 | + cli-sha256: "<sha256 of that release for linux-amd64>" |
| 50 | +``` |
| 51 | +
|
| 52 | +## Inputs |
| 53 | +
|
| 54 | +| Input | Required | What it does | |
| 55 | +|---|---|---| |
| 56 | +| `username` | yes | BrowserStack username, from your secret store | |
| 57 | +| `access-key` | yes | BrowserStack access key, from your secret store | |
| 58 | +| `cli-version` | no | Pin the CLI. Recommended, see above | |
| 59 | +| `cli-sha256` | no | Checksum for the pinned version | |
| 60 | +| `build-effect` | no | When this step fails. `fail-on-break` (default): the run broke, could not start or hit a limit, not test failures. `report`: never. `fail`: anything but success. The check reports the real outcome either way | |
| 61 | +| `workflow` | no | Manual runs only; event-driven runs read the pipeline file | |
| 62 | +| `preview` | no | Report what would happen and change nothing | |
| 63 | +| `allow-unisolated` | no | `"true"` runs the agent as the job's own user when it cannot be locked down, where it can reach this job's tokens and secrets. Off by default | |
| 64 | +| `app-id` / `app-private-key` | no | Post as the GitHub App. Keep the workflow's `permissions:` block: the workflow token is the fallback | |
| 65 | + |
| 66 | +## Approving a plan |
| 67 | + |
| 68 | +Before a job changes anything, Test Companion posts its plan and waits for |
| 69 | +someone with write access to reply `go`. Read the plan before you reply. |
| 70 | + |
| 71 | +Without the GitHub App, Test Companion posts as `github-actions[bot]`, the |
| 72 | +account every workflow in your repository shares, and recognises its own plans |
| 73 | +by that account and a hidden marker. Another workflow that copies outside text |
| 74 | +into a comment could imitate a plan. A `go` only ever approves a plan for the |
| 75 | +pull request's current commit. With the App, Test Companion posts under its own |
| 76 | +account, which no other workflow can use. |
| 77 | + |
| 78 | +## How the CLI is installed |
| 79 | + |
| 80 | +Each run downloads the installer from |
| 81 | +`test-companion.browserstack.com/cli/install.sh`. The installer itself is not |
| 82 | +checked against a fixed checksum, so a run trusts that address. Pinning |
| 83 | +`cli-version` with `cli-sha256` makes it refuse any CLI build but the one you |
| 84 | +tested. |
| 85 | + |
| 86 | +## Notes for maintainers |
| 87 | + |
| 88 | +A composite action with no dependencies and no `dist/` bundle: the sources in |
| 89 | +`src/` are what run. |
| 90 | + |
| 91 | +Tests: `cd test-companion && node --test`. No network or credentials needed. |
0 commit comments