Files
loki/.github/workflows/ci.yml
CatoandClaude Opus 5.5 06cf743de9 feat(browser): fill forms on the phone too — Loki for Firefox and one /fill page (#1156)
* wip(browser): Loki for Firefox + /fill page (validation in progress)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BWXjqiHm8jFta4FXuc7Tck

* fix(fill): long values wrap under their label on a 320px phone

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BWXjqiHm8jFta4FXuc7Tck

* style: prettier on the extension test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BWXjqiHm8jFta4FXuc7Tck

* fix(demo): /api/browser-task is denied in the demo sandbox — it reaches the owner's machine

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BWXjqiHm8jFta4FXuc7Tck

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-11 16:32:05 -07:00

300 lines
15 KiB
YAML

name: CI
on:
push:
branches: [main]
pull_request:
# Load-bearing for CD: a merge made by auto-merge.yml uses the default
# GITHUB_TOKEN, and a push made with that token does NOT trigger workflows.
# Deploy chains off CI via workflow_run, so without a way to dispatch CI on
# main by hand, every automated merge would land and silently never ship.
workflow_dispatch: {}
# On a PR branch the newest push is the only one that matters, so cancel the
# rest — that is where the minutes are saved.
#
# On main the group is keyed per COMMIT, and the bug that forced this was a
# commit cancelling a DIFFERENT commit's run.
#
# Two paths ship a commit, and exactly one fires per commit by design: a push to
# main chains through `workflow_run`, and a dispatch runs the `ship` job below.
# Under one group-per-branch, the dispatch cancels the push run for the same
# commit — that is intended, it is how `ship` becomes the single path. What was
# never intended is the NEXT merge cancelling the surviving run of the previous
# one, which kills both paths at once and leaves the commit in the repository.
#
# Seen four times on 2026-09-11. Nothing was red. `gh run list` showed, for one
# commit, a cancelled push run and a cancelled dispatch run, and for the commit
# five minutes later, a clean success. Main green, every check passing, and the
# box still serving the previous build.
#
# Per-commit keeps same-commit cancellation (so it still ships once) and stops
# cross-commit cancellation (so it ships at all).
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.ref == 'refs/heads/main' && github.sha || 'branch' }}
cancel-in-progress: true
jobs:
check:
runs-on: ubuntu-latest
# A migrated Postgres, so tests that need one stop being excluded forever.
# Six suites were on the permanent skip list for lack of a database, and
# the entitlement e2e — signature verification, actor lookup, grant write,
# dedupe, expiry sweep — is the BILLING boundary. It had never run in CI.
#
# pgvector, not plain postgres: src/db/schema/knowledge-embeddings.ts
# declares a `vector` column, and drizzle-kit push dies with
# `type "vector" does not exist` on a stock image.
services:
postgres:
image: pgvector/pgvector:pg16
env:
POSTGRES_PASSWORD: postgres
ports: ["5432:5432"]
options: >-
--health-cmd pg_isready
--health-interval 5s
--health-timeout 5s
--health-retries 10
env:
DATABASE_URL: postgresql://postgres:postgres@127.0.0.1:5432/postgres
steps:
# fetch-depth: 0, because one check compares against a release TAG.
# The default shallow checkout fetches no tags at all, and a shallow one
# with `fetch-tags` still lacks the tagged commit's trees — so
# `git diff fleet-runner-v* HEAD` could not run, and the desktop-release
# drift gate would have passed vacuously in the one place it most needs
# to run. It reports that absence as a failure rather than as clean, so
# this line is what keeps it able to go green honestly.
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: pnpm/action-setup@v6
# setup-pnpm's default store nests inside its own bin dir, which breaks
# any prepare-building dep (portable-type TS2742) — pin it outside.
- run: pnpm config set store-dir ~/.pnpm-store --global
- uses: actions/setup-node@v7
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile
# check:design scans with ripgrep, which is NOT preinstalled on the
# runner. Without this the script exited 127 on every pattern, read that
# as "no matches", and reported ok while scanning nothing — the gate was
# decorative for its entire life. The script now hard-fails when rg is
# absent, so this step is what keeps the gate able to run at all.
- name: Install ripgrep (required by check:design)
run: sudo apt-get update -qq && sudo apt-get install -y -qq ripgrep
# scripts/test/widget-host-avoid-browser.ts proves in a real browser that
# the feedback launcher never sits on a host page's controls. It FAILS
# under CI when Chromium is missing (it only skips on a laptop without
# one), so this step is what lets it run rather than pass vacuously.
# Full Chromium, not only the headless shell: scripts/test/browser-extension.ts
# loads the built Loki for Firefox extension, and the shell cannot run
# extensions — it would fail here (CI requires the browser) rather than skip.
- name: Install Chromium (widget placement + extension browser tests)
run: pnpm exec playwright install --with-deps chromium
# ONE canonical bundle — the exact `pnpm run verify` you run locally
# (tsc + lint + check:design + check:desktop + test:unit + test:home +
# test:ops). CI calls it VERBATIM, so a green local verify can't diverge
# from a green CI. The unit suite is glob-discovered
# (scripts/test-unit.ts), so a new scripts/test/*.ts is picked up for
# free — no more born-dead tests.
#
# check:desktop is deliberately IN the bundle rather than a parallel job:
# a separate job would be faster in wall-clock but would break "green
# local verify => green CI", and desktop/ is precisely the area where
# nobody was running anything locally. See scripts/check-desktop.sh.
# `drizzle-kit push`, NOT the drizzle/*.sql files. Those do not replay
# from empty — 0001_canonical_project_identity.sql references
# `user_projects`, which 0000 never creates, and 51 of 56 migrations fail
# against a fresh database. The journal is history, not a rebuild recipe.
#
# push is safe to run non-interactively HERE specifically because the
# database is empty: its truncate prompts only fire for tables holding
# rows, so there is nothing for it to ask about. Never point this at a
# database with data in it.
- name: Migrate the CI database
run: |
psql "$DATABASE_URL" -c 'CREATE EXTENSION IF NOT EXISTS vector;'
npx drizzle-kit push --force
# The queue's SQL decides which agent may start and which run is dead.
# It has put two prompts into one agent session and dropped queued work
# in production, and nothing executed it: every suite in `verify` is
# database-free by design. This job already builds a real, migrated
# Postgres and used it for nothing — so this is where that SQL is tested.
- name: Database tests
run: pnpm run test:db
# scripts/site-template is bitbaum/fleet templates/app at the commit pinned
# in its .fleet-source. Hand edits here would fork the starter every new
# product is made from, so CI proves the copy is exact (the kickoff's
# generated file map is held to the directory by test:unit). Pinned, not
# "fleet main": a fleet change never turns an unrelated PR here red —
# starter-sync.yml brings it in as its own PR.
- name: The site template is fleet's starter, unedited
run: bash scripts/templates/sync-starter.sh --check
# Merge→live latency (Cato 2026-09-16): full `verify` is ~60m. PRs keep it.
# Squash merges onto main already passed that gate on the PR — re-running
# doubles merge→live for no new signal. Fast `verify:main` on those tips;
# manual/weird main pushes (no (#N) in the subject) still get full verify.
- name: Verify
run: |
set -euo pipefail
subject=$(git log -1 --format=%s)
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "PR — full verify"
pnpm run verify
elif [ "${{ github.ref }}" = "refs/heads/main" ] && echo "$subject" | grep -Eq '\(#[0-9]+\)'; then
echo "main tip looks like a PR merge ($subject) — fast verify:main"
pnpm run verify:main
else
echo "main without PR subject ($subject) — full verify"
pnpm run verify
fi
# `next build` is intentionally NOT here — the App-Router pages do
# DB queries during static pre-render, so a real Postgres would
# need to be set up + migrated + seeded before the build can run.
# The Hetzner deploy step (scripts/deploy-hetzner.sh) builds against
# the live box DB, so this CI focuses on type/lint and leaves build
# verification to that deploy.
# ── Close the CD gap where it opens, instead of polling for it ──────────────
#
# Deploy chains off CI via workflow_run. That event never fires for a CI run
# that GITHUB_TOKEN started — which is exactly how every auto-merged PR gets
# its main-CI (auto-merge.yml dispatches it, because the merge push itself
# triggers nothing either). So the chain is broken for the ONLY path that
# actually merges code here.
#
# The sweep covered that by reconciling on its next tick: correct, self-
# healing, and up to ten minutes late. Measured on #284: 18.6 minutes of the
# 26.8-minute merge→live was this wait, with nothing running.
#
# A dispatch is not a push, so it is not subject to the no-cascade rule: this
# job can start Deploy directly the moment CI proves main is green. The sweep
# keeps its reconciler as the safety net for a deploy that never fired or
# failed — a poll is the right shape for "did something get missed?", and the
# wrong shape for "did something just happen?".
#
# Deliberately only for workflow_dispatch: a real push to main still chains
# through workflow_run on its own, and dispatching here too would ship twice.
ship:
needs: check
if: github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
# contents: read is not optional. A job-level permissions block turns
# everything it does not list OFF, and on a PRIVATE repo a token without
# contents cannot even check out its own code: "Repository not found",
# CI red on main, and the fleet sweep never ships a red main — so a new
# private site stopped one step before going live (probe-loop, 2026-09-26).
permissions:
actions: write
contents: read
steps:
- uses: actions/checkout@v7
- name: Dispatch Deploy now that main is green — unless the push already did
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SHA: ${{ github.sha }}
run: |
# This job is the fallback path. A merge made with GITHUB_TOKEN
# triggers no workflows, so nothing else would ship it — that is why
# the job exists. But the sweep now merges with a PAT, which DOES
# produce a push-triggered CI run, and that run chains to Deploy on
# its own through workflow_run. When both happen, the commit is built,
# rsynced and restarted twice.
#
# Before commits on main stopped cancelling each other this was
# mostly hidden: the dispatch usually cancelled the push run first.
# Now both survive on purpose, so the duplicate has to be declined
# here instead — by asking whether a push-triggered CI run for THIS
# commit has already succeeded, since that is exactly the condition
# under which Deploy is already coming.
pushed=$(gh run list --workflow ci.yml --event push --limit 30 \
--json headSha,conclusion \
--jq "[.[] | select(.headSha == \"$SHA\" and .conclusion == \"success\")] | length")
if [ "${pushed:-0}" -gt 0 ]; then
echo "a push-triggered CI run for $SHA already succeeded — Deploy is"
echo "already chained off it through workflow_run. Not dispatching a"
echo "second build of the same commit."
exit 0
fi
echo "no push-triggered CI run for $SHA — this dispatch is the only"
echo "path to the box, so dispatching Deploy without waiting for a sweep tick"
gh workflow run deploy.yml --ref main
# ---------------------------------------------------------------------------
# Mint the Fleet Runner release tag once main is green, so desktop code ships
# itself the way server code already does.
#
# The gap this closes: desktop/ only reaches a machine when a
# `fleet-runner-v*` tag exists, and until now a human had to mint it. Nobody
# did. Six merged commits sat unreleased after v0.8.12 — a power-source
# router, a usage double-billing fix, capture-hook changes — all live on the
# server, none on any machine, with nothing anywhere reporting a problem.
#
# The split of responsibility is deliberate:
# the BUMP is human — it says "this change is meant to reach machines",
# and scripts/test/desktop-release-drift.ts fails the
# build when desktop/ changed without one.
# the TAG is automatic — a purely mechanical step, and therefore exactly the
# kind of step a person forgets.
#
# Idempotent by construction: it exits when the tag already exists, so it is a
# no-op on every push between version bumps.
#
# WHY IT DISPATCHES INSTEAD OF RELYING ON THE TAG PUSH: a push made with the
# default GITHUB_TOKEN triggers no workflows, and desktop-release.yml fires on
# `push: tags`. Pushing the tag from here would therefore create the tag and
# build nothing — the same silent no-cascade trap that once left merges
# undeployed. So the tag push is treated as bookkeeping and the release is
# started explicitly, with `--ref` on the tag so the `mirror` job's
# `startsWith(github.ref, 'refs/tags/fleet-runner-v')` guard still holds.
# ---------------------------------------------------------------------------
release-desktop:
needs: check
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Tag and release Fleet Runner if the version moved
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
version="$(node -p "require('./desktop/package.json').version")"
tag="fleet-runner-v${version}"
if git rev-parse -q --verify "refs/tags/${tag}" >/dev/null; then
echo "${tag} already exists — nothing to release."
exit 0
fi
echo "desktop/package.json is at ${version} with no ${tag} — releasing."
git tag "$tag"
git push origin "$tag"
# The tag now exists but nothing is watching it (see the header).
gh workflow run desktop-release.yml --ref "$tag"
echo "dispatched desktop-release.yml on ${tag}"