Skip to content

Add SymbolLocator dependency and OpenSwiftUISymbolDualTests #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2025

Conversation

Kyle-Ye
Copy link
Member

@Kyle-Ye Kyle-Ye commented May 2, 2025

Summary by CodeRabbit

  • New Features

    • Introduced additional test targets and modularized testing infrastructure for improved test coverage.
    • Added support for symbol resolution testing related to the CGSize.hasZero property in SwiftUI.
    • Integrated a new external package dependency for symbol location.
  • Bug Fixes

    • Improved consistency and structure of package dependencies and target declarations.
  • Documentation

    • Added new documentation explaining symbol dual testing and usage examples for internal SwiftUI APIs.
  • Chores

    • Removed the package resolution lock file to streamline dependency management.

Copy link

coderabbitai bot commented May 2, 2025

Walkthrough

This update restructures the Swift package manifest (Package.swift) by introducing new targets, test targets, and an external package dependency (SymbolLocator). It adds a helper module and corresponding tests for symbol duality, specifically targeting the CGSize.hasZero property in SwiftUI. The update also includes new C and Swift files for stubbing and testing internal SwiftUI symbols, and provides documentation for the new symbol dual tests. The package dependency lock file (Package.resolved) has been removed, reflecting a shift in dependency management.

Changes

File(s) Change Summary
Package.resolved Deleted the package dependency lock file that specified exact dependency versions and revisions.
Package.swift Reorganized and expanded the manifest: added new targets and test targets, introduced the SymbolLocator dependency, clarified target groupings, and updated dependencies and test infrastructure.
Sources/OpenSwiftUISymbolDualTestsHelper/Extension/CGSize+ExtensionTestsStub.c Added a C stub file that defines a symbol for CGSize.hasZero using the SymbolLocator framework, conditionally compiled for Darwin platforms.
Tests/OpenSwiftUISymbolDualTests/Extension/CGSize+ExtensionTests.swift Added Swift test file extending CGSize with a computed property linked to a SwiftUI internal symbol and tests verifying parity between OpenSwiftUI and SwiftUI implementations.
Tests/OpenSwiftUISymbolDualTests/README.md Added documentation describing the use of symbol stubs and dual testing for the CGSize.hasZero property, including code snippets in C and Swift.

Sequence Diagram(s)

sequenceDiagram
    participant TestRunner
    participant CGSize_ExtensionTests
    participant CGSize
    participant SwiftUIStub

    TestRunner->>CGSize_ExtensionTests: Run hasZero test
    CGSize_ExtensionTests->>CGSize: Call hasZero (OpenSwiftUI)
    CGSize_ExtensionTests->>CGSize: Call swiftUIHasZero (via @_silgen_name)
    CGSize->>SwiftUIStub: Access OpenSwiftUITestStub_CGSizeHasZero
    SwiftUIStub-->>CGSize: Return result
    CGSize_ExtensionTests->>TestRunner: Assert results match expected
Loading

Suggested reviewers

  • Mx-Iris

Poem

A hop, a skip, a package anew,
With targets and tests, and dependencies too!
Symbols are stubbed, extensions are tried,
SwiftUI secrets, no longer to hide.
The README now sings of stubs and delight—
A rabbit’s code garden, blooming just right! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
Tests/OpenSwiftUISymbolDualTests/README.md (1)

3-4: Minor wording tweak for clarity

Missing article “a/the” makes the sentence read a little abruptly.

-Test non-public API of SwiftUI via SymbolLocator.
+Test a non-public SwiftUI API via the SymbolLocator framework.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~3-~3: You might be missing the article “the” here.
Context: ## OpenSwiftUISymbolDualTests Test non-public API of SwiftUI via SymbolLocator...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)

Tests/OpenSwiftUISymbolDualTests/Extension/CGSize+ExtensionTests.swift (1)

18-18: Rename test type to adhere to Swift naming guidelines

SwiftLint rightfully warns that CGSize_ExtensionTests contains an underscore.
CGSizeHasZeroTests or CGSizeExtensionTests reads cleaner and avoids the violation.

-struct CGSize_ExtensionTests {
+struct CGSizeHasZeroTests {
🧰 Tools
🪛 SwiftLint (0.57.0)

[Error] 18-18: Type name 'CGSize_ExtensionTests' should only contain alphanumeric and other allowed characters

(type_name)

Package.swift (1)

249-259: Helper target is always built but contains only Darwin stubs

OpenSwiftUISymbolDualTestsHelper has C sources that are effectively empty on non-Darwin after the previous suggestion.
SwiftPM will still build (and distribute) the target on Linux, pulling the SymbolLocator dependency unnecessarily.

Consider limiting the target with a platform condition to speed up cross-platform builds:

-let openSwiftUISymbolDualTestsHelperTarget = Target.target(
+let openSwiftUISymbolDualTestsHelperTarget = Target.target(
+    // Only meaningful on Apple OSes where SwiftUI exists
+    // (Linux & Windows can still compile the main package without the helper)
     name: "OpenSwiftUISymbolDualTestsHelper",
     dependencies: [
         .product(name: "SymbolLocator", package: "SymbolLocator"),
     ],
@@
-)
+    swiftSettings: sharedSwiftSettings,
+    linkerSettings: [],
+    cSettings: [],
+    cxxSettings: [],
+    // 🔽
+    // 📌 Make this target Apple-only.
+    //     .when(platforms: [.darwinPlatforms])
+)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ab004a and 1e8e715.

📒 Files selected for processing (5)
  • Package.resolved (0 hunks)
  • Package.swift (7 hunks)
  • Sources/OpenSwiftUISymbolDualTestsHelper/Extension/CGSize+ExtensionTestsStub.c (1 hunks)
  • Tests/OpenSwiftUISymbolDualTests/Extension/CGSize+ExtensionTests.swift (1 hunks)
  • Tests/OpenSwiftUISymbolDualTests/README.md (1 hunks)
💤 Files with no reviewable changes (1)
  • Package.resolved
🧰 Additional context used
🪛 LanguageTool
Tests/OpenSwiftUISymbolDualTests/README.md

[uncategorized] ~3-~3: You might be missing the article “the” here.
Context: ## OpenSwiftUISymbolDualTests Test non-public API of SwiftUI via SymbolLocator...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)

🪛 SwiftLint (0.57.0)
Tests/OpenSwiftUISymbolDualTests/Extension/CGSize+ExtensionTests.swift

[Error] 18-18: Type name 'CGSize_ExtensionTests' should only contain alphanumeric and other allowed characters

(type_name)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Execute tests on Ubuntu (6.0.1)
  • GitHub Check: Execute compatibility tests for macOS (macos-15, 16.0, 2024)
  • GitHub Check: Execute tests on macOS (macos-15, 16.0, 2024)
  • GitHub Check: Execute tests on macOS (macos-15, 16.0, 2021)
  • GitHub Check: Execute tests on iOS (macos-15, 16.0, 2021, 18.0)
  • GitHub Check: Execute tests on iOS (macos-15, 16.0, 2024, 18.0)
🔇 Additional comments (2)
Tests/OpenSwiftUISymbolDualTests/Extension/CGSize+ExtensionTests.swift (1)

17-33: Attribute argument syntax likely to fail compilation

The second parameter is passed as .enabled { … }, but the @Test macro expects either
enabled: labeled argument or .enabled{} inside an options array depending on the overload.

Please double-check the syntax against the current Testing API. A minimal change that compiles on 6.1 snapshots is:

-    .enabled {
+    enabled: {
         #available(iOS 18, macOS 14, *)
     },

Also consider removing the trailing comma before the closing ) to silence “unexpected argument” diagnostics.

🧰 Tools
🪛 SwiftLint (0.57.0)

[Error] 18-18: Type name 'CGSize_ExtensionTests' should only contain alphanumeric and other allowed characters

(type_name)

Package.swift (1)

300-303: Confirm third-party licence compatibility for SymbolLocator

Before merging, verify that SymbolLocator’s licence is compatible with OpenSwiftUI’s distribution model (especially if you plan to publish binaries).

Comment on lines +5 to +13
#include "OpenSwiftUIBase.h"

#if OPENSWIFTUI_TARGET_OS_DARWIN

#import <SymbolLocator.h>

DEFINE_SL_STUB_SLF(OpenSwiftUITestStub_CGSizeHasZero, SwiftUI, $sSo6CGSizeV7SwiftUIE7hasZeroSbvg);

#endif
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Guard the Darwin-only code earlier to avoid build failures on non-Darwin platforms

OpenSwiftUIBase.h may itself pull in Darwin-specific SDK headers. Including it unconditionally means this file will still be compiled on Linux/WASI and will fail during preprocessing even though the body is wrapped in #if OPENSWIFTUI_TARGET_OS_DARWIN.

-#include "OpenSwiftUIBase.h"
-
-#if OPENSWIFTUI_TARGET_OS_DARWIN
-#import <SymbolLocator.h>
-DEFINE_SL_STUB_SLF(OpenSwiftUITestStub_CGSizeHasZero, SwiftUI, $sSo6CGSizeV7SwiftUIE7hasZeroSbvg);
-#endif
+#if OPENSWIFTUI_TARGET_OS_DARWIN
+#include "OpenSwiftUIBase.h"
+#import <SymbolLocator.h>
+DEFINE_SL_STUB_SLF(OpenSwiftUITestStub_CGSizeHasZero, SwiftUI, $sSo6CGSizeV7SwiftUIE7hasZeroSbvg);
+#endif

This keeps the entire translation unit empty on non-Darwin platforms and avoids accidental header leakage.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#include "OpenSwiftUIBase.h"
#if OPENSWIFTUI_TARGET_OS_DARWIN
#import <SymbolLocator.h>
DEFINE_SL_STUB_SLF(OpenSwiftUITestStub_CGSizeHasZero, SwiftUI, $sSo6CGSizeV7SwiftUIE7hasZeroSbvg);
#endif
#if OPENSWIFTUI_TARGET_OS_DARWIN
#include "OpenSwiftUIBase.h"
#import <SymbolLocator.h>
DEFINE_SL_STUB_SLF(OpenSwiftUITestStub_CGSizeHasZero, SwiftUI, $sSo6CGSizeV7SwiftUIE7hasZeroSbvg);
#endif

Comment on lines +10 to +15
extension CGSize {
var swiftUIHasZero: Bool {
@_silgen_name("OpenSwiftUITestStub_CGSizeHasZero")
get
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Prefer an external C-style thunk instead of applying @_silgen_name directly to a property

@_silgen_name is intended for functions; applying it to a property accessor is unsupported and relies on undefined behaviour.
A safer pattern is to expose the stub as a private C-style function and wrap it in a Swift computed property:

-extension CGSize {
-    var swiftUIHasZero: Bool {
-        @_silgen_name("OpenSwiftUITestStub_CGSizeHasZero")
-        get
-    }
-}
+@_silgen_name("OpenSwiftUITestStub_CGSizeHasZero")
+private func _swiftUIHasZero(_ size: CGSize) -> Bool
+
+extension CGSize {
+    var swiftUIHasZero: Bool { _swiftUIHasZero(self) }
+}

This avoids ABI guess-work and makes the call-site explicit.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
extension CGSize {
var swiftUIHasZero: Bool {
@_silgen_name("OpenSwiftUITestStub_CGSizeHasZero")
get
}
}
@_silgen_name("OpenSwiftUITestStub_CGSizeHasZero")
private func _swiftUIHasZero(_ size: CGSize) -> Bool
extension CGSize {
var swiftUIHasZero: Bool { _swiftUIHasZero(self) }
}

Copy link

codecov bot commented May 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 20.96%. Comparing base (9ab004a) to head (2eade37).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #263      +/-   ##
==========================================
+ Coverage   20.94%   20.96%   +0.02%     
==========================================
  Files         337      337              
  Lines       15486    15486              
==========================================
+ Hits         3243     3247       +4     
+ Misses      12243    12239       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
Tests/OpenSwiftUISymbolDualTests/Extension/CGSize+ExtensionTests.swift (1)

10-15: Prefer an external C-style thunk instead of applying @_silgen_name directly to a property

@_silgen_name is intended for functions; applying it to a property accessor is unsupported and relies on undefined behavior.
A safer pattern is to expose the stub as a private C-style function and wrap it in a Swift computed property:

-extension CGSize {
-    var swiftUIHasZero: Bool {
-        @_silgen_name("OpenSwiftUITestStub_CGSizeHasZero")
-        get
-    }
-}
+@_silgen_name("OpenSwiftUITestStub_CGSizeHasZero")
+private func _swiftUIHasZero(_ size: CGSize) -> Bool
+
+extension CGSize {
+    var swiftUIHasZero: Bool { _swiftUIHasZero(self) }
+}

This avoids ABI guess-work and makes the call-site explicit.

🧹 Nitpick comments (2)
Tests/OpenSwiftUISymbolDualTests/README.md (1)

3-3: Consider adding "the" before "non-public API"

The sentence would read better as "Test the non-public API of SwiftUI via SymbolLocator."

-Test non-public API of SwiftUI via SymbolLocator.
+Test the non-public API of SwiftUI via SymbolLocator.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~3-~3: You might be missing the article “the” here.
Context: ## OpenSwiftUISymbolDualTests Test non-public API of SwiftUI via SymbolLocator...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)

Tests/OpenSwiftUISymbolDualTests/Extension/CGSize+ExtensionTests.swift (1)

18-18: Use camelCase for type names instead of snake_case

Swift naming conventions recommend using camelCase for type names. Rename CGSize_ExtensionTests to CGSizeExtensionTests to follow this convention.

-struct CGSize_ExtensionTests {
+struct CGSizeExtensionTests {
🧰 Tools
🪛 SwiftLint (0.57.0)

[Error] 18-18: Type name 'CGSize_ExtensionTests' should only contain alphanumeric and other allowed characters

(type_name)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e8e715 and 2eade37.

📒 Files selected for processing (5)
  • Package.resolved (0 hunks)
  • Package.swift (7 hunks)
  • Sources/OpenSwiftUISymbolDualTestsHelper/Extension/CGSize+ExtensionTestsStub.c (1 hunks)
  • Tests/OpenSwiftUISymbolDualTests/Extension/CGSize+ExtensionTests.swift (1 hunks)
  • Tests/OpenSwiftUISymbolDualTests/README.md (1 hunks)
💤 Files with no reviewable changes (1)
  • Package.resolved
🚧 Files skipped from review as they are similar to previous changes (1)
  • Sources/OpenSwiftUISymbolDualTestsHelper/Extension/CGSize+ExtensionTestsStub.c
🧰 Additional context used
🪛 SwiftLint (0.57.0)
Tests/OpenSwiftUISymbolDualTests/Extension/CGSize+ExtensionTests.swift

[Error] 18-18: Type name 'CGSize_ExtensionTests' should only contain alphanumeric and other allowed characters

(type_name)

🪛 LanguageTool
Tests/OpenSwiftUISymbolDualTests/README.md

[uncategorized] ~3-~3: You might be missing the article “the” here.
Context: ## OpenSwiftUISymbolDualTests Test non-public API of SwiftUI via SymbolLocator...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Execute compatibility tests for iOS (macos-15, 16.0, 2024, 18.0)
  • GitHub Check: Execute tests on Ubuntu (6.0.1)
🔇 Additional comments (11)
Tests/OpenSwiftUISymbolDualTests/README.md (1)

5-23: Code examples look good!

The code examples clearly demonstrate how to use the SymbolLocator for testing SwiftUI internal symbols. The C macro for defining the stub and the Swift extension with the silgen name annotations are well structured.

Tests/OpenSwiftUISymbolDualTests/Extension/CGSize+ExtensionTests.swift (1)

19-40: Well-structured test with comprehensive test cases

The test is well-designed with multiple test cases covering different combinations of width and height values. The test correctly verifies that both the OpenSwiftUI and SwiftUI implementations behave identically and match the expected results.

Package.swift (9)

104-118: Clean restructuring of targets

The CoreGraphicsShims targets are now properly organized with a main target and corresponding test target, which improves the package structure.


132-143: Good test target organization

The OpenSwiftUI_SPITests target is properly structured with appropriate dependencies, including the main target and Numerics for testing.


161-170: Well-structured test target with appropriate dependencies

The OpenSwiftUICoreTests target includes the necessary dependencies for testing, with a proper comment explaining the OpenSwiftUI import requirement.


174-181: Clean COpenSwiftUI target declaration

The COpenSwiftUI target is well-structured with appropriate header search paths and settings.


204-220: Good test target reorganization

The OpenSwiftUITests and OpenSwiftUICompatibilityTests targets are properly restructured with appropriate dependencies.


228-234: Proper source specification for OpenSwiftUIBridge

The OpenSwiftUIBridge target now explicitly specifies its sources, which improves clarity and maintainability.


247-269: Well-designed SymbolDualTests infrastructure

The new OpenSwiftUISymbolDualTestsHelper target and its corresponding test target are properly structured with the necessary SymbolLocator dependency. This provides a clean separation between the test support code and the actual tests.


301-301: Successfully added SymbolLocator dependency

The SymbolLocator package dependency is properly specified with an appropriate version constraint.


315-334: Well-organized target list

The target list is now well-organized and includes all the new targets in a logical order, making the package structure easier to understand.

@Kyle-Ye Kyle-Ye merged commit e9db49a into main May 2, 2025
10 checks passed
@Kyle-Ye Kyle-Ye deleted the feature/test branch May 2, 2025 06:32
@coderabbitai coderabbitai bot mentioned this pull request May 5, 2025
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