Files
ForgeFlow/tests/update-service.test.mjs
T
2026-07-24 20:29:23 +02:00

53 lines
2.0 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { mkdtemp, rm } from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const { UpdateService } = require('../src/main/update-service.cjs');
test('update check pins version to an exact branch commit', async () => {
const temp = await mkdtemp(path.join(os.tmpdir(), 'forgeflow-update-test-'));
const saved = [];
const store = {
data: {
gitea: { baseUrl: 'https://gitea.example.test' },
updates: { owner: 'Jens', repo: 'ForgeFlow', branch: 'main', autoCheck: true }
},
async save() { saved.push(true); }
};
const calls = [];
const gitea = {
async getBranch(owner, repo, branch) {
calls.push(['branch', owner, repo, branch]);
return { commit: { id: 'a'.repeat(40) } };
},
async getRepositoryFile(input) {
calls.push(['file', input]);
return { decoded: JSON.stringify({ name: 'forgeflow', version: '0.4.1' }) };
}
};
const service = new UpdateService({
store, gitea, diagnostics: null,
appInfo: { version: '0.4.0', packaged: false },
sourcePath: temp, userDataPath: temp
});
const result = await service.check();
assert.equal(result.available, true);
assert.equal(result.remoteSha, 'a'.repeat(40));
assert.equal(calls[1][1].ref, 'a'.repeat(40));
assert.equal(saved.length, 1);
await rm(temp, { recursive: true, force: true });
});
test('update repository parts reject path injection', async () => {
const temp = await mkdtemp(path.join(os.tmpdir(), 'forgeflow-update-test-'));
const service = new UpdateService({
store: { data: { updates: { owner: '../Jens', repo: 'ForgeFlow', branch: 'main' } }, save: async () => {} },
gitea: {}, diagnostics: null, appInfo: { version: '0.4.0', packaged: false }, sourcePath: temp, userDataPath: temp
});
await assert.rejects(() => service.check(), /unsupported characters/);
await rm(temp, { recursive: true, force: true });
});