tina4ruby 3.13.163 → 3.13.164

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: 34f4ce86795d403ce1236cfcdd459faa59f11fd43f7cf9d3a9a3dc9d13ec5209
4
- data.tar.gz: 1a613e2d130a451750e228b99daf2e33bba88b5378bdd5ccb83cd99f1fbc05c7
3
+ metadata.gz: 13b5afb4fa32e8a1b77bfd40d3a39ea07c52640ed539bac20fece78228463bb3
4
+ data.tar.gz: fa81074247e7b31b87ca0015077bb491815f83da4e3385b8e9a41044468c8356
5
5
  SHA512:
6
- metadata.gz: 60c7c05fee96e02aa8320b77e2ab0b6a1ed9458cc5456bcfb18284dc8ff4f1e5a1f0ee03e1056c0004590ef19e2f17c56c6466fd53665b0accb0fae356c39cda
7
- data.tar.gz: 0232f479a2f5bcd8fa9e3cf0940ffcf717d2940919656762151b3abf6e6f88e4f2527715a483f5bfbb515d7772f97457ccb7b7c316125a845e2eb6ddbf958e42
6
+ metadata.gz: 4af1bb9bda86630089e49f1e7d8556a7ff546fa7ed9bf8c5628ec6d8dae3f1814ba66813a01b6b9b10423420fc72819b5afc62004e10aa21a98a8c1b703b3e0c
7
+ data.tar.gz: e764cee8581d65b732d7ba924f64027eb582b6c84bfc672c203ab73816a72ae648d877d122de3d9720001ccf4e1b3c13c881e3715be782f9c8e2f7f5b1fb530b
data/CHANGELOG.md CHANGED
@@ -6,6 +6,23 @@ number means the same thing everywhere.
6
6
  **The authoritative release notes for every shipped version live in the documentation:**
7
7
  https://tina4.com/ruby/36-releases
8
8
 
9
+ ## 3.13.164 - 2026-11-17
10
+
11
+ ### Fixed
12
+
13
+ - Template globals registered with `Tina4.template_global` / `Tina4::Template.add_global` now reach `response.render` (they rendered empty), and so does the auto-wired `t()`, which also accepts a params hash: `{{ t("welcome", {"name": n}) }}` (it raised `ArgumentError`). Class-level filters and tests reach every render whenever they are registered. A function called in a template before it was registered no longer stays a plain (empty) variable after it is registered (#179, #181; ADR-0106, ADR-0107; parity with tina4-python, tina4-php, tina4-nodejs).
14
+ - Boot no longer logs "Database connected" after a failed connect. `Database.new` logs and degrades on a failed connect, and `setup_database` logged success regardless; it now logs the success line only when the database reports a connection, otherwise a warning "Database not connected: <url>" (#172, from a contributor).
15
+ - Pooled mode (`TINA4_DB_POOL>0`) no longer claims "Database connected" before anything connects; it says the pool is configured and connects on first use. A successful connect logs one line, with the URL minus credentials, instead of two (#174).
16
+ - `tina4ruby` serve no longer prints "Port N is in use; takeover is disabled outside dev mode" for a port nothing holds (#173, parity with tina4-php#362, tina4-python#318, tina4-nodejs#198).
17
+ - `/__dev/api/system` sends `memory_mb` (the process's current RSS), so the dashboard no longer always shows "Memory: ?" (#175).
18
+
19
+ ### Changed
20
+
21
+ - AI skills: the shared tina4-maintainer and tina4-js skills are synced with tina4-python; tina4-developer-ruby's contradictions are fixed against the code (frond.js API, no `{% query %}` tag, `TINA4_SWAGGER_*`, `TINA4_OVERRIDE_CLIENT` in Docker, `request.query` for query strings, realtime auth by default); the skill forbids patching the framework (#177, #180).
22
+ - AI tool files point at `CLAUDE.md` for the full API (#178).
23
+ - `llms.txt` follows the llmstxt.org specification, with link lists to the markdown docs and a CI check (#176).
24
+ - Test-only: the raw-TCP contract tests take their own free port instead of the HTTP port + 1 (#171).
25
+
9
26
  ## 3.13.163 - 2026-11-13
10
27
 
11
28
  ### Fixed
data/lib/tina4/cli.rb CHANGED
@@ -778,11 +778,12 @@ module Tina4
778
778
  # holder is signalled ONLY when a Tina4 dev server recorded its PID in the
779
779
  # per-port PID file. A foreign holder is left running and a clear message is
780
780
  # printed; takeover is also skipped in a container, outside dev mode, and when
781
- # opted out (TINA4_NO_TAKEOVER / --no-kill). Returns true only when a Tina4
782
- # holder was actually signalled.
783
- def kill_process_on_port(port)
781
+ # opted out (TINA4_NO_TAKEOVER / --no-kill). `host` is the address serve will
782
+ # bind; when given, a port that binds there is reported as free, not "in use".
783
+ # Returns true only when a Tina4 holder was actually signalled.
784
+ def kill_process_on_port(port, host = nil)
784
785
  result = Tina4::PortTakeover.take_over_port(
785
- port, dev: Tina4::PortTakeover.dev?, no_takeover: Tina4::PortTakeover.no_takeover_opted_out?
786
+ port, dev: Tina4::PortTakeover.dev?, no_takeover: Tina4::PortTakeover.no_takeover_opted_out?, host: host
786
787
  )
787
788
  if result.reclaimed?
788
789
  puts " #{result.message}"
@@ -867,7 +868,7 @@ module Tina4
867
868
  options[:host] = resolve_config(:host, options[:host])
868
869
 
869
870
  # Kill existing process on port
870
- kill_process_on_port(options[:port])
871
+ kill_process_on_port(options[:port], options[:host])
871
872
 
872
873
  require_relative "../tina4"
873
874
 
@@ -527,7 +527,10 @@ module Tina4
527
527
  # that have no native setter.
528
528
  @driver.autocommit = @autocommit if driver_implements?(@driver, :autocommit=)
529
529
 
530
- Tina4::Log.info("Database connected: #{@driver_name}")
530
+ # The ONE "connected" line for this database: it names the target (no
531
+ # credentials), so Tina4.setup_database no longer repeats it at boot.
532
+ target = Tina4::DatabaseUrl.without_credentials(@connection_string)
533
+ Tina4::Log.info("Database connected: #{target.empty? ? @driver_name : target}")
531
534
  @connect_error = nil
532
535
  rescue => e
533
536
  Tina4::Log.error("Database connection failed: #{scrub_connection_string(e.message)}")
@@ -176,6 +176,13 @@ module Tina4
176
176
  end
177
177
  end
178
178
 
179
+ # The connection string with the whole `user:pass@` removed, for log lines
180
+ # that only need to say WHICH database. Stricter than #redact (the user name
181
+ # goes too), and built on it so a password never survives an odd URL shape.
182
+ def self.without_credentials(raw)
183
+ redact(raw).gsub(%r{://[^/\s@]*@}, "://")
184
+ end
185
+
179
186
  # Structural redaction of a string that did NOT parse.
180
187
  def self.scrub(text)
181
188
  head, separator, rest = text.to_s.partition("://")
@@ -1012,17 +1012,24 @@ module Tina4
1012
1012
  { routes: routes, count: routes.size }
1013
1013
  end
1014
1014
 
1015
+ # Current resident set size of THIS process in KB: VmRSS from
1016
+ # /proc/self/status on Linux, `ps -o rss=` on macOS. nil where the OS
1017
+ # exposes neither (e.g. Windows) or the read fails. Never the peak.
1018
+ def current_rss_kb
1019
+ kb = if RUBY_PLATFORM.include?("darwin")
1020
+ `ps -o rss= -p #{Process.pid}`.strip.to_i
1021
+ elsif RUBY_PLATFORM.include?("linux")
1022
+ File.read("/proc/self/status")[/VmRSS:\s+(\d+)/, 1].to_i
1023
+ end
1024
+ kb && kb.positive? ? kb : nil
1025
+ rescue StandardError
1026
+ nil
1027
+ end
1028
+
1015
1029
  def system_payload
1016
1030
  gc = GC.stat
1017
- mem = begin
1018
- if RUBY_PLATFORM.include?("darwin")
1019
- `ps -o rss= -p #{Process.pid}`.strip.to_i # KB
1020
- elsif RUBY_PLATFORM.include?("linux")
1021
- (File.read("/proc/self/status")[/VmRSS:\s+(\d+)/, 1].to_i rescue 0)
1022
- else
1023
- 0
1024
- end
1025
- end
1031
+ rss_kb = current_rss_kb
1032
+ mem = rss_kb || 0
1026
1033
 
1027
1034
  os_release = (`uname -r`.strip rescue "unknown")
1028
1035
  host_name = (`hostname`.strip rescue "unknown")
@@ -1032,6 +1039,10 @@ module Tina4
1032
1039
  ruby_engine: RUBY_ENGINE,
1033
1040
  os: "#{RUBY_PLATFORM} #{os_release}",
1034
1041
  architecture: RUBY_PLATFORM,
1042
+ # The dashboard's "Memory" figure: the process's current RSS in MB
1043
+ # (parity with tina4-python / tina4-nodejs). nil when unmeasurable,
1044
+ # so the dashboard shows "?" rather than a made-up number.
1045
+ memory_mb: rss_kb ? (rss_kb / 1024.0).round(1) : nil,
1035
1046
  memory: {
1036
1047
  current_mb: (mem / 1024.0).round(1),
1037
1048
  peak_mb: "N/A",
data/lib/tina4/frond.rb CHANGED
@@ -39,10 +39,10 @@ module Tina4
39
39
  # -- Class-level registries ------------------------------------------------
40
40
  # Persist globals, filters, and tests across hot-reloads and across module
41
41
  # boundaries. When app.rb does ``Tina4::Frond.add_filter("money") { ... }``
42
- # at startup before any instance exists, the registration sits here. Every
43
- # subsequent ``Tina4::Frond.new`` drains these into its instance-local
44
- # registries — so hot-reloads (which re-execute ``frond = Frond.new``) and
45
- # late-constructed engines automatically inherit prior registrations.
42
+ # at startup (or later), the registration sits here. Every engine reads
43
+ # it at render time -- globals directly, filters and tests through a merge
44
+ # rebuilt when this registry changes -- so hot-reloaded, late-constructed
45
+ # AND already-existing engines all see it (ADR-0106, ADR-0107).
46
46
  #
47
47
  # The same-name dual-callable (class + instance) methods below let callers
48
48
  # write either ``Tina4::Frond.add_filter(...)`` (process-global) or
@@ -51,6 +51,9 @@ module Tina4
51
51
  @@class_filters = {}
52
52
  @@class_globals = {}
53
53
  @@class_tests = {}
54
+ # Bumped on every class-level filter/test change, so an engine knows when
55
+ # to rebuild its merged filter/test maps (see sync_registries).
56
+ @@class_registry_version = 0
54
57
 
55
58
  # -- Live-block registries (server-rendered {% live %} regions) -----------
56
59
  # A {% live %} block registers three things when its page first renders:
@@ -76,6 +79,7 @@ module Tina4
76
79
  @@class_filters = {}
77
80
  @@class_globals = {}
78
81
  @@class_tests = {}
82
+ @@class_registry_version += 1
79
83
  @@class_live_fragments = {}
80
84
  @@class_live_sources = {}
81
85
  @@class_live_ws_paths = {}
@@ -322,9 +326,14 @@ module Tina4
322
326
 
323
327
  def initialize(template_dir: "src/templates")
324
328
  @template_dir = template_dir
325
- @filters = default_filters
326
- @globals = {}
327
- @tests = default_tests
329
+ @builtin_filters = default_filters
330
+ @builtin_tests = default_tests
331
+ @local_filters = {} # this instance's own add_filter calls (ADR-0052)
332
+ @local_tests = {} # this instance's own add_test calls (ADR-0052)
333
+ @registry_version = -1
334
+ sync_registries # builds @filters / @tests
335
+ @globals = {} # this instance's own add_global calls (ADR-0052)
336
+ @builtin_globals = {}
328
337
  @auto_escape = true
329
338
 
330
339
  # Sandboxing
@@ -352,15 +361,24 @@ module Tina4
352
361
  # Built-in global functions
353
362
  register_builtin_globals
354
363
 
355
- # Drain class-level registries into this instance. Filters and tests
356
- # registered via ``Tina4::Frond.add_filter`` BEFORE this instance was
357
- # constructed flow in here. Globals likewise. This is the key to the
358
- # static-facade: ``app.rb`` registers once at startup, and every
359
- # Frond instance created later (including those born from hot-reloads)
360
- # automatically inherits the registration. Parity with tina4-python.
361
- @filters.merge!(@@class_filters)
362
- @globals.merge!(@@class_globals)
363
- @tests.merge!(@@class_tests)
364
+ # Class registrations are never copied in for good: with_globals reads
365
+ # @@class_globals at render time, and sync_registries re-merges the class
366
+ # filters/tests whenever they change. So a Tina4::Frond.add_global /
367
+ # add_filter / add_test made after this engine exists (after the first
368
+ # response.render, say) still reaches it (ADR-0106, ADR-0107).
369
+ end
370
+
371
+ # Rebuild the merged filter/test maps when the class registry changed.
372
+ #
373
+ # Same layering as globals -- built-ins < class < this instance. Filter
374
+ # lookup is on the hot path, so the merge is a plain Hash rebuilt only
375
+ # when the class-registry version moves, never a per-lookup chain.
376
+ def sync_registries
377
+ return if @registry_version == @@class_registry_version
378
+
379
+ @filters = @builtin_filters.merge(@@class_filters, @local_filters)
380
+ @tests = @builtin_tests.merge(@@class_tests, @local_tests)
381
+ @registry_version = @@class_registry_version
364
382
  end
365
383
 
366
384
  # Render a template file with data. Uses token caching for performance.
@@ -370,7 +388,7 @@ module Tina4
370
388
  # * TINA4_TEMPLATE_CACHE_TTL > 0 — cache entries expire after N seconds.
371
389
  # * TINA4_TEMPLATE_CACHE_TTL == 0 (default in production) — permanent cache.
372
390
  def render(template, data = {})
373
- context = @globals.merge(stringify_keys(data))
391
+ context = with_globals(data)
374
392
 
375
393
  path = File.join(@template_dir, template)
376
394
  raise "Template not found: #{path}" unless File.exist?(path)
@@ -401,7 +419,7 @@ module Tina4
401
419
 
402
420
  # Render a template string directly. Uses token caching for performance.
403
421
  def render_string(source, data = {})
404
- context = @globals.merge(stringify_keys(data))
422
+ context = with_globals(data)
405
423
 
406
424
  key = Digest::MD5.hexdigest(source)
407
425
  cached_tokens = @compiled_strings[key]
@@ -416,6 +434,17 @@ module Tina4
416
434
  execute_cached(tokens, context)
417
435
  end
418
436
 
437
+ # Layer the globals under the render data: built-ins < class globals (read
438
+ # live, so registration order never matters) < this instance's own
439
+ # globals < the data passed to render.
440
+ #
441
+ # Every render starts here, so this is also where the filter/test maps
442
+ # catch up with any class registration made since the last render.
443
+ def with_globals(data)
444
+ sync_registries
445
+ @builtin_globals.merge(@@class_globals, @globals, stringify_keys(data))
446
+ end
447
+
419
448
  # Clear all compiled template caches.
420
449
  def clear_cache
421
450
  @compiled.clear
@@ -428,11 +457,12 @@ module Tina4
428
457
  # Register a custom filter on the class registry only.
429
458
  #
430
459
  # Callable as ``Tina4::Frond.add_filter("money") { |v| ... }`` at app
431
- # startup BEFORE any instance exists. The registration is remembered at
432
- # class level so every later ``Tina4::Frond.new`` inherits it. To also
433
- # update a live instance's filter map, use the instance method form.
460
+ # startup or later. The registration is remembered at class level and
461
+ # every engine -- existing ones included -- merges it at its next render
462
+ # (ADR-0107). Use the instance method form for an engine-local filter.
434
463
  def self.add_filter(name, &blk)
435
464
  @@class_filters[name.to_s] = blk
465
+ @@class_registry_version += 1
436
466
  end
437
467
 
438
468
  # Register a custom test on the class registry only.
@@ -441,6 +471,7 @@ module Tina4
441
471
  # the static-facade pattern.
442
472
  def self.add_test(name, &blk)
443
473
  @@class_tests[name.to_s] = blk
474
+ @@class_registry_version += 1
444
475
  end
445
476
 
446
477
  # Register a global variable on the class registry only.
@@ -451,6 +482,11 @@ module Tina4
451
482
  @@class_globals[name.to_s] = wrap_global(value) # ADR-0085
452
483
  end
453
484
 
485
+ # A snapshot of the class-level globals (registered via Frond.add_global).
486
+ def self.class_globals
487
+ @@class_globals.dup
488
+ end
489
+
454
490
  # Wrap a bare zero-argument Proc/lambda/Method so a bare reference to it
455
491
  # auto-calls (ADR-0085). Node auto-calls any function reached by a bare
456
492
  # reference and uses the return value; Ruby stored the proc instead, so
@@ -484,6 +520,7 @@ module Tina4
484
520
  # Updates this instance's live filter map only. Class calls remain the
485
521
  # process-global registration path. tina4: ADR-0052.
486
522
  def add_filter(name, &blk)
523
+ @local_filters[name.to_s] = blk
487
524
  @filters[name.to_s] = blk
488
525
  self
489
526
  end
@@ -492,6 +529,7 @@ module Tina4
492
529
  #
493
530
  # Updates this instance's live tests map only.
494
531
  def add_test(name, &blk)
532
+ @local_tests[name.to_s] = blk
495
533
  @tests[name.to_s] = blk
496
534
  self
497
535
  end
@@ -1882,6 +1920,10 @@ module Tina4
1882
1920
  result = eval_function_call(expr, context)
1883
1921
  return remember_form(expr, :function, result) unless result == :not_function
1884
1922
 
1923
+ # A call to a name that is not callable YET is not pinned as :resolve: a
1924
+ # global registered after this render must still be called next time.
1925
+ return resolve(expr, context) if expr.match?(FUNC_CALL_RE)
1926
+
1885
1927
  remember_form(expr, :resolve, nil)
1886
1928
  resolve(expr, context)
1887
1929
  end
@@ -3381,22 +3423,22 @@ module Tina4
3381
3423
  # -----------------------------------------------------------------------
3382
3424
 
3383
3425
  def register_builtin_globals
3384
- @globals["form_token"] = ->(descriptor = "") { Frond.generate_form_token(descriptor.to_s) }
3385
- @globals["formTokenValue"] = ->(descriptor = "") { Frond.generate_form_token_value(descriptor.to_s) }
3386
- @globals["form_token_value"] = ->(descriptor = "") { Frond.generate_form_token_value(descriptor.to_s) }
3387
- @globals["range"] = ->(start, finish, step = 1) { Frond.frond_range(start, finish, step) }
3426
+ @builtin_globals["form_token"] = ->(descriptor = "") { Frond.generate_form_token(descriptor.to_s) }
3427
+ @builtin_globals["formTokenValue"] = ->(descriptor = "") { Frond.generate_form_token_value(descriptor.to_s) }
3428
+ @builtin_globals["form_token_value"] = ->(descriptor = "") { Frond.generate_form_token_value(descriptor.to_s) }
3429
+ @builtin_globals["range"] = ->(start, finish, step = 1) { Frond.frond_range(start, finish, step) }
3388
3430
 
3389
3431
  # Debug helper: {{ dump(x) }} — gated on TINA4_DEBUG=true.
3390
3432
  # Both this global and the |dump filter call Frond.render_dump which
3391
3433
  # returns an empty SafeString in production so dump never leaks state.
3392
- @globals["dump"] = ->(value = nil) { Frond.render_dump(value) }
3434
+ @builtin_globals["dump"] = ->(value = nil) { Frond.render_dump(value) }
3393
3435
 
3394
3436
  # CSP nonce: {{ csp_nonce() }} returns the current response's nonce so a
3395
3437
  # template can serve an inline <style>/<script> under the strict default
3396
3438
  # Content-Security-Policy — <style nonce="{{ csp_nonce() }}">. The value
3397
3439
  # matches the 'nonce-X' the security middleware puts in the CSP header
3398
3440
  # (ADR-0088).
3399
- @globals["csp_nonce"] = -> { Tina4::Csp.current_nonce }
3441
+ @builtin_globals["csp_nonce"] = -> { Tina4::Csp.current_nonce }
3400
3442
  end
3401
3443
 
3402
3444
  # Render a value as a pre-formatted inspect() wrapped in <pre> tags.
@@ -6,6 +6,8 @@
6
6
  # file, You can obtain one at https://mozilla.org/MPL/2.0/.
7
7
 
8
8
 
9
+ require "socket"
10
+
9
11
  module Tina4
10
12
  # Identity-checked port takeover, shared by the CLI and the runtime paths.
11
13
  #
@@ -153,21 +155,43 @@ module Tina4
153
155
  []
154
156
  end
155
157
 
156
- # Reclaim *port* ONLY from an identity-confirmed Tina4 dev server. The single
157
- # guarded path for both the CLI (`tina4 serve`) and the runtime bind-failure
158
- # fallback. `dev`/`no_takeover` are passed in so this stays pure and directly
159
- # testable; callers resolve them from #dev? / #no_takeover_opted_out?.
160
- def take_over_port(port, dev:, no_takeover:, base_dir: nil, grace: 0.5)
158
+ # True when a plain TCP listener on *host*:*port* binds right now. TCPServer
159
+ # sets SO_REUSEADDR off Windows only, as the server's own bind does.
160
+ def bindable?(host, port)
161
+ TCPServer.new(host, port).close
162
+ true
163
+ rescue StandardError
164
+ false
165
+ end
166
+
167
+ # The result to return before any holder lookup, or nil to carry on.
168
+ #
169
+ # Takeover is refused when opted out or outside dev mode. Before a bind, the
170
+ # caller passes the host it will bind: if that bind succeeds, nothing holds
171
+ # the port, so there is nothing to refuse and nothing to say.
172
+ def refusal(port, dev, no_takeover, host)
173
+ return nil if dev && !no_takeover
174
+ return Result.new(NOTHING, port, [], "") if host && bindable?(host, port)
175
+
161
176
  if no_takeover
162
177
  return Result.new(REFUSED_OPTOUT, port, [],
163
178
  "Port #{port} is in use and takeover is disabled " \
164
179
  "(TINA4_NO_TAKEOVER/--no-kill) -- free it or choose another port.")
165
180
  end
166
- unless dev
167
- return Result.new(REFUSED_PROD, port, [],
168
- "Port #{port} is in use; takeover is disabled outside dev mode " \
169
- "-- free it or choose another port.")
170
- end
181
+ Result.new(REFUSED_PROD, port, [],
182
+ "Port #{port} is in use; takeover is disabled outside dev mode " \
183
+ "-- free it or choose another port.")
184
+ end
185
+
186
+ # Reclaim *port* ONLY from an identity-confirmed Tina4 dev server. The single
187
+ # guarded path for both the CLI (`tina4 serve`) and the runtime bind-failure
188
+ # fallback. `dev`/`no_takeover` are passed in so this stays pure and directly
189
+ # testable; callers resolve them from #dev? / #no_takeover_opted_out?.
190
+ # Before a bind, the caller passes the `host` it will bind, so a free port
191
+ # is reported as NOTHING rather than refused as "in use".
192
+ def take_over_port(port, dev:, no_takeover:, base_dir: nil, grace: 0.5, host: nil)
193
+ early = refusal(port, dev, no_takeover, host)
194
+ return early if early
171
195
  return Result.new(SKIPPED_CONTAINER, port, [], "") if in_container?
172
196
 
173
197
  tokens = port_holders(port)
@@ -29,7 +29,8 @@ module Tina4
29
29
  # Sync custom filters/globals from the user engine
30
30
  if @_framework_frond
31
31
  user_engine = get_frond
32
- @_framework_frond.instance_variable_get(:@filters).merge!(user_engine.instance_variable_get(:@filters))
32
+ # Instance filters only: class filters reach every engine already.
33
+ user_engine.instance_variable_get(:@local_filters).each { |name, fn| @_framework_frond.add_filter(name, &fn) }
33
34
  @_framework_frond.instance_variable_get(:@globals).merge!(user_engine.instance_variable_get(:@globals))
34
35
  end
35
36
  @_framework_frond
@@ -63,7 +63,11 @@ module Tina4
63
63
  @globals ||= { "csp_nonce" => -> { Tina4::Csp.current_nonce } }
64
64
  end
65
65
 
66
+ # Register a template global. It is also registered on the Frond class,
67
+ # so it reaches every Frond engine -- response.render's included --
68
+ # whenever that engine was built.
66
69
  def add_global(key, value)
70
+ Tina4::Frond.add_global(key, value)
67
71
  globals[key.to_s] = value
68
72
  end
69
73
 
data/lib/tina4/version.rb CHANGED
@@ -7,5 +7,5 @@
7
7
 
8
8
 
9
9
  module Tina4
10
- VERSION = "3.13.163"
10
+ VERSION = "3.13.164"
11
11
  end
data/lib/tina4.rb CHANGED
@@ -913,7 +913,17 @@ module Tina4
913
913
  # Gate 3: a database must be resolvable.
914
914
  db = Tina4.database
915
915
  unless db
916
- Tina4::Log.debug("Startup migrations skipped (no database configured)")
916
+ # Only an unset TINA4_DATABASE_URL is "no database configured". A set
917
+ # one that Database.new could not open must say so, or the operator
918
+ # chases a missing setting that is in fact present.
919
+ configured_url = ENV["TINA4_DATABASE_URL"].to_s.strip
920
+ if configured_url.empty?
921
+ Tina4::Log.debug("Startup migrations skipped (no database configured)")
922
+ else
923
+ cause = @database_setup_error ? ": #{@database_setup_error}" : ""
924
+ Tina4::Log.debug("Startup migrations skipped (database configured but could not connect to " \
925
+ "#{Tina4::DatabaseUrl.without_credentials(configured_url)})#{cause}")
926
+ end
917
927
  return
918
928
  end
919
929
 
@@ -974,19 +984,40 @@ module Tina4
974
984
  return if Tina4::Localization.translations.empty?
975
985
 
976
986
  # Don't overwrite a user-registered t() global
977
- return if Tina4::Template.globals.key?("t")
987
+ return if Tina4::Template.globals.key?("t") || Tina4::Frond.class_globals.key?("t")
978
988
 
979
- Tina4::Template.add_global("t", ->(key, **opts) { Tina4::Localization.t(key, **opts) })
989
+ # Templates call t("key") or t("key", {"name" => n}): Frond passes the
990
+ # params map positionally, so the global takes it as a positional hash.
991
+ Tina4::Template.add_global("t", lambda { |key, params = nil, locale: nil, **interpolations|
992
+ Tina4::Localization.t(key, locale: locale, **(params || {}), **interpolations)
993
+ })
980
994
  Tina4::Log.debug("Auto-wired i18n t() as template global")
981
995
  end
982
996
 
983
997
  def setup_database
984
998
  db_url = ENV["TINA4_DATABASE_URL"]
999
+ @database_setup_error = nil
985
1000
  if db_url && !db_url.empty?
1001
+ safe_url = Tina4::DatabaseUrl.without_credentials(db_url)
986
1002
  begin
987
- bind_database(Tina4::Database.new(db_url))
988
- Tina4::Log.info("Database connected: #{Tina4::DatabaseUrl.redact(db_url)}")
1003
+ database = bind_database(Tina4::Database.new(db_url))
1004
+ if database.pool
1005
+ # Pooled mode connects lazily on first use, so `connected` is true
1006
+ # before anything has connected. Say what is actually known: the pool
1007
+ # exists. Verifying a connection here would change boot behaviour
1008
+ # (an unreachable database would cost a connect timeout at boot);
1009
+ # the first query reports a failure with its cause instead.
1010
+ Tina4::Log.info("Database pool configured (#{database.pool_size} connections, " \
1011
+ "not yet connected - connects on first use): #{safe_url}")
1012
+ elsif !database.connected
1013
+ # Database.new logs-and-degrades on a failed connect instead of
1014
+ # raising, so only claim a connection the database itself reports.
1015
+ Tina4::Log.warning("Database not connected: #{safe_url}")
1016
+ end
1017
+ # A successful single connection was already logged, with this URL, by
1018
+ # Database#connect - one "Database connected" line, not two.
989
1019
  rescue => e
1020
+ @database_setup_error = e.message.to_s.gsub(db_url) { safe_url }.gsub(%r{://[^/\s@]*@}, "://")
990
1021
  Tina4::Log.error("Database connection failed: #{e.message}")
991
1022
  end
992
1023
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tina4ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.13.163
4
+ version: 3.13.164
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tina4 Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-13 00:00:00.000000000 Z
11
+ date: 2026-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sqlite3