mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 23:21:23 +00:00
style: format agent workspace and prompts
This commit is contained in:
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { runCommandWithTimeout } from "../process/exec.js";
|
||||
import type { WorkspaceBootstrapFile } from "./workspace.js";
|
||||
import {
|
||||
DEFAULT_AGENTS_FILENAME,
|
||||
@@ -40,6 +41,34 @@ describe("ensureAgentWorkspace", () => {
|
||||
await expect(fs.stat(bootstrap)).resolves.toBeDefined();
|
||||
});
|
||||
|
||||
it("initializes a git repo for brand-new workspaces when git is available", async () => {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-ws-"));
|
||||
const nested = path.join(dir, "nested");
|
||||
const gitAvailable = await runCommandWithTimeout(["git", "--version"], { timeoutMs: 2_000 })
|
||||
.then((res) => res.code === 0)
|
||||
.catch(() => false);
|
||||
if (!gitAvailable) return;
|
||||
|
||||
await ensureAgentWorkspace({
|
||||
dir: nested,
|
||||
ensureBootstrapFiles: true,
|
||||
});
|
||||
|
||||
await expect(fs.stat(path.join(nested, ".git"))).resolves.toBeDefined();
|
||||
});
|
||||
|
||||
it("does not initialize git when workspace already exists", async () => {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-ws-"));
|
||||
await fs.writeFile(path.join(dir, "AGENTS.md"), "custom", "utf-8");
|
||||
|
||||
await ensureAgentWorkspace({
|
||||
dir,
|
||||
ensureBootstrapFiles: true,
|
||||
});
|
||||
|
||||
await expect(fs.stat(path.join(dir, ".git"))).rejects.toBeDefined();
|
||||
});
|
||||
|
||||
it("does not overwrite existing AGENTS.md", async () => {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-ws-"));
|
||||
const agentsPath = path.join(dir, "AGENTS.md");
|
||||
|
||||
Reference in New Issue
Block a user