mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-12 20:53:34 +08:00
fix: set USERPROFILE in tests for Windows os.homedir() compatibility
On Windows, os.homedir() uses USERPROFILE env var instead of HOME. Tests that override HOME to a temp dir must also set USERPROFILE for the session-manager, session-aliases, and session-start hook tests to find files in the correct directory.
This commit is contained in:
@@ -110,7 +110,7 @@ async function runTests() {
|
|||||||
fs.mkdirSync(path.join(isoHome, '.claude', 'skills', 'learned'), { recursive: true });
|
fs.mkdirSync(path.join(isoHome, '.claude', 'skills', 'learned'), { recursive: true });
|
||||||
try {
|
try {
|
||||||
const result = await runScript(path.join(scriptsDir, 'session-start.js'), '', {
|
const result = await runScript(path.join(scriptsDir, 'session-start.js'), '', {
|
||||||
HOME: isoHome
|
HOME: isoHome, USERPROFILE: isoHome
|
||||||
});
|
});
|
||||||
assert.strictEqual(result.code, 0, `Exit code should be 0, got ${result.code}`);
|
assert.strictEqual(result.code, 0, `Exit code should be 0, got ${result.code}`);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -138,7 +138,7 @@ async function runTests() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await runScript(path.join(scriptsDir, 'session-start.js'), '', {
|
const result = await runScript(path.join(scriptsDir, 'session-start.js'), '', {
|
||||||
HOME: isoHome
|
HOME: isoHome, USERPROFILE: isoHome
|
||||||
});
|
});
|
||||||
assert.strictEqual(result.code, 0);
|
assert.strictEqual(result.code, 0);
|
||||||
// stdout should NOT contain the template content
|
// stdout should NOT contain the template content
|
||||||
@@ -163,7 +163,7 @@ async function runTests() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await runScript(path.join(scriptsDir, 'session-start.js'), '', {
|
const result = await runScript(path.join(scriptsDir, 'session-start.js'), '', {
|
||||||
HOME: isoHome
|
HOME: isoHome, USERPROFILE: isoHome
|
||||||
});
|
});
|
||||||
assert.strictEqual(result.code, 0);
|
assert.strictEqual(result.code, 0);
|
||||||
assert.ok(
|
assert.ok(
|
||||||
@@ -191,7 +191,7 @@ async function runTests() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await runScript(path.join(scriptsDir, 'session-start.js'), '', {
|
const result = await runScript(path.join(scriptsDir, 'session-start.js'), '', {
|
||||||
HOME: isoHome
|
HOME: isoHome, USERPROFILE: isoHome
|
||||||
});
|
});
|
||||||
assert.strictEqual(result.code, 0);
|
assert.strictEqual(result.code, 0);
|
||||||
assert.ok(
|
assert.ok(
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ const os = require('os');
|
|||||||
const tmpHome = path.join(os.tmpdir(), `ecc-alias-test-${Date.now()}`);
|
const tmpHome = path.join(os.tmpdir(), `ecc-alias-test-${Date.now()}`);
|
||||||
fs.mkdirSync(path.join(tmpHome, '.claude'), { recursive: true });
|
fs.mkdirSync(path.join(tmpHome, '.claude'), { recursive: true });
|
||||||
const origHome = process.env.HOME;
|
const origHome = process.env.HOME;
|
||||||
|
const origUserProfile = process.env.USERPROFILE;
|
||||||
process.env.HOME = tmpHome;
|
process.env.HOME = tmpHome;
|
||||||
|
process.env.USERPROFILE = tmpHome; // Windows: os.homedir() uses USERPROFILE
|
||||||
|
|
||||||
const aliases = require('../../scripts/lib/session-aliases');
|
const aliases = require('../../scripts/lib/session-aliases');
|
||||||
|
|
||||||
@@ -496,8 +498,13 @@ function runTests() {
|
|||||||
assert.ok(data.metadata.lastUpdated);
|
assert.ok(data.metadata.lastUpdated);
|
||||||
})) passed++; else failed++;
|
})) passed++; else failed++;
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup — restore both HOME and USERPROFILE (Windows)
|
||||||
process.env.HOME = origHome;
|
process.env.HOME = origHome;
|
||||||
|
if (origUserProfile !== undefined) {
|
||||||
|
process.env.USERPROFILE = origUserProfile;
|
||||||
|
} else {
|
||||||
|
delete process.env.USERPROFILE;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
fs.rmSync(tmpHome, { recursive: true, force: true });
|
fs.rmSync(tmpHome, { recursive: true, force: true });
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -332,10 +332,12 @@ src/main.ts
|
|||||||
console.log('\ngetAllSessions:');
|
console.log('\ngetAllSessions:');
|
||||||
|
|
||||||
// Override HOME to a temp dir for isolated getAllSessions/getSessionById tests
|
// Override HOME to a temp dir for isolated getAllSessions/getSessionById tests
|
||||||
|
// On Windows, os.homedir() uses USERPROFILE, not HOME — set both for cross-platform
|
||||||
const tmpHome = path.join(os.tmpdir(), `ecc-session-mgr-test-${Date.now()}`);
|
const tmpHome = path.join(os.tmpdir(), `ecc-session-mgr-test-${Date.now()}`);
|
||||||
const tmpSessionsDir = path.join(tmpHome, '.claude', 'sessions');
|
const tmpSessionsDir = path.join(tmpHome, '.claude', 'sessions');
|
||||||
fs.mkdirSync(tmpSessionsDir, { recursive: true });
|
fs.mkdirSync(tmpSessionsDir, { recursive: true });
|
||||||
const origHome = process.env.HOME;
|
const origHome = process.env.HOME;
|
||||||
|
const origUserProfile = process.env.USERPROFILE;
|
||||||
|
|
||||||
// Create test session files with controlled modification times
|
// Create test session files with controlled modification times
|
||||||
const testSessions = [
|
const testSessions = [
|
||||||
@@ -354,6 +356,7 @@ src/main.ts
|
|||||||
}
|
}
|
||||||
|
|
||||||
process.env.HOME = tmpHome;
|
process.env.HOME = tmpHome;
|
||||||
|
process.env.USERPROFILE = tmpHome;
|
||||||
|
|
||||||
if (test('getAllSessions returns all sessions', () => {
|
if (test('getAllSessions returns all sessions', () => {
|
||||||
const result = sessionManager.getAllSessions({ limit: 100 });
|
const result = sessionManager.getAllSessions({ limit: 100 });
|
||||||
@@ -578,8 +581,13 @@ src/main.ts
|
|||||||
assert.ok(!isNaN(result.datetime.getTime()), 'datetime should be valid');
|
assert.ok(!isNaN(result.datetime.getTime()), 'datetime should be valid');
|
||||||
})) passed++; else failed++;
|
})) passed++; else failed++;
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup — restore both HOME and USERPROFILE (Windows)
|
||||||
process.env.HOME = origHome;
|
process.env.HOME = origHome;
|
||||||
|
if (origUserProfile !== undefined) {
|
||||||
|
process.env.USERPROFILE = origUserProfile;
|
||||||
|
} else {
|
||||||
|
delete process.env.USERPROFILE;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
fs.rmSync(tmpHome, { recursive: true, force: true });
|
fs.rmSync(tmpHome, { recursive: true, force: true });
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Reference in New Issue
Block a user