Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions packages/cli/src/telemetry/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { describe, expect, it, vi, beforeEach } from "vitest";
import { readFileSync, unlinkSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";

// CI exports HYPERFRAMES_NO_TELEMETRY=1 (and users may set DO_NOT_TRACK), which
// makes shouldTrack() short-circuit — and it caches that decision for the module's
Expand Down Expand Up @@ -319,15 +321,36 @@ describe("telemetry queue delivery", () => {
expect(args.join(" ").length).toBeLessThan(32_767);
});

it("flushSync warns when the child cannot be started", () => {
it("flushSync stays silent when the child cannot be started", () => {
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
spawnMock.mockImplementationOnce(() => {
throw new Error("spawn failed");
});
trackEvent("render_complete", { quality: "draft" });
flushSync();
expect(warn).toHaveBeenCalledWith(expect.stringContaining("spawn failed"));
expect(() => flushSync()).not.toThrow();
expect(warn).not.toHaveBeenCalled();
warn.mockRestore();
});

it("flushSync stays silent when the scratch folder cannot be written", () => {
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
const error = vi.spyOn(console, "error").mockImplementation(() => {});
const missing = join(tmpdir(), `hf-no-such-scratch-${process.pid}`);
const names = ["TMPDIR", "TEMP", "TMP"];
const before = names.map((name) => process.env[name]);
for (const name of names) vi.stubEnv(name, missing);
spawnMock.mockClear();
trackEvent("render_complete", { quality: "draft" });
try {
expect(() => flushSync()).not.toThrow();
} finally {
names.forEach((name, i) => vi.stubEnv(name, before[i]));
}
expect(spawnMock).not.toHaveBeenCalled();
expect(warn).not.toHaveBeenCalled();
expect(error).not.toHaveBeenCalled();
warn.mockRestore();
error.mockRestore();
});
});

Expand Down
6 changes: 1 addition & 5 deletions packages/cli/src/telemetry/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { randomUUID } from "node:crypto";
import { unlinkSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { diag } from "../ui/diagnostics.js";
import { POSTHOG_API_KEY } from "./posthogKey.js";
import { readConfig } from "./config.js";
import { hostAnswers } from "../utils/hostAnswers.js";
Expand Down Expand Up @@ -190,12 +189,9 @@ export function flushSync(): void {
);
// Let the parent exit without waiting for the child
child.unref();
} catch (error) {
} catch {
try {
unlinkSync(file);
} catch {}
diag.warn(
`hyperframes: telemetry was not sent (${error instanceof Error ? error.message : error})`,
);
}
}
Loading