Skip to content

feat: Add a Swift harness - #5

Merged
Zaimwa9 merged 2 commits into
mainfrom
harness/swift
Oct 21, 2026
Merged

Zaimwa9 merged 2 commits into
mainfrom
harness/swift

Conversation

@Zaimwa9

@Zaimwa9 Zaimwa9 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Adds a Swift harness, so Swift SDKs can run the spec. First user: Flagsmith/flagsmith-ios-client#109.

  • harness/swift/: Swift cannot call a function by name at runtime, so, like the Go and Rust harnesses, the harness compiles the steps file in. A build tool plugin, GenerateSteps, runs StepsGenerator on the SDK's sdk-spec/steps.swift and generates a table mapping each step marker (Create the SDK client or When …) to the first function after it. The harness speaks the stdio protocol and decodes each JSON argument to the function's parameter type, inferred through step overloads by arity, so step functions can take and return any Decodable/Encodable types, and can be async and throw.
  • The SDK provides sdk-spec/Package.swift, which makes the steps file an SDKSpecSteps library depending on the SDK by path (as with the Rust harness's Cargo.toml). The README shows it and the sdk-spec/Dockerfile.
  • Steps run off the main thread, and the main thread runs dispatchMain(), because SDKs such as flagsmith-ios-client call back on the main queue.
  • SDK output on stdout is redirected to stderr. Responses go to the original stdout.
  • compatibility.yml: adds flagsmith-ios-client (ios, language swift).

Verified against flagsmith-ios-client feat/sdk-spec: 2 passed natively on macOS, and with the linux/amd64 image built as run-spec.yml does.

@Zaimwa9

Zaimwa9 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

@themis-blindfold review

@themis-blindfold

Copy link
Copy Markdown

⚖️ Themis review: 🟠 Fix before merge

TL;DR: The Swift harness can fail to build for a normally documented step because its generator mistakes func in a documentation comment for a declaration. CI is still queued; only the PR-title check has completed successfully.

Area Score
🎯 Correctness 3/5
🧪 Test coverage 2/5
📐 Code quality 3/5
🚀 Product impact 3/5

🟠 Majors

  • harness/swift/Sources/StepsGenerator/main.swift:21 — documentation comments can be mistaken for step functions, preventing documented steps from building.
📝 Walkthrough
  • harness/swift - adds a SwiftPM harness and integration instructions for SDK repositories.
  • StepsGenerator - generates the compile-time table required to dispatch Swift step functions.
  • Protocol handling - redirects SDK stdout, serialises JSON-line responses, and preserves stored client handles.
  • Compatibility CI - adds the iOS SDK to the cross-SDK spec matrix.
🧪 How to verify
  1. Add a /// documentation line containing func between a step marker and its public function, then run swift build --package-path harness against a sample SDK package.
  2. Confirm the generated table references the actual function rather than a word from the documentation line.
  3. Build the documented iOS SDK Dockerfile with the Swift harness context.
  4. Run the Swift compatibility scenario suite and confirm all implemented steps are reported and exercised.
    Automate: add a generator fixture with documentation comments, annotations, and valid function declarations.

Product take: This unlocks behavioural-spec coverage for the iOS SDK, a solid integration improvement.
The parser defect blocks SDK authors from using ordinary function documentation in their steps files, so it needs fixing before the harness is relied on.

🧭 Assumptions & unverified claims

The Swift and Docker toolchains were unavailable locally, so the package build and end-to-end image run were not repeated; the spec checks remain queued.

One small parser snag before Swift gets to do its swift thing · reviewed at 0df6726

@Zaimwa9
Zaimwa9 force-pushed the harness/swift branch 2 times, most recently from 2ce3603 to 2e3ef98 Compare October 21, 2026 14:40
@Zaimwa9

Zaimwa9 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

@themis-blindfold review

@Zaimwa9
Zaimwa9 marked this pull request as ready for review October 21, 2026 14:48
khvn26
khvn26 previously approved these changes Oct 21, 2026

@khvn26 khvn26 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@themis-blindfold

Copy link
Copy Markdown

⚖️ Themis review: 🟠 Fix before merge

The completed Swift compatibility run passes the current SDK scenarios, but an open generator defect still makes a documented Swift step bind to a comment rather than its declaration. The harness is also missing from the language index.

Area Score
🎯 Correctness 2/5
🧪 Test coverage 2/5
📐 Code quality 3/5
🚀 Product impact 3/5

🟠 Majors

  • harness/swift/Sources/StepsGenerator/main.swift:19 — documentation comments can be generated as function bindings (open thread).

🧹 Nits

  • HARNESS.md:8 — Observed: the language table omits the new Swift harness; add its row so SDK authors can discover it.
📝 Walkthrough
  • Swift harness - adds a SwiftPM executable, protocol loop, and JSON/client conversion layer for SDK steps.
  • Step generation - uses a SwiftPM build-tool plugin to map step comments in an SDK checkout to compiled Swift functions.
  • Compatibility matrix - adds the iOS SDK to the compatibility workflow.
🧪 How to verify
  1. Add a /// documentation line containing func between a step marker and its implementation, then build the harness; it must bind the declaration, not the comment text.
  2. Build the README Dockerfile example against the iOS SDK's sdk-spec checkout on Linux.
  3. Run SDK_COMMAND=<swift-harness-binary> uv run pytest -v from runner and confirm both core scenarios pass.
  4. Confirm harness/swift is listed in the language table alongside the other supported harnesses.
    Automate: add unit coverage for marker/function extraction, including comments, strings, attributes, and documented functions.

Product take: This is a solid onboarding improvement for the iOS SDK, but the parser defect can block SDK builds as soon as step functions are documented.

🧭 Assumptions & unverified claims

No unverified assumptions or claims.

Swift has joined the harness club; it just needs the guest list and comment parser checked. · reviewed at 2e3ef98

@Zaimwa9

Zaimwa9 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

@themis-blindfold review

@Zaimwa9
Zaimwa9 merged commit 39ee9af into main Oct 21, 2026
12 checks passed
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.

2 participants