mirror of
https://github.com/Routstr/routstrd.git
synced 2026-10-05 20:38:22 +00:00
`routstrd clients` only exposed list/delete/add, so operators had no way to refresh client integrations on demand or to stop the daemon from rewriting their client configs every 21 minutes. - clients --manual-refresh: refresh routstr21 models from Nostr and re-run every registered client integration now. The old `routstrd refresh` body moves into a shared refreshModelsAndClientsAction() so both commands stay in sync. - clients --disable-automatic-refresh / --enable-automatic-refresh: toggle the daemon's scheduled refresh job via a new POST /settings/auto-refresh endpoint, so the toggle also works against a remote daemon where the config lives on the host. Persisted as autoRefresh.enabled in config.json. - The daemon refresh job now re-reads autoRefresh on every tick (like the NWC auto-refill getter), so toggling takes effect without a restart. While disabled it polls once a minute so re-enabling applies promptly. - Startup still fetches models (the proxy needs them) but skips the client integration pass when the job is disabled, so a restart cannot overwrite hand-edited client configs. Adds tests/daemon/auto-refresh.* covering the endpoint contract and the persisted flag. Co-authored-by: redshift <213178690+1ftredsh@users.noreply.github.com>
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { spawnSync } from "child_process";
|
|
import { mkdtempSync, rmSync } from "fs";
|
|
import { join } from "path";
|
|
import { tmpdir } from "os";
|
|
|
|
// The scenario mutates process.env.ROUTSTRD_DIR before the config module is
|
|
// loaded, so it runs in an isolated bun subprocess (same approach as
|
|
// config-store.perms.test.ts).
|
|
|
|
const SCENARIO = join(import.meta.dir, "auto-refresh.scenario.ts");
|
|
|
|
function runScenario(name: string): { code: number; out: string } {
|
|
const dir = mkdtempSync(join(tmpdir(), `routstrd-auto-refresh-${name}-`));
|
|
const res = spawnSync("bun", [SCENARIO, name], {
|
|
env: {
|
|
...process.env,
|
|
NODE_ENV: "test",
|
|
ROUTSTRD_DIR: join(dir, "daemon"),
|
|
},
|
|
stdout: "pipe",
|
|
stderr: "pipe",
|
|
});
|
|
const out = `${res.stdout}${res.stderr}`;
|
|
rmSync(dir, { recursive: true, force: true });
|
|
return { code: res.status ?? res.exitCode ?? -1, out };
|
|
}
|
|
|
|
describe("auto-refresh settings endpoint", () => {
|
|
test("persists the scheduled-refresh toggle to the daemon config", () => {
|
|
const { code, out } = runScenario("toggle-endpoint");
|
|
expect(out).toContain("SCENARIO-OK");
|
|
expect(code).toBe(0);
|
|
});
|
|
});
|