feat(slice-4c.8): scenario clone server-side wired to POST /api/scenarios#36
Merged
Merged
Conversation
…rios
Server:
- New POST /api/scenarios with atomic Store.createScenario:
schema-validates body, 409 + EEXIST on id collision, 201 on
create, requires risk-map:edit. Mirrors POST /api/profiles
(slice 4c.3).
- 5 unit tests added (happy path 201, schema rejection on empty
oracles, 409 EEXIST, concurrent-POSTs atomicity, permission).
Store:
- New StoreProvider.createScenario(scenario): { created: boolean }
contract. MemoryStore implements via has+set in a single sync
block (no TOCTOU window). PostgresStore stays notImpl.
- Scaffold "every method throws not implemented" test extended
to cover createScenario.
Scope note: this slice delivers server-side trust-boundary +
atomic-create only. The admin-side Scenario Clone wizard is
deferred — same rationale as slice 4c.7 (the scenario detail
page is currently a read-only YAML preview; building a clone
modal requires either fabricating schema-conforming scenario
fixtures or wiring full-scenario reads from the store, both
larger than this slice).
Server: 72/72 (+5). Store: 6/6. Lint preexisting only.
There was a problem hiding this comment.
Pull request overview
Adds server-side support for “Scenario Clone” by introducing a create-only POST /api/scenarios endpoint backed by an atomic store operation, mirroring the existing profile-clone flow.
Changes:
- Introduces
POST /api/scenariosthat schema-validates the request, usesStoreProvider.createScenarioatomically, returns201on create and409 (code=EEXIST)on id collision, and requiresrisk-map:edit. - Extends the store contract with
createScenario(scenario): Promise<{ created: boolean }>and implements it inMemoryStore(withPostgresStorescaffolded to thrownot implemented). - Adds/extends unit tests covering the new endpoint behavior and the Postgres scaffold “not implemented” surface.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/store/test/store.test.ts | Extends Postgres scaffold tests to include createScenario as “not implemented”. |
| packages/store/src/types.ts | Adds StoreProvider.createScenario atomic-create contract. |
| packages/store/src/postgres.ts | Adds createScenario stub that throws not implemented. |
| packages/store/src/memory.ts | Implements createScenario with create-only semantics returning { created }. |
| packages/server/test/api.test.ts | Adds POST /api/scenarios tests: 201, 400 schema failure, 409 EEXIST, concurrency atomicity, permission. |
| packages/server/src/api.ts | Adds POST /api/scenarios handler wired to ctx.store.createScenario with correct status codes and permission. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
v1.7 slice 4c.8 — Scenario Clone, server-side.
Server
Store
Scope note
Admin-side Scenario Clone wizard is deferred — same rationale as slice 4c.7. The scenario detail page is currently a read-only YAML preview, and a clone modal needs either fabricated scenario fixtures or full-scenario reads from the store, both larger than this slice. The server contract is ready when that UI lands.
Test plan
🤖 Generated with Claude Code