hecks 2.6.0 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. checksums.yaml +4 -4
  2. data/exe/hecks +13 -0
  3. data/lib/hecks/adapters/driven/google_authentication.rb +1 -1
  4. data/lib/hecks/adapters/driven/lambda/client.rb +1 -1
  5. data/lib/hecks/adapters/driven/memory.rb +1 -1
  6. data/lib/hecks/adapters/driven/postgres.rb +1 -1
  7. data/lib/hecks/adapters/driven/prism.rb +2 -2
  8. data/lib/hecks/adapters/driven/sqlite/projection.rb +1 -1
  9. data/lib/hecks/adapters/driven/tenant_provisioner.rb +31 -10
  10. data/lib/hecks/behaviors/expectations.rb +2 -2
  11. data/lib/hecks/bluebook/assembly/contract.rb +1 -1
  12. data/lib/hecks/bluebook/assembly/contracts.rb +5 -5
  13. data/lib/hecks/bluebook/assembly/specializer.rb +2 -2
  14. data/lib/hecks/bluebook/assembly.rb +1 -1
  15. data/lib/hecks/bluebook/behaviour/chapter.rb +5 -2
  16. data/lib/hecks/bluebook/behaviour/read_model.rb +18 -0
  17. data/lib/hecks/bluebook/capabilities.rb +2 -2
  18. data/lib/hecks/bluebook/chapter.rb +1 -1
  19. data/lib/hecks/bluebook/dsl/aggregate_builder.rb +2 -2
  20. data/lib/hecks/bluebook/dsl/binding_proxy.rb +6 -1
  21. data/lib/hecks/bluebook/dsl/bluebook_builder.rb +2 -2
  22. data/lib/hecks/bluebook/dsl/bootstrap_table.rb +2 -0
  23. data/lib/hecks/bluebook/dsl/command_builder.rb +3 -3
  24. data/lib/hecks/bluebook/dsl/entity_builder.rb +1 -1
  25. data/lib/hecks/bluebook/dsl/generic_dispatch.rb +1 -1
  26. data/lib/hecks/bluebook/dsl/hecksagon_builder.rb +14 -9
  27. data/lib/hecks/bluebook/dsl/port_operation_builder.rb +1 -1
  28. data/lib/hecks/bluebook/dsl/rule_reference.rb +3 -3
  29. data/lib/hecks/bluebook/dsl/translation_builder.rb +1 -1
  30. data/lib/hecks/bluebook/dsl/world_builder.rb +47 -3
  31. data/lib/hecks/bluebook/hexagon.rb +15 -7
  32. data/lib/hecks/bluebook/meta_validator/judge.rb +3 -3
  33. data/lib/hecks/bluebook/meta_validator/plan.rb +4 -4
  34. data/lib/hecks/bluebook/meta_validator/readings.rb +1 -1
  35. data/lib/hecks/bluebook/meta_validator/reconstruction.rb +2 -2
  36. data/lib/hecks/bluebook/meta_validator/shapes.rb +1 -1
  37. data/lib/hecks/bluebook/meta_validator/syntax_boot.rb +11 -10
  38. data/lib/hecks/bluebook/meta_validator/world_judge.rb +3 -1
  39. data/lib/hecks/bluebook/meta_validator.rb +1 -1
  40. data/lib/hecks/bluebook/model_check/client_profile.rb +4 -70
  41. data/lib/hecks/bluebook/model_check.rb +13 -14
  42. data/lib/hecks/cache_dir.rb +103 -0
  43. data/lib/hecks/cli/document.rb +104 -0
  44. data/lib/hecks/cli/ir.rb +47 -0
  45. data/lib/hecks/cli/mcp.rb +32 -0
  46. data/lib/hecks/cli/mcp_door.rb +461 -0
  47. data/lib/hecks/cli/model_check.rb +270 -0
  48. data/lib/hecks/cli/project_cli.rb +123 -0
  49. data/lib/hecks/cli/project_diagrams.rb +43 -0
  50. data/lib/hecks/cli/run.rb +219 -0
  51. data/lib/hecks/cli/smoke_test.rb +59 -0
  52. data/lib/hecks/cli/stores.rb +54 -0
  53. data/lib/hecks/cli.rb +166 -0
  54. data/lib/hecks/embryonaut_bluebook/lock.rb +72 -0
  55. data/lib/hecks/embryonaut_bluebook/shape.rb +47 -0
  56. data/lib/hecks/embryonaut_bluebook/vendor.rb +194 -0
  57. data/lib/hecks/embryonaut_bluebook/vendor_cli.rb +88 -0
  58. data/lib/hecks/embryonaut_bluebook.rb +29 -3
  59. data/lib/hecks/facade/handle.rb +2 -2
  60. data/lib/hecks/facade/surface/aggregate_door.rb +1 -1
  61. data/lib/hecks/forms/value_object_shape.rb +1 -1
  62. data/lib/hecks/framework/bluebook/console_settings.bluebook +3 -3
  63. data/lib/hecks/language/bluebook/vocabulary.bluebook +16 -0
  64. data/lib/hecks/language/world/world.bluebook +32 -2
  65. data/lib/hecks/mcp_door_scope.rb +176 -0
  66. data/lib/hecks/ports/key_vault.rb +1 -1
  67. data/lib/hecks/ports/persistence/append_only.rb +1 -1
  68. data/lib/hecks/ports/persistence/binding_policy.rb +16 -5
  69. data/lib/hecks/ports/persistence/plugins/era/era_check.rb +3 -2
  70. data/lib/hecks/ports/persistence/plugins/era/era_guard.rb +2 -2
  71. data/lib/hecks/ports/persistence/plugins/era/era_tamper.rb +2 -2
  72. data/lib/hecks/ports/persistence/plugins/era/expected_era.rb +132 -0
  73. data/lib/hecks/ports/persistence/plugins/era/lineage.rb +1 -1
  74. data/lib/hecks/ports/persistence/plugins/era/postgres_era/lineage/era_store.rb +2 -2
  75. data/lib/hecks/ports/persistence/plugins/era/postgres_era/lineage/head_compiler.rb +1 -1
  76. data/lib/hecks/ports/persistence/plugins/era/postgres_era/lineage_manager/minter.rb +1 -1
  77. data/lib/hecks/ports/persistence/plugins/era/translation/rule_compiler.rb +13 -7
  78. data/lib/hecks/ports/persistence/plugins/era.rb +7 -4
  79. data/lib/hecks/ports/persistence/postgres_dump/connection.rb +73 -0
  80. data/lib/hecks/ports/persistence/postgres_dump.rb +125 -0
  81. data/lib/hecks/ports/persistence/repository_factory.rb +2 -2
  82. data/lib/hecks/ports/persistence/state_codec.rb +1 -1
  83. data/lib/hecks/ports/persistence.rb +4 -0
  84. data/lib/hecks/projections/deploy/fargate/assembly.rb +193 -0
  85. data/lib/hecks/projections/deploy/fargate/cdn.rb +318 -0
  86. data/lib/hecks/projections/deploy/fargate/cdn_default.rb +87 -0
  87. data/lib/hecks/projections/deploy/fargate/check.rb +172 -0
  88. data/lib/hecks/projections/deploy/fargate/containers.rb +412 -0
  89. data/lib/hecks/projections/deploy/fargate/extras.rb +268 -0
  90. data/lib/hecks/projections/deploy/fargate/monitoring.rb +448 -0
  91. data/lib/hecks/projections/deploy/fargate/settings.rb +235 -0
  92. data/lib/hecks/projections/deploy/fargate/yaml.rb +116 -0
  93. data/lib/hecks/projections/deploy/fargate.rb +188 -139
  94. data/lib/hecks/projections/deploy/lambda.rb +8 -8
  95. data/lib/hecks/projections/deploy/preview/access_yaml.rb +145 -0
  96. data/lib/hecks/projections/deploy/preview/containers.rb +218 -0
  97. data/lib/hecks/projections/deploy/preview/preview.sh.erb +446 -0
  98. data/lib/hecks/projections/deploy/preview/routing_yaml.rb +216 -0
  99. data/lib/hecks/projections/deploy/preview/script.rb +40 -0
  100. data/lib/hecks/projections/deploy/preview/settings.rb +140 -0
  101. data/lib/hecks/projections/deploy/preview/task_yaml.rb +215 -0
  102. data/lib/hecks/projections/deploy/preview/template.rb +247 -0
  103. data/lib/hecks/projections/deploy/preview/yaml_text.rb +48 -0
  104. data/lib/hecks/projections/deploy/preview.rb +103 -0
  105. data/lib/hecks/projections/deploy/scripts/deploy-service.sh.tmpl +182 -0
  106. data/lib/hecks/projections/deploy/scripts/expected-era.header +17 -0
  107. data/lib/hecks/projections/deploy/scripts/hosting.mk.tmpl +54 -0
  108. data/lib/hecks/projections/deploy/scripts/settings.rb +114 -0
  109. data/lib/hecks/projections/deploy/scripts/smoke-after-deploy.sh.tmpl +232 -0
  110. data/lib/hecks/projections/deploy/scripts.rb +171 -0
  111. data/lib/hecks/projections/deploy/smoke/harness.js +366 -0
  112. data/lib/hecks/projections/deploy/smoke/workflow.yml.tmpl +56 -0
  113. data/lib/hecks/projections/deploy/smoke.rb +159 -0
  114. data/lib/hecks/projections/deploy/template_diff/comparer.rb +231 -0
  115. data/lib/hecks/projections/deploy/template_diff/loader.rb +105 -0
  116. data/lib/hecks/projections/deploy/template_diff.rb +173 -0
  117. data/lib/hecks/projections/glossary/sensitivity.rb +1 -1
  118. data/lib/hecks/projections/reference.rb +7 -1
  119. data/lib/hecks/projections.rb +2 -0
  120. data/lib/hecks/projector/exporter.rb +4 -4
  121. data/lib/hecks/projector/target.rb +1 -1
  122. data/lib/hecks/release/gem_pin/published_versions.rb +58 -0
  123. data/lib/hecks/release/gem_pin.rb +112 -0
  124. data/lib/hecks/release/runner/ci_publisher.rb +96 -0
  125. data/lib/hecks/release/runner/commands.rb +68 -0
  126. data/lib/hecks/release/runner/console.rb +52 -0
  127. data/lib/hecks/release/runner/gem_publisher.rb +44 -0
  128. data/lib/hecks/release/runner/git.rb +48 -0
  129. data/lib/hecks/release/runner/npm_publisher.rb +89 -0
  130. data/lib/hecks/release/runner/preflight.rb +119 -0
  131. data/lib/hecks/release/runner/published.rb +55 -0
  132. data/lib/hecks/release/runner/tagger.rb +87 -0
  133. data/lib/hecks/release/runner.rb +244 -0
  134. data/lib/hecks/router/namespace_installer.rb +1 -1
  135. data/lib/hecks/runtime/command_interpreter.rb +3 -3
  136. data/lib/hecks/runtime/command_rules/admissibility.rb +2 -2
  137. data/lib/hecks/runtime/command_rules/arithmetic.rb +2 -2
  138. data/lib/hecks/runtime/entity_element.rb +1 -1
  139. data/lib/hecks/runtime/entity_interpreter.rb +1 -1
  140. data/lib/hecks/runtime/invocation.rb +1 -1
  141. data/lib/hecks/runtime/loader.rb +27 -3
  142. data/lib/hecks/runtime/outbox.rb +1 -1
  143. data/lib/hecks/runtime/reaction_invocation.rb +3 -3
  144. data/lib/hecks/runtime/read_model_interpreter.rb +37 -15
  145. data/lib/hecks/runtime/reference_hop.rb +4 -4
  146. data/lib/hecks/runtime/registry/saga_persistence.rb +8 -2
  147. data/lib/hecks/runtime/registry/verification.rb +15 -13
  148. data/lib/hecks/runtime/registry/world_defaults.rb +106 -0
  149. data/lib/hecks/runtime/registry.rb +22 -13
  150. data/lib/hecks/runtime/saga_interpreter.rb +1 -1
  151. data/lib/hecks/runtime/tenant_check.rb +1 -1
  152. data/lib/hecks/runtime/value/coercion.rb +3 -3
  153. data/lib/hecks/runtime/value/entity_list_coercion.rb +1 -1
  154. data/lib/hecks/storehouse.rb +18 -12
  155. data/lib/hecks/vendoring/git_environment.rb +35 -0
  156. data/lib/hecks/vendoring/git_source.rb +102 -0
  157. data/lib/hecks/vendoring.rb +102 -0
  158. data/lib/hecks/version.rb +1 -1
  159. data/lib/hecks/vocabulary.rb +5 -0
  160. data/lib/hecks.rb +8 -2
  161. metadata +72 -58
  162. data/lib/hecks/bench/cli.rb +0 -74
  163. data/lib/hecks/bench/environment.rb +0 -100
  164. data/lib/hecks/bench/postgres_probe.rb +0 -41
  165. data/lib/hecks/bench/report.rb +0 -116
  166. data/lib/hecks/bench/ruby_runner.rb +0 -151
  167. data/lib/hecks/bench/run.rb +0 -55
  168. data/lib/hecks/bench/rust_runner.rb +0 -165
  169. data/lib/hecks/bench/stats.rb +0 -75
  170. data/lib/hecks/bench/suite.rb +0 -172
  171. data/lib/hecks/bench/workload.rb +0 -137
  172. data/lib/hecks/bench.rb +0 -28
  173. data/lib/hecks/codemod.rb +0 -443
  174. data/lib/hecks/corpus.rb +0 -479
  175. data/lib/hecks/doc/reference.rb +0 -585
  176. data/lib/hecks/fuzzing/bounded_exhaustive_expressions.rb +0 -684
  177. data/lib/hecks/fuzzing/combination_miner.rb +0 -178
  178. data/lib/hecks/fuzzing/concurrent_dispatch.rb +0 -469
  179. data/lib/hecks/fuzzing/coverage_campaign.rb +0 -161
  180. data/lib/hecks/fuzzing/differential.rb +0 -192
  181. data/lib/hecks/fuzzing/domain_generator.rb +0 -871
  182. data/lib/hecks/fuzzing/era_boundary.rb +0 -154
  183. data/lib/hecks/fuzzing/form_census.rb +0 -285
  184. data/lib/hecks/fuzzing/generated_domain_check.rb +0 -171
  185. data/lib/hecks/fuzzing/invalid_value_generator.rb +0 -125
  186. data/lib/hecks/fuzzing/isolated_boot.rb +0 -604
  187. data/lib/hecks/fuzzing/nondeterministic.rb +0 -79
  188. data/lib/hecks/fuzzing/persistence_parity.rb +0 -253
  189. data/lib/hecks/fuzzing/properties/corrections.rb +0 -125
  190. data/lib/hecks/fuzzing/properties/dispatch_and_mutations.rb +0 -688
  191. data/lib/hecks/fuzzing/properties/guards.rb +0 -398
  192. data/lib/hecks/fuzzing/properties/invariants_and_aggregation.rb +0 -399
  193. data/lib/hecks/fuzzing/properties/lifecycle_and_replay.rb +0 -137
  194. data/lib/hecks/fuzzing/properties/outbox.rb +0 -180
  195. data/lib/hecks/fuzzing/properties/querying.rb +0 -260
  196. data/lib/hecks/fuzzing/properties.rb +0 -267
  197. data/lib/hecks/fuzzing/qa_settings.rb +0 -164
  198. data/lib/hecks/fuzzing/replay.rb +0 -930
  199. data/lib/hecks/fuzzing/rotation_priority.rb +0 -114
  200. data/lib/hecks/fuzzing/rust_gap_manifest.rb +0 -139
  201. data/lib/hecks/fuzzing/self_consistency.rb +0 -825
  202. data/lib/hecks/fuzzing/sequence_generator/adversary.rb +0 -532
  203. data/lib/hecks/fuzzing/sequence_generator/catalog.rb +0 -171
  204. data/lib/hecks/fuzzing/sequence_generator/outcome_tracker.rb +0 -127
  205. data/lib/hecks/fuzzing/sequence_generator/picker.rb +0 -116
  206. data/lib/hecks/fuzzing/sequence_generator/query_binding.rb +0 -138
  207. data/lib/hecks/fuzzing/sequence_generator/step_builder.rb +0 -344
  208. data/lib/hecks/fuzzing/sequence_generator.rb +0 -311
  209. data/lib/hecks/fuzzing/shrinker.rb +0 -309
  210. data/lib/hecks/fuzzing/structural_skips.rb +0 -53
  211. data/lib/hecks/fuzzing/sweep_depth.rb +0 -61
  212. data/lib/hecks/fuzzing/target_capabilities.rb +0 -255
  213. data/lib/hecks/fuzzing/value_generator.rb +0 -340
  214. data/lib/hecks/fuzzing.rb +0 -23
  215. data/lib/hecks/grammar/evolve.rb +0 -524
  216. data/lib/hecks/query_ir.rb +0 -482
@@ -1,178 +0,0 @@
1
- require "json"
2
- require "open3"
3
- require_relative "form_census"
4
-
5
- module Hecks
6
- module Fuzzing
7
- # An agent reads the adversarial corpus and writes the next meeting.
8
- #
9
- # `DomainGenerator` forces two `FormCensus::FORMS` onto one aggregate
10
- # from a seed — cheap, mechanical, and blind to why a combination
11
- # should break. The bugs the ledger actually logged came from someone
12
- # reading a stress domain, a bug title, and a runtime file side by
13
- # side and guessing where the next divergence lives (`corrections`
14
- # from BUG#30-33, `case_escalation` from ADR 0037 Finding 5 meeting
15
- # `corrects`). This is that guess, delegated: the mechanical half
16
- # (what the corpus already puts together, which pairs nothing meets,
17
- # what the recent bugs were) is computed here; the judgment half is a
18
- # prompt (`qa/combination_miner/prompt.md`) an agent answers by
19
- # writing candidate bluebooks, each with a hypothesis. Checking them
20
- # is not this module's job — `bin/qa_mine_combinations` hands every
21
- # valid candidate to `bin/qa_generated_domains --source`, the same
22
- # differential, self-consistency, Rust build and shrinking path a
23
- # generated domain takes.
24
- #
25
- # **Opt-in, never the rotation**. An agent call costs money and minutes
26
- # and answers differently every time; `bin/qa_tick` never runs it and
27
- # no `QualityControlDials` entry turns it on. A person runs
28
- # `bin/qa_mine_combinations` when they want new shapes.
29
- module CombinationMiner
30
- PROMPT_TEMPLATE = "qa/combination_miner/prompt.md".freeze
31
- HYPOTHESIS_FILE = "HYPOTHESIS.md".freeze
32
-
33
- module_function
34
-
35
- # Every adversarial domain plus every example — the corpus the
36
- # census is measured over. Promoted generated domains are included:
37
- # their shapes are already swept too.
38
- #
39
- # @param root [String] repository root to search under
40
- # @return [Array<String>] paths of every stress/example corpus member that
41
- # declares at least one bluebook file
42
- def corpus_paths(root)
43
- Hecks::Corpus.members(:stress, :example, root: root).map(&:path)
44
- .select { |path| Hecks::Corpus.bluebook_files(path) }
45
- .sort
46
- end
47
-
48
- # The last `limit` bug commit subjects on this branch — cheap, needs
49
- # no ledger or Postgres, and names the mechanism in the title by
50
- # convention (`BUG#n: …`).
51
- #
52
- # @param root [String] repository root to run `git log` in
53
- # @param limit [Integer] maximum number of commit subjects to return
54
- # @return [Array<String>] matching commit subjects, newest first; empty if
55
- # `git log` fails
56
- def recent_bug_titles(root, limit: 60)
57
- out, status = Open3.capture2("git", "log", "--format=%s", "--grep=BUG#", "-n", limit.to_s, chdir: root)
58
- status.success? ? out.lines.map(&:strip).reject(&:empty?) : []
59
- end
60
-
61
- # The mechanical half: which form pairs the corpus meets (and by
62
- # whom), which it never meets, and what could not be measured.
63
- #
64
- # @param paths [Array<String>] corpus member paths to census, as returned by
65
- # `#corpus_paths`
66
- # @param root [String] repository root, to render `paths` relative to it
67
- # @param bug_titles [Array<String>] recent bug commit subjects, as returned
68
- # by `#recent_bug_titles`
69
- # @return [Hash] `"forms"` (`Array<String>`, every declared form name),
70
- # `"corpus"` (`Array<String>`, `paths` relative to `root`),
71
- # `"unmet_pairs"` (`Array<String>`, form pairs no corpus member meets),
72
- # `"single_carrier_pairs"` (`Array<String>`, pairs only one form name
73
- # meets), `"skipped"` (`Array<String>`, paths that could not be
74
- # censused, with the error), `"recent_bugs"` (`bug_titles`), and
75
- # `"covered"` (`Hash{String => Array<String>}`, pair to every form name
76
- # that meets it)
77
- def brief(paths, root:, bug_titles:)
78
- covered = Hash.new { |hash, key| hash[key] = [] }
79
- skipped = []
80
- paths.each do |path|
81
- FormCensus.covered_pairs(FormCensus.census(path)).each { |pair, names| covered[pair].concat(names) }
82
- rescue StandardError, ScriptError => e
83
- skipped << "#{relative(path, root)} (#{e.class}: #{e.message.lines.first&.strip})"
84
- end
85
- { "forms" => FormCensus::FORMS.keys, "corpus" => paths.map { |path| relative(path, root) },
86
- "unmet_pairs" => (FormCensus.pairs - covered.keys).sort,
87
- "single_carrier_pairs" => covered.select { |_, names| names.uniq.size == 1 }
88
- .map { |pair, names| "#{pair} (only #{names.first})" }.sort,
89
- "skipped" => skipped, "recent_bugs" => bug_titles, "covered" => covered }
90
- end
91
-
92
- # Fills `PROMPT_TEMPLATE`'s `{{placeholders}}` with `brief`'s own data, for
93
- # the agent to answer by writing candidate bluebooks.
94
- #
95
- # @param root [String] repository root the prompt template is read from
96
- # @param brief [Hash] the mechanical brief, as returned by `#brief`
97
- # @param count [Integer] how many candidates the prompt asks the agent for
98
- # @param out_dir [String] where the prompt asks the agent to write candidates
99
- # @return [String] the filled-in prompt text
100
- # @raise [KeyError] if the template names a placeholder `substitutions` does
101
- # not provide
102
- def prompt(root, brief, count:, out_dir:)
103
- substitutions = {
104
- "count" => count.to_s, "out_dir" => out_dir, "forms" => brief["forms"].join(", "),
105
- "corpus" => bulleted(brief["corpus"]), "unmet_pairs" => bulleted(brief["unmet_pairs"]),
106
- "single_carrier_pairs" => bulleted(brief["single_carrier_pairs"]),
107
- "recent_bugs" => bulleted(brief["recent_bugs"]), "skipped" => bulleted(brief["skipped"])
108
- }
109
- File.read(File.join(root, PROMPT_TEMPLATE)).gsub(/\{\{(\w+)\}\}/) { substitutions.fetch(Regexp.last_match(1)) }
110
- end
111
-
112
- # The second, narrower ask: these candidates did not boot, here is
113
- # why, fix them in place. Nothing else in the directory changes.
114
- #
115
- # @param failures [Array<Array(Hash, String)>] `[candidate, error]` pairs,
116
- # `candidate` as returned by `#candidates`, `error` the boot failure message
117
- # @param out_dir [String] the directory the candidates were written under
118
- # @return [String] the repair round's own prompt text
119
- def repair_prompt(failures, out_dir:)
120
- listed = failures.map { |candidate, error| "- #{candidate[:bluebook]}\n boot error: #{error}" }.join("\n")
121
- <<~PROMPT
122
- REPAIR ROUND. You wrote candidate Hecks bluebooks under #{out_dir} for the QA combination miner.
123
- These did not boot. Edit each file IN PLACE so it boots, keeping the construct combination its
124
- #{HYPOTHESIS_FILE} names (update the hypothesis if the fix changes the shape). Do not create new
125
- candidates and do not touch anything outside #{out_dir}.
126
-
127
- #{listed}
128
- PROMPT
129
- end
130
-
131
- # `<out_dir>/<slug>/<anything>.bluebook` plus an optional
132
- # HYPOTHESIS.md beside it. One bluebook per candidate: the first,
133
- # alphabetically, if an agent wrote more.
134
- #
135
- # @param out_dir [String] the directory candidates were written under
136
- # @return [Array<Hash>] one `{slug:, dir:, bluebook:, hypothesis:}` entry per
137
- # candidate subdirectory that declares a `.bluebook` file; `hypothesis` is
138
- # `nil` when no `HYPOTHESIS.md` sits beside it
139
- def candidates(out_dir)
140
- Dir[File.join(out_dir, "*")].select { |dir| File.directory?(dir) }.sort.filter_map do |dir|
141
- bluebook = Dir[File.join(dir, "*.bluebook")].min
142
- next unless bluebook
143
-
144
- hypothesis = File.join(dir, HYPOTHESIS_FILE)
145
- { slug: File.basename(dir), dir: dir, bluebook: bluebook,
146
- hypothesis: File.exist?(hypothesis) ? File.read(hypothesis).strip : nil }
147
- end
148
- end
149
-
150
- # Pairs the candidate meets on one aggregate that no corpus domain
151
- # does — informational, never a gate: an agent may be aiming at a
152
- # shape the census does not name yet.
153
- #
154
- # @param candidate_dir [String] path to the candidate's own directory
155
- # @param covered [Hash{String => Array<String>}] the corpus's own covered
156
- # pairs, as returned in `#brief`'s `"covered"` entry
157
- # @return [Array<String>] form pairs the candidate meets that `covered` does
158
- # not already name, sorted
159
- def new_pairs(candidate_dir, covered)
160
- FormCensus.covered_pairs(FormCensus.census(candidate_dir)).keys.reject { |pair| covered.key?(pair) }.sort
161
- end
162
-
163
- # Renders a path relative to the repository root.
164
- #
165
- # @param path [String] an absolute (or `root`-prefixed) path
166
- # @param root [String] the prefix to strip
167
- # @return [String] `path` with `root`'s own prefix removed
168
- def relative(path, root) = path.delete_prefix("#{root}/")
169
-
170
- # Renders a list of strings as a Markdown bullet list.
171
- #
172
- # @param items [Array<String>] lines to render as a Markdown bullet list
173
- # @return [String] one `"- item"` line per entry, newline-joined; `"(none)"`
174
- # when `items` is empty
175
- def bulleted(items) = items.empty? ? "(none)" : items.map { |item| "- #{item}" }.join("\n")
176
- end
177
- end
178
- end
@@ -1,469 +0,0 @@
1
- require "fileutils"
2
- require "tmpdir"
3
- require "tempfile"
4
- require "json"
5
- require_relative "isolated_boot"
6
- require_relative "../naming"
7
-
8
- module Hecks
9
- module Fuzzing
10
- # **A generated sequence, raced for real** — `spec/adapters/driven/
11
- # postgres_era_concurrent_dispatch_spec.rb` proves ADR 0036's own fix
12
- # (a real `pg_advisory_xact_lock` serializes a PostgresEra-bound
13
- # dispatch across separate OS processes) against one hand-authored
14
- # fixture and one hand-picked conflicting pair (two `$6,000` Debits
15
- # against a `$10,000` account). This module asks the same question —
16
- # does the cross-process write lock actually serialize concurrent
17
- # writers? — of an arbitrary generated sequence against a real target
18
- # domain, so the practice's own adversarial generator gets to pick the
19
- # conflict instead of a human picking it once and never again.
20
- #
21
- # ## The mechanism
22
- #
23
- # Generalized from that spec rather than rederived: a
24
- # command step partway through a generated sequence is chosen as the
25
- # race step; every step before it is setup (replayed once, sequentially,
26
- # to bring a fresh disposable schema to the state the race step expects
27
- # to act against); the race step is then dispatched twice — once from
28
- # each of two real, separate, forked OS processes racing against that
29
- # same schema, no artificial gating, whichever the scheduler favors.
30
- #
31
- # ## The oracle
32
- #
33
- # The same pair, dispatched sequentially, not a
34
- # hardcoded expectation — unlike the hand-authored spec (which can
35
- # assert `%w[refused succeeded]` because it knows its own fixture's
36
- # business rule), this module has no idea whether an arbitrary
37
- # generated race step conflicts with itself at all. So it asks the
38
- # domain: replay the identical setup on a separate fresh schema, then
39
- # dispatch the same race step twice, one after the other, in one
40
- # process, with no contention at all — genuinely correct by
41
- # construction, since nothing else can touch that schema while it
42
- # runs. Two conflicting writes settle as {"succeeded", "refused"};
43
- # two independent ones settle as {"succeeded", "succeeded"}; either
44
- # way, that is the multiset the concurrent pair must also produce if
45
- # the write lock actually serializes them — order does not matter
46
- # (which real racer wins a genuine race is never controlled), the set
47
- # of outcomes does.
48
- #
49
- # ## What a broken lock looks like here
50
- #
51
- # The concurrent pair settling as
52
- # {"succeeded", "succeeded"} where the sequential oracle says
53
- # {"succeeded", "refused"} — two processes each hydrated the
54
- # pre-write state, neither saw the other's write, and the second
55
- # commit landed as a silent lost update instead of failing its own
56
- # `given`. That is the exact corruption class ADR 0036 fixed for
57
- # PostgresEra and `postgres_concurrent_dispatch_spec.rb` still
58
- # documents, unfixed, for plain Postgres.
59
- #
60
- # ## Not a replacement for the hand-authored spec
61
- #
62
- # That spec proves the
63
- # mechanism once, precisely, with controlled gating so the assertion
64
- # is deterministic; this module proves the same mechanism holds for
65
- # whatever a real domain's own generated sequences throw at it, with
66
- # no gating (a genuine, ungated race), on every sweep this mode runs.
67
- module ConcurrentDispatch
68
- module_function
69
-
70
- COMMAND_STEP = ->(step) { step["verb"] && !step["query"] && !step["dry_run"] }
71
-
72
- # One divergence list, the same shape every other mode in this
73
- # practice produces — `[]` when nothing was found (including the
74
- # legitimate "this seed's generated sequence has no command step to
75
- # race at all" case: a sequence of pure queries/dry-runs has nothing
76
- # to concurrently dispatch, and that is not a finding).
77
- #
78
- # `database:` is the shared, never-dropped scratch database
79
- # (`bin/qa_sweep`'s own `persistence_parity_database`, reused here
80
- # for the identical reason: a container, not the thing that's
81
- # unique per run). `race_schema:`/`reference_schema:` are two
82
- # different disposable schema names this one call owns for its own
83
- # duration — the caller creates neither ahead of time (both are
84
- # wiped fresh by the boots below) and drops both afterward, the
85
- # same lifecycle `persistence_parity_schema` already has.
86
- #
87
- # @param domain_path [String] filesystem path to the target domain's directory
88
- # @param steps [Array<Hash>] a generated sequence's own steps, any-keyed (normalized
89
- # to String keys internally)
90
- # @param database [String] the shared, never-dropped scratch database to connect to
91
- # @param race_schema [String] a disposable schema name for the two racing processes
92
- # @param reference_schema [String] a disposable schema name for the sequential oracle
93
- # @return [Array<Hash>] `[]` if nothing raceable was found or no divergence occurred;
94
- # otherwise one or more `field:`-keyed divergence findings
95
- def check(domain_path, steps, database:, race_schema:, reference_schema:)
96
- normalized = steps.map { |step| step.transform_keys(&:to_s) }
97
- lockable, probe_errors = lockable_verbs(domain_path, normalized, database: database, schema: reference_schema)
98
- race_index = pick_race_index(normalized, lockable)
99
- unless race_index
100
- # `[]` here means "nothing to race", and must only ever mean that.
101
- # A sequence of pure queries/dry-runs is a legitimate clean
102
- # result; a probe that raised for every verb is not — see
103
- # `lockable_verbs`, whose own `probe_errors` half exists so this
104
- # branch can tell the two apart rather than answering `[]` for both.
105
- return [] if probe_errors.empty?
106
-
107
- return [{ field: "concurrency_unraceable",
108
- detail: "no command step could be raced because the cross-process-lock probe failed: " \
109
- "#{probe_errors.uniq.join('; ')}" }]
110
- end
111
-
112
- setup_steps = normalized[0...race_index]
113
- race_step = normalized[race_index]
114
-
115
- reference = reference_outcomes(domain_path, setup_steps, race_step, database: database, schema: reference_schema)
116
- concurrent = concurrent_outcomes(domain_path, setup_steps, race_step, database: database, schema: race_schema)
117
-
118
- divergences_for(race_step, reference, concurrent)
119
- rescue StandardError => e
120
- [{ field: "process", detail: "#{e.class}: #{e.message}" }]
121
- end
122
-
123
- # The command step closest to the middle of the sequence — not the
124
- # first (racing a bare identity-creation with no setup at all is a
125
- # legitimate, useful case, so index 0 is not excluded) and not
126
- # chosen for any domain-specific reason: a mid-sequence step has, on
127
- # average, the deepest state to act against and the best odds of
128
- # actually conflicting with itself. `nil` when the generated
129
- # sequence has no command step at all (every step a query or a dry
130
- # run) — nothing here for this seed to race.
131
- #
132
- # `lockable_verbs` — optional, but `check` always passes one: the
133
- # set of verbs whose own aggregate is actually bound to an adapter
134
- # that declares `:cross_process_lock` in this domain (see
135
- # `lockable_verbs` below for why this can't be assumed just because
136
- # the domain binds some of its own aggregates to PostgresEra).
137
- # Racing anything outside that set is not a legitimate race at
138
- # all — nil when nothing eligible is left, same as the "no command
139
- # step" case, never a finding of its own.
140
- #
141
- # @param steps [Array<Hash>] a normalized (String-keyed) generated sequence
142
- # @param lockable_verbs [Array<String>, nil] the verbs eligible to race, as
143
- # `lockable_verbs` returns; nil to consider every command step eligible
144
- # @return [Integer, nil] the index of the chosen race step, or nil if no eligible
145
- # command step exists
146
- def pick_race_index(steps, lockable_verbs = nil)
147
- command_indices = steps.each_index.select { |i| COMMAND_STEP.call(steps[i]) }
148
- command_indices = command_indices.select { |i| lockable_verbs.include?(steps[i]["verb"]) } if lockable_verbs
149
- return nil if command_indices.empty?
150
-
151
- command_indices[command_indices.size / 2]
152
- end
153
-
154
- # Which of this sequence's own command verbs are even candidates to
155
- # race — BUG#142 (SW-quality_control-1789768606's own first real
156
- # concurrency run, seed 3): a domain that `persisted_by("PostgresEra")`
157
- # binds its own aggregates is not thereby binding a framework
158
- # member it merely `uses_framework`s — `hecksagon_builder.rb`'s own
159
- # `uses_framework` loads only that member's shape, never its
160
- # persistence (see `examples/banking/bluebook/banking.hecksagon`'s
161
- # own comment: a framework member's aggregates need a sibling
162
- # hecksagon, registered under that member's own name, or
163
- # `Ports::Persistence::BindingPolicy.default_binding` silently
164
- # gives them "Memory" — no hecksagon registered under that name at
165
- # all, so `resolve`'s own `missing_binding` refusal (which only
166
- # fires when a hecksagon exists for that domain and simply omits
167
- # this aggregate) never gets a chance to say so).
168
- # `qa/bluebook/quality_control.hecksagon` attaches `Governance` via
169
- # `uses_framework` with no such sibling — `Governance::
170
- # RoleAssignment`/`RoleTransition` are Memory-backed, process-
171
- # local, in the real ledger, `concurrency` mode included. Racing a
172
- # Memory-backed aggregate across two real OS processes can never
173
- # agree with the single-process sequential oracle — each racer's
174
- # own boot gets its own independent, empty store — no matter how
175
- # correct any write lock is; that is a guaranteed false positive,
176
- # not evidence of a broken lock.
177
- #
178
- # Boots the same PostgresEra-rebound copy the race itself boots
179
- # (`boot_preserving_schema` — structural inspection only, nothing
180
- # dispatched, so the schema it's given is left exactly as it found
181
- # it) and asks each distinct command verb's own resolved repository
182
- # whether it actually declares `:cross_process_lock` — the same
183
- # capability `Interpreting#run_dispatch_order_with_isolation`
184
- # itself keys off of to decide whether a real advisory lock is
185
- # even in play for that aggregate. A verb this boot can't resolve
186
- # at all (a malformed adversarial verb, say) is conservatively
187
- # excluded, not raced on a guess.
188
- # Answers `[lockable, probe_errors]`. The errors half exists because
189
- # the probe below rescues to `false`: a verb that cannot be resolved
190
- # is indistinguishable, from the outside, from one that resolves fine
191
- # and simply declares no `:cross_process_lock`. If resolution broke
192
- # for every verb (a renamed capability symbol, a wiring change),
193
- # `lockable` came back empty, `check` returned `[]`, and the sweep
194
- # logged a clean concurrency Check for a race that never happened.
195
- # `check` reports that case now instead of holding it.
196
- #
197
- # @param domain_path [String] filesystem path to the target domain's directory
198
- # @param steps [Array<Hash>] a normalized (String-keyed) generated sequence
199
- # @param database [String] the shared, never-dropped scratch database to connect to
200
- # @param schema [String] a disposable schema name for the structural-inspection boot
201
- # @return [Array(Array<String>, Array<String>)] `[lockable, probe_errors]` — the
202
- # command verbs bound to a `:cross_process_lock`-declaring adapter, and one
203
- # `"verb: Class: message"` entry per verb whose resolution raised
204
- def lockable_verbs(domain_path, steps, database:, schema:)
205
- verbs = steps.select { |step| COMMAND_STEP.call(step) }.map { |step| step["verb"] }.uniq
206
- lockable = []
207
- probe_errors = []
208
- boot_preserving_schema(domain_path, database: database, schema: schema) do |copy|
209
- runtime = Hecks.boot(copy)
210
- verbs.each do |verb|
211
- lockable << verb if verb_cross_process_lockable?(runtime, verb, probe_errors)
212
- end
213
- end
214
- [lockable, probe_errors]
215
- end
216
-
217
- # Answers whether `verb`'s own resolved repository declares a cross-process lock.
218
- #
219
- # @param runtime [Runtime::Dispatcher, Runtime::RemoteDispatcher] the booted,
220
- # structural-inspection-only runtime to resolve `verb` against
221
- # @param verb [String] the command verb to check
222
- # @param probe_errors [Array<String>] mutated in place: appended with
223
- # `"verb: Class: message"` if resolving `verb` raises
224
- # @return [Boolean] whether `verb`'s aggregate resolves and declares
225
- # `:cross_process_lock`; false (with an appended probe error) if resolution raises
226
- def verb_cross_process_lockable?(runtime, verb, probe_errors = [])
227
- domain, aggregate_name, = Naming.split_verb(verb)
228
- return false unless domain && aggregate_name
229
-
230
- aggregate = runtime.registry.bluebook(domain)&.aggregate(aggregate_name)
231
- return false unless aggregate
232
-
233
- repository = runtime.registry.repository(domain, aggregate)
234
- repository.capabilities.include?(:cross_process_lock)
235
- rescue StandardError => e
236
- # Still `false` — a verb this boot cannot resolve is not raced on a
237
- # guess — but no longer silent: `check` needs to tell "nothing here
238
- # declares a cross-process lock" from "asking broke".
239
- probe_errors << "#{verb}: #{e.class}: #{e.message}"
240
- false
241
- end
242
-
243
- # Compares the sequential oracle's outcomes against the two racing
244
- # processes' own outcomes, and reports any crash or disagreement.
245
- #
246
- # @param race_step [Hash] the race step, String-keyed
247
- # @param reference [Array<String>] the sequential oracle's two outcomes,
248
- # `"succeeded"`, `"refused"`, or `"crashed:..."`
249
- # @param concurrent [Array<String>] the two racing processes' own outcomes,
250
- # the same shape as `reference`
251
- # @return [Array<Hash>] `[]` if the two multisets agree and neither side crashed;
252
- # otherwise one or more `field:`-keyed divergence findings (`"concurrency_crash"`
253
- # or `"concurrency_race"`)
254
- def divergences_for(race_step, reference, concurrent)
255
- crashes = (reference + concurrent).select { |outcome| outcome.start_with?("crashed:") }.uniq
256
- return crashes.map { |c| { field: "concurrency_crash", verb: race_step["verb"], detail: c } } if crashes.any?
257
-
258
- return [] if reference.sort == concurrent.sort
259
-
260
- [{ field: "concurrency_race", verb: race_step["verb"], reference: reference, concurrent: concurrent,
261
- detail: "two concurrent cross-process dispatches of #{race_step['verb']} settled as #{concurrent.sort} " \
262
- "where the identical pair, dispatched sequentially with no contention, settled as " \
263
- "#{reference.sort} — the cross-process write lock did not correctly serialize this write" }]
264
- end
265
-
266
- # The oracle — one boot, one process, the setup then the race step
267
- # twice in immediate succession. Nothing else ever touches this
268
- # schema while this runs, so whatever the domain itself settles on
269
- # is correct by construction, not asserted.
270
- #
271
- # @param domain_path [String] filesystem path to the target domain's directory
272
- # @param setup_steps [Array<Hash>] the normalized steps replayed once, sequentially,
273
- # before the race step
274
- # @param race_step [Hash] the normalized step dispatched twice in immediate succession
275
- # @param database [String] the shared, never-dropped scratch database to connect to
276
- # @param schema [String] this oracle's own disposable schema name
277
- # @return [Array<String>] the two outcomes `dispatch_one` recorded, in dispatch order
278
- def reference_outcomes(domain_path, setup_steps, race_step, database:, schema:)
279
- outcomes = []
280
- IsolatedBoot.call(domain_path, adapter: :postgres_era, database: database, schema: schema) do |copy|
281
- runtime = Hecks.boot(copy)
282
- dispatch_all!(runtime, setup_steps)
283
- outcomes << dispatch_one(runtime, race_step)
284
- outcomes << dispatch_one(runtime, race_step)
285
- end
286
- outcomes
287
- end
288
-
289
- # The race itself — setup runs once, sequentially, in this process
290
- # (the same `IsolatedBoot.call` wipe-then-boot every other mode
291
- # here already uses), and only then do the two real racers run.
292
- # Each racer boots its own fresh copy of the domain against the
293
- # same now-populated schema — `boot_preserving_schema`, below,
294
- # deliberately skips the wipe `IsolatedBoot.call` always does, or
295
- # the setup this line just wrote would be gone before either racer
296
- # ever dispatched anything.
297
- #
298
- # Real, separate OS processes, not `Thread.new` — `postgres_era_
299
- # concurrent_dispatch_spec.rb`'s own header explains why:
300
- # `Runtime::AggregateLock`'s in-process registry would fully (and
301
- # misleadingly) serialize two threads sharing one process even with
302
- # the cross-process lock fix reverted. Only two genuinely separate
303
- # OS processes exercise the gap this check exists to catch.
304
- #
305
- # `Process.spawn`, not `Process.fork` — `bin/qa_sweep`'s own
306
- # top-of-file comment on `--all` names the identical hazard this
307
- # sidesteps: by the time a `concurrency` seed runs, this process
308
- # already holds the QualityControl ledger's own live PostgresEra
309
- # connection (this module's own caller, `bin/qa_sweep`, booted it
310
- # long before any seed ran). `Process.fork` duplicates every open
311
- # file descriptor, SSL session state included — confirmed live
312
- # while wiring this mode up: forking directly from here corrupted
313
- # the ledger's own connection the moment either racer child exited,
314
- # surfacing on the next unrelated ledger write, nowhere near this
315
- # method's own code. `bin/qa_concurrency_racer` is this method's own
316
- # worker, one real `ruby` process per racer — read that script's own
317
- # header for the rest of this reasoning.
318
- #
319
- # @param domain_path [String] filesystem path to the target domain's directory
320
- # @param setup_steps [Array<Hash>] the normalized steps replayed once, sequentially,
321
- # before the two racers spawn
322
- # @param race_step [Hash] the normalized step both racer processes dispatch
323
- # @param database [String] the shared, never-dropped scratch database to connect to
324
- # @param schema [String] this race's own disposable schema name, shared by both racers
325
- # @return [Array<String>] the two racers' own outcomes, in `Process.wait` order;
326
- # `"crashed:no output from bin/qa_concurrency_racer"` for a racer that printed nothing
327
- def concurrent_outcomes(domain_path, setup_steps, race_step, database:, schema:)
328
- IsolatedBoot.call(domain_path, adapter: :postgres_era, database: database, schema: schema) do |copy|
329
- dispatch_all!(Hecks.boot(copy), setup_steps)
330
- end
331
-
332
- root = File.expand_path("../../..", __dir__)
333
- racer = File.join(root, "bin/qa_concurrency_racer")
334
- args_json = JSON.generate(race_step["args"] || {})
335
- logs = Array.new(2) { Tempfile.new(["qa-concurrency-racer-", ".log"]) }
336
- logs.each(&:unlink)
337
-
338
- pids = logs.map do |log|
339
- Process.spawn("bundle", "exec", "ruby", racer, domain_path, database, schema, race_step["verb"], args_json,
340
- out: log, err: log, chdir: root)
341
- end
342
-
343
- pids.each { |pid| Process.wait(pid) }
344
- logs.map do |log|
345
- log.rewind
346
- output = log.read
347
- log.close
348
- output.strip.empty? ? "crashed:no output from bin/qa_concurrency_racer" : output.lines.last.chomp
349
- end
350
- end
351
-
352
- # One step, one outcome — never raises: a declared domain refusal is
353
- # "refused" (the expected, ordinary answer a `given`/invariant can
354
- # give), anything else escaping is "crashed:<class>: <message>", a
355
- # genuine finding this module's own caller surfaces rather than lets
356
- # kill a forked racer silently.
357
- #
358
- # @param runtime [Runtime::Dispatcher, Runtime::RemoteDispatcher] the booted runtime
359
- # to dispatch against
360
- # @param step [Hash] the normalized (String-keyed) step to dispatch
361
- # @return [String] `"succeeded"`, `"refused"`, or `"crashed:<class>: <message>"`
362
- def dispatch_one(runtime, step)
363
- args = (step["args"] || {}).transform_keys(&:to_sym)
364
- runtime.dispatch_flat(step["verb"], args)
365
- "succeeded"
366
- rescue *Hecks::Runtime::DOMAIN_REFUSALS, Hecks::Bluebook::Expression::EvaluationError
367
- "refused"
368
- rescue StandardError => e
369
- "crashed:#{e.class}: #{e.message}"
370
- end
371
-
372
- # Dispatches every step in order, raising the first time one crashes.
373
- #
374
- # Setup tolerates an ordinary refusal (a generated sequence's own
375
- # earlier step can legitimately refuse — every other mode in this
376
- # practice already replays a prefix that way) but never a crash: an
377
- # unexpected exception during setup means the schema this race is
378
- # about to run against is in an unknown state, which is itself
379
- # worth surfacing, not silently racing anyway.
380
- #
381
- # @param runtime [Runtime::Dispatcher, Runtime::RemoteDispatcher] the booted runtime
382
- # to dispatch against
383
- # @param steps [Array<Hash>] the normalized steps to dispatch, in order
384
- # @return [void]
385
- # @raise [RuntimeError] if any step's own `dispatch_one` outcome is a crash, naming
386
- # the step's verb and outcome
387
- def dispatch_all!(runtime, steps)
388
- steps.each do |step|
389
- outcome = dispatch_one(runtime, step)
390
- raise "setup step #{step['verb']} #{outcome}" if outcome.start_with?("crashed:")
391
- end
392
- end
393
-
394
- # Boots a `PostgresEra`-rebound copy of the domain against an
395
- # existing schema, without wiping it first.
396
- #
397
- # The same copy-and-rebind `IsolatedBoot.call(..., adapter:
398
- # :postgres_era, ...)` does, minus the schema wipe — deliberately
399
- # not reusing `IsolatedBoot.rebind_to_postgres_era!` itself, which
400
- # bundles `ensure_postgres_era_schema!`'s own `DROP SCHEMA` into the
401
- # same call with no way to opt out (see that method's own header:
402
- # the wipe is the "zero-history guarantee every other adapter mode
403
- # already gives," exactly the guarantee this caller must not have —
404
- # the whole point of a race is booting against what setup already
405
- # wrote). `copy_dereferencing`/`rewrite_bindings!` are the same two
406
- # public steps that method itself calls first; only the `.world`
407
- # this writes is duplicated from it, not re-derived, because the
408
- # shape a `PostgresEra`-bound copy's `.world` needs is exactly that
409
- # method's own, one step short.
410
- #
411
- # @param domain_path [String] filesystem path to the target domain's directory
412
- # @param database [String] the PostgresEra database name to bind the copy to
413
- # @param schema [String] the existing PostgresEra schema name to bind the copy to,
414
- # left exactly as found
415
- # @yield [copy] runs against the rebound copy
416
- # @yieldparam copy [String] filesystem path to the rebound domain copy
417
- # @return [Object] the block's own result
418
- def boot_preserving_schema(domain_path, database:, schema:)
419
- Dir.mktmpdir("hecks-concurrency") do |tmp|
420
- copy = File.join(tmp, File.basename(domain_path))
421
- IsolatedBoot.copy_dereferencing(domain_path, copy)
422
- FileUtils.rm_rf(File.join(copy, "data"))
423
- IsolatedBoot.rewrite_bindings!(copy, "PostgresEra")
424
- write_postgres_era_world!(copy, database: database, schema: schema)
425
- yield copy
426
- end
427
- end
428
-
429
- # Writes a `.world` file binding every hecksagon-named member in
430
- # `copy` to `database`/`schema`, replacing any other `.world` file
431
- # the copy already carries.
432
- #
433
- # @param copy [String] filesystem path to the domain copy to rewrite
434
- # @param database [String] the PostgresEra database name to write into the `.world` file
435
- # @param schema [String] the PostgresEra schema name to write into the `.world` file
436
- # @return [void]
437
- def write_postgres_era_world!(copy, database:, schema:)
438
- # Same merge IsolatedBoot.rebind_to_postgres_era! now does — one
439
- # world file per directory, every hecksagon name in that directory.
440
- worlds_by_dir = Hash.new { |h, k| h[k] = [] }
441
- Dir.glob(File.join(copy, "**", "*.hecksagon")).each do |hecksagon_path|
442
- names = File.read(hecksagon_path).scan(/Hecks\.hecksagon\s+"([^"]+)"/).flatten
443
- worlds_by_dir[File.dirname(hecksagon_path)].concat(names)
444
- end
445
- worlds_by_dir.each do |dir, names|
446
- names = names.uniq
447
- next if names.empty?
448
-
449
- world_path = File.join(dir, "hecks_fuzz_postgres_era.world")
450
- File.write(world_path, names.map do |name|
451
- <<~WORLD
452
- Hecks.world "#{name}" do
453
- persisted_by("PostgresEra") do
454
- database "#{database}"
455
- schema "#{schema}"
456
- allow_superuser true
457
- end
458
- end
459
- WORLD
460
- end.join("\n"))
461
- end
462
-
463
- Dir.glob(File.join(copy, "**", "*.world")).each do |path|
464
- File.delete(path) unless File.basename(path) == "hecks_fuzz_postgres_era.world"
465
- end
466
- end
467
- end
468
- end
469
- end