Files
routstrd/tests/daemon/auto-model-path.test.ts
redshift 819fde0972 feat(cli): add routstrd models auto-model-path toggle
Enabling automatic model-path selection meant hand-editing `autoModelPath`
in ~/.routstrd/config.json. Add a first-class way to flip it:

  routstrd models auto-model-path          # show the current setting
  routstrd models auto-model-path on|off
  routstrd models auto-model-path toggle
  routstrd models auto-model-path on --no-restart

- daemon: GET/POST /settings/auto-model-path persists `autoModelPath` and
  reports `restartRequired` (the running daemon captures the setting at
  startup, so a restart is what makes it take effect). GET also reports the
  value on disk (`configured`) next to the value in effect.
- cli: the command restarts the local daemon after a change (skip with
  --no-restart) and, for a remote node, prints the reminder that its
  operator has to restart it. `status` warns when config.json and the
  running daemon disagree.
- cli: factor the stop/wait/start sequence into `restartLocalDaemon` and
  reuse it from `restart` and `mode`; `restart` now also keeps the
  configured `provider` pin, which it previously dropped.
- docs: README/SKILL cover the command, the setting, and the endpoint.
- tests: endpoint scenario (persist, pending restart, no-op re-post) and
  unit tests for the state argument parsing.
2026-10-09 23:41:40 +08:00

42 lines
1.4 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
// auto-refresh.test.ts).
const SCENARIO = join(import.meta.dir, "auto-model-path.scenario.ts");
function runScenario(name: string): { code: number; out: string } {
const dir = mkdtempSync(join(tmpdir(), `routstrd-auto-model-path-${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 model path settings endpoint", () => {
test("persists the toggle and reports a pending restart", () => {
const { code, out } = runScenario("enable-from-off");
expect(out).toContain("SCENARIO-OK");
expect(code).toBe(0);
});
test("re-posting the active value does not request a restart", () => {
const { code, out } = runScenario("disable-from-on");
expect(out).toContain("SCENARIO-OK");
expect(code).toBe(0);
});
});