Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"a2a:export": "node scripts/a2a_export.js",
"a2a:ingest": "node scripts/a2a_ingest.js",
"a2a:promote": "node scripts/a2a_promote.js",
"test": "node -e \"const fs=require('fs'),cp=require('child_process');const skip=new Set(['solidifyIntegration.test.js','proxyTracePlatformInstall.test.js','spawnReplacementProcess.test.js']);const all=fs.readdirSync('test').filter(f=>f.endsWith('.test.js')&&!skip.has(f));const iso=new Set(['solidifyIntegration.test.js']);const others=all.filter(f=>!iso.has(f)).map(f=>'test/'+f);const isoFiles=all.filter(f=>iso.has(f)).map(f=>'test/'+f);if(others.length)cp.execSync('node --test '+others.join(' '),{stdio:'inherit'});if(isoFiles.length)cp.execSync('node --test '+isoFiles.join(' '),{stdio:'inherit'})\""
"test": "node scripts/run-tests.js"
},
"engines": {
"node": ">=22.12"
Expand Down
38 changes: 38 additions & 0 deletions scripts/run-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

const fs = require('fs');
const path = require('path');
const { spawnSync } = require('child_process');

const repoRoot = path.resolve(__dirname, '..');
const testDir = path.join(repoRoot, 'test');
const setupFile = path.join(testDir, 'setup.js');
const skipped = new Set([
'solidifyIntegration.test.js',
'proxyTracePlatformInstall.test.js',
'spawnReplacementProcess.test.js',
]);

const testFiles = fs.readdirSync(testDir)
.filter((file) => file.endsWith('.test.js') && !skipped.has(file))
.sort()
.map((file) => path.join('test', file));

const result = spawnSync(process.execPath, [
'--require',
setupFile,
'--test',
...testFiles,
], {
cwd: repoRoot,
env: { ...process.env, NODE_ENV: 'test' },
stdio: 'inherit',
});

if (result.error) throw result.error;
if (result.signal) {
console.error(`Test process terminated by ${result.signal}`);
process.exitCode = 1;
} else {
process.exitCode = result.status === null ? 1 : result.status;
}
6 changes: 3 additions & 3 deletions test/atpProxyRouting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('ATP hubClient proxy routing (regression #460 Bug 2)', () => {
const ENV_KEYS = [
'EVOMAP_PROXY', 'A2A_TRANSPORT', 'A2A_HUB_URL', 'A2A_NODE_ID',
'A2A_NODE_SECRET', 'EVOMAP_PROXY_PORT', 'EVOMAP_HUB_ALLOW_INSECURE',
'EVOLVER_SETTINGS_DIR',
];

before(async () => {
Expand Down Expand Up @@ -93,6 +94,7 @@ describe('ATP hubClient proxy routing (regression #460 Bug 2)', () => {
tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), 'evomap-atp-route-'));
process.env.HOME = tmpHome;
process.env.USERPROFILE = tmpHome;
process.env.EVOLVER_SETTINGS_DIR = path.join(tmpHome, '.evolver');

// Seed A2A env so hubClient can call getNodeId / buildHubHeaders without
// touching the filesystem persist path. We mint a fresh 64-hex secret
Expand Down Expand Up @@ -129,9 +131,7 @@ describe('ATP hubClient proxy routing (regression #460 Bug 2)', () => {
});

function writeProxySettings(url) {
// settings.js uses os.homedir()/.evolver/settings.json. os.homedir()
// on linux reads $HOME which we've swapped to tmpHome above.
const settingsDir = path.join(tmpHome, '.evolver');
const settingsDir = process.env.EVOLVER_SETTINGS_DIR;
fs.mkdirSync(settingsDir, { recursive: true });
fs.writeFileSync(path.join(settingsDir, 'settings.json'), JSON.stringify({
proxy: { url, pid: process.pid, started_at: new Date().toISOString() },
Expand Down
18 changes: 18 additions & 0 deletions test/fixtures/homeIsolationProbe.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

const assert = require('node:assert/strict');
const fs = require('fs');
const path = require('path');
const test = require('node:test');

test('runs with isolated user state', () => {
const parentHome = process.env.EVOLVER_TEST_PARENT_HOME;
assert.ok(parentHome);
assert.notEqual(process.env.HOME, parentHome);
assert.notEqual(process.env.USERPROFILE, parentHome);
assert.notEqual(process.env.EVOLVER_HOME, path.join(parentHome, '.evomap'));
assert.notEqual(process.env.EVOLVER_SETTINGS_DIR, path.join(parentHome, '.evolver'));

fs.mkdirSync(process.env.EVOLVER_HOME, { recursive: true });
fs.writeFileSync(path.join(process.env.EVOLVER_HOME, 'node_secret'), 'test-only');
});
18 changes: 18 additions & 0 deletions test/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

const fs = require('fs');
const os = require('os');
const path = require('path');

if (process.env.NODE_TEST_CONTEXT) {
const testHome = fs.mkdtempSync(path.join(os.tmpdir(), 'evolver-test-home-'));

process.env.HOME = testHome;
process.env.USERPROFILE = testHome;
process.env.EVOLVER_HOME = path.join(testHome, '.evomap');
process.env.EVOLVER_SETTINGS_DIR = path.join(testHome, '.evolver');

process.on('exit', () => {
try { fs.rmSync(testHome, { recursive: true, force: true }); } catch {}
});
}
49 changes: 49 additions & 0 deletions test/testHomeIsolation.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict';

const assert = require('node:assert/strict');
const fs = require('fs');
const os = require('os');
const path = require('path');
const { spawnSync } = require('child_process');
const test = require('node:test');

test('npm test preloads the isolation setup through the suite runner', () => {
const repoRoot = path.resolve(__dirname, '..');
const packageJson = JSON.parse(fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8'));
const runner = fs.readFileSync(path.join(repoRoot, 'scripts', 'run-tests.js'), 'utf8');

assert.equal(packageJson.scripts.test, 'node scripts/run-tests.js');
assert.match(runner, /spawnSync\(process\.execPath/);
assert.match(runner, /'--require',\s*setupFile,\s*'--test'/);
});

test('test setup keeps identity files out of the parent home', () => {
const parentHome = fs.mkdtempSync(path.join(os.tmpdir(), 'evolver-parent-home-'));
const repoRoot = path.resolve(__dirname, '..');

try {
const result = spawnSync(process.execPath, [
'--require',
path.join(repoRoot, 'test', 'setup.js'),
'--test',
path.join(repoRoot, 'test', 'fixtures', 'homeIsolationProbe.test.js'),
], {
cwd: repoRoot,
encoding: 'utf8',
env: {
...process.env,
HOME: parentHome,
USERPROFILE: parentHome,
EVOLVER_HOME: path.join(parentHome, '.evomap'),
EVOLVER_SETTINGS_DIR: path.join(parentHome, '.evolver'),
EVOLVER_TEST_PARENT_HOME: parentHome,
},
});

assert.equal(result.status, 0, result.stdout + result.stderr);
assert.equal(fs.existsSync(path.join(parentHome, '.evomap')), false);
assert.equal(fs.existsSync(path.join(parentHome, '.evolver')), false);
} finally {
fs.rmSync(parentHome, { recursive: true, force: true });
}
});
Loading