mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-25 09:59:32 +00:00
refactor(agents): remove stale wrapper exports
This commit is contained in:
@@ -4,9 +4,9 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import { loadExtraBootstrapFiles, loadExtraBootstrapFilesWithDiagnostics } from "./workspace.js";
|
||||
import { loadExtraBootstrapFilesWithDiagnostics } from "./workspace.js";
|
||||
|
||||
describe("loadExtraBootstrapFiles", () => {
|
||||
describe("loadExtraBootstrapFilesWithDiagnostics", () => {
|
||||
let fixtureRoot = "";
|
||||
let fixtureCount = 0;
|
||||
|
||||
@@ -26,6 +26,11 @@ describe("loadExtraBootstrapFiles", () => {
|
||||
}
|
||||
});
|
||||
|
||||
async function loadExtraBootstrapFileList(dir: string, extraPatterns: string[]) {
|
||||
const { files } = await loadExtraBootstrapFilesWithDiagnostics(dir, extraPatterns);
|
||||
return files;
|
||||
}
|
||||
|
||||
it("loads recognized bootstrap files from glob patterns", async () => {
|
||||
const workspaceDir = await createWorkspaceDir("glob");
|
||||
const packageDir = path.join(workspaceDir, "packages", "core");
|
||||
@@ -33,7 +38,7 @@ describe("loadExtraBootstrapFiles", () => {
|
||||
await fs.writeFile(path.join(packageDir, "TOOLS.md"), "tools", "utf-8");
|
||||
await fs.writeFile(path.join(packageDir, "README.md"), "not bootstrap", "utf-8");
|
||||
|
||||
const files = await loadExtraBootstrapFiles(workspaceDir, ["packages/*/*"]);
|
||||
const files = await loadExtraBootstrapFileList(workspaceDir, ["packages/*/*"]);
|
||||
|
||||
expect(files).toStrictEqual([
|
||||
{
|
||||
@@ -51,7 +56,7 @@ describe("loadExtraBootstrapFiles", () => {
|
||||
await fs.mkdir(packageDir, { recursive: true });
|
||||
await fs.writeFile(path.join(packageDir, "AGENTS.md"), "agents", "utf-8");
|
||||
|
||||
const files = await loadExtraBootstrapFiles(workspaceDir, ["./packages/*/AGENTS.md"]);
|
||||
const files = await loadExtraBootstrapFileList(workspaceDir, ["./packages/*/AGENTS.md"]);
|
||||
|
||||
expect(files).toStrictEqual([
|
||||
{
|
||||
@@ -69,7 +74,7 @@ describe("loadExtraBootstrapFiles", () => {
|
||||
await fs.mkdir(packageDir, { recursive: true });
|
||||
await fs.writeFile(path.join(packageDir, "AGENTS.md"), "literal agents", "utf-8");
|
||||
|
||||
const files = await loadExtraBootstrapFiles(workspaceDir, ["pkg[1]/AGENTS.md"]);
|
||||
const files = await loadExtraBootstrapFileList(workspaceDir, ["pkg[1]/AGENTS.md"]);
|
||||
|
||||
expect(files).toStrictEqual([
|
||||
{
|
||||
@@ -89,7 +94,7 @@ describe("loadExtraBootstrapFiles", () => {
|
||||
await fs.mkdir(outsideDir, { recursive: true });
|
||||
await fs.writeFile(path.join(outsideDir, "AGENTS.md"), "outside", "utf-8");
|
||||
|
||||
const files = await loadExtraBootstrapFiles(workspaceDir, ["../outside/AGENTS.md"]);
|
||||
const files = await loadExtraBootstrapFileList(workspaceDir, ["../outside/AGENTS.md"]);
|
||||
|
||||
expect(files).toHaveLength(0);
|
||||
});
|
||||
@@ -106,7 +111,7 @@ describe("loadExtraBootstrapFiles", () => {
|
||||
await fs.writeFile(path.join(realWorkspace, "AGENTS.md"), "linked agents", "utf-8");
|
||||
await fs.symlink(realWorkspace, linkedWorkspace, "dir");
|
||||
|
||||
const files = await loadExtraBootstrapFiles(linkedWorkspace, ["AGENTS.md"]);
|
||||
const files = await loadExtraBootstrapFileList(linkedWorkspace, ["AGENTS.md"]);
|
||||
|
||||
expect(files).toStrictEqual([
|
||||
{
|
||||
@@ -142,7 +147,7 @@ describe("loadExtraBootstrapFiles", () => {
|
||||
throw err;
|
||||
}
|
||||
|
||||
const files = await loadExtraBootstrapFiles(workspaceDir, ["AGENTS.md"]);
|
||||
const files = await loadExtraBootstrapFileList(workspaceDir, ["AGENTS.md"]);
|
||||
expect(files).toHaveLength(0);
|
||||
});
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import {
|
||||
filterBootstrapFilesForSession,
|
||||
isWorkspaceBootstrapPending,
|
||||
loadWorkspaceBootstrapFiles,
|
||||
reconcileWorkspaceBootstrapCompletion,
|
||||
resolveWorkspaceBootstrapStatus,
|
||||
resolveDefaultAgentWorkspaceDir,
|
||||
resolveWorkspaceAttestationPath,
|
||||
@@ -617,9 +616,7 @@ describe("ensureAgentWorkspace", () => {
|
||||
content: "# IDENTITY.md\n\n- **Name:** Example\n",
|
||||
});
|
||||
|
||||
const result = await reconcileWorkspaceBootstrapCompletion(tempDir);
|
||||
expect(result.repaired).toBe(true);
|
||||
expect(result.bootstrapExists).toBe(false);
|
||||
await ensureAgentWorkspace({ dir: tempDir, ensureBootstrapFiles: true });
|
||||
await expectPathMissing(path.join(tempDir, DEFAULT_BOOTSTRAP_FILENAME));
|
||||
const state = await readWorkspaceState(tempDir);
|
||||
expect(state.bootstrapSeededAt).toMatch(/\d{4}-\d{2}-\d{2}T/);
|
||||
@@ -642,10 +639,7 @@ describe("ensureAgentWorkspace", () => {
|
||||
.mockRejectedValueOnce(Object.assign(new Error("not a directory"), { code: "ENOTDIR" }));
|
||||
|
||||
try {
|
||||
const result = await reconcileWorkspaceBootstrapCompletion(tempDir);
|
||||
|
||||
expect(result.repaired).toBe(true);
|
||||
expect(result.bootstrapExists).toBe(true);
|
||||
await ensureAgentWorkspace({ dir: tempDir, ensureBootstrapFiles: true });
|
||||
expect(rmSpy).toHaveBeenCalledWith(bootstrapPath, { force: true });
|
||||
await expect(fs.access(bootstrapPath)).resolves.toBeUndefined();
|
||||
const state = await readWorkspaceState(tempDir);
|
||||
@@ -666,9 +660,7 @@ describe("ensureAgentWorkspace", () => {
|
||||
content: "# SOUL.md\n\nUse a concise, practical voice.\n",
|
||||
});
|
||||
|
||||
const result = await reconcileWorkspaceBootstrapCompletion(tempDir);
|
||||
expect(result.repaired).toBe(true);
|
||||
expect(result.bootstrapExists).toBe(false);
|
||||
await ensureAgentWorkspace({ dir: tempDir, ensureBootstrapFiles: true });
|
||||
await expectPathMissing(path.join(tempDir, DEFAULT_BOOTSTRAP_FILENAME));
|
||||
});
|
||||
|
||||
@@ -678,9 +670,7 @@ describe("ensureAgentWorkspace", () => {
|
||||
await fs.mkdir(path.join(tempDir, ".git"), { recursive: true });
|
||||
await fs.writeFile(path.join(tempDir, ".git", "HEAD"), "ref: refs/heads/main\n");
|
||||
|
||||
const result = await reconcileWorkspaceBootstrapCompletion(tempDir);
|
||||
expect(result.repaired).toBe(false);
|
||||
expect(result.bootstrapExists).toBe(true);
|
||||
await ensureAgentWorkspace({ dir: tempDir, ensureBootstrapFiles: true });
|
||||
await expect(resolveWorkspaceBootstrapStatus(tempDir)).resolves.toBe("pending");
|
||||
await expect(
|
||||
fs.access(path.join(tempDir, DEFAULT_BOOTSTRAP_FILENAME)),
|
||||
|
||||
@@ -768,23 +768,6 @@ export async function isWorkspaceBootstrapPending(dir: string): Promise<boolean>
|
||||
return (await resolveWorkspaceBootstrapStatus(dir)) === "pending";
|
||||
}
|
||||
|
||||
export async function reconcileWorkspaceBootstrapCompletion(
|
||||
dir: string,
|
||||
): Promise<WorkspaceBootstrapCompletionReconcileResult> {
|
||||
const resolvedDir = resolveUserPath(dir);
|
||||
const statePath = resolveWorkspaceStatePath(resolvedDir);
|
||||
const bootstrapPath = path.join(resolvedDir, DEFAULT_BOOTSTRAP_FILENAME);
|
||||
const state = await readWorkspaceSetupStateForDir(resolvedDir, {
|
||||
persistLegacyMigration: true,
|
||||
});
|
||||
return await reconcileWorkspaceBootstrapCompletionState({
|
||||
dir: resolvedDir,
|
||||
bootstrapPath,
|
||||
statePath,
|
||||
state,
|
||||
});
|
||||
}
|
||||
|
||||
async function writeWorkspaceSetupState(
|
||||
statePath: string,
|
||||
state: WorkspaceSetupState,
|
||||
@@ -1244,14 +1227,6 @@ async function resolveExtraBootstrapPatternPaths(
|
||||
return matches.length > 0 ? matches : [pattern];
|
||||
}
|
||||
|
||||
export async function loadExtraBootstrapFiles(
|
||||
dir: string,
|
||||
extraPatterns: string[],
|
||||
): Promise<WorkspaceBootstrapFile[]> {
|
||||
const loaded = await loadExtraBootstrapFilesWithDiagnostics(dir, extraPatterns);
|
||||
return loaded.files;
|
||||
}
|
||||
|
||||
export async function loadExtraBootstrapFilesWithDiagnostics(
|
||||
dir: string,
|
||||
extraPatterns: string[],
|
||||
|
||||
@@ -321,10 +321,12 @@ describe("subcommand help cold imports", () => {
|
||||
});
|
||||
|
||||
it("keeps agents help out of agent action modules", async () => {
|
||||
const { registerAgentCommands } = await import("./program/register.agent.js");
|
||||
const { registerAgentsCommands } = await import("./program/register.agent.js");
|
||||
const { registerAgentTurnCommand } = await import("./program/register.agent-turn.js");
|
||||
const program = makeProgram();
|
||||
|
||||
registerAgentCommands(program, { agentChannelOptions: "last|telegram|discord" });
|
||||
registerAgentTurnCommand(program, { agentChannelOptions: "last|telegram|discord" });
|
||||
registerAgentsCommands(program);
|
||||
await expectHelpExit(program, ["agents", "--help"]);
|
||||
|
||||
expect(loaded.modules).not.toContain("agent-via-gateway-command");
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// Register agent tests cover agent command registration and option wiring.
|
||||
import { Command } from "commander";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { registerAgentCommands } from "./register.agent.js";
|
||||
import { registerAgentsCommands } from "./register.agent.js";
|
||||
import { registerAgentTurnCommand } from "./register.agent-turn.js";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
agentCliCommandMock: vi.fn(),
|
||||
@@ -65,10 +66,11 @@ vi.mock("../../runtime.js", () => ({
|
||||
defaultRuntime: mocks.runtime,
|
||||
}));
|
||||
|
||||
describe("registerAgentCommands", () => {
|
||||
describe("agent command registration", () => {
|
||||
async function runCli(args: string[]) {
|
||||
const program = new Command();
|
||||
registerAgentCommands(program, { agentChannelOptions: "last|telegram|discord" });
|
||||
registerAgentTurnCommand(program, { agentChannelOptions: "last|telegram|discord" });
|
||||
registerAgentsCommands(program);
|
||||
await program.parseAsync(args, { from: "user" });
|
||||
}
|
||||
|
||||
@@ -220,7 +222,7 @@ describe("registerAgentCommands", () => {
|
||||
|
||||
it("documents bind accountId resolution behavior in help text", () => {
|
||||
const program = new Command();
|
||||
registerAgentCommands(program, { agentChannelOptions: "last|telegram|discord" });
|
||||
registerAgentsCommands(program);
|
||||
const agents = program.commands.find((command) => command.name() === "agents");
|
||||
const bind = agents?.commands.find((command) => command.name() === "bind");
|
||||
const help = bind?.helpInformation() ?? "";
|
||||
|
||||
@@ -5,7 +5,6 @@ import { theme } from "../../../packages/terminal-core/src/theme.js";
|
||||
import { hasExplicitOptions } from "../command-options.js";
|
||||
import { formatHelpExamples } from "../help-format.js";
|
||||
import { collectOption } from "./helpers.js";
|
||||
import { registerAgentTurnCommand } from "./register.agent-turn.js";
|
||||
|
||||
type AgentsAddModule = typeof import("../../commands/agents.commands.add.js");
|
||||
type AgentsBindModule = typeof import("../../commands/agents.commands.bind.js");
|
||||
@@ -71,15 +70,6 @@ async function runAgentsCommandAction(
|
||||
});
|
||||
}
|
||||
|
||||
/** Register single-turn `agent` plus multi-agent management commands. */
|
||||
export function registerAgentCommands(
|
||||
program: Command,
|
||||
args: { agentChannelOptions: string },
|
||||
): void {
|
||||
registerAgentTurnCommand(program, args);
|
||||
registerAgentsCommands(program);
|
||||
}
|
||||
|
||||
/** Register `agents` management subcommands for config, bindings, identity, and deletion. */
|
||||
export function registerAgentsCommands(program: Command): void {
|
||||
const agents = program
|
||||
|
||||
Reference in New Issue
Block a user