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 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
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時間
マージ済み PR(30日)
103

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Zoo-Code-Org/Zoo-Code のほかの issue

Zoo-Code-Org/Zoo-Code の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。