Files
oh-my-opencode/packages/omo-codex/plugin/test/sync-hook-status-messages.test.mjs
T
2026-05-31 11:53:18 +09:00

67 lines
2.3 KiB
JavaScript

import assert from "node:assert/strict";
import { mkdtemp, mkdir, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { tmpdir } from "node:os";
import test from "node:test";
import { syncHookStatusMessages } from "../scripts/sync-hook-status-messages.mjs";
async function writeJson(path, value) {
await writeFile(path, `${JSON.stringify(value, null, "\t")}\n`);
}
async function readJson(path) {
return JSON.parse(await readFile(path, "utf8"));
}
test("#given a component without hooks #when hook status messages sync #then build-time version sync skips it", async () => {
// given
const root = await mkdtemp(join(tmpdir(), "omo-codex-hook-status-"));
await mkdir(join(root, ".codex-plugin"), { recursive: true });
await mkdir(join(root, "hooks"), { recursive: true });
await mkdir(join(root, "components", "comment-checker", "hooks"), { recursive: true });
await mkdir(join(root, "components", "git-bash"), { recursive: true });
await writeJson(join(root, ".codex-plugin", "plugin.json"), { version: "0.1.0" });
await writeJson(join(root, "components", "comment-checker", "package.json"), { version: "0.1.1" });
await writeJson(join(root, "components", "git-bash", "package.json"), { version: "0.3.0" });
await writeJson(join(root, "hooks", "hooks.json"), {
hooks: {
PostToolUse: [
{
hooks: [
{
type: "command",
command: 'node "${PLUGIN_ROOT}/components/comment-checker/dist/cli.js" hook post-tool-use',
statusMessage: "LazyCodex(0.1.0): Checking Comments",
},
],
},
],
},
});
await writeJson(join(root, "components", "comment-checker", "hooks", "hooks.json"), {
hooks: {
PostToolUse: [
{
hooks: [
{
type: "command",
command: 'node "${PLUGIN_ROOT}/dist/cli.js" hook post-tool-use',
statusMessage: "LazyCodex(0.1.0): Checking Comments",
},
],
},
],
},
});
// when
await syncHookStatusMessages(root);
// then
const aggregateHooks = await readJson(join(root, "hooks", "hooks.json"));
const componentHooks = await readJson(join(root, "components", "comment-checker", "hooks", "hooks.json"));
assert.equal(aggregateHooks.hooks.PostToolUse[0].hooks[0].statusMessage, "LazyCodex(0.1.1): Checking Comments");
assert.equal(componentHooks.hooks.PostToolUse[0].hooks[0].statusMessage, "LazyCodex(0.1.1): Checking Comments");
});