refactor(config): lazy lookup interface for @elastic/config-resolver
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
- issue の種類
- リファクタリング
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- typescript
調査の方向性
Start with the suggested TDD order: inspect the @elastic/config-resolver entry point and its tests, then review loader.ts, schema.ts, factory.ts, and extension/context.ts. Run the existing config tests to identify eager-resolution assumptions, including the skipContextResolve and resolveHelpConfig paths. Done means lazy memoized access, preserved validation and error codes, updated clients and tests, and passing npm test and lint.
索引モデルが issue の本文から書いたものです。
説明
Summary
Refactor @elastic/config-resolver to expose a lazy, memoized lookup interface, and move the CLI's resolve-then-validate logic (resolveExpressions + post-resolution ContextSchema validation + the skipContextResolve special case) behind it. This is a standalone refactor of that library and the CLI code that consumes it; it is not tied to any feature work.
Motivation
Today loadConfig resolves every expression in the active context up front (resolveExpressions deep-walks the whole context and commands), then validates the resolved result with ContextSchema. That is all-or-nothing, and it has accumulated workarounds:
elastic es searchstill runs every$(cmd:...)/$(pass:...)in thekibanaandcloudblocks, even though onlyelasticsearchis used.- Command registration and
--helponly needelasticsearch.version/kibana.versionand the command policy. To avoid resolving secrets there (#706) we addedskipContextResolve, a cache exception, and a separate fast path inloader.ts(resolveHelpConfig) that reads raw YAML and skips validation. - That fast path reads
versionunresolved, soversion: $(env:ES_VERSION)is silently ignored when filtering help. - The
preActionhook resolves secrets before--dry-runis considered, so a dry run still spawns secret subprocesses.
Lazy per-field lookup removes the need for the special case and fixes the above.
Proposal
Add a lazy accessor to @elastic/config-resolver:
createLazyConfig(raw: object, opts?: {
leafValidators?: Record<string, (value: string) => string | undefined>
}): {
get(path: readonly string[]): string | undefined // resolve + validate leaf + memoize
peek(path: readonly string[]): unknown // raw, unresolved
}
- Array paths, not dotted strings (context names can contain dots).
- Memoized per path; concurrent
gets of the same path share one resolution. - Keep the existing
__proto__/constructorguard. - Errors keep the field path in the message, and the CLI maps them to the existing
config_unresolvederror.code(the code catalog is frozen).
CLI side:
loadConfigkeeps file discovery, YAML parsing, structural validation, context selection, profile precedence and the inline-secret permission warning. Only the resolve + validate steps and the result cache move behind the lazy accessor.ResolvedConfigbecomes a thin facade overget.- Delete
skipContextResolve,resolveHelpConfigand the associated cache exception.
Design decisions to settle
- Post-resolution validation.
ContextSchemacurrently validates the resolved context (e.g. URL scheme), sourl: $(cmd:...)could not pass it unresolved. This needs two layers: a raw-shape check that accepts expression strings, plus per-field leaf validators applied when a value is read (the URL scheme and non-empty rules currently inschema.ts). This is the largest piece of work. - Sync vs async. All seven built-in resolvers are synchronous (
execSync/readFileSync), butResolverFnallows promises. An asyncget()would makegetEsClient,getCloudClientandgetKbClientasync and ripple intofactory.ts. NarrowingResolverFnto sync would letResolvedConfigkeep its current shape with memoized lazy getters on secret-bearing leaves, so consumers would not change. The package isprivateat 0.1.2, so that break is cheap, but it drops async custom resolvers. Proposal: start sync. - Failure timing. A bad expression currently fails the command up front. Lazily it fails when the value is first read, inside the handler. Existing tests pin the old timing (e.g. "still fails when the active context has an unresolvable expression" in
test/config/loader.test.ts) and would need rewriting, each change called out explicitly. - Enumeration safety. A lazy config object must not fire every resolver (or leak values) when serialized or spread. Audit
status, theconfigcommands, andextension/context.ts(which referencesResolvedConfig; changing its shape may be an extension-facing API change). commandspolicy. Currently resolved like everything else; becomes a lazyget(['commands']).
Out of scope
- Moving file discovery, YAML/JSON parsing, structural validation, profile precedence or the permission warning out of the CLI. Only about a third of
loader.tsis affected. - Any startup-performance claim. The help-path ajv/YAML cost is already addressed separately; this refactor simplifies that code but is not expected to make it faster.
Suggested order of work (TDD)
- Lazy accessor in
config-resolverwith tests for memoization, concurrent access, error paths (field path preserved), and the prototype guard. - Leaf validators covering the rules
ContextSchemaenforces after resolution. - Switch
loadConfigand the three clients over; deleteskipContextResolveandresolveHelpConfig. - Rewrite tests that pin eager semantics, listing each change with justification.
Acceptance
- Reading
elasticsearch.*never runs resolvers forkibana.*orcloud.*. --helpand--dry-runnever run a secret resolver.version: $(env:...)is honoured for availability filtering.config_unresolvedis still emitted for unresolvable expressions, and no newerror.codestrings are introduced.npm testand lint pass; startup perf baselines are not regressed.
authored by Pi Coding Agent (Claude Opus 4.8)
- 主要言語
- TypeScript
- スター
- 49
- フォーク
- 27
- 平均マージ
- 1日 23時間
- マージ済み PR(30日)
- 67
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
elastic/cli のほかの issue
-
feat: ship skills/elastic/SKILL.md for agent invocation対応中かも @onatozmenn が 21 日前に担当しました。 オープンenhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 38/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 58/100
メンテナーはふだん 1 日以内に返信
-
refactor(config): drop unused safeParse wrappers and stale Zod comments in config/schema.ts対応中かも @JoshMock が 2 日前に担当しました。 オープン
難易度 3/5 半日 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
bug priority: P2
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
wayfinder:task
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
bug customer-reported data-plane question Service Attention Storage
難易度 2/5 1〜3時間 初心者へのやさしさ 69/100
Azure/azure-rest-api-specs#47397 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Claude thinking budget can shrink capped Haiku responses to 2,048 tokens対応中かも @DavyMassoneto が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
diegosouzapw/OmniRoute#17109 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
paperclipai/paperclip#16785 ·
メンテナーはふだん 1 日以内に返信