Skip to content

Commit 06eea06

Browse files
phase3devclaude
andcommitted
fix(launcher): adopt legacy unmarked context-icon patch; Windows precise walk-up
Codex audit follow-ups, folded into the reconcile mechanism so md-copy builds on a clean base. Finding 1 (legacy bare-101): the old launcher/standalone wrote a bare, unmarked `>=101)return null}`. The marker-only undo treated that as foreign, so every default launch warned "context-icon anchor not found (extension changed?)" and `CC_PATCH_CONTEXT_ICON=0` could not revert it (breaking the migration table). undo now recognizes the bare form as a second ownership fingerprint (`>=101` is dead upstream code, so it only ever appears as our own output). A legacy bundle now self-heals: a default launch reverts bare -> `>=50` then re-applies the marked form, capturing the correct pristine snapshot, with no warning; a disabled launch reverts cleanly. The genuine "extension changed" warning still fires for an unrecognized bundle. Finding 2 (Windows precise discovery): reconcile was called with only wrapperBin, ignoring the resolved `claude` (CLAUDE_REAL_BIN / autodetected). An extension whose root sits outside the HOME fallback scan was left unpatched on a terminal launch, contradicting the documented discovery model and bash's walk from REAL_CLAUDE. Now reconcile(wrapperBin || claude), at parity with bash. Tests: replace the obsolete "bare-101 is upstream" assertion with legacy adoption + stderr-quiet coverage (upgrade-when-enabled, revert-when-disabled, revert-by-master-switch, unrecognized-still-warns) across bash and node, plus a precise-walk-up test with an extension root outside the fallback scan on both platforms. 24 -> 32 tests, all green; bash -n / shellcheck --severity=warning / node --check / py_compile clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 4d1a1ac commit 06eea06

3 files changed

Lines changed: 147 additions & 21 deletions

File tree

‎launcher/claudemax‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,9 @@ fi
212212
# Generic engine (replaces the single hard-coded context-icon sed). Each
213213
# bundle-patch feature registers, per target file, an idempotent + reversible
214214
# (apply, undo) pair. Every applied edit carries an ownership MARKER, and undo
215-
# keys off the MARKED form only, so the launcher reverses ONLY its own edits and
216-
# never touches upstream code that merely resembles a patched value.
215+
# keys off our own fingerprints (the MARKER, plus any legacy unmarked form an
216+
# older version of this tool wrote), so the launcher reverses ONLY its own edits
217+
# and never touches upstream code that merely resembles a patched value.
217218
#
218219
# Per-file reconcile (see TECHNICAL.md "patch composition"):
219220
# C = current bytes with every KNOWN feature's undo applied in REVERSE order
@@ -266,10 +267,18 @@ _cc_apply_context_icon() {
266267
}
267268

268269
_cc_undo_context_icon() {
270+
# Revert our edit to the pristine upstream form. Two ownership fingerprints are
271+
# recognized: the current MARKED form, and the legacy BARE form that older
272+
# launcher/standalone versions wrote before the marker existed. `>=101)return
273+
# null}` is dead upstream code (c maxes at 100), so it appears only as our own
274+
# output; adopting it lets a legacy install revert and upgrade cleanly instead
275+
# of warning on every launch. The MARKED substitution runs first because the
276+
# bare string is a prefix of the marked one.
269277
local f="$1" tmp
270-
if ! grep -q '/\*ccwa-context-icon\*/' "$f" 2>/dev/null; then return 0; fi # nothing of ours
278+
grep -qF '>=101)return null}' "$f" 2>/dev/null || return 0 # nothing of ours
271279
tmp="${f}.ccundo.$$"
272-
if sed 's#>=101)return null}/\*ccwa-context-icon\*/#>=50)return null}#' "$f" > "$tmp" 2>/dev/null \
280+
if sed -e 's#>=101)return null}/\*ccwa-context-icon\*/#>=50)return null}#g' \
281+
-e 's#>=101)return null}#>=50)return null}#g' "$f" > "$tmp" 2>/dev/null \
273282
&& [ -s "$tmp" ]; then
274283
cat "$tmp" > "$f" 2>/dev/null || true
275284
fi

‎launcher/claudemax.win.js‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,14 @@ if (!claude) {
238238
// routine safely no-ops until the anchor here is updated.
239239
const ICON_OLD = ">=50)return null}";
240240
const ICON_MARKER = "/*ccwa-context-icon*/";
241-
const ICON_NEW = ">=101)return null}" + ICON_MARKER;
241+
const ICON_BARE = ">=101)return null}"; // legacy unmarked form (older launcher/standalone)
242+
const ICON_NEW = ICON_BARE + ICON_MARKER;
242243

243244
// Bundle-patch feature registry. Each feature is idempotent (apply/undo are
244245
// no-ops when their target state already holds) and reversible; undo keys off
245-
// the ownership MARKER only, so it reverses ONLY our own edits. Order matters:
246-
// apply runs forward, undo runs in reverse.
246+
// our own fingerprints (the ownership MARKER, plus any legacy unmarked form an
247+
// older version wrote), so it reverses ONLY our own edits. Order matters: apply
248+
// runs forward, undo runs in reverse.
247249
function applyContextIcon(data) {
248250
if (data.indexOf(ICON_MARKER) !== -1) return data; // already applied
249251
const n = data.split(ICON_OLD).length - 1;
@@ -258,8 +260,13 @@ function applyContextIcon(data) {
258260
}
259261

260262
function undoContextIcon(data) {
261-
if (data.indexOf(ICON_MARKER) === -1) return data; // nothing of ours
262-
return data.split(ICON_NEW).join(ICON_OLD);
263+
// Revert our edit to the pristine upstream form. Two ownership fingerprints
264+
// are recognized: the current MARKED form, and the legacy BARE form older
265+
// versions wrote before the marker existed. ICON_BARE is dead upstream code
266+
// (c maxes at 100), so it appears only as our own output; adopting it lets a
267+
// legacy install revert/upgrade cleanly. Marked must go first: ICON_BARE is a
268+
// prefix of ICON_NEW.
269+
return data.split(ICON_NEW).join(ICON_OLD).split(ICON_BARE).join(ICON_OLD);
263270
}
264271

265272
function contextIconEnabled() {
@@ -442,8 +449,12 @@ if (
442449
args.push("--thinking-display", displayValue);
443450
}
444451

445-
// Reconcile the webview before handing off (best-effort; never throws).
446-
reconcile(wrapperBin);
452+
// Reconcile the webview before handing off (best-effort; never throws). Walk up
453+
// from the resolved binary - wrapperBin when the extension handed us one, else
454+
// the CLAUDE_REAL_BIN/autodetected `claude` - so an extension whose root sits
455+
// outside the HOME fallback scan is still reached (parity with the bash walk
456+
// from REAL_CLAUDE).
457+
reconcile(wrapperBin || claude);
447458

448459
const invocation = resolveClaudeInvocation(claude, args);
449460
if (!invocation) process.exit(1);

‎tests/test_reconcile.py‎

Lines changed: 116 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ def make_extension(home, content):
4747
return idx
4848

4949

50+
def make_extension_outside_scan(td, content):
51+
"""Create an extension whose root is NOT under any HOME .vscode scan dir.
52+
53+
Returns (index_js, extroot, bindir). The extension's bundled binary lives at
54+
<extroot>/resources/native-binary/, mirroring the real layout the official
55+
process-wrapper hands the launcher. Reaching this bundle requires the precise
56+
walk-up from the resolved binary path; the HOME fallback scan never sees it.
57+
"""
58+
extroot = pathlib.Path(td) / "custom-ext-dir" / "anthropic.claude-code-9.9.9"
59+
idx = extroot / "webview" / "index.js"
60+
idx.parent.mkdir(parents=True)
61+
idx.write_text(content, encoding="utf-8")
62+
bindir = extroot / "resources" / "native-binary"
63+
bindir.mkdir(parents=True)
64+
return idx, extroot, bindir
65+
66+
5067
class ReconcileMixin:
5168
"""Platform-agnostic reconcile assertions. Subclasses implement `_run`/`_captured`."""
5269

@@ -102,16 +119,55 @@ def test_master_switch_reverts_all_and_injects_nothing(self):
102119
self.assertEqual(idx.read_text(encoding="utf-8"), f"before {OLD} after")
103120
self.assertEqual(self._captured(), ["--thinking=adaptive"])
104121

105-
def test_unmarked_upstream_value_is_left_untouched(self):
106-
for env_extra in ({}, {"CC_PATCH_CONTEXT_ICON": "0"}):
107-
with self.subTest(env=env_extra):
108-
with tempfile.TemporaryDirectory() as td:
109-
home = pathlib.Path(td)
110-
original = f"keep {BARE101} this"
111-
idx = make_extension(home, original)
112-
res = self._run(td, home, env_extra=env_extra)
113-
self.assertEqual(res.returncode, 0, res.stderr)
114-
self.assertEqual(idx.read_text(encoding="utf-8"), original)
122+
def test_legacy_bare_patch_is_upgraded_to_marked_when_enabled(self):
123+
# A bundle left by the OLD launcher/standalone carries the bare,
124+
# unmarked >=101 form. `c` maxes at 100, so >=101 is dead upstream code
125+
# that only ever appears as our own output; reconcile adopts it as a
126+
# legacy fingerprint, upgrading it to the marked form and capturing the
127+
# correct pristine (>=50) snapshot - without the spurious "anchor not
128+
# found" warning the marker-only path used to emit on every launch.
129+
with tempfile.TemporaryDirectory() as td:
130+
home = pathlib.Path(td)
131+
idx = make_extension(home, f"before {BARE101} after")
132+
res = self._run(td, home)
133+
self.assertEqual(res.returncode, 0, res.stderr)
134+
self.assertEqual(idx.read_text(encoding="utf-8"), f"before {MARKED} after")
135+
self.assertNotIn("anchor not found", res.stderr)
136+
bak = idx.with_name(idx.name + BAK)
137+
self.assertTrue(bak.exists())
138+
self.assertEqual(bak.read_text(encoding="utf-8"), f"before {OLD} after")
139+
140+
def test_legacy_bare_patch_is_reverted_when_feature_disabled(self):
141+
# Migration-table promise: disabling the fix reverts our edit. A legacy
142+
# bare patch must revert to pristine just like a marked one does.
143+
with tempfile.TemporaryDirectory() as td:
144+
home = pathlib.Path(td)
145+
idx = make_extension(home, f"before {BARE101} after")
146+
res = self._run(td, home, env_extra={"CC_PATCH_CONTEXT_ICON": "0"})
147+
self.assertEqual(res.returncode, 0, res.stderr)
148+
self.assertEqual(idx.read_text(encoding="utf-8"), f"before {OLD} after")
149+
self.assertNotIn("anchor not found", res.stderr)
150+
151+
def test_legacy_bare_patch_is_reverted_by_master_switch(self):
152+
with tempfile.TemporaryDirectory() as td:
153+
home = pathlib.Path(td)
154+
idx = make_extension(home, f"before {BARE101} after")
155+
res = self._run(td, home, env_extra={"CC_WORKAROUNDS": "0"})
156+
self.assertEqual(res.returncode, 0, res.stderr)
157+
self.assertEqual(idx.read_text(encoding="utf-8"), f"before {OLD} after")
158+
159+
def test_unrecognized_bundle_warns_and_is_left_untouched(self):
160+
# The genuine "extension changed" signal must survive: a bundle with
161+
# neither our anchor nor either of our fingerprints is left untouched and
162+
# still warns (so a real upstream change is not silently ignored).
163+
with tempfile.TemporaryDirectory() as td:
164+
home = pathlib.Path(td)
165+
original = "totally unrelated minified code; return null}"
166+
idx = make_extension(home, original)
167+
res = self._run(td, home)
168+
self.assertEqual(res.returncode, 0, res.stderr)
169+
self.assertEqual(idx.read_text(encoding="utf-8"), original)
170+
self.assertIn("anchor not found", res.stderr)
115171

116172
def test_reconcile_bypass_leaves_bundle_untouched_but_still_injects(self):
117173
with tempfile.TemporaryDirectory() as td:
@@ -172,6 +228,33 @@ def test_apply_preserves_file_mode(self):
172228
self.assertEqual(res.returncode, 0, res.stderr)
173229
self.assertEqual(stat.S_IMODE(idx.stat().st_mode), 0o640)
174230

231+
def test_precise_walkup_patches_extension_outside_scan_dirs(self):
232+
# bash walks up from REAL_CLAUDE, so this already held; it guards against
233+
# regressing the precise-target path the Windows fix brings to parity.
234+
with tempfile.TemporaryDirectory() as td:
235+
home = pathlib.Path(td) / "empty-home"
236+
home.mkdir()
237+
idx, _extroot, bindir = make_extension_outside_scan(td, f"before {OLD} after")
238+
fake = bindir / "claude"
239+
fake.write_text(
240+
"#!/usr/bin/env bash\n"
241+
"python3 - \"$@\" <<'PY'\n"
242+
"import json, os, sys\n"
243+
"open(os.environ['CAPTURE_ARGS'], 'w').write(json.dumps(sys.argv[1:]))\n"
244+
"PY\n",
245+
encoding="utf-8",
246+
)
247+
fake.chmod(fake.stat().st_mode | stat.S_IXUSR)
248+
capture = pathlib.Path(td) / "args.json"
249+
env = {
250+
"HOME": str(home),
251+
"CLAUDE_REAL_BIN": str(fake),
252+
"CAPTURE_ARGS": str(capture),
253+
}
254+
res = run([str(LAUNCHER_BASH), "--thinking=adaptive"], env=env)
255+
self.assertEqual(res.returncode, 0, res.stderr)
256+
self.assertEqual(idx.read_text(encoding="utf-8"), f"before {MARKED} after")
257+
175258

176259
class WinReconcileTests(ReconcileMixin, unittest.TestCase):
177260
def _run(self, td, home, args=None, env_extra=None):
@@ -188,6 +271,29 @@ def _run(self, td, home, args=None, env_extra=None):
188271
env.update(env_extra)
189272
return run(["node", str(LAUNCHER_WIN), *(args or [])], env=env)
190273

274+
def test_precise_walkup_patches_extension_outside_scan_dirs(self):
275+
# Finding 2: when CLAUDE_REAL_BIN resolves to the extension's bundled
276+
# binary in a location the HOME fallback scan never sees, reconcile must
277+
# still patch that extension via the precise walk-up from the resolved
278+
# binary. The old code passed only wrapperBin (null on a terminal launch),
279+
# so the bundle was left unpatched; reconcile(wrapperBin || claude) fixes it.
280+
with tempfile.TemporaryDirectory() as td:
281+
home = pathlib.Path(td) / "empty-home"
282+
home.mkdir()
283+
idx, _extroot, bindir = make_extension_outside_scan(td, f"before {OLD} after")
284+
cli, capture = make_fake_node_cli(td)
285+
shim = bindir / "claude.cmd" # the extension's bundled npm-shim binary
286+
shim.write_text(f'@ECHO off\nnode "{cli}" %*\n', encoding="utf-8")
287+
env = {
288+
"HOME": str(home),
289+
"USERPROFILE": str(home),
290+
"CLAUDE_REAL_BIN": str(shim),
291+
"CAPTURE_ARGS": str(capture),
292+
}
293+
res = run(["node", str(LAUNCHER_WIN), "--thinking=adaptive"], env=env)
294+
self.assertEqual(res.returncode, 0, res.stderr)
295+
self.assertEqual(idx.read_text(encoding="utf-8"), f"before {MARKED} after")
296+
191297

192298
@unittest.skipIf(os.name == "nt", "needs both bash and node on PATH")
193299
class ParityTests(unittest.TestCase):

0 commit comments

Comments
 (0)