@@ -21,8 +21,12 @@ import Vapor
2121struct EnvironmentClient {
2222 // See https://swiftpackageindex.com/pointfreeco/swift-dependencies/main/documentation/dependenciesmacros/dependencyclient()#Restrictions
2323 // regarding the use of XCTFail here.
24+ // Closures returning optionals or Void don't need this, because they automatically get the default failing
25+ // mechanism when they're not set up in a test.
2426 var allowBuildTriggers : @Sendable ( ) -> Bool = { XCTFail ( " allowBuildTriggers " ) ; return true }
2527 var allowSocialPosts : @Sendable ( ) -> Bool = { XCTFail ( " allowSocialPosts " ) ; return true }
28+ var apiSigningKey : @Sendable ( ) -> String ?
29+ var appVersion : @Sendable ( ) -> String ?
2630 var awsAccessKeyId : @Sendable ( ) -> String ?
2731 var awsDocsBucket : @Sendable ( ) -> String ?
2832 var awsReadmeBucket : @Sendable ( ) -> String ?
@@ -32,12 +36,9 @@ struct EnvironmentClient {
3236 var buildTriggerAllowList : @Sendable ( ) -> [ Package . Id ] = { XCTFail ( " buildTriggerAllowList " ) ; return [ ] }
3337 var buildTriggerDownscaling : @Sendable ( ) -> Double = { XCTFail ( " buildTriggerDownscaling " ) ; return 1 }
3438 var buildTriggerLatestSwiftVersionDownscaling : @Sendable ( ) -> Double = { XCTFail ( " buildTriggerLatestSwiftVersionDownscaling " ) ; return 1 }
35- // We're not defaulting current to XCTFail, because its use is too pervasive and would require the vast
36- // majority of tests to be wrapped with `withDependencies`.
37- // We can do so at a later time once more tests are transitioned over for other dependencies. This is
38- // the exact same default behaviour we have with the Current dependency injection: it defaults to
39- // .development and does not raise an error when not injected.
40- var current : @Sendable ( ) -> Environment = { . development }
39+ var collectionSigningCertificateChain : @Sendable ( ) -> [ URL ] = { XCTFail ( " collectionSigningCertificateChain " ) ; return [ ] }
40+ var collectionSigningPrivateKey : @Sendable ( ) -> Data ?
41+ var current : @Sendable ( ) -> Environment = { XCTFail ( " current " ) ; return . development }
4142 var mastodonCredentials : @Sendable ( ) -> Mastodon . Credentials ?
4243 var mastodonPost : @Sendable ( _ client: Client , _ post: String ) async throws -> Void
4344 var random : @Sendable ( _ range: ClosedRange < Double > ) -> Double = { XCTFail ( " random " ) ; return Double . random ( in: $0) }
@@ -55,6 +56,8 @@ extension EnvironmentClient: DependencyKey {
5556 . flatMap ( \. asBool)
5657 ?? Constants . defaultAllowSocialPosts
5758 } ,
59+ apiSigningKey: { Environment . get ( " API_SIGNING_KEY " ) } ,
60+ appVersion: { App . appVersion } ,
5861 awsAccessKeyId: { Environment . get ( " AWS_ACCESS_KEY_ID " ) } ,
5962 awsDocsBucket: { Environment . get ( " AWS_DOCS_BUCKET " ) } ,
6063 awsReadmeBucket: { Environment . get ( " AWS_README_BUCKET " ) } ,
@@ -77,6 +80,16 @@ extension EnvironmentClient: DependencyKey {
7780 . flatMap ( Double . init)
7881 ?? 1.0
7982 } ,
83+ collectionSigningCertificateChain: {
84+ [
85+ " package_collections.cer " ,
86+ " AppleWWDRCAG3.cer " ,
87+ " AppleIncRootCertificate.cer " ,
88+ ] . map { SignedCollection . certsDir. appendingPathComponent ( $0) }
89+ } ,
90+ collectionSigningPrivateKey: {
91+ Environment . get ( " COLLECTION_SIGNING_PRIVATE_KEY " ) . map { Data ( $0. utf8) }
92+ } ,
8093 current: { ( try ? Environment . detect ( ) ) ?? . development } ,
8194 mastodonCredentials: {
8295 Environment . get ( " MASTODON_ACCESS_TOKEN " )
@@ -102,7 +115,19 @@ extension EnvironmentClient {
102115
103116
104117extension EnvironmentClient : TestDependencyKey {
105- static var testValue : Self { Self ( ) }
118+ static var testValue : Self {
119+ // sas 2024-11-22:
120+ // For a few attributes we provide a default value overriding the XCTFail, because theis use is too
121+ // pervasive and would require the vast majority of tests to be wrapped with `withDependencies`.
122+ // We can do so at a later time once more tests are transitioned over for other dependencies. This is
123+ // the exact same default behaviour we had with the Current dependency injection. It did not have
124+ // a "fail if not set" mechanism and relied on default values only. We're simply preserving this
125+ // mechanism for a few heavily used dependencies at the moment.
126+ var mock = Self ( )
127+ mock. appVersion = { " test " }
128+ mock. current = { . development }
129+ return mock
130+ }
106131}
107132
108133
0 commit comments