Repository navigation
fix(v2): load settings at first use, not while amber is required - #1424
Draft
crimson-knight wants to merge 4 commits into
Draft
crimson-knight wants to merge 4 commits into
crimson-knight wants to merge 4 commits into
Conversation
Amber::Pipe::Logger set Colorize.enabled from Amber.settings in its class body, so requiring amber loaded and cached the settings before an app's config/initializers could register custom sections or set Amber.path. The colorize setting now applies when the logger pipe is built and when the server starts. A compiled fixture checks that a section registered after require loads from YAML, and that require leaves Amber.settings and Amber.env unread.
Building the logger pipe or starting the server set the process-wide Colorize.enabled flag, which could reverse a color choice the app made itself. Amber::Support::LogColor now colors Amber's own log lines from the logging.colorize setting, and the logger, server and error pipe use it. A colorize: false setting keeps Amber's lines plain, and an app that disables Colorize keeps every line plain.
actions/checkout@v4 and oprypin/install-crystal@v1 were movable refs that their owners can repoint. Each is now pinned to the commit its ref points to today (checkout v4.4.0, install-crystal v1.9.4), so CI runs the same code as before.
ClientReload now colors its log lines through LogColor, and the EncryptionKeyMissing message is plain text, so logging.colorize: false leaves no ANSI codes in Amber's output. The require-time settings spec needs CRYSTAL or crystal-alpha to build its fixture; CI sets CRYSTAL to the compiler that runs the suite.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed and why
In 2.0.0-beta.5,
require "amber"readAmber.settingsand cached it. The read was in the class body ofAmber::Pipe::Logger:Colorize.enabled = Amber.settings.logging.colorize. Settings were therefore loaded before an app'sconfig/initializerscould callAmber::Configuration.register. A compiled probe in a generated sqlite app showed the result: the registered custom section came back missing, and only a forced reload returned its YAML value. The early read also locked inAmber.pathandAmber.envbeforeconfig/application.crcould set them.logging.colorize,filterandskipwhen the pipe is built, which happens inconfig/routes.cr, after the initializers. I searched the rest ofsrc/amber/**(class bodies, constants, class property defaults, top-level code) and found no other read ofAmber.settingsorAmber.envthat runs at require time. Codex reached the same result.Colorize.enabledflag. The newAmber::Support::LogColor.paintcolors Amber's own log lines according tologging.colorize. The logger, server start, error pipe andClientReloadall use it. Withcolorize: false, Amber's lines are plain, and an app that turnsColorizeoff (for example withNO_COLOR) gets plain lines everywhere. TheEncryptionKeyMissingmessage is now plain text.spec/amber/environment/require_time_settings_spec.crcompilesspec/fixtures/require_time_settings/probe_app.crand runs it from an empty directory. The probe requiresamberandamber/testing, then setsAMBER_ENVandAmber.pathand registers a customprobesection. One example checks that the section's YAML value (from-yaml) loads. The other checks that the name and environment come from the settings path and environment the probe set after require. Either check fails if any require-time read returns. With the old class-body read restored, both examples fail (MISSING,Amber_App).spec/amber/pipes/logger_spec.crandspec/amber/support/log_color_spec.crcovercolorize: trueandcolorize: false, the default taken from settings, and the global flag staying unchanged.CRYSTALwhen it is set, and otherwise withcrystal-alpha. If neither is available, it raises a clear error. The CI spec step now setsCRYSTAL: crystal, the compiler that runs the suite there.actions/checkoutandoprypin/install-crystal(cherry-picked8b8f0a9cfrom chore(v2): clear the 25 compiler warnings so the build is GREEN #1421) so the branch passes the dependency-pin gate.Spec result
crystal-alpha spec: 2411 examples, 0 failures, 0 errors, 0 pending. The build is YELLOW, and only because of the 25 existingParams#validationdeprecation warnings that draft PR chore(v2): clear the 25 compiler warnings so the build is GREEN #1421 clears.crystal-alpha tool format --checkpasses. Ameba reports 876 findings before and after this change, none of them new.scripts/check_beta_contract.shpasses.Codex review (gpt-6-sol, xhigh, two passes)
Colorize.enabledLogColorcolors per line, and Amber never writes the global flagcolorize: truefalse,trueand default cases are covered, plus a check that the global flag is left aloneClientReloadandEncryptionKeyMissingstill colored their output directlyClientReloadusesLogColor, and the exception message is plain textcrystalCRYSTALorcrystal-alphaand gives a clear error when neither is found; CI setsCRYSTAL/logger_specto the shared routerbeginand always restoredCodex found no other require-time read of
Amber.settingsorAmber.env.Unblocks
AMBER_overrides for custom sections depend on.config/application.crloadsconfig/initializersfirst. That load order only works oncerequire "amber"stops loading settings.