Skip to content

Commit 930cbdb

Browse files
Merge branch 'master' into fix/LOC-7659-local-args-multiple-values
2 parents 9e02c71 + 024b083 commit 930cbdb

48 files changed

Lines changed: 9325 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# If this check is ever made required, remove the `paths` filter: a required
2+
# check that never reports blocks the pull request.
3+
name: Test Companion tests
4+
5+
on:
6+
pull_request:
7+
branches: [master]
8+
paths:
9+
- "test-companion/**"
10+
- ".github/workflows/test-companion-tests.yml"
11+
push:
12+
branches: [master]
13+
paths:
14+
- "test-companion/**"
15+
16+
permissions:
17+
contents: read
18+
19+
concurrency:
20+
group: test-companion-tests-${{ github.event.pull_request.number || github.ref }}
21+
cancel-in-progress: true
22+
23+
jobs:
24+
unit-tests:
25+
name: Test Companion unit tests
26+
runs-on: ubuntu-latest
27+
timeout-minutes: 10
28+
steps:
29+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
30+
with:
31+
persist-credentials: false
32+
33+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
34+
with:
35+
node-version: "22"
36+
37+
# `node --test` exits 0 when a test file fails to load; only a
38+
# `not ok` line shows it.
39+
- name: Run the unit tests
40+
working-directory: test-companion
41+
run: |
42+
set -o pipefail
43+
node --test --test-reporter=tap test/*.test.mjs | tee test-output.tap
44+
if grep -nE '^\s*not ok' test-output.tap; then
45+
echo "::error::A test failed or a test file did not load. See the 'not ok' lines above."
46+
exit 1
47+
fi

‎CODEOWNERS‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
* @browserstack/automate-public-repos
2+
3+
/test-companion/ @browserstack/automate-public-repos @browserstack/test-companion
4+
/.github/workflows/test-companion-tests.yml @browserstack/automate-public-repos @browserstack/test-companion

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ If you want to test your open source project on BrowserStack, then [sign-up here
2020

2121
* [setup-local](./setup-local): This Action downloads and starts the appropriate BrowserStackLocal binary, thereby creating a secure tunnel connection from the GitHub Actions runner environment to the BrowserStack device cloud. This secure tunnel will be used by the remote browsers in BrowserStack to access your web application hosted in the GitHub Actions runner environment. **You do not need this Action if the application to be tested is accessible over the public internet.**
2222

23+
* [test-companion](./test-companion): Ask BrowserStack Test Companion for test work from a pull request. Comment `@browserstack test this PR` and it proposes the tests it would write, then writes them once someone with write access replies `go`. Needs a Linux runner. See its [README](./test-companion/README.md) for setup.
24+
2325
## Prerequisites
2426
* You should set your BrowserStack Username and Access Key as GitHub Secrets, i.e. `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` respectively.
2527

‎test-companion/README.md‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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

Comments
 (0)