Skip to content

Comments

Expand test coverage#24

Merged
rudrankriyam merged 1 commit intomainfrom
expand-test-coverage
Dec 8, 2025
Merged

Expand test coverage#24
rudrankriyam merged 1 commit intomainfrom
expand-test-coverage

Conversation

@rudrankriyam
Copy link
Member

This PR adds additional test coverage for:

Error Localization (3 tests)

  • Verify all SpeechSessionError cases have non-empty errorDescription
  • Verify all SpeechSessionError cases have non-empty failureReason
  • Verify all SpeechSessionError cases have non-empty recoverySuggestion

File Transcription Edge Cases (2 tests)

  • Test audioFileInvalidURL for non-file URLs
  • Test audioFileOutsideAllowedDirectories for restricted paths

Voice Activation (1 test)

  • Test disabling voice activation resets isSpeechDetected to true

Session Lifecycle (2 tests)

  • Test pause when idle does nothing
  • Test resume when idle does nothing

Test count increased from 12 to 20.

…session lifecycle

- Add SpeechSessionErrorTests to verify all error cases have descriptions, failure reasons, and recovery suggestions
- Add file transcription tests for invalid URLs and restricted directory paths
- Add voice activation test for isSpeechDetected reset behavior
- Add session lifecycle tests for pause/resume when idle
@gemini-code-assist
Copy link

Summary of Changes

Hello @rudrankriyam, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands the test coverage for the AuralKit framework, increasing the total test count from 12 to 20. The new tests focus on improving the robustness of error handling by verifying localization strings for SpeechSessionError cases, addressing edge cases in file transcription, ensuring correct behavior of voice activation state resets, and confirming idempotent session lifecycle operations when the session is idle. This enhancement aims to improve the overall stability and reliability of the speech session functionality.

Highlights

  • Error Localization: Added three new tests to verify that all SpeechSessionError cases provide non-empty errorDescription, failureReason, and recoverySuggestion for better user feedback and debugging.
  • File Transcription Edge Cases: Introduced two new tests to cover edge cases in file transcription, specifically handling invalid non-file URLs and restricted directory paths to prevent unexpected behavior.
  • Voice Activation: Added a test to ensure that disabling voice activation correctly resets the isSpeechDetected state to true, maintaining consistent session state.
  • Session Lifecycle: Included two new tests to confirm that pauseTranscribing() and resumeTranscribing() methods have no effect when the speech session is already in an idle state, ensuring idempotent operations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request significantly expands the test coverage for AuralKit, adding 8 new tests for error localization, file transcription edge cases, voice activation, and session lifecycle management. The new tests are well-written and cover important scenarios. My review includes a few suggestions to refactor some of the new test cases to use more modern and concise patterns from the Swift Testing framework, which will improve code clarity and maintainability.

Comment on lines +93 to +104
do {
_ = try await session.transcribe(audioFile: httpURL)
Issue.record("Expected audioFileInvalidURL error")
} catch let error as SpeechSessionError {
guard case let .audioFileInvalidURL(url) = error else {
Issue.record("Unexpected error: \(error)")
return
}
#expect(url == httpURL)
} catch {
Issue.record("Unexpected error: \(error)")
}

Choose a reason for hiding this comment

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

medium

The test logic can be simplified by using the #expect(throws:) macro from the Testing framework. This makes the test more concise and idiomatic for error validation, improving readability.

        await #expect(throws: SpeechSessionError.self) {
            _ = try await session.transcribe(audioFile: httpURL)
        } catch: { error in
            guard case let .audioFileInvalidURL(url) = error else {
                Issue.record("Unexpected error type: \(error)")
                return
            }
            #expect(url == httpURL)
        }

Comment on lines +118 to +128
do {
_ = try await session.transcribe(audioFile: tempURL, options: restrictedOptions)
Issue.record("Expected audioFileOutsideAllowedDirectories error")
} catch let error as SpeechSessionError {
guard case .audioFileOutsideAllowedDirectories = error else {
Issue.record("Unexpected error: \(error)")
return
}
} catch {
Issue.record("Unexpected error: \(error)")
}

Choose a reason for hiding this comment

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

medium

Similar to the test above, this do-catch block can be simplified using the #expect(throws:) macro. This improves readability and aligns with modern Swift testing practices.

        do {
            try await #expect(throws: SpeechSessionError.self) {
                _ = try await session.transcribe(audioFile: tempURL, options: restrictedOptions)
            } catch: { error in
                guard case .audioFileOutsideAllowedDirectories = error else {
                    Issue.record("Unexpected error type: \(error)")
                    return
                }
            }
        } catch {
            Issue.record("Unexpected error: \(error)")
        }

Comment on lines +42 to +67
@Test("all error cases have non-empty errorDescription")
func allErrorsHaveDescription() {
for error in Self.allErrors {
let description = error.errorDescription
#expect(description != nil, "Missing errorDescription for \(error)")
#expect(description?.isEmpty == false, "Empty errorDescription for \(error)")
}
}

@Test("all error cases have non-empty failureReason")
func allErrorsHaveFailureReason() {
for error in Self.allErrors {
let reason = error.failureReason
#expect(reason != nil, "Missing failureReason for \(error)")
#expect(reason?.isEmpty == false, "Empty failureReason for \(error)")
}
}

@Test("all error cases have non-empty recoverySuggestion")
func allErrorsHaveRecoverySuggestion() {
for error in Self.allErrors {
let suggestion = error.recoverySuggestion
#expect(suggestion != nil, "Missing recoverySuggestion for \(error)")
#expect(suggestion?.isEmpty == false, "Empty recoverySuggestion for \(error)")
}
}

Choose a reason for hiding this comment

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

medium

These three tests are very similar and contain duplicated logic. You can consolidate them into a single, more maintainable parameterized test using the Testing framework's argument support. This reduces boilerplate and makes it easier to add checks for other localized properties in the future.

Suggested change
@Test("all error cases have non-empty errorDescription")
func allErrorsHaveDescription() {
for error in Self.allErrors {
let description = error.errorDescription
#expect(description != nil, "Missing errorDescription for \(error)")
#expect(description?.isEmpty == false, "Empty errorDescription for \(error)")
}
}
@Test("all error cases have non-empty failureReason")
func allErrorsHaveFailureReason() {
for error in Self.allErrors {
let reason = error.failureReason
#expect(reason != nil, "Missing failureReason for \(error)")
#expect(reason?.isEmpty == false, "Empty failureReason for \(error)")
}
}
@Test("all error cases have non-empty recoverySuggestion")
func allErrorsHaveRecoverySuggestion() {
for error in Self.allErrors {
let suggestion = error.recoverySuggestion
#expect(suggestion != nil, "Missing recoverySuggestion for \(error)")
#expect(suggestion?.isEmpty == false, "Empty recoverySuggestion for \(error)")
}
}
private struct LocalizedProperty: Sendable {
let name: String
let keyPath: KeyPath<SpeechSessionError, String?>
}
private static let localizedProperties: [LocalizedProperty] = [
.init(name: "errorDescription", keyPath: \.errorDescription),
.init(name: "failureReason", keyPath: \.failureReason),
.init(name: "recoverySuggestion", keyPath: \.recoverySuggestion)
]
@Test("all error cases have non-empty localized strings", arguments: localizedProperties)
func allErrorsHaveNonEmptyLocalizedStrings(property: LocalizedProperty) {
for error in Self.allErrors {
let value = error[keyPath: property.keyPath]
#expect(value != nil, "Missing \(property.name) for \(error)")
#expect(value?.isEmpty == false, "Empty \(property.name) for \(error)")
}
}

@rudrankriyam rudrankriyam merged commit 6b1c971 into main Dec 8, 2025
1 check passed
@rudrankriyam rudrankriyam deleted the expand-test-coverage branch January 20, 2026 21:27
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