Skip to content

feat(accounts): look up ./.netrc before ~/.netrc for per-project credentials - #3844

Open
heroku-johnny wants to merge 3 commits into
mainfrom
W-23597907
Open

feat(accounts): look up ./.netrc before ~/.netrc for per-project credentials#3844
heroku-johnny wants to merge 3 commits into
mainfrom
W-23597907

Conversation

@heroku-johnny

Copy link
Copy Markdown
Contributor

Summary

Closes #1452 / GUS W-23597907

  • initNetrc() in src/lib/accounts/accounts.ts now checks for a .netrc file in process.cwd() before falling back to ~/.netrc
  • If a CWD-local .netrc exists, its machine entries are loaded and merged on top of the home netrc so per-project credentials take priority
  • If no CWD .netrc is found, behavior is unchanged (falls through to ~/.netrc)

Test plan

  • npx mocha test/unit/lib/accounts/accounts.unit.test.ts — 33 tests pass, 3 new tests cover the CWD lookup describe block
  • npx eslint src/lib/accounts/accounts.ts test/unit/lib/accounts/accounts.unit.test.ts — 0 errors
  • Manual: place a .netrc with project-specific credentials in a project directory, run heroku accounts:current from that directory, confirm it resolves the project account

🤖 Generated with Claude Code

…entials (W-23597907, #1452)

When `initNetrc()` loads credentials it now checks for a `.netrc` in
`process.cwd()` first. If found, its machine entries are merged into the
home `~/.netrc` with local entries taking priority, enabling per-project
credential overrides without touching the global netrc file.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@heroku-johnny
heroku-johnny requested a review from a team as a code owner July 27, 2026 20:16

@michaelmalave michaelmalave left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dev Tools Standards Review Results (machine-generated)

🟡 3 advisory.


// Build a fake "cwd" netrc and simulate the merge manually, as the
// module performs it: cwd entries overwrite home entries for same host.
homeNetrc.machines['api.heroku.com'] = {login: 'project@example.com', password: 'project-pass'}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add-test-coverage (Testing · important · 60% confidence): It looks like the "cwd .netrc takes priority over home" test pre-populates the cache via setNetrc and mutates machines by hand before calling initNetrc(), so initNetrc returns the cached object without ever exercising the cwd-merge path — the comment even says the merge is "simulated manually," meaning the assertion passes regardless of module behavior. Should we drop the pre-seeded cache so initNetrc() actually reads and merges the cwd .netrc, or assert against the real merge output instead of the hand-built one?

import {expect} from 'chai'
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete-unused-code (Code style · minor · 75% confidence): It looks like import path from 'node:path' is added but never referenced anywhere in the file. Should we delete it?

beforeEach(function () {
setNetrc(null)
existsSyncStub = stub(fs, 'existsSync')
cwdStub = stub(process, 'cwd').returns('/fake/project')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete-unused-code (Code style · minor · 50% confidence): It looks like cwdStub = stub(process, 'cwd')... is set in beforeEach but never referenced, and process.cwd is never invoked because the tests short-circuit on the cached netrc. Should we remove the stub, or add a test that actually drives the cwd path so it gets used?

@michaelmalave michaelmalave left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Some comments but nothing blocking on this.

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.

Feature: Use .netrc first and then look for ~/.netrc

2 participants