Merge reviewed PR #3982: fix(cli): honor global --dry-run in auto-update, setup, and nasiko

This commit is contained in:
haelyra committed 2026-11-19 15:16:15 -05:00
commit f021f3b788
6 files changed
+208 -3

No files matched your search

+5 -1
View File
@@ -49,7 +49,11 @@ function parseArgs(argv) {
}
}
return parsed;
const dryRunEnv = process.env.ECC_DRY_RUN;
if (dryRunEnv !== undefined && dryRunEnv !== '0' && dryRunEnv !== '1') {
throw new Error('ECC_DRY_RUN must be "1" or "0" when set');
}
return { ...parsed, dryRun: parsed.dryRun || dryRunEnv === '1' };
}
function deriveRepoRootFromState(state) {
+5 -1
View File
@@ -51,7 +51,11 @@ function parseMutationArguments(argumentsList, command = 'install') {
}
if (!options.version) throw new Error(`Nasiko ${command} requires --version v0.1.0.`);
if (options.installDir) validateInstallDirectory(options.installDir);
return options;
const dryRunEnv = process.env.ECC_DRY_RUN;
if (dryRunEnv !== undefined && dryRunEnv !== '0' && dryRunEnv !== '1') {
throw new Error('ECC_DRY_RUN must be "1" or "0" when set');
}
return { ...options, dryRun: options.dryRun || dryRunEnv === '1' };
}
function defaultExecutablePath() {
+9 -1
View File
@@ -59,6 +59,14 @@ Migration installs and verifies the destination before removing the source scope
`);
}
function resolveDryRunOption(dryRun) {
const dryRunEnv = process.env.ECC_DRY_RUN;
if (dryRunEnv !== undefined && dryRunEnv !== '0' && dryRunEnv !== '1') {
throw new Error('ECC_DRY_RUN must be "1" or "0" when set');
}
return dryRun || dryRunEnv === '1';
}
function parseArgs(argv) {
const options = {
dryRun: false,
@@ -112,7 +120,7 @@ function parseArgs(argv) {
if (options.moveScope && options.scope === undefined) {
throw new Error('--move-scope requires an explicit --scope destination.');
}
return options;
return { ...options, dryRun: resolveDryRunOption(options.dryRun) };
}
function questionWithCancellation(terminal, prompt) {
+60
View File
@@ -58,6 +58,27 @@ function tarGzipFixture({
]));
}
function writeNasikoInstallFixture(canonicalRoot) {
const { getQualifiedRelease, normalizePlatform } = require('../../scripts/lib/nasiko-release');
const normalized = normalizePlatform();
const release = getQualifiedRelease('v0.1.0');
const executable = path.join(canonicalRoot, normalized.binaryName);
const metadataPath = path.join(canonicalRoot, '.ecc-nasiko-install.json');
fs.writeFileSync(executable, 'placeholder binary', { mode: 0o700 });
fs.writeFileSync(metadataPath, `${JSON.stringify({
version: 'v0.1.0',
platform: release.os,
architecture: release.arch,
manifestDigest: release.manifestDigest,
artifactDigest: release.manifestDigest,
binaryDigest: release.binaryDigest,
installedPath: executable,
license: release.license,
sourceUrl: release.sourceUrl,
}, null, 2)}\n`, { mode: 0o600 });
return { executable, metadataPath };
}
async function main() {
console.log('\n=== Testing Nasiko CLI lifecycle bridge ===\n');
@@ -523,6 +544,45 @@ async function main() {
assert.ok(!packageJson.dependencies?.nasiko);
assert.ok(!packageJson.optionalDependencies?.nasiko);
}],
['global ecc --dry-run keeps nasiko install and uninstall read-only', () => {
const { normalizePlatform } = require('../../scripts/lib/nasiko-release');
const installRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-nasiko-global-dry-run-'));
try {
const canonicalRoot = fs.realpathSync(installRoot);
const executable = path.join(canonicalRoot, normalizePlatform().binaryName);
const baseEnv = Object.fromEntries(
Object.entries(process.env).filter(([key]) => key !== 'ECC_DRY_RUN')
);
const installPreview = spawnSync(process.execPath, [
path.join(REPO_ROOT, 'scripts', 'ecc.js'),
'--dry-run', 'nasiko', 'install', '--version', 'v0.1.0', '--yes',
'--install-dir', canonicalRoot, '--json',
], { encoding: 'utf8', env: baseEnv });
assert.strictEqual(installPreview.status, 0, installPreview.stderr);
assert.strictEqual(JSON.parse(installPreview.stdout).dryRun, true);
assert.strictEqual(fs.existsSync(executable), false);
const { metadataPath } = writeNasikoInstallFixture(canonicalRoot);
const uninstallPreview = spawnSync(process.execPath, [
path.join(REPO_ROOT, 'scripts', 'ecc.js'),
'--dry-run', 'nasiko', 'uninstall', '--version', 'v0.1.0', '--yes',
'--install-dir', canonicalRoot, '--json',
], { encoding: 'utf8', env: baseEnv });
assert.strictEqual(uninstallPreview.status, 0, uninstallPreview.stderr);
assert.strictEqual(JSON.parse(uninstallPreview.stdout).dryRun, true);
assert.strictEqual(fs.existsSync(executable), true);
assert.strictEqual(fs.existsSync(metadataPath), true);
const invalid = spawnSync(process.execPath, [
path.join(REPO_ROOT, 'scripts', 'nasiko.js'),
'install', '--version', 'v0.1.0', '--install-dir', canonicalRoot,
], { encoding: 'utf8', env: { ...baseEnv, ECC_DRY_RUN: 'yes' } });
assert.strictEqual(invalid.status, 1);
assert.match(invalid.stderr, /ECC_DRY_RUN must be "1" or "0"/);
} finally {
fs.rmSync(installRoot, { recursive: true, force: true });
}
}],
];
let passed = 0;
+90
View File
@@ -19,6 +19,7 @@ const {
} = require('../../scripts/auto-update');
const {
createInstallState,
writeInstallState,
} = require('../../scripts/lib/install-state');
function test(name, fn) {
@@ -83,6 +84,56 @@ function ensureFakeRepo(repoRoot) {
fs.writeFileSync(path.join(repoRoot, 'scripts', 'install-apply.js'), '#!/usr/bin/env node\n');
}
function createBehindRemoteRepoFixture(fixture) {
const remoteRepo = path.join(fixture, 'remote.git');
const localRepo = path.join(fixture, 'local-ecc');
const pusherRepo = path.join(fixture, 'pusher');
execFileSync('git', ['init', '--bare', '-b', 'main', remoteRepo], { encoding: 'utf8' });
execFileSync('git', ['clone', remoteRepo, localRepo], { encoding: 'utf8' });
execFileSync('git', ['config', 'user.email', 'test@example.com'], { cwd: localRepo, encoding: 'utf8' });
execFileSync('git', ['config', 'user.name', 'Test'], { cwd: localRepo, encoding: 'utf8' });
ensureFakeRepo(localRepo);
fs.writeFileSync(
path.join(localRepo, 'scripts', 'install-apply.js'),
'#!/usr/bin/env node\nprocess.stdout.write(JSON.stringify({ dryRun: process.argv.includes("--dry-run"), plan: {} }));\n'
);
execFileSync('git', ['add', '.'], { cwd: localRepo, encoding: 'utf8' });
execFileSync('git', ['commit', '-m', 'initial'], { cwd: localRepo, encoding: 'utf8' });
execFileSync('git', ['push', '-u', 'origin', 'main'], { cwd: localRepo, encoding: 'utf8' });
const headBefore = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: localRepo, encoding: 'utf8' }).trim();
execFileSync('git', ['clone', remoteRepo, pusherRepo], { encoding: 'utf8' });
execFileSync('git', ['config', 'user.email', 'test@example.com'], { cwd: pusherRepo, encoding: 'utf8' });
execFileSync('git', ['config', 'user.name', 'Test'], { cwd: pusherRepo, encoding: 'utf8' });
fs.writeFileSync(path.join(pusherRepo, 'UPSTREAM.txt'), 'new commit\n');
execFileSync('git', ['add', 'UPSTREAM.txt'], { cwd: pusherRepo, encoding: 'utf8' });
execFileSync('git', ['commit', '-m', 'upstream update'], { cwd: pusherRepo, encoding: 'utf8' });
execFileSync('git', ['push', 'origin', 'main'], { cwd: pusherRepo, encoding: 'utf8' });
return { localRepo, headBefore };
}
function seedCursorInstallState(projectRoot, headBefore) {
const targetRoot = path.join(projectRoot, '.cursor');
const statePath = path.join(targetRoot, 'ecc-install-state.json');
fs.mkdirSync(targetRoot, { recursive: true });
writeInstallState(statePath, createInstallState({
adapter: { id: 'cursor-project', target: 'cursor', kind: 'project' },
targetRoot,
installStatePath: statePath,
request: {
profile: null,
modules: [],
includeComponents: [],
excludeComponents: [],
legacyLanguages: ['typescript'],
legacyMode: true,
hookConsent: 'declined',
},
resolution: { selectedModules: ['legacy-cursor-install'], skippedModules: [] },
source: { repoVersion: '1.10.0', repoCommit: headBefore, manifestVersion: 1 },
operations: [],
}));
}
function runTests() {
console.log('\n=== Testing auto-update.js ===\n');
@@ -658,6 +709,45 @@ function runTests() {
}
})) passed += 1; else failed += 1;
if (test('global --dry-run skips git pull and previews auto-update without mutating the repo', () => {
const fixture = createTempDir('auto-update-global-dry-run-');
const homeDir = path.join(fixture, 'home');
const projectRoot = path.join(fixture, 'project');
const realRepoRoot = path.resolve(__dirname, '..', '..');
fs.mkdirSync(homeDir);
fs.mkdirSync(projectRoot);
try {
const { localRepo, headBefore } = createBehindRemoteRepoFixture(fixture);
seedCursorInstallState(projectRoot, headBefore);
const inheritedEnv = Object.fromEntries(
Object.entries(process.env).filter(([key]) => key !== 'ECC_DRY_RUN')
);
const baseEnv = { ...inheritedEnv, HOME: homeDir, USERPROFILE: homeDir };
const previewRaw = execFileSync(process.execPath, [
path.join(realRepoRoot, 'scripts', 'ecc.js'),
'--dry-run', 'auto-update', '--target', 'cursor', '--repo-root', localRepo, '--json',
], { cwd: projectRoot, env: baseEnv, encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 });
const preview = JSON.parse(previewRaw);
assert.strictEqual(preview.dryRun, true);
assert.strictEqual(preview.results[0].status, 'planned');
assert.strictEqual(preview.results[0].payload.dryRun, true);
const headAfter = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: localRepo, encoding: 'utf8' }).trim();
assert.strictEqual(headAfter, headBefore);
assert.strictEqual(fs.existsSync(path.join(localRepo, 'UPSTREAM.txt')), false);
assert.throws(
() => execFileSync(process.execPath, [
path.join(realRepoRoot, 'scripts', 'auto-update.js'), '--json',
], { cwd: projectRoot, env: { ...baseEnv, ECC_DRY_RUN: 'yes' }, encoding: 'utf8', stdio: 'pipe' }),
error => /ECC_DRY_RUN must be "1" or "0"/.test(error.stderr)
);
} finally {
cleanup(fixture);
}
})) passed += 1; else failed += 1;
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
process.exit(failed > 0 ? 1 : 0);
}
+39
View File
@@ -301,6 +301,45 @@ test('dry-run JSON emits JSON only and reads inventory without mutation', () =>
});
});
test('global ecc --dry-run setup previews without mutating plugins or settings', () => {
withFixture({}, fixture => {
const inheritedEnv = Object.fromEntries(
Object.entries(process.env).filter(([key]) => key !== 'ECC_DRY_RUN')
);
const env = {
...inheritedEnv,
HOME: fixture.homeDir,
USERPROFILE: fixture.homeDir,
CLAUDE_CONFIG_DIR: fixture.configDir,
PATH: `${fixture.binDir}${path.delimiter}${withoutShadowingClaude(process.env.PATH)}`,
ECC_TEST_CLAUDE_STATE: fixture.statePath,
ECC_TEST_CLAUDE_CALLS: fixture.callsPath,
};
const result = spawnSync(process.execPath, [
eccScript,
'--dry-run',
'setup',
'--mode', 'claude-plugin',
'--scope', 'user',
'--hooks', 'standard',
'--yes',
'--json',
], { cwd: fixture.projectRoot, env, encoding: 'utf8', timeout: 15000 });
assert.strictEqual(result.status, 0, result.stderr);
const payload = JSON.parse(result.stdout);
assert.strictEqual(payload.action, 'would-install');
assert.strictEqual(payload.dryRun, true);
assert.strictEqual(hasMutation(fixture), false);
assert.strictEqual(fs.existsSync(path.join(fixture.configDir, 'settings.json')), false);
const invalid = runSetup(fixture, [
'--mode', 'claude-plugin', '--scope', 'user', '--hooks', 'standard', '--yes',
], { env: { ECC_DRY_RUN: 'yes' } });
assert.strictEqual(invalid.status, 1);
assert.match(invalid.stderr, /ECC_DRY_RUN must be "1" or "0"/);
});
});
test('dry-run leaves a pristine HOME unchanged when Claude inventory creates backups', () => {
withFixture({}, fixture => {
assert.deepStrictEqual(fs.readdirSync(fixture.homeDir), []);