From 6a2e8a809bee3edb3c8f31bf15b546f650d56945 Mon Sep 17 00:00:00 2001 From: Priyanshubhartistm Date: Thu, 3 Dec 2026 18:49:08 +0530 Subject: [PATCH 1/4] fix(cli): keep nginx/ssl out of the stash that update creates Signed-off-by: Priyanshubhartistm --- .changeset/update-keep-ssl-out-of-stash.md | 5 ++ src/cli/commands/update.ts | 15 +++- test/unit/cli/update.spec.ts | 96 +++++++++++++++++++--- 3 files changed, 101 insertions(+), 15 deletions(-) create mode 100644 .changeset/update-keep-ssl-out-of-stash.md diff --git a/.changeset/update-keep-ssl-out-of-stash.md b/.changeset/update-keep-ssl-out-of-stash.md new file mode 100644 index 000000000..147162bbd --- /dev/null +++ b/.changeset/update-keep-ssl-out-of-stash.md @@ -0,0 +1,5 @@ +--- +"nostream": patch +--- + +`nostream update` no longer stashes the files under `nginx/ssl`. They are not tracked or ignored, so the stash took the certificates the nginx compose file mounts, private keys included, into a Git object any local account can read, and restoring them did not keep the owner-only mode they had. The directory now stays where it is while the rest of the local changes are stashed and restored as before. diff --git a/src/cli/commands/update.ts b/src/cli/commands/update.ts index 0c6859dad..6e211f970 100644 --- a/src/cli/commands/update.ts +++ b/src/cli/commands/update.ts @@ -4,6 +4,13 @@ import { runCommand, runCommandWithOutput } from '../utils/process' import { runStart } from './start' import { runStop } from './stop' +// `git stash -u` takes every untracked file that is not ignored, and nginx/ssl is neither tracked nor ignored: it holds +// the certificates the nginx compose file mounts, private keys included. Git keeps a stashed file as an object that any +// local account can read, and restoring it creates the file with the default mode, so a key that was readable by its +// owner only would not be afterwards. The directory is left where it is, and the paths are anchored at the top of the +// repository so the command does not depend on the directory it runs in. +export const STASH_ARGS = ['stash', 'push', '-u', '-m', 'nostream-cli-update', '--', ':/', ':(top,exclude)nginx/ssl'] + const wasStashCreated = (output: string): boolean => { return !output.includes('No local changes to save') } @@ -17,9 +24,13 @@ export const runUpdate = async (passthrough: string[]): Promise => { return code } - const stashResult = await runCommandWithOutput('git', ['stash', 'push', '-u', '-m', 'nostream-cli-update']) + const stashResult = await runCommandWithOutput('git', STASH_ARGS) if (!stashResult.ok) { - spinner.fail(stashResult.ok === false && stashResult.reason === 'not-found' ? 'Update failed: git is not installed' : 'Update failed while stashing local changes') + spinner.fail( + stashResult.ok === false && stashResult.reason === 'not-found' + ? 'Update failed: git is not installed' + : 'Update failed while stashing local changes', + ) return 1 } if (stashResult.code !== 0) { diff --git a/test/unit/cli/update.spec.ts b/test/unit/cli/update.spec.ts index 7f216b71e..bddc760ef 100644 --- a/test/unit/cli/update.spec.ts +++ b/test/unit/cli/update.spec.ts @@ -1,7 +1,12 @@ +import { execFileSync } from 'node:child_process' +import fs from 'node:fs' +import os from 'node:os' +import path from 'node:path' + import { expect } from 'chai' import sinon from 'sinon' -import { runUpdate } from '../../../src/cli/commands/update' +import { runUpdate, STASH_ARGS } from '../../../src/cli/commands/update' import * as processUtils from '../../../src/cli/utils/process' import * as startCommand from '../../../src/cli/commands/start' import * as stopCommand from '../../../src/cli/commands/stop' @@ -20,12 +25,7 @@ describe('runUpdate', () => { stdout: 'Saved working directory and index state WIP on main: abc123', stderr: '', }) - const runCommandStub = sinon - .stub(processUtils, 'runCommand') - .onFirstCall() - .resolves(1) - .onSecondCall() - .resolves(0) + const runCommandStub = sinon.stub(processUtils, 'runCommand').onFirstCall().resolves(1).onSecondCall().resolves(0) const code = await runUpdate([]) @@ -44,12 +44,7 @@ describe('runUpdate', () => { stdout: 'Saved working directory and index state WIP on main: abc123', stderr: '', }) - const runCommandStub = sinon - .stub(processUtils, 'runCommand') - .onFirstCall() - .resolves(1) - .onSecondCall() - .resolves(2) + const runCommandStub = sinon.stub(processUtils, 'runCommand').onFirstCall().resolves(1).onSecondCall().resolves(2) const code = await runUpdate([]) @@ -58,4 +53,79 @@ describe('runUpdate', () => { expect(runCommandStub.secondCall.args).to.deep.equal(['git', ['stash', 'pop']]) expect(runStartStub.called).to.equal(false) }) + + it('stashes with the arguments that leave nginx/ssl out', async () => { + sinon.stub(stopCommand, 'runStop').resolves(0) + sinon.stub(startCommand, 'runStart').resolves(0) + const runCommandWithOutputStub = sinon.stub(processUtils, 'runCommandWithOutput').resolves({ + ok: true, + code: 0, + stdout: 'No local changes to save', + stderr: '', + }) + sinon.stub(processUtils, 'runCommand').resolves(0) + + await runUpdate([]) + + expect(runCommandWithOutputStub.firstCall.args).to.deep.equal(['git', STASH_ARGS]) + }) + + describe('the stash', () => { + let repo: string + const git = (...args: string[]) => execFileSync('git', args, { cwd: repo, encoding: 'utf-8' }) + const stashPaths = () => + git('stash', 'show', '--include-untracked', '--name-only', 'stash@{0}').split('\n').filter(Boolean) + + beforeEach(() => { + repo = fs.mkdtempSync(path.join(os.tmpdir(), 'nostream-update-')) + git('init', '-q') + git('config', 'user.email', 'test@example.com') + git('config', 'user.name', 'test') + fs.writeFileSync(path.join(repo, 'tracked'), 'tracked') + git('add', 'tracked') + git('commit', '-q', '-m', 'initial') + fs.mkdirSync(path.join(repo, 'nginx/ssl/live/relay.example'), { recursive: true }) + fs.writeFileSync(path.join(repo, 'nginx/ssl/live/relay.example/privkey.pem'), 'PRIVATE KEY', { mode: 0o600 }) + }) + + afterEach(() => { + fs.rmSync(repo, { recursive: true, force: true }) + }) + + it('keeps a private key under nginx/ssl out of the stash and in place', () => { + fs.writeFileSync(path.join(repo, 'notes.txt'), 'local') + + git(...STASH_ARGS) + + expect(stashPaths()).to.deep.equal(['notes.txt']) + const key = path.join(repo, 'nginx/ssl/live/relay.example/privkey.pem') + expect(fs.readFileSync(key, 'utf-8')).to.equal('PRIVATE KEY') + expect(fs.statSync(key).mode & 0o777).to.equal(0o600) + }) + + it('still stashes the other local files and restores them', () => { + fs.writeFileSync(path.join(repo, 'notes.txt'), 'local') + fs.writeFileSync(path.join(repo, 'tracked'), 'changed') + + git(...STASH_ARGS) + expect(fs.existsSync(path.join(repo, 'notes.txt'))).to.equal(false) + git('stash', 'pop', '-q') + + expect(fs.readFileSync(path.join(repo, 'notes.txt'), 'utf-8')).to.equal('local') + expect(fs.readFileSync(path.join(repo, 'tracked'), 'utf-8')).to.equal('changed') + }) + + it('leaves nothing to stash when nginx/ssl is the only local change', () => { + expect(git(...STASH_ARGS)).to.contain('No local changes to save') + }) + + it('does not depend on the directory it runs in', () => { + fs.mkdirSync(path.join(repo, 'sub')) + fs.writeFileSync(path.join(repo, 'notes.txt'), 'local') + + execFileSync('git', [...STASH_ARGS], { cwd: path.join(repo, 'sub') }) + + expect(stashPaths()).to.deep.equal(['notes.txt']) + }) + }) }) From 1c481092d58d26d0370ad9fe4b4a8d64d160d1ae Mon Sep 17 00:00:00 2001 From: Priyanshubhartistm Date: Thu, 3 Dec 2026 19:36:52 +0530 Subject: [PATCH 2/4] fix(cli): stash in the C locale and isolate the update tests from git config Signed-off-by: Priyanshubhartistm --- src/cli/commands/update.ts | 6 +++++- test/unit/cli/update.spec.ts | 20 ++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/cli/commands/update.ts b/src/cli/commands/update.ts index 6e211f970..d8ddbe630 100644 --- a/src/cli/commands/update.ts +++ b/src/cli/commands/update.ts @@ -11,6 +11,10 @@ import { runStop } from './stop' // repository so the command does not depend on the directory it runs in. export const STASH_ARGS = ['stash', 'push', '-u', '-m', 'nostream-cli-update', '--', ':/', ':(top,exclude)nginx/ssl'] +// wasStashCreated() reads git's own message, which git translates, so the command runs in the C locale. In another one +// "nothing to stash" would read as a stash that was made, and the pop after the pull would restore an older stash or fail. +export const STASH_ENV = { LC_ALL: 'C' } + const wasStashCreated = (output: string): boolean => { return !output.includes('No local changes to save') } @@ -24,7 +28,7 @@ export const runUpdate = async (passthrough: string[]): Promise => { return code } - const stashResult = await runCommandWithOutput('git', STASH_ARGS) + const stashResult = await runCommandWithOutput('git', STASH_ARGS, { env: STASH_ENV }) if (!stashResult.ok) { spinner.fail( stashResult.ok === false && stashResult.reason === 'not-found' diff --git a/test/unit/cli/update.spec.ts b/test/unit/cli/update.spec.ts index bddc760ef..e7567076e 100644 --- a/test/unit/cli/update.spec.ts +++ b/test/unit/cli/update.spec.ts @@ -6,7 +6,7 @@ import path from 'node:path' import { expect } from 'chai' import sinon from 'sinon' -import { runUpdate, STASH_ARGS } from '../../../src/cli/commands/update' +import { runUpdate, STASH_ARGS, STASH_ENV } from '../../../src/cli/commands/update' import * as processUtils from '../../../src/cli/utils/process' import * as startCommand from '../../../src/cli/commands/start' import * as stopCommand from '../../../src/cli/commands/stop' @@ -67,12 +67,24 @@ describe('runUpdate', () => { await runUpdate([]) - expect(runCommandWithOutputStub.firstCall.args).to.deep.equal(['git', STASH_ARGS]) + expect(runCommandWithOutputStub.firstCall.args).to.deep.equal(['git', STASH_ARGS, { env: STASH_ENV }]) + expect(STASH_ENV).to.deep.equal({ LC_ALL: 'C' }) }) describe('the stash', () => { let repo: string - const git = (...args: string[]) => execFileSync('git', args, { cwd: repo, encoding: 'utf-8' }) + // The fixture is its own repository: variables that point git at the caller's checkout are dropped, and neither the + // developer's global or system configuration (commit signing, hooks, templates) nor their locale applies to it. + const isolatedEnv = (): NodeJS.ProcessEnv => { + const env = Object.fromEntries(Object.entries(process.env).filter(([name]) => !name.startsWith('GIT_'))) + return { ...env, GIT_CONFIG_GLOBAL: os.devNull, GIT_CONFIG_NOSYSTEM: '1', LC_ALL: 'C' } + } + const git = (...args: string[]) => + execFileSync('git', ['-c', 'commit.gpgsign=false', '-c', `core.hooksPath=${os.devNull}`, ...args], { + cwd: repo, + encoding: 'utf-8', + env: isolatedEnv(), + }) const stashPaths = () => git('stash', 'show', '--include-untracked', '--name-only', 'stash@{0}').split('\n').filter(Boolean) @@ -123,7 +135,7 @@ describe('runUpdate', () => { fs.mkdirSync(path.join(repo, 'sub')) fs.writeFileSync(path.join(repo, 'notes.txt'), 'local') - execFileSync('git', [...STASH_ARGS], { cwd: path.join(repo, 'sub') }) + execFileSync('git', [...STASH_ARGS], { cwd: path.join(repo, 'sub'), env: isolatedEnv() }) expect(stashPaths()).to.deep.equal(['notes.txt']) }) From 9e36e15e8f8f40fc986fb371ba569a907d1649de Mon Sep 17 00:00:00 2001 From: Priyanshubhartistm Date: Fri, 4 Dec 2026 19:28:32 +0530 Subject: [PATCH 3/4] fix(cli): ignore nginx/ssl instead of excluding it from the stash Signed-off-by: Priyanshubhartistm --- .changeset/update-keep-ssl-out-of-stash.md | 2 +- .gitignore | 3 +++ src/cli/commands/update.ts | 9 +++------ test/unit/cli/update.spec.ts | 15 ++++----------- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/.changeset/update-keep-ssl-out-of-stash.md b/.changeset/update-keep-ssl-out-of-stash.md index 147162bbd..0d263872f 100644 --- a/.changeset/update-keep-ssl-out-of-stash.md +++ b/.changeset/update-keep-ssl-out-of-stash.md @@ -2,4 +2,4 @@ "nostream": patch --- -`nostream update` no longer stashes the files under `nginx/ssl`. They are not tracked or ignored, so the stash took the certificates the nginx compose file mounts, private keys included, into a Git object any local account can read, and restoring them did not keep the owner-only mode they had. The directory now stays where it is while the rest of the local changes are stashed and restored as before. +`nostream update` no longer stashes the files under `nginx/ssl`. They were neither tracked nor ignored, so the stash took the certificates the nginx compose file mounts, private keys included, into a Git object any local account can read, and restoring them did not keep the owner-only mode they had. The directory is now in `.gitignore`, so it stays where it is while the rest of the local changes are stashed and restored as before. diff --git a/.gitignore b/.gitignore index 1437c2f19..66f2cb147 100644 --- a/.gitignore +++ b/.gitignore @@ -55,3 +55,6 @@ coverage-report/ # graphify code-graph output (regenerated, ~4 MB per run) graphify-out/ + +# TLS certificates and private keys the nginx compose file mounts +nginx/ssl/ diff --git a/src/cli/commands/update.ts b/src/cli/commands/update.ts index d8ddbe630..716d067ee 100644 --- a/src/cli/commands/update.ts +++ b/src/cli/commands/update.ts @@ -4,12 +4,9 @@ import { runCommand, runCommandWithOutput } from '../utils/process' import { runStart } from './start' import { runStop } from './stop' -// `git stash -u` takes every untracked file that is not ignored, and nginx/ssl is neither tracked nor ignored: it holds -// the certificates the nginx compose file mounts, private keys included. Git keeps a stashed file as an object that any -// local account can read, and restoring it creates the file with the default mode, so a key that was readable by its -// owner only would not be afterwards. The directory is left where it is, and the paths are anchored at the top of the -// repository so the command does not depend on the directory it runs in. -export const STASH_ARGS = ['stash', 'push', '-u', '-m', 'nostream-cli-update', '--', ':/', ':(top,exclude)nginx/ssl'] +// `git stash -u` takes every untracked file that is not ignored. nginx/ssl holds the certificates the nginx compose file +// mounts, private keys included, so it is listed in .gitignore and the stash leaves it where it is. +export const STASH_ARGS = ['stash', 'push', '-u', '-m', 'nostream-cli-update'] // wasStashCreated() reads git's own message, which git translates, so the command runs in the C locale. In another one // "nothing to stash" would read as a stash that was made, and the pop after the pull would restore an older stash or fail. diff --git a/test/unit/cli/update.spec.ts b/test/unit/cli/update.spec.ts index e7567076e..7efbf9add 100644 --- a/test/unit/cli/update.spec.ts +++ b/test/unit/cli/update.spec.ts @@ -54,7 +54,7 @@ describe('runUpdate', () => { expect(runStartStub.called).to.equal(false) }) - it('stashes with the arguments that leave nginx/ssl out', async () => { + it('stashes the untracked files in the C locale', async () => { sinon.stub(stopCommand, 'runStop').resolves(0) sinon.stub(startCommand, 'runStart').resolves(0) const runCommandWithOutputStub = sinon.stub(processUtils, 'runCommandWithOutput').resolves({ @@ -94,7 +94,9 @@ describe('runUpdate', () => { git('config', 'user.email', 'test@example.com') git('config', 'user.name', 'test') fs.writeFileSync(path.join(repo, 'tracked'), 'tracked') - git('add', 'tracked') + // The repository's own .gitignore, which is what keeps nginx/ssl out of the stash. + fs.copyFileSync(path.resolve(__dirname, '../../../.gitignore'), path.join(repo, '.gitignore')) + git('add', 'tracked', '.gitignore') git('commit', '-q', '-m', 'initial') fs.mkdirSync(path.join(repo, 'nginx/ssl/live/relay.example'), { recursive: true }) fs.writeFileSync(path.join(repo, 'nginx/ssl/live/relay.example/privkey.pem'), 'PRIVATE KEY', { mode: 0o600 }) @@ -130,14 +132,5 @@ describe('runUpdate', () => { it('leaves nothing to stash when nginx/ssl is the only local change', () => { expect(git(...STASH_ARGS)).to.contain('No local changes to save') }) - - it('does not depend on the directory it runs in', () => { - fs.mkdirSync(path.join(repo, 'sub')) - fs.writeFileSync(path.join(repo, 'notes.txt'), 'local') - - execFileSync('git', [...STASH_ARGS], { cwd: path.join(repo, 'sub'), env: isolatedEnv() }) - - expect(stashPaths()).to.deep.equal(['notes.txt']) - }) }) }) From 59d696cbe4c07b4280e0d8c2475841082bce4f7e Mon Sep 17 00:00:00 2001 From: Priyanshubhartistm Date: Fri, 4 Dec 2026 19:37:17 +0530 Subject: [PATCH 4/4] fix(cli): keep the nginx/ssl stash exclusion alongside the ignore rule Signed-off-by: Priyanshubhartistm --- .changeset/update-keep-ssl-out-of-stash.md | 2 +- src/cli/commands/update.ts | 6 ++++-- test/unit/cli/update.spec.ts | 24 ++++++++++++++++++---- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.changeset/update-keep-ssl-out-of-stash.md b/.changeset/update-keep-ssl-out-of-stash.md index 0d263872f..f8ebd2405 100644 --- a/.changeset/update-keep-ssl-out-of-stash.md +++ b/.changeset/update-keep-ssl-out-of-stash.md @@ -2,4 +2,4 @@ "nostream": patch --- -`nostream update` no longer stashes the files under `nginx/ssl`. They were neither tracked nor ignored, so the stash took the certificates the nginx compose file mounts, private keys included, into a Git object any local account can read, and restoring them did not keep the owner-only mode they had. The directory is now in `.gitignore`, so it stays where it is while the rest of the local changes are stashed and restored as before. +`nostream update` no longer stashes the files under `nginx/ssl`. They were neither tracked nor ignored, so the stash took the certificates the nginx compose file mounts, private keys included, into a Git object any local account can read, and restoring them did not keep the owner-only mode they had. The directory is now in `.gitignore`, and the stash command leaves it out as well, because it runs before the pull that brings that rule to an older checkout. diff --git a/src/cli/commands/update.ts b/src/cli/commands/update.ts index 716d067ee..07749c2cd 100644 --- a/src/cli/commands/update.ts +++ b/src/cli/commands/update.ts @@ -5,8 +5,10 @@ import { runStart } from './start' import { runStop } from './stop' // `git stash -u` takes every untracked file that is not ignored. nginx/ssl holds the certificates the nginx compose file -// mounts, private keys included, so it is listed in .gitignore and the stash leaves it where it is. -export const STASH_ARGS = ['stash', 'push', '-u', '-m', 'nostream-cli-update'] +// mounts, private keys included, and a stash keeps them as a Git object any local account can read. The directory is in +// .gitignore, but the stash runs before the pull that brings that rule to an older checkout, so the command leaves it +// out as well. The paths are anchored at the top of the repository so the command does not depend on where it runs. +export const STASH_ARGS = ['stash', 'push', '-u', '-m', 'nostream-cli-update', '--', ':/', ':(top,exclude)nginx/ssl'] // wasStashCreated() reads git's own message, which git translates, so the command runs in the C locale. In another one // "nothing to stash" would read as a stash that was made, and the pop after the pull would restore an older stash or fail. diff --git a/test/unit/cli/update.spec.ts b/test/unit/cli/update.spec.ts index 7efbf9add..cf567a806 100644 --- a/test/unit/cli/update.spec.ts +++ b/test/unit/cli/update.spec.ts @@ -54,7 +54,7 @@ describe('runUpdate', () => { expect(runStartStub.called).to.equal(false) }) - it('stashes the untracked files in the C locale', async () => { + it('stashes with the arguments that leave nginx/ssl out, in the C locale', async () => { sinon.stub(stopCommand, 'runStop').resolves(0) sinon.stub(startCommand, 'runStart').resolves(0) const runCommandWithOutputStub = sinon.stub(processUtils, 'runCommandWithOutput').resolves({ @@ -94,9 +94,7 @@ describe('runUpdate', () => { git('config', 'user.email', 'test@example.com') git('config', 'user.name', 'test') fs.writeFileSync(path.join(repo, 'tracked'), 'tracked') - // The repository's own .gitignore, which is what keeps nginx/ssl out of the stash. - fs.copyFileSync(path.resolve(__dirname, '../../../.gitignore'), path.join(repo, '.gitignore')) - git('add', 'tracked', '.gitignore') + git('add', 'tracked') git('commit', '-q', '-m', 'initial') fs.mkdirSync(path.join(repo, 'nginx/ssl/live/relay.example'), { recursive: true }) fs.writeFileSync(path.join(repo, 'nginx/ssl/live/relay.example/privkey.pem'), 'PRIVATE KEY', { mode: 0o600 }) @@ -106,6 +104,7 @@ describe('runUpdate', () => { fs.rmSync(repo, { recursive: true, force: true }) }) + // An older checkout has no ignore rule for nginx/ssl until the pull that follows the stash. it('keeps a private key under nginx/ssl out of the stash and in place', () => { fs.writeFileSync(path.join(repo, 'notes.txt'), 'local') @@ -132,5 +131,22 @@ describe('runUpdate', () => { it('leaves nothing to stash when nginx/ssl is the only local change', () => { expect(git(...STASH_ARGS)).to.contain('No local changes to save') }) + + it('does not depend on the directory it runs in', () => { + fs.mkdirSync(path.join(repo, 'sub')) + fs.writeFileSync(path.join(repo, 'notes.txt'), 'local') + + execFileSync('git', [...STASH_ARGS], { cwd: path.join(repo, 'sub'), env: isolatedEnv() }) + + expect(stashPaths()).to.deep.equal(['notes.txt']) + }) + + it('is kept out of a plain stash by the project .gitignore', () => { + fs.copyFileSync(path.resolve(__dirname, '../../../.gitignore'), path.join(repo, '.gitignore')) + git('add', '.gitignore') + git('commit', '-q', '-m', 'ignore') + + expect(git('stash', 'push', '-u', '-m', 'plain')).to.contain('No local changes to save') + }) }) })