       ],
       whenAutolinking: autolinkLifecycleExpectations)
       .moduleDependencyGraph()
-  }
-
-  private func tryAfterAfterAddition(newInputBasenameWithoutExt: String
-  ) throws -> ModuleDependencyGraph {
-    let newInputPath = inputPath(basename: newInputBasenameWithoutExt)
-    return try doABuild(
-      "after after addition of \(newInputBasenameWithoutExt)",
+
+    XCTAssert(graph.contains(sourceBasenameWithoutExt: newInput))
+    XCTAssert(graph.contains(name: topLevelName))
+  }
+
+  /// Ensure that incremental builds happen after an addition.
+  ///
+  /// - Parameters:
+  ///   - newInput: The basename without extension of the new file
+  ///   - topLevelName: The top-level decl name added by the new file
+  private func checkRestorationOfIncrementalityAfterAddition(
+    newInput: String,
+    definingTopLevel topLevelName: String
+  ) throws {
+    let newInputPath = inputPath(basename: newInput)
+    let graph = try doABuild(
+      "after after addition of \(newInput)",
       checkDiagnostics: true,
       extraArguments: [newInputPath.pathString],
       expectingRemarks: [

    whenAutolinking: autolinkLifecycleExpectations)
  }

  private func tryReplacingMain(checkDiagnostics: Bool = false,
                        extraArguments: [String] = []
  ) throws {
    replace(contentsOf: "main", with: "let foo = \"hello\"")
    try doABuild(
      "propagating into 2nd wave",
      checkDiagnostics: checkDiagnostics,
      extraArguments: extraArguments,
      expectingRemarks: [

  /// Ensure that if an output of post-compile job is missing, the job gets rerun.
  func testIncrementalPostCompileJob() throws {
    #if !os(Linux)
    let driver = try XCTUnwrap(buildInitialState(checkDiagnostics: true))
    for postCompileOutput in try driver.postCompileOutputs() {
      let absPostCompileOutput = try XCTUnwrap(postCompileOutput.file.absolutePath)
      try localFileSystem.removeFileTree(absPostCompileOutput)
      XCTAssertFalse(localFileSystem.exists(absPostCompileOutput))
      try checkNullBuild()
      XCTAssertTrue(localFileSystem.exists(absPostCompileOutput))
    }
    #endif
