Files
oh-my-opencode/packages/omo-claude/scripts/sync-telemetry-component.test.mjs
T
YeonGyu-Kim c39d16c378 feat(omo-claude): copy telemetry component sync script
Product-agnostic sync-telemetry-component.mjs (verbatim from omo-codex) +
test; generates the telemetry component's atomic-write/data-path/env-flags/
posthog-activity-state from src/telemetry. product-identity is authored
per-package, not synced.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-29 13:40:10 +09:00

71 lines
2.2 KiB
JavaScript

import assert from "node:assert/strict";
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
const SCRIPT_PATH = new URL("./sync-telemetry-component.mjs", import.meta.url);
async function makeTempDir() {
return mkdtemp(join(tmpdir(), "omo-claude-telemetry-sync-"));
}
async function runSync(args) {
const { syncTelemetryComponent } = await import(SCRIPT_PATH);
return syncTelemetryComponent(args);
}
test("#given stale telemetry component files #when sync runs #then pure package telemetry source rewrites the component copy", async () => {
// given
const root = await makeTempDir();
const sourceDir = join(root, "source");
const componentDir = join(root, "component");
await mkdir(sourceDir);
await mkdir(componentDir);
await writeFile(join(sourceDir, "atomic-write.ts"), "export const source = true\n", { flush: true });
await writeFile(join(componentDir, "atomic-write.ts"), "export const stale = true\n", { flush: true });
try {
// when
const result = await runSync({
sourceDir,
componentDir,
files: ["atomic-write.ts"],
check: false,
});
// then
assert.deepEqual(result, {
checked: false,
changed: ["atomic-write.ts"],
});
assert.equal(await readFile(join(componentDir, "atomic-write.ts"), "utf8"), "export const source = true\n");
} finally {
await rm(root, { recursive: true, force: true });
}
});
test("#given a missing pure telemetry source file #when sync runs #then it fails with the missing source path", async () => {
// given
const root = await makeTempDir();
const sourceDir = join(root, "source");
const componentDir = join(root, "component");
await mkdir(componentDir);
await writeFile(join(componentDir, "atomic-write.ts"), "export const stale = true\n", { flush: true });
try {
// when / then
await assert.rejects(
runSync({
sourceDir,
componentDir,
files: ["atomic-write.ts"],
check: false,
}),
(error) => error instanceof Error && error.message.includes(join(sourceDir, "atomic-write.ts")),
);
} finally {
await rm(root, { recursive: true, force: true });
}
});