Files
Genarrative/apps/ai-game-creator-shell/scripts/build-release.test.mjs
suzmii 64b9ccfb9d 发布链路加固:要求版本已提交后再发布
- 新增 assertVersionCommitted:发布前确认 5 个版本来源相对 HEAD 已提交,避免仅 bump 未提交就 release 导致本地与 Jenkins 检出版本不一致

- release-upload 在取版本、OSS 防降级前调用该守卫

- 更新 AGC 更新技术方案文档,并补发布校验回归测试
2026-09-07 14:09:16 +08:00

90 lines
2.9 KiB
JavaScript

import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { test } from 'node:test';
import { fileURLToPath } from 'node:url';
import {
bumpVersion,
compareVersions,
createUpdateManifest,
selectReleaseArtifact,
} from './build-release.mjs';
test('selects an explicit release artifact when configured', () => {
const artifactPath = fileURLToPath(
new URL('../package.json', import.meta.url),
);
const previous = process.env.AGC_UPDATE_ARTIFACT;
process.env.AGC_UPDATE_ARTIFACT = artifactPath;
try {
assert.equal(selectReleaseArtifact([]), artifactPath);
} finally {
if (previous === undefined) delete process.env.AGC_UPDATE_ARTIFACT;
else process.env.AGC_UPDATE_ARTIFACT = previous;
}
});
test('does not select unsupported files', () => {
assert.equal(
selectReleaseArtifact(['/tmp/latest.json', '/tmp/readme.txt']),
null,
);
});
test('manifest contains version, download URL and integrity fields', () => {
const manifest = createUpdateManifest(
fileURLToPath(new URL('../package.json', import.meta.url)),
);
assert.match(manifest.version, /^\d+\.\d+\.\d+$/u);
assert.match(
manifest.downloadUrl,
new RegExp(`/agc/${manifest.version}/package\\.json$`, 'u'),
);
assert.equal(manifest.sha256.length, 64);
assert.equal(typeof manifest.size, 'number');
});
test('manifest preserves multiline release notes', () => {
const previous = process.env.AGC_UPDATE_RELEASE_NOTES;
process.env.AGC_UPDATE_RELEASE_NOTES = '第一行\n第二行\r\n第三行';
try {
const manifest = createUpdateManifest(
fileURLToPath(new URL('../package.json', import.meta.url)),
);
assert.equal(manifest.releaseNotes, '第一行\n第二行\r\n第三行');
} finally {
if (previous === undefined) delete process.env.AGC_UPDATE_RELEASE_NOTES;
else process.env.AGC_UPDATE_RELEASE_NOTES = previous;
}
});
test('bump version follows the requested target', () => {
assert.equal(compareVersions('0.1.15', '0.1.12'), 1);
assert.equal(compareVersions('0.1.12', '0.1.12'), 0);
assert.equal(bumpVersion('0.1.19', 'patch'), '0.1.20');
assert.equal(bumpVersion('0.1.19'), '0.1.20');
assert.equal(bumpVersion('0.1.19', 'minor'), '0.2.0');
assert.equal(bumpVersion('0.1.19', 'major'), '1.0.0');
assert.equal(bumpVersion('0.1.12', '0.1.25'), '0.1.25');
});
test('release upload forces overwrite for versioned artifact and latest pointer', () => {
const source = readFileSync(
new URL('./release-upload.mjs', import.meta.url),
'utf8',
);
assert.equal(
(source.match(/runOssutil\(\['cp', '--force'/gu) ?? []).length,
2,
);
});
test('release upload verifies the version is committed and not below OSS', () => {
const source = readFileSync(
new URL('./release-upload.mjs', import.meta.url),
'utf8',
);
assert.match(source, /assertVersionCommitted\(\)/u);
assert.match(source, /assertVersionNotBelowOss\(/u);
});