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)
Les mainteneurs répondent en général sous 3 jours
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 28/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- typescript
- Domaine
- tooling
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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
- Branch n20/w2f-publish-guard from main at f015dae5326501ef5eb70616ac698828465b0deb.
- 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.
- 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.
- 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.
- Run the local mutation preflight on the unit delta (its own base, not main) before pushing, with no Stryker disable directive added.
- 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.
- Langage dominant
- TypeScript
- Étoiles
- 2k
- Forks
- 301
- Merge moyen
- 3 j 14 h
- PR mergées (30 j)
- 103
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de Zoo-Code-Org/Zoo-Code
-
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
Zoo-Code-Org/Zoo-Code#2773 · 1 commentaire ·
Les mainteneurs répondent en général sous 3 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Zoo-Code-Org/Zoo-Code#2717 · 1 commentaire ·
Les mainteneurs répondent en général sous 3 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 77/100
Zoo-Code-Org/Zoo-Code#2515 ·
Les mainteneurs répondent en général sous 3 jours
-
fix(scripts): stryker-diff.mjs spawns the extensionless .bin shim and cannot run on WindowsPeut-être pris @easonLiangWorldedtech l’a pris il y a 15 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Zoo-Code-Org/Zoo-Code#2514 ·
Les mainteneurs répondent en général sous 3 jours
-
[BUG] search_files hides matching text on long linesPeut-être pris @DananjayaNadun l’a pris il y a 9 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
Zoo-Code-Org/Zoo-Code#2496 · 1 commentaire · 1 personne assignée ·
Les mainteneurs répondent en général sous 3 jours
Toutes les issues de Zoo-Code-Org/Zoo-Code
Issues similaires
-
enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
ci
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
ClickHouse/clickhouse-js#1248 ·
Les mainteneurs répondent en général sous 1 jour
-
E2E: Darlehen-Test wartet auf die gebuchte Auszahlung, bevor er zur Liquiditätsvorschau wechseltOuvertetechnik
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
SR5-FoundryVTT/SR5-FoundryVTT#2162 ·
Les mainteneurs répondent en général sous 1 jour
-
enhancement good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
AhmedNAgy25/analysor#25 ·
Les mainteneurs répondent en général sous 1 jour