mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 01:39:52 +08:00
feat(cron): expose run receipts and modularize execution
Return committed trigger IDs and add CLI wait and trigger-specific logs while preserving API, CLI, transaction, deduplication and unknown-result semantics. Move scheduling, lifecycle, settlement, queries and legacy adapters into back/cron; remove obsolete internal import paths and circular dependencies. Apply project formatting across the repository, cover CJS/MJS in formatting hooks, add prettier:check and require formatting checks in AGENTS.md. Validation: backend build; 1398 backend/frontend tests passed (17 platform skips); 327 CLI tests passed (6 platform skips); 670 files pass format checks.
This commit is contained in:
1 parent
77ece406ac
commit
c5458596c8
346 files changed
+32133
-11556
No files matched your search
@@ -106,6 +106,8 @@ assert.equal(process.env.QL_PANEL_INTEGRATION, '1');
|
||||
await fs.rm(foreignRoot, { recursive: true, force: true });
|
||||
}
|
||||
})().catch(() => {
|
||||
console.error('Bot installation integration test failed; raw subprocess errors are omitted to protect environment credentials.');
|
||||
console.error(
|
||||
'Bot installation integration test failed; raw subprocess errors are omitted to protect environment credentials.',
|
||||
);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
@@ -5,8 +5,12 @@ const path = require('node:path');
|
||||
const os = require('node:os');
|
||||
const { setTimeout: delay } = require('node:timers/promises');
|
||||
const { createContext } = require('../../dist/internal/runtime/context');
|
||||
const { runContainer } = require('../../dist/internal/runtime/containerRuntime');
|
||||
const { launchStartupHook } = require('../../dist/internal/maintenance/bootstrap');
|
||||
const {
|
||||
runContainer,
|
||||
} = require('../../dist/internal/runtime/containerRuntime');
|
||||
const {
|
||||
launchStartupHook,
|
||||
} = require('../../dist/internal/maintenance/bootstrap');
|
||||
const { launchBot } = require('../../dist/internal/maintenance/bot');
|
||||
|
||||
const live = (pid) => {
|
||||
|
||||
@@ -36,7 +36,12 @@ const { LocalApi } = require('../../dist/internal/runtime/api');
|
||||
{ stdio: 'pipe' },
|
||||
);
|
||||
const nginxPid = Number(
|
||||
(await fs.readFile(systemd ? '/run/nginx.pid' : '/run/nginx/nginx.pid', 'utf8')).trim(),
|
||||
(
|
||||
await fs.readFile(
|
||||
systemd ? '/run/nginx.pid' : '/run/nginx/nginx.pid',
|
||||
'utf8',
|
||||
)
|
||||
).trim(),
|
||||
);
|
||||
assert.ok(Number.isSafeInteger(nginxPid) && nginxPid > 1);
|
||||
process.kill(nginxPid, 0);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs/promises');
|
||||
const { spawnSync } = require('node:child_process');
|
||||
const { createContext } = require('/opt/qinglong-cli/dist/internal/runtime/context');
|
||||
const {
|
||||
createContext,
|
||||
} = require('/opt/qinglong-cli/dist/internal/runtime/context');
|
||||
const { LocalApi } = require('/opt/qinglong-cli/dist/internal/runtime/api');
|
||||
assert.equal(process.env.QL_PANEL_INTEGRATION, '1');
|
||||
(async () => {
|
||||
|
||||
@@ -2,7 +2,10 @@ process.channel.ref();
|
||||
// Child fixture: real service startup pauses at a deterministic cancellation boundary.
|
||||
const { createContext } = require('../../dist/internal/runtime/context');
|
||||
const { replaceAndReload } = require('../../dist/internal/maintenance/upgrade');
|
||||
const { startPanel, stopPanel } = require('../../dist/internal/maintenance/operator');
|
||||
const {
|
||||
startPanel,
|
||||
stopPanel,
|
||||
} = require('../../dist/internal/maintenance/operator');
|
||||
const {
|
||||
withCommandCancellation,
|
||||
cancellableOperation,
|
||||
|
||||
@@ -4,7 +4,10 @@ const fs = require('node:fs/promises');
|
||||
const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
const { createContext } = require('../../dist/internal/runtime/context');
|
||||
const { startPanel, stopPanel } = require('../../dist/internal/maintenance/operator');
|
||||
const {
|
||||
startPanel,
|
||||
stopPanel,
|
||||
} = require('../../dist/internal/maintenance/operator');
|
||||
const { reloadPanel } = require('../../dist/internal/maintenance/upgrade');
|
||||
|
||||
test(
|
||||
|
||||
+181
-32
@@ -9,53 +9,202 @@ const fs = require('node:fs/promises');
|
||||
assert.equal(process.env.QL_PANEL_INTEGRATION, '1');
|
||||
const url = 'http://127.0.0.1:5700';
|
||||
const api = async (route, method = 'GET', body) => {
|
||||
const response = await fetch(url + '/api/' + route, { method,
|
||||
headers: { 'content-type': 'application/json' }, body: body === undefined ? undefined : JSON.stringify(body) });
|
||||
const result = await response.json(); assert.equal(result.code, 200); return result.data;
|
||||
const response = await fetch(url + '/api/' + route, {
|
||||
method,
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
});
|
||||
const result = await response.json();
|
||||
assert.equal(result.code, 200);
|
||||
return result.data;
|
||||
};
|
||||
const info = await api('system');
|
||||
assert.equal(info.isInitialized, false, 'Refuse initialized panels');
|
||||
const credentials = {
|
||||
username: 'fixture-' + randomUUID(),
|
||||
password: randomUUID(),
|
||||
};
|
||||
const info = await api('system'); assert.equal(info.isInitialized, false, 'Refuse initialized panels');
|
||||
const credentials = { username: 'fixture-' + randomUUID(), password: randomUUID() };
|
||||
await api('user/init', 'PUT', credentials);
|
||||
const owner = (await api('user/login', 'POST', credentials)).token;
|
||||
const config = '/tmp/ql-openapi-auth.json';
|
||||
const entry = path.resolve(__dirname, '../../dist/npm/ql.js');
|
||||
const cli = (args, ownerMode = false, extra = {}) => {
|
||||
const result = spawnSync(process.execPath, [entry, ...args, '--json'], {
|
||||
encoding: 'utf8', timeout: 30000,
|
||||
env: { ...process.env, QL_CLI_CONFIG: config, QL_URL: ownerMode ? url : '', QL_ACCESS_TOKEN: ownerMode ? owner : '', ...extra },
|
||||
encoding: 'utf8',
|
||||
timeout: 30000,
|
||||
env: {
|
||||
...process.env,
|
||||
QL_CLI_CONFIG: config,
|
||||
QL_URL: ownerMode ? url : '',
|
||||
QL_ACCESS_TOKEN: ownerMode ? owner : '',
|
||||
...extra,
|
||||
},
|
||||
});
|
||||
// Report only the command name, never request bodies or application credentials.
|
||||
assert.equal(result.status, 0, args.slice(0, 2).join(' ') + ': ' + result.stderr);
|
||||
assert.equal(
|
||||
result.status,
|
||||
0,
|
||||
args.slice(0, 2).join(' ') + ': ' + result.stderr,
|
||||
);
|
||||
return JSON.parse(result.stdout).data;
|
||||
};
|
||||
const app = cli(['app', 'create', '--name', 'cli-fixture', '--scopes', 'crons,subscriptions,envs,configs,scripts,logs,dependencies,system,dashboard', '--show-secrets'], true);
|
||||
const app = cli(
|
||||
[
|
||||
'app',
|
||||
'create',
|
||||
'--name',
|
||||
'cli-fixture',
|
||||
'--scopes',
|
||||
'crons,subscriptions,envs,configs,scripts,logs,dependencies,system,dashboard',
|
||||
'--show-secrets',
|
||||
],
|
||||
true,
|
||||
);
|
||||
assert.ok(app.client_id && app.client_secret);
|
||||
cli(['login', '--url', url], false, { QL_CLIENT_ID: app.client_id, QL_CLIENT_SECRET: app.client_secret });
|
||||
cli(['login', '--url', url], false, {
|
||||
QL_CLIENT_ID: app.client_id,
|
||||
QL_CLIENT_SECRET: app.client_secret,
|
||||
});
|
||||
cli(['auth', 'status', '--scope', 'crons']);
|
||||
cli(['app', 'update', String(app.id), '--name', 'cli-updated', '--scopes', 'crons,subscriptions,envs,configs,scripts,logs,dependencies,system,dashboard'], true);
|
||||
assert.ok(cli(['app', 'list'], true).every(item => !('client_secret' in item) && !('tokens' in item)));
|
||||
const task = cli(['task', 'create', '--name', 'cli-task', '--command', 'echo OPENAPI_FIXTURE', '--schedule', '0 0 * * *']);
|
||||
cli(['task', 'update', String(task.id), '--name', 'cli-task-updated', '--command', 'echo OPENAPI_UPDATED', '--schedule', '0 1 * * *']);
|
||||
cli(['task', 'disable', String(task.id)]); cli(['task', 'enable', String(task.id)]);
|
||||
cli(
|
||||
[
|
||||
'app',
|
||||
'update',
|
||||
String(app.id),
|
||||
'--name',
|
||||
'cli-updated',
|
||||
'--scopes',
|
||||
'crons,subscriptions,envs,configs,scripts,logs,dependencies,system,dashboard',
|
||||
],
|
||||
true,
|
||||
);
|
||||
assert.ok(
|
||||
cli(['app', 'list'], true).every(
|
||||
(item) => !('client_secret' in item) && !('tokens' in item),
|
||||
),
|
||||
);
|
||||
const task = cli([
|
||||
'task',
|
||||
'create',
|
||||
'--name',
|
||||
'cli-task',
|
||||
'--command',
|
||||
'echo OPENAPI_FIXTURE',
|
||||
'--schedule',
|
||||
'0 0 * * *',
|
||||
]);
|
||||
cli([
|
||||
'task',
|
||||
'update',
|
||||
String(task.id),
|
||||
'--name',
|
||||
'cli-task-updated',
|
||||
'--command',
|
||||
'echo OPENAPI_UPDATED',
|
||||
'--schedule',
|
||||
'0 1 * * *',
|
||||
]);
|
||||
cli(['task', 'disable', String(task.id)]);
|
||||
cli(['task', 'enable', String(task.id)]);
|
||||
assert.equal(cli(['task', 'get', String(task.id)]).name, 'cli-task-updated');
|
||||
const sub = cli(['subscription', 'create', '--type', 'file', '--url', url + '/fixture.js', '--alias', 'cli-sub', '--schedule-type', 'crontab', '--schedule', '0 0 * * *']);
|
||||
cli(['subscription', 'update', String(sub.id), '--data', JSON.stringify({ type: 'file', url: url + '/fixture.js', alias: 'cli-sub', name: 'cli-sub-updated', schedule_type: 'crontab', schedule: '0 1 * * *' })]);
|
||||
cli(['subscription', 'disable', String(sub.id)]); cli(['subscription', 'enable', String(sub.id)]);
|
||||
assert.equal(cli(['subscription', 'get', String(sub.id)]).name, 'cli-sub-updated');
|
||||
const env = cli(['env', 'create', '--data', '[{"name":"CLI_FIXTURE","value":"one"}]'])[0];
|
||||
cli(['env', 'update', String(env.id), '--data', '{"name":"CLI_FIXTURE","value":"two"}']);
|
||||
const sub = cli([
|
||||
'subscription',
|
||||
'create',
|
||||
'--type',
|
||||
'file',
|
||||
'--url',
|
||||
url + '/fixture.js',
|
||||
'--alias',
|
||||
'cli-sub',
|
||||
'--schedule-type',
|
||||
'crontab',
|
||||
'--schedule',
|
||||
'0 0 * * *',
|
||||
]);
|
||||
cli([
|
||||
'subscription',
|
||||
'update',
|
||||
String(sub.id),
|
||||
'--data',
|
||||
JSON.stringify({
|
||||
type: 'file',
|
||||
url: url + '/fixture.js',
|
||||
alias: 'cli-sub',
|
||||
name: 'cli-sub-updated',
|
||||
schedule_type: 'crontab',
|
||||
schedule: '0 1 * * *',
|
||||
}),
|
||||
]);
|
||||
cli(['subscription', 'disable', String(sub.id)]);
|
||||
cli(['subscription', 'enable', String(sub.id)]);
|
||||
assert.equal(
|
||||
cli(['subscription', 'get', String(sub.id)]).name,
|
||||
'cli-sub-updated',
|
||||
);
|
||||
const env = cli([
|
||||
'env',
|
||||
'create',
|
||||
'--data',
|
||||
'[{"name":"CLI_FIXTURE","value":"one"}]',
|
||||
])[0];
|
||||
cli([
|
||||
'env',
|
||||
'update',
|
||||
String(env.id),
|
||||
'--data',
|
||||
'{"name":"CLI_FIXTURE","value":"two"}',
|
||||
]);
|
||||
assert.equal(cli(['env', 'get', String(env.id)]).value, 'two');
|
||||
cli(['env', 'delete', String(env.id)]);
|
||||
cli(['script', 'create', '--data', '{"filename":"cli-openapi.js","content":"console.log(1)","path":""}']);
|
||||
assert.equal(cli(['script', 'get', '--query', '{"file":"cli-openapi.js"}']), 'console.log(1)');
|
||||
cli(['config', 'save', '--data', '{"name":"cli-openapi.sh","content":"# fixture"}']);
|
||||
assert.equal(cli(['config', 'get', '--query', '{"path":"cli-openapi.sh"}']), '# fixture');
|
||||
cli(['log', 'list']); cli(['dependency', 'list']);
|
||||
cli(['task', 'delete', String(task.id)]); cli(['subscription', 'delete', String(sub.id)]);
|
||||
const reset = cli(['app', 'reset-secret', String(app.id), '--show-secrets'], true);
|
||||
cli([
|
||||
'script',
|
||||
'create',
|
||||
'--data',
|
||||
'{"filename":"cli-openapi.js","content":"console.log(1)","path":""}',
|
||||
]);
|
||||
assert.equal(
|
||||
cli(['script', 'get', '--query', '{"file":"cli-openapi.js"}']),
|
||||
'console.log(1)',
|
||||
);
|
||||
cli([
|
||||
'config',
|
||||
'save',
|
||||
'--data',
|
||||
'{"name":"cli-openapi.sh","content":"# fixture"}',
|
||||
]);
|
||||
assert.equal(
|
||||
cli(['config', 'get', '--query', '{"path":"cli-openapi.sh"}']),
|
||||
'# fixture',
|
||||
);
|
||||
cli(['log', 'list']);
|
||||
cli(['dependency', 'list']);
|
||||
cli(['task', 'delete', String(task.id)]);
|
||||
cli(['subscription', 'delete', String(sub.id)]);
|
||||
const reset = cli(
|
||||
['app', 'reset-secret', String(app.id), '--show-secrets'],
|
||||
true,
|
||||
);
|
||||
assert.ok(reset.client_secret !== app.client_secret);
|
||||
cli(['login', '--url', url], false, { QL_CLIENT_ID: app.client_id, QL_CLIENT_SECRET: reset.client_secret });
|
||||
cli(['auth', 'status']); cli(['app', 'delete', String(app.id)], true);
|
||||
cli(['login', '--url', url], false, {
|
||||
QL_CLIENT_ID: app.client_id,
|
||||
QL_CLIENT_SECRET: reset.client_secret,
|
||||
});
|
||||
cli(['auth', 'status']);
|
||||
cli(['app', 'delete', String(app.id)], true);
|
||||
await fs.rm(config, { force: true });
|
||||
console.log(JSON.stringify({ panelVersion: info.version, taskCrud: true, subscriptionCrud: true, appCrudAndSecretRotation: true, envCrud: true, scriptCreateRead: true, configSaveRead: true, logAndDependencyRead: true }));
|
||||
})().catch(error => { console.error(error.message); process.exitCode = 1; });
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
panelVersion: info.version,
|
||||
taskCrud: true,
|
||||
subscriptionCrud: true,
|
||||
appCrudAndSecretRotation: true,
|
||||
envCrud: true,
|
||||
scriptCreateRead: true,
|
||||
configSaveRead: true,
|
||||
logAndDependencyRead: true,
|
||||
}),
|
||||
);
|
||||
})().catch((error) => {
|
||||
console.error(error.message);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
@@ -38,7 +38,11 @@ exports.verifyAccountMaintenance = async function verifyAccountMaintenance(
|
||||
assert.equal((await login()).code, 200, 'New credentials were not saved');
|
||||
const incorrect = randomUUID();
|
||||
for (let attempt = 0; attempt < 3; attempt++) {
|
||||
assert.equal((await login(incorrect)).code, 400, 'Expected a rejected password before throttling');
|
||||
assert.equal(
|
||||
(await login(incorrect)).code,
|
||||
400,
|
||||
'Expected a rejected password before throttling',
|
||||
);
|
||||
}
|
||||
assert.equal(
|
||||
(await login()).code,
|
||||
@@ -49,7 +53,12 @@ exports.verifyAccountMaintenance = async function verifyAccountMaintenance(
|
||||
const session = await login();
|
||||
assert.equal(session.code, 200, 'Login limit was not cleared');
|
||||
assert.ok(session.data.token, 'Fresh owner session required');
|
||||
await api('system/auth/reset', 'PUT', { twoFactorActivated: true }, session.data.token);
|
||||
await api(
|
||||
'system/auth/reset',
|
||||
'PUT',
|
||||
{ twoFactorActivated: true },
|
||||
session.data.token,
|
||||
);
|
||||
assert.equal(
|
||||
(await login()).code,
|
||||
420,
|
||||
|
||||
@@ -38,7 +38,10 @@ exports.verifyOperator = async function verifyOperator(api) {
|
||||
last_execution_time: start,
|
||||
log_path: 'cli-retention/2000-01-01-kept.log',
|
||||
});
|
||||
assert.equal((await api(`crons/${task.id}`)).data.log_path, 'cli-retention/2000-01-01-kept.log');
|
||||
assert.equal(
|
||||
(await api(`crons/${task.id}`)).data.log_path,
|
||||
'cli-retention/2000-01-01-kept.log',
|
||||
);
|
||||
const result = invoke(['rmlog', '7']);
|
||||
assert.ok(result.removed.includes('cli-retention/2000-01-01-unused.log'));
|
||||
assert.ok(result.retained.includes('cli-retention/2000-01-01-kept.log'));
|
||||
|
||||
@@ -2,7 +2,9 @@ const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs/promises');
|
||||
const { randomUUID } = require('node:crypto');
|
||||
const { createContext } = require('../../dist/internal/runtime/context');
|
||||
const { installPanelDependencies } = require('../../dist/internal/maintenance/operator');
|
||||
const {
|
||||
installPanelDependencies,
|
||||
} = require('../../dist/internal/maintenance/operator');
|
||||
const { reloadPanel } = require('../../dist/internal/maintenance/upgrade');
|
||||
assert.equal(process.env.QL_PANEL_INTEGRATION, '1');
|
||||
(async () => {
|
||||
|
||||
@@ -43,10 +43,21 @@ let restoreEntrypoints;
|
||||
const switched = process.env.QL_PANEL_ENTRYPOINTS === '1';
|
||||
if (switched && process.env.QL_PANEL_PACKAGED === '1') {
|
||||
assert.equal(process.env.QL_CLI_ROOT, '/opt/qinglong-cli');
|
||||
for (const [name, module] of [['task', 'task'], ['ql', 'ql']]) {
|
||||
const target = require('node:path').join(require('node:os').homedir(), 'bin', name);
|
||||
for (const [name, module] of [
|
||||
['task', 'task'],
|
||||
['ql', 'ql'],
|
||||
]) {
|
||||
const target = require('node:path').join(
|
||||
require('node:os').homedir(),
|
||||
'bin',
|
||||
name,
|
||||
);
|
||||
assert.equal((await fs.lstat(target)).isSymbolicLink(), false);
|
||||
assert.ok((await fs.readFile(target, 'utf8')).includes(Buffer.from(`/opt/qinglong-cli/dist/${module}.js`).toString('base64')));
|
||||
assert.ok(
|
||||
(await fs.readFile(target, 'utf8')).includes(
|
||||
Buffer.from(`/opt/qinglong-cli/dist/${module}.js`).toString('base64'),
|
||||
),
|
||||
);
|
||||
}
|
||||
} else if (switched)
|
||||
restoreEntrypoints =
|
||||
@@ -214,7 +225,9 @@ let restoreEntrypoints;
|
||||
})()
|
||||
.catch(() => {
|
||||
// Assertions can embed environment values or subprocess output in their message.
|
||||
console.error('Disposable panel integration failed; inspect the failing scenario locally.');
|
||||
console.error(
|
||||
'Disposable panel integration failed; inspect the failing scenario locally.',
|
||||
);
|
||||
process.exitCode = 1;
|
||||
})
|
||||
.finally(async () => {
|
||||
|
||||
@@ -7,7 +7,9 @@ const { createHash } = require('node:crypto');
|
||||
const { createContext } = require('../../dist/internal/runtime/context');
|
||||
const operator = require('../../dist/internal/maintenance/operator');
|
||||
const { stageUpgrade } = require('../../dist/internal/maintenance/upgrade');
|
||||
const { cancellableOperation } = require('../../dist/internal/runtime/cancellation');
|
||||
const {
|
||||
cancellableOperation,
|
||||
} = require('../../dist/internal/runtime/cancellation');
|
||||
|
||||
test(
|
||||
'published master archives pass actual HTTPS download and staging validation',
|
||||
@@ -43,7 +45,9 @@ test(
|
||||
context.paths.dir_tmp,
|
||||
);
|
||||
installations.push(directory);
|
||||
await fs.mkdir(path.join(directory, 'node_modules'), { recursive: true });
|
||||
await fs.mkdir(path.join(directory, 'node_modules'), {
|
||||
recursive: true,
|
||||
});
|
||||
},
|
||||
);
|
||||
const controller = new AbortController();
|
||||
|
||||
@@ -7,7 +7,9 @@ const net = require('node:net');
|
||||
const { execFileSync, spawn } = require('node:child_process');
|
||||
const { setTimeout: delay } = require('node:timers/promises');
|
||||
const { createContext } = require('../../dist/internal/runtime/context');
|
||||
const { syncRepository } = require('../../dist/internal/subscription/subscriptionRunner');
|
||||
const {
|
||||
syncRepository,
|
||||
} = require('../../dist/internal/subscription/subscriptionRunner');
|
||||
|
||||
test(
|
||||
'real SSH subscriptions require the configured identity and pinned host key',
|
||||
|
||||
@@ -5,7 +5,10 @@ const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
const { fork } = require('node:child_process');
|
||||
const { createContext } = require('../../dist/internal/runtime/context');
|
||||
const { startPanel, stopPanel } = require('../../dist/internal/maintenance/operator');
|
||||
const {
|
||||
startPanel,
|
||||
stopPanel,
|
||||
} = require('../../dist/internal/maintenance/operator');
|
||||
const { runProcess } = require('../../dist/internal/runtime/process');
|
||||
|
||||
test(
|
||||
|
||||
Reference in new issue
Block a user