Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

refactor(config): drop unused safeParse wrappers and stale Zod comments in config/schema.ts

已关闭
#740 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@JoshMock 已经在做这个了。

开始于 2026年10月16日。

  • #777 来自 @JoshMock —— 未关闭

评估

难度
3/5
预计耗时
半天
新手友好度
62/100
Issue 类型
重构
描述清晰度
基本清楚
活跃度
活跃
技术栈
typescript
领域
cli

调研方向

Start by running rg for the five unused exports (ApiKeyAuthSchema, BasicAuthSchema, AuthSchema, ServiceBlockSchema, ConfigFileSchema) in src/config/schema.ts to confirm only tests use them, then run rg -i zod src to find the stale comments in loader.ts, ajv-validate.ts, json-schema-args.ts, namespaces.ts and factory.ts. Done means the wrappers and their tests are removed with a justification, the post-checks live only in ContextSchema, rg -i zod src is empty, and npm test and npx tsc --noEmit pass. Leave the strip* helpers and additionalProperties alone, since #716 covers them.

由索引模型根据 Issue 内容生成。

描述

Stale

Summary

src/config/schema.ts exports five ajv-backed safeParse wrappers that nothing in src/ calls. Only tests use them. Several comments across src/ also still describe validation as Zod-based, but zod has been removed from the project.

Unused exports (current main):

  • ApiKeyAuthSchema (line 306)
  • BasicAuthSchema (line 316)
  • AuthSchema (line 326)
  • ServiceBlockSchema (line 335)
  • ConfigFileSchema (line 402)

Production code uses only StructuralConfigSchema (loader.ts, completion/complete.ts, completers/context-names.ts), ContextSchema (loader.ts, config/commands.ts) and CommandPolicySchema (loader.ts, completion/complete.ts).

ConfigFileSchema also duplicates the three per-context post-checks from ContextSchema, with different wording:

  • At least one service block: ContextSchema line 382-383 vs ConfigFileSchema line 426-427 ("at least one service block required").
  • contextUrlErrors: line 385 vs line 429.
  • contextVersionErrors: line 387 vs line 431.

These were around lines 378-385 and 431-440 in an earlier revision.

Stale Zod comments:

  • src/config/loader.ts:14: "Validate active context with full Zod schemas"
  • src/lib/ajv-validate.ts:7
  • src/lib/json-schema-args.ts:9
  • src/namespaces.ts:107
  • src/factory.ts:737

Proposal

  1. Delete the five unused wrappers and their tests. Deleting ConfigFileSchema removes the duplicated post-checks, so ContextSchema becomes their single home.
  2. Update the Zod comments so they describe the current ajv/JSON Schema behaviour.

The PR must explicitly justify deleting the tests for the removed wrappers: they cover only code being removed, and the behaviour that remains is still covered through ContextSchema/StructuralConfigSchema.

Out of scope: deferred to #716 (design decision 1)

This issue does not cover replacing the strip* helpers (schema.ts ~238-298, plus the ! assertions on their results) with ValidateFunction<T> type guards, or adding additionalProperties: false. Either change would alter behaviour. Today unknown config keys are silently stripped (schema.ts:137: "no additionalProperties — we strip manually"). A type guard would pass them through, and additionalProperties: false would reject them, which would break existing configs that have extra keys. Both options also overlap with #716's raw-shape plus per-field leaf validator split, which reshapes ContextSchema, contextUrlErrors, contextVersionErrors and the strip* helpers. Decide them there.

Acceptance criteria

  • ConfigFileSchema, AuthSchema, ApiKeyAuthSchema, BasicAuthSchema and ServiceBlockSchema are removed, or any that stay have a documented reason.
  • The three per-context post-checks exist only in ContextSchema.
  • No comment in src/ refers to Zod (rg -i zod src is empty).
  • The PR justifies each deleted test.
  • No behaviour change: unknown keys are still stripped, and npm test and npx tsc --noEmit pass.

Related

  • #716 (design decision 1: the strip*/type-guard and unknown-key handling is deferred there)

authored by Pi Coding Agent (Claude Opus)

主要语言
TypeScript
星标
51
派生
27
平均合并
22 小时 48 分钟
30 天内合并 PR
48

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

elastic/cli 的其他 Issue

查看 elastic/cli 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。