Skip to content
Closed
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
22 changes: 17 additions & 5 deletions scripts/validate-suite.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
// Usage: node scripts/validate-suite.js [test-glob-pattern]
// Runs the evolver test suite -- repo root is derived from script location, no shell glob needed.
const { execSync } = require('child_process');
const { execFileSync } = require('child_process');
const path = require('path');
const fs = require('fs');

const EVOLVER_REPO_ROOT = path.join(__dirname, '..');
const pattern = process.argv[2] || 'test/*.test.js';

function expandTestGlob(repoRoot, pat) {
const dir = pat.replace(/\/\*\.test\.js$/, '');
const fullPattern = path.isAbsolute(pat) ? pat : path.join(repoRoot, pat);
if (fs.existsSync(fullPattern) && fs.statSync(fullPattern).isFile()) {
return fullPattern.endsWith('.test.js') ? [fullPattern] : [];
}

const dir = path.dirname(pat);
const basenamePattern = path.basename(pat);
const fullDir = path.isAbsolute(dir) ? dir : path.join(repoRoot, dir);
if (!fs.existsSync(fullDir) || !fs.statSync(fullDir).isDirectory()) return [];

const escaped = basenamePattern
.replace(/[.+?^${}()|[\]\\]/g, '\\$&')
.replace(/\*/g, '.*');
const matcher = new RegExp('^' + escaped + '$');
return fs.readdirSync(fullDir)
.filter(f => f.endsWith('.test.js'))
.filter(f => f.endsWith('.test.js') && matcher.test(f))
.map(f => path.join(fullDir, f))
.sort();
}
Expand All @@ -22,17 +34,17 @@ if (files.length === 0) {
process.exit(1);
}

const cmd = 'node --test ' + files.join(' ');
const env = Object.assign({}, process.env, {
NODE_ENV: 'test',
EVOLVER_REPO_ROOT,
GEP_ASSETS_DIR: path.join(EVOLVER_REPO_ROOT, 'assets', 'gep'),
});
delete env.EVOLVE_BRIDGE;
delete env.OPENCLAW_WORKSPACE;
delete env.NODE_TEST_CONTEXT;

try {
const output = execSync(cmd, {
const output = execFileSync(process.execPath, ['--test', ...files], {
cwd: EVOLVER_REPO_ROOT,
stdio: ['pipe', 'pipe', 'pipe'],
timeout: 180000,
Expand Down
21 changes: 21 additions & 0 deletions test/validateSuite.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

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

const repoRoot = path.join(__dirname, '..');

test('validate-suite accepts a single test file argument', () => {
const output = execFileSync(process.execPath, [
'scripts/validate-suite.js',
'test/mailboxStore.test.js',
], {
cwd: repoRoot,
encoding: 'utf8',
timeout: 30_000,
});

assert.match(output, /ok: \d+ test\(s\) passed, 0 failed/);
});