trmnl_preview 0.22.1 → 0.23.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: abbaf54f1f6ccdb3a4b76b1be3d43b574a74c06f63c59e493c4a1b7e2a409bc3
4
- data.tar.gz: 4275a70d54b9456786a149bbc43ff778357e06d99bc70be516b89bdf240c1509
3
+ metadata.gz: 8124e73871c707f410d584753b41438447d13ad2afd1cabc8e3cdbe5380e2122
4
+ data.tar.gz: 07d30b092fd5d63dbc3851b505cedda84c71d378f16593a40571bb8def898a2f
5
5
  SHA512:
6
- metadata.gz: 3931b0a7a91a3f2c8fc1eafc72211a799bf980baa7575fb1af1000fe1666b8e846acc6af68a50107349d7e887d46c0b5d01a67be535682c5f5844be43decd050
7
- data.tar.gz: 1318426dd6a23949218f826bb4cdcb926914856f4f00447eb5b3a18565c496ab2920e1b5bf06e7952b3ccf578204108834ec3a5b789f98404f9f58d1b71b2cee
6
+ metadata.gz: 81b1aa797fca660e60ea557ee60914ff00109526376931c64e54f5742cde11da52c0711db3997530e5454ee6bb67faa666a38b959753d520f7d3e9f2e685395d
7
+ data.tar.gz: 689f8792288c7c8fc9487923f52ac5775cc9357b8cdb3e23edc127a5fef8ff24139cc2e8aa86e2770da88d031340be551f398793354fc60464a49d9cffecd307
data/CHANGELOG.md CHANGED
@@ -1,6 +1,16 @@
1
1
 
2
2
  # Changelog
3
3
 
4
+ ## 0.23.1
5
+
6
+ - A transform that prints more than about 64 KB no longer hangs until its timeout in `trmnlp test` and `trmnlp serve`; its output is read while it runs.
7
+
8
+ ## 0.23.0
9
+
10
+ - `TRMNLP::Poller#fetch_responses` is public: each polling url as TRMNL resolves it, with its live response. A tool can keep them as the mocks `trmnlp test` answers with.
11
+ - `it_behaves_like 'a publishable recipe'` uses the group's `data`, so a webhook plugin's examples can draw from the merge variables it stores.
12
+ - A static plugin with blank `static_data` renders with no data, as on TRMNL, instead of failing with "invalid JSON in static_data". A byte order mark before the JSON is skipped, as on TRMNL.
13
+
4
14
  ## 0.22.1
5
15
 
6
16
  - The Docker image runs liquid 5.14 and selenium-webdriver 4.50, as TRMNL does. It had 5.13 and 4.48, so Liquid output could differ from TRMNL. Installs of the gem already took the newer versions.
@@ -69,8 +69,10 @@ module TRMNLP
69
69
 
70
70
  def id = @config['id']
71
71
 
72
+ # Like TRMNL: blank is no data, and a byte order mark is not part of the JSON.
72
73
  def static_data
73
- JSON.parse(@config['static_data'] || '{}')
74
+ text = @config['static_data'].to_s.delete_prefix("\uFEFF")
75
+ text.strip.empty? ? {} : JSON.parse(text)
74
76
  rescue JSON::ParserError
75
77
  raise InvalidConfig, 'invalid JSON in static_data'
76
78
  end
data/lib/trmnlp/poller.rb CHANGED
@@ -46,6 +46,16 @@ module TRMNLP
46
46
  {}
47
47
  end
48
48
 
49
+ # Each polling url as TRMNL resolves it, with its response, or nil when the fetch failed.
50
+ def fetch_responses
51
+ # Resolve once per attempt (it refreshes as a side effect), then share across
52
+ # every URL, header, and body render.
53
+ variables = trmnl_variables.call.merge(oauth_session.liquid_variables)
54
+ headers = config.plugin.polling_headers(extra_variables: variables)
55
+ body = config.plugin.polling_body(extra_variables: variables)
56
+ config.plugin.polling_urls(extra_variables: variables).map { |url| [url, fetch_one(url, headers, body)] }
57
+ end
58
+
49
59
  private
50
60
 
51
61
  attr_reader :config, :paths, :oauth_session, :trmnl_variables, :reporter, :async_callback
@@ -74,24 +84,16 @@ module TRMNLP
74
84
  end
75
85
 
76
86
  def aggregate_responses
77
- fetched = fetch_all
87
+ fetched = fetch_responses
78
88
  # Like the hosted service: a token rejected before its expiry gets one refresh and retry.
79
- fetched = fetch_all if fetched.any? { |_url, response| response&.status == 401 } && oauth_session.force_refresh!
89
+ token_rejected = fetched.any? { |_url, response| response&.status == 401 }
90
+ fetched = fetch_responses if token_rejected && oauth_session.force_refresh!
80
91
  responses = fetched.map { |url, response| response ? parse_response(response, url) : {} }
81
92
  return responses.first if responses.size == 1
82
93
 
83
94
  responses.each_with_index.with_object({}) { |(r, i), h| h["IDX_#{i}"] = r }
84
95
  end
85
96
 
86
- def fetch_all
87
- # Resolve once per attempt (it refreshes as a side effect), then share across
88
- # every URL, header, and body render.
89
- variables = trmnl_variables.call.merge(oauth_session.liquid_variables)
90
- headers = config.plugin.polling_headers(extra_variables: variables)
91
- body = config.plugin.polling_body(extra_variables: variables)
92
- config.plugin.polling_urls(extra_variables: variables).map { |url| [url, fetch_one(url, headers, body)] }
93
- end
94
-
95
97
  def fetch_one(url, headers, body)
96
98
  verb = config.plugin.polling_verb.upcase
97
99
  response, failure = outbound_request.call(verb, url, headers:, body:)
@@ -35,7 +35,8 @@ end
35
35
  RSpec.shared_examples 'a publishable recipe' do |screens: TRMNLP::Testing::PUBLISHABLE_RECIPE_SCREENS|
36
36
  let(:recipe_inputs) do
37
37
  { mocks: respond_to?(:mocks) ? mocks : {}, custom_fields: respond_to?(:custom_fields) ? custom_fields : {},
38
- variables: respond_to?(:variables) ? variables : {}, now: respond_to?(:now) ? now : nil }
38
+ variables: respond_to?(:variables) ? variables : {}, now: respond_to?(:now) ? now : nil,
39
+ data: respond_to?(:data) ? data : nil }
39
40
  end
40
41
 
41
42
  def draw_cleanly = have_no_problems.and(have_no_leaked_text)
@@ -65,13 +65,16 @@ module TRMNLP
65
65
  @on_spawn&.call(wait_thr.pid)
66
66
  stdin_io.write(stdin)
67
67
  stdin_io.close
68
+ # Read while it runs: a process that fills a pipe waits for its reader, so reading after it exits hangs.
69
+ stdout_reader = Thread.new { stdout_io.read }
70
+ stderr_reader = Thread.new { stderr_io.read }
68
71
 
69
72
  unless wait_thr.join(timeout_seconds)
70
73
  kill(wait_thr)
71
74
  return failure("timeout after #{timeout_seconds}s", monotonic_ms - started)
72
75
  end
73
76
 
74
- build_result(stdout_io.read, stderr_io.read, wait_thr.value, output_path, monotonic_ms - started)
77
+ build_result(stdout_reader.value, stderr_reader.value, wait_thr.value, output_path, monotonic_ms - started)
75
78
  end
76
79
  end
77
80
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TRMNLP
4
- VERSION = '0.22.1'
4
+ VERSION = '0.23.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trmnl_preview
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.1
4
+ version: 0.23.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rockwell Schrock