@mayurdluffy/ccwf 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,7 +23,7 @@ npx @mayurdluffy/ccwf init # tools + user-level skills + project files
23
23
  |---|---|
24
24
  | `core` (always) | discipline rules in `AGENTS.md` (`CLAUDE.md` imports it), `commit` skill, Cursor rule, `docs/agents/workflow.md` and `setup.md` |
25
25
  | `memory` | `.agent-memory/MEMORY.md` + rules |
26
- | `tracking` | empty `docs/GLOSSARY.md`, `DECISIONS.md`, `FEATURES.md`, `BACKLOG.md`, `adr/` + rules; `docs/agents/{domain,issue-tracker,triage-labels}.md` |
26
+ | `tracking` | `docs/ROADMAP.md` (session entry point: product, order of work, efforts with their `progress.md`), empty `docs/GLOSSARY.md`, `DECISIONS.md`, `FEATURES.md`, `BACKLOG.md`, `adr/`, `learnings/` + `save-learning` skill + rules; `docs/agents/{domain,issue-tracker,triage-labels}.md` |
27
27
  | `browser` | `agent-browser` + `verify-ui` skills, `chrome-devtools` MCP, `.cursor/cli.json`, Claude MCP approval and allowed sites |
28
28
  | `workers` | `orchestrate-workers` skill (a `workers` tab of four panes in the orchestrator's own herdr space, `hc` reference, `workers.conf`) |
29
29
 
package/lib/modules.js CHANGED
@@ -120,11 +120,13 @@ const MODULES = {
120
120
  },
121
121
  },
122
122
  tracking: {
123
- desc: "empty GLOSSARY, DECISIONS, FEATURES, BACKLOG, adr/ + the rules for using them",
123
+ desc: "ROADMAP, GLOSSARY, DECISIONS, FEATURES, BACKLOG, adr/, learnings/ + save-learning skill + the rules",
124
124
  run(ctx) {
125
125
  const { ins } = ctx;
126
- for (const f of ["GLOSSARY", "DECISIONS", "BACKLOG", "FEATURES"]) ins.seed(`docs/${f}.md`, tpl("docs", `${f}.md`), undefined, true);
126
+ for (const f of ["ROADMAP", "GLOSSARY", "DECISIONS", "BACKLOG", "FEATURES"]) ins.seed(`docs/${f}.md`, tpl("docs", `${f}.md`), undefined, true);
127
127
  ins.seed("docs/adr/.gitkeep", "");
128
+ ins.seed("docs/learnings/README.md", tpl("docs", "learnings", "README.md"), undefined, true);
129
+ installSkill(ctx, "save-learning");
128
130
  for (const f of ["domain", "issue-tracker", "triage-labels"]) ins.seed(`docs/agents/${f}.md`, tpl("docs", "agents", `${f}.md`), undefined, true);
129
131
  ins.block("AGENTS.md", "tracking", blockBody("tracking", ctx.params));
130
132
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mayurdluffy/ccwf",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "One command to set up skills, MCP servers, shared memory and rules for Claude Code, Codex and Cursor in any repo",
5
5
  "main": "bin/ccwf.js",
6
6
  "bin": {
@@ -1,8 +1,11 @@
1
1
  ## Browser verification (Claude Code, Codex, Cursor)
2
2
 
3
- Never screenshot to check that something exists or loaded; read the accessibility tree instead. Screenshot only for purely visual questions (layout, colors).
3
+ Every feature and every bug fix that can be seen in a browser, whether the change is in the UI or in the API behind it, is checked with the `verify-ui` skill before it is reported done. Never screenshot to check that something exists, loaded or says the right thing; read the accessibility tree instead, which costs far fewer tokens. Screenshot only for purely visual questions (layout, colors).
4
4
 
5
- - **Start with the `verify-ui` skill** (`.agents/skills/verify-ui`): `probe.sh <path>` prints a page's health (uncaught errors, console, failed and API requests, vitals, interactive elements) in one call; `run.sh <dir>` runs ticket scenarios as a regression suite; `PLAYBOOK.md` maps each browser symptom to one command. Evidence is saved under `.scratch/.verify-out/` (git-ignored). Base URL and allowed sites are in `.agents/skills/verify-ui/verify-ui.conf`; the skill asks for them on first use, then run `npx @mayurdluffy/ccwf sync`.
5
+ - **Feature:** write its scenario, run it, then run the whole suite.
6
+ - **Bug:** first reproduce it as a failing scenario, then fix, then keep the scenario as the regression test.
7
+
8
+ - **Start with the `verify-ui` skill** (`.agents/skills/verify-ui`): `probe.sh <path>` prints a page's health (uncaught errors, console, failed and API requests, vitals, interactive elements) in one call; `run.sh <dir>` runs ticket scenarios as a regression suite (behaviour, accessibility, screenshot baselines; a scenario that passes only on a rerun is reported as flaky); `PLAYBOOK.md` maps each browser symptom to one command. Evidence is saved under `.scratch/.verify-out/` (git-ignored). Base URL and allowed sites are in `.agents/skills/verify-ui/verify-ui.conf`; the skill asks for them on first use, then run `npx @mayurdluffy/ccwf sync`.
6
9
  - **Drive/inspect UI by hand → `agent-browser`** (CLI; skill in `.agents/skills/agent-browser`; run `agent-browser skills get core` once per session). Use your own session: `S=$(agent-browser session id --scope worktree --prefix task)` then `agent-browser --session $S ...`. Loop: `open <url>` → `snapshot -i -c` (add `--delta` on re-snapshots) → act on `@eN` refs → `console` for errors → `close`.
7
10
  - **`chrome-devtools` MCP only for what agent-browser cannot do**: logpoints, CSS cascade, throttling, performance traces, heap snapshots, Lighthouse. Keep its output small.
8
11
  - **Dev server**: start it as a background process and stop it by its ID; never `pkill`/`killall`.
@@ -1,6 +1,19 @@
1
1
  ## Project tracking and domain docs (Claude Code, Codex, Cursor)
2
2
 
3
- These files in `docs/` start empty and are kept current in **every** session:
3
+ `docs/ROADMAP.md` is the entry point: the product, the order of work, and a table of efforts (each a `.scratch/<feature>/` folder with `spec.md`, `issues/` and `progress.md`). At the start of every session, before any task:
4
+
5
+ 1. Read `docs/ROADMAP.md`.
6
+ 2. Run its "Live progress" command for ticket counts.
7
+ 3. For the effort the task belongs to, read the `spec.md` sections that bear on the task and the `## Resume` section of its `progress.md`.
8
+
9
+ Keep the roadmap current in the same change:
10
+
11
+ - A new spec or effort adds a row to the efforts table and gets a `progress.md` with a `## Resume` section.
12
+ - Starting, pausing or finishing an effort changes its state in the table; a change to what the product is or to the order of work updates the top two sections.
13
+ - Ending a session that moved an effort forward rewrites that effort's `## Resume` (state with the date, next action, waiting on the user).
14
+ - Ticket status lives only in each ticket's `**Status:**` line; `ROADMAP.md` stores no counts.
15
+
16
+ These files in `docs/` are kept current in **every** session:
4
17
 
5
18
  - `docs/GLOSSARY.md` — the project's domain language, only terms, no implementation detail. Read it before exploring or naming things; use its terms exactly. Add or sharpen a term the moment it is resolved (the `domain-modeling` skill does this during `grill-with-docs`).
6
19
  - `docs/adr/` — architecture decision records, one file per decision, only for decisions that are hard to reverse, surprising without context and a real trade-off. Read the ones touching the area you work in; surface a conflict instead of silently overriding an ADR.
@@ -9,3 +22,13 @@ These files in `docs/` start empty and are kept current in **every** session:
9
22
  - `docs/FEATURES.md` — every feature as Done / In progress / Planned. Update it in the same change that starts or finishes the work.
10
23
 
11
24
  Keep the repo root clean: new project documents go under `docs/`. How the planning skills find these files: `docs/agents/domain.md`, `docs/agents/issue-tracker.md`, `docs/agents/triage-labels.md`. The full workflow is in `docs/agents/workflow.md`; machine and tool setup is in `docs/agents/setup.md`.
25
+
26
+ ## Learnings (Claude Code, Codex, Cursor)
27
+
28
+ `docs/learnings/` holds findings the project should not have to rediscover; read its `README.md` index before researching a topic. Save a learning with the `save-learning` skill (`.agents/skills/save-learning/SKILL.md`) in three cases:
29
+
30
+ - the user asks to add something to the learnings;
31
+ - deep web research returned findings;
32
+ - before ending a session that found the root cause of a critical bug or a non-obvious fact about a tool, provider, API or rule.
33
+
34
+ In the last two cases, ask the user first: list what you would save and write it only after they approve.
@@ -0,0 +1,41 @@
1
+ # Roadmap
2
+
3
+ What this project is becoming, which specs exist, and where each one stands. Read this at the start of every session. Rules for keeping it current: `AGENTS.md` ("Project tracking").
4
+
5
+ ## The product
6
+
7
+ <!-- One or two paragraphs: what the product is, who uses it, and its main parts. Agents fill this in during the first grilling session. -->
8
+
9
+ ## Order of work
10
+
11
+ <!-- Numbered list: the current phase first, then what comes after it. -->
12
+
13
+ ## Efforts
14
+
15
+ An effort is one folder in `.scratch/` holding a `spec.md`, one file per ticket in `issues/`, and a `progress.md` with the resume notes.
16
+
17
+ | Effort | State | What it is | Spec | Progress and resume |
18
+ |---|---|---|---|---|
19
+
20
+ States: **Active** (being built), **Queued** (spec and tickets ready, not started), **Done** (every ticket done and accepted by the user).
21
+
22
+ ## Live progress
23
+
24
+ Ticket files are the source of truth for status, so counts are read, not stored here. From the repo root:
25
+
26
+ ```sh
27
+ for d in .scratch/*/issues; do echo "== $d"; grep -h '^\*\*Status:\*\*' "$d"/*.md | sort | uniq -c; done
28
+ ```
29
+
30
+ Then open the active effort's `progress.md` and read its `## Resume` section: it holds the next action, what is waiting on the user, and the environment checklist.
31
+
32
+ ## Where the rest lives
33
+
34
+ | Need | File |
35
+ |---|---|
36
+ | Why a choice was made, in the user's words | `docs/DECISIONS.md` |
37
+ | Vocabulary | `docs/GLOSSARY.md` |
38
+ | Architecture decisions | `docs/adr/` |
39
+ | Feature status (Done / In progress / Planned) | `docs/FEATURES.md` |
40
+ | Deferred work | `docs/BACKLOG.md` |
41
+ | Researched facts and bug root causes | `docs/learnings/` |
@@ -30,11 +30,11 @@ Log in once per agent (not scriptable): `claude`, `codex login`, `cursor-agent l
30
30
 
31
31
  ## 3. What `ccwf init` wrote into the repo
32
32
 
33
- - `.agents/skills/` — `commit`, `agent-browser`, `verify-ui`, `orchestrate-workers` (Claude reaches them through `.claude/skills/` symlinks).
33
+ - `.agents/skills/` — `commit`, `save-learning`, `agent-browser`, `verify-ui`, `orchestrate-workers` (Claude reaches them through `.claude/skills/` symlinks).
34
34
  - `AGENTS.md` — rule sections between `<!-- ccwf:begin ... -->` markers (edit around them, not inside); `CLAUDE.md` imports it.
35
35
  - Agent configs: `.mcp.json`, `.codex/config.toml`, `.cursor/mcp.json`, `.cursor/cli.json`, `.claude/settings.json`.
36
36
  - `.cursor/cli.json` is the Cursor allowlist: listed commands run without asking, including `node`, `npx` and `curl`. The allow and deny lists are merged, so an entry you remove comes back on `update`.
37
- - Empty docs: `docs/GLOSSARY.md`, `DECISIONS.md`, `FEATURES.md`, `BACKLOG.md`, `adr/`, `.agent-memory/MEMORY.md`.
37
+ - Starter docs: `docs/ROADMAP.md` (the session entry point; fill in the product and order of work), `docs/GLOSSARY.md`, `DECISIONS.md`, `FEATURES.md`, `BACKLOG.md`, `adr/`, `learnings/README.md`, `.agent-memory/MEMORY.md`.
38
38
  - `.ccwf.json` — what was installed and the hash of every file `ccwf` wrote. Commit it.
39
39
 
40
40
  ## 4. Settings skills ask for
@@ -9,6 +9,8 @@ idea ──► grill-with-docs ──► to-spec ──► to-tickets ──►
9
9
 
10
10
  ## 1. Decide: `/grill-with-docs`
11
11
 
12
+ Every session starts by reading `docs/ROADMAP.md` (what the product is, the order of work, each effort with its spec and `progress.md`) and the `## Resume` of the effort at hand, so a new session or a different coding agent knows where things stand.
13
+
12
14
  Start with a rough idea. The coding agent interviews you in rounds (numbered questions, each with its recommended answer), checks facts in the code itself, and writes the project's language and decisions down as they are settled:
13
15
 
14
16
  - `docs/GLOSSARY.md` — terms, as they are resolved.
@@ -20,7 +22,7 @@ Say "yes" to accept a recommendation. The session ends when nothing is left open
20
22
 
21
23
  ## 2. Write: `/to-spec`
22
24
 
23
- Turns the conversation into a spec file: `.scratch/<feature>/spec.md`. No new interview.
25
+ Turns the conversation into a spec file: `.scratch/<feature>/spec.md`. No new interview. Add the effort to the table in `docs/ROADMAP.md` and give it a `progress.md` with a `## Resume` section.
24
26
 
25
27
  ## 3. Split: `/to-tickets`
26
28
 
@@ -50,6 +52,8 @@ State lives in the ticket `Status:` lines and `.scratch/<feature>/progress.md`,
50
52
  | New feature test-first | `/tdd` |
51
53
  | Review a branch or PR | `/code-review`, `/pr` |
52
54
  | Remember something for every agent | ask it to write `.agent-memory/` |
55
+ | Keep a researched fact or a bug's root cause | `save-learning` (writes `docs/learnings/`) |
56
+ | Know where things stand | `docs/ROADMAP.md`, then the effort's `progress.md` → `## Resume` |
53
57
 
54
58
  ## Rules of thumb
55
59
 
@@ -0,0 +1,3 @@
1
+ # Learnings
2
+
3
+ Findings the project should not have to rediscover: researched facts, root causes of critical bugs, limits found by trying. One topic per file. How to add one: the `save-learning` skill (`.agents/skills/save-learning/SKILL.md`).
@@ -0,0 +1,43 @@
1
+ ---
2
+ name: save-learning
3
+ description: Save a learning to docs/learnings/ — a finding the project should not have to rediscover. Use when the user says "add this to our learnings" or "save this learning", after deep web research returns findings, after the root cause of a critical bug is found, or when a session uncovers a non-obvious fact about a tool, provider, API or rule.
4
+ ---
5
+
6
+ # save-learning
7
+
8
+ A **learning** is a finding that cost real effort to get and that the code, git history and other docs do not already record: a researched fact about a provider or API, the root cause of a critical bug, a limit or gotcha found by trying. Decisions go to `docs/DECISIONS.md`, vocabulary to `docs/GLOSSARY.md`, architecture choices to `docs/adr/`; a learning is the evidence those rest on.
9
+
10
+ ## Steps
11
+
12
+ 1. **Collect** every learning in scope: the whole conversation when the user names no topic, otherwise the topic they name. Done when each finding is listed with where it came from (URL, command output, file, or test).
13
+ 2. **Confirm** when the save is your own idea (after research, a bug fix or a finding) and the user did not ask for it: show the list from step 1 as one line per learning and ask whether to save. Save only what the user approves. A direct request from the user to save is the approval.
14
+ 3. **Place** each one. Read `docs/learnings/README.md`; update the existing file when the topic is already there, otherwise create `docs/learnings/<topic-slug>.md` (kebab-case, topic only, no date). One topic per file.
15
+ 4. **Write** the file in the format below. Every claim carries its source and one of two marks: **confirmed** (read in a primary source or observed directly) or **unverified** (secondary source, search summary, or general knowledge). Rewrite a claim that later evidence overturns, and say what replaced it.
16
+ 5. **Index** it: one line in `docs/learnings/README.md`, alphabetical, `- [Title](file.md) — what it answers`.
17
+ 6. **Report** the file paths and anything left unverified.
18
+
19
+ ## Format
20
+
21
+ ```markdown
22
+ # <Topic>
23
+
24
+ Checked: <YYYY-MM-DD> · Source: <deep web research | bug fix | experiment | user>
25
+
26
+ ## Why it matters
27
+ <one or two sentences: which decision or code this affects>
28
+
29
+ ## Findings
30
+ - **<claim>** — confirmed. <detail> ([source](url))
31
+ - **<claim>** — unverified. <detail and why it is unverified>
32
+
33
+ ## Still unknown
34
+ - <open question and how to settle it>
35
+ ```
36
+
37
+ For a bug, `Findings` holds the symptom, the root cause, the fix, and how to recognise it next time.
38
+
39
+ ## Rules
40
+
41
+ - Write facts and their evidence. Leave choices to `docs/DECISIONS.md` and link to the entry.
42
+ - Re-check a learning older than three months against its source before relying on it; APIs, prices and regulations change. Update `Checked` when you do.
43
+ - The repo is pushed to GitHub: keep secrets, credentials, personal details and customer data out.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: verify-ui
3
- description: Verify and debug this project's web app in a real browser — a page health report (console, network, errors, vitals, accessibility), ticket scenarios kept as a regression suite, and a playbook of browser debugging recipes. Use when finishing or reviewing a ticket with UI, API or browser-visible behaviour, when asked to "verify", "browser check", "smoke test" or "regression check", or when debugging anything seen in the browser (blank page, dead click, failed request, wrong state, layout, slowness).
3
+ description: Verify and debug this project's web app in a real browser — a page health report (console, network, errors, vitals, accessibility), ticket scenarios kept as a regression suite with accessibility and screenshot-baseline checks, and a playbook of browser debugging recipes. Use it every time a feature or a bug fix can be seen in a browser, whether the change is in the UI or in the API behind it: when building or finishing a ticket, when reviewing one, when asked to "verify", "browser check", "smoke test" or "regression check", and when reproducing or debugging anything seen in the browser (blank page, dead click, failed request, wrong state, layout, slowness). Use it instead of looking at screenshots.
4
4
  ---
5
5
 
6
6
  # verify-ui
@@ -19,7 +19,13 @@ Automated tests cover pure logic only, so the browser is the only check of what
19
19
  3. **agent-browser by hand**, in the session `probe.sh --keep` printed (or your own: `agent-browser session id --scope worktree --prefix task`), to explore while writing a scenario or chasing a bug: `snapshot -i -c`, act on `@eN` refs, `snapshot -i -c --delta` after each action. Close the session when done.
20
20
  4. **[`PLAYBOOK.md`](PLAYBOOK.md)**: read it when a verdict shows a problem and the cause is not obvious. It maps each symptom (dead click, wrong state, failed or missing request, layout, slowness, memory) to the one command that exposes it, including the few jobs that need the chrome-devtools MCP.
21
21
 
22
- Screenshots are for what the tree cannot say (a drawing, layout, colour). Save them as evidence (`shot <name>` in a scenario) and look at one only when the question is visual.
22
+ Screenshots are for what the tree cannot say (a drawing, layout, colour). Save them as evidence (`shot <name>` in a scenario) and look at one only when the question is visual. A verdict line costs a few dozen tokens and an image costs thousands, so never open an image to learn whether something loaded, exists or says the right thing.
23
+
24
+ ## When to use it
25
+
26
+ - **Building a feature:** write the ticket's scenario as you build, run it, then run the whole suite before reporting done.
27
+ - **Fixing a bug (UI or API):** reproduce it first as a scenario that fails for the reported reason (`probe.sh` and the playbook find the cause). Fix the code, watch the scenario pass, and keep it in the suite as the regression test. A bug with no failing scenario is not yet understood.
28
+ - **Reviewing:** run the suite yourself and read each new scenario as a test.
23
29
 
24
30
  ## Scenario files
25
31
 
@@ -41,7 +47,15 @@ A scenario proves a ticket when:
41
47
  - it asserts the effect as well as the screen: `expect-request` for an API call, `expect-storage` for saved data, `reload` then `expect-text` for persistence;
42
48
  - it covers the unhappy path the ticket names, forced with `network route <url> --abort`, `set offline on` or a mocked `--body`, with `allow-console` / `allow-request` naming exactly the errors that path is meant to produce;
43
49
  - it asserts what a person sees (text, URL, counts), and builds its own state from a fresh browser: each file runs alone, in any order;
44
- - it holds placeholder data only: credentials and real phone numbers or emails stay out of scenario files.
50
+ - it holds placeholder data only: credentials and real phone numbers or emails stay out of scenario files;
51
+ - every page it shows has an `expect-a11y` line (fails on critical and serious axe violations; the elements are saved to `a11y.txt` in the evidence folder);
52
+ - a screen whose look matters and that shows no clock, date or generated id has an `expect-shot <name>` line at a fixed viewport. It compares the screen with `baselines/<scenario>/<name>.png` beside the scenario file (committed). Look at the page first, then save or replace baselines with `UPDATE_BASELINES=1` on the same `run.sh` command; never update a baseline to make an unexplained difference pass.
53
+
54
+ Keep scenarios short and steady:
55
+ - **Shared steps:** put lines several scenarios repeat (sign in, create the first record) in `steps/<name>.txt` beside the scenario files and write `use <name> [args]`; `{1}`, `{2}` in the steps file are replaced by the args.
56
+ - **No sleeps:** `expect-*` lines and action lines (`find ... click`, `fill`) wait up to 5 seconds for the page. After an action whose result the next step depends on (a save, a sign-in, a sent message), assert that result with an `expect-*` line before navigating away.
57
+ - **Flaky scenarios:** a failed scenario runs once more. `FLAKY <name>` means it passed the second time; the line names the step that raced. Fix it with an `expect-*` line on the missing result, never with a wait. `RERUN=0` shows first failures only.
58
+ - **Scenarios that create data** must not run against an app with real data. Put a `guard.sh` beside them: it runs before the scenarios with `BASE_URL` set, and a non-zero exit refuses the run.
45
59
 
46
60
  ## First use: settings
47
61
 
@@ -16,10 +16,15 @@
16
16
  # expect-status <path> <code> HTTP status of a direct request, without the browser
17
17
  # expect-eval <js expression> evaluates to true in the page
18
18
  # expect-a11y [impacts] no axe violations of these impacts (default critical,serious)
19
+ # expect-shot <name> [max-percent] the screen matches baselines/<scenario>/<name>.png beside the scenario file
20
+ # (default 0.5% of pixels may differ); UPDATE_BASELINES=1 saves new baselines.
21
+ # Use it on screens with no clock, date or generated id, at a fixed viewport.
19
22
  # allow-console <regex> console errors matching this are expected in this scenario
20
23
  # allow-request <regex> 4xx/5xx requests matching this are expected (e.g. a 401 check)
21
24
  # shot <name> save a screenshot as evidence (a drawing, layout); path is printed
22
- # <anything else> an agent-browser command, must succeed:
25
+ # use <name> [args] run the lines of steps/<name>.txt beside the scenario file here;
26
+ # {1}, {2}, ... in that file are replaced by the args (shared sign-in, seeding)
27
+ # <anything else> an agent-browser command, must succeed (a missing element is retried for 5s):
23
28
  # find role button click --name "Save", fill, press, wait --text,
24
29
  # set viewport 390 844, set offline on, network route <url> --abort
25
30
  # Arguments with spaces: quote them where a command takes more than one (expect-value "#name" "Sam").
@@ -27,6 +32,12 @@
27
32
  # After every scenario, automatically: no uncaught page errors, no console errors, no 4xx/5xx
28
33
  # request to the app (unhandled promise rejections count as page errors). On FAIL the full tree, console,
29
34
  # errors, network list and a screenshot are saved; the FAIL block prints the folder.
35
+ #
36
+ # A failed scenario is run once more. If it then passes it is reported as FLAKY (with the first
37
+ # failure) and does not fail the suite: fix the race it names. RERUN=0 turns the second run off.
38
+ #
39
+ # A guard.sh beside the scenario files runs once before them (BASE_URL is exported to it). A non-zero
40
+ # exit refuses the run: use it to make sure scenarios that create data only run against a throwaway app.
30
41
  . ${0:A:h}/lib.sh
31
42
  need_server
32
43
 
@@ -36,6 +47,11 @@ for a in "$@"; do
36
47
  done
37
48
  (( ${#files} )) || { echo "SETUP: no scenario files"; exit 2; }
38
49
 
50
+ for d in ${(u)files:A:h}; do
51
+ [[ -f $d/guard.sh ]] || continue
52
+ BASE_URL=$base sh "$d/guard.sh" || { echo "SETUP: $d/guard.sh refused this run"; exit 2; }
53
+ done
54
+
39
55
  has_text() { tree | grep -qF -- "$1"; }
40
56
  url_has() { [[ $(ab get url) == *$1* ]]; }
41
57
  is_visible() { [[ $(ab is visible "$1") == true ]]; }
@@ -43,16 +59,39 @@ count_is() { [[ $(ab get count "$1") == $2 ]]; }
43
59
  value_is() { [[ $(ab get value "$1") == $2 ]]; }
44
60
  stored() { ab storage local "$1" | grep -qF -- "$2"; }
45
61
  requested() { requests | grep -F -- "] $1 " | grep -F -- "$2" | grep -qE "\) ${3:-[0-9]*}\$"; }
46
- js_true() { [[ $(ab eval -b "$(print -rn -- "$1" | base64)") == true ]]; }
62
+ js_true() { [[ $(ab eval -b "$(print -rn -- "$1" | base64 | tr -d '\n')") == true ]]; }
47
63
 
48
- passed=0; failed=0; S=""
49
- trap '[[ -n $S ]] && ab close >/dev/null 2>&1' EXIT; trap 'exit 130' INT TERM # an interrupted run must not leave a browser behind
50
- for f in $files; do
51
- name=${f:t:r}; S=verify-$name-$$; out=$outroot/$name
52
- step=0; fail=""; okcon=""; okreq=""; shots=()
53
- rm -rf "$out"
64
+ # Read a scenario into $lines, replacing each "use <name> [args]" by the lines of steps/<name>.txt.
65
+ load() {
66
+ local file=$1 depth=$2 line cmd arg inc i; shift 2
67
+ local -a params; params=("$@")
68
+ (( depth > 5 )) && { loaderr="use: nested deeper than 5 at $file"; return 1; }
54
69
  while IFS= read -r line || [[ -n $line ]]; do
55
70
  [[ -z ${line// } || $line == \#* ]] && continue
71
+ for (( i = 1; i <= ${#params}; i++ )); do line=${line//\{$i\}/$params[i]}; done
72
+ cmd=${line%% *}; arg=${line#* }
73
+ if [[ $cmd == use ]]; then
74
+ local -a u; u=("${(@Q)${(z)arg}}")
75
+ inc=${file:A:h}/steps/$u[1].txt
76
+ [[ -f $inc ]] || inc=$sdir/steps/$u[1].txt
77
+ [[ -f $inc ]] || { loaderr="use $u[1]: no steps/$u[1].txt beside $file"; return 1; }
78
+ load "$inc" $(( depth + 1 )) "${(@)u[2,-1]}" || return 1
79
+ else
80
+ lines+=("$line")
81
+ fi
82
+ done < "$file"
83
+ }
84
+
85
+ # Run one scenario file. Sets $fail (empty on success), $rep (the lines to print) and $step.
86
+ run_one() {
87
+ local f=$1 line cmd arg o e v i bl max pct warn
88
+ local -a w
89
+ S=verify-$name-$$; out=$outroot/$name
90
+ step=0; fail=""; okcon=""; okreq=""; shots=(); lines=(); loaderr=""; sdir=${f:A:h}
91
+ rm -rf "$out"
92
+ load "$f" 0 || fail=$loaderr
93
+ for line in $lines; do
94
+ [[ -n $fail ]] && break
56
95
  (( step++ ))
57
96
  cmd=${line%% *}; arg=${line#* }; w=("${(@Q)${(z)arg}}")
58
97
  case $cmd in
@@ -65,19 +104,41 @@ for f in $files; do
65
104
  expect-value) poll value_is "$w[1]" "${(j: :)w[2,-1]}" || fail="value of $w[1] is '$(ab get value "$w[1]")', wanted '${(j: :)w[2,-1]}'" ;;
66
105
  expect-storage) poll stored "$w[1]" "${(j: :)w[2,-1]}" || fail="localStorage $w[1] lacks '${(j: :)w[2,-1]}': $(ab storage local "$w[1]" | short)" ;;
67
106
  expect-request) poll requested "$w[1]" "$w[2]" "$w[3]" || fail="no $w[1] request matching '$w[2]'${w[3]:+ with status $w[3]}; api calls seen: $(api_requests | tail -3 | short | tr '\n' ' ')" ;;
68
- expect-status) got=$(curl -s -o /dev/null -w '%{http_code}' --max-time 5 "$base$w[1]")
69
- [[ $got == $w[2] ]] || fail="$w[1] returned $got, wanted $w[2]" ;;
107
+ expect-status) o=$(curl -s -o /dev/null -w '%{http_code}' --max-time 5 "$base$w[1]")
108
+ [[ $o == $w[2] ]] || fail="$w[1] returned $o, wanted $w[2]" ;;
70
109
  expect-eval) poll js_true "$arg" || fail="not true: $arg" ;;
71
110
  expect-a11y) [[ $arg == $cmd ]] && arg=critical,serious
72
- v=$(ab a11y | grep -E "^\[(${arg//,/|})\]" | short)
73
- [[ -n $v ]] && fail="accessibility: $(print -r -- "$v" | head -4 | tr '\n' ' ')" ;;
111
+ for i in 1 2 3 4; do # colours in the middle of a transition read as low contrast: let them settle
112
+ # Violations only: axe lists what it could not decide under "incomplete".
113
+ v=$(ab a11y | sed '/^incomplete/,$d' | grep -E "^\[(${arg//,/|})\]" | short)
114
+ [[ -z $v ]] && break; sleep 0.5
115
+ done
116
+ [[ -n $v ]] && { mkdir -p "$out"; ab a11y > "$out/a11y.txt"; fail="accessibility: $(print -r -- "$v" | head -4 | tr '\n' ' ') (elements: $out/a11y.txt)"; } ;;
117
+ expect-shot) # Compare with the committed baseline; UPDATE_BASELINES=1 saves a new one instead.
118
+ bl=${f:A:h}/baselines/$name/$w[1].png; max=${w[2]:-0.5}
119
+ mkdir -p "$out" "${bl:h}"
120
+ ab eval "document.fonts.ready.then(() => true)" >/dev/null; sleep 0.3
121
+ if [[ -n $UPDATE_BASELINES ]]; then
122
+ o=$(ab screenshot "$bl") || fail="screenshot: $o"
123
+ elif [[ ! -f $bl ]]; then
124
+ fail="no baseline $bl; look at the page, then rerun with UPDATE_BASELINES=1 to save it"
125
+ else
126
+ o=$(ab diff screenshot --baseline "$bl" --output "$out/$w[1].diff.png")
127
+ pct=$(print -r -- "$o" | grep -oE '[0-9.]+%' | head -1 | tr -d '%')
128
+ [[ -n $pct ]] && (( pct <= max )) || fail="screen differs from baseline $w[1] by ${pct:-?}% (allowed $max%); diff image: $out/$w[1].diff.png; if the change is intended rerun with UPDATE_BASELINES=1"
129
+ fi ;;
74
130
  allow-console) okcon=${okcon:+$okcon|}$arg ;;
75
131
  allow-request) okreq=${okreq:+$okreq|}$arg ;;
76
132
  shot) mkdir -p "$out"; o=$(ab screenshot "$out/$arg.png") && shots+=("$out/$arg.png") || fail="screenshot: $o" ;;
77
- *) o=$(eval "ab $line") || fail="'$line' failed: $(print -r -- "$o" | tail -2 | tr '\n' ' ')" ;;
133
+ *) # An element that is not there yet (page still loading) is retried like an expect; any other error fails at once.
134
+ for i in 1 2 3 4 5 6 7 8 9 10; do
135
+ o=$(eval "ab $line") && break
136
+ [[ ( $o == *"No element found"* || $o == *"but none match"* ) && $i != 10 ]] || { fail="'$line' failed: $(print -r -- "$o" | tail -2 | tr '\n' ' ')"; break; }
137
+ sleep 0.5
138
+ done ;;
78
139
  esac
79
- [[ -n $fail ]] && { fail="step $step: $fail"; break; }
80
- done < "$f"
140
+ [[ -n $fail ]] && fail="step $step: $fail"
141
+ done
81
142
 
82
143
  if [[ -z $fail ]]; then
83
144
  e=$(page_errors | head -3 | short)
@@ -98,16 +159,30 @@ for f in $files; do
98
159
  rep="FAIL $name: $fail"$'\n'" url: $(ab get url)"$'\n'"$(itree | head -15 | short | sed 's/^/ | /')"
99
160
  evidence "$out"; ab screenshot "$out/fail.png" >/dev/null
100
161
  rep+=$'\n'" evidence: $out (tree.txt console.txt errors.txt network.txt fail.png)"
101
- (( failed++ ))
102
162
  else
103
163
  warn=$(console_of warning | wc -l | tr -d ' ')
104
164
  (( warn )) && warn=", $warn console warnings" || warn=""
105
165
  rep="PASS $name ($step steps$warn)"
106
166
  (( ${#shots} )) && rep+=$'\n'" shots: $shots"
107
- (( passed++ ))
108
167
  fi
109
168
  ab close >/dev/null 2>&1; S=""
169
+ }
170
+
171
+ passed=0; failed=0; flaky=0; S=""
172
+ trap '[[ -n $S ]] && ab close >/dev/null 2>&1' EXIT; trap 'exit 130' INT TERM # an interrupted run must not leave a browser behind
173
+ for f in $files; do
174
+ name=${f:t:r}
175
+ run_one "$f"
176
+ if [[ -n $fail && ${RERUN:-1} != 0 && -z $UPDATE_BASELINES ]]; then
177
+ first=$fail
178
+ run_one "$f"
179
+ if [[ -z $fail ]]; then
180
+ rep="FLAKY $name: passed on the second run; first run failed at $first"
181
+ (( flaky += 1 ))
182
+ fi
183
+ fi
184
+ if [[ -n $fail ]]; then (( failed += 1 )); else (( passed += 1 )); fi
110
185
  print -r -- "$rep"
111
186
  done
112
- echo "SUITE: $passed passed, $failed failed"
187
+ (( flaky )) && echo "SUITE: $passed passed ($flaky flaky), $failed failed" || echo "SUITE: $passed passed, $failed failed"
113
188
  (( failed == 0 ))