--- name: two-node:generate-tests argument-hint: description: Generate Ginkgo e2e test cases for a TNF/TNA (two-node/OpenShift edge) Jira ticket user-invocable: true allowed-tools: Bash, Read, Write, Glob, Grep, WebFetch, mcp__jira__jira_get_issue, mcp__jira__jira_search --- # two-node:generate-tests ## Synopsis ```bash /two-node:generate-tests JIRA-TICKET-ID ``` ## Description Generate comprehensive Ginkgo e2e test coverage for TNF/TNA (two-node and HA OpenShift edge) features based on Jira tickets. **NOTE**: For other projects or to customize this workflow, see `TEMPLATE.md` alongside this skill for a generic template you can adapt. **Target profile**: This skill defines the target-agnostic generation pipeline. Target-specific facts — test-tree layout, keyword/resource discovery rules, validation commands, harness constraints — live in `profile.md` alongside this skill and must be read before generating tests. ## Prerequisites **Jira Access**: This command requires access to Red Hat Jira (https://redhat.atlassian.net). - Ensure you're logged into Red Hat Jira in your browser before running this command - Login at: https://redhat.atlassian.net **Fallback**: If Jira access fails, you'll be prompted to manually provide: - Ticket description and acceptance criteria - Links to GitHub PRs - Feature documentation ## Implementation Steps ### Step 1: Analyze the Ticket Walk the ticket's context **top-down**, not just its direct links: - Fetch the Jira ticket (OCPSTRAT feature or OCPEDGE story) from `https://redhat.atlassian.net/browse/` - Extract feature description, acceptance criteria, and technical details - Identify the epic (parent) of the analyzed ticket and list **all its child stories**, not only tickets directly linked from the analyzed one. For each child story, capture: summary, status, assignee, and any implementing PR - Check the parent and one level of sibling features for interacting behavior (e.g., a CA-consolidation feature that changes what a renewal test should assert) - Identify all linked implementation tickets (look in "Issue Links" section) - Find GitHub PR links from linked tickets or the analyzed ticket - **If no PR links were found in Jira**, search GitHub as a fallback (the Jira development panel is often empty): `gh pr list --repo --search ""`, and also search PR titles/bodies for the feature name. Record which PRs were found by which method - **Re-read the analyzed ticket's acceptance criteria after the walk**: ACs added after the initial design (late customer feedback) are a common source of missed requirements - **Freshness check**: before investing in generation, check whether the feature is alive. Jira statuses go stale — a ticket can say "Code Review" for a year. Check the last commit date on the implementing PR(s) and the last meaningful Jira transition — **including PRs on linked issues**: an epic can be unassigned pre-work while a linked bug already carries the live implementation (distinguish "dormant" — stale, rotting PRs — from "pre-work" — no stories yet, implementation just starting). If the code hasn't moved in months and the only PR activity is CI stale-markers and rebase bots, surface that to the user ("this feature appears dormant — last code pushed ") and ask whether to proceed before generating test cases for it - **Check `openshift-eng/edge-context`**: search it (local clone or `gh` search) for the ticket key and feature name; read any test plans, decision records, or review checklists found and treat them as input requirements **VALIDATION - Check for sufficient information**: After analyzing the ticket, verify: 1. **Description Quality**: Does the ticket have detailed description, acceptance criteria, or technical implementation details? 2. **PR Links**: Are there any useful GitHub PR links in the analyzed ticket or its linked/child tickets? **If BOTH conditions fail** (no detailed description AND no PR links): - Ask user for additional information: "The ticket lacks detailed information for test generation. It's missing: - Detailed feature description or acceptance criteria - Linked implementation tickets with GitHub PRs Please provide ONE of the following to continue: 1. A link to documentation (PR description, GitHub .md files, design docs) 2. A brief description of the feature functionality and expected behavior 3. Additional context about what this feature does Or type 'skip' to proceed with limited information (may result in generic tests)." - **Wait for user response**: - If user provides documentation link: Fetch and analyze it - If user provides description: Use it as supplementary context - If user types 'skip': Proceed with warning that tests may be generic **If at least ONE condition passes**, proceed to Step 2. ### Step 2: Analyze Existing Test Coverage Coverage comes from two sources — open PRs **and** the repository's test tree: - For each GitHub PR found, check if it contains test files for the target framework (per the profile) - Note the test file names and their location in the PR - **Grep the repository's test tree** (per the profile's layout, **on the default branch** — a feature branch's own tests are not "existing coverage") for the feature's keywords, commands, and config keys. Candidate suites must be **read in full — test bodies and [Documentation], not just test names**: a name like "Configured Lifetimes Can Be Prepared While Running" does not reveal that it asserts midnight-aligned notAfter windows. Map each acceptance criterion to the *specific existing tests* that verify it, and treat found tests as existing coverage — a run with no coverage document at hand must still not propose tests that duplicate merged tests - Identify functionality already covered by existing tests **Ground in the implementation source**: before authoring test cases (Step 3), read the feature's implementation — the PRs found in Step 1 and the relevant code in the target repo. Acceptance criteria and design docs describe *intent*; the code defines *behavior*, and tests must assert behavior. Discrepancies between ACs/docs and code are recorded as findings in the test-case document (and reported upstream) — never encoded as test assumptions. Grounding is what catches: inventory undercounts (doc claims 10 client certs, code issues 11 via two `.WithClientCertificates()` calls), undocumented policies that change what an assertion should expect (per-cert rotation thresholds that make status colors predictable), and ACs whose implementation differs from their wording. ### Step 3: Generate Top 10 Most Impactful Missing Tests **Merge into an existing coverage document when one exists.** Before writing, search the current directory and the project workspace for an existing test-case or coverage document (glob for `test-cases*.md`, `test_plan*.md`, `COVERAGE.md`, `coverage*.md`). If one exists: **append new test cases to it** using its existing ID scheme and status vocabulary, and update its coverage summary — do not create a parallel document. Only create a new document (named `test_cases_.md` in the current working directory) when none exists. Focus ONLY on the **10 most impactful test scenarios NOT already covered**: **Dedupe rule**: if an existing test (open PR or merged) already verifies a scenario, record it as covered in the test-case document; do not generate a parallel test for it. 1. **Core Functionality** - Primary use cases not tested 2. **Configuration Edge Cases** - Invalid/boundary configurations not covered 3. **Dynamic Behavior** - Runtime changes, reloads not tested 4. **Integration Gaps** - Component interactions not validated 5. **Multi-tenant/Namespace** - Cross-namespace scenarios missing 6. **Error Handling** - Failure modes not covered 7. **Upgrade/Compatibility** - Version compatibility gaps 8. **Performance** - Load/scale testing if missing 9. **Security** - Permission/isolation tests not present 10. **Real Customer Scenarios** - Use cases from RFE not tested For each test, provide: - **Test ID**: derive the ID scheme from the existing test-case/coverage document when one is found (Step 2) and follow it exactly. Only if no existing document or scheme is available, use `-XXX-TC-YYY` based on the linked implementation ticket's project key - **Priority**: Critical/High/Medium - **Coverage Gap**: What existing tests don't cover - **Test Description**: Clear objective - **Why it matters**: the failure mode or customer impact if this behavior breaks (one sentence, no document references) - **Test type**: black-box / grey-box / negative / white-box - **Steps to Reproduce**: Concrete test steps with actual config/commands - **Expected Results**: Expected outcome for each step **Every field must be filled without referencing another document.** Pointers may be added *in addition*, never *instead* — each test case must be understandable standing alone. **Testability check**: before accepting a scenario, check it against the profile's testability-constraints knowledge base (harness facts that make some scenarios untestable by design). A scenario that fights the constraints (e.g., requires manipulating something the harness controls) must be redesigned or rejected at generation time — not discovered untestable after an on-host iteration. **Consolidation rule**: group acceptance criteria that exercise the same physical operations into one test scenario with one keyword per AC — each keyword named for its criterion and failing with its own message. Emit a runtime cost estimate per scenario using the profile's cost units, and warn when a suite approaches the profile's CI scenario window. One scenario per AC by default produces too many tests and too much runtime. **Traceability table**: build an acceptance-criterion → test case(s) → owner map (owner = existing PR test, generated test, or none) — citing **specific test names**, not suite-level generalities: "AC #6 → `Renewal Messages Match The Real Impact On External Kubeconfigs` (networking/hpp.go)" is verifiable; "AC #6 → networking tests" is not, and hides duplication. **Every AC must appear.** Any AC with no test is flagged as a gap in the Step 6 summary regardless of how many tests were generated. An AC can be implemented by a story under a *different* epic than the one walked — before declaring an AC a gap, search Jira for the AC's topic (e.g. its metric, command, or config key) to find cross-epic implementing stories and PRs. ### Step 4: Create Test Files (framework and conventions per the profile) **BEFORE writing any tests:** 1. Read the target profile (`profile.md` alongside this skill) — it defines the framework, the repo's test-tree layout, reusable-helper locations and discovery rules, and the framework conventions (setup/teardown patterns, reuse rules, naming) 2. Search for existing reusable helpers in the codebase using the profile's discovery rules 3. Identify reusable helpers for common operations 4. Check for existing fixtures/utilities/resource files 5. Use Grep/Glob to find similar test patterns Do not hardcode helper or resource locations — the profile's discovery rules are authoritative for where they live and how tests import them. **When creating tests:** - REUSE existing helpers whenever possible - DON'T create duplicates of helpers that already exist - EXTEND existing helper files if new helpers are truly needed - DON'T reinvent common operations (oc commands, pod management, etc.) **Test documentation requirements**: every generated test documents, via the framework's documentation mechanism (per the profile), at least: one "Verify that..." sentence, one line of *why* where the reason is not obvious, and the test-case ID for traceability. The test-case document remains the authority; the in-code documentation is the pointer back to it. **Test File Creation Process:** - Generate or update the test-case document per Step 3's merge rule (append to an existing coverage document when one exists) - Test files are created in the target repository AFTER the git branch is created in Step 5 - Follow the target repo's naming convention (per the profile) - If tests exist in PRs, create files with matching names - **Place tests in the suite that owns the helpers they need**: grep for the helpers the new tests use, find the existing suites that import them, and add the tests to one of those suites. Create a new suite only when no existing suite has the needed setup/teardown machinery - When creating a new suite is unavoidable: determine its directory by finding where tests with similar setup/helpers live (per the profile's placement rule), never from a fixed category map; and import only genuine helper/resource files — **never a file containing test cases** - Implement the top 3-5 most critical missing tests - Follow existing patterns from similar test files in the target codebase - Include proper setup, teardown, and error handling, per the profile's framework conventions ### Step 5: Create Git Branch and Test Files in the Target Repository **IMPORTANT**: Before creating git branch, **WAIT for user confirmation**. Ask user for confirmation: **Prompt user**: "Would you like me to create a new git branch in the target repository? The branch will be named `test--YYYYMMDD`. (yes/no)" **If user confirms (yes)**: #### 5.1: Create Git Branch 1. Ask user for the target repository path on their system 2. Navigate to the target repository 3. Check current git status 4. Create new branch: `test--$(date +%Y%m%d)` 5. Confirm branch creation and provide branch name **Prompt user**: "Please provide the full path to your target repository (the profile names the repo if known):" **Commands** (use the path provided by user): ```bash cd git status git checkout -b test--$(date +%Y%m%d) git branch --show-current ``` #### 5.2: Create Test Files in the New Branch After branch is created, create the test file(s) directly in the target repository: 1. Determine the suite directory by finding where tests with similar setup/keywords live (per the profile's placement rule), not from a fixed category map 2. Create the test file(s) with the target repo's naming convention (per the profile) 3. Implement the top 3-5 most critical tests from Step 3 4. Add file to git staging **Commands** (use the user-provided target repository path): ```bash # After file is created, stage it cd git add git status ``` **Output to user**: - Branch created: test--YYYYMMDD - Repository: `` - Current branch: \[branch name\] - Test file(s) created (paths, with test count) - File staged for commit: Ready to commit #### 5.3: Validate Generated Tests (mandatory) The skill is **not done** when the files are written — it is done when they pass mechanical validation. Run the profile's validation commands (lint check, format check, dry-run) over every touched suite and fix all errors before reporting completion. - A dry-run proves keywords and arguments resolve only — it does **not** evaluate `Evaluate` expressions or keyword logic (see the behavioral smoke check) - A lint-clean file can still fail the format check — run both - Doc-convention lint (per the profile's traceability convention — e.g. sig/feature tags in test titles for Ginkgo): exactly one traceability marker per scenario, no duplicated marker blocks - **Criteria check**: run `plugins/shared/scripts/check_tests.py` over the touched files — it mechanically checks intent, traceability markers, topology naming, and duplicate suspects (criteria C1/C2/C3/C7 of the edge test criteria), and prints the AC->test map - **Expression-type smoke**: execute every `Evaluate` / `Should Be True` expression and any non-trivial keyword logic with representative argument types before finishing. Dry-run and lint cannot catch these — write a minimal standalone `.robot` repro locally (synthetic data, no host) and run it to confirm the expression evaluates and the assertions catch their violations. Ten seconds locally versus a host run (or a CI round) to find a scope or type error - If validation cannot run (no toolchain available), say so explicitly in the summary instead of implying the output is verified ### Step 6: Summary Report Provide: - List of tickets and PRs analyzed (epic, child stories, linked tickets) - Existing test files found (with coverage summary) - Test case document (test cases, per Step 3's merge rule) - filename and path - Test file(s) created (with test count) - filename and path - Git branch created (branch name and repository path) - if created - Coverage gaps addressed - Remaining gaps (if any) - **Traceability table** (AC → test case(s) → owner), with every acceptance criterion that has no test explicitly flagged as a gap - **Runtime cost estimate** per generated scenario, with a warning if the suite approaches the CI scenario window **Write results back into the coverage document**: update each generated test case's status there (e.g., "Written (not run)") and record, per test: file, line, verification done (dry-run/lint/format check/behavioral repro), and verification still needed (real-host run). The coverage document is the single authority — the summary report must not be the only place the state lives. **Emit knowledge candidates**: for every manual fix, validation surprise, or harness constraint discovered during the run, emit a candidate entry for the profile's knowledge intake (harness fact / domain fact / criteria candidate, with the date and the run that taught it). The run's findings are the profile's next facts — they must not evaporate with the session.