Skip to content

fix: keep variants usable when tweakcc cannot patch - #54

Merged
numman-ali merged 1 commit into
mainfrom
fix/windows-ci-smoke
May 31, 2026
Merged

numman-ali merged 1 commit into
mainfrom
fix/windows-ci-smoke

Conversation

@numman-ali

Copy link
Copy Markdown
Owner

Summary

  • continue create/update with the pristine native runtime when tweakcc patch validation fails in a known recoverable way
  • mark prompt-pack/tweakcc metadata as disabled when fallback is used
  • add a regression test for recoverable patched-binary validation failure

Validation

  • npm test
  • npm run typecheck
  • npm run lint
  • npm run bundle
  • npm run test:coverage

This PR is intended to unblock the Windows smoke failure before publishing v2.2.3.

@claude

claude Bot commented May 31, 2026

Copy link
Copy Markdown

Code Review

Overview

This PR adds graceful degradation when tweakcc fails to patch the Claude Code binary in a known-recoverable way (validation failures, Bun CommonJS wrapper issues, node-lief errors). Instead of aborting variant creation/update, the build continues with the pristine native runtime and marks tweakcc as disabled in the capability metadata. A regression test covers the async create path.

The fix is focused and the intent is clear. A few issues worth addressing below.


Issues

1. handleTweakccFailure() is copy-pasted between two classes

TweakccStep and TweakccUpdateStep each define an identical private handleTweakccFailure() method. Both BuildContext and UpdateContext share the relevant shape (prefs.promptPackEnabled, prefs.promptPackPreference, state.notes). Extract a standalone function in errors.ts (or a shared tweakcc-helpers.ts) that accepts that minimal interface, and call it from both steps.

// errors.ts (or a new shared module)
export function applyTweakccFallback(
  output: string,
  prefs: { promptPackEnabled: boolean; promptPackPreference: boolean },
  notes: string[]
): void {
  const message = formatTweakccFailure(output);
  if (!isRecoverableTweakccFailure(output)) throw new Error(message);
  prefs.promptPackEnabled = false;
  prefs.promptPackPreference = false;
  const fallback = 'Continuing with pristine native runtime; tweakcc theming and prompt pack were skipped.';
  if (!notes.includes(message)) notes.push(message);
  if (!notes.includes(fallback)) notes.push(fallback);
}

2. isRecoverableTweakccFailure mixes case-normalisation inconsistently

The function normalises the input for its own checks but passes the original string to isBunCommonJsWrapperFailure() and isTweakccNativeExtractionFailure(). If those helpers are also case-sensitive, this is fine — but it is easy to miss and should be made explicit (either always normalise before calling helpers, or document that the helpers handle normalisation themselves).

3. The node-lief match is overly broad

normalized.includes('node-lief')

Any output that mentions node-lief anywhere — including partial, unrelated messages — will trigger the recoverable path. Consider tightening this to a more specific phrase (e.g. 'cannot find module' + 'node-lief', or the exact error string emitted by tweakcc), or add a comment explaining why the substring alone is sufficient.

4. settingsOnly fallback in FinalizeUpdateStep could silently disable tweakcc

const tweakccEnabled = ctx.opts.settingsOnly
  ? (meta.capabilities?.tweakcc?.enabled ?? profile?.features.tweakcc.defaultEnabled ?? false)
  : !ctx.opts.noTweak && state.tweakResult?.status === 0;

The final ?? false means that if neither meta.capabilities nor a provider profile is present, tweakccEnabled silently becomes false. That scenario is unlikely, but the existing ?? chain already covers it through profile?.features.tweakcc.defaultEnabled. The trailing ?? false is correct as a last resort but worth a comment so a future reader doesn't remove it thinking it's redundant.


Minor Observations

  • Missing return-type annotation: handleTweakccFailure(ctx, output) returns void but the return type is not annotated. The rest of the step classes seem to annotate method signatures consistently.
  • execute() sync path not tested: The new test only exercises executeAsync(). The sync execute() path goes through the same handleTweakccFailure() but has no dedicated test. Given the duplicated code, a bug could live in one path without being caught by the other's test.
  • process.env.PATH mutation in test: Mutating PATH and relying on finally for cleanup is fine for sequential tests but could be fragile if the Node test runner ever parallelises within a process. Mocking the subprocess spawn would be more robust, though the current approach is pragmatic and consistent with other e2e-style tests in this repo.

Summary

The core logic is sound and the metadata propagation through FinalizeStep / FinalizeUpdateStep is correct. The main ask before merging is deduplicating handleTweakccFailure — having two identical copies is the kind of thing that will diverge silently when the next edge case is added. The other items are lower priority but worth a look.

@numman-ali
numman-ali merged commit 925e664 into main May 31, 2026
6 checks passed
@numman-ali
numman-ali deleted the fix/windows-ci-smoke branch May 31, 2026 19:45
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