Skip to content
Open
16 changes: 12 additions & 4 deletions Tests/SafeDIToolFuzzerTests/SafeDIToolGraphFuzzerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8035,10 +8035,10 @@ struct SafeDIToolGraphFuzzerTests {

/// What the level function capture check judges over the public mock corpus (`Corpus.levelFunctionCaptureCounts`).
/// Pins: derived on CI.
static let publicMockCorpusLevelFunctionCaptureCounts = GraphFuzzerLevelFunctionCaptureCounts(judged: 640, judgedWithNamed: 399, named: 1_075, conversions: 0, fills: 504)
static let publicMockCorpusLevelFunctionCaptureCounts = GraphFuzzerLevelFunctionCaptureCounts(judged: 650, judgedWithNamed: 399, named: 1_075, conversions: 0, fills: 504)

/// What the retention oracle judges over the public mock corpus (`Corpus.retentionCounts`). Pins: derived on CI.
static let publicMockCorpusRetentionCounts = GraphFuzzerRetentionCounts(judged: 722, judgedDrawingRetentionShape: 131, judgedThroughHandWrittenBuilder: 92, unpairedExperiments: 0)
static let publicMockCorpusRetentionCounts = GraphFuzzerRetentionCounts(judged: 729, judgedDrawingRetentionShape: 131, judgedThroughHandWrittenBuilder: 92, unpairedExperiments: 0)

static let seamCorpusSeedCount = 2_000
static let seamCorpusFixtureHash: UInt64 = 0xA2DFC61CD88A5D0C
Expand Down Expand Up @@ -9694,6 +9694,10 @@ struct SafeDIToolGraphFuzzerTests {
.optionalPlacePublicMockReceived: 84,
.optionalPlacePublicMockPassedUp: 67,
.optionalPlacePublicMockPublicConsumer: 45,
.sendableHolderOfPublicMockCall: 54,
.sendableHolderOfPublicMockCallThroughInstantiator: 32,
.sendableHolderOfPublicMockCallBesideByValueSibling: 40,
.sendableHolderOfPublicMockCallFillReadsHoldersValue: 21,
.outerFulfillerPublicMockCall: 112,
.unbuildableValuePublicMockCall: 174,
.unbuildableValuePublicMockCallPublicTier: 174,
Expand Down Expand Up @@ -9762,7 +9766,7 @@ struct SafeDIToolGraphFuzzerTests {
]

static let publicMockCorpusSeedCount = 1_000
static let publicMockCorpusFixtureHash: UInt64 = 0x32C6CEEE9631BE2D
static let publicMockCorpusFixtureHash: UInt64 = 0x0EC1F530FC320B24
static let publicMockCorpusAcceptedSeedCount = 854
static let publicMockCorpusAcceptedSeedsSum: UInt64 = 0xA0030516C7DF62F
/// How many of the public mock corpus's graphs the tool accepts as drawn and as their known-right path, which the
Expand Down Expand Up @@ -9824,7 +9828,7 @@ struct SafeDIToolGraphFuzzerTests {
/// Pinned by `publicMockSmokeAndKnownIssueFixtureHash`.
static let publicMockSmokeSeeds: [UInt64] = [0, 7, 10, 23, 37, 43, 46, 59, 98, 142, 151, 189, 197, 208, 215, 253, 551, 555, 836, 1_339, 1_649, 2_687, 2_840]

static let publicMockSmokeAndKnownIssueFixtureHash: UInt64 = 0x481228257866F044
static let publicMockSmokeAndKnownIssueFixtureHash: UInt64 = 0xBA85F14186D123AA

/// Seeds in `0..<publicMockCorpusSeedCount` whose graphs fail today, by shape. Every seed is the feature's own: the
/// draw shares no graph with the base corpus.
Expand Down Expand Up @@ -10077,6 +10081,10 @@ struct SafeDIToolGraphFuzzerTests {
.retentionPublicMockValueBeforeBuilder: 144,
.retentionPublicMockValueBeforeBuilderFillReadsValue: 41,
.retentionPublicMockValueBeforeBuilderLeafThroughInstantiator: 70,
.sendableHolderOfPublicMockCall: 63,
.sendableHolderOfPublicMockCallBesideByValueSibling: 49,
.sendableHolderOfPublicMockCallFillReadsHoldersValue: 26,
.sendableHolderOfPublicMockCallThroughInstantiator: 37,
.sharedConstructionPublicMock: 270,
.sharedConstructionPublicMockBeneathCycleEdge: 60,
.sharedConstructionPublicMockBesideDeclaringModulesOwn: 61,
Expand Down
92 changes: 91 additions & 1 deletion Tests/SafeDIToolTestSupport/GraphFuzzerPublicMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,21 @@ enum GraphFuzzerPublicMockDrawFeature: String, CaseIterable, Comparable {
/// `OptionalScreen`'s mock is `.public`.
case optionalPlacePublicMockPublicConsumer

/// On a stream of its own (`publicMockSendableHolderRandomSeedMask`), a call of a public mock whose place the calling
/// module fills, held by a type that one mocked consumer builds inside a `@Sendable` function: `PluggedPlug`, a `.public`
/// type of the declaring module with an `internal` initializer, holds a place of `PluggedApi`, which `PluggedLive` fills
/// in a consumer module; `PluggedHolder` there builds `PluggedPlug`, and `PluggedHost`, a mocked consumer, builds
/// `PluggedHolder` through a `Sendable` wrapper, so that the call is inside the `@Sendable` builder function and takes
/// its builder from the `@Sendable` family.
case sendableHolderOfPublicMockCall
/// `PluggedHost` builds `PluggedHolder` through a `SendableInstantiator`, not a `SendableLazilyInstantiated`.
case sendableHolderOfPublicMockCallThroughInstantiator
/// `PluggedSibling`, another mocked consumer, builds `PluggedHolder` by value, so that the module's mocks build the
/// holder inside and outside a `@Sendable` function and share its configuration.
case sendableHolderOfPublicMockCallBesideByValueSibling
/// `PluggedLive` reads `pluggedToken`, which `PluggedHolder` declares before the call, only if available.
case sendableHolderOfPublicMockCallFillReadsHoldersValue

/// On a stream of its own (`publicMockTwinRandomSeedMask`), twins over a shared screen beneath a public mock
/// (`drawTwinsPublicMock`), one case per `TwinShape` it draws.
case twinsPublicMock
Expand Down Expand Up @@ -515,7 +530,8 @@ enum GraphFuzzerPublicMockDrawFeature: String, CaseIterable, Comparable {
/// `retentionPublicMockValueBeforeBuilder…`, `sharedConstructionPublicMock…`, `keywordLabeledPublicMock…`,
/// `overrideClosure…`, `promotedHolePublicMock…`, `unbuildableValuePublicMockCall…`, `carrierBeforeSibling…`,
/// `wrapperReadByValuePublicMock…`, `valueFormsBesidePublicMockCall…`, `optionalPlacePublicMock…`,
/// `outerFulfillerPublicMockCall`, `twinsPublicMock…`, `passThroughRingPublicMock…`, and `T6`'s mock isolated to the main
/// `outerFulfillerPublicMockCall`, `twinsPublicMock…`, `passThroughRingPublicMock…`, `sendableHolderOfPublicMockCall…`,
/// and `T6`'s mock isolated to the main
/// actor or built with its hand-written mock in another public mock) draws this shape, whose count in accepted graphs the
/// public mock corpus pins too (`acceptedPublicMockDrawFeatureCounts`), at least ten each.
/// `unbuildableValuePublicMockCallTierOmits` is not one: the tool rejects every graph of it, which
Expand All @@ -533,6 +549,7 @@ enum GraphFuzzerPublicMockDrawFeature: String, CaseIterable, Comparable {
|| rawValue.hasPrefix("outerFulfillerPublicMockCall")
|| rawValue.hasPrefix("twinsPublicMock")
|| rawValue.hasPrefix("passThroughRingPublicMock")
|| rawValue.hasPrefix("sendableHolderOfPublicMockCall")
|| self == .holeMockIsolatedToMainActor || self == .holeHandWrittenMockBuiltInPublicMock
|| self == .ownOptionalDefaultOnNonisolatedTypeThatBuilds
}
Expand Down Expand Up @@ -826,6 +843,8 @@ struct GraphFuzzerPublicMockDraw {
drawTwinsPublicMock(random: &twinRandom)
var passThroughRingRandom = GraphFuzzerRandomNumberGenerator(seed: seed ^ Self.publicMockPassThroughRingRandomSeedMask)
drawPassThroughRingPublicMock(random: &passThroughRingRandom)
var sendableHolderRandom = GraphFuzzerRandomNumberGenerator(seed: seed ^ Self.publicMockSendableHolderRandomSeedMask)
drawSendableHolderOfPublicMockCall(random: &sendableHolderRandom)
if Self.drawsCallerValueFormsOfSharedCall {
var sharedCallRandom = GraphFuzzerRandomNumberGenerator(seed: seed ^ Self.publicMockSharedCallCallerFormsRandomSeedMask)
drawCallerValueFormsOfSharedCall(random: &sharedCallRandom)
Expand Down Expand Up @@ -1015,6 +1034,9 @@ struct GraphFuzzerPublicMockDraw {
/// Draws only a place a public mock's tree instantiates only if available (`drawOptionalPlacePublicMock`): rolls added
/// after the rest of the draw was pinned, so that its other shapes are drawn as before.
static let publicMockOptionalPlaceRandomSeedMask: UInt64 = 0x7075626D6B6F7074
/// Draws a holder of a call of a public mock that one mocked consumer builds inside a `@Sendable` function and another by
/// value (`drawSendableHolderOfPublicMockCall`): a roll added after the rest of the draw was pinned.
static let publicMockSendableHolderRandomSeedMask: UInt64 = 0x7075626D6B73686C
/// Draws only two mocked consumers that call one public mock whose fill captures a value they declare in two forms
/// (`drawCallerValueFormsOfSharedCall`), where `drawsCallerValueFormsOfSharedCall` is on.
static let publicMockSharedCallCallerFormsRandomSeedMask: UInt64 = 0x7075626D6B736366
Expand Down Expand Up @@ -3339,6 +3361,62 @@ struct GraphFuzzerPublicMockDraw {
files.append(File(module: consumerModule, declarations: [Self.renderer(of: screen), sessionExtension]))
}

/// A call of a public mock inside a `@Sendable` builder function, whose place the calling module fills, in one graph in
/// four whose types are all `Sendable`: the shape of the defect in which such a call took its builder from its own
/// family rather than the `@Sendable` one, and its record then dropped the fill's override, so that a mock building the
/// holder by value read a configuration field no mock declared (value harness seed 36). `PluggedPlug`, a `.public` type
/// of the declaring module with an `internal` initializer, so that a consumer's mock calls its public mock, holds
/// `pluggedApi: any PluggedApi`, which no declaration of its module fulfills. In one consumer module `PluggedLive` fills
/// it, now and then reading `pluggedToken` only if available, which `PluggedHolder`, a type no mock is generated for,
/// then declares before it builds `PluggedPlug`. `PluggedHost`, a mocked consumer, builds `PluggedHolder` through a
/// `SendableLazilyInstantiated` or a `SendableInstantiator`; four draws in five `PluggedSibling`, another mocked
/// consumer, declared before or after it, builds `PluggedHolder` by value, so that the module's mocks build the holder
/// inside and outside a `@Sendable` function and share its configuration. Every roll is made before any is read.
private mutating func drawSendableHolderOfPublicMockCall(random: inout GraphFuzzerRandomNumberGenerator) {
let drawsShape = random.percentChance(25)
let throughInstantiator = random.percentChance(50)
let hasSibling = random.percentChance(80)
let siblingFirst = random.percentChance(50)
let fillReadsToken = random.percentChance(40)
let consumerModuleRoll = random.integer(in: 0...1)
let consumerModules = consumerModules
guard drawsShape, isSendableGraph, !consumerModules.isEmpty, !hasDifferingMockCondition else { return }
let consumerModule = consumerModules[consumerModuleRoll % consumerModules.count]
let conformances = ["@unchecked Sendable"]
let apiName = name("PluggedApi")
let tokenName = name("PluggedToken")
var plug = InstantiableClass(name: name("PluggedPlug"), conformances: conformances)
plug.mockGeneration = ".public"
// An `internal` initializer, which no consumer module can call, so that each consumer's mock calls the public mock.
plug.initializerAccess = .internal
plug.properties = [Property(attribute: "@Instantiated", label: "pluggedApi", type: "any \(apiName)")]
var live = InstantiableClass(name: name("PluggedLive"), conformances: [apiName] + conformances)
live.arguments = ["fulfillingAdditionalTypes: [\(apiName).self]"]
var holder = InstantiableClass(name: name("PluggedHolder"), conformances: conformances)
if fillReadsToken {
live.properties = [Property(attribute: "@Received(onlyIfAvailable: true)", label: "pluggedToken", type: "\(tokenName)?")]
holder.properties.append(Property(attribute: "@Instantiated", label: "pluggedToken", type: tokenName))
}
holder.properties.append(Property(attribute: "@Instantiated", label: "pluggedPlug", type: plug.name))
var host = InstantiableClass(name: name("PluggedHost"), conformances: conformances)
host.mockGeneration = "true"
host.properties = [throughInstantiator
? Property(attribute: "@Instantiated", label: "pluggedHolderBuilder", type: "SendableInstantiator<\(holder.name)>")
: Property(attribute: "@Instantiated", label: "pluggedHolder", type: "SendableLazilyInstantiated<\(holder.name)>")]
var consumerDeclarations = [Self.renderer(of: live), Self.renderer(of: holder), Self.renderer(of: host)]
if fillReadsToken {
consumerDeclarations.append(Self.renderer(of: InstantiableClass(name: tokenName, conformances: conformances)))
}
if hasSibling {
var sibling = InstantiableClass(name: name("PluggedSibling"), conformances: conformances)
sibling.mockGeneration = "true"
sibling.properties = [Property(attribute: "@Instantiated", label: "pluggedHolder", type: holder.name)]
consumerDeclarations.insert(Self.renderer(of: sibling), at: siblingFirst ? 0 : consumerDeclarations.count)
}
files.append(File(module: .seamModule, declarations: [protocolDeclaration(apiName), Self.renderer(of: plug)]))
files.append(File(module: consumerModule, declarations: consumerDeclarations))
}

/// A ring of types that pass to one another the answer to whether a value is handed, read by a call of a public mock, in
/// three graphs in ten, its length drawn as the growth rows draw a chain: `RingScreen`, a mocked consumer, `true` or, one
/// draw in three, `.public`, builds `RingLink1`, by value or through an instantiator, and declares `ringSession` three
Expand Down Expand Up @@ -4891,6 +4969,18 @@ extension GraphFuzzerPublicMockDraw {
features.insert(.wrapperReadByValuePublicMockReaderThroughInstantiator)
}
}
if let host = types.declarations["\(prefix)PluggedHost"], let holder = types.declarations["\(prefix)PluggedHolder"], types.declarations["\(prefix)PluggedPlug"] != nil {
features.insert(.sendableHolderOfPublicMockCall)
if host.properties.contains(where: { $0.type.hasPrefix("SendableInstantiator<") }) {
features.insert(.sendableHolderOfPublicMockCallThroughInstantiator)
}
if types.declarations["\(prefix)PluggedSibling"] != nil {
features.insert(.sendableHolderOfPublicMockCallBesideByValueSibling)
}
if holder.properties.contains(where: { $0.label == "pluggedToken" }) {
features.insert(.sendableHolderOfPublicMockCallFillReadsHoldersValue)
}
}
if let screen = types.declarations["\(prefix)RingScreen"], types.declarations["\(prefix)RingCache"] != nil {
features.insert(.passThroughRingPublicMock)
let links = (1...4).compactMap { types.declarations["\(prefix)RingLink\($0)"] }
Expand Down
Loading