activity_sdk_ir_family_coverage.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #pragma once
  2. #include <array>
  3. #include <cstddef>
  4. #include <cstdint>
  5. #include <string>
  6. #include <string_view>
  7. namespace sunrise::client::content::activity::sdk_generation::ir_family_coverage {
  8. // TODO: the native pack pipeline must declare every family and gate publication on close().
  9. /** Canonical native order of every normalized SDK family. Keep this in lockstep with IR v5. */
  10. enum class Family : std::uint8_t {
  11. sources,
  12. buildProfile,
  13. packages,
  14. activities,
  15. contentActivities,
  16. namedRoots,
  17. scenarios,
  18. bubbles,
  19. states,
  20. entries,
  21. registries,
  22. registryObjectEdges,
  23. objects,
  24. objectOccurrences,
  25. slots,
  26. missionSeeds,
  27. missionAuthGroups,
  28. missionIntentMappings,
  29. placedSubblocks,
  30. placedLeaves,
  31. placedHops,
  32. placedBareTargets,
  33. placedConfigOccurrences,
  34. configs,
  35. configContexts,
  36. authoredSpawners,
  37. authoredSpawnerMembers,
  38. authoredSpawnerCandidates,
  39. actorClasses,
  40. rsatDescriptors,
  41. rsatSchemas,
  42. authoredSpawnRules,
  43. authoredSpawnPoints,
  44. authoredPlacements,
  45. authoredPlacementContexts,
  46. spawnPointPlacementMatches,
  47. authoredSpawnerRuleEdges,
  48. descriptors,
  49. authoredSceneResources,
  50. authoredSceneSquadEdges,
  51. typedReferenceDefs,
  52. typedReferences,
  53. symbolTemplates,
  54. symbolDeclarations,
  55. slotFamilies,
  56. schemas,
  57. activityMessages,
  58. behaviorPrograms,
  59. behaviorEdges,
  60. behaviorPaths,
  61. behaviorUnresolved,
  62. hostApi,
  63. capabilities,
  64. refusals,
  65. validation,
  66. count,
  67. };
  68. // A coverage report carries one row per family.
  69. inline constexpr std::size_t kFamilyCount = static_cast<std::size_t>(Family::count);
  70. static_assert(kFamilyCount == 55);
  71. /** Families are grouped only to make coverage reports and missing-producer failures actionable. */
  72. enum class Domain : std::uint8_t {
  73. sourceIdentity,
  74. activityGraph,
  75. worldGraph,
  76. squadGraph,
  77. schemaGraph,
  78. behaviorGraph,
  79. apiPolicy,
  80. validation,
  81. };
  82. /** Exactness rule used to prove that a family was not merely mentioned by a producer. */
  83. enum class Projection : std::uint8_t {
  84. exactRows,
  85. losslessDerivedRows,
  86. singletonMetadata,
  87. diagnosticRows,
  88. };
  89. /** A completed producer either retained rows or proved an empty installed-content census. */
  90. enum class Status : std::uint8_t {
  91. unresolved,
  92. exact,
  93. verifiedEmpty,
  94. };
  95. /** Stable identity and ownership of one required SDK family. */
  96. struct Descriptor final {
  97. Family family{};
  98. std::string_view name{};
  99. Domain domain{};
  100. };
  101. /** Final aggregate supplied by the producer that owns one family. */
  102. struct Declaration final {
  103. std::uint64_t sourceRecordCount{};
  104. std::uint64_t outputRowCount{};
  105. std::uint64_t discardedSourceRecordCount{};
  106. std::uint32_t contributorCount{};
  107. Projection projection{Projection::exactRows};
  108. Status status{Status::unresolved};
  109. };
  110. /** Stable reason returned by the fail-closed SDK-completeness gate. */
  111. enum class Failure : std::uint8_t {
  112. none,
  113. invalidFamily,
  114. duplicateDeclaration,
  115. missingDeclaration,
  116. unresolvedFamily,
  117. missingContributor,
  118. discardedSourceRows,
  119. exactRowCountMismatch,
  120. invalidExactEmpty,
  121. invalidVerifiedEmpty,
  122. invalidSingleton,
  123. aggregateOverflow,
  124. };
  125. /** Complete aggregate emitted only after all 55 declarations close. */
  126. struct Summary final {
  127. std::uint64_t sourceRecordCount{};
  128. std::uint64_t outputRowCount{};
  129. std::uint32_t exactFamilyCount{};
  130. std::uint32_t verifiedEmptyFamilyCount{};
  131. [[nodiscard]] bool operator==(const Summary&) const noexcept = default;
  132. };
  133. /** Fixed-size ledger; no producer can silently invent, omit, or redeclare a family. */
  134. struct Ledger final {
  135. std::array<Declaration, kFamilyCount> declarations{};
  136. std::array<bool, kFamilyCount> declared{};
  137. Failure fault{Failure::none};
  138. Family faultFamily{Family::count};
  139. };
  140. /** @return The canonical ordered 55-family contract. */
  141. [[nodiscard]] const std::array<Descriptor, kFamilyCount>& descriptors() noexcept;
  142. /** @return Exact snake-case family spelling, or an empty view for an invalid enum. */
  143. [[nodiscard]] std::string_view family_name(Family family) noexcept;
  144. /** Resolves only an exact canonical family spelling. */
  145. [[nodiscard]] bool family_from_name(std::string_view name, Family& output) noexcept;
  146. /** Adds one final aggregate. A duplicate or invalid declaration permanently faults the ledger. */
  147. [[nodiscard]] bool declare(Ledger& ledger, Family family, const Declaration& declaration) noexcept;
  148. /** Requires an exact or verified-empty declaration for every canonical family. */
  149. [[nodiscard]] bool
  150. close(const Ledger& ledger, Summary& output, Failure& failure, Family& failureFamily) noexcept;
  151. /** @return Stable lowercase spelling for logs and generated contracts. */
  152. [[nodiscard]] std::string_view stable_name(Failure failure) noexcept;
  153. /** @return Stable lowercase spelling used by the generated coverage artifact. */
  154. [[nodiscard]] std::string_view stable_name(Domain domain) noexcept;
  155. [[nodiscard]] std::string_view stable_name(Projection projection) noexcept;
  156. [[nodiscard]] std::string_view stable_name(Status status) noexcept;
  157. /** Renders the complete ledger as deterministic JSON; incomplete ledgers produce no bytes. */
  158. [[nodiscard]] bool render_json(const Ledger& ledger,
  159. std::string& output,
  160. Failure& failure,
  161. Family& failureFamily) noexcept;
  162. } // namespace sunrise::client::content::activity::sdk_generation::ir_family_coverage