Repository navigation
fix(auth): create settings dir before watching it - #65
John-David Dalton (jdalton) wants to merge 1 commit into
Conversation
3aa3099 to
1f1b83e
Compare
4398e9f to
cc455f7
Compare
7e914f7 to
a5d3a5e
Compare
On a fresh install, VSCode logged errors about watching a folder that does not exist. The token watcher was pointed at <dataHome>/socket, a folder only created on first login, so before that first login VSCode kept reporting a missing watched directory. Create the directory (recursively, ignoring any error) right before creating the watcher, so the watcher always points at a folder that exists. It is idempotent and never throws, so it cannot break activation on a read-only or unusual filesystem. The two pieces are extracted into a pure module, src/auth-paths.ts, and unit-tested in test/auth-paths.test.mts: ensureDirectoryExists (the create-before-watch behavior) and resolveDataHome (the cross-platform data-home derivation). Closes SURF-111.
a5d3a5e to
87ae94e
Compare
|
Closing this as obsolete rather than merging it — This PR fixed a VSCode warning about watching a folder that does not exist yet, by creating the settings directory before pointing a file-system watcher at it. Since then, The helper it added also already exists on
|
Closes SURF-111 ("VSCode is searching for non-existent folder").
On a fresh install of the Socket extension, VSCode logs errors saying it is watching a folder that does not exist. The folder is where the extension saves your API token, and it is only created the first time you log in — but the extension starts watching it the moment it activates, before that folder has ever been created. So every new user gets watcher errors in their log until they log in.
The fix is one line of intent: create the directory (recursively, ignoring any error) right before creating the watcher, so the watcher always points at something real.
Why it happened — the watcher is set up at activation, the folder is created at first login
During activation the extension sets up a file watcher so it can react when the user's saved API token changes on disk. The token is stored at
<dataHome>/socket/settings, and the watcher is pointed at the folder that contains it,<dataHome>/socket.That folder is only created the first time the user logs in and a token is written. Before that first login the folder does not exist, so VSCode's watcher keeps reporting that it is watching a missing directory.
Why creating it early is safe — idempotent, never throws, and the same location the extension already writes to
The extension already writes the token to this exact location on login — this only makes the folder a moment earlier.
mkdirSyncwithrecursive: trueis a no-op when the folder is already there, and any error is swallowed, so this cannot break activation on a read-only or unusual filesystem.It uses
node:fs(like the scores manager already does for its cache directory) so the behavior is testable with real files; for the local data-home path this is equivalent to the previousvscode.workspace.fs.createDirectorycall.What is covered by tests — both pieces extracted into a pure module, 9 cases
Ran:
tsc --noEmit,oxlint,oxfmt --check, and the test suite — all pass locally.The fix's two pieces are both extracted into
src/auth-paths.tsand unit-tested intest/auth-paths.test.mts(9 cases):ensureDirectoryExists— the create-before-watch behavior itself, tested against a real temporary directory:<dataHome>/socketshape);resolveDataHome— the cross-platform derivation of which directory that is: Windows%LOCALAPPDATA%, Windows throwing when it is missing,$XDG_DATA_HOME, and the macOS and Linux fallbacks.The ticket text had drifted — this fixes the defect in the title, not the stale scope discussion
The ticket's written description had drifted into questions about API-token scopes and the endpoints
npm/scoreandnpm/pkg/ver/issues. Those endpoints belong to the old (pre-rewrite) extension; the current extension calls/v0/purlinstead. This PR fixes the reproducible defect named in the ticket title (the missing folder), not the stale scope discussion.CI is red for an unrelated reason — a fleet-infrastructure failure that affects every PR in this repo
The red
Check/Testjobs are a fleet-infrastructure failure in the shared bootstrap step (setup-and-install), which runs before any of this code. The same base tree is green on themainpush run but red onpull_requestruns; it affects every PR in the repo, not this change. Flagged to the team separately.