standard_flags 0.3.0 → 0.4.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 (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +188 -0
  3. data/README.md +531 -59
  4. data/conformance/README.md +152 -3
  5. data/conformance/legacy_env.json +7 -1
  6. data/conformance/schema/fixture.schema.json +390 -21
  7. data/conformance/schema/manifest.schema.json +347 -0
  8. data/conformance/upgrade/client_status_server.json +297 -0
  9. data/conformance/wire/client_state.json +2115 -2
  10. data/conformance/wire/client_status.json +359 -0
  11. data/conformance/wire/manifest_check.json +5713 -0
  12. data/lib/generators/standard_flags/install/templates/initializer.rb.tt +4 -1
  13. data/lib/generators/standard_flags/migrations/migrations_generator.rb +37 -9
  14. data/lib/generators/standard_flags/migrations/templates/create_standard_flags_compat_stats.rb.tt +17 -0
  15. data/lib/standard_flags/client_app.rb +229 -0
  16. data/lib/standard_flags/client_status/controller.rb +59 -0
  17. data/lib/standard_flags/client_status.rb +110 -0
  18. data/lib/standard_flags/config.rb +18 -1
  19. data/lib/standard_flags/controller.rb +110 -5
  20. data/lib/standard_flags/definition.rb +37 -35
  21. data/lib/standard_flags/diagnostics.rb +61 -3
  22. data/lib/standard_flags/env_pin.rb +5 -15
  23. data/lib/standard_flags/errors.rb +31 -0
  24. data/lib/standard_flags/evaluator.rb +1 -0
  25. data/lib/standard_flags/mcp/flags.rb +12 -1
  26. data/lib/standard_flags/open_feature/provider.rb +2 -1
  27. data/lib/standard_flags/parser.rb +0 -16
  28. data/lib/standard_flags/registry.rb +46 -4
  29. data/lib/standard_flags/runtime/active_record_store.rb +64 -0
  30. data/lib/standard_flags/runtime/compat_tracker.rb +228 -0
  31. data/lib/standard_flags/runtime/memory_store.rb +20 -0
  32. data/lib/standard_flags/runtime/models.rb +6 -0
  33. data/lib/standard_flags/runtime/store.rb +18 -0
  34. data/lib/standard_flags/runtime.rb +33 -3
  35. data/lib/standard_flags/stores/app_store.rb +172 -0
  36. data/lib/standard_flags/stores.rb +37 -0
  37. data/lib/standard_flags/tooling/kotlin.rb +319 -0
  38. data/lib/standard_flags/tooling/manifest.rb +401 -0
  39. data/lib/standard_flags/tooling/manifest_check.rb +355 -0
  40. data/lib/standard_flags/tooling.rb +150 -55
  41. data/lib/standard_flags/version.rb +1 -1
  42. data/lib/standard_flags.rb +3 -0
  43. data/lib/tasks/standard_flags.rake +47 -0
  44. metadata +15 -2
  45. data/conformance/legacy_exact.json +0 -90
@@ -71,6 +71,53 @@ namespace :standard_flags do
71
71
  puts "Wrote #{path.relative_path_from(Rails.root)}"
72
72
  end
73
73
 
74
+ namespace :manifest do
75
+ # Exit 0 when the committed manifest matches the registry; 1 when it is
76
+ # stale or missing; 2 when a wire the baseline told a client is gone
77
+ # without a tombstone serving it, changed type, or a public audience
78
+ # went private, or when a manifest (or a given BASE) can't be read.
79
+ # Without BASE= the committed file is the baseline, with a warning;
80
+ # BASE_OPTIONAL=1 lets a BASE file that doesn't exist skip the contract
81
+ # checks; a directory or an unreadable file still fails.
82
+ desc "Check the committed manifest against the registry: BASE=<base branch's manifest> [BASE_OPTIONAL=1]"
83
+ task check: :environment do
84
+ path = Rails.root.join(StandardFlags.config.manifest_path)
85
+ committed = File.file?(path) ? File.binread(path).force_encoding(Encoding::UTF_8) : nil
86
+ base_path = ENV["BASE"].to_s.strip
87
+ base =
88
+ if base_path.empty? then :committed
89
+ elsif File.directory?(base_path) then StandardFlags::Tooling::ManifestCheck::Unavailable.new(reason: "BASE #{base_path} is a directory")
90
+ elsif !File.exist?(base_path) then StandardFlags::Tooling::ManifestCheck::Unavailable.new(reason: "BASE #{base_path} does not exist", missing: true)
91
+ else
92
+ begin
93
+ File.binread(base_path).force_encoding(Encoding::UTF_8)
94
+ rescue SystemCallError => e
95
+ StandardFlags::Tooling::ManifestCheck::Unavailable.new(reason: "BASE #{base_path} can't be read (#{e.class})")
96
+ end
97
+ end
98
+ check = StandardFlags::Tooling::ManifestCheck.new(committed: committed, base: base, base_optional: ENV["BASE_OPTIONAL"] == "1")
99
+ result = check.call
100
+ relative = path.relative_path_from(Rails.root).to_s
101
+ if result.ok?
102
+ puts check.render(result, path: relative)
103
+ else
104
+ warn check.render(result, path: relative)
105
+ exit result.exit_code
106
+ end
107
+ end
108
+ end
109
+
110
+ desc "Write Kotlin enums per audience from the manifest (config.kotlin_path, config.kotlin_package)"
111
+ task kotlin: :environment do
112
+ path = Rails.root.join(StandardFlags.config.kotlin_path)
113
+ FileUtils.mkdir_p(path.dirname)
114
+ # The existing file's entry names are kept, so shipped client code keeps
115
+ # compiling against the same constants. Delete it to name everything afresh.
116
+ previous = File.file?(path) ? File.read(path) : nil
117
+ File.write(path, StandardFlags::Tooling::Kotlin.new(previous: previous).render)
118
+ puts "Wrote #{path.relative_path_from(Rails.root)}"
119
+ end
120
+
74
121
  desc "Write TypeScript Features types per audience (config.typescript_path)"
75
122
  task typescript: :environment do
76
123
  path = Rails.root.join(StandardFlags.config.typescript_path)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard_flags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rarebit One
@@ -94,17 +94,20 @@ files:
94
94
  - conformance/bucket_vectors.json
95
95
  - conformance/guards_and_errors.json
96
96
  - conformance/legacy_env.json
97
- - conformance/legacy_exact.json
98
97
  - conformance/operations/write_path.json
99
98
  - conformance/permanent_flags.json
100
99
  - conformance/resolution.json
101
100
  - conformance/runtime/client.json
102
101
  - conformance/runtime/rules.json
103
102
  - conformance/schema/fixture.schema.json
103
+ - conformance/schema/manifest.schema.json
104
+ - conformance/upgrade/client_status_server.json
104
105
  - conformance/versions/legacy_ranges.json
105
106
  - conformance/versions/version_ranges.json
106
107
  - conformance/wire/client_state.json
108
+ - conformance/wire/client_status.json
107
109
  - conformance/wire/delivery.json
110
+ - conformance/wire/manifest_check.json
108
111
  - lib/generators/standard_flags/admin/admin_generator.rb
109
112
  - lib/generators/standard_flags/admin/templates/controller.rb.tt
110
113
  - lib/generators/standard_flags/admin/templates/index.tsx.tt
@@ -113,6 +116,7 @@ files:
113
116
  - lib/generators/standard_flags/install/templates/flags.rb.tt
114
117
  - lib/generators/standard_flags/install/templates/initializer.rb.tt
115
118
  - lib/generators/standard_flags/migrations/migrations_generator.rb
119
+ - lib/generators/standard_flags/migrations/templates/create_standard_flags_compat_stats.rb.tt
116
120
  - lib/generators/standard_flags/migrations/templates/create_standard_flags_tables.rb.tt
117
121
  - lib/standard_flags.rb
118
122
  - lib/standard_flags/actor.rb
@@ -120,6 +124,9 @@ files:
120
124
  - lib/standard_flags/audit_trail.rb
121
125
  - lib/standard_flags/bucket.rb
122
126
  - lib/standard_flags/client.rb
127
+ - lib/standard_flags/client_app.rb
128
+ - lib/standard_flags/client_status.rb
129
+ - lib/standard_flags/client_status/controller.rb
123
130
  - lib/standard_flags/config.rb
124
131
  - lib/standard_flags/context.rb
125
132
  - lib/standard_flags/controller.rb
@@ -173,6 +180,7 @@ files:
173
180
  - lib/standard_flags/runtime.rb
174
181
  - lib/standard_flags/runtime/active_record_store.rb
175
182
  - lib/standard_flags/runtime/cache.rb
183
+ - lib/standard_flags/runtime/compat_tracker.rb
176
184
  - lib/standard_flags/runtime/evaluation_tracker.rb
177
185
  - lib/standard_flags/runtime/memory_store.rb
178
186
  - lib/standard_flags/runtime/models.rb
@@ -183,10 +191,15 @@ files:
183
191
  - lib/standard_flags/semantic_version.rb
184
192
  - lib/standard_flags/sensor.rb
185
193
  - lib/standard_flags/snapshot.rb
194
+ - lib/standard_flags/stores.rb
195
+ - lib/standard_flags/stores/app_store.rb
186
196
  - lib/standard_flags/subscribers.rb
187
197
  - lib/standard_flags/testing.rb
188
198
  - lib/standard_flags/tooling.rb
189
199
  - lib/standard_flags/tooling/changes.rb
200
+ - lib/standard_flags/tooling/kotlin.rb
201
+ - lib/standard_flags/tooling/manifest.rb
202
+ - lib/standard_flags/tooling/manifest_check.rb
190
203
  - lib/standard_flags/version.rb
191
204
  - lib/standard_flags/version_range.rb
192
205
  - lib/tasks/standard_flags.rake
@@ -1,90 +0,0 @@
1
- {
2
- "description": "legacy_parser: exact reads legacy env: names the way a hand-written ENV[\"X\"] == \"on\" reader did: no trimming or case folding, on only for a legacy_true value, any other value (including a set-but-blank one, unless inverted) pins off, and modes match a value exactly (blank is unset). The canonical STANDARD_FLAGS_<KEY> pin is always strict.",
3
- "suite": "evaluation",
4
- "scope": "server",
5
- "registry": {
6
- "flags": [
7
- { "kind": "flag", "key": "purge_inactive", "owner": "platform", "permanent": true,
8
- "env": "ACME_PURGE_INACTIVE", "legacy_parser": "exact" },
9
- { "kind": "flag", "key": "bulk_export", "owner": "reporting", "permanent": true,
10
- "env": "ACME_BULK_EXPORT", "legacy_parser": "exact", "legacy_true": ["on", "enabled"] },
11
- { "kind": "kill_switch", "key": "ai_assistant", "owner": "assistant",
12
- "env": "ACME_ASSISTANT_DISABLED", "inverted": true, "legacy_parser": "exact" },
13
- { "kind": "mode", "key": "strict_gates", "owner": "platform", "preset": "sensor",
14
- "env": "ACME_STRICT_GATES", "legacy_parser": "exact" },
15
- { "kind": "flag", "key": "new_reports", "owner": "reporting", "remove_by": "2027-01-01", "final": true,
16
- "env": "ACME_REPORTS_ENABLED" }
17
- ]
18
- },
19
- "cases": [
20
- { "name": "exact legacy on turns the flag on", "flag": "purge_inactive", "environment": "production",
21
- "env_vars": { "ACME_PURGE_INACTIVE": "on" },
22
- "expected": { "value": true, "variant": "on", "reason": "ENV_PIN", "source_env_var": "ACME_PURGE_INACTIVE" } },
23
- { "name": "exact legacy true is not on: it pins the flag off", "flag": "purge_inactive", "environment": "production",
24
- "env_vars": { "ACME_PURGE_INACTIVE": "true" },
25
- "expected": { "value": false, "variant": "off", "reason": "ENV_PIN", "source_env_var": "ACME_PURGE_INACTIVE" } },
26
- { "name": "exact legacy matching is case-sensitive", "flag": "purge_inactive", "environment": "production",
27
- "env_vars": { "ACME_PURGE_INACTIVE": "ON" },
28
- "expected": { "value": false, "variant": "off", "reason": "ENV_PIN", "source_env_var": "ACME_PURGE_INACTIVE" } },
29
- { "name": "exact legacy matching does not strip whitespace", "flag": "purge_inactive", "environment": "production",
30
- "env_vars": { "ACME_PURGE_INACTIVE": " on" },
31
- "expected": { "value": false, "variant": "off", "reason": "ENV_PIN", "source_env_var": "ACME_PURGE_INACTIVE" } },
32
- { "name": "an unrecognised exact legacy value pins off instead of being ignored", "flag": "purge_inactive", "environment": "production",
33
- "env_vars": { "ACME_PURGE_INACTIVE": "maybe" },
34
- "expected": { "value": false, "variant": "off", "reason": "ENV_PIN", "source_env_var": "ACME_PURGE_INACTIVE" } },
35
- { "name": "a set-but-blank exact legacy value pins the flag off", "flag": "purge_inactive", "environment": "production",
36
- "env_vars": { "ACME_PURGE_INACTIVE": " " },
37
- "expected": { "value": false, "variant": "off", "reason": "ENV_PIN", "source_env_var": "ACME_PURGE_INACTIVE" } },
38
- { "name": "an empty exact legacy value pins the flag off", "flag": "purge_inactive", "environment": "production",
39
- "env_vars": { "ACME_PURGE_INACTIVE": "" },
40
- "expected": { "value": false, "variant": "off", "reason": "ENV_PIN", "source_env_var": "ACME_PURGE_INACTIVE" } },
41
- { "name": "an unset exact legacy name falls through to the default", "flag": "purge_inactive", "environment": "production",
42
- "env_vars": {},
43
- "expected": { "value": false, "variant": "off", "reason": "DEFAULT" } },
44
- { "name": "a blank canonical pin is unset, so the exact legacy name decides", "flag": "purge_inactive", "environment": "production",
45
- "env_vars": { "STANDARD_FLAGS_PURGE_INACTIVE": " ", "ACME_PURGE_INACTIVE": "on" },
46
- "expected": { "value": true, "variant": "on", "reason": "ENV_PIN", "source_env_var": "ACME_PURGE_INACTIVE" } },
47
- { "name": "the canonical pin stays strict and case-insensitive", "flag": "purge_inactive", "environment": "production",
48
- "env_vars": { "STANDARD_FLAGS_PURGE_INACTIVE": " TRUE " },
49
- "expected": { "value": true, "variant": "on", "reason": "ENV_PIN", "source_env_var": "STANDARD_FLAGS_PURGE_INACTIVE" } },
50
- { "name": "the canonical pin wins over an exact legacy name", "flag": "purge_inactive", "environment": "production",
51
- "env_vars": { "STANDARD_FLAGS_PURGE_INACTIVE": "off", "ACME_PURGE_INACTIVE": "on" },
52
- "expected": { "value": false, "variant": "off", "reason": "ENV_PIN", "source_env_var": "STANDARD_FLAGS_PURGE_INACTIVE" } },
53
- { "name": "an unparseable canonical pin falls through to the exact legacy name", "flag": "purge_inactive", "environment": "production",
54
- "env_vars": { "STANDARD_FLAGS_PURGE_INACTIVE": "maybe", "ACME_PURGE_INACTIVE": "on" },
55
- "expected": { "value": true, "variant": "on", "reason": "ENV_PIN", "source_env_var": "ACME_PURGE_INACTIVE" } },
56
- { "name": "legacy_true lists every value that means on", "flag": "bulk_export", "environment": "production",
57
- "env_vars": { "ACME_BULK_EXPORT": "enabled" },
58
- "expected": { "value": true, "variant": "on", "reason": "ENV_PIN", "source_env_var": "ACME_BULK_EXPORT" } },
59
- { "name": "legacy_true replaces the default on", "flag": "bulk_export", "environment": "production",
60
- "env_vars": { "ACME_BULK_EXPORT": "yes" },
61
- "expected": { "value": false, "variant": "off", "reason": "ENV_PIN", "source_env_var": "ACME_BULK_EXPORT" } },
62
- { "name": "inverted exact legacy on turns the kill switch off", "flag": "ai_assistant", "environment": "production",
63
- "env_vars": { "ACME_ASSISTANT_DISABLED": "on" },
64
- "expected": { "value": false, "variant": "off", "reason": "KILL_SWITCH", "source_env_var": "ACME_ASSISTANT_DISABLED" } },
65
- { "name": "inverted exact legacy true keeps the kill switch on", "flag": "ai_assistant", "environment": "production",
66
- "env_vars": { "ACME_ASSISTANT_DISABLED": "true" },
67
- "expected": { "value": true, "variant": "on", "reason": "ENV_PIN", "source_env_var": "ACME_ASSISTANT_DISABLED" } },
68
- { "name": "a blank inverted exact legacy value is unset", "flag": "ai_assistant", "environment": "production",
69
- "env_vars": { "ACME_ASSISTANT_DISABLED": "" },
70
- "expected": { "value": true, "variant": "on", "reason": "DEFAULT" } },
71
- { "name": "a blank exact legacy mode value is unset", "flag": "strict_gates", "environment": "production",
72
- "env_vars": { "ACME_STRICT_GATES": " " },
73
- "expected": { "value": "off", "variant": "off", "reason": "DEFAULT" } },
74
- { "name": "an exact legacy mode value must equal a mode name", "flag": "strict_gates", "environment": "production",
75
- "env_vars": { "ACME_STRICT_GATES": "sensor" },
76
- "expected": { "value": "sensor", "variant": "sensor", "reason": "ENV_PIN", "source_env_var": "ACME_STRICT_GATES" } },
77
- { "name": "an exact legacy mode value in another case is rejected", "flag": "strict_gates", "environment": "production",
78
- "env_vars": { "ACME_STRICT_GATES": "Sensor" },
79
- "expected": { "value": "off", "variant": "off", "reason": "DEFAULT" } },
80
- { "name": "an exact legacy mode value with whitespace is rejected", "flag": "strict_gates", "environment": "production",
81
- "env_vars": { "ACME_STRICT_GATES": "on " },
82
- "expected": { "value": "off", "variant": "off", "reason": "DEFAULT" } },
83
- { "name": "the canonical mode pin stays case-insensitive", "flag": "strict_gates", "environment": "production",
84
- "env_vars": { "STANDARD_FLAGS_STRICT_GATES": "Sensor" },
85
- "expected": { "value": "sensor", "variant": "sensor", "reason": "ENV_PIN", "source_env_var": "STANDARD_FLAGS_STRICT_GATES" } },
86
- { "name": "a legacy name without legacy_parser stays strict", "flag": "new_reports", "environment": "production",
87
- "env_vars": { "ACME_REPORTS_ENABLED": " Yes " },
88
- "expected": { "value": true, "variant": "on", "reason": "ENV_PIN", "source_env_var": "ACME_REPORTS_ENABLED" } }
89
- ]
90
- }