# Nightly runs and first run

## Nightly runs, alerts and the first run

### Nightly schedule and alerts

Whichever path the human chose in `tests`, setup ends with that suite on a nightly schedule with failure alerts. Do not leave it as a suggestion. Post `cofactor setup update --step schedule "<one sentence>"` before you ask and after each command below; Cofactor marks the step done once an enabled schedule and an alert exist. The human is only asked for the alert target. Detail: the docs pages `testing/suites-and-schedules` and `release-gate/reports`. First run `cofactor teams status`: leave Teams out of the ask unless it shows Teams available: yes. Ask: "Which Slack channel or email should failures go to?" (add "or Teams channel" when Teams is available). Then tell them: for Slack, they approve the connection in the browser page you open; for Teams, they run `cofactor teams install` in their own terminal and approve it. Email needs no connection. Slack and Teams need one, only when the human picks them, and connecting is for organization admins:

- Slack: run `cofactor slack connect` in the background: it opens Settings -> Slack and waits up to 10 minutes for the human's approval. If it connected the wrong workspace, with the human's go-ahead run `cofactor slack disconnect --yes`, then connect again. A private channel must add the Cofactor app first (`/invite` in that channel).
- Teams: the human's `cofactor teams install` opens Settings -> Microsoft Teams in their browser (signing in first if needed), which sends them to the Microsoft consent page and waits for it; they then add the Cofactor app to the channel, and `cofactor teams channels` lists the name to pass to `--teams`.

```bash
cofactor test-suite create --name "<App> Nightly"                  # new suite only
cofactor test-suite set-members <suite> --layer <wf_...,wf_...>    # new suite only
cofactor test-suite suites                                        # existing Playwright tests: the suite's id (new suite: printed by create)
cofactor schedule suite create --name "<App> Nightly" --suite-id <id> --at 02:00 --timezone <their IANA zone>
cofactor alert create --on-schedule <scheduleId> --slack "#<channel>" --when failure   # or --teams "<channel>", or --email <addr>
```

Done when `cofactor schedule suite get <scheduleId>` shows the next run and the alert.

### First run

- `cofactor test-suite run --suite <suite>` now (do not wait for tonight); it streams results and prints the run URL. Read it with `cofactor test-suite get <executionId>` (new suite) or `cofactor external-run get <run-id>` (existing Playwright tests). For failures: `cofactor skill install cofactor-triage-tests` (and `cofactor-debug-run` for a new suite). Keep the run URL and a short summary (what ran, passed, failed and why) for `report`.

Rules: neutral example names (Acme, example.com) in tests; never real credentials in steps or chat.

Next: `cofactor setup guide skills`
