Skip to content

Harden GenerationGuide runtime validation#60

Closed
christopherkarani wants to merge 1 commit into
mainfrom
codex/check-frameworks-for-issues-20260514
Closed

Harden GenerationGuide runtime validation#60
christopherkarani wants to merge 1 commit into
mainfrom
codex/check-frameworks-for-issues-20260514

Conversation

@christopherkarani

Copy link
Copy Markdown
Owner

Summary

This PR addresses a production safety gap in Conduit’s public generation-guide API by removing process-terminating preconditions from runtime-facing guide builders and replacing them with safe no-op behavior.

Problem

Several public guide constructors used precondition(...) on values that may originate from dynamic runtime paths (including user/config-driven inputs):

  • GenerationGuide<String>.anyOf(_:) with empty arrays
  • GenerationGuide<[Element]>.minimumCount(_:) with negative values
  • GenerationGuide<[Element]>.maximumCount(_:) with negative values
  • GenerationGuide<[Element]>.count(_:) for negative exact counts
  • GenerationGuide<[Element]>.count(_:) for ranges with negative lower bounds

In production apps, hitting these branches terminates the process.

Changes

  • Replaced precondition traps with guard-based safe fallback returning .unsupported (no-op constraint).
  • Added regression tests in GenerationGuideValidationTests proving:
    • empty anyOf guide degrades to no-op (no enum emitted)
    • negative array count guides degrade to no-op (no min/max items emitted)

Why this design

  • Invalid guide inputs should not crash host applications.
  • .unsupported already exists as an intentional no-op constraint path and integrates cleanly with schema generation.
  • This keeps API compatibility and prevents runtime termination while preserving deterministic schema behavior for valid guides.

Verification

  • swift test --filter GenerationGuideValidationTests
  • swift test
  • swift build

All passed locally.

- replace precondition traps in public guide builders with unsupported/no-op fallback

- add regression tests for empty anyOf and negative array count guides

- verify with targeted guide tests, full swift test, and swift build
@christopherkarani

Copy link
Copy Markdown
Owner Author

Closing as superseded. The GenerationGuide runtime validation fix was already landed via PR #59, and this branch is now stale/conflicting with no remaining unique merge value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant