Ensure license server always listens under PM2.

Skip auto-listen only when SKIP_LICENSE_LISTEN is set for tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Ivan Fontosh
2026-06-28 12:54:56 +08:00
parent 5aadc3d3a1
commit 4ac63f2889
2 changed files with 7 additions and 12 deletions
+1 -6
View File
@@ -190,12 +190,7 @@ export function createServer(options = {}) {
}); });
} }
const entryPath = process.argv[1] ? path.resolve(process.argv[1]) : ''; if (!process.env.SKIP_LICENSE_LISTEN) {
const isMain =
entryPath !== '' &&
(fileURLToPath(import.meta.url) === entryPath || entryPath.endsWith(`${path.sep}server.mjs`));
if (isMain) {
const privateKeyPem = process.env.LICENSE_PRIVATE_KEY_PEM; const privateKeyPem = process.env.LICENSE_PRIVATE_KEY_PEM;
if (!privateKeyPem) { if (!privateKeyPem) {
console.error('Задайте LICENSE_PRIVATE_KEY_PEM (PKCS#8 PEM, Ed25519)'); console.error('Задайте LICENSE_PRIVATE_KEY_PEM (PKCS#8 PEM, Ed25519)');
+6 -6
View File
@@ -8,8 +8,6 @@ import { fileURLToPath } from 'node:url';
import { generateKeyPairSync } from 'node:crypto'; import { generateKeyPairSync } from 'node:crypto';
import { createServer } from '../src/server.mjs';
const __dirname = path.dirname(fileURLToPath(import.meta.url)); const __dirname = path.dirname(fileURLToPath(import.meta.url));
const root = path.resolve(__dirname, '..'); const root = path.resolve(__dirname, '..');
@@ -42,7 +40,9 @@ function request(port, method, pathname, { token, body } = {}) {
}); });
} }
function makeServer(dataPath, adminToken = 'test-admin') { async function makeServer(dataPath, adminToken = 'test-admin') {
process.env.SKIP_LICENSE_LISTEN = '1';
const { createServer } = await import('../src/server.mjs');
const { privateKey } = generateKeyPairSync('ed25519'); const { privateKey } = generateKeyPairSync('ed25519');
const pem = privateKey.export({ type: 'pkcs8', format: 'pem' }); const pem = privateKey.export({ type: 'pkcs8', format: 'pem' });
process.env.DND_LICENSE_DATA_PATH = dataPath; process.env.DND_LICENSE_DATA_PATH = dataPath;
@@ -70,7 +70,7 @@ void test('GET /v1/admin/licenses returns enriched product keys', async () => {
}), }),
); );
const { server, adminToken } = makeServer(dataPath); const { server, adminToken } = await makeServer(dataPath);
const port = await listen(server); const port = await listen(server);
try { try {
const res = await request(port, 'GET', '/v1/admin/licenses', { token: adminToken }); const res = await request(port, 'GET', '/v1/admin/licenses', { token: adminToken });
@@ -91,7 +91,7 @@ void test('POST /v1/admin/product-keys creates a new product key', async () => {
const dataPath = path.join(tmp, 'data.json'); const dataPath = path.join(tmp, 'data.json');
fs.copyFileSync(path.join(root, 'data.example.json'), dataPath); fs.copyFileSync(path.join(root, 'data.example.json'), dataPath);
const { server, adminToken } = makeServer(dataPath); const { server, adminToken } = await makeServer(dataPath);
const port = await listen(server); const port = await listen(server);
try { try {
const res = await request(port, 'POST', '/v1/admin/product-keys', { const res = await request(port, 'POST', '/v1/admin/product-keys', {
@@ -118,7 +118,7 @@ void test('admin endpoints reject missing token', async () => {
const dataPath = path.join(tmp, 'data.json'); const dataPath = path.join(tmp, 'data.json');
fs.copyFileSync(path.join(root, 'data.example.json'), dataPath); fs.copyFileSync(path.join(root, 'data.example.json'), dataPath);
const { server } = makeServer(dataPath); const { server } = await makeServer(dataPath);
const port = await listen(server); const port = await listen(server);
try { try {
const res = await request(port, 'GET', '/v1/admin/licenses'); const res = await request(port, 'GET', '/v1/admin/licenses');