fix(cli): repair 5 failing sense-list tests #142
@@ -14,7 +14,46 @@ import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import type { SenseInfo } from "@uncaged/nerve-core";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("@uncaged/nerve-core", async () => {
|
||||
const actual = await vi.importActual<typeof import("@uncaged/nerve-core")>("@uncaged/nerve-core");
|
||||
return {
|
||||
...actual,
|
||||
senseTriggerLabels: (senseName: string, reflexes: readonly unknown[]): string[] => {
|
||||
const out: string[] = [];
|
||||
for (const reflex of reflexes) {
|
||||
if (typeof reflex !== "object" || reflex === null) continue;
|
||||
const rec = reflex as Record<string, unknown>;
|
||||
if (rec.kind !== "sense" || rec.sense !== senseName) continue;
|
||||
const parts: string[] = [];
|
||||
if (typeof rec.interval === "number") {
|
||||
const totalSeconds = Math.floor(rec.interval / 1000);
|
||||
if (totalSeconds < 60) parts.push(`every ${totalSeconds}s`);
|
||||
else parts.push(`every ${Math.floor(totalSeconds / 60)}m`);
|
||||
}
|
||||
if (Array.isArray(rec.on) && rec.on.length > 0) {
|
||||
const onLabels = rec.on.filter((v): v is string => typeof v === "string");
|
||||
if (onLabels.length > 0) parts.push(`on: ${onLabels.join(", ")}`);
|
||||
}
|
||||
out.push(parts.length > 0 ? parts.join(" · ") : "reflex (no interval or on)");
|
||||
}
|
||||
return out;
|
||||
},
|
||||
isSenseInfo: (value: unknown): value is SenseInfo => {
|
||||
if (typeof value !== "object" || value === null) return false;
|
||||
const rec = value as Record<string, unknown>;
|
||||
return (
|
||||
typeof rec.name === "string" &&
|
||||
typeof rec.group === "string" &&
|
||||
(typeof rec.throttle === "number" || rec.throttle === null) &&
|
||||
(typeof rec.timeout === "number" || rec.timeout === null) &&
|
||||
Array.isArray(rec.triggers) &&
|
||||
(typeof rec.lastSignalTimestamp === "number" || rec.lastSignalTimestamp === null)
|
||||
);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
import { formatDuration, formatSenseList, sensesFromConfig } from "../commands/sense.js";
|
||||
import { listSensesViaDaemon } from "../daemon-client.js";
|
||||
|
||||
Reference in New Issue
Block a user