write_to_file publishes its own whole-file read as never-read, and drops the approved outside-workspace identity (split unit planned from pull 2444)

未关闭
#2,459 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
28/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript
领域
tooling

调研方向

Start in src/core/tools/WriteToFileTool.ts, where the prevent-focus arm reads the whole file without recording an observation and both publish calls (saveDirectly, saveChanges) use the old argument lists. Then read src/core/tools/guardedWrite.ts (the never-read branch) and the parameter handling in src/integrations/editor/DiffViewProvider.ts. Done means the new spec writeToFileTool.guardedPublish.spec.ts fails before the change and passes after, asserting the publish arguments and the recorded observation.

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

描述

What the code prints

At head 8948d9a30d4865cc6cd955144debf7f94735453d, src/core/tools/WriteToFileTool.ts still publishes with the pre-guard argument lists: saveDirectly is called with five arguments at line 135 and saveChanges with two at line 167, so the guarded kinds and the approved-target arguments stay defaulted.

  • The prevent-focus arm reads the whole file itself at line 114 and records no observation. guardedWrite therefore finds obs undefined and takes its never-read branch (src/core/tools/guardedWrite.ts lines 674-682, createIfAbsent): it refuses a target that this very arm had just read end to end. The arm holds the complete content and the guard is told nothing about it.
  • Neither arm threads the approved outside-workspace identity that saveChanges (src/integrations/editor/DiffViewProvider.ts lines 530-541) and saveDirectly (lines 1689-1704) exist to receive, while the tool computes isOutsideWorkspace at line 88 and puts it only into the approval payload at line 94.
  • The diff-view arm behaves as designed and is not part of this unit: open() records a partial preview observation only when none exists (DiffViewProvider.ts 203-206) and a verified empty placeholder as complete (239-259), so a never-read existing file correctly gets the re-read remediation and a new file publishes against the placeholder token.

Measured size of the fix

32 changed executable lines in package extension, measured with the repo gate's own function (scripts/stryker-diff.mjs buildManifest over the drafted working-tree diff; 49 raw lines added, 4 deleted). The ceiling is 500 changed executable lines per package. Drafted source is preserved in the lane capture at .tmp-n202237-cutshape/sec83/WriteToFileTool-draft.ts.

This is why the fix is a unit of its own rather than a commit on pull 2444: that pull is priced by the hosted gate itself at 1315 changed executable lines (log line of job 132565556554) against the 500 ceiling, so the gate refuses there whatever this delta is, and carrying it would buy the change no mutation proof. On its own branch the delta is 32 of 500 and the gate can run on it.

Plan for the unit

  1. Branch n20/w2f-publish-guard from main at f015dae5326501ef5eb70616ac698828465b0deb.
  2. src/core/tools/WriteToFileTool.ts: bracket the prevent-focus arm's whole-file read with stats and record it as a complete observation only while the bracketing stats agree; name the guarded kind the operation is (update for an existing target, create for an absent one); capture canonicalizeForApproval before the ask for an outside-workspace target and thread it, plus the approved flag, into both publish arms. No knob, no suppression, no directive.
  3. Add the regression spec at the lowest layer that would have failed: src/core/tools/tests/writeToFileTool.guardedPublish.spec.ts, asserting the arguments the two publish calls receive and the observation the prevent-focus arm records - not merely that a method was called.
  4. Prove both directions: the new spec red at the pinned head blob, green with the fix; counts printed by each run with the transcripts named and the on-disk hash of the pinned source captured before the run starts.
  5. Run the local mutation preflight on the unit delta (its own base, not main) before pushing, with no Stryker disable directive added.
  6. Lint with the shared prune switch left off from a real pnpm install --frozen-lockfile, prove src/eslint-suppressions.json byte identical to its blob, add no changeset and no changelog entry per AGENTS.md.

Gaps this unit does not claim to close

  • Host scenario: no recorded extension-host scenario exercises the refusal. Both recorded write_to_file scenarios create new files (fixture ids call_write_to_file_create_001 and call_write_to_file_nested_001, expected payload fragments "operation":"created"), so a green host run on that suite shows no regression and does not clear the refusal path. A host scenario that overwrites an existing file would have to be written and is not claimed here.
  • Assertion hole, the same one apply_diff had before its own spec: src/core/tools/tests/writeToFileTool.spec.ts asserts only that saveChanges was called (expect(mockCline.diffViewProvider.saveChanges).toHaveBeenCalled()) and never reads its arguments, so it passes identically with and without the fix.

Where this came from

Named for provenance, with no verdict asked of anyone: pull 2444 (https://github.com/Zoo-Code-Org/Zoo-Code/pull/2444) is where this class of defect was found while repairing that pull's red required leg e2e-mock; the sibling tool was named there and left unfixed. Queue rows q4352 (this unit) and q4344 (the 2444 leg) carry the lane records.

主要语言
TypeScript
星标
2k
派生
301
平均合并
3 天 14 小时
30 天内合并 PR
103

环境准备

从这里开始

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

Zoo-Code-Org/Zoo-Code 的其他 Issue

查看 Zoo-Code-Org/Zoo-Code 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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