Gherkin Derive
Role: worker. A standalone Gherkin derivation skill. It derives scenarios for
a repo's public surface directly from code — it does not require any prior
/cd-test-architecture analysis, and it does not create tracker Stories
(the calling orchestrator owns triage). /gherkin-public remains a
public-boundary Gherkin authoring worker used standalone.
Usable two ways: on its own to capture intended behavior before any test change,
or as the Phase-3 sub-step of /test-improve.
Parse Arguments
- Positional:
<repo-path>(default: cwd). --mode <none|xunit-with-annotations|bdd-runner>— the binding mode. When
omitted, present the BDD value rubric (Step 1) and let the operator choose.
--repo-slug <slug>— namespace for the surface inventory under
.claude/memory/<workflow>/<slug>/ (/test-improve passes --workflow test-improve).
Step 1 — Choose the binding mode (BDD value rubric)
If --mode was not supplied, present the 5-question rubric from
knowledge/references/bdd-value-guide.md and recommend a mode from the score:
≥ 3 yes→bdd-runner1–2 yes→xunit-with-annotations0 yes→none
Show the recommendation and let the operator override. The three modes:
none— emit no Gherkin. Exit immediately with a one-line recommendation
to use plain xUnit (e.g. *"0/5 BDD signals — use plain xUnit; no .feature
files written."*). Write no files.
xunit-with-annotations— derive scenarios and write.featurefiles, but
do NOT wire a BDD runner or install any framework. The files are
documentation that /build cites in test method names and leading comments.
bdd-runner— derive scenarios, write.featurefiles, wire the
language-appropriate BDD framework (Step 4), and generate pending step
definition stubs.
Step 2 — Discover the public surface
No pre-computed component map is required. Discover surfaces in this **priority
order**, most authoritative first:
- OpenAPI / Swagger spec (
openapi.yaml,openapi.json,swagger.json) —
the most authoritative description of the public surface. Each path+method is
a surface.
- Route definitions — Express/Fastify handlers, Spring
@Controller/
@RestController, ASP.NET [ApiController], Go http.HandleFunc / Chi / Gin
routes. Each registered route is a surface.
- Existing test names —
describe/it/[Fact]/@Testblocks. These
yield characterization scenarios (current behavior, not intended
behavior). Use them as the primary source only when OpenAPI and routes do
not already cover the surface. **Never treat a test's assertion as ground
truth on its own** — before accepting a test-derived scenario, cross-check
it against any other available signal (docstrings, comments, adjacent
OpenAPI/route info, obvious status-code conventions). Record what was
cross-checked (or that nothing was found) per Step 3.
- Public function signatures + docstrings — exported functions/classes with
doc comments. The lowest-priority fallback for libraries with no HTTP surface.
Stop climbing the list for the same surface description once a
higher-priority source covers it — do not duplicate a route's success/failure
scenarios from its tests. But do not let this rule discard information: even
when a surface is already covered by OpenAPI or a route, still scan its
existing tests for error/edge branches that are not present in the
documented spec, and add those as supplemental characterization scenarios
rather than dropping them.
Graph-assisted discovery. Prefer CodeGraph/Repowise over raw Grep for
locating routes, handlers, and exported signatures — see