From c36037b03a5747dbb57b3e89d07e5a3f7c4a550f Mon Sep 17 00:00:00 2001 From: Josh Wright Date: Wed, 7 Oct 2026 15:58:06 -0400 Subject: [PATCH] Fix artifact metadata test fixtures and cover modified files --- tests/unit/server-detail-api.test.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/unit/server-detail-api.test.ts b/tests/unit/server-detail-api.test.ts index 1c79be3..636406f 100644 --- a/tests/unit/server-detail-api.test.ts +++ b/tests/unit/server-detail-api.test.ts @@ -1,3 +1,4 @@ +import { createHash } from 'node:crypto'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { newFixture, type Fixture } from '../helpers/fixture.js'; @@ -35,8 +36,8 @@ describe('server detail data', () => { db().exec("INSERT INTO servers (name) VALUES ('target')"); const { createScript } = await import('../../src/lib/server/fleet/scripts.js'); const { recordScript } = await import('../../src/lib/server/fleet/inventory.js'); - const { version } = createScript({ name:'Plugin', kind:'plugin', targetRelPath:'native.bin', content:Buffer.from('plugin') }); - recordScript('target','native.bin',version.id,'hash',6,'beta'); + const { script, version } = createScript({ name:'Plugin', kind:'plugin', releaseVersion:'v1.0.0', targetRelPath:'native.bin', content:Buffer.from('plugin') }); + recordScript('target','native.bin',version.id,version.sha256,6,'beta'); recordScript('target','dedicated_zm.cfg',null,'hash',10,'compose'); recordScript('target','main.gsc',null,'hash',10,'beta'); recordScript('target','unknown.dat',null,'hash',10,'manual'); @@ -45,5 +46,24 @@ describe('server detail data', () => { expect(Object.fromEntries(body.scripts.map((file: {relPath:string;kind:string}) => [file.relPath,file.kind]))).toEqual({ 'dedicated_zm.cfg':'config','main.gsc':'script','native.bin':'plugin','unknown.dat':'file' }); + expect(body.scripts.find((file: { relPath: string }) => file.relPath === 'native.bin')).toMatchObject({ + artifactId: script.id, version: version.version, releaseVersion: 'v1.0.0', sha256: version.sha256 + }); + }); + it.each([['native.bin', 'file'], ['native.dll', 'plugin']])('omits saved artifact metadata for modified %s and falls back to its extension', async (path, kind) => { + const { db } = await import('../../src/lib/server/db/index.js'); + db().exec("INSERT INTO servers (name) VALUES ('target')"); + const { createScript } = await import('../../src/lib/server/fleet/scripts.js'); + const { recordScript } = await import('../../src/lib/server/fleet/inventory.js'); + const { version } = createScript({ name:'Plugin', kind:'plugin', releaseVersion:'v1.0.0', targetRelPath:path, content:Buffer.from('plugin') }); + const content = Buffer.from('modified plugin'); + const sha256 = createHash('sha256').update(content).digest('hex'); + recordScript('target',path,version.id,sha256,content.length,'manual'); + const { GET } = await import('../../src/routes/api/servers/[name]/scripts/+server.js'); + const body = await (await GET({ params: {name:'target'} })).json(); + expect(body.scripts).toEqual([expect.objectContaining({ + relPath: path, kind, artifactId: null, version: null, releaseVersion: null, + scriptVersionId: version.id, sha256, size: content.length, source: 'manual' + })]); }); });