# Test Scenarios for rgen CLI
**Purpose:** Comprehensive test scenarios mapping all CLI commands to Jobs To Be Done (JTBD) to ensure complete functionality coverage.
---
## Table of Contents
1. [Core Generation Commands](#core-generation-commands)
2. [Marketplace Commands](#marketplace-commands)
3. [Discovery Commands](#discovery-commands)
4. [Utility Commands](#utility-commands)
5. [Developer Commands](#developer-commands)
6. [Test Coverage Matrix](#test-coverage-matrix)
---
## Core Generation Commands
### 1. `rgen gen` - Generate code from templates
**JTBD:** "When I need to generate code, I want to use a template with variables, so that I can create consistent, reproducible artifacts."
#### Command Syntax
```bash
rgen gen [OPTIONS] <TEMPLATE>
-o, --out <OUT> Output directory root [default: .]
-v, --var <VARS> Variables (key=value pairs)
--dry Dry run (no write)
```
#### Test Scenarios
##### ✅ Scenario 1.1: Generate from local template
```gherkin
Given I have a local template at "templates/cli/subcommand/rust.tmpl"
When I run "rgen gen templates/cli/subcommand/rust.tmpl --var cmd=hello --var summary='Print greeting'"
Then a file should be created at "src/cmds/hello.rs"
And the file should contain "fn hello"
And the file should contain "Print greeting"
```
**Feature File:** `template_generation.feature`
**BDD Status:** Step definitions exist ✅
##### ✅ Scenario 1.2: Generate with pack reference
```gherkin
Given I have installed rpack "io.rgen.rust.cli-subcommand"
When I run "rgen gen io.rgen.rust.cli-subcommand:cli/subcommand/rust.tmpl --var cmd=test"
Then a file should be created at "src/cmds/test.rs"
```
**Feature File:** `quickstart.feature`
**BDD Status:** Step definitions exist ✅
##### ✅ Scenario 1.3: Dry run (preview without writing)
```gherkin
Given I have a local template
When I run "rgen gen templates/cli/subcommand/rust.tmpl --dry --var cmd=preview"
Then no files should be created
And I should see the preview output
```
**Feature File:** `template_generation.feature`
**BDD Status:** Step definitions exist ✅
##### ✅ Scenario 1.4: Generate to custom output directory
```gherkin
Given I have a local template
When I run "rgen gen templates/cli/subcommand/rust.tmpl --out ./custom --var cmd=test"
Then a file should be created at "./custom/src/cmds/test.rs"
```
**Feature File:** `template_generation.feature`
**BDD Status:** Step definitions exist ✅
##### ✅ Scenario 1.5: Deterministic generation (same input = same output)
```gherkin
Given I have a template with determinism config
When I run the generation command twice with the same seed
Then both outputs should be byte-identical
```
**Feature File:** `determinism.feature`
**BDD Status:** Step definitions exist ✅
##### ✅ Scenario 1.6: Multi-language template support
```gherkin
Given I have templates for Python, JavaScript, and Rust
When I run generation for each language
Then correct syntax files should be generated for each
```
**Feature File:** `multi_language.feature`
**BDD Status:** Step definitions exist ✅
##### ✅ Scenario 1.7: RDF/SPARQL integration
```gherkin
Given I have a template with RDF data and SPARQL queries
When I run generation
Then the SPARQL query results should be injected into the template
```
**Feature File:** `rdf_sparql.feature`
**BDD Status:** Step definitions exist ✅
---
### 2. `rgen list` - List available templates
**JTBD:** "When I need to know what templates are available, I want to see a list with metadata, so that I can choose the right template."
#### Command Syntax
```bash
rgen list
```
#### Test Scenarios
##### ✅ Scenario 2.1: List local templates
```gherkin
Given I have templates in "templates/" directory
When I run "rgen list"
Then I should see a list of templates
And each template should show:
- Template path
- Output path pattern
- Required variables
- RDF file count
- SPARQL query count
```
**Feature File:** `cli_commands.feature`
**BDD Status:** Step definitions exist ✅
##### ✅ Scenario 2.2: List shows template metadata
```gherkin
Given I have a template "templates/cli/subcommand/rust.tmpl"
When I run "rgen list"
Then I should see:
"""
📄 cli/subcommand/rust.tmpl
Output: src/cmds/{{cmd}}.rs
Variables:
cmd: example
summary: Example command
RDF files: 1
SPARQL queries: 1
"""
```
**Feature File:** `cli_commands.feature`
**BDD Status:** Step definitions exist ✅
##### ✅ Scenario 2.3: Empty template directory
```gherkin
Given I have no templates
When I run "rgen list"
Then I should see "No templates found"
```
**Feature File:** `cli_commands.feature`
**BDD Status:** Step definitions exist ✅
---
### 3. `rgen show` - Show template metadata
**JTBD:** "When I need detailed information about a template, I want to see its full configuration, so that I understand how to use it."
#### Command Syntax
```bash
rgen show [OPTIONS] <TEMPLATE>
-v, --vars <VARS> Variables (key=value pairs)
```
#### Test Scenarios
##### ✅ Scenario 3.1: Show template frontmatter
```gherkin
Given I have a template with complete frontmatter
When I run "rgen show templates/cli/subcommand/rust.tmpl"
Then I should see:
- Output path pattern
- All variables with defaults
- Injection mode settings
- RDF files list
- SPARQL queries
- Shell hooks (if any)
```
**Feature File:** `cli_commands.feature`
**BDD Status:** Step definitions exist ✅
##### ✅ Scenario 3.2: Show with variable substitution
```gherkin
Given I have a template with Tera syntax in frontmatter
When I run "rgen show templates/test.tmpl --vars name=Alice"
Then the frontmatter should be rendered with "Alice"
```
**Feature File:** `cli_commands.feature`
**BDD Status:** Step definitions exist ✅
##### ✅ Scenario 3.3: Show template body preview
```gherkin
Given I have a template
When I run "rgen show templates/test.tmpl"
Then I should see a preview of the first 10 lines
And a count of remaining lines if > 10
```
**Feature File:** `cli_commands.feature`
**BDD Status:** Step definitions exist ✅
---
## Marketplace Commands
### 4. `rgen search` - Search for rpacks in registry
**JTBD:** "When I need to find a template package, I want to search the marketplace, so that I can discover and install the right solution."
#### Command Syntax
```bash
rgen search [OPTIONS] <QUERY>
-c, --category <CATEGORY> Filter by category
-k, --keyword <KEYWORD> Filter by keyword
-a, --author <AUTHOR> Filter by author/owner
--stable Show only stable versions
-l, --limit <LIMIT> Limit results [default: 20]
--json Output as JSON
-d, --detailed Show detailed information
```
#### Test Scenarios
##### ✅ Scenario 4.1: Basic search (WORKING)
```gherkin
Given the registry has rpacks
When I run "rgen search rust"
Then I should see matching rpacks
And each result should show:
- ID
- Latest version
- Tags
- Description (truncated)
```
**Current Status:** ✅ Working with local mock registry
**Unit Test:** `test_search_command_basic_usage` ✅ PASSING
**Feature File:** `marketplace.feature`
##### ✅ Scenario 4.2: Search with category filter
```gherkin
Given the registry has rpacks in multiple categories
When I run "rgen search api --category rust"
Then I should only see Rust category rpacks
```
**Current Status:** ✅ Working
**Unit Test:** `test_search_command_with_filters` ✅ PASSING
**Feature File:** `marketplace.feature`
##### ✅ Scenario 4.3: Search with JSON output (WORKING)
```gherkin
Given the registry has rpacks
When I run "rgen search rust --json"
Then I should receive valid JSON
And it should contain fields: id, name, description, tags, version
```
**Current Status:** ✅ Working
**Unit Test:** `test_cli_output_formats` ✅ PASSING
**Feature File:** `marketplace.feature`
##### ✅ Scenario 4.4: Search with detailed output
```gherkin
Given the registry has rpacks
When I run "rgen search rust --detailed"
Then I should see full information including:
- ID, name, version
- Full description
- All tags and keywords
- Category
- Author
- Download count
- Last updated date
```
**Current Status:** ✅ Working
**Unit Test:** `test_cli_output_formats` ✅ PASSING
**Feature File:** `marketplace.feature`
##### ⚠️ Scenario 4.5: Search with no results
```gherkin
Given the registry has rpacks
When I run "rgen search nonexistent-xyz-123"
Then I should see "No rpacks found matching your criteria"
```
**Feature File:** `marketplace.feature`
**BDD Status:** Needs implementation
---
### 5. `rgen categories` - Show popular categories and keywords
**JTBD:** "When I want to explore the marketplace, I want to see popular categories and keywords, so that I can discover relevant templates."
#### Command Syntax
```bash
rgen categories [OPTIONS]
--keywords Show popular keywords instead
-d, --detailed Show detailed statistics
--json Output as JSON
```
#### Test Scenarios
##### ⚠️ Scenario 5.1: List categories
```gherkin
Given the registry has rpacks in multiple categories
When I run "rgen categories"
Then I should see popular categories like:
- rust
- python
- web
- cli
```
**Feature File:** `marketplace.feature`
**BDD Status:** Needs implementation
##### ⚠️ Scenario 5.2: List keywords
```gherkin
Given the registry has rpacks with keywords
When I run "rgen categories --keywords"
Then I should see popular keywords like:
- api
- database
- auth
- cli
```
**Feature File:** `marketplace.feature`
**BDD Status:** Needs implementation
---
### 6. `rgen add` - Add an rpack to the project
**JTBD:** "When I find a useful template package, I want to install it to my project, so that I can use its templates locally."
#### Command Syntax
```bash
rgen add <RPACK_ID>
```
#### Test Scenarios
##### ⚠️ Scenario 6.1: Add latest version
```gherkin
Given the rpack "io.rgen.rust.cli-subcommand" exists
When I run "rgen add io.rgen.rust.cli-subcommand"
Then the rpack should be downloaded
And it should be added to rgen.toml
And it should be cached locally
```
**Feature File:** `marketplace.feature`
**BDD Status:** Step definitions exist ✅
##### ⚠️ Scenario 6.2: Add specific version
```gherkin
Given the rpack has multiple versions
When I run "rgen add io.rgen.rust.cli-subcommand@0.2.0"
Then version 0.2.0 should be installed
```
**Feature File:** `marketplace.feature`
**BDD Status:** Needs implementation
##### ⚠️ Scenario 6.3: Add already installed rpack
```gherkin
Given the rpack is already installed
When I run "rgen add io.rgen.rust.cli-subcommand"
Then I should see "Already installed at version X.X.X"
And no changes should be made
```
**Feature File:** `marketplace.feature`
**BDD Status:** Needs implementation
---
### 7. `rgen remove` - Remove an rpack from the project
**JTBD:** "When I no longer need a template package, I want to uninstall it, so that my project stays clean."
#### Command Syntax
```bash
rgen remove [OPTIONS] <RPACK_ID>
--prune Also remove from cache
```
#### Test Scenarios
##### ⚠️ Scenario 7.1: Remove rpack
```gherkin
Given the rpack "io.rgen.rust.cli-subcommand" is installed
When I run "rgen remove io.rgen.rust.cli-subcommand"
Then it should be removed from rgen.toml
And the templates should no longer be available
But the cache should remain (unless --prune)
```
**Feature File:** `marketplace.feature`
**BDD Status:** Needs implementation
##### ⚠️ Scenario 7.2: Remove with cache cleanup
```gherkin
Given the rpack is installed
When I run "rgen remove io.rgen.rust.cli-subcommand --prune"
Then it should be removed from rgen.toml
And it should be removed from cache
And disk space should be freed
```
**Feature File:** `marketplace.feature`
**BDD Status:** Needs implementation
---
### 8. `rgen packs` - List installed rpacks
**JTBD:** "When I need to see what packages are installed, I want a list with versions, so that I can manage my dependencies."
#### Command Syntax
```bash
rgen packs
```
#### Test Scenarios
##### ⚠️ Scenario 8.1: List installed rpacks
```gherkin
Given I have installed 2 rpacks
When I run "rgen packs"
Then I should see both rpacks with:
- ID
- Version
- Template count
```
**Feature File:** `marketplace.feature`
**BDD Status:** Needs implementation
##### ⚠️ Scenario 8.2: No rpacks installed
```gherkin
Given I have no rpacks installed
When I run "rgen packs"
Then I should see "No rpacks installed"
```
**Feature File:** `marketplace.feature`
**BDD Status:** Needs implementation
---
### 9. `rgen update` - Update rpacks to latest versions
**JTBD:** "When new versions are available, I want to update my packages, so that I have the latest features and fixes."
#### Command Syntax
```bash
rgen update [RPACK_ID]
```
#### Test Scenarios
##### ⚠️ Scenario 9.1: Update all rpacks
```gherkin
Given I have installed rpacks with updates available
When I run "rgen update"
Then all rpacks should be updated to latest compatible versions
And rgen.toml should be updated
```
**Feature File:** `marketplace.feature`
**BDD Status:** Needs implementation
##### ⚠️ Scenario 9.2: Update specific rpack
```gherkin
Given "io.rgen.rust.cli-subcommand" has an update
When I run "rgen update io.rgen.rust.cli-subcommand"
Then only that rpack should be updated
```
**Feature File:** `marketplace.feature`
**BDD Status:** Needs implementation
---
## Discovery Commands
### 10. `rgen lint` - Lint template with schema validation
**JTBD:** "When I create a template, I want to validate it, so that I catch errors before using it."
#### Command Syntax
```bash
rgen lint [OPTIONS] <TEMPLATE>
-v, --var <VARS> Variables for frontmatter rendering
--verbose Show detailed output
--shacl Perform SHACL validation
```
#### Test Scenarios
##### ⚠️ Scenario 10.1: Lint valid template
```gherkin
Given I have a valid template
When I run "rgen lint templates/test.tmpl"
Then I should see "✓ Template is valid"
```
**Feature File:** `cli_commands.feature`
**BDD Status:** Needs implementation
##### ⚠️ Scenario 10.2: Lint invalid frontmatter
```gherkin
Given I have a template with invalid YAML frontmatter
When I run "rgen lint templates/invalid.tmpl"
Then I should see syntax errors
And line numbers where errors occur
```
**Feature File:** `cli_commands.feature`
**BDD Status:** Needs implementation
##### ⚠️ Scenario 10.3: SHACL validation
```gherkin
Given I have a template with RDF data
When I run "rgen lint templates/test.tmpl --shacl"
Then SHACL constraints should be validated
```
**Feature File:** `cli_commands.feature`
**BDD Status:** Needs implementation
---
## Utility Commands
### 11. `rgen graph` - Export RDF graph
**JTBD:** "When I need to inspect RDF data, I want to export the graph, so that I can debug or analyze it."
#### Command Syntax
```bash
rgen graph [OPTIONS] <SCOPE> <ACTION>
-f, --format <FORMAT> turtle, ntriples, rdfxml, jsonld [default: turtle]
-o, --output <OUTPUT> Output file (default: stdout)
--include-prefixes Include prefixes
```
#### Test Scenarios
##### ⚠️ Scenario 11.1: Export graph as Turtle
```gherkin
Given I have RDF data for scope "cli" and action "subcommand"
When I run "rgen graph cli subcommand"
Then I should see Turtle format RDF output
```
**Feature File:** `rdf_sparql.feature`
**BDD Status:** Needs implementation
##### ⚠️ Scenario 11.2: Export to file
```gherkin
Given I have RDF data
When I run "rgen graph cli subcommand --output graph.ttl"
Then a file "graph.ttl" should be created
And it should contain valid Turtle syntax
```
**Feature File:** `rdf_sparql.feature`
**BDD Status:** Needs implementation
##### ⚠️ Scenario 11.3: Export as JSON-LD
```gherkin
Given I have RDF data
When I run "rgen graph cli subcommand --format jsonld"
Then I should see valid JSON-LD output
```
**Feature File:** `rdf_sparql.feature`
**BDD Status:** Needs implementation
---
### 12. `rgen hazard` - Generate hazard report
**JTBD:** "When I want to assess code safety, I want a hazard report, so that I can identify potential risks."
#### Command Syntax
```bash
rgen hazard
```
#### Test Scenarios
##### ✅ Scenario 12.1: Generate hazard report
```gherkin
Given I have templates with various patterns
When I run "rgen hazard"
Then I should see a report of potential hazards
```
**Current Status:** ✅ Working
**Unit Test:** `test_hazard_stdout` ✅ PASSING
**Feature File:** `cli_commands.feature`
##### ✅ Scenario 12.2: Hazard exit code
```gherkin
Given I have templates
When I run "rgen hazard"
Then the exit code should be 0 (success)
```
**Current Status:** ✅ Working
**Unit Test:** `test_hazard_exit_code` ✅ PASSING
**Feature File:** `cli_commands.feature`
---
### 13. `rgen completion` - Generate shell completion scripts
**JTBD:** "When I use rgen frequently, I want shell completions, so that I can work faster with tab completion."
#### Command Syntax
```bash
rgen completion <SHELL>
bash, zsh, fish
```
#### Test Scenarios
##### ⚠️ Scenario 13.1: Generate bash completion
```gherkin
When I run "rgen completion bash"
Then I should see valid bash completion script
And it should include all rgen commands
```
**Feature File:** `cli_commands.feature`
**BDD Status:** Needs implementation
##### ⚠️ Scenario 13.2: Generate zsh completion
```gherkin
When I run "rgen completion zsh"
Then I should see valid zsh completion script
```
**Feature File:** `cli_commands.feature`
**BDD Status:** Needs implementation
---
## Developer Commands
### 14. Global Options
**JTBD:** "When I debug issues, I want verbose logging, so that I can understand what's happening."
#### Command Syntax
```bash
rgen [OPTIONS] <COMMAND>
-c, --config <FILE> Custom config file
--manifest-path <PATH> Path to rgen.toml
-d, --debug <DEBUG> Enable debug mode
-l, --log-level <LOG_LEVEL> Set log level
-h, --help Show help
-V, --version Show version
```
#### Test Scenarios
##### ✅ Scenario 14.1: Version command
```gherkin
When I run "rgen --version"
Then I should see "rgen 0.1.0"
```
**Current Status:** ✅ Working
**Unit Test:** `test_version` ✅ PASSING
##### ✅ Scenario 14.2: Help command
```gherkin
When I run "rgen --help"
Then I should see all available commands
And usage examples
```
**Current Status:** ✅ Working
**Unit Test:** `test_cli_help_commands` ✅ PASSING
##### ✅ Scenario 14.3: Subcommand help
```gherkin
When I run "rgen gen --help"
Then I should see gen-specific options
And usage examples for gen
```
**Current Status:** ✅ Working
**Unit Test:** `test_cli_help_commands` ✅ PASSING
##### ✅ Scenario 14.4: Environment variables
```gherkin
Given RGEN_TRACE is set to "1"
When I run any rgen command
Then tracing output should be enabled
```
**Current Status:** ✅ Working
**Unit Test:** `test_cli_environment_variables` ✅ PASSING
##### ✅ Scenario 14.5: Error handling
```gherkin
When I run "rgen gen nonexistent.tmpl"
Then I should see a clear error message
And the exit code should be non-zero
```
**Current Status:** ✅ Working
**Unit Test:** `test_cli_error_handling` ✅ PASSING
---
## Test Coverage Matrix
### Unit Tests Status (46 tests)
| rgen-core lib | 3 | ✅ PASS | Core functionality |
| utils lib | 3 | ✅ PASS | Utilities |
| CLI integration | 13 | ✅ PASS | All CLI scenarios |
| E2E tests | 7 | ✅ PASS | End-to-end flows |
| Integration | 3 | ✅ PASS | Component integration |
| Mock registry | 17 | ✅ PASS | Registry operations |
| **TOTAL** | **46** | **✅ PASS** | **100% passing** |
### BDD Feature Coverage
| quickstart.feature | 3 | ✅ Exist | Ready for scenarios |
| template_generation.feature | TBD | ✅ Exist | Ready for scenarios |
| marketplace.feature | TBD | ✅ Exist | Ready for scenarios |
| cli_commands.feature | TBD | ✅ Exist | Ready for scenarios |
| determinism.feature | TBD | ✅ Exist | Ready for scenarios |
| multi_language.feature | TBD | ✅ Exist | Ready for scenarios |
| rdf_sparql.feature | TBD | ✅ Exist | Ready for scenarios |
| installation.feature | TBD | ✅ Exist | Ready for scenarios |
### Command Coverage Status
| `rgen gen` | ✅ | ✅ | ✅ | Local & pack templates |
| `rgen list` | ✅ | ✅ | ✅ | Template listing |
| `rgen show` | ✅ | ⚠️ | ✅ | Frontmatter display |
| `rgen search` | ✅ | ✅ | ✅ | **NOW WORKING!** |
| `rgen categories` | ⚠️ | ⚠️ | ⚠️ | Needs implementation |
| `rgen add` | ⚠️ | ⚠️ | ✅ | Step defs exist |
| `rgen remove` | ⚠️ | ⚠️ | ⚠️ | Needs implementation |
| `rgen packs` | ⚠️ | ⚠️ | ⚠️ | Needs implementation |
| `rgen update` | ⚠️ | ⚠️ | ⚠️ | Needs implementation |
| `rgen lint` | ⚠️ | ⚠️ | ⚠️ | Needs implementation |
| `rgen graph` | ⚠️ | ⚠️ | ⚠️ | Needs implementation |
| `rgen hazard` | ✅ | ✅ | ✅ | Fully tested |
| `rgen completion` | ⚠️ | ⚠️ | ⚠️ | Needs implementation |
| Global options | ✅ | ✅ | ✅ | Help, version, etc. |
**Legend:**
- ✅ = Fully tested and working
- ⚠️ = Needs implementation or additional tests
- 🔴 = Known issues
---
## Priority Test Implementation Plan
### Phase 1: Core v0.1.0 (COMPLETE ✅)
- [x] rgen gen (all modes)
- [x] rgen list
- [x] rgen show
- [x] rgen search (NOW WORKING!)
- [x] rgen hazard
- [x] Global options (help, version, debug)
### Phase 2: Marketplace v0.2.0 (Future)
- [ ] rgen add (with version support)
- [ ] rgen remove (with prune)
- [ ] rgen packs (detailed listing)
- [ ] rgen update (all & specific)
- [ ] rgen categories (with keywords)
### Phase 3: Advanced v0.3.0 (Future)
- [ ] rgen lint (with SHACL)
- [ ] rgen graph (all formats)
- [ ] rgen completion (all shells)
- [ ] Advanced RDF/SPARQL scenarios
- [ ] Multi-language edge cases
---
## Summary
**Current Status:**
- ✅ **46/46 unit tests passing**
- ✅ **Core commands fully tested**
- ✅ **Search functionality working with mock registry**
- ✅ **BDD infrastructure ready**
- ⚠️ **Marketplace commands need implementation**
**Next Steps:**
1. Implement BDD scenarios for existing features
2. Complete marketplace command tests (add/remove/update/packs)
3. Add lint and graph command scenarios
4. Expand RDF/SPARQL test coverage
**Test Philosophy:**
- **Unit tests:** Fast, isolated, comprehensive edge cases
- **Integration tests:** Component interaction, realistic flows
- **BDD tests:** User-facing scenarios, acceptance criteria
- **E2E tests:** Full workflows, real-world usage patterns