Skip to content

Windows: cloudpin's own variables and the read-only check fold names; Wrangler's login folder per platform (#136) - #152

Merged
paureis merged 22 commits into
mainfrom
fix/136-windows-case-gaps
Nov 2, 2026
Merged

paureis merged 22 commits into
mainfrom
fix/136-windows-case-gaps

Conversation

@paureis

@paureis paureis commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Closes #136. Target: 1.3.0. This is a draft stacked on #135 (base fix/119-cloudflare-account-vars), because it builds on #135's foldEnvNames. Merge #135 first, then retarget this PR to main. The CHANGELOG and ROADMAP lines get added at that point.

What changes (Windows only; Linux and macOS controls unchanged)

  1. cloudpin's own variables are case-insensitive in hook mode.

    • A lowercase cloudpin_env, cloudpin_branch, cloudpin_confirm or cloudpin_skip set by the user now counts, as it does for the real process. guard folds the environment before findConfig.
    • An agent still can't set or unset CLOUDPIN_ENV/CLOUDPIN_BRANCH in any spelling. On win32, envFor's user-only check folds the name, and the read fold and the check fold land in the same commit (2c4e82a).
    • CONFIRM and SKIP still count in shell mode only.
  2. The read-only check gets the folded environment, so on Windows a lowercase aws_config_file makes a protected aws s3 ls ask.

  3. Wrangler's login folder. The identity cache now watches the folder Wrangler really uses:

    • Windows: %APPDATA%\xdg.config\.wrangler
    • macOS: ~/Library/Preferences/.wrangler
    • elsewhere: ~/.config/.wrangler
    • A non-empty XDG_CONFIG_HOME wins on every platform.

    Source: cloudflare/workers-sdk packages/workers-utils/src/xdg-app-paths.ts and global-wrangler-config-path.ts. Before, a re-login on Windows or macOS didn't drop the 5-minute whoami cache.

  4. Providers get the platform guard is given (CommandContext.platform, cacheInputs(env, platform)), so wranglerDotenv's fold of .env names is tested for both platforms on any host.

src/shellwords.ts was over the 5,000-token file cap, so USER_ONLY_VARS and envFor moved to the new src/user-env.ts first, in a pure move (5322307). A script proved it verbatim, its one-character controls fail as they should, and the test counts are unchanged.

Tests

The tests are in the new files test/windows-case-gaps.test.ts and test/wrangler-login-folder.test.ts. They were committed failing first: 11 of the 13 failed, and the two Linux-only ones passed. Typecheck passes. Full suite: 52 files, 1265 passed, 8 skipped.

  • The builder ran 12 mutations, and the tests caught all 12. One of them (agents.ts passing no platform) is caught only when the host platform differs from the target, which a simulated Linux run confirmed.
  • I ran two more myself: un-folding the user-only check, so an agent's inline cloudpin_env= would be accepted (2 tests failed), and removing the findConfig fold (3 failed). The files were restored afterwards.

Left open

  • When two spellings hold different values, the uppercase one wins (Node's choice). There's no "can't tell" block for this.
  • envFor's name in base check for plain assignments, and unset of non-user variables, still compare names case-sensitively.

🤖 Generated with Claude Code

paureis and others added 14 commits October 23, 2026 18:34
…#119)

`CLOUDFLARE_ACCOUNT_ID=$(cat id) wrangler deploy` dropped the variable,
since guard only stops on an unknown value in a provider's identity
variables (cacheInputs().env, #86), and the account variables weren't
in Cloudflare's list. cloudpin then resolved the account without them
while Wrangler used the unknown value.

Cloudflare's identity variables are now every name in DOTENV_VARS (the
account variables, CLOUDFLARE_ENV, WRANGLER_CACHE_DIR, the credentials)
plus DOTENV_KEY, which makes Wrangler decrypt a .env.vault instead of
.env. whoami's cache key gains names it ignores, which can only make it
miss.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Windows variable names ignore case, and so does every guarded CLI there:
Node's process.env, Wrangler's caseInsensitiveEnv proxy over its merged
environment (wrangler@4.151.3, config/case-insensitive-env.ts, used by
config/dot-env.ts loadDotEnv on Windows only, installed as process.env
in index.ts), Go's os.Getenv and Python's upper-cased os.environ. guard
handed providers a plain object, so `cloudflare_account_id=B` from the
shell or an agent's line was missed by env.CLOUDFLARE_ACCOUNT_ID, as were
gh_host and the rest, and the identity cache keyed on AWS_* missed
aws_profile and reused another profile's identity.

On win32 guard now gives the provider one upper-case key per name. When
two spellings of a variable that decides the account hold different
values, which one a CLI sees depends on the shell and the CLI, so the
command blocks as can't tell, naming the spellings, never the values.
Other variables keep the value of the first key in code-unit order, the
one Node keeps when it spawns. An unknown value in either spelling
blocks as before (#86). Linux and macOS are unchanged. The platform is
injectable through GuardDeps for tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The cache wrapper computed its watched files from the unfolded
environment, so with a lowercase azure_config_dir it watched the default
~/.azure folder, and an `az account set` in the named folder kept
reusing the old identity for up to five minutes. It now gets the same
folded environment as resolve.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
New tests for what the Windows variable-name fold (#119) left out, each with
a Linux control and the platform given to guard, so both sides run on any OS:

- the user's lowercase cloudpin_env and cloudpin_branch pick the environment
  in the agent hook on win32, while the agent's own assignment, export or
  unset of them in any spelling still doesn't count;
- a lowercase cloudpin_confirm or cloudpin_skip in a terminal on win32;
- a lowercase aws_config_file next to an alias file makes a protected
  environment ask on win32;
- a lowercase name inside Wrangler's .env folds by the given platform;
- the identity cache watches Wrangler's login file where Wrangler writes it
  on each platform (%APPDATA%\xdg.config on Windows).

Before the fix, 11 fail and the 2 Linux-only tests pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…136)

guard folds the command's variable names before it reads CLOUDPIN_SKIP and
CLOUDPIN_CONFIRM, so a user's lowercase cloudpin_confirm or cloudpin_skip
counts in a terminal on Windows, as Windows itself reads them. Both still
count in shell mode only, so an agent can't use either in any spelling.
Linux and macOS are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
isReadOnly decides whether a protected environment asks for confirmation,
and for aws it looks for an alias file next to AWS_CONFIG_FILE. It got the
unfolded environment, so on Windows a lowercase aws_config_file was missed
and an aliased `aws s3 ls` skipped the question. guard now passes the
environment with Windows names folded. Linux and macOS are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The command context now carries the platform the command runs on, and
guard passes its own. The Cloudflare provider hands it to wranglerDotenv,
which folds the names inside .env files on Windows only, as Wrangler does;
it used to fold by process.platform, so the Windows behaviour was tested
only on a Windows run and the Linux one only elsewhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cOS (#136)

The cached `wrangler whoami` is keyed on Wrangler's login file, but cloudpin
watched ~/.config/.wrangler on every platform. Wrangler's XDG config folder
is %APPDATA%\xdg.config on Windows and ~/Library/Preferences on macOS
(workers-utils getGlobalConfigPath and xdgConfig, unchanged from
wrangler@4.151.3 to the current main), so a re-login there didn't drop the
5-minute cache. cacheInputs now takes the platform (guard passes its own;
it defaults to this process's), and an empty XDG_CONFIG_HOME counts as
unset, as in Wrangler.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A pure move, no behaviour change: USER_ONLY_VARS and envFor, with their
doc comments, go verbatim from src/shellwords.ts (over its size limit) into
the new src/user-env.ts, which imports only the Invocation type from
shellwords.ts. The importers (hooks/agents.ts, explain.ts and three tests)
import envFor from user-env.ts directly; nothing else used it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ents still can't set them (#136)

guard folds the command's variable names before findConfig, so a user's
lowercase cloudpin_env or cloudpin_branch picks the environment in the
agent hook on Windows, as the real process reads it there. In the same
change envFor's user-only check folds the names on Windows, so an agent's
inline, exported, plain or unset cloudpin_env (any spelling) is still
ignored, as CLOUDPIN_ENV=... is today. The hook and explain pass the
platform guard is given. Linux and macOS are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@paureis paureis added this to the 1.3.0 milestone Oct 25, 2026
@paureis
paureis changed the base branch from fix/119-cloudflare-account-vars to main November 2, 2026 17:49
paureis and others added 8 commits November 2, 2026 12:53
Every conflicted file takes main's version; #152's behaviour is ported
onto main's code in the commits that follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main's cacheInputs (#103) watches each Wrangler folder's config/ directory,
which holds every profile's login, and its profile bindings file, rather than
config/default.toml alone, so the test expects those per platform. On win32
Wrangler's home is USERPROFILE (os.homedir), so the XDG_CONFIG_HOME case sets
it next to HOME. The folders expected per platform are unchanged. Still
failing: cacheInputs ignores the platform it is given.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…136)

guard folds the command's variable names once, before anything reads them,
and the terminal's CLOUDPIN_SKIP and CLOUDPIN_CONFIRM come from that folded
environment, so a lowercase cloudpin_confirm counts on win32 as it does for
the shell. Agents still can't confirm or skip in any spelling; other
platforms are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
isReadOnly reads AWS_CONFIG_FILE to find an AWS CLI alias file; on win32 a
lowercase aws_config_file is the same variable for the AWS CLI, so a
protected `aws s3 ls` next to an alias file now asks there too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CommandContext carries the platform the command runs on and cacheInputs
takes it as a second argument, both from guard's deps.platform, so a
provider's per-platform behaviour can be tested on any host. Without it they
default to this process's platform, as before. CONTRIBUTING says to read it
there, never process.platform.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…en (#136)

wranglerConfigDirs (#103) already knows Wrangler's per-platform login folder:
%APPDATA%\xdg.config\.wrangler on Windows, ~/Library/Preferences/.wrangler on
macOS, ~/.config/.wrangler elsewhere, XDG_CONFIG_HOME first when non-empty.
cacheInputs and resolve now hand it, the .env reader and the profile lookup
the platform they are given instead of this process's, so the identity cache
and .env name folding are right for the command and testable on any host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ents still can't set them (#136)

guard hands findConfig the folded environment, so a user's lowercase
cloudpin_env or cloudpin_branch picks the environment on win32, as Windows
reads it. In the same change envFor's user-only check folds the name on
win32 (the platform guard is given, passed by the hook and explain), so an
agent's cloudpin_env=..., export, $env: assignment or unset, in any
spelling, still doesn't count and can't undo the user's choice. Linux and
macOS are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@paureis
paureis marked this pull request as ready for review November 2, 2026 18:00
@paureis
paureis merged commit e30fafc into main Nov 2, 2026
5 checks passed
@paureis
paureis deleted the fix/136-windows-case-gaps branch November 2, 2026 18:02
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.

Windows: remaining variable-name case and folder gaps

1 participant