Files
oh-my-opencode/packages/omo-codex/plugin/test/aggregate.test.mjs
T
YeonGyu-Kim bd867019f9 feat(omo-codex): wire Codex SessionStart telemetry for DAU/WAU/MAU
Adds a new Codex plugin component `telemetry` that emits a single
omo_codex_daily_active event (reason: session_start) from every Codex
SessionStart hook, with the same UTC-day deduplication, hashed
installation identifier, and four-flag opt-out as the install-time
event. Previously omo-codex telemetry only fired on install_completed,
so DAU/WAU/MAU under-reported real Codex usage.

- New plugin component packages/omo-codex/plugin/components/telemetry/
  mirrors the rules/comment-checker/lsp pattern: own src/, tsc build,
  vitest tests, package.json (posthog-node dep), hooks/hooks.json.
- src/codex-hook.ts wraps createPluginPostHog().trackActive(..., "session_start")
  with safeShutdown so Codex session startup never blocks on telemetry.
- Plugin root hooks.json + workspaces register the new component
  alongside rules and ultrawork on SessionStart.
- Aggregate test expectations updated to include the telemetry directory.
- cross-package-equivalence.test.ts pins product-identity constants and
  shouldDisablePostHog behavior to stay byte-equivalent between the CLI
  installer (src/telemetry/) and the plugin runtime
  (plugin/components/telemetry/src/), so the two PostHog sources never
  drift on event name, distinct_id base, dedup file path, or opt-out
  flags.
- PostHogActivityReason union in the CLI-side posthog.ts gains
  "session_start" so future CLI paths can emit the same reason without
  a type break.
2026-05-28 13:58:11 +09:00

81 lines
2.6 KiB
JavaScript

import assert from "node:assert/strict";
import { readdir, readFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import test from "node:test";
import { fileURLToPath } from "node:url";
const root = dirname(dirname(fileURLToPath(import.meta.url)));
async function readJson(relativePath) {
return JSON.parse(await readFile(join(root, relativePath), "utf8"));
}
test("#given aggregate plugin manifest #when inspected #then it owns the omo namespace", async () => {
// given
const manifest = await readJson(".codex-plugin/plugin.json");
// when
const hookPath = manifest.hooks;
const skillsPath = manifest.skills;
const mcpPath = manifest.mcpServers;
// then
assert.equal(manifest.name, "omo");
assert.equal(hookPath, "./hooks/hooks.json");
assert.equal(skillsPath, "./skills/");
assert.equal(mcpPath, "./.mcp.json");
});
test("#given isolated components #when hooks are inspected #then commands stay inside component roots", async () => {
// given
const hooks = await readJson("hooks/hooks.json");
const text = JSON.stringify(hooks);
// when
const componentMarkers = [
"components/comment-checker/dist/cli.js",
"components/lsp/dist/cli.js",
"components/rules/dist/cli.js",
"components/telemetry/dist/cli.js",
"components/ultragoal/dist/cli.js",
"components/ultrawork/hooks/sync-agents.py",
"components/ultrawork/hooks/ultrawork-detector.py",
];
// then
for (const marker of componentMarkers) {
assert.match(text, new RegExp(marker.replaceAll("/", "\\/")));
}
assert.doesNotMatch(text, /codex-(comment-checker|lsp|rules|telemetry|ultragoal|ultrawork)@/);
});
test("#given aggregate MCP config #when inspected #then lsp server stays component isolated", async () => {
// given
const mcp = await readJson(".mcp.json");
// when
const server = mcp.mcpServers.lsp;
// then
assert.equal(server.command, "node");
assert.deepEqual(server.args, ["./components/lsp/packages/lsp-tools-mcp/dist/cli.js", "mcp"]);
assert.equal(server.cwd, ".");
});
test("#given component directories #when scanned #then only root owns plugin identity", async () => {
// given
const components = await readdir(join(root, "components"), { withFileTypes: true });
// when
const componentNames = components.filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
// then
assert.deepEqual(componentNames, ["comment-checker", "lsp", "rules", "telemetry", "ultragoal", "ultrawork"]);
for (const name of componentNames) {
await assert.rejects(
readFile(join(root, "components", name, ".codex-plugin", "plugin.json"), "utf8"),
/code: 'ENOENT'|ENOENT/,
);
}
});