Skip to content

Commit 189e97d

Browse files
committed
wip
1 parent 80bc86e commit 189e97d

File tree

6 files changed

+33
-21
lines changed

6 files changed

+33
-21
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"check:types": "tsc --noEmit --project tsconfig.json",
3030
"reformat": "prettier --write .",
3131
"generate": "./scripts/generate.sh",
32-
"test": "node --experimental-vm-modules ./node_modules/.bin/jest --coverage"
32+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage"
3333
},
3434
"license": "Apache-2.0",
3535
"devDependencies": {

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ try {
2020
version: packageInfo.version,
2121
});
2222

23-
const telemetry = Telemetry.create(session);
23+
const telemetry = Telemetry.create(session, config);
2424

2525
const server = new Server({
2626
mcpServer,

src/telemetry/telemetry.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export class Telemetry {
7171
return this.commonProperties.device_id;
7272
}
7373

74-
const originalId = await nodeMachineId.machineId(true);
74+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
75+
const originalId: string = await nodeMachineId.machineId(true);
7576

7677
// Create a hashed format from the all uppercase version of the machine ID
7778
// to match it exactly with the denisbrodbeck/machineid library that Atlas CLI uses.

tests/integration/telemetry.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import { createHmac } from "crypto";
2-
import { machineId } from "node-machine-id";
2+
import nodeMachineId from "node-machine-id";
33
import { Telemetry } from "../../src/telemetry/telemetry.js";
44
import { Session } from "../../src/session.js";
5+
import { config } from "../../src/config.js";
56

67
describe("Telemetry", () => {
78
it("should resolve the actual machine ID", async () => {
8-
const actualId = await machineId(true);
9+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
10+
const actualId: string = await nodeMachineId.machineId(true);
911
const actualHashedId = createHmac("sha256", actualId.toUpperCase()).update("atlascli").digest("hex");
1012

1113
const telemetry = Telemetry.create(
1214
new Session({
1315
apiBaseUrl: "",
14-
})
16+
}),
17+
config
1518
);
1619

1720
expect(telemetry.getCommonProperties().device_id).toBe(undefined);

tests/unit/deferred-promise.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { DeferredPromise } from "../../src/deferred-promise.js";
2+
import { jest } from "@jest/globals";
23

34
describe("DeferredPromise", () => {
45
beforeEach(() => {

tests/unit/telemetry.test.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Mock node-machine-id to simulate machine ID resolution
2+
jest.mock("node-machine-id", () => ({
3+
machineId: jest.fn(),
4+
}));
5+
16
import { ApiClient } from "../../src/common/atlas/apiClient.js";
27
import { Session } from "../../src/session.js";
38
import { DEVICE_ID_TIMEOUT, Telemetry } from "../../src/telemetry/telemetry.js";
@@ -6,6 +11,9 @@ import { EventCache } from "../../src/telemetry/eventCache.js";
611
import { config } from "../../src/config.js";
712
import { MACHINE_METADATA } from "../../src/telemetry/constants.js";
813
import { jest } from "@jest/globals";
14+
import { createHmac } from "crypto";
15+
import logger, { LogId } from "../../src/logger.js";
16+
import nodeMachineId from "node-machine-id";
917

1018
// Mock the ApiClient to avoid real API calls
1119
jest.mock("../../src/common/atlas/apiClient.js");
@@ -15,14 +23,7 @@ const MockApiClient = ApiClient as jest.MockedClass<typeof ApiClient>;
1523
jest.mock("../../src/telemetry/eventCache.js");
1624
const MockEventCache = EventCache as jest.MockedClass<typeof EventCache>;
1725

18-
// Mock node-machine-id to simulate machine ID resolution
19-
jest.mock("node-machine-id", () => ({
20-
machineId: jest.fn(),
21-
}));
22-
23-
import * as nodeMachineId from "node-machine-id";
24-
import { createHmac } from "crypto";
25-
import logger, { LogId } from "../../src/logger.js";
26+
const mockMachineId = jest.spyOn(nodeMachineId, "machineId");
2627

2728
describe("Telemetry", () => {
2829
let mockApiClient: jest.Mocked<ApiClient>;
@@ -145,7 +146,9 @@ describe("Telemetry", () => {
145146

146147
describe("sending events", () => {
147148
beforeEach(() => {
148-
(nodeMachineId.machineId as jest.Mock).mockResolvedValue("test-machine-id");
149+
// @ts-expect-error This is a workaround
150+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
151+
mockMachineId.mockResolvedValue("test-machine-id");
149152
});
150153

151154
describe("when telemetry is enabled", () => {
@@ -265,8 +268,9 @@ describe("Telemetry", () => {
265268
});
266269

267270
it("should successfully resolve the machine ID", async () => {
268-
(nodeMachineId.machineId as jest.Mock).mockResolvedValue(machineId);
269-
telemetry = Telemetry.create(session);
271+
// @ts-expect-error This is a workaround
272+
mockMachineId.mockResolvedValue(machineId);
273+
telemetry = Telemetry.create(session, config);
270274

271275
expect(telemetry["isBufferingEvents"]).toBe(true);
272276
expect(telemetry.getCommonProperties().device_id).toBe(undefined);
@@ -280,9 +284,11 @@ describe("Telemetry", () => {
280284
it("should handle machine ID resolution failure", async () => {
281285
const loggerSpy = jest.spyOn(logger, "debug");
282286

283-
(nodeMachineId.machineId as jest.Mock).mockRejectedValue(new Error("Failed to get device ID"));
287+
// @ts-expect-error This is a workaround
288+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
289+
mockMachineId.mockRejectedValue(new Error("Failed to get device ID"));
284290

285-
telemetry = Telemetry.create(session);
291+
telemetry = Telemetry.create(session, config);
286292

287293
expect(telemetry["isBufferingEvents"]).toBe(true);
288294
expect(telemetry.getCommonProperties().device_id).toBe(undefined);
@@ -302,11 +308,12 @@ describe("Telemetry", () => {
302308
it("should timeout if machine ID resolution takes too long", async () => {
303309
const loggerSpy = jest.spyOn(logger, "debug");
304310

305-
(nodeMachineId.machineId as jest.Mock).mockImplementation(() => {
311+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
312+
mockMachineId.mockImplementation(() => {
306313
return new Promise(() => {});
307314
});
308315

309-
telemetry = Telemetry.create(session);
316+
telemetry = Telemetry.create(session, config);
310317

311318
expect(telemetry["isBufferingEvents"]).toBe(true);
312319
expect(telemetry.getCommonProperties().device_id).toBe(undefined);

0 commit comments

Comments
 (0)