latticerb 0.4.0-x86_64-linux

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 (32) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +176 -0
  3. data/README.md +163 -0
  4. data/exe/lattice +7 -0
  5. data/ext/lattice_native/rustfmt.toml +1 -0
  6. data/lib/lattice/3.2/lattice_native.so +0 -0
  7. data/lib/lattice/3.3/lattice_native.so +0 -0
  8. data/lib/lattice/3.4/lattice_native.so +0 -0
  9. data/lib/lattice/4.0/lattice_native.so +0 -0
  10. data/lib/lattice/agent.rb +204 -0
  11. data/lib/lattice/cli.rb +469 -0
  12. data/lib/lattice/constraints.rb +265 -0
  13. data/lib/lattice/formatters.rb +193 -0
  14. data/lib/lattice/ipog.rb +103 -0
  15. data/lib/lattice/model.rb +83 -0
  16. data/lib/lattice/native.rb +10 -0
  17. data/lib/lattice/parser.rb +427 -0
  18. data/lib/lattice/resources/claude/lattice-workflow/SKILL.md +144 -0
  19. data/lib/lattice/resources/claude/lattice-workflow/references/modeling-rules.md +52 -0
  20. data/lib/lattice/resources/claude/lattice-workflow/references/worked-examples.md +59 -0
  21. data/lib/lattice/resources/codex/lattice-workflow/SKILL.md +144 -0
  22. data/lib/lattice/resources/codex/lattice-workflow/agents/openai.yaml +7 -0
  23. data/lib/lattice/resources/codex/lattice-workflow/references/modeling-rules.md +52 -0
  24. data/lib/lattice/resources/codex/lattice-workflow/references/worked-examples.md +59 -0
  25. data/lib/lattice/resources/generic/lattice-workflow/SKILL.md +152 -0
  26. data/lib/lattice/resources/generic/lattice-workflow/references/modeling-rules.md +52 -0
  27. data/lib/lattice/resources/generic/lattice-workflow/references/worked-examples.md +59 -0
  28. data/lib/lattice/schema_text.rb +153 -0
  29. data/lib/lattice/version.rb +5 -0
  30. data/lib/lattice.rb +88 -0
  31. data/lib/latticerb.rb +4 -0
  32. metadata +99 -0
@@ -0,0 +1,153 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "psych"
5
+
6
+ module Lattice
7
+ # Reads schema text (JSON or YAML) into plain Hashes, Arrays and Strings,
8
+ # keeping every value as the text the user wrote. `1.10` stays "1.10",
9
+ # `0x1F` stays "0x1F" and `2026-10-26T10:00:00Z` stays as typed, instead of
10
+ # being converted to a number or time and printed back differently by Ruby
11
+ # and Python. The only conversions:
12
+ #
13
+ # - unquoted yes/no/on/off/true/false (in the case forms below) become
14
+ # true/false, and an empty value, ~ or null becomes nil;
15
+ # - JSON integers are written in plain decimal form.
16
+ #
17
+ # The Python implementation (lattice.schema_text) follows the same rules, and
18
+ # test/fixtures/scalar_text.* pins the result for both.
19
+ module SchemaText
20
+ extend self
21
+
22
+ class SyntaxError < StandardError; end
23
+
24
+ TRUE_WORDS = %w[yes Yes YES true True TRUE on On ON].freeze
25
+ FALSE_WORDS = %w[no No NO false False FALSE off Off OFF].freeze
26
+ NULL_WORDS = ["", "~", "null", "Null", "NULL"].freeze
27
+
28
+ YAML_TAG_PREFIX = "tag:yaml.org,2002:"
29
+ STR_TAGS = ["!", "#{YAML_TAG_PREFIX}str"].freeze
30
+ SCALAR_TAGS = %w[str int float bool null timestamp binary merge value].map { |name| "#{YAML_TAG_PREFIX}#{name}" }.freeze
31
+ SEQUENCE_TAGS = [nil, "!", "#{YAML_TAG_PREFIX}seq"].freeze
32
+ MAPPING_TAGS = [nil, "!", "#{YAML_TAG_PREFIX}map"].freeze
33
+
34
+ # Hands JSON floats back as their source text.
35
+ class RawNumber
36
+ def self.new(text) = text
37
+ end
38
+
39
+ # Rejects a key written twice. json 2.x calls []= on a custom object_class;
40
+ # json 3.x checks duplicates itself when allow_duplicate_key is false.
41
+ class UniqueHash < Hash
42
+ def []=(key, value)
43
+ raise JSON::ParserError, "duplicate key `#{key}`" if key?(key)
44
+
45
+ super
46
+ end
47
+ end
48
+
49
+ def load_json(text)
50
+ json_strings(
51
+ JSON.parse(text, decimal_class: RawNumber, object_class: UniqueHash, allow_duplicate_key: false)
52
+ )
53
+ end
54
+
55
+ def load_yaml(text)
56
+ documents = Psych.parse_stream(text).children
57
+ raise SyntaxError, "expected a single YAML document, found #{documents.length}" if documents.length > 1
58
+ return nil if documents.empty?
59
+
60
+ yaml_value(documents.first.root, {})
61
+ end
62
+
63
+ private
64
+
65
+ def json_strings(value)
66
+ case value
67
+ when Hash then value.to_h { |key, child| [key, json_strings(child)] }
68
+ when Array then value.map { |child| json_strings(child) }
69
+ when Integer then value.to_s
70
+ else value
71
+ end
72
+ end
73
+
74
+ # `anchors` maps each anchor to its value once built; an anchor still
75
+ # being built (nil value) means an alias points back into itself.
76
+ def yaml_value(node, anchors)
77
+ return yaml_alias(node, anchors) if node.is_a?(Psych::Nodes::Alias)
78
+
79
+ anchors[node.anchor] = nil if node.anchor
80
+ value =
81
+ case node
82
+ when Psych::Nodes::Scalar then yaml_scalar(node)
83
+ when Psych::Nodes::Sequence
84
+ check_tag(node.tag, SEQUENCE_TAGS)
85
+ node.children.map { |child| yaml_value(child, anchors) }
86
+ when Psych::Nodes::Mapping then yaml_mapping(node, anchors)
87
+ end
88
+ anchors[node.anchor] = [value] if node.anchor
89
+ value
90
+ end
91
+
92
+ def yaml_alias(node, anchors)
93
+ built = anchors.fetch(node.anchor) { raise SyntaxError, "unknown alias `*#{node.anchor}`" }
94
+ raise SyntaxError, "recursive alias" if built.nil?
95
+
96
+ built.first
97
+ end
98
+
99
+ def yaml_scalar(node)
100
+ check_tag(node.tag, [nil, "!"] + SCALAR_TAGS)
101
+ return node.value unless node.style == Psych::Nodes::Scalar::PLAIN && !STR_TAGS.include?(node.tag)
102
+ return true if TRUE_WORDS.include?(node.value)
103
+ return false if FALSE_WORDS.include?(node.value)
104
+ return nil if NULL_WORDS.include?(node.value)
105
+
106
+ node.value
107
+ end
108
+
109
+ # Keys from `<<` merges come first, earlier sources winning; the
110
+ # mapping's own keys then override them. A key written twice is an error.
111
+ def yaml_mapping(node, anchors)
112
+ check_tag(node.tag, MAPPING_TAGS)
113
+ merged = {}
114
+ own = {}
115
+ seen_merge = false
116
+ node.children.each_slice(2) do |key_node, value_node|
117
+ key = yaml_value(key_node, anchors)
118
+ raise SyntaxError, "mapping keys must be scalars" if key.is_a?(Enumerable)
119
+
120
+ if merge_key?(key_node)
121
+ raise SyntaxError, "duplicate key `<<`" if seen_merge
122
+
123
+ seen_merge = true
124
+ merge_sources(yaml_value(value_node, anchors)).each do |source|
125
+ source.each { |merged_key, merged_value| merged[merged_key] = merged_value unless merged.key?(merged_key) }
126
+ end
127
+ next
128
+ end
129
+
130
+ raise SyntaxError, "duplicate key `#{Lattice.normalize_scalar(key)}`" if own.key?(key)
131
+
132
+ own[key] = yaml_value(value_node, anchors)
133
+ end
134
+ merged.merge(own)
135
+ end
136
+
137
+ def merge_key?(key_node)
138
+ key_node.is_a?(Psych::Nodes::Scalar) && key_node.style == Psych::Nodes::Scalar::PLAIN && key_node.value == "<<" &&
139
+ [nil, "#{YAML_TAG_PREFIX}merge"].include?(key_node.tag)
140
+ end
141
+
142
+ def merge_sources(value)
143
+ sources = [value].flatten(1)
144
+ raise SyntaxError, "merge key `<<` needs a mapping or a list of mappings" unless sources.all?(Hash)
145
+
146
+ sources
147
+ end
148
+
149
+ def check_tag(tag, allowed)
150
+ raise SyntaxError, "unsupported YAML tag `#{tag}`" unless allowed.include?(tag)
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lattice
4
+ VERSION = "0.4.0"
5
+ end
data/lib/lattice.rb ADDED
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lattice/version"
4
+ require_relative "lattice/model"
5
+ require_relative "lattice/parser"
6
+ require_relative "lattice/constraints"
7
+ require_relative "lattice/ipog"
8
+ require_relative "lattice/formatters"
9
+
10
+ module Lattice
11
+ # A generation run: the parsed model plus its covering array, with
12
+ # ready-to-use named scenarios for tests, fixtures, and factories.
13
+ class Run
14
+ attr_reader :model, :result, :seed
15
+
16
+ def initialize(model:, result:, seed:)
17
+ @model = model
18
+ @result = result
19
+ @seed = seed
20
+ end
21
+
22
+ # Scenarios as an array of `{ "parameter" => "value" }` hashes.
23
+ def scenarios
24
+ @scenarios ||= Formatters.named_rows(model, result).each(&:freeze).freeze
25
+ end
26
+
27
+ def each_scenario(&) = scenarios.each(&)
28
+
29
+ def coverage_curve = result.coverage_curve
30
+
31
+ def to_table = Formatters.render_output(model, result, output_format: "table", seed:)
32
+ def to_json_output = Formatters.render_output(model, result, output_format: "json", seed:)
33
+ def to_csv = Formatters.render_output(model, result, output_format: "csv", seed:)
34
+ def to_summary = Formatters.render_output(model, result, output_format: "summary", seed:)
35
+ def to_yaml_output = Formatters.render_output(model, result, output_format: "yaml", seed:)
36
+ end
37
+
38
+ class << self
39
+ # Parse a schema from a Hash (already-decoded JSON/YAML), a JSON or YAML
40
+ # String, or a file path via `file:`.
41
+ def parse_model(source = nil, file: nil, strength: nil)
42
+ if file
43
+ Parser.load_model(file, strength_override: strength)
44
+ elsif source.is_a?(Hash)
45
+ Parser.parse_model_data(source, strength_override: strength)
46
+ elsif source.is_a?(String)
47
+ data = Parser.deserialize_model(source, "string", nil)
48
+ Parser.parse_model_data(data, strength_override: strength)
49
+ elsif source.is_a?(Model)
50
+ strength ? source.with(strength:) : source
51
+ else
52
+ raise ArgumentError, "Pass a schema Hash, a JSON/YAML String, a Lattice::Model, or file: <path>."
53
+ end
54
+ end
55
+
56
+ # Generate a covering array for a schema and return a Run.
57
+ #
58
+ # run = Lattice.generate(file: "spec/fixtures/checkout.yaml")
59
+ # run.scenarios.each { |row| ... }
60
+ def generate(source = nil, file: nil, strength: nil, seed: 42, pool_size: 16,
61
+ max_rows: nil, stop_after_coverage: nil, progress: nil)
62
+ model = parse_model(source, file:, strength:)
63
+ result = IPOG.generate_covering_array(
64
+ model,
65
+ strength: model.strength,
66
+ seed:,
67
+ pool_size:,
68
+ progress:,
69
+ max_rows:,
70
+ stop_after_coverage:
71
+ )
72
+ Run.new(model:, result:, seed:)
73
+ end
74
+
75
+ # Convenience: generate and return just the named scenario hashes.
76
+ def scenarios(...) = generate(...).scenarios
77
+
78
+ # Parse and constraint-check a schema, raising Lattice::ValidationError or
79
+ # Lattice::ConstraintError when invalid. Returns the Model.
80
+ def validate!(source = nil, file: nil, strength: nil)
81
+ model = parse_model(source, file:, strength:)
82
+ engine = ConstraintEngine.new(model)
83
+ raise ValidationError, ["Model has no valid complete assignments."] unless engine.satisfiable?
84
+
85
+ model
86
+ end
87
+ end
88
+ end
data/lib/latticerb.rb ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Gem entry point: Bundler auto-requires `gem "latticerb"` as "latticerb".
4
+ require_relative "lattice"
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: latticerb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: x86_64-linux
6
+ authors:
7
+ - Tyler Klose
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2026-11-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: csv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ description: Lattice generates deterministic pairwise/t-way covering arrays from a
28
+ constrained schema of parameters and values. Use it as a library in test suites
29
+ (RSpec, Minitest, Rails fixtures) or via the bundled `lattice` CLI. Generation runs
30
+ in a Rust engine shared with the Python lattice-cli package, so both give identical
31
+ rows for the same schema and seed.
32
+ email:
33
+ - tylerklose@gmail.com
34
+ executables:
35
+ - lattice
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - LICENSE
40
+ - README.md
41
+ - exe/lattice
42
+ - ext/lattice_native/rustfmt.toml
43
+ - lib/lattice.rb
44
+ - lib/lattice/3.2/lattice_native.so
45
+ - lib/lattice/3.3/lattice_native.so
46
+ - lib/lattice/3.4/lattice_native.so
47
+ - lib/lattice/4.0/lattice_native.so
48
+ - lib/lattice/agent.rb
49
+ - lib/lattice/cli.rb
50
+ - lib/lattice/constraints.rb
51
+ - lib/lattice/formatters.rb
52
+ - lib/lattice/ipog.rb
53
+ - lib/lattice/model.rb
54
+ - lib/lattice/native.rb
55
+ - lib/lattice/parser.rb
56
+ - lib/lattice/resources/claude/lattice-workflow/SKILL.md
57
+ - lib/lattice/resources/claude/lattice-workflow/references/modeling-rules.md
58
+ - lib/lattice/resources/claude/lattice-workflow/references/worked-examples.md
59
+ - lib/lattice/resources/codex/lattice-workflow/SKILL.md
60
+ - lib/lattice/resources/codex/lattice-workflow/agents/openai.yaml
61
+ - lib/lattice/resources/codex/lattice-workflow/references/modeling-rules.md
62
+ - lib/lattice/resources/codex/lattice-workflow/references/worked-examples.md
63
+ - lib/lattice/resources/generic/lattice-workflow/SKILL.md
64
+ - lib/lattice/resources/generic/lattice-workflow/references/modeling-rules.md
65
+ - lib/lattice/resources/generic/lattice-workflow/references/worked-examples.md
66
+ - lib/lattice/schema_text.rb
67
+ - lib/lattice/version.rb
68
+ - lib/latticerb.rb
69
+ homepage: https://github.com/tylerklose/lattice-ruby
70
+ licenses:
71
+ - Apache-2.0
72
+ metadata:
73
+ homepage_uri: https://github.com/tylerklose/lattice-ruby
74
+ source_code_uri: https://github.com/tylerklose/lattice-ruby
75
+ rubygems_mfa_required: 'true'
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '3.2'
85
+ - - "<"
86
+ - !ruby/object:Gem::Version
87
+ version: 4.1.dev
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubygems_version: 3.5.23
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Deterministic combinatorial coverage for agent workflows and constrained
98
+ variant surfaces.
99
+ test_files: []