refactor: type-safe snapshot system derived from OpenAPI schemas#4
Merged
refactor: type-safe snapshot system derived from OpenAPI schemas#4
Conversation
Replace all hand-written *Snapshot interfaces with types derived from the generated OpenAPI Update*Request schemas via Required<Schemas[...]>. This guarantees that when the API contract changes (field added, removed, or renamed), the TypeScript compiler immediately errors in the snapshot functions, preventing silent drift between YAML engine and API. Key changes: - Remove dead alwaysChanged plumbing from HandlerDef / defineHandler - Replace 14 custom snapshot interfaces with Required<UpdateXRequest> type aliases (tag, environment, notificationPolicy, webhook, resourceGroup, monitor) or documented custom types for special cases (secret: hash-based, alertChannel: hash-based, dependency: split API) - Remove 7 old normalization helpers, replace with 4 API-type-aligned helpers (sortAssertions, apiAssertionsToSnapshot, apiIncidentPolicyToSnapshot, apiTagsToSnapshot) - Export toCreateAssertionRequest and toIncidentPolicy from transform.ts - Centralize as-any casts into api-client.ts helper functions - Add typed RefEntry<K> generics to resolver.ts - Add RefTypeDtoMap to types.ts for compile-time DTO mapping - Fix webhook snapshot to also track enabled field - Fix resourceGroup snapshot field name (defaultAlertChannelIds → defaultAlertChannels) to match API contract - Make toDesiredSnapshot / toCurrentSnapshot required (not optional) Made-with: Cursor
8137bfe to
da3cf9a
Compare
- Exit codes: plan/deploy exit 0 by default; add --detailed-exitcode opt-in flag (exit 10 when changes pending, 11 for partial failure) - JSON output: add -o json to plan/deploy/validate for structured machine-readable output (ChangesetJson format) - Lock timeout: add --lock-timeout flag with 5s retry backoff - Force-unlock: add standalone `deploy force-unlock` command with confirmation prompt - Bump default lock TTL from 10min to 30min - Fix: integrate handleApiError into checkedFetch, remove dead code - Fix: environment handler uses slug for update/delete paths - Fix: group membership differ properly diffs against API state - Fix: webhook enabled field now controllable from YAML config - Remove dead monitor.resourceGroup field from schema/validator - Add monitors versions list/get commands Made-with: Cursor
… extraction - Update monitoring-api.json with latest spec (includes @Schema descriptions) - Regenerate api.generated.ts and descriptions.generated.ts - Add AcquireDeployLockRequest to extract-descriptions TARGET_SCHEMAS - Add cross-reference comment pointing to monorepo MUST_HAVE list Made-with: Cursor
- Environment handler now uses slug for update/delete paths (not ID) - Webhook snapshot now includes `enabled` field - Remove dead resourceGroup validation test (field was removed) Made-with: Cursor
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
Required<Schemas['UpdateXRequest']>— if the API contract changes (field added/removed/renamed), the TypeScript compiler immediately errors in the snapshot functions, preventing silent drift between YAML engine and API.alwaysChangedplumbing fromHandlerDef/defineHandler, 14 custom*Snapshotinterfaces, 7 old normalization helpers.as anycasts for dynamic API paths intoapi-client.tshelper functions (apiGet,apiPost,apiPut,apiPatch,apiDelete), cleaning them out of all other files.RefEntry<K>toresolver.tsandRefTypeDtoMaptotypes.tsfor compile-time DTO mapping on reference lookups.enabled; resource group field name corrected (defaultAlertChannelIds→defaultAlertChannelsto match API);toDesiredSnapshot/toCurrentSnapshotare now required (not optional).Three resources keep documented custom snapshot types where update semantics don't map 1:1:
Test plan
npx tsc --noEmit— clean typechecknpm test— all 384 tests passmake test-surface SURFACE=cliMade with Cursor