mirror of
https://github.com/UNITRONIX/BetterDesk.git
synced 2026-10-25 22:10:49 +00:00
cead414395
Remove GitHub prebuilt server binary delivery from panel updates. Fetch only required source subtrees for the selected commit and compile the Go server locally while preserving existing deployment and rollback behavior. Refs: panel update local build path Thanks: INSOLVE (Honorary); Marco Jakobs (@jacotec); MyNameisStitch (@MyNameisStitch); Redspin (@playerumpknow)
81 lines
3.1 KiB
JavaScript
81 lines
3.1 KiB
JavaScript
'use strict';
|
|
|
|
const https = require('https');
|
|
|
|
describe('updateService local server build', () => {
|
|
let updateService;
|
|
|
|
beforeEach(() => {
|
|
jest.restoreAllMocks();
|
|
delete require.cache[require.resolve('../services/updateService')];
|
|
updateService = require('../services/updateService');
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.restoreAllMocks();
|
|
delete require.cache[require.resolve('../services/updateService')];
|
|
});
|
|
|
|
it('exposes local build readiness without GitHub binary delivery helpers', () => {
|
|
expect(updateService.getServerUpdateInfo()).toMatchObject({
|
|
canAutoUpdate: true,
|
|
buildMethod: 'local',
|
|
canInstallGo: true,
|
|
});
|
|
expect(updateService.getPrebuiltInfo).toBeUndefined();
|
|
expect(updateService.checkPrebuiltAvailable).toBeUndefined();
|
|
expect(updateService.downloadPrebuiltBinary).toBeUndefined();
|
|
expect(updateService.downloadGithubBuffer).toBeUndefined();
|
|
});
|
|
|
|
it('keeps the server build result explicitly local', () => {
|
|
expect(updateService.getServerUpdateInfo().buildMethod).toBe('local');
|
|
});
|
|
|
|
it('enumerates only the requested GitHub subtree', async () => {
|
|
const commit = 'a'.repeat(40);
|
|
const rootTree = 'b'.repeat(40);
|
|
const serverTree = 'c'.repeat(40);
|
|
const routes = new Map([
|
|
[
|
|
`/repos/UNITRONIX/BetterDesk/git/commits/${commit}`,
|
|
{ tree: { sha: rootTree } },
|
|
],
|
|
[
|
|
`/repos/UNITRONIX/BetterDesk/git/trees/${rootTree}`,
|
|
{ tree: [{ type: 'tree', path: 'betterdesk-server', sha: serverTree }] },
|
|
],
|
|
[
|
|
`/repos/UNITRONIX/BetterDesk/git/trees/${serverTree}?recursive=1`,
|
|
{ tree: [
|
|
{ type: 'blob', path: 'go.mod' },
|
|
{ type: 'blob', path: 'api/server.go' },
|
|
] },
|
|
],
|
|
]);
|
|
const requested = [];
|
|
jest.spyOn(https, 'get').mockImplementation((options, callback) => {
|
|
const route = typeof options === 'string' ? new URL(options).pathname : options.path;
|
|
requested.push(route);
|
|
const body = routes.get(route);
|
|
process.nextTick(() => callback({
|
|
statusCode: body ? 200 : 404,
|
|
headers: {},
|
|
on(event, handler) {
|
|
if (event === 'data' && body) process.nextTick(() => handler(Buffer.from(JSON.stringify(body))));
|
|
if (event === 'end') process.nextTick(handler);
|
|
},
|
|
}));
|
|
return {
|
|
on: jest.fn(),
|
|
setTimeout: jest.fn(),
|
|
destroy: jest.fn(),
|
|
};
|
|
});
|
|
|
|
await expect(updateService.listRepoBlobPathsUnderPrefix(commit, 'betterdesk-server/'))
|
|
.resolves.toEqual(['betterdesk-server/go.mod', 'betterdesk-server/api/server.go']);
|
|
expect(requested).not.toContain(`/repos/UNITRONIX/BetterDesk/git/trees/${commit}?recursive=1`);
|
|
});
|
|
});
|