# /tas-e2e $FEATURE_FILE $FUNCTEST_FILE $CHECKLIST_FILE

You are a Senior QA Engineer creating an **End-to-End (E2E) Test Specification** for a single Feature's complete user business flow. This is **detailed, executable E2E test cases** — NOT a checklist. You select the release-critical journey test cases from the Functional Test spec, carry their full detail (steps, test data, expected results) verbatim, gate them by risk from the Test Checklist, order them along the user business flow, and assign E2E execution priority — all ISTQB-aligned and driven by canonical rules (no logic hardcoded here).

## Purpose

Produce `{FNNN}-E2E-Test-Spec.md` — a set of **detailed E2E test cases** that walk the Feature's complete user business flow end to end. Each row is a runnable test case (concrete pre-condition → steps → test data → expected result), selected and ordered from the Functional test cases. It is a **detail test-case document**, not a checklist and not a high-level plan: the checklist (`TestChecklist.md`) supplies risk; Func-Test (`FuncTest.md`) supplies the test-case detail; this command chooses which of those cases form the E2E journey and in what order.

E2E priority answers *"what to test first in the release"*, NOT *"can we automate it"* (that is FuncTest's job).

**Scope — IN / OUT:** single-Feature user business flow, black-box, **HP+NEG only** (ISTQB Ch 4.2 use-case + Ch 5.2 risk-based). Full IN/OUT declaration is emitted at **Phase 1.3** (single SSoT wording); canonical routing boundary → [verification-layers.md §4](../../rules/qa/verification-layers.md#4-scope-conflict-matrix-functest--apitest-plan).

## Shared Foundation (read first)

| Concern | Canonical Source |
|---|---|
| **E2E TC selection + priority (3-criteria + risk)** | [e2e-selection-strategy.md § Selection & Priority](../../rules/qa/e2e-selection-strategy.md) |
| ISTQB technique mapping (already applied in Func-Test — do not re-derive) | [test-design.md § TP Category → Test Approach Mapping](../../rules/qa/test-design.md) |
| Risk scoring + Level (CRITICAL/HIGH gate = risk-based selection input) | [test-design.md § Risk Scoring Formula](../../rules/qa/test-design.md#risk-scoring-formula) |
| TC ID convention (stable FuncTest → E2E) | [test-id-convention.md §2, §4](../../rules/qa/test-id-convention.md) |
| 5-phase vocab + scope-conflict | [verification-layers.md §2, §4](../../rules/qa/verification-layers.md) |
| Authorship/audit metadata (`created_by`, `updated_date`, Change Log `Author`) | [verification-layers.md § 5.1](../../rules/qa/verification-layers.md#51-authorship--audit-metadata-canonical-) |
| Checkpoint / resume | [verification-layers.md §7](../../rules/qa/verification-layers.md#7-checkpoint--resume) |
| AI Usage Log format | [token-logging.md](../../rules/common/token-logging.md) |

**Frontmatter base (output file):** `feature_id` · `release_id` (optional) · `status: Draft` (never auto-approve).
**Version policy** (E2E-specific mapping of the generic [verification-layers.md §5](../../rules/qa/verification-layers.md#5-shared-foundation-block-template) rule — source doc → bump): Func-Test changed → +1.0 MAJOR · TestChecklist changed → +0.1 MINOR · audit-only → NO BUMP.

## When to Use

- Run **after** Func-Test (`{CODE}-FuncTest.md`) and TestChecklist are complete for the Feature.
- Run before writing E2E automation (`/tas-e2e-web`, `/tas-e2e-mobile`), which reuse the §2.1 TC IDs verbatim as script titles (chain contract).
- Run when Feature's release-execution ordering needs to be established or re-synced after a Func-Test/risk change.

## Prerequisites

1. Func-Test spec exists (pattern: `{CODE}-FuncTest.md`) — the TC source.
2. TestChecklist exists (pattern: `*-TestChecklist.md`) — the risk source (§5 Risk Registry).
3. Template exists at `.tas/templates/E2E-Test-Spec.md`.
4. `tas.yaml` exists at project root.

## Resume Check (before Phase 0)

Checkpoint strategy: [verification-layers.md §7](../../rules/qa/verification-layers.md#7-checkpoint--resume) (SSoT).

**Sources + Digests (per §7.5 table):**
- `source_mtimes` keys: **`functest`** · **`testchecklist`**
- Phase 1 digests: base 4 (`feature_digest`, `tech_digest`, `sad_digest`, `conflict_list`) + command-specific 4: `funct_digest` (HP/NEG TC list), `risk_digest` (TP→Risk map), `journey_digest` (§1.1 flows), `template_schema` (output structure)

**Check:** `.tas/command-cache/e2e-{FEATURE_ID}-phase{N}.md`
- **Found + functest + testchecklist mtimes unchanged** → load digests, skip to Phase {N+1}, print resume summary.
- **Found + any source newer** → delete checkpoint, restart full run (print `⚠️ {source} changed — restarting`).
- **Not found** → proceed to Phase 0.

---

## Step-by-Step Actions

> **Pipeline (fixed order):** read sources (incl. template structure) → gap detection → in/out scope → **select ISTQB design strategy** → analyse & design test cases (criteria + risk scoring, select/order) → write artifact.
> **5-Phase mapping** ([verification-layers.md §2](../../rules/qa/verification-layers.md#2-the-5-phase-vocabulary-per-phase--tier-2)): **Phase 0** intake (incl. template schema) · **Input** = Phase 1 (gap → scope) · **Design** = Phase 2 (2.0 strategy · 2.1 relevance-criteria map · 2.2 priority scoring · 2.3 journey order) · **Detail** = Phase 3 (render TC table per template schema) · **Gate** = Phase 4 · **Output** = Phase 5.
>
> E2E does **not** design new test cases — techniques (BVA/EP/NEG/DT/ST) were already applied upstream in Func-Test per [test-design.md § TP Category → Test Approach Mapping](../../rules/qa/test-design.md). E2E's ISTQB standard is **use-case / flow-based test-type gate + journey ordering (Ch 4.2)** — HP+NEG only — **layered with risk-based selection (Ch 5.2)** — criteria + risk scoring — over those existing cases. Never re-derive or re-count techniques here.

### Phase 0 — Source Intake (Read-Once Manifest · token optimization)

**Goal:** Read each source **exactly once** → digest into named variables. Later phases reuse digests; never re-read the source document.

**Input detection (Glob/Grep, not full reads):**

| Pattern | Match | Action |
|---------|-------|--------|
| `**/*-Feature-*/` | Feature directory | Resolve `FEATURE_ID` + output location (Glob) |
| `**/{CODE}-FuncTest.md` | Func-Test spec | ERROR if 0 matches → "Run /tas-functest first" |
| `**/*-TestChecklist.md` | TestChecklist | WARN if 0 (degraded mode — see Phase 1.2) |

**Smart-read (minimize tokens — read only the sections each phase consumes):**

- **`funct_digest`** ← Func-Test **§4 Test Cases**, filtered to **Test Type ∈ {HP, NEG}** only (grab: TC ID, Test Type, **Category** (VAL/BL/EXC/GUI/SEC), **source TP/AC# → Flow ID**, Pre-Condition/Depends, Steps, Test Data, Expected, Autoable per row). DT/ST/BVA/EP/GUI rows are skipped at digest time — not scored, not counted as candidates (GUI kept aside only for the PE-justified-blocker exception). Skip §2 (env), §4.E (exploratory), §5 (risk — read from TestChecklist SSoT instead). Also read Func-Test **§1** one-liner (Feature Summary → §1 Business Journey). Category + Flow ID are required for the C1 journey-step representative gate ([e2e-selection-strategy.md § Step 1](../../rules/qa/e2e-selection-strategy.md#step-1--relevance-criteria-per-tc)) — do not drop them from the digest.
- **`risk_digest`** ← TestChecklist **§5 Risk Registry** (grab: `TP ID → Risk Level, RC`; **and if the backward-compat `RC-INT` row is present, grab its Root Cause API list → `bc_apis[]`** — the C3 + §2.3.1 source) + **§1.5 Shared Component Impact** if present (grab: component → Risk Level → **Used By (Features)** → regression scope, used for C2 SIT-relevance AND §2.3 Cross-Feature Impact Checklist). Skip §1.3–§4 (already encoded in Func-Test TCs).
- **`journey_digest`** ← TestChecklist **§1.1 In-Scope Business Flows** (grab: Flow ID → Name → Type Main/Alt/Edge → order/Depends) — the user business flow spine, used for C1 journey-critical scoring.
- **`bc_applicable` + `bc_apis[]`** ← from `risk_digest` only (no extra read): apply [e2e-selection-strategy.md § Step 1 — `bc_applicable` definition](../../rules/qa/e2e-selection-strategy.md#step-1--relevance-criteria-per-tc) — do **not** restate the rule here. In short: `true` ⟺ TestChecklist §5 has the backward-compat `RC-INT` row; its Root Cause API list → `bc_apis[]` (the per-TC C3 signal + §2.3.1 regression list). Drives whether C3 counts in the applicable-criteria denominator.

**Do NOT** read PRD, SAD, or Feature-Technical — E2E derives entirely from Func-Test + TestChecklist (including `bc_applicable`, read from the §5 backward-compat row as above). If a needed fact is absent, it is a gap (Phase 1.2), not a reason to read upstream docs.

> **Token rule:** Prefer Grep-to-section-anchor then a bounded Read over reading whole files. A typical run reads ~§4 of Func-Test + ~§5/§1.1/§1.5 of TestChecklist — not the entire artifacts.

**Read template** `.tas/templates/E2E-Test-Spec.md` and extract `template_schema` — the mandatory output structure: frontmatter field list (incl. `metrics.*` sub-fields), section order (§1 → §2.1 → §2.2 → §2.3 → §2.3.1 → §3 → §4), and the exact column list + order for each of §2.1 / §2.2 / §2.3 / §2.3.1. Store `template_schema` as a digest — **read the template exactly once here**; Phase 3 renders against it and Phase 4 validates against it, neither phase re-reads the template file.

---

### Phase 1 — Input (Feature ID → Gap Detection → In/Out Scope)

**1.1 Extract `FEATURE_ID`** (CRITICAL — determines output filename + all references):
Priority: TestChecklist frontmatter `feature_id:` → Func-Test frontmatter `feature_id:` → Feature dir name. Store as `FEATURE_ID` (e.g. `F003`). TC IDs are **reused verbatim** from Func-Test §4 — never regenerate.

**1.2 Gap detection (gap-first — before scope or selection).** Never fabricate to fill a gap:
- **Func-Test §4 has no HP/NEG TC** → STOP: "Func-Test has no HP/NEG test cases. Run /tas-functest first."
- **HP/NEG TC whose source TP is absent from TestChecklist §5** → cannot score risk → record `[TECH-COVERAGE]`; treat risk as **LOW** (default-safe) for Step-2 scoring; ask PE to add a §5 risk row if it should score higher.
- **TestChecklist absent** (degraded mode) → C1 (journey) still works via Func-Test `Depends` chain inference; C2 (SIT) and risk scoring cannot run → treat all as risk LOW/no-C2; only all-3-criteria-impossible rows fall back to C1-only P0/P1 per Step 2; warn "no risk source → running degraded, C2/risk scoring skipped".
- **journey_digest empty** (no §1.1 flows) → derive journey order and C1 flow-type (Main/Alt/Edge) from Func-Test §4 `Depends` chain depth (0 prior = Main, else Alt/Edge); warn ordering/C1 is inferred.
- **No §5 backward-compat row** → `bc_applicable=false` = net-new, C3 n/a (the definition itself resolves this — not a gap; a feature merely calling an API is not backward-compat). Only if §5 is entirely missing (degraded mode) → default **not applicable** (safe: don't inflate the denominator); note in output.

**1.3 In/Out scope declaration** (mandatory per [verification-layers.md §4](../../rules/qa/verification-layers.md#4-scope-conflict-matrix-functest--apitest-plan)):
Emit: *"Scope: single-Feature user business flow, black-box, HP+NEG only, scored by release-cycle relevance (E2E journey / SIT / Backward-Compat) + risk (ISTQB Ch 4.2 + 5.2). DT/ST/BVA/EP stay Func-Test-owned. OUT = SEC/INT(contract)/PERF → routed to API/security/NFR pipelines."*

**Phase 1 checkpoint** (on no blocking gap): save `.tas/command-cache/e2e-{FEATURE_ID}-phase1.md` with:
- Frontmatter: `feature_id`, `command: tas-e2e`, `phase_completed: 1`, `timestamp`, `source_mtimes: {functest_mtime, testchecklist_mtime}`
- Base digests: `feature_digest`, `tech_digest`, `sad_digest`, `conflict_list` (if detected)
- Command-specific: `funct_digest` (HP/NEG TC list from Func-Test §4), `risk_digest` (TP→Risk map from TestChecklist §5/§1.5), `journey_digest` (Flow ID/Type/Depends from TestChecklist §1.1), `template_schema` (E2E-Test-Spec.md structure)

Print `📌 Checkpoint saved → .tas/command-cache/e2e-{FEATURE_ID}-phase1.md`.

---

### Phase 2 — Design (Strategy → Relevance Criteria → Priority Scoring → Journey Order)

> **SSoT — run ALL selection/priority logic from the rule file, never from memory:** [e2e-selection-strategy.md § Selection & Priority (canonical algorithm)](../../rules/qa/e2e-selection-strategy.md#selection--priority-canonical-algorithm). E2E priority ≠ FuncTest priority. The algorithm is **not** re-printed here — read it there and apply.

**2.0 Select ISTQB design strategy (declare, don't re-derive).** For a single-Feature E2E over already-designed Func-Test cases, the strategy is fixed:
- **Use-case / flow-based testing** (ISTQB Ch 4.2) — the *test-type gate + ordering method*: E2E covers HP+NEG only (minimal-sufficient journey correctness), walked along the user business flow spine (Main → Alt → Edge) as Journey Steps.
- **Risk-based testing** (ISTQB Ch 5.2) — the *selection filter*: score each HP/NEG TC against 3 release-cycle-relevance criteria (E2E journey / SIT / Backward-Compat) + risk. Canonical scoring → [test-design.md § Risk Scoring Formula](../../rules/qa/test-design.md#risk-scoring-formula).
- DT/ST/BVA/EP/GUI are **inherited verbatim as Func-Test-owned techniques** (already applied per [test-design.md § TP Category → Test Approach Mapping](../../rules/qa/test-design.md)) and are out of E2E's test-type gate — E2E neither re-derives nor promotes them (GUI's single PE-justified exception aside).

**2.1 Relevance-criteria map (feeds Step 2 scoring).** From `funct_digest` (HP/NEG rows only) + `journey_digest` + `risk_digest` + `bc_applicable`, score each TC's 3 criteria per [e2e-selection-strategy.md § Step 1](../../rules/qa/e2e-selection-strategy.md#step-1--relevance-criteria-per-tc). Store `criteria[TC_ID] = {c1, c2, c3_or_na, risk_level}`:

| Criterion | Command-side lookup |
|---|---|
| **C1 — E2E journey-critical** | TC's flow in `journey_digest` = Main **and** TC Type=HP **and** passes the journey-step representative gate for Category ∈ {VAL, BL} (see below) → C1=true; else C1=false. |
| — NEG exception | NEG TCs are exempt from the representative gate (per [e2e-selection-strategy.md § journey-step representative gate](../../rules/qa/e2e-selection-strategy.md#step-1--relevance-criteria-per-tc)) — Main+NEG → C1=true unconditionally. |
| **C2 — SIT-relevant** | Source TP's §5 RC = RC-INT, or TP's component listed in §1.5 → C2=true |
| **C3 — Backward-Compat** | Only scored if `bc_applicable=true` (else n/a, excluded from denominator). When applicable: C3=true if the TC's source TP's component/API is one of the `bc_apis[]` named in the §5 backward-compat row's Root Cause (a plain `RC-INT` TP is C2, not C3 — per rule § Step 1 C3 detection) |
| **risk_level** | Source TP's §5 Risk Level; absent from §5 → LOW (default-safe per Phase 1.2 gap rule) |

**VAL/BL representative gate:** apply [e2e-selection-strategy.md § journey-step representative gate](../../rules/qa/e2e-selection-strategy.md#step-1--relevance-criteria-per-tc) verbatim (bucket + lowest-TC-ID selection is defined there — not re-derived here). Store its output as `c1_representative[TC_ID] = true/false` alongside `criteria`.

**2.2 Analyse & select each HP/NEG TC** — apply the canonical criteria+risk algorithm ([e2e-selection-strategy.md § Step 2](../../rules/qa/e2e-selection-strategy.md#step-2--priority-criteria--risk--p0p1-then-autoable-gate)) using `criteria` from 2.1 and each TC's Func-Test `Autoable` value. Outcome per TC (the Priority + section placement **encode** it — no rationale column):
- **P0, §2.1** — meets ALL applicable criteria, Autoable=YES.
- **P0, §2.2** — meets ALL applicable criteria, Autoable=NO (release-blocking manual case — tag `[MANUAL-BLOCKER]`).
- **P1, §2.1** — meets 1–2 (or 1-of-2 when C3 n/a) criteria at Risk≥MEDIUM, Autoable=YES.
- **P1, §2.2** — meets 1–2 criteria at Risk≥MEDIUM but Autoable=NO; OR meets 0 criteria at Risk≥MEDIUM (risk-only regression watch — never §2.1).
- **Excluded** — 0 criteria and Risk<MEDIUM; plus Tier-3 SEC/INT(contract)/PERF (routed out). Do **not** emit an excluded row anywhere; count them only in the §5.6 console output summary (never in the written file).

**2.3 Journey ordering & grouping (use-case method).** Order §2.1 TCs by `journey_digest` flow spine (Main → Alt → Edge), then by Func-Test §4 `Depends` chain within each flow. Assign the **Journey Step** number per business-flow step (not per TC). §2.1 rows are then grouped **Platform → Role → Journey Step (asc)** per template §2.1 rule, so each Platform+Role block is one continuous execution pass. §2.2 Regression Watch rows are grouped by **Risk Level (desc)** instead — regression priority, not journey order.

**Phase 2 checkpoint:** save `.tas/command-cache/e2e-{FEATURE_ID}-phase2.md` with:
- Frontmatter: `feature_id`, `command: tas-e2e`, `phase_completed: 2`, `timestamp`, `source_mtimes`
- Phase 2 digests: `selected_tc_list` (TC ID, Priority, §2.1/§2.2, criteria match, risk, Journey Step), `criteria_map` (per TC: C1/C2/C3 true/false, applicable-count denominator, risk_level)

Print `📌 Checkpoint saved → .tas/command-cache/e2e-{FEATURE_ID}-phase2.md`.

---

### Phase 3 — Detail (Render Selected TCs into Detailed E2E Test Cases)

Render the Phase-2 selection into template `E2E-Test-Spec.md` as **detailed executable test cases**, following `template_schema` from Phase 0 exactly (section order, frontmatter fields, column list/order per table) — **structure only from the template; test-case detail carried verbatim from Func-Test §4**. Do not re-select, re-decide, paraphrase, summarize into a checklist, or invent a layout not present in `template_schema` — each row must stay a full, runnable test case.

**3.1 §2.1 TC Execution Table** — one row per §2.1-selected test case (P0/P1, Autoable=YES, criteria-matched). **Column format = Func-Test §4 verbatim + 3 journey columns prepended** (`template_schema` is SSoT for exact order):
`Platform | Role | Journey Step | TC ID | Test Type | Description | Pre-Condition | Logical Steps | Test Data | Execution Locators | Expected Result | Priority | Traceability`
- **TC ID / Test Type / Description / Pre-Condition / Logical Steps / Test Data / Expected Result / Traceability** → copy **verbatim** from `funct_digest` (Func-Test §4) — chain contract, do NOT paraphrase or renumber.
- **Execution Locators** → carry Func-Test's `_Phase 3 — SE_` placeholder (overwritten later by `/tas-e2e-web`/`-mobile`).
- **Priority (E2E)** → from Phase 2.2. The Priority value **encodes** the criteria+risk outcome (P0=all applicable criteria met; P1=partial-criteria or risk-only), so no separate rationale column is emitted. E2E priority ≠ Func-Test priority — do NOT copy Func-Test's Priority value.
- **Journey Step** → from Phase 2.3. **Platform / Role** → from Func-Test row (or Feature platform).
- **Row order (single table, grouped):** sort rows **Platform (web→app) → Role → Journey Step (asc)** per `template_schema` — do NOT split into sub-tables. Keep a Platform+Role block contiguous so it runs as one pass.
- **Pre-Condition Depends** → keep Func-Test's `Depends: {TC_ID}` FIRST (dependency/execution order preserved).
- **Dropped:** Func-Test's `Test Result` column is NOT carried (execution tracked in the run report, not this spec). `Autoable` column dropped (every §2.1 row is Autoable=YES by construction).

**3.2 §2.2 Regression Watch** — TCs from Phase 2.2 that scored P0/P1 by criteria+risk but are **Autoable=NO** (release-blocking manual, tagged `[MANUAL-BLOCKER]`), plus TCs that matched **0 criteria but Risk≥MEDIUM** (risk-only, regardless of Autoable).

**Column format (`template_schema` is SSoT):** `Platform | Role | Risk Level | TC ID | Test Type | Watch Reason | Autoable | Description | Pre-Condition | Logical Steps | Test Data | Expected Result | Priority | Traceability` — **14 columns**. Carries Func-Test §4 columns verbatim (minus `Execution Locators` dropped), plus `Risk Level` prepended after `Role`, plus `Watch Reason` after `Test Type`, plus `Autoable` after `Watch Reason`. Grouped by **Risk Level (desc)**, not journey order.

**3.3 §2.3 Cross-Feature Impact Checklist** — from `risk_digest`'s §1.5 rows: for each Shared Component row whose `Used By (Features)` lists a Feature **other than** this `FEATURE_ID`, emit one checklist row (Component, Risk Level, Impacted Feature, Regression Scope, `Reviewed?` = unchecked `☐`). One row per impacted Feature (a component used by 3 other Features → 3 rows). Do **not** pull in the impacted Feature's own TC IDs or steps — QC on that Feature finds/re-runs its own relevant TCs; this is a pointer, not a TC carry-over. Omit the whole section if TestChecklist §1.5 is absent/empty.

**3.4 §1 Business Journey** — fill from `funct_digest §1` + `journey_digest` (Feature ID, Business Value, User Journey step→step→verify, Key Business Rules).

---

### Phase 4 — Gate (Validate before write)

Run ALL checks before writing. On any fail → STOP, log check number, do NOT emit a broken artifact.

```
✓ Check 0 (Feature ID): FEATURE_ID is short code (e.g. F003), not "PROJ-Feature-001". Else STOP.
✓ Check 1 (Test-type gate): every §2.1/§2.2 TC Type ∈ {HP, NEG} or PE-justified GUI;
    DT/ST/BVA/EP/SEC/INT/PERF count = 0 in both sections (test-type gate + Tier-3 routing enforced). Else STOP.
✓ Check 2 (Priority validity): P0 only when ALL applicable criteria (C1+C2[+C3]) are met, or PE-justified GUI;
    P1 only when 1–2 criteria met at Risk≥MEDIUM, or 0 criteria at Risk≥MEDIUM (risk-only). Any P0/P1 without
    a traceable criteria+risk basis in the Phase 2 checkpoint → STOP.
✓ Check 2b (Section routing): §2.1 rows are Autoable=YES only; §2.2 rows are Autoable=NO (any priority) or
    0-criteria+Risk≥MEDIUM (any Autoable). A criteria-matched Autoable=YES row sitting in §2.2, or an
    Autoable=NO row sitting in §2.1 → STOP.
✓ Check 3 (TC ID fidelity): every §2.1/§2.2 TC ID exists verbatim in Func-Test §4 (chain contract). Any invented/renumbered ID → STOP.
✓ Check 4 (Depends preserved): TCs with Func-Test Depends keep "Depends: {TC_ID}" FIRST; referenced TC present in §2.1 or noted. Else STOP.
✓ Check 5 (Coverage vs FuncTest HP+NEG): included = §2.1 + §2.2; excluded = Tier-3 + (0-criteria & Risk<MEDIUM).
    Report count reconciliation against Func-Test's total HP+NEG count (no silent loss).
✓ Check 6 (Autoable vocab): every §2.2 Autoable cell ∈ {YES, NO}; every §2.2 Watch Reason ∈ {MANUAL-BLOCKER, RISK-ONLY}. Else STOP.
✓ Check 7 (Journey grouping): §2.1 rows sorted Platform → Role → Journey Step (asc), single table, each Platform+Role
    block contiguous. §2.2 rows sorted Risk Level (desc). Any out-of-order row → STOP.
✓ Check 8 (Cross-Feature impact completeness): every TestChecklist §1.5 row whose `Used By (Features)` lists a
    Feature other than this FEATURE_ID has a matching §2.3 row. Missing impacted-Feature row → STOP.
✓ Check 8b (Backward-compat note): if `bc_applicable=true`, §2.3.1 is present and every API named in the
    TestChecklist §5 RC-INT Root Cause appears as a row (API names copied, not re-derived). If `bc_applicable=false`,
    §2.3.1 is absent. Mismatch → STOP.
✓ Check 9 (VAL/BL representative gate): for every `(Flow ID, Category)` group where Category ∈ {VAL, BL} and
    flow=Main and Type=HP, at most ONE TC scores C1=true (the stored `c1_representative` pick). Any group with
    2+ TCs scoring C1=true on this basis → STOP (representative gate not applied — see e2e-selection-strategy.md).
✓ Check 10 (Table integrity): for §2.1 and §2.2, header col-count == separator (`|---|`) col-count == every
    data-row col-count. Ignore `\|` escaped pipes inside cell content (e.g. `{HP\|NEG}`, `Depends: X \| Page: Y`) —
    those are literal text, not column separators. Any mismatch → STOP, fix before write.
✓ Check 11 (Template compliance): frontmatter field set, section order, and every table's column list/order
    match `template_schema` (Phase 0) exactly — no extra/missing/reordered field, section, or column. This
    includes: no extra section beyond §1/§2.1/§2.2/§2.3/§2.3.1/§3/§4 (e.g. no "Methodology" or "Gate Results"
    section — see §5.4b); AI Usage Log has exactly 3 columns and sits at §3 (before Change Log at §4);
    `gate_result` ∈ {PASS, FAIL, WARN}, never left as "PENDING" or an invented value. Any deviation → STOP,
    fix before write (never silently adapt the template).
```

---

### Phase 5 — Output (Write file + metadata + cleanup)

**5.1 Output location** (SSoT path downstream commands read):
```
{Feature directory}/{FEATURE_ID}-E2E-Test-Spec.md
```
Same directory as the Feature document (e.g. `docs/features/{CODE}-Feature-{NNN}-{slug}/`). `/tas-e2e-web` and `/tas-e2e-mobile` resolve the spec from this path — writing elsewhere breaks the chain.

**5.2 Fill template** in order: frontmatter (below) → header → §1 Business Journey → §2.1 TC table → §2.2 Regression Watch → §2.3 Cross-Feature Impact Checklist (incl. **§2.3.1 Backward-Compat Regression Note**) → §3 AI Usage Log → §4 Change Log.

**§2.3.1 fill rule:** if `bc_applicable=true`, populate §2.3.1 from the TestChecklist §5 backward-compat `RC-INT` row — copy the **API name(s) + change type verbatim from its Root Cause** (do not re-derive), set Related E2E TC(s) = the §2.1/§2.2 TCs whose C3=true (or `— (API-only)` if none surfaced in E2E), Owner = SE (API TC) / PE (regression sign-off). If `bc_applicable=false` → omit the entire §2.3.1 block.

**Authorship (per [verification-layers.md § 5.1](../../rules/qa/verification-layers.md#51-authorship--audit-metadata-canonical-)):**
- Read PE name from `tas.yaml` key `project.qa_owner` → populate `owner` (CREATE only, immutable)
- Run `git config user.name` → populate `author`, `created_by`, Change Log Author (per § 5.1 procedure: git user, or fallback to owner)
- Set `created_date`, `updated_date` (YYYY-MM-DD): CREATE for both; UPDATE for updated_date only

**Template:** `.tas/templates/E2E-Test-Spec.md` — frontmatter fields {owner, author, created_by, created_date, updated_date} are empty placeholders for substitution.

Then populate remaining fields:
```yaml
feature_id: {FEATURE_ID}
feature_title: {from Func-Test §1}
status: Draft
platform: {web | app | both}
ver: 1.0                                  # or increment per Version Policy (MAJOR on Feature change)
release_id: ""

sources:
  functest: "{path} # v{ver}"
  testchecklist: "{path} # v{ver}"

metrics:
  total_tcs: {§2.1 count}        # P0+P1 in §2.1 only (Autoable=YES, criteria-matched)
  p0_count: {M}                  # §2.1 rows meeting ALL applicable criteria
  p1_count: {K}                  # §2.1 rows meeting 1–2 criteria at Risk≥MEDIUM
  regression_watch_count: {R}    # §2.2 rows (MANUAL-BLOCKER + RISK-ONLY)
  excluded_count: {L}            # Tier-3 routed + 0-criteria & Risk<MEDIUM
  autoable_yes: {N}              # across §2.1 + §2.2
  autoable_no: {N}

gate_result: "PASS"            # set by Phase 4
coverage_percentage: {(P0+P1)/FuncTest§4 HP+NEG count × 100}
```

**5.3 §2.1 footer Summary — `template_schema` is SSoT, single line, exactly as in the template:**
```
**Summary:** Total {N} | P0 {M} | P1 {K} | Coverage vs Func-Test: {M+K}/{Func-Test §4 HP+NEG count}
```
Do not expand this into extra lines (Regression Watch / Excluded counts) — those belong only in the §5.6 console output summary, never in the written artifact.

**5.4 AI Usage Log + Change Log:** Append row to §3 AI Usage Log — **exactly 3 columns** (`# | Date | Command`), per `.tas/rules/common/token-logging.md`. Do NOT add token-estimate columns or any other column; do NOT renumber this section (it is always §3, immediately after §2.3.1, before §4 Change Log — never move it after Change Log). CREATE or UPDATE with version bump only per Version Policy; skip on audit-only runs. Then append §4 Change Log with Author = `git config user.name` output per [verification-layers.md § 5.1](../../rules/qa/verification-layers.md#51-authorship--audit-metadata-canonical-) procedure.

**5.4b No extra sections.** The written file contains ONLY the sections in `template_schema` (§1, §2.1, §2.2, §2.3, §2.3.1 if applicable, §3 AI Usage Log, §4 Change Log) — nothing else. In particular:
- Do **not** write a "Selection & Priority Methodology", "Phase recap", or any Gate-check results (Phase 4) into the file — Phase 4 is a pre-write validation step; its checks are internal and are never rendered into the artifact.
- The §5.6 output summary is chat-facing only — never copy/paste it (or any part of it) into the file.
- `gate_result` in frontmatter must resolve to exactly one of `PASS | FAIL | WARN` before writing (Check 11) — never left as the template's `"PENDING"` placeholder and never an invented value (e.g. "CONDITIONAL PASS") in prose or frontmatter. If Phase 4 did not cleanly pass, do not write the file at all (see Phase 4 preamble).
- `coverage_percentage` is computed **once**, in frontmatter, per the formula below — no other section may restate it with a different number.

**5.5 Checkpoint cleanup:** delete all `.tas/command-cache/e2e-{FEATURE_ID}-phase*.md` files (unconditional — per §7.3). Print `✅ Checkpoints deleted. E2E {FEATURE_ID} complete.`

**5.6 Output summary — CHAT MESSAGE ONLY, not file content.** Print the block below directly to the user in the conversation. It is not part of `template_schema` and must never be written to, or appended into, `{FEATURE_ID}-E2E-Test-Spec.md` (see §5.4b):
```
✓ E2E Test Spec created: {FEATURE_ID}-E2E-Test-Spec.md

Feature: {FEATURE_ID} — {title}
Selection (per e2e-selection-strategy.md — criteria: E2E journey / SIT / Backward-Compat + risk):
├─ §2.1 P0 (all applicable criteria met, Autoable=YES): {M}
├─ §2.1 P1 (1–2 criteria at Risk≥MEDIUM, Autoable=YES): {K}
├─ §2.2 Regression Watch (MANUAL-BLOCKER + RISK-ONLY): {R}
├─ §2.3 Cross-Feature Impact Checklist: {X} row(s) across {Y} impacted Feature(s)
└─ Excluded: {L} (SEC/INT/PERF routed + 0-criteria & Risk<MEDIUM)

Criteria matches detected:
├─ C1 E2E journey-critical (Main flow): {count}
├─ C2 SIT-relevant (integration boundary / shared component): {count}
└─ C3 Backward-Compat-relevant: {count} (n/a — net-new Feature, if applicable)

Coverage vs FuncTest (HP+NEG): {M+K}/{total} TCs in §2.1
Autoable: YES {y} / NO {n} (across §2.1+§2.2)

Next Steps:
1. Review journey ordering + P0/P1 + Regression Watch with QA lead.
2. Automate §2.1 (Autoable=YES) → /tas-e2e-web (web) / /tas-e2e-mobile (app) — they reuse §2.1 TC IDs as script titles.
3. Execute §2.1 P0 first; any P0 fail → STOP release gate. Schedule §2.2 Regression Watch per Risk Level.
4. Hand §2.3 rows to each impacted Feature's QC owner to confirm regression coverage, then check off.
```

## Important Notes

1. **E2E priority ≠ FuncTest priority** — E2E = release execution order across E2E/SIT/Backward-Compat cycles (criteria+risk scored); FuncTest = automation capability. Never copy FuncTest priorities.
2. **TC IDs are a chain contract** — reused verbatim from Func-Test §4 so `/tas-e2e-web`/`-mobile` can bind scripts. Never regenerate or renumber.
3. **Test-type gate** — only HP/NEG TCs are scored for E2E; DT/ST/BVA/EP stay Func-Test-owned and never enter §2.1/§2.2.
4. **Criteria+risk scoring** — P0 requires ALL applicable criteria (C1 journey + C2 SIT + C3 Backward-Compat if applicable); P1 requires partial-criteria or risk-only at Risk≥MEDIUM.
5. **§2.1 vs §2.2 split is Autoable-driven, not risk-driven** — §2.1 = criteria-matched AND Autoable=YES; §2.2 Regression Watch = everything else worth keeping (manual-blocker or risk-only), tagged with its own Autoable column.
6. **No upstream reads** — E2E derives from Func-Test + TestChecklist only. Missing facts are gaps, not a trigger to read PRD/SAD.
7. **Never fabricate** — a gap is logged and defaults to the safe outcome (risk=LOW, C3=n/a), not invented to force a higher priority.
8. **Template is read once (Phase 0)** — structure (frontmatter, section order, columns) is fixed by `template_schema`; Phase 3 renders against it and Phase 4 Check 11 enforces it. Never re-read the template mid-run or improvise a layout it doesn't define.

## Error Handling

- No Func-Test found: "No {CODE}-FuncTest.md found. Run /tas-functest first."
- No HP/NEG TCs in Func-Test: "Func-Test has no HP/NEG test cases. Run /tas-functest first."
- No TestChecklist found: "Warning: no TestChecklist — running degraded (C1 journey scoring only; C2/risk scoring skipped, treated as LOW/no-C2)."
- Template missing: "Error: E2E-Test-Spec.md template not found in .tas/templates/"
- P0/P1 without traceable criteria+risk basis (Gate Check 2): "Error: {TC_ID} assigned {Priority} but Phase 2 checkpoint has no matching criteria/risk record."
- Section-routing mismatch (Gate Check 2b): "Error: {TC_ID} is Autoable={Yes/No} but placed in §{2.1/2.2} — see e2e-selection-strategy.md § Step 2 routing rule."
- Template-schema mismatch (Gate Check 11): "Error: output {frontmatter field | section | column} does not match E2E-Test-Spec.md template — see Phase 0 template_schema."
