mirror of
https://github.com/whyour/qinglong.git
synced 2026-11-30 16:27:21 +08:00
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.
211 lines
5.4 KiB
JavaScript
211 lines
5.4 KiB
JavaScript
// Fresh disposable official panel only; never run against an initialized panel.
|
|
const assert = require('node:assert/strict');
|
|
const { randomUUID } = require('node:crypto');
|
|
const { spawnSync } = require('node:child_process');
|
|
const path = require('node:path');
|
|
const fs = require('node:fs/promises');
|
|
|
|
(async () => {
|
|
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 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,
|
|
},
|
|
});
|
|
// Report only the command name, never request bodies or application credentials.
|
|
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,
|
|
);
|
|
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(['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)]);
|
|
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"}',
|
|
]);
|
|
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,
|
|
);
|
|
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);
|
|
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;
|
|
});
|