mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 09:45:36 +08:00
fix: freeze release runtime tools and npm consumer artifacts
This commit is contained in:
1 parent
a70ec66fe3
commit
2f359c6bf0
63 files changed
+42562
-8738
No files matched your search
@@ -9,39 +9,72 @@ const { spawnSync } = require('node:child_process');
|
||||
const source = fs
|
||||
.readFileSync('shell/start.sh', 'utf8')
|
||||
.split('. ${QL_DIR}/shell/share.sh')[0];
|
||||
|
||||
function fixture(t, existing) {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ql-env-'));
|
||||
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
||||
fs.mkdirSync(path.join(root, 'shell'));
|
||||
fs.mkdirSync(path.join(root, 'scripts'));
|
||||
fs.writeFileSync(path.join(root, 'shell/test.sh'), '# fixture');
|
||||
fs.writeFileSync(path.join(root, '.env.example'), 'BACK_PORT=5700\n');
|
||||
const custom = 'BACK_PORT=5800\nJWT_SECRET=synthetic-test-only\n';
|
||||
if (existing)
|
||||
fs.writeFileSync(path.join(root, '.env'), custom, { mode: 0o600 });
|
||||
const trace = path.join(root, 'runtime-install.json');
|
||||
fs.writeFileSync(
|
||||
path.join(root, 'scripts/install-runtime-tools.cjs'),
|
||||
`const fs = require('node:fs');
|
||||
fs.writeFileSync(process.env.QL_INSTALL_TRACE, JSON.stringify(process.argv.slice(2)));
|
||||
if (process.env.QL_INSTALL_FAILURE === '1') process.exit(19);
|
||||
`,
|
||||
);
|
||||
return { root, custom, trace };
|
||||
}
|
||||
|
||||
function startup(root, trace, command, fail = false) {
|
||||
return spawnSync(
|
||||
'/bin/bash',
|
||||
[
|
||||
'-c',
|
||||
`npm(){ [[ "$*" == 'prefix --global' ]] || return 2; printf '%s\\n' "$QL_DIR/global-prefix"; };
|
||||
node(){ command '${process.execPath}' "$@"; };
|
||||
pip3(){ :; }; apk(){ :; }; sudo(){ "$@"; }; python3(){ printf 3.11; };
|
||||
${source}`,
|
||||
'startup-test',
|
||||
command,
|
||||
],
|
||||
{
|
||||
encoding: 'utf8',
|
||||
env: {
|
||||
...process.env,
|
||||
QL_DIR: root,
|
||||
QL_DATA_DIR: path.join(root, 'data'),
|
||||
QL_OS_TYPE: 'alpine',
|
||||
QL_INSTALL_TRACE: trace,
|
||||
QL_INSTALL_FAILURE: fail ? '1' : '0',
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
for (const command of ['start', 'reload']) {
|
||||
for (const existing of [false, true]) {
|
||||
test(`${command} ${
|
||||
existing ? 'preserves existing' : 'initializes missing'
|
||||
} .env`, (t) => {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ql-env-'));
|
||||
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
||||
fs.mkdirSync(path.join(root, 'shell'));
|
||||
fs.writeFileSync(path.join(root, 'shell/test.sh'), '# fixture');
|
||||
fs.writeFileSync(path.join(root, '.env.example'), 'BACK_PORT=5700\n');
|
||||
const custom = 'BACK_PORT=5800\nJWT_SECRET=synthetic-test-only\n';
|
||||
if (existing)
|
||||
fs.writeFileSync(path.join(root, '.env'), custom, { mode: 0o600 });
|
||||
const result = spawnSync(
|
||||
'/bin/bash',
|
||||
[
|
||||
'-c',
|
||||
'npm(){ :; }; pip3(){ :; }; apk(){ :; }; sudo(){ "$@"; }; python3(){ printf 3.11; };\n' +
|
||||
source,
|
||||
'startup-test',
|
||||
command,
|
||||
],
|
||||
{
|
||||
encoding: 'utf8',
|
||||
env: {
|
||||
...process.env,
|
||||
QL_DIR: root,
|
||||
QL_DATA_DIR: root + '/data',
|
||||
QL_OS_TYPE: 'alpine',
|
||||
},
|
||||
},
|
||||
);
|
||||
const { root, custom, trace } = fixture(t, existing);
|
||||
const result = startup(root, trace, command);
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
if (command === 'start')
|
||||
assert.deepEqual(JSON.parse(fs.readFileSync(trace, 'utf8')), [
|
||||
'--archive',
|
||||
path.join(root, 'static/runtime-tools.tgz'),
|
||||
'--proof',
|
||||
path.join(root, 'static/runtime-tools-proof.json'),
|
||||
'--prefix',
|
||||
path.join(root, 'global-prefix'),
|
||||
]);
|
||||
else assert.equal(fs.existsSync(trace), false);
|
||||
assert.equal(
|
||||
fs.readFileSync(path.join(root, '.env'), 'utf8'),
|
||||
existing ? custom : 'BACK_PORT=5700\n',
|
||||
@@ -51,3 +84,18 @@ for (const command of ['start', 'reload']) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (const existing of [false, true]) {
|
||||
test(`failed runtime installation stops before ${
|
||||
existing ? 'changing existing' : 'creating missing'
|
||||
} .env`, (t) => {
|
||||
const { root, custom, trace } = fixture(t, existing);
|
||||
const result = startup(root, trace, 'start', true);
|
||||
assert.equal(result.status, 19, result.stderr);
|
||||
assert.equal(fs.existsSync(trace), true);
|
||||
if (existing) {
|
||||
assert.equal(fs.readFileSync(path.join(root, '.env'), 'utf8'), custom);
|
||||
assert.equal(fs.statSync(path.join(root, '.env')).mode & 0o777, 0o600);
|
||||
} else assert.equal(fs.existsSync(path.join(root, '.env')), false);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user