claude-code-gitea-action/base-action/test/prepare-prompt.test.ts
claude (ops) 32685a740f
Some checks failed
Test Custom Executables / test-custom-executables (push) Has been cancelled
CI / test (push) Has been cancelled
CI / prettier (push) Has been cancelled
CI / typecheck (push) Has been cancelled
Sync Base Action to claude-code-base-action / Sync base-action to claude-code-base-action repository (push) Has been cancelled
Test Claude Code Action / test-inline-prompt (push) Has been cancelled
Test Claude Code Action / test-prompt-file (push) Has been cancelled
Test Claude Env Feature / test-claude-env-with-comments (push) Has been cancelled
Test MCP Servers / test-mcp-integration (push) Has been cancelled
Test MCP Servers / test-mcp-config-flag (push) Has been cancelled
Test Settings Feature / test-settings-inline-allow (push) Has been cancelled
Test Settings Feature / test-settings-inline-deny (push) Has been cancelled
Test Settings Feature / test-settings-file-allow (push) Has been cancelled
Test Settings Feature / test-settings-file-deny (push) Has been cancelled
Forgejo-patched claude-code-gitea-action (View-job URL uses per-repo run index)
Fork of markwylde/claude-code-gitea-action@b744372 (v1.0.21) with the
'View job' link fixed to use GITHUB_RUN_NUMBER (per-repo index) instead of
GITHUB_RUN_ID (global id), because Forgejo routes run pages by per-repo index.
See VENDOR.txt.
2026-07-01 06:42:55 +00:00

114 lines
3.1 KiB
TypeScript

#!/usr/bin/env bun
import { describe, test, expect, beforeEach, afterEach } from "bun:test";
import { preparePrompt, type PreparePromptInput } from "../src/prepare-prompt";
import { unlink, writeFile, readFile, stat } from "fs/promises";
describe("preparePrompt integration tests", () => {
beforeEach(async () => {
try {
await unlink("/tmp/claude-action/prompt.txt");
} catch {
// Ignore if file doesn't exist
}
});
afterEach(async () => {
try {
await unlink("/tmp/claude-action/prompt.txt");
} catch {
// Ignore if file doesn't exist
}
});
test("should create temporary prompt file when only prompt is provided", async () => {
const input: PreparePromptInput = {
prompt: "This is a test prompt",
promptFile: "",
};
const config = await preparePrompt(input);
expect(config.path).toBe("/tmp/claude-action/prompt.txt");
expect(config.type).toBe("inline");
const fileContent = await readFile(config.path, "utf-8");
expect(fileContent).toBe("This is a test prompt");
const fileStat = await stat(config.path);
expect(fileStat.size).toBeGreaterThan(0);
});
test("should use existing file when promptFile is provided", async () => {
const testFilePath = "/tmp/test-prompt.txt";
await writeFile(testFilePath, "Prompt from file");
const input: PreparePromptInput = {
prompt: "",
promptFile: testFilePath,
};
const config = await preparePrompt(input);
expect(config.path).toBe(testFilePath);
expect(config.type).toBe("file");
await unlink(testFilePath);
});
test("should fail when neither prompt nor promptFile is provided", async () => {
const input: PreparePromptInput = {
prompt: "",
promptFile: "",
};
await expect(preparePrompt(input)).rejects.toThrow(
"Neither 'prompt' nor 'prompt_file' was provided",
);
});
test("should fail when promptFile points to non-existent file", async () => {
const input: PreparePromptInput = {
prompt: "",
promptFile: "/tmp/non-existent-file.txt",
};
await expect(preparePrompt(input)).rejects.toThrow(
"Prompt file '/tmp/non-existent-file.txt' does not exist.",
);
});
test("should fail when prompt is empty", async () => {
const emptyFilePath = "/tmp/empty-prompt.txt";
await writeFile(emptyFilePath, "");
const input: PreparePromptInput = {
prompt: "",
promptFile: emptyFilePath,
};
await expect(preparePrompt(input)).rejects.toThrow("Prompt file is empty");
try {
await unlink(emptyFilePath);
} catch {
// Ignore cleanup errors
}
});
test("should fail when both prompt and promptFile are provided", async () => {
const testFilePath = "/tmp/test-prompt.txt";
await writeFile(testFilePath, "Prompt from file");
const input: PreparePromptInput = {
prompt: "This should cause an error",
promptFile: testFilePath,
};
await expect(preparePrompt(input)).rejects.toThrow(
"Both 'prompt' and 'prompt_file' were provided. Please specify only one.",
);
await unlink(testFilePath);
});
});