Files
BetterDesk/web-nodejs/tests/agentBuildWorker.version.test.js
T
UNITRONIX 1bc16efe8f fix(agent): enhance Support Agent profile handling and branding backup
- Implemented logic to reissue incomplete or expired signed Support Agent profiles during rebuilds, preventing operators from getting stuck in retry loops.
- Updated `build.sh` to handle the absence of `branding.pub` more gracefully, ensuring it doesn't fail on fresh workspaces.
- Refactored branding functions to utilize a dedicated support profile service, improving code organization and maintainability.
- Added tests to verify the correct behavior of version injection and support profile validity checks.
2026-08-06 21:08:42 +02:00

51 lines
1.8 KiB
JavaScript

'use strict';
const fs = require('fs');
const os = require('os');
const path = require('path');
describe('agentBuildWorker product version injection', () => {
let rootDir;
beforeEach(() => {
rootDir = fs.mkdtempSync(path.join(os.tmpdir(), 'bd-agent-version-'));
});
afterEach(() => {
fs.rmSync(rootDir, { recursive: true, force: true });
});
test('reads root VERSION and injects it into the copied Support Agent source', async () => {
const workspace = path.join(rootDir, 'workspace');
fs.mkdirSync(workspace, { recursive: true });
fs.writeFileSync(path.join(rootDir, 'VERSION'), '7.6.5\n');
fs.writeFileSync(
path.join(workspace, 'main.go'),
'package main\n\nvar version = "0.1.0"\n'
);
const worker = require('../services/agentBuildWorker');
const version = await worker._internals.injectSupportAgentVersion(workspace, { rootDir });
expect(version).toBe('7.6.5');
expect(worker._internals.getSupportAgentBuildVersion({ rootDir })).toBe('7.6.5');
expect(fs.readFileSync(path.join(workspace, 'main.go'), 'utf8'))
.toContain('var version = "7.6.5"');
});
test('inject succeeds when main.go already has the target version', async () => {
const workspace = path.join(rootDir, 'workspace');
fs.mkdirSync(workspace, { recursive: true });
fs.writeFileSync(
path.join(workspace, 'main.go'),
'package main\n\nvar version = "0.1.0"\n'
);
const worker = require('../services/agentBuildWorker');
const version = await worker._internals.injectSupportAgentVersion(workspace, {
version: '0.1.0',
});
expect(version).toBe('0.1.0');
});
});