mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
app_version was attached only to feedback events; every other allowlist stripped it, so the install base could not be segmented by release. One property on the once-per-boot census event covers it. Fixes #674.
65 lines
2.3 KiB
TypeScript
65 lines
2.3 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const mockExistsSync = vi.hoisted(() => vi.fn());
|
|
const mockDeployMode = vi.hoisted(() => vi.fn());
|
|
|
|
vi.mock("node:fs", () => ({
|
|
existsSync: mockExistsSync,
|
|
}));
|
|
vi.mock("../../../apps/api/src/lib/deploy-mode.js", () => ({
|
|
deployMode: mockDeployMode,
|
|
}));
|
|
|
|
import { APP_VERSION } from "@snapotter/shared";
|
|
import { gatherSystemProperties } from "../../../apps/api/src/lib/system-info.js";
|
|
|
|
describe("gatherSystemProperties", () => {
|
|
const origArch = process.arch;
|
|
|
|
afterEach(() => {
|
|
Object.defineProperty(process, "arch", { value: origArch, configurable: true });
|
|
mockExistsSync.mockReset();
|
|
mockDeployMode.mockReset();
|
|
});
|
|
|
|
it("reports arm64 for an arm64 process", () => {
|
|
Object.defineProperty(process, "arch", { value: "arm64", configurable: true });
|
|
mockDeployMode.mockReturnValue("native");
|
|
mockExistsSync.mockReturnValue(false);
|
|
expect(gatherSystemProperties().arch).toBe("arm64");
|
|
});
|
|
|
|
it("reports amd64 for an x64 process", () => {
|
|
Object.defineProperty(process, "arch", { value: "x64", configurable: true });
|
|
mockDeployMode.mockReturnValue("native");
|
|
mockExistsSync.mockReturnValue(false);
|
|
expect(gatherSystemProperties().arch).toBe("amd64");
|
|
});
|
|
|
|
it("reports gpu_present true when /dev/nvidia0 exists", () => {
|
|
mockExistsSync.mockImplementation((p: string) => p === "/dev/nvidia0");
|
|
mockDeployMode.mockReturnValue("external");
|
|
expect(gatherSystemProperties().gpu_present).toBe(true);
|
|
});
|
|
|
|
it("reports gpu_present false when /dev/nvidia0 is absent", () => {
|
|
mockExistsSync.mockReturnValue(false);
|
|
mockDeployMode.mockReturnValue("external");
|
|
expect(gatherSystemProperties().gpu_present).toBe(false);
|
|
});
|
|
|
|
it("carries the app version so release adoption is measurable", () => {
|
|
mockDeployMode.mockReturnValue("embedded");
|
|
mockExistsSync.mockReturnValue(false);
|
|
expect(gatherSystemProperties().app_version).toBe(APP_VERSION);
|
|
});
|
|
|
|
it("passes through deploy mode and os platform", () => {
|
|
mockDeployMode.mockReturnValue("embedded");
|
|
mockExistsSync.mockReturnValue(false);
|
|
const props = gatherSystemProperties();
|
|
expect(props.deploy_mode).toBe("embedded");
|
|
expect(props.os_platform).toBe(process.platform);
|
|
});
|
|
});
|