mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-03-30 13:43:26 +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 });
|
||||
try {
|
||||
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}`);
|
||||
} finally {
|
||||
@@ -138,7 +138,7 @@ async function runTests() {
|
||||
|
||||
try {
|
||||
const result = await runScript(path.join(scriptsDir, 'session-start.js'), '', {
|
||||
HOME: isoHome
|
||||
HOME: isoHome, USERPROFILE: isoHome
|
||||
});
|
||||
assert.strictEqual(result.code, 0);
|
||||
// stdout should NOT contain the template content
|
||||
@@ -163,7 +163,7 @@ async function runTests() {
|
||||
|
||||
try {
|
||||
const result = await runScript(path.join(scriptsDir, 'session-start.js'), '', {
|
||||
HOME: isoHome
|
||||
HOME: isoHome, USERPROFILE: isoHome
|
||||
});
|
||||
assert.strictEqual(result.code, 0);
|
||||
assert.ok(
|
||||
@@ -191,7 +191,7 @@ async function runTests() {
|
||||
|
||||
try {
|
||||
const result = await runScript(path.join(scriptsDir, 'session-start.js'), '', {
|
||||
HOME: isoHome
|
||||
HOME: isoHome, USERPROFILE: isoHome
|
||||
});
|
||||
assert.strictEqual(result.code, 0);
|
||||
assert.ok(
|
||||
|
||||
@@ -17,7 +17,9 @@ const os = require('os');
|
||||
const tmpHome = path.join(os.tmpdir(), `ecc-alias-test-${Date.now()}`);
|
||||
fs.mkdirSync(path.join(tmpHome, '.claude'), { recursive: true });
|
||||
const origHome = process.env.HOME;
|
||||
const origUserProfile = process.env.USERPROFILE;
|
||||
process.env.HOME = tmpHome;
|
||||
process.env.USERPROFILE = tmpHome; // Windows: os.homedir() uses USERPROFILE
|
||||
|
||||
const aliases = require('../../scripts/lib/session-aliases');
|
||||
|
||||
@@ -496,8 +498,13 @@ function runTests() {
|
||||
assert.ok(data.metadata.lastUpdated);
|
||||
})) passed++; else failed++;
|
||||
|
||||
// Cleanup
|
||||
// Cleanup — restore both HOME and USERPROFILE (Windows)
|
||||
process.env.HOME = origHome;
|
||||
if (origUserProfile !== undefined) {
|
||||
process.env.USERPROFILE = origUserProfile;
|
||||
} else {
|
||||
delete process.env.USERPROFILE;
|
||||
}
|
||||
try {
|
||||
fs.rmSync(tmpHome, { recursive: true, force: true });
|
||||
} catch {
|
||||
|
||||
@@ -332,10 +332,12 @@ src/main.ts
|
||||
console.log('\ngetAllSessions:');
|
||||
|
||||
// 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 tmpSessionsDir = path.join(tmpHome, '.claude', 'sessions');
|
||||
fs.mkdirSync(tmpSessionsDir, { recursive: true });
|
||||
const origHome = process.env.HOME;
|
||||
const origUserProfile = process.env.USERPROFILE;
|
||||
|
||||
// Create test session files with controlled modification times
|
||||
const testSessions = [
|
||||
@@ -354,6 +356,7 @@ src/main.ts
|
||||
}
|
||||
|
||||
process.env.HOME = tmpHome;
|
||||
process.env.USERPROFILE = tmpHome;
|
||||
|
||||
if (test('getAllSessions returns all sessions', () => {
|
||||
const result = sessionManager.getAllSessions({ limit: 100 });
|
||||
@@ -578,8 +581,13 @@ src/main.ts
|
||||
assert.ok(!isNaN(result.datetime.getTime()), 'datetime should be valid');
|
||||
})) passed++; else failed++;
|
||||
|
||||
// Cleanup
|
||||
// Cleanup — restore both HOME and USERPROFILE (Windows)
|
||||
process.env.HOME = origHome;
|
||||
if (origUserProfile !== undefined) {
|
||||
process.env.USERPROFILE = origUserProfile;
|
||||
} else {
|
||||
delete process.env.USERPROFILE;
|
||||
}
|
||||
try {
|
||||
fs.rmSync(tmpHome, { recursive: true, force: true });
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user