Skip to content

refactor(config): compile config patterns once, type settings secrets, trim cache checks - #358

Merged
sweepies merged 11 commits into
mainfrom
refactor/simplify-config
Nov 22, 2026
Merged

sweepies merged 11 commits into
mainfrom
refactor/simplify-config

Conversation

@sweepies

@sweepies sweepies commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Simplification pass over crates/config (settings included) and crates/cache. The items come from the review of cache, config, report, process and testkit (items 2–6, 11 and 12).

Done

  • Patterns, filters and regexes are compiled when the config is read (item 2). Pattern/Patterns, Filter and ConfigRegex deserialize straight from the config text and keep it. Serializing writes that text back, so the serialized config (which the engine hashes for its extraction cache) stays byte-for-byte the same. serialized_configs_keep_their_bytes checks this for every example and for a config that sets each compiled field, against crates/config/tests/config-serialized.txt. That file was recorded from the previous build. Errors keep their field paths, such as rules[0].select.packages[1]: invalid regex: …, and compile_errors_name_the_field_path checks this. Validation no longer compiles each pattern just to throw it away. Lookup's CompiledRule and its Evaluator fields are gone, the scanner reads files/exclude straight from the config, custom extractors use the compiled regexes, and the report reads quietImages directly instead of calling .ok(). The is_ok_and path in custom.rs is gone. It skipped an extractor whose paths did not compile. Validation already rejected that case, and now the type cannot hold it at all.
  • Typed registry auth and secrets (item 3). Registry.auth is Option<RegistryAuth>, where Basic { username, secret } or Bearer { secret }. Secret is Env(name) or File(path). Both are built through try_from from the Pkl shape. "Exactly one secret source" and "username only for basic" can no longer be represented, so Secret::source, read_bytes_with, the engine's credentials (and its "secret is missing" case) and the CLI server's secret helper stop handling shapes that were already refused. Security: the same entries are refused as before. The rules now hold by construction, which is strictly stronger. Wording change: a shape problem is now reported at the registry's path, for example registries.<key>: username is required for basic registries, …, instead of registries["<key>"].username …. The settings diagnostic still masks the quoted key.
  • One Registry variant for a named registry (item 4). Registry::Url and Registry::Unusable were told apart on read-back by the same check producers apply. The one reader, the datasource lookup, treated both alike and checks the value itself, so they merge into Registry::Named. Serialization is unchanged (the recorded string). The URL check moves into the manager's registry_url, its only user. Ord loses the kind tiebreak, because the indexes tiebreak already keeps it consistent with Eq.
  • One evaluator over supplied files (item 5). load_files puts the bundled schema beside the entry when the supplied files leave it out. The evaluator then serves its map and nothing else, for repository configs and local settings alike. The local flag and its /repo prefix check go. Security: unchanged. The evaluator never reads the host filesystem, so a path outside the map was already unreadable. Imports are still confined by import_files.
  • Settings::default() evaluates the bundled PatchulaSettings.pkl (item 6) instead of keeping a hand-written copy of its defaults. A CLI run without a settings file now does one Pkl evaluation.
  • Cache writer loop (item 11): the per-job conn.path() check is dropped. Only call() recovers the store, and it clears readers_valid before it does.
  • plain() accepts + (item 12). Migration 014 runs once, before any write, on caches older than version 14, so a + written later is never deleted.

The code-versioned states whose hashed sources this touches are bumped in tests/state-versions.tsv and tests/derived-versions.tsv.

Dropped

  • Item 1 (cache release-history store): not dead. crates/datasource/src/github.rs uses merge_release_page and releases.

Follow-ups

  • Evaluator::new and Scanner::new can no longer fail but still return Result. Changing that touches about 280 call sites in crates other open PRs are editing, so it is left for after they land.

Notes

  • New clippy.toml: it tells mutable_key_type to ignore Pattern. Pattern compares and orders by its text alone, so the regex's internal cache never affects a quietImages key.
  • Tested on the VM: cargo test --workspace passes, cargo clippy --workspace --all-targets -D warnings is clean, and the state/derived parity checks pass.

View guided diff Turn on auto-fix

After review

An adversarial review confirmed every security property but found two diagnostic regressions. Both came from moving map-entry checks into serde: serde_path_to_error splits a map key at its dots, and the diagnostic highlights the path's last dotted part.

  • Registry shape errors. The path became registries.https://npm.acme.dev. Nothing was highlighted, or for a host ending in .tools the caret landed on another entry's tools = true. The settings masking also hid which registry was meant. Field paths are now built from the error's segments, so a registry key reads registries["https://npm.acme.dev/"]: its scheme, host, port and path when it parses as an http(s) URL without a user or password, and [redacted] otherwise. The diagnostic leaves only http(s) URLs with no user, password, query or fragment unmasked; everything else is still masked. A username or secret problem names that property again (registries["…"].username is required …), as before this PR. Tests: a_registry_problem_names_and_points_at_its_registry covers the .tools host, naming the registry, and a key with a user and password staying redacted.
  • security.quietImages key errors. The path became security.quietImages.<pattern>, and [unclosed.images highlighted images = true. Map keys now format as security.quietImages[<key>]. The property to highlight is the last name outside any bracketed key, so this case highlights quietImages. Test: a_bad_quiet_image_key_points_at_quiet_images.

The parity hashes are updated for the changed crates/config/src; versions were already bumped in this PR. Tested on the VM: config, engine, cli and server tests pass, workspace clippy with -D warnings is clean, and parity passes.

plain() rejected + so no new key could look like the retired per-build
keys migration 014 deletes. That migration runs once, before any write,
on caches older than 14, so a + written later is never deleted.
Only call() recovers the store, and it clears readers_valid before it
does, so the writer loop's per-job connection path check never fired.
Registry::Url and Registry::Unusable were told apart on read-back by the
same check producers apply, and the one reader (the datasource lookup)
treats both alike, re-checking the value itself. They become
Registry::Named; the URL check moves to the manager, its only user, and
Ord drops the kind tiebreak, which the indexes already cover.
load_files puts the bundled schema beside the entry when the files leave
it out, so the evaluator serves its map and nothing else for repository
configs and local settings alike; the local flag and its /repo check
go. A path outside the map was already unreadable: the evaluator never
touches the host filesystem.
The hand copy of PatchulaSettings.pkl's defaults goes; a settings-less
CLI run evaluates the schema once instead.
A registry entry and its secret are read through try_from into enums:
basic carries its username and secret, bearer only a secret, and a
secret is either an environment variable or a file. Exactly one secret
source and a username only for basic can no longer be represented, so
Secret::source, read_bytes_with and the engine's credentials stop
handling the shapes the settings check refused. A shape problem now
reads as the registry's path and what is wrong with it.
Settings diagnostics mask quoted values, the registry key among them.
Config fields holding patterns, version filters and extractor regexes
deserialize straight into compiled Pattern, Patterns, Filter and
ConfigRegex values that keep their text, which is how they serialize.
A bad one is reported at its field path (rules[0].select.packages[1])
as the config is read, so validation stops compiling each one only to
throw it away, and the lookup evaluator, the scanner, custom extractors
and the report stop compiling them again: lookup's CompiledRule goes,
and the extractor path check that silently skipped an invalid pattern
is gone with the compile it guarded. The serialized config, which keys
the extraction cache, is byte-for-byte what it was; a test pins it for
every example against bytes recorded from the previous build.
Pattern compares and orders by its text alone, so the regex's internal
cache never affects a quietImages key; clippy.toml says so.
Since map entries are checked as they deserialize, serde's error path
split a map key at its dots, so a registry or quietImages problem
highlighted whatever the key's last dotted part spelled (a host ending
in .tools pointed at another entry's tools) and the settings masking
hid which registry it was. Paths are now built from the error's
segments: a registries key reads registries["https://host/path"] (its
scheme, host, port and path; [redacted] when it carries a user or does
not parse), a quietImages key reads security.quietImages[key], and the
property to highlight is the last name outside any bracketed key. A
registry's username or secret problem names that property again.
@sweepies
sweepies force-pushed the refactor/simplify-config branch from 7e4aebf to be34fa3 Compare November 22, 2026 20:50
@sweepies
sweepies merged commit 2117118 into main Nov 22, 2026
12 checks passed
@sweepies
sweepies deleted the refactor/simplify-config branch November 22, 2026 20:58
@sweepies-ops sweepies-ops Bot mentioned this pull request Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant