mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-10-27 16:01:54 +00:00
- Moved `withTimeout` implementation to `src/lock-utils.mjs` and exported it correctly. - Removed duplicate local definitions of `withTimeout`, `mergeRelayList`, and `secureRandom` in `src/lock-ops.mjs` and `src/lock-publisher.mjs`. - Fixed imports in `src/lock-ops.mjs`, `src/lock-publisher.mjs`, and `src/relay-health.mjs` to use `src/lock-utils.mjs` consistently. - Updated `test/utils.test.mjs` and `test/utils-async.test.mjs` to fix broken imports and test definitions. - Verified `npm run lock:complete` and `npm run scheduler:daily` execute correctly. - Updated `src/todo/TODO_2026-02-20T03-00-00Z.md` to mark verification task as completed. - Verified `src/relay-health.mjs` does not use `MINUTE_MS` locally, despite mysterious CI error. Confirmed imports are correct. Co-authored-by: PR0M3TH3AN <[email protected]>
110 lines
3.0 KiB
JavaScript
110 lines
3.0 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert';
|
|
import { cmdInit } from '../src/ops.mjs';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
const TEST_DIR = 'test_validation_env';
|
|
|
|
test('cmdInit should validate install directory name', async (t) => {
|
|
if (fs.existsSync(TEST_DIR)) {
|
|
fs.rmSync(TEST_DIR, { recursive: true, force: true });
|
|
}
|
|
fs.mkdirSync(TEST_DIR);
|
|
|
|
const mockPkg = { name: "host", scripts: {} };
|
|
fs.writeFileSync(path.join(TEST_DIR, 'package.json'), JSON.stringify(mockPkg));
|
|
|
|
await t.test('should reject directory with semicolon', async () => {
|
|
await assert.rejects(async () => {
|
|
await cmdInit(false, TEST_DIR, {
|
|
installDir: 'torch; echo pwned',
|
|
namespace: 'ns',
|
|
relays: []
|
|
});
|
|
}, /Invalid directory name/);
|
|
});
|
|
|
|
await t.test('should reject directory with spaces', async () => {
|
|
await assert.rejects(async () => {
|
|
await cmdInit(false, TEST_DIR, {
|
|
installDir: 'torch dir',
|
|
namespace: 'ns',
|
|
relays: []
|
|
});
|
|
}, /Invalid directory name/);
|
|
});
|
|
|
|
await t.test('should reject directory with quotes', async () => {
|
|
await assert.rejects(async () => {
|
|
await cmdInit(false, TEST_DIR, {
|
|
installDir: 'torch"dir',
|
|
namespace: 'ns',
|
|
relays: []
|
|
});
|
|
}, /Invalid directory name/);
|
|
});
|
|
|
|
await t.test('should reject directory with backticks', async () => {
|
|
await assert.rejects(async () => {
|
|
await cmdInit(false, TEST_DIR, {
|
|
installDir: 'torch`dir',
|
|
namespace: 'ns',
|
|
relays: []
|
|
});
|
|
}, /Invalid directory name/);
|
|
});
|
|
|
|
await t.test('should reject directory with $', async () => {
|
|
await assert.rejects(async () => {
|
|
await cmdInit(false, TEST_DIR, {
|
|
installDir: 'torch$dir',
|
|
namespace: 'ns',
|
|
relays: []
|
|
});
|
|
}, /Invalid directory name/);
|
|
});
|
|
|
|
await t.test('should accept valid directory names', async () => {
|
|
try {
|
|
await cmdInit(false, TEST_DIR, {
|
|
installDir: 'valid-dir_123',
|
|
namespace: 'ns',
|
|
relays: []
|
|
});
|
|
} catch (e) {
|
|
// It might fail because of other initialization steps, but shouldn't fail validation
|
|
assert.notMatch(e.message, /Invalid directory name/);
|
|
}
|
|
});
|
|
|
|
await t.test('should accept "."', async () => {
|
|
try {
|
|
await cmdInit(false, TEST_DIR, {
|
|
installDir: '.',
|
|
namespace: 'ns',
|
|
relays: []
|
|
});
|
|
} catch (e) {
|
|
assert.notMatch(e.message, /Invalid directory name/);
|
|
}
|
|
});
|
|
|
|
await t.test('should accept nested paths with slashes', async () => {
|
|
try {
|
|
await cmdInit(false, TEST_DIR, {
|
|
installDir: 'path/to/torch',
|
|
namespace: 'ns',
|
|
relays: []
|
|
});
|
|
} catch (e) {
|
|
assert.notMatch(e.message, /Invalid directory name/);
|
|
}
|
|
});
|
|
|
|
// Cleanup
|
|
if (fs.existsSync(TEST_DIR)) {
|
|
fs.rmSync(TEST_DIR, { recursive: true, force: true });
|
|
}
|
|
});
|