Running in CI
In CI you run the same four things you run locally, in order: the server, channelstack env, your app, and the tests. This page has a GitHub Actions job for Vitest and for pytest, a nightly live job, and what to look at when a job hangs.
The job#
name: Agent tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
cache: npm
- run: npm ci
- name: Start channelstack
env:
CHANNELSTACK_SLACK_WEBHOOK_URL: http://localhost:3000/slack/events
run: |
npx channelstack start --no-portless --port 4500 > channelstack.log 2>&1 &
timeout 30 bash -c 'until npx channelstack env > /dev/null 2>&1; do sleep 1; done'
- name: Point the agent at it
run: npx channelstack env >> "$GITHUB_ENV"
- name: Start the agent
env:
PORT: 3000
run: |
node agent.js > agent.log 2>&1 &
timeout 30 bash -c 'until curl -s -o /dev/null http://localhost:3000/; do sleep 1; done'
- run: npx vitest run
- if: failure()
uses: actions/upload-artifact@v4
with:
name: logs
path: "*.log"
What each step does:
- Start channelstack.
--no-portlessserves every fake on one loopback port over plain HTTP (http://127.0.0.1:4500/slack, …), so the runner needs no portless and no CA. The server readsCHANNELSTACK_<CHANNEL>_WEBHOOK_URLwhen it starts, so set it on this step; a Socket Mode agent connects out and needs none. The loop waits until the server has written~/.channelstack/server.jsonand answers. - Point the app at it.
channelstack envprints the fake tokens, signing secrets and API URLs asKEY=valuelines. Appending them to$GITHUB_ENVmakes them part of every later step's environment. They are fake values, made fresh for this runner. - Start the app in the background, unchanged, and wait until its port answers.
- Run the tests. The Vitest plugin finds the running server through
server.jsonand gives each test its own session.
Make the plugin refuse to start a server of its own in CI. In auto mode (the default), a missing server makes it start a private one, which your app doesn't know about, and every test would time out instead of failing at once:
import { defineConfig } from "vitest/config";
import channelstack from "channelstack/vitest";
export default defineConfig({
plugins: [channelstack({ mode: process.env.CI ? "attach" : "auto" })],
});
The server, its logs and its state are gone when the job ends. Nothing needs cleaning up in fake mode.
With pytest#
The server comes from npm in a Python project too. Install it globally, so the Python SDK finds channelstack on the PATH:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
- uses: actions/setup-python@v5
with:
python-version: "3.13"
cache: pip
- run: npm install --global channelstack
- run: pip install -r requirements.txt pytest-channelstack
- name: Start channelstack
env:
CHANNELSTACK_SLACK_WEBHOOK_URL: http://localhost:3000/slack/events
run: |
channelstack start --no-portless --port 4500 > channelstack.log 2>&1 &
timeout 30 bash -c 'until channelstack env > /dev/null 2>&1; do sleep 1; done'
- run: channelstack env >> "$GITHUB_ENV"
- name: Start the agent
env:
PORT: 3000
run: |
python agent.py > agent.log 2>&1 &
timeout 30 bash -c 'until curl -s -o /dev/null http://localhost:3000/; do sleep 1; done'
- run: pytest --channelstack-mode attach
--channelstack-mode attach does what mode: "attach" does for Vitest; channelstack_mode = attach in your pytest ini settings does the same (pytest).
Caching#
- npm:
actions/setup-nodewithcache: npmcaches the npm cache, which holds the server binary too: it comes withchannelstackas an optional dependency for the runner's platform (@channelstack/server-linux-x64onubuntu-latest). Don't install with--no-optional, or the binary is missing. - pip:
actions/setup-pythonwithcache: pip. - Don't cache
~/.channelstack. It holds the install's fake secrets and, for live runs, saved browser sessions. A fresh runner makes new secrets, andchannelstack envprints them in the same job.
A nightly live job#
The same tests run against real sandboxes when the credentials are set (Live mode). Run that on a schedule, never on pull requests, so a fork's code never sees the secrets:
name: Live
on:
schedule:
- cron: "17 3 * * *"
workflow_dispatch:
concurrency:
group: live # one run at a time: the sandbox and its rate limits are shared
cancel-in-progress: false
jobs:
live:
runs-on: ubuntu-latest
environment: live # the secrets live in a protected environment
timeout-minutes: 30
env:
CHANNELSTACK_RUN_ID: gh${{ github.run_id }}
CHANNELSTACK_LIVE_SLACK_TEAMS: ${{ vars.CHANNELSTACK_LIVE_SLACK_TEAMS }}
CHANNELSTACK_SLACK_APP_ID: ${{ secrets.CHANNELSTACK_SLACK_APP_ID }}
CHANNELSTACK_SLACK_BOT_TOKEN: ${{ secrets.CHANNELSTACK_SLACK_BOT_TOKEN }}
CHANNELSTACK_SLACK_USER_ANA_TOKEN: ${{ secrets.CHANNELSTACK_SLACK_USER_ANA_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
cache: npm
- run: npm ci
- name: Restore Ana's browser session
env:
SESSION: ${{ secrets.SLACK_ANA_BROWSER_SESSION }}
run: |
mkdir -p ~/.channelstack/browser
(umask 077; printf '%s' "$SESSION" > ~/.channelstack/browser/slack-ana.json)
- run: npx channelstack doctor
- name: Start channelstack
run: |
node_modules/.bin/channelstack start --no-portless --port 4500 > channelstack.log 2>&1 &
echo $! > channelstack.pid
timeout 30 bash -c 'until npx channelstack env > /dev/null 2>&1; do sleep 1; done'
- name: Start the agent with its real app, in Socket Mode
env:
SLACK_BOT_TOKEN: ${{ secrets.CHANNELSTACK_SLACK_BOT_TOKEN }}
SLACK_APP_TOKEN: ${{ secrets.SLACK_APP_TOKEN }}
run: node agent.js > agent.log 2>&1 &
- run: npx vitest run
- name: Stop channelstack
if: always()
run: kill "$(cat channelstack.pid)" && sleep 5
- name: Check that the run left nothing behind
if: always()
run: npx channelstack sweep --check --run "$CHANNELSTACK_RUN_ID"
- name: Remove what it left
if: failure()
run: npx channelstack sweep --run "$CHANNELSTACK_RUN_ID"
How it differs from the fake job:
- Credentials are job-level
env, so the server (app credentials, allowlists,CHANNELSTACK_RUN_ID), the test process (people's tokens) anddoctorandsweepall see them. Allowlists aren't secret, so they can be repository variables. CHANNELSTACK_RUN_IDtags everything the run creates, and a re-run of the job keeps it. It must be 1 to 24 letters and digits. A run of 7 or more digits, like GitHub's run number, goes into names in base 36 (Linear takes it for a phone number otherwise), andsweep --runfinds the run by the same id.- The app runs with its real app, not with
channelstack env(which prints nothing for a live channel). Real Slack delivers to it; Socket Mode means the runner needs no public URL. - The browser actor needs each person's saved session: run
channelstack login slack --user anaonce on your machine and store the file's contents as a secret.ubuntu-latesthas Chrome. doctorfails the job before the tests when a credential is wrong or a session has expired.- Stopping the server closes what its sessions still hold; then
sweep --checkfails the job if anything of this run is left, andsweepremoves it.
Tests that use fake-only features skip with the reason, and a setup that can't work fails, so a broken setup turns the job red instead of skipping everything (what skips and what fails).
If the job hangs#
A matcher waits 10 seconds by default and a negative check waits for the app to be quiet, so a single test doesn't hang for long. When the job does, look at these in order:
- The server never came up. The
untilloop times out after 30 seconds.channelstack.logsays why, for example that a server is already running from the sameserver.json, or that portless isn't installed (start with--no-portless). - The app never came up, or crashed. Its wait loop times out, or every test fails with no reply. Read
agent.log: a missing variable usually means thechannelstack envstep ran in a different job, or before the server was up. - Events don't reach the app.
CHANNELSTACK_SLACK_WEBHOOK_URLwasn't set on the step that started the server, or it doesn't match the app's port and path. - Every test waits its full timeout. Start the server with
--log-level debug: it logs each delivery attempt and how it ended (unreachable,timed_out, a status code). Logs are redacted, so they can go into an artifact. - Live runs are slower. A real model and real rate limits take longer: give positive matchers a longer
timeout. The first browser actor start on a fresh runner can take a minute or two while the matching Chrome driver is fetched.
Troubleshooting has the symptoms in more detail.