@anselmdk/feature-spec-md 0.4.0 → 0.5.0-rc.1

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.
Files changed (39) hide show
  1. package/README.md +59 -78
  2. package/SPEC_FORMAT.md +38 -78
  3. package/dist/cli.js +75 -81
  4. package/dist/cli.js.map +1 -1
  5. package/dist/featureSpecs.d.ts +1 -1
  6. package/dist/featureSpecs.d.ts.map +1 -1
  7. package/dist/featureSpecs.js +57 -10
  8. package/dist/featureSpecs.js.map +1 -1
  9. package/dist/githubActionDiffReport.d.ts +4 -0
  10. package/dist/githubActionDiffReport.d.ts.map +1 -0
  11. package/dist/githubActionDiffReport.js +209 -0
  12. package/dist/githubActionDiffReport.js.map +1 -0
  13. package/dist/githubActionFtp.d.ts +25 -0
  14. package/dist/githubActionFtp.d.ts.map +1 -0
  15. package/dist/githubActionFtp.js +210 -0
  16. package/dist/githubActionFtp.js.map +1 -0
  17. package/dist/githubActionOutput.d.ts +3 -0
  18. package/dist/githubActionOutput.d.ts.map +1 -0
  19. package/dist/githubActionOutput.js +33 -0
  20. package/dist/githubActionOutput.js.map +1 -0
  21. package/dist/githubActionReport.d.ts +2 -1
  22. package/dist/githubActionReport.d.ts.map +1 -1
  23. package/dist/githubActionReport.js +15 -182
  24. package/dist/githubActionReport.js.map +1 -1
  25. package/dist/index.d.ts +2 -2
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +1 -1
  28. package/dist/index.js.map +1 -1
  29. package/dist/reportTemplate.js +37 -33
  30. package/dist/reportTemplate.js.map +1 -1
  31. package/dist/screenshots.d.ts +3 -1
  32. package/dist/screenshots.d.ts.map +1 -1
  33. package/dist/screenshots.js +23 -0
  34. package/dist/screenshots.js.map +1 -1
  35. package/dist/types.d.ts +11 -1
  36. package/dist/types.d.ts.map +1 -1
  37. package/docs/evidence-policy.md +63 -0
  38. package/docs/spec-driven-flow.md +67 -8
  39. package/package.json +1 -1
package/README.md CHANGED
@@ -20,23 +20,13 @@ It gives you:
20
20
  - **Stable IDs** for model items, rules, and scenarios, so tests can reference exactly what they implement.
21
21
  - **Validation** that checks frontmatter, headings, IDs, cross-document references, and test coverage expectations.
22
22
  - **Coverage reporting** that shows which model items, rules, and scenarios are implemented by tests.
23
+ - **Scenario evidence policy** so specs can declare whether behavior should be tested by unit, integration, Playwright, manual, or no executable tests.
23
24
  - **HTML reports** that are useful for reviews, CI artifacts, or published build reports.
24
25
  - **Screenshot evidence** for scenarios when using the Playwright helper.
25
26
  - **A library API** for projects that want to parse specs, check coverage, collect screenshots, or render reports from their own tooling.
26
27
 
27
28
  The specs are meant to be written with an AI before implementation. The tests are meant to be written with an AI from those specs. `feature-spec-md` then checks that the Markdown stays structured and that executable tests still cover the model items, rules, and scenarios the specs define.
28
29
 
29
- ## Why this exists
30
-
31
- AI can write tests quickly, but it needs a stable source of truth. Free-form product notes are often too ambiguous, and generated tests are hard to audit later. `feature-spec-md` keeps the source of truth in readable Markdown and makes the AI preserve IDs such as `ACCOUNT-M001`, `TICKET-R001`, or `TICKET-S001` in the generated tests.
32
-
33
- That gives humans a simple review loop:
34
-
35
- 1. Read the Markdown spec.
36
- 2. Read or run the generated tests.
37
- 3. Run `feature-spec-md check` or `coverage` to see what is missing.
38
- 4. Open the HTML report to review the implemented scenarios, rules, model items, and screenshots.
39
-
40
30
  ## Demo project
41
31
 
42
32
  A complete demo app is available in [`anselmdk/feature-spec-md-demo`](https://github.com/anselmdk/feature-spec-md-demo). It shows a small support-ticket desk built from model, feature, stack, and design specs, with unit tests, Playwright tests, generated coverage, and a published report.
@@ -75,9 +65,24 @@ A person who has completed registration and can request sign-in links.
75
65
  Feature specs describe user-facing behavior with rules and scenarios. Rules and scenarios get stable IDs that tests can reference.
76
66
 
77
67
  ```md
78
- ### ACCOUNT-ACCESS-R001: Sign-in links expire
68
+ ---
69
+ id: ACCOUNT-ACCESS
70
+ title: Account access
71
+ test: playwright
72
+ screenshots: required
73
+ ---
74
+
75
+ # Account access
76
+
77
+ ## Purpose
78
+
79
+ Allow registered people to access their account securely.
80
+
81
+ ## Rules
82
+
83
+ - ACCOUNT-ACCESS-R001: Sign-in links MUST expire.
79
84
 
80
- Sign-in links can only be used within the configured expiry window.
85
+ ## Scenarios
81
86
 
82
87
  ### ACCOUNT-ACCESS-S001: Registered person signs in
83
88
 
@@ -86,6 +91,27 @@ When they request and open a valid sign-in link
86
91
  Then they are signed in
87
92
  ```
88
93
 
94
+ Feature specs can declare the expected test and evidence policy:
95
+
96
+ ```txt
97
+ test: unit | integration | playwright | manual | skip
98
+ screenshots: required | optional | skip
99
+ ```
100
+
101
+ If `screenshots` is omitted, Playwright scenarios default to `required`; non-Playwright scenarios default to `skip`. Scenario-level overrides can be written directly below a scenario heading:
102
+
103
+ ```md
104
+ ### ACCOUNT-ACCESS-S002: Link expiry is calculated
105
+ Test: unit
106
+ Screenshots: skip
107
+
108
+ Given a sign-in link was created 31 minutes ago
109
+ When expiry is calculated
110
+ Then the link is expired
111
+ ```
112
+
113
+ See [SPEC_FORMAT.md](SPEC_FORMAT.md) and [docs/evidence-policy.md](docs/evidence-policy.md) for the exact format.
114
+
89
115
  ### Stack specs
90
116
 
91
117
  Stack specs document technical decisions that shape the implementation: framework, storage, test runner, deployment constraints, external services, or architecture decisions.
@@ -94,8 +120,6 @@ Stack specs document technical decisions that shape the implementation: framewor
94
120
 
95
121
  Design specs capture product, UI, and interaction direction: layout priorities, states, accessibility expectations, empty states, or copy tone.
96
122
 
97
- See [SPEC_FORMAT.md](SPEC_FORMAT.md) for the exact document format.
98
-
99
123
  ## How tests connect to specs
100
124
 
101
125
  Tests reference spec IDs in titles, tags, annotations, comments, or metadata. The tool scans test files and matches those references back to the Markdown documents.
@@ -126,11 +150,12 @@ npx feature-spec-md init --kind design --dir specs
126
150
  ## Workflow
127
151
 
128
152
  1. Ask an AI to draft or update `*.model.md`, `*.feature.md`, `*.stack.md`, and `*.design.md` files.
129
- 2. Run `npx feature-spec-md check` until the spec set is valid.
130
- 3. Ask an AI to write executable tests from the specs, preserving the relevant `-M001`, `-R001`, and `-S001` IDs in the test source.
131
- 4. Run `npx feature-spec-md coverage` to see which scenarios, rules, and model items have tests.
132
- 5. Run `npx feature-spec-md report` to generate an HTML implementation report for review or CI artifacts.
133
- 6. Use `npx feature-spec-md github-report` in GitHub Actions when the report should be linked from the job summary or published.
153
+ 2. Declare each feature/scenario test evidence policy where the default is not right.
154
+ 3. Run `npx feature-spec-md check` until the spec set is valid.
155
+ 4. Ask an AI to write executable tests from the specs, preserving the relevant `-M001`, `-R001`, and `-S001` IDs in the test source.
156
+ 5. Run `npx feature-spec-md coverage` to see which scenarios, rules, and model items have tests.
157
+ 6. Run `npx feature-spec-md report` to generate an HTML implementation report for review or CI artifacts.
158
+ 7. Use `npx feature-spec-md github-report` in GitHub Actions when the report should be linked from the job summary or published.
134
159
 
135
160
  The longer flow, including AI prompts and CI setup, is in [docs/spec-driven-flow.md](docs/spec-driven-flow.md). The demo repository also shows the flow in practice: <https://github.com/anselmdk/feature-spec-md-demo>.
136
161
 
@@ -161,16 +186,6 @@ npx feature-spec-md check \
161
186
  --tests "e2e/**/*.spec.ts"
162
187
  ```
163
188
 
164
- ### `init`
165
-
166
- Creates starter Markdown files for one spec kind.
167
-
168
- ```bash
169
- npx feature-spec-md init --kind feature --dir specs
170
- ```
171
-
172
- Supported kinds are `model`, `feature`, `stack`, and `design`.
173
-
174
189
  ### `check`
175
190
 
176
191
  Validates the spec set and, by default, requires scenario coverage when tests are scanned.
@@ -181,12 +196,6 @@ npx feature-spec-md check
181
196
 
182
197
  `check` validates spec structure, references between documents, and test coverage. Use `--require-scenario-coverage=false` while drafting. Use `--require-rule-coverage` and `--require-model-coverage` when rules and model items must also fail validation if they have no test references.
183
198
 
184
- The demo uses stricter coverage gates for all tests:
185
-
186
- ```bash
187
- feature-spec-md check --tests "tests/**/*.ts" --require-rule-coverage --require-model-coverage
188
- ```
189
-
190
199
  ### `coverage`
191
200
 
192
201
  Prints a terminal implementation report showing covered and missing model items, rules, and scenarios.
@@ -214,19 +223,20 @@ npx feature-spec-md report \
214
223
  --screenshots "test-results/spec-report/screenshots-*.json"
215
224
  ```
216
225
 
217
- The demo report is published at <https://feature-spec-md.anselm.dk/demo/> and includes scenario screenshots, so it is the best place to see what the report output looks like.
218
-
219
- ### `github-report`
220
-
221
- Writes a GitHub Actions job summary and prepares the generated report for either artifact upload or FTP publishing.
226
+ When CI should fail for missing declared screenshot evidence, add `--enforce-evidence`:
222
227
 
223
228
  ```bash
224
- npx feature-spec-md github-report \
225
- --report-dir test-results/spec-report \
226
- --publish artifact
229
+ npx feature-spec-md report \
230
+ --screenshots "test-results/spec-report/screenshots-*.json" \
231
+ --enforce-evidence \
232
+ --out test-results/spec-report/index.html
227
233
  ```
228
234
 
229
- Use `--publish ftp` when the report should be uploaded to a public report site from CI.
235
+ This gate only fails for scenarios whose resolved screenshot policy is `required`.
236
+
237
+ ### `github-report`
238
+
239
+ Writes a GitHub Actions job summary and prepares the generated report for either artifact upload or FTP publishing.
230
240
 
231
241
  ```bash
232
242
  npx feature-spec-md github-report \
@@ -238,29 +248,13 @@ npx feature-spec-md github-report \
238
248
 
239
249
  The package exports a Playwright helper from `@anselmdk/feature-spec-md/playwright`. It maps scenario step text back to the spec line, wraps the implementation in a Playwright `test.step`, captures a screenshot after the step, attaches it to the test, and writes a screenshot manifest such as `test-results/spec-report/screenshots-0.json`.
240
250
 
241
- That manifest can then be passed to `feature-spec-md report` with `--screenshots "test-results/spec-report/screenshots-*.json"` so the HTML report can show scenario evidence next to the relevant spec step.
251
+ That manifest can then be passed to `feature-spec-md report` with `--screenshots "test-results/spec-report/screenshots-*.json"` so the HTML report can show scenario evidence next to the relevant spec step. With `--enforce-evidence`, missing screenshots fail only for scenarios declared as `screenshots: required`.
242
252
 
243
253
  ## GitHub Actions report publishing
244
254
 
245
255
  `feature-spec-md github-report` writes the GitHub Actions job summary and can either prepare outputs for a GitHub artifact upload or publish the generated report to FTP.
246
256
 
247
- ```bash
248
- npx feature-spec-md github-report \
249
- --report-dir test-results/spec-report \
250
- --publish ftp
251
- ```
252
-
253
- For FTP publishing, configure repository secrets in GitHub under **Settings → Secrets and variables → Actions → Repository secrets**. For this repository, the direct settings URL is:
254
-
255
- ```txt
256
- https://github.com/anselmdk/feature-spec-md/settings/secrets/actions
257
- ```
258
-
259
- GitHub's documentation for repository secrets is here:
260
-
261
- ```txt
262
- https://docs.github.com/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository
263
- ```
257
+ For FTP publishing, configure repository secrets in GitHub under **Settings → Secrets and variables → Actions → Repository secrets**.
264
258
 
265
259
  Required secrets or environment variables:
266
260
 
@@ -292,20 +286,6 @@ Example GitHub Actions step:
292
286
  FEATURE_SPEC_REPORT_BASE_URL: ${{ secrets.FEATURE_SPEC_REPORT_BASE_URL }}
293
287
  ```
294
288
 
295
- With `FEATURE_SPEC_REPORT_BASE_URL=http://feature-spec-md.anselm.dk/` and GitHub Actions build number `42`, the report is uploaded to a build-numbered directory and linked as:
296
-
297
- ```txt
298
- http://feature-spec-md.anselm.dk/42/
299
- ```
300
-
301
- The build index is created or updated at:
302
-
303
- ```txt
304
- http://feature-spec-md.anselm.dk/
305
- ```
306
-
307
- FTP reports are uploaded into a build-numbered directory using `GITHUB_RUN_NUMBER`, and an `index.html` file is created or updated at the public base URL so all uploaded builds can be browsed. When FTP publishing is used, the command emits `upload-github-artifact=false` and links the GitHub Actions job summary directly to the hosted report URL.
308
-
309
289
  ## Library API
310
290
 
311
291
  Most integrations can use the top-level document API:
@@ -316,6 +296,7 @@ import {
316
296
  collectSpecScreenshots,
317
297
  parseSpecDocument,
318
298
  renderHtmlReport,
299
+ validateScenarioScreenshots,
319
300
  validateSpecDocument,
320
301
  } from "@anselmdk/feature-spec-md";
321
302
  ```
@@ -326,8 +307,8 @@ Useful exports include:
326
307
  - `validateSpecDocument` and `validateSpecGraph` for checking one document or a connected spec set.
327
308
  - `checkSpecDocuments` for loading specs and tests, validating documents, and computing coverage in one call.
328
309
  - `buildSpecCoverageSummary` and `collectSpecTestReferences` for custom coverage workflows.
310
+ - `collectSpecScreenshots` and `validateScenarioScreenshots` for loading and enforcing screenshot evidence.
329
311
  - `renderHtmlReport` for generating the same report UI from your own integration.
330
- - `collectSpecScreenshots` for loading screenshot manifest files before rendering a report.
331
312
  - `writeTextFile` for small report-writing integrations.
332
313
 
333
314
  Feature-only helpers such as `parseFeatureSpec` and `checkFeatureSpecs` remain available for compatibility.
package/SPEC_FORMAT.md CHANGED
@@ -20,15 +20,6 @@ A spec set can contain four document types:
20
20
  - `*.stack.md` defines technical platform choices and their rationale.
21
21
  - `*.design.md` defines product, UI, layout, visual, and interaction direction.
22
22
 
23
- The short version:
24
-
25
- ```txt
26
- model tells tests what things mean
27
- features tell tests what behavior must work
28
- stack tells implementation what tools and constraints to use
29
- design tells implementation what experience to create
30
- ```
31
-
32
23
  ## Frontmatter
33
24
 
34
25
  Every file starts with YAML-like frontmatter:
@@ -53,6 +44,8 @@ Optional fields:
53
44
  - `owner`
54
45
  - `model`: a single referenced model id, for feature and design files
55
46
  - `models`: comma-separated referenced model ids, for feature and design files
47
+ - `test`: default scenario test type for feature files
48
+ - `screenshots`: default screenshot evidence policy for feature files
56
49
 
57
50
  IDs use uppercase words separated by hyphens. IDs are the contract between specs, tests, reports, and implementation work.
58
51
 
@@ -128,115 +121,81 @@ When they create a card with the title "Write release notes"
128
121
  Then the card "Write release notes" is visible in the To do column
129
122
  ```
130
123
 
131
- Allowed step keywords:
132
-
133
- - `Given`
134
- - `When`
135
- - `Then`
136
- - `And`
137
- - `But`
124
+ Allowed step keywords are `Given`, `When`, `Then`, `And`, and `But`.
138
125
 
139
126
  Rules state durable product truths. Scenarios show concrete examples that executable tests can implement.
140
127
 
141
- ## Stack Files
142
-
143
- Stack files use the `.stack.md` suffix.
128
+ ### Scenario Test And Evidence Policy
144
129
 
145
- A stack file defines technical platform choices and the reasoning behind them.
130
+ Feature specs can declare how scenarios are expected to be tested and whether screenshot evidence is required.
146
131
 
147
- Required sections:
132
+ Feature-level frontmatter sets defaults for all scenarios in a feature:
148
133
 
149
134
  ```md
150
- # Kanban tech stack
151
-
152
- ## Purpose
153
-
154
- ## Stack
135
+ ---
136
+ id: KANBAN-CARD-AUTHORING
137
+ title: Card authoring
138
+ test: playwright
139
+ screenshots: required
140
+ ---
155
141
  ```
156
142
 
157
- Optional sections:
143
+ Scenario-level overrides go directly below a scenario heading:
158
144
 
159
145
  ```md
160
- ## Context
146
+ ### KANBAN-CARD-AUTHORING-S002: Card title is normalized
147
+ Test: unit
148
+ Screenshots: skip
161
149
 
162
- ## Rationale
163
-
164
- ## Consequences
150
+ Given the raw card title contains leading whitespace
151
+ When the title is normalized
152
+ Then the stored title has no leading whitespace
165
153
  ```
166
154
 
167
- Example:
155
+ Supported `test` values are `unit`, `integration`, `playwright`, `manual`, and `skip`.
168
156
 
169
- ```md
170
- ---
171
- id: KANBAN-STACK
172
- title: Kanban tech stack
173
- status: draft
174
- ---
157
+ Supported `screenshots` values are `required`, `optional`, and `skip`. `screenshots: none` is accepted as an alias for `screenshots: skip`.
175
158
 
176
- # Kanban tech stack
159
+ Defaults:
177
160
 
178
- ## Purpose
161
+ - If `test` is omitted, scenarios default to `unit`.
162
+ - If `screenshots` is omitted and `test` resolves to `playwright`, screenshots default to `required`.
163
+ - If `screenshots` is omitted and `test` resolves to `unit`, `integration`, `manual`, or `skip`, screenshots default to `skip`.
179
164
 
180
- Define the initial technical stack for implementing the Kanban board.
165
+ See [Scenario Test And Evidence Policy](docs/evidence-policy.md) for details and CI examples.
181
166
 
182
- ## Stack
183
-
184
- | Area | Choice |
185
- | -------- | ---------- |
186
- | Frontend | React |
187
- | Language | TypeScript |
188
- | Testing | Playwright |
189
- ```
190
-
191
- ## Design Files
192
-
193
- Design files use the `.design.md` suffix.
167
+ ## Stack Files
194
168
 
195
- A design file defines product, UI, layout, visual, and interaction direction.
169
+ Stack files use the `.stack.md` suffix and define technical platform choices and the reasoning behind them.
196
170
 
197
171
  Required sections:
198
172
 
199
173
  ```md
200
- # Kanban board design
174
+ # Kanban tech stack
201
175
 
202
176
  ## Purpose
203
177
 
204
- ## Design
178
+ ## Stack
205
179
  ```
206
180
 
207
- Optional sections:
208
-
209
- ```md
210
- ## Principles
211
-
212
- ## Layout
181
+ Optional sections are `## Context`, `## Rationale`, and `## Consequences`.
213
182
 
214
- ## Interaction
183
+ ## Design Files
215
184
 
216
- ## Visual style
217
- ```
185
+ Design files use the `.design.md` suffix and define product, UI, layout, visual, and interaction direction.
218
186
 
219
- Example:
187
+ Required sections:
220
188
 
221
189
  ```md
222
- ---
223
- id: KANBAN-DESIGN
224
- title: Kanban board design
225
- status: draft
226
- model: KANBAN
227
- ---
228
-
229
190
  # Kanban board design
230
191
 
231
192
  ## Purpose
232
193
 
233
- Define the visual and interaction design direction for the Kanban board.
234
-
235
194
  ## Design
236
-
237
- The board should feel lightweight, immediate, and calm.
238
195
  ```
239
196
 
197
+ Optional sections are `## Principles`, `## Layout`, `## Interaction`, and `## Visual style`.
198
+
240
199
  ## Splitting Guidance
241
200
 
242
201
  Split model files by coherent domain vocabulary, ownership, or lifecycle.
@@ -251,7 +210,7 @@ Keep each document small enough for an AI to read, revise, and use as test-writi
251
210
 
252
211
  ## Test Coverage Convention
253
212
 
254
- Spec files do not contain test mappings.
213
+ Spec files declare expected test and evidence policy, but they do not map scenarios to concrete test files.
255
214
 
256
215
  Tests reference model item, rule, and scenario IDs in test titles, tags, annotations, comments, or metadata.
257
216
 
@@ -261,6 +220,7 @@ Generated tooling can answer:
261
220
  - Which scenarios have tests?
262
221
  - Which rules have executable coverage?
263
222
  - Which tests reference deleted or unknown spec IDs?
223
+ - Which scenarios are expected to have screenshot evidence?
264
224
  - Which visible flows have screenshots, traces, or other evidence?
265
225
 
266
226
  Example: