fix: stabilize tests and logging
This commit is contained in:
@@ -1,19 +1,17 @@
|
||||
import { Command } from "commander";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
const callGatewayFromCli = vi.fn(
|
||||
async (method: string, _opts: unknown, params?: unknown) => {
|
||||
if (method.endsWith(".get")) {
|
||||
return {
|
||||
path: "/tmp/exec-approvals.json",
|
||||
exists: true,
|
||||
hash: "hash-1",
|
||||
file: { version: 1, agents: {} },
|
||||
};
|
||||
}
|
||||
return { method, params };
|
||||
},
|
||||
);
|
||||
const callGatewayFromCli = vi.fn(async (method: string, _opts: unknown, params?: unknown) => {
|
||||
if (method.endsWith(".get")) {
|
||||
return {
|
||||
path: "/tmp/exec-approvals.json",
|
||||
exists: true,
|
||||
hash: "hash-1",
|
||||
file: { version: 1, agents: {} },
|
||||
};
|
||||
}
|
||||
return { method, params };
|
||||
});
|
||||
|
||||
const runtimeLogs: string[] = [];
|
||||
const runtimeErrors: string[] = [];
|
||||
@@ -31,9 +29,7 @@ vi.mock("./gateway-rpc.js", () => ({
|
||||
}));
|
||||
|
||||
vi.mock("./nodes-cli/rpc.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./nodes-cli/rpc.js")>(
|
||||
"./nodes-cli/rpc.js",
|
||||
);
|
||||
const actual = await vi.importActual<typeof import("./nodes-cli/rpc.js")>("./nodes-cli/rpc.js");
|
||||
return {
|
||||
...actual,
|
||||
resolveNodeId: vi.fn(async () => "node-1"),
|
||||
@@ -57,11 +53,7 @@ describe("exec approvals CLI", () => {
|
||||
|
||||
await program.parseAsync(["approvals", "get"], { from: "user" });
|
||||
|
||||
expect(callGatewayFromCli).toHaveBeenCalledWith(
|
||||
"exec.approvals.get",
|
||||
expect.anything(),
|
||||
{},
|
||||
);
|
||||
expect(callGatewayFromCli).toHaveBeenCalledWith("exec.approvals.get", expect.anything(), {});
|
||||
expect(runtimeErrors).toHaveLength(0);
|
||||
});
|
||||
|
||||
@@ -77,11 +69,9 @@ describe("exec approvals CLI", () => {
|
||||
|
||||
await program.parseAsync(["approvals", "get", "--node", "macbook"], { from: "user" });
|
||||
|
||||
expect(callGatewayFromCli).toHaveBeenCalledWith(
|
||||
"exec.approvals.node.get",
|
||||
expect.anything(),
|
||||
{ nodeId: "node-1" },
|
||||
);
|
||||
expect(callGatewayFromCli).toHaveBeenCalledWith("exec.approvals.node.get", expect.anything(), {
|
||||
nodeId: "node-1",
|
||||
});
|
||||
expect(runtimeErrors).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -151,15 +151,13 @@ export function registerExecApprovalsCli(program: Command) {
|
||||
});
|
||||
nodesCallOpts(setCmd);
|
||||
|
||||
const allowlist = approvals
|
||||
.command("allowlist")
|
||||
.description("Edit the per-agent allowlist");
|
||||
const allowlist = approvals.command("allowlist").description("Edit the per-agent allowlist");
|
||||
|
||||
const allowlistAdd = allowlist
|
||||
.command("add <pattern>")
|
||||
.description("Add a glob pattern to an allowlist")
|
||||
.option("--node <node>", "Target node id/name/IP (defaults to gateway)")
|
||||
.option("--agent <id>", "Agent id (defaults to \"default\")")
|
||||
.option("--agent <id>", 'Agent id (defaults to "default")')
|
||||
.action(async (pattern: string, opts: ExecApprovalsCliOpts) => {
|
||||
const trimmed = pattern.trim();
|
||||
if (!trimmed) {
|
||||
@@ -196,7 +194,7 @@ export function registerExecApprovalsCli(program: Command) {
|
||||
.command("remove <pattern>")
|
||||
.description("Remove a glob pattern from an allowlist")
|
||||
.option("--node <node>", "Target node id/name/IP (defaults to gateway)")
|
||||
.option("--agent <id>", "Agent id (defaults to \"default\")")
|
||||
.option("--agent <id>", 'Agent id (defaults to "default")')
|
||||
.action(async (pattern: string, opts: ExecApprovalsCliOpts) => {
|
||||
const trimmed = pattern.trim();
|
||||
if (!trimmed) {
|
||||
|
||||
@@ -87,19 +87,13 @@ describe("gateway SIGTERM", () => {
|
||||
const out: string[] = [];
|
||||
const err: string[] = [];
|
||||
|
||||
const bunBin = process.env.BUN_INSTALL
|
||||
? path.join(process.env.BUN_INSTALL, "bin", "bun")
|
||||
: "bun";
|
||||
|
||||
child = spawn(
|
||||
process.execPath,
|
||||
[
|
||||
"--import",
|
||||
"tsx",
|
||||
"src/index.ts",
|
||||
"gateway",
|
||||
"--port",
|
||||
String(port),
|
||||
"--bind",
|
||||
"loopback",
|
||||
"--allow-unconfigured",
|
||||
],
|
||||
bunBin,
|
||||
["src/entry.ts", "gateway", "--port", String(port), "--bind", "loopback", "--allow-unconfigured"],
|
||||
{
|
||||
cwd: process.cwd(),
|
||||
env: {
|
||||
|
||||
@@ -156,9 +156,7 @@ export function registerMemoryCli(program: Command) {
|
||||
for (const result of allResults) {
|
||||
const { agentId, status, embeddingProbe, indexError } = result;
|
||||
if (opts.index) {
|
||||
const line = indexError
|
||||
? `Memory index failed: ${indexError}`
|
||||
: "Memory index complete.";
|
||||
const line = indexError ? `Memory index failed: ${indexError}` : "Memory index complete.";
|
||||
defaultRuntime.log(line);
|
||||
}
|
||||
const lines = [
|
||||
@@ -167,9 +165,7 @@ export function registerMemoryCli(program: Command) {
|
||||
`(requested: ${status.requestedProvider})`,
|
||||
)}`,
|
||||
`${label("Model")} ${info(status.model)}`,
|
||||
status.sources?.length
|
||||
? `${label("Sources")} ${info(status.sources.join(", "))}`
|
||||
: null,
|
||||
status.sources?.length ? `${label("Sources")} ${info(status.sources.join(", "))}` : null,
|
||||
`${label("Indexed")} ${success(`${status.files} files · ${status.chunks} chunks`)}`,
|
||||
`${label("Dirty")} ${status.dirty ? warn("yes") : muted("no")}`,
|
||||
`${label("Store")} ${info(status.dbPath)}`,
|
||||
|
||||
@@ -116,12 +116,14 @@ export function registerNodesStatusCommands(nodes: Command) {
|
||||
const family = typeof obj.deviceFamily === "string" ? obj.deviceFamily : null;
|
||||
const model = typeof obj.modelIdentifier === "string" ? obj.modelIdentifier : null;
|
||||
const ip = typeof obj.remoteIp === "string" ? obj.remoteIp : null;
|
||||
const versions = formatNodeVersions(obj as {
|
||||
platform?: string;
|
||||
version?: string;
|
||||
coreVersion?: string;
|
||||
uiVersion?: string;
|
||||
});
|
||||
const versions = formatNodeVersions(
|
||||
obj as {
|
||||
platform?: string;
|
||||
version?: string;
|
||||
coreVersion?: string;
|
||||
uiVersion?: string;
|
||||
},
|
||||
);
|
||||
|
||||
const parts: string[] = ["Node:", displayName, nodeId];
|
||||
if (ip) parts.push(ip);
|
||||
|
||||
Reference in New Issue
Block a user