|
2 | 2 |
|
3 | 3 | ## Purpose |
4 | 4 | Define `openspec schema init` behavior for creating project-local schema skeletons in interactive and non-interactive modes. |
5 | | - |
6 | 5 | ## Requirements |
7 | 6 | ### Requirement: Schema init command creates project-local schema |
8 | 7 | The CLI SHALL provide an `openspec schema init <name>` command that creates a new schema directory under `openspec/schemas/<name>/` with a valid `schema.yaml` file and default template files. |
@@ -74,3 +73,23 @@ The CLI SHALL support `--json` flag for machine-readable output. |
74 | 73 | - **THEN** system outputs JSON with `error` field describing the issue |
75 | 74 | - **AND** exits with non-zero code |
76 | 75 |
|
| 76 | +### Requirement: Schema init validates artifacts before forced replacement |
| 77 | +The CLI SHALL validate all requested artifact IDs before replacing an existing project-local schema. If artifact validation fails, the CLI SHALL leave the existing schema directory and all of its contents unchanged on every supported platform. |
| 78 | + |
| 79 | +#### Scenario: Unknown artifact preserves existing schema |
| 80 | +- **GIVEN** `openspec/schemas/tdd-driven/` already exists with user-authored files |
| 81 | +- **WHEN** the user runs `schema init tdd-driven` with `--force` and an artifact list containing the unknown ID `task` |
| 82 | +- **THEN** the command exits with a non-zero status and reports the unknown artifact |
| 83 | +- **AND** the existing `tdd-driven` schema directory and its contents remain unchanged |
| 84 | + |
| 85 | +#### Scenario: Unknown artifact preserves a schema at a Windows project path |
| 86 | +- **GIVEN** an existing project-local schema is resolved from a Windows filesystem path |
| 87 | +- **WHEN** forced schema initialization fails artifact validation |
| 88 | +- **THEN** the resolved schema directory and its contents remain unchanged |
| 89 | + |
| 90 | +#### Scenario: Valid artifacts allow forced replacement |
| 91 | +- **GIVEN** a project-local schema already exists |
| 92 | +- **WHEN** the user runs `schema init` with `--force` and only valid artifact IDs |
| 93 | +- **THEN** the command replaces the existing schema with the newly generated schema |
| 94 | +- **AND** reports successful creation |
| 95 | + |
0 commit comments