Files
OmniRoute/tests/unit/auto-update-runtime.test.mjs
Diego Rodrigues de Sa e Souza 1442c47bbb chore(release): v3.5.6 — email masking, model toggle, OpenRouter registries & bug fixes (#1080)
* fix(minimax): switch auth from x-api-key to Authorization Bearer (#1076)

Integrated into release/v3.5.6 — MiniMax auth fix with authHeader consistency normalization

* feat(CI,i18n): autogenerate language files + Add missing strings (#1071)

Integrated into release/v3.5.6 — i18n translations for memory, skills, and missing keys across 31 languages

* fix(ci): restore i18n continue-on-error, remove auto-commit race condition

* fix(husky): load nvm in hooks for VS Code compatibility

* fix(husky): gracefully skip hooks when npm is not in PATH

* fix: convert OpenAI function tool_choice to Claude tool format (#1072)

* fix: prevent EPIPE feedback loop filling logs at GB/s (#1006)

* fix: fallback to native fetch when undici dispatcher fails (#1054)

* fix: improve Qoder PAT validation with actionable error messages (#966)

- Add QODER_PERSONAL_ACCESS_TOKEN env var fallback for both validation and execution
- Pre-flight ping check to diagnose connectivity issues (Docker/proxy)
- Detect encrypted auth blobs from ~/.qoder/.auth/user and guide to website PAT
- Clear error messages for auth failures with link to integrations page
- Treat non-auth 4xx as auth-pass (request format issue, not token issue)
- Update tests to cover new validation paths (23 tests, all passing)

* feat: Improve the Chinese translation (#1079)

Integrated into release/v3.5.6

* chore(release): v3.5.6 — i18n updates and credential security fixes

* fix(ci): resolve e2e and docs-sync pipeline failures

* fix(security): bump next to 16.2.3 to resolve SNYK-JS-NEXT-15954202

* fix: guard Memory/Cache UI against null toLocaleString crash (#1083)

* fix: translate OpenAI tool_choice type 'function' to Claude 'tool' format (#1072)

* fix: pass custom baseUrl in provider API key validation (#1078)

* docs: update CHANGELOG with v3.5.6 bug fixes and security patches

* docs: rewrite implement-features workflow with 5-phase harvest-research-report-plan-execute pipeline

* docs: organize _ideia/ into viable/defer/notfit + add Phase 2.5 auto-response workflow

* docs: implementation plans for #1025, #750, #960, #1046 + close already-implemented #833, #973, #982

* feat: mask email addresses in dashboard for privacy (#1025)

* feat: add OpenRouter and GitHub to embedding/image provider registries (#960)

* feat: add model visibility toggle and search filter to provider page (#750)

* docs: move implemented features to notfit, update task plans status

* chore: untrack _ideia/ and _tasks/ from git — private/internal only

* chore(release): bump to v3.5.6 — changelog, docs, version sync & any-budget fix

* fix: remove explicit .ts extension in qoderCli import that caused 500 error in production build

---------

Co-authored-by: Jean Brito <jeanfbrito@gmail.com>
Co-authored-by: zenobit <zenobit@disroot.org>
Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com>
Co-authored-by: Ethan Hunt <136065060+only4copilot@users.noreply.github.com>
2026-04-09 15:55:59 -03:00

137 lines
4.9 KiB
JavaScript

import { describe, it } from "node:test";
import assert from "node:assert/strict";
const autoUpdate = await import("../../src/lib/system/autoUpdate.ts");
describe("getAutoUpdateConfig", () => {
it("defaults to npm or source mode locally", () => {
const config = autoUpdate.getAutoUpdateConfig({ DATA_DIR: "/tmp/omniroute" });
assert.ok(config.mode === "npm" || config.mode === "source");
assert.equal(config.repoDir, "/workspace/omniroute");
assert.equal(config.composeProfile, "cli");
});
it("reads docker-compose settings from env", () => {
const config = autoUpdate.getAutoUpdateConfig({
DATA_DIR: "/tmp/custom-data",
AUTO_UPDATE_MODE: "docker-compose",
AUTO_UPDATE_REPO_DIR: "/srv/omniroute",
AUTO_UPDATE_COMPOSE_FILE: "/srv/omniroute/docker-compose.yml",
AUTO_UPDATE_COMPOSE_PROFILE: "base",
AUTO_UPDATE_SERVICE: "omniroute-base",
AUTO_UPDATE_GIT_REMOTE: "upstream",
AUTO_UPDATE_PATCH_COMMITS: "abc123 def456,ghi789",
AUTO_UPDATE_LOG_PATH: "/tmp/update.log",
});
assert.equal(config.mode, "docker-compose");
assert.equal(config.repoDir, "/srv/omniroute");
assert.equal(config.composeFile, "/srv/omniroute/docker-compose.yml");
assert.equal(config.composeProfile, "base");
assert.equal(config.composeService, "omniroute-base");
assert.equal(config.gitRemote, "upstream");
assert.deepEqual(config.patchCommits, ["abc123", "def456", "ghi789"]);
assert.equal(config.logPath, "/tmp/update.log");
});
});
describe("validateAutoUpdateRuntime", () => {
it("supports source mode when git is available in a git repository", async () => {
const config = autoUpdate.getAutoUpdateConfig({
AUTO_UPDATE_MODE: "source",
});
const result = await autoUpdate.validateAutoUpdateRuntime(
config,
async (file) => {
if (file === "git") return { stdout: "git version 2.0.0", stderr: "" };
throw new Error(`unexpected command: ${file}`);
},
async () => true
);
assert.deepEqual(result, {
supported: true,
reason: null,
composeCommand: null,
});
});
it("reports missing docker socket for docker-compose mode", async () => {
const config = autoUpdate.getAutoUpdateConfig({
AUTO_UPDATE_MODE: "docker-compose",
AUTO_UPDATE_REPO_DIR: "/repo",
AUTO_UPDATE_COMPOSE_FILE: "/repo/docker-compose.yml",
});
const result = await autoUpdate.validateAutoUpdateRuntime(
config,
async () => ({ stdout: "git version 2.0.0", stderr: "" }),
async (targetPath) => targetPath !== "/var/run/docker.sock"
);
assert.equal(result.supported, false);
assert.match(result.reason, /Docker socket/);
});
it("detects docker-compose command availability", async () => {
const config = autoUpdate.getAutoUpdateConfig({
AUTO_UPDATE_MODE: "docker-compose",
AUTO_UPDATE_REPO_DIR: "/repo",
AUTO_UPDATE_COMPOSE_FILE: "/repo/docker-compose.yml",
});
const result = await autoUpdate.validateAutoUpdateRuntime(
config,
async (file, args) => {
if (file === "git") return { stdout: "git version 2.0.0", stderr: "" };
if (file === "docker" && args?.[0] === "compose") {
return { stdout: "Docker Compose version v2.0.0", stderr: "" };
}
throw new Error(`unexpected command: ${file}`);
},
async () => true
);
assert.equal(result.supported, true);
assert.equal(result.composeCommand, "docker compose");
});
});
describe("buildDockerComposeUpdateScript", () => {
it("includes git checkout and compose rebuild steps", () => {
const config = autoUpdate.getAutoUpdateConfig({
AUTO_UPDATE_MODE: "docker-compose",
AUTO_UPDATE_REPO_DIR: "/repo",
AUTO_UPDATE_COMPOSE_FILE: "/repo/docker-compose.yml",
AUTO_UPDATE_COMPOSE_PROFILE: "cli",
AUTO_UPDATE_SERVICE: "omniroute-cli",
AUTO_UPDATE_GIT_REMOTE: "origin",
AUTO_UPDATE_PATCH_COMMITS: "1501a87 e569e1c",
});
const script = autoUpdate.buildDockerComposeUpdateScript({
latest: "3.2.6",
config,
composeCommand: "docker compose",
});
assert.match(script, /git fetch --tags/);
assert.match(script, /git config --global --add safe\.directory/);
assert.match(script, /git checkout -B "autoupdate\/\$\{TARGET_TAG#v\}" "\$TARGET_TAG"/);
assert.match(script, /git cherry-pick --keep-redundant-commits '1501a87' 'e569e1c'/);
assert.match(script, /docker compose -f "\$COMPOSE_FILE" up -d --build "\$SERVICE"/);
});
});
describe("buildSourceUpdateScript", () => {
it("includes git checkout, env sync, and rebuild steps", () => {
const script = autoUpdate.buildSourceUpdateScript("3.2.6", "upstream");
assert.match(script, /git fetch --tags 'upstream'/);
assert.match(script, /git checkout "v3\.2\.6"/);
assert.match(script, /node scripts\/sync-env\.mjs 2>\/dev\/null \|\| true/);
assert.match(script, /pm2 restart omniroute --update-env \|\| true/);
});
});