Require release versions for script uploads
CI / checks (push) Successful in 5m26s

This commit is contained in:
2026-10-12 18:46:57 -04:00
parent ffda04f276
commit 2f52dcb1ef
50 changed files with 871 additions and 113 deletions
+12 -8
View File
@@ -10,8 +10,9 @@ beforeEach(async () => {
afterEach(async () => {
await fixture.cleanup();
});
function request(content: string, reuse = false) {
function request(content: string, reuse = false, releaseVersion = '1.0.0') {
const form = new FormData();
form.append('releaseVersion', releaseVersion);
form.append('content', new File([content], 'hud.gsc'));
if (reuse) form.append('reuseExisting', 'true');
return new Request('http://localhost/api/scripts/inspect', { method: 'POST', body: form });
@@ -21,6 +22,7 @@ async function seed() {
return {
...mod,
...mod.createScript({
releaseVersion: '1.0.0',
name: 'HUD',
targetRelPath: 'hud.gsc',
scopeType: 'game',
@@ -33,7 +35,7 @@ async function seed() {
describe('script upload review', () => {
it('inspects content against all versions without creating records or including plugins', async () => {
const { script, version, uploadNewVersion, createScript, listVersions } = await seed();
uploadNewVersion(script.id, Buffer.from('changed(){}'));
uploadNewVersion(script.id, Buffer.from('changed(){}'), undefined, '1.0.1');
createScript({
name: 'Plugin',
targetRelPath: 'plugin.dll',
@@ -44,17 +46,19 @@ describe('script upload review', () => {
const res = await POST({ request: request('main(){}') });
expect(await res.json()).toEqual({
sha256: version.sha256,
duplicates: [{ scriptId: script.id, versionId: version.id, version: 1 }]
duplicates: [
{ scriptId: script.id, versionId: version.id, version: 1, release_version: '1.0.0' }
]
});
expect(listVersions(script.id)).toHaveLength(2);
expect((await POST({ request: request('') })).status).toBe(400);
});
it('reuses identical historical content and creates changed versions while preserving scope', async () => {
const { script, version, uploadNewVersion, listVersions, getScript } = await seed();
uploadNewVersion(script.id, Buffer.from('changed(){}'));
uploadNewVersion(script.id, Buffer.from('changed(){}'), undefined, '1.0.2');
const { POST } = await import('../../src/routes/api/scripts/[id]/versions/+server.js');
const invoke = (content: string) =>
POST({ params: { id: String(script.id) }, request: request(content, true) });
const invoke = (content: string, release = '1.0.0') =>
POST({ params: { id: String(script.id) }, request: request(content, true, release) });
const res = await invoke('main(){}');
expect(await res.json()).toMatchObject({
ok: true,
@@ -62,7 +66,7 @@ describe('script upload review', () => {
version: { id: version.id, version: 1 }
});
expect(listVersions(script.id)).toHaveLength(2);
const added = await invoke('third(){}');
const added = await invoke('third(){}', '1.1.0');
expect(await added.json()).toMatchObject({ ok: true, version: { version: 3 } });
expect(listVersions(script.id)).toHaveLength(3);
expect(getScript(script.id)).toMatchObject({ scope_type: 'game', scope_value: 't5' });
@@ -90,7 +94,7 @@ describe('script upload review', () => {
});
it('lists promoted and latest version metadata separately without file contents', async () => {
const { script, version, uploadNewVersion } = await seed();
const latest = uploadNewVersion(script.id, Buffer.from('changed(){}'));
const latest = uploadNewVersion(script.id, Buffer.from('changed(){}'), undefined, '1.0.3');
const { db } = await import('../../src/lib/server/db/index.js');
db()
.prepare('UPDATE scripts SET current_version_id = ? WHERE id = ?')