Merge pull request #1727 from HAHH9527/fix/windows-schtasks-tr-261-char-limit

fix(cli): externalize Windows startup PowerShell to .ps1 wrapper (schtasks /TR 261-char limit)
This commit is contained in:
Bohdan Triapitsyn
2026-08-28 01:22:57 +03:00
committed by GitHub
2 changed files with 64 additions and 9 deletions
+35
View File
@@ -43,6 +43,7 @@ import {
resolveServeHost,
resolveServeUiPassword,
} from './cli.js';
import { buildWindowsStartupTaskCommand } from './lib/cli-startup.js';
async function withTempOpenChamberDataDir(fn) {
const previous = process.env.OPENCHAMBER_DATA_DIR;
@@ -1421,3 +1422,37 @@ describe('lifecycle commands with unmanaged explicit ports', () => {
});
});
});
describe('Windows startup task command builder', () => {
it('default-path length stays under 200 chars', () => {
const cmd = buildWindowsStartupTaskCommand(
'C:\\Users\\test\\.config\\openchamber\\bin\\OpenChamber.ps1'
);
expect(cmd).toMatch(/^powershell\.exe -NoProfile -ExecutionPolicy Bypass -File /);
expect(cmd.length).toBeLessThan(200);
});
it('worst-case long path stays under 261-char Task Scheduler ceiling', () => {
// Build a wrapper path >= 180 chars (simulates long OPENCHAMBER_DATA_DIR)
// Overhead = 57 chars (prefix + closing quote), so max wrapper for <261 total is 203
const longPath =
'C:\\Users\\' +
'a'.repeat(139) +
'\\.config\\openchamber\\bin\\OpenChamber.ps1';
expect(longPath.length).toBeGreaterThanOrEqual(180);
const cmd = buildWindowsStartupTaskCommand(longPath);
expect(cmd.length).toBeLessThan(261);
});
it('does NOT inline SetEnvironmentVariable (externalization invariant)', () => {
const cmd = buildWindowsStartupTaskCommand('C:\\wrapper.ps1');
expect(cmd).not.toContain('SetEnvironmentVariable');
});
it('uses -File form, not -Command', () => {
const cmd = buildWindowsStartupTaskCommand('C:\\wrapper.ps1');
expect(cmd).toContain('-File ');
expect(cmd).not.toContain('-Command ');
});
});