refactor(3/3): extract shared test infrastructure to reduce duplication - #7
Merged
Conversation
…ate) into TestHarness.swift, eliminating 3× duplicated makeTempDir, 3× duplicated cleanup, and 2× duplicated date function definitions across SkillUsageTrackerE2ETests, SkillCuratorE2ETests, and SessionSearchE2ETests, net -28 lines with all 6212+12 tests passing.
…erties in AgentEventTypesE2ETests.swift, eliminating 21× duplicated JSONEncoder+iso8601 and 17× duplicated JSONDecoder+iso8601 construction blocks, net -23 lines with all 5682+12 tests passing.
…umentation test files, eliminating 548 lines of duplicated helper methods (projectRoot, examplesDir, fileContent, packageSwiftContent) that were identically copied across all files, with all 5682+12 tests passing.
…es in AgentEventTypesTests.swift, eliminating 37× duplicated JSONEncoder+iso8601 and 64× duplicated JSONDecoder+iso8601 construction blocks, net -85 lines with all 5682+12 tests passing.
…es in SkillEvolutionTypesTests.swift, centralizing 4 iso8601-configured and 10 raw JSONEncoder/JSONDecoder sites into 2 shared properties, while correctly preserving 4 SkillSignal test sites that require the default .deferredToDate date strategy, net -5 lines with all 5682+12 tests passing.
…n MemoryFactTests and TokenStreamingEventTests (centralizing 3 iso8601 encoder+decoder sites), and replaced 2 raw ISO8601DateFormatter constructions in FactStoreTests with makeISO8601DateFormatter(), with all 5682+12 tests passing.
…, eliminating 276 lines of duplicated setUp/tearDown tempDir boilerplate (13× ~21 lines each) into a single 31-line shared base class, net -245 lines with all 5682+12 tests passing.
…Helpers.swift and replaced 436 duplicated guard-let-XCTFail-return blocks across 15 documentation test files with single-line try requireFileContent() calls, saving 1308 lines with all 5682+12 tests passing.
…Tests, FileCacheTests, MemoryReviewHookTests) to inherit from TempDirTestCase instead of XCTestCase, eliminating 125 lines of duplicated setUp/tearDown tempDir boilerplate with all 5682+12 tests passing.
…, FrozenSnapshotTests, SkillLoaderTests) to inherit from TempDirTestCase instead of XCTestCase, eliminating 41 lines of duplicated setUp/tearDown tempDir boilerplate with all 5682+12 tests passing.
…wift to inherit from TempDirTestCase, eliminating 152 lines of duplicated setUp/tearDown tempDir boilerplate with all 5682+12 tests passing.
…ests 2 classes, SessionManagementWiringATDDTests 3 classes, SessionSearchEngineTests 1 class) to inherit from TempDirTestCase instead of XCTestCase, eliminating 64 lines of duplicated setUp/tearDown tempDir boilerplate with all 5682+12 tests passing.
…, CombinedSessionOptionsWiringTests, StreamSessionWiringTests) in SessionManagementWiringATDDTests.swift to inherit from TempDirTestCase instead of XCTestCase, eliminating 18 lines of duplicated setUp/tearDown tempDir boilerplate with all 5682+12 tests passing.
…grated 2 remaining test files (TraceRecorderTests, ProjectDocumentDiscoveryTests) to inherit from TempDirTestCase instead of XCTestCase, eliminating 21 lines of duplicated setUp/tearDown tempDir boilerplate with all 5682+12 tests passing.
…makeMockURLSession) into MockURLProtocolHelpers.swift, eliminating 10 duplicated readBodyFromStream method definitions across 8 files and 17 duplicated URLSessionConfiguration.ephemeral patterns across 15 files, net -158 lines with all 5682+12 tests passing.
…eTempGitRepo, cleanupTempDir) and makeTestToolContext() shared test helpers, eliminating 2×48-line createTemplateGitRepo method definitions and 6×6-line makeContextWithoutStore definitions across 7 test files, net -28 lines with all 5682+12 tests passing.
…Id parameters and removed 14 private makeContext/makeTestToolContext method definitions across 14 test files, net -105 lines with all 5682+12 tests passing.
…s (teamStore, taskStore, planStore, cronStore, todoStore, worktreeStore, mailboxStore, senderName, mcpConnections) and removed 8 private makeContext/makeTestToolContext method definitions across 8 test files, net -64 lines with all 5682+12 tests passing.
…n 5 test files (APITypesTests, TaskTypesExtendedTests, TokenUsageTests, TaskTypesTests, PromptEvolutionTypesTests), centralizing 67 JSONEncoder/JSONDecoder construction sites into 10 shared static properties with all 6209 tests passing.
…swift, eliminating 4 duplicated private makeSkill() method definitions across ExecuteSkillTests, ExecuteSkillStreamTests, SkillToolTests, and SkillRegistryTests, net -54 lines with all 17028+12 tests passing.
… into GitTestHelpers.swift, eliminating 3 duplicated seedSkill method definitions (17 lines each) and 2 duplicated date(daysAgo:) method definitions (3 lines each) across SkillUsageTrackerTests, SkillCuratorTests, and IntelligentCuratorTests, with all 5682+12 tests passing.
…s.swift, replacing 12 identical 9-line callTool method definitions across 12 test files with thin 3-line delegations, net -26 lines with all 5682+12 tests passing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Part 3 of the complexity reduction refactoring (60 iterations, net -3500 lines). This PR contains all test infrastructure changes.
Key Changes
Shared Test Helpers:
TempDirTestCasebase class — eliminates 276+ lines of duplicated setUp/tearDown tempDir boilerplate across 47 test classesGitTestHelpers.swift— sharedcreateTemplateGitRepo,makeTestToolContext(),makeTestSkill(),seedSkill(),callToolForTest()MockURLProtocolHelpers.swift— sharedreadRequestBodyFromStream,makeMockURLSessionDocumentationTestHelpers— sharedprojectRoot,requireFileContent()across 17 doc test filesShared Encoder/Decoder Properties:
static let testEncoder/testDecoderproperties across 8 test filesNo production code changes. All changes are in
Tests/only.Test Plan
🤖 Generated with Claude Code