






















@@ -3,7 +3,7 @@ import fs from "node:fs/promises";
33import os from "node:os";
44import path from "node:path";
55import { afterEach, describe, expect, it, vi } from "vitest";
6-import { captureEnv } from "../test-utils/env.js";
6+import { withEnvAsync } from "../test-utils/env.js";
77import type { PluginManifestRecord } from "./manifest-registry.js";
8899const mocks = vi.hoisted(() => ({
@@ -95,83 +95,83 @@ function expectEnabledClaudeBundleCommands(
95959696describe("loadEnabledClaudeBundleCommands", () => {
9797it("loads enabled Claude bundle markdown commands and skips disabled-model-invocation entries", async () => {
98-const env = captureEnv(["HOME", "USERPROFILE", "OPENCLAW_HOME", "OPENCLAW_STATE_DIR"]);
99-try {
100-const homeDir = await createTempDir("openclaw-bundle-commands-home-");
101-const workspaceDir = await createTempDir("openclaw-bundle-commands-workspace-");
102-process.env.HOME = homeDir;
103-process.env.USERPROFILE = homeDir;
104-delete process.env.OPENCLAW_HOME;
105-delete process.env.OPENCLAW_STATE_DIR;
98+const homeDir = await createTempDir("openclaw-bundle-commands-home-");
99+const workspaceDir = await createTempDir("openclaw-bundle-commands-workspace-");
100+await withEnvAsync(
101+{
102+HOME: homeDir,
103+USERPROFILE: homeDir,
104+OPENCLAW_HOME: undefined,
105+OPENCLAW_STATE_DIR: undefined,
106+},
107+async () => {
108+await writeClaudeBundleCommandFixture({
109+ homeDir,
110+pluginId: "compound-bundle",
111+commands: [
112+{
113+relativePath: "commands/office-hours.md",
114+contents: [
115+"---",
116+"description: Help with scoping and architecture",
117+"---",
118+"Give direct engineering advice.",
119+],
120+},
121+{
122+relativePath: "commands/workflows/review.md",
123+contents: [
124+"---",
125+"name: workflows:review",
126+"description: Run a structured review",
127+"---",
128+"Review the code. $ARGUMENTS",
129+],
130+},
131+{
132+relativePath: "commands/disabled.md",
133+contents: ["---", "disable-model-invocation: true", "---", "Do not load me."],
134+},
135+],
136+});
106137107-await writeClaudeBundleCommandFixture({
108- homeDir,
109-pluginId: "compound-bundle",
110-commands: [
111-{
112-relativePath: "commands/office-hours.md",
113-contents: [
114-"---",
115-"description: Help with scoping and architecture",
116-"---",
117-"Give direct engineering advice.",
118-],
138+const commands = loadEnabledClaudeBundleCommands({
139+ workspaceDir,
140+cfg: {
141+plugins: {
142+entries: { "compound-bundle": { enabled: true } },
143+},
119144},
145+});
146+147+expectEnabledClaudeBundleCommands(commands, [
120148{
121-relativePath: "commands/workflows/review.md",
122-contents: [
123-"---",
124-"name: workflows:review",
125-"description: Run a structured review",
126-"---",
127-"Review the code. $ARGUMENTS",
128-],
149+pluginId: "compound-bundle",
150+rawName: "office-hours",
151+description: "Help with scoping and architecture",
152+promptTemplate: "Give direct engineering advice.",
153+sourceFilePath: path.join(
154+resolveBundlePluginRoot(homeDir, "compound-bundle"),
155+"commands",
156+"office-hours.md",
157+),
129158},
130159{
131-relativePath: "commands/disabled.md",
132-contents: ["---", "disable-model-invocation: true", "---", "Do not load me."],
133-},
134-],
135-});
136-137-const commands = loadEnabledClaudeBundleCommands({
138- workspaceDir,
139-cfg: {
140-plugins: {
141-entries: { "compound-bundle": { enabled: true } },
160+pluginId: "compound-bundle",
161+rawName: "workflows:review",
162+description: "Run a structured review",
163+promptTemplate: "Review the code. $ARGUMENTS",
164+sourceFilePath: path.join(
165+resolveBundlePluginRoot(homeDir, "compound-bundle"),
166+"commands",
167+"workflows",
168+"review.md",
169+),
142170},
143-},
144-});
145-146-expectEnabledClaudeBundleCommands(commands, [
147-{
148-pluginId: "compound-bundle",
149-rawName: "office-hours",
150-description: "Help with scoping and architecture",
151-promptTemplate: "Give direct engineering advice.",
152-sourceFilePath: path.join(
153-resolveBundlePluginRoot(homeDir, "compound-bundle"),
154-"commands",
155-"office-hours.md",
156-),
157-},
158-{
159-pluginId: "compound-bundle",
160-rawName: "workflows:review",
161-description: "Run a structured review",
162-promptTemplate: "Review the code. $ARGUMENTS",
163-sourceFilePath: path.join(
164-resolveBundlePluginRoot(homeDir, "compound-bundle"),
165-"commands",
166-"workflows",
167-"review.md",
168-),
169-},
170-]);
171-const rawNames = commands.map((entry) => entry.rawName);
172-expect(rawNames).not.toContain("disabled");
173-} finally {
174-env.restore();
175-}
171+]);
172+const rawNames = commands.map((entry) => entry.rawName);
173+expect(rawNames).not.toContain("disabled");
174+},
175+);
176176});
177177});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。