Repository navigation
fix(oauth): make the Windows CredRead shim compile (#3722) - #3726
Conversation
Add-Type -Namespace ClaudeMem -Name CredRead generates a C# class CredRead that declares a member CredRead, which C# rejects with CS0542, "member names cannot be the same as their enclosing type". The type never compiled, every [ClaudeMem.CredRead]::CredRead call threw, and both -ErrorAction SilentlyContinue and the script's $ErrorActionPreference swallowed it. The script then reached exit 0 with no output, so the caller reported 'Windows Credential Manager has no entry for "Claude Code-credentials"' -- a wrong answer, not a missing one, for a machine that has the credential. The type is now CredApi, distinct from every member it declares. The Add-Type call runs with -ErrorAction Stop inside a try/catch that prints a marker, so a future compile failure is reported as "could not be queried" instead of silently becoming "no entry". The snippet moves into an exported buildWindowsCredentialScript() so the shim can be checked without a Windows host.
|
Correction to my own PR body: the line " This checkout has no installed No typecheck ran, and the earlier line came from misreading tooling output rather than from a real result. Nothing else in the PR body depends on it. What I did actually run and stand behind:
The change is a rename plus a |
Greptile SummaryThis change corrects the TypeScript generator for the Windows Credential Manager P/Invoke shim, adds an explicit compilation-error marker, and adds regression tests for the generated source. The packaged worker bundle was not regenerated: Confidence Score: 4/5Not safe to merge until the distributed worker bundle is regenerated with the corrected credential shim. A focused structural reproduction confirmed the class/member collision in the shipped bundle, confirmed that the source generator no longer has that collision, and verified that the stale bundle is included in the package and invoked by worker entry points. Files Needing Attention:
What T-Rex did
|
|
The finding is right and it is the important one: I did the rebuild to see what committing it would actually mean, and it is not a clean act right now. Rebuilding on clean So the committed bundle is stale against And it is not just minifier churn. Same version stamp, very different size: The build says so itself: A rebuild today trips the repo's own size guard and points at exactly the #2584 leak. That is a real question about What I verified about the fix itself in the rebuilt bundle (grep, not inference): So the generator change does flow into the bundle correctly; the only question is when the bundle gets committed. Your call, and I will do either:
Same question applies to #3727, where the shipped bundle likewise has no |
|
Flagging an overlap I should have caught before opening this: #3723 fixes the same issue and was opened about six hours earlier. I found #3722 by reading the issue list and did not check for an existing PR against it. That is on me. If you merge #3723, this can be closed — the rename is the core of both, and theirs also updates the generated worker bundle, which mine deliberately does not (I set out why in the comment above: rebuilding today pulls in ~834 lines of unrelated drift and a +418 KB jump that trips the build's own size guard). Two things here are not in #3723, in case you want them either way — I am happy to reduce this PR to just them on top of theirs:
No objection to theirs going in first; it got there first. |
|
Support for the extras. Yield the rename itself to #3723. #3723 already ships CredApi in The piece I would not drop: a failed Add-Type must not look like "no credential". SilentlyContinue is why CS0542 sat in production as a quiet miss. I would rather see those land on top of #3723 than close this as a straight duplicate. |
|
+1 to what's already in this thread — #3723 carries the regenerated |
|
Agreed, and thanks for cross-posting — that is the right merge order. #3723 should go first: it carries the regenerated One note on why I have not already stripped this down to just the extras, since that is the obvious next question. The CS0542 test here asserts the invariant — that the generated type is not named after one of its own members — rather than the string So, concretely, whichever is easier for you:
Either way there is no reason for both to wait on the same review. The substantive piece I would not want dropped in the shuffle is the marker: |
Closes #3722.
Add-Type -Namespace ClaudeMem -Name CredReadgenerates the C# classClaudeMem.CredRead, and that class declarespublic static extern bool CredRead(...). C# rejects that:So the type never compiled,
[ClaudeMem.CredRead]::CredRead($t, 1, 0, [ref]$ptr)threw on every candidate target, and two separate settings hid it —-ErrorAction SilentlyContinueon theAdd-Typeand$ErrorActionPreference = 'SilentlyContinue'at the top of the script. The script then reachedexit 0with empty stdout, which the caller reads as:That is a wrong answer rather than a missing one, and it is the reason this could sit unnoticed: the Windows keychain path reported itself as working correctly on a machine that has the credential.
Verified on a real Windows host
Windows 11, PowerShell 5.1. The reporter's minimal case:
And end to end, feeding the generated shim block from
buildWindowsCredentialScript()into PowerShell after this change:I ran only the
Add-Typeblock, not the credential loop — no secret was read.What changed
CredApi, distinct from every member it declares. All four references move with it.Add-Typeruns with-ErrorAction Stopinside atry/catchthat prints__CLAUDEMEM_CRED_SHIM_ERROR__ <message>. The caller recognises that marker and returns "Windows Credential Manager could not be queried: the CredRead shim failed to compile (…)" with alogger.warn, instead of claiming there is no entry. The rename fixes today's failure; this is what stops the next one from being invisible.buildWindowsCredentialScript(username). Nothing else about the read path, the candidate target names, or the quoting changes.Tests
tests/shared/windows-credential-shim.test.tsreads the generated script rather than running PowerShell, so it holds on the Linux CI runner too:CredApi, so any future rename stays covered[ClaudeMem.X]reference names the type actually declared, so a half-done rename fails-ErrorAction Stopo'brienis still escaped too''brienMutation-checked — restoring
-Name CredReadand its references fails exactly the CS0542 case:npx tsc --noEmit: no errors.Note:
plugin/scripts/worker-service.cjsis a build artefact of this source, so it picks the fix up on the next bundle; I have not hand-edited it.