Skip to content

armgit / ECC

Public Imported from GitHub
0

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

test: add --global success, bare PM name, and source label tests (Round 62)

Affaan Mustafa85a86f67471d
diff --git a/tests/scripts/setup-package-manager.test.js b/tests/scripts/setup-package-manager.test.js
index 48a1953b1..25861d21c 100644
--- a/tests/scripts/setup-package-manager.test.js
+++ b/tests/scripts/setup-package-manager.test.js
@@ -8,6 +8,8 @@
const assert = require('assert');
const path = require('path');
+const fs = require('fs');
+const os = require('os');
const { execFileSync } = require('child_process');
const SCRIPT = path.join(__dirname, '..', '..', 'scripts', 'setup-package-manager.js');
@@ -256,6 +258,54 @@ function runTests() {
assert.strictEqual(installCount, 4, `Expected 4 "Install:" entries, found ${installCount}`);
})) passed++; else failed++;
+ // ── Round 62: --global success path and bare PM name ──
+ console.log('\n--global success path (Round 62):');
+
+ if (test('--global npm writes config and succeeds', () => {
+ const tmpDir = path.join(os.tmpdir(), `spm-test-global-${Date.now()}`);
+ fs.mkdirSync(tmpDir, { recursive: true });
+ try {
+ const result = run(['--global', 'npm'], { HOME: tmpDir, USERPROFILE: tmpDir });
+ assert.strictEqual(result.code, 0, `Expected exit 0, got ${result.code}. stderr: ${result.stderr}`);
+ assert.ok(result.stdout.includes('Global preference set to'), 'Should show success message');
+ assert.ok(result.stdout.includes('npm'), 'Should mention npm');
+ // Verify config file was created
+ const configPath = path.join(tmpDir, '.claude', 'package-manager.json');
+ assert.ok(fs.existsSync(configPath), 'Config file should be created');
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
+ assert.strictEqual(config.packageManager, 'npm', 'Config should contain npm');
+ } finally {
+ fs.rmSync(tmpDir, { recursive: true, force: true });
+ }
+ })) passed++; else failed++;
+
+ console.log('\nbare PM name success (Round 62):');
+
+ if (test('bare npm sets global preference and succeeds', () => {
+ const tmpDir = path.join(os.tmpdir(), `spm-test-bare-${Date.now()}`);
+ fs.mkdirSync(tmpDir, { recursive: true });
+ try {
+ const result = run(['npm'], { HOME: tmpDir, USERPROFILE: tmpDir });
+ assert.strictEqual(result.code, 0, `Expected exit 0, got ${result.code}. stderr: ${result.stderr}`);
+ assert.ok(result.stdout.includes('Global preference set to'), 'Should show success message');
+ // Verify config file was created
+ const configPath = path.join(tmpDir, '.claude', 'package-manager.json');
+ assert.ok(fs.existsSync(configPath), 'Config file should be created');
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
+ assert.strictEqual(config.packageManager, 'npm', 'Config should contain npm');
+ } finally {
+ fs.rmSync(tmpDir, { recursive: true, force: true });
+ }
+ })) passed++; else failed++;
+
+ console.log('\n--detect source label (Round 62):');
+
+ if (test('--detect with env var shows source as environment', () => {
+ const result = run(['--detect'], { CLAUDE_PACKAGE_MANAGER: 'pnpm' });
+ assert.strictEqual(result.code, 0);
+ assert.ok(result.stdout.includes('Source: environment'), 'Should show environment as source');
+ })) passed++; else failed++;
+
// Summary
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
process.exit(failed > 0 ? 1 : 0);