Skip to content

chore: compare lint guard JS plugins regardless of their order - #5249

Merged
RealKai42 merged 1 commit into
mainfrom
chore/guards-jsplugins-order
Nov 23, 2026
Merged

RealKai42 merged 1 commit into
mainfrom
chore/guards-jsplugins-order

Conversation

@RealKai42

Copy link
Copy Markdown
Collaborator

Requirement or Bug

在有的检出目录里,pnpm lint 会在 guards 这一步失败,报 changed: jsPlugins changed,但 .oxlintrc.json 和快照都没改。仓库要求结束改动前 pnpm lint 必须以 0 退出,所以在这些目录里工作的人和 agent 都会被挡住,还容易误用 --update 改写快照来绕过。这个 PR 之后,guards 的结果不再取决于在哪个目录里运行。

Bug Reproduction Steps

  1. 同一份提交、同一个 oxlint 1.94.0,在两个检出目录里分别运行 pnpm exec oxlint --type-aware --print-config。两边打印出的 jsPlugins 顺序不同;在同一个目录里多跑几次,结果一致。
  2. 在顺序和快照相反的那个目录里运行 node scripts/checks/guards.mjs:报 jsPlugins changed,以 1 退出。

Root Cause

guards 把 jsPlugins 当成普通字段,用 JSON 字符串整体比较,数组顺序一变就算改动;--update 也照 oxlint 打印的顺序写快照。但 oxlint 打印 jsPlugins 的顺序随检出目录变化,并不一定是配置里写的顺序,所以快照只在和生成它的目录顺序相同的地方才能通过。

这是根本修复:比较和写快照都不再依赖这个顺序。

Code Changes

  • diffConfigs 把 jsPlugins 和 plugins 一样按成员比较:只是顺序不同不报;删掉一个插件报 weakened,新增一个报 changed。
  • 新增 normalizeConfig:读取生效配置时先给 jsPlugins 排序,所以 --update 在任何目录写出的快照都一样。它是 readEffectiveConfig 里不调用 oxlint 的那部分,拆出来是为了能写单元测试。
  • 快照按排序后的顺序重写。只有这两行互换了位置,规则没有任何变化。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
JS 插件只是顺序不同 报 changed: jsPlugins changed,lint 失败 不报 无;受影响的是在顺序和快照相反的目录里跑 lint 的开发者和 agent 无
删掉或新增 JS 插件 报 changed: jsPlugins changed 删掉报 weakened: JS plugin removed: <路径>,新增报 changed: JS plugin added: <路径>,lint 仍然失败 评审 lint 配置改动的人 无
--update 写出的快照 按 oxlint 打印的顺序 按排序后的顺序 更新快照的人 无

测试:scripts/checks/guards.test.mjs 新增 3 条:只换顺序时不报差异;增删插件时的报法;normalizeConfig 的结果不随打印顺序变化。前两条在修复前失败,报的就是 jsPlugins changed;第三条在去掉排序后失败。

验证(macOS)
  • node --test 'scripts/checks/*.test.mjs':60 条全部通过。
  • pnpm lint:在顺序和原快照相反的检出目录里以 0 退出,修复前在 guards 这一步失败。
  • 在另一个顺序和原快照相同的检出目录里,换上新脚本和新快照后,guards 通过,--update 写出的快照和这里逐字节相同。

只改仓库脚本、测试和快照,不需要 changeset。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

oxlint prints jsPlugins in an order that depends on the checkout
directory, so the guard reported "jsPlugins changed" and failed
pnpm lint in some checkouts without any config change.

Compare JS plugins as members, like plugins: a removed plugin is
reported as weakened and an added one as changed, while a different
order is not reported. Record them sorted so that --update writes the
same snapshot in every checkout, and rewrite the snapshot in that
order.
@changeset-bot

changeset-bot Bot commented Nov 23, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f926454

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T04:44:03.408112Z f926454 PR opened
🔒 Security Review ✅ Completed 2026-11-23T04:46:43.901016Z f926454 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 23, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@f926454
npx https://pkg.pr.new/@moonshot-ai/kimi-code@f926454

commit: f926454

@RealKai42
RealKai42 merged commit 6fd6f1d into main Nov 23, 2026
24 checks passed
@RealKai42
RealKai42 deleted the chore/guards-jsplugins-order branch November 23, 2026 05:12
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 25, 2026
Keep a per-step next-block cursor so an open step's content parts append
straight to the turn and only out-of-order rewrites fall back to upsert
(MoonshotAI#5344); a step with no items seeds the cursor and step.end drops it.
Compare and diff jsPlugins as sets so lint-guard configs are order
insensitive and a removed plugin reads as weakened (MoonshotAI#5249). Ledger: 5015
equivalent.
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