Skip to content

Add unit tests for all sample apps (104 tests)#11

Open
tolgaki wants to merge 3 commits intomainfrom
add-unit-tests
Open

Add unit tests for all sample apps (104 tests)#11
tolgaki wants to merge 3 commits intomainfrom
add-unit-tests

Conversation

@tolgaki
Copy link
Copy Markdown
Contributor

@tolgaki tolgaki commented Apr 5, 2026

Summary

Adds comprehensive test coverage across all four sample apps — 104 tests total, ~60% covering non-happy-path scenarios.

Test suites

Suite Tests Coverage
dotnet/a2a-raw.tests 24 ExtractText JSON parsing, arg parsing
dotnet/rest.tests 25 BuildChatBody, Trunc, arg parsing
dotnet/a2a.tests 21 Extract/Join with A2A SDK types, arg parsing
rust/a2a (inline) 34 Auth code extraction, JWT decode, message building, delta printing
swift/a2a 8 ChatMessage model + commented suggestions for private members

Non-happy-path coverage

  • Arg parsing crashes: IndexOutOfRangeException when flags like --token are last arg without a value (all 3 .NET samples)
  • Format errors: FormatException on --verbosity abc (rest sample)
  • Malformed JSON: empty objects, missing/null properties, non-array parts
  • Security: JSON injection attempts in message body, null characters
  • Boundary: empty strings, 100KB+ payloads, unicode/emoji/CJK text
  • Auth edge cases: error+code both present in redirect, invalid base64, empty JWT segments

Bugs documented by tests

These tests use Assert.Throws to prove existing bugs:

  1. args[++i] throws IndexOutOfRangeException if a flag is the last argument
  2. int.Parse(args[++i]) throws FormatException on non-integer verbosity

tolgaki and others added 3 commits April 5, 2026 12:21
Add comprehensive test coverage across all four sample apps:

- dotnet/a2a-raw.tests: 24 tests (ExtractText JSON parsing, arg parsing)
- dotnet/rest.tests: 25 tests (BuildChatBody, Trunc, arg parsing)
- dotnet/a2a.tests: 21 tests (Extract/Join with A2A SDK types, arg parsing)
- rust/a2a: 34 inline tests (auth code extraction, JWT decode, message
  building, text joining, delta printing)
- swift/a2a: 8 tests (ChatMessage model) + commented test suggestions
  for private members

~60% of tests cover non-happy-path scenarios: malformed JSON, empty/null
inputs, arg parsing crashes (IndexOutOfRangeException, FormatException),
JSON injection attempts, unicode/emoji, large payloads, and auth error
priority handling.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Move testable pure functions (ParseArgs, ExtractText, BuildChatBody,
  Trunc, Extract, Join) from Program.cs into Helpers.cs files so tests
  exercise real production code instead of duplicated copies
- Fix args[++i] crash when a flag is the last argument (returns error
  instead of IndexOutOfRangeException) in all 3 .NET samples
- Fix int.Parse on --verbosity (use TryParse, return error instead of
  FormatException) in rest and a2a samples
- Add WorkIQSamples.sln and scripts/test.sh for running all tests
- Make Swift BearerTokenAuth internal and extract renderMarkdown as a
  free function so both can be unit tested (9 new Swift tests enabled)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add platform column to root sample table, include a2a-raw and Swift
- Fix .NET SDK version: 8.0 -> 10.0, add Xcode to prerequisites
- Add pre-obtained JWT examples to all .NET READMEs for macOS/Linux
- Add explicit "WAM is Windows-only" notes to all .NET quick starts
- Fix rest README: add missing --graph flag, --verbosity, --header params
- Add Azure CLI install commands for all platforms (brew/winget/apt link)
- Document Windows token cache path alongside Unix path in Rust README
- Note NTFS vs Unix file permissions for cached tokens

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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