@disco_trooper/apple-notes-mcp 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,70 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
+
3
+ describe("runtime checks", () => {
4
+ beforeEach(() => {
5
+ vi.resetModules();
6
+ });
7
+
8
+ describe("isBunRuntime", () => {
9
+ it("should return false when Bun global is not defined", async () => {
10
+ // vitest runs in Node.js, so Bun is not defined
11
+ const { isBunRuntime } = await import("./runtime.js");
12
+ expect(isBunRuntime()).toBe(false);
13
+ });
14
+
15
+ it("should return true when Bun global is defined", async () => {
16
+ // Mock Bun global
17
+ (globalThis as Record<string, unknown>).Bun = {};
18
+ const { isBunRuntime } = await import("./runtime.js");
19
+ expect(isBunRuntime()).toBe(true);
20
+ delete (globalThis as Record<string, unknown>).Bun;
21
+ });
22
+ });
23
+
24
+ describe("checkBunRuntime", () => {
25
+ let mockExit: ReturnType<typeof vi.spyOn>;
26
+ let mockConsoleError: ReturnType<typeof vi.spyOn>;
27
+
28
+ beforeEach(() => {
29
+ mockExit = vi.spyOn(process, "exit").mockImplementation(() => {
30
+ throw new Error("process.exit called");
31
+ });
32
+ mockConsoleError = vi.spyOn(console, "error").mockImplementation(() => {});
33
+ });
34
+
35
+ afterEach(() => {
36
+ mockExit.mockRestore();
37
+ mockConsoleError.mockRestore();
38
+ delete (globalThis as Record<string, unknown>).Bun;
39
+ });
40
+
41
+ it("should exit with error message when Bun is not available", async () => {
42
+ const { checkBunRuntime } = await import("./runtime.js");
43
+ expect(() => checkBunRuntime()).toThrow("process.exit called");
44
+ expect(mockExit).toHaveBeenCalledWith(1);
45
+ expect(mockConsoleError).toHaveBeenCalled();
46
+ });
47
+
48
+ it("should not exit when Bun is available", async () => {
49
+ (globalThis as Record<string, unknown>).Bun = {};
50
+ const { checkBunRuntime } = await import("./runtime.js");
51
+ expect(() => checkBunRuntime()).not.toThrow();
52
+ expect(mockExit).not.toHaveBeenCalled();
53
+ });
54
+ });
55
+
56
+ describe("isTTY", () => {
57
+ it("should return boolean", async () => {
58
+ const { isTTY } = await import("./runtime.js");
59
+ expect(typeof isTTY()).toBe("boolean");
60
+ });
61
+
62
+ it("should return false when stdin or stdout is not a TTY", async () => {
63
+ // In CI/test environments, typically not a TTY
64
+ const { isTTY } = await import("./runtime.js");
65
+ // The result depends on the environment, but it should be a boolean
66
+ const result = isTTY();
67
+ expect(result === true || result === false).toBe(true);
68
+ });
69
+ });
70
+ });
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Runtime environment checks.
3
+ */
4
+
5
+ /**
6
+ * Check if running in Bun runtime.
7
+ */
8
+ export function isBunRuntime(): boolean {
9
+ return typeof Bun !== "undefined";
10
+ }
11
+
12
+ /**
13
+ * Check Bun runtime and throw helpful error if not available.
14
+ */
15
+ export function checkBunRuntime(): void {
16
+ if (!isBunRuntime()) {
17
+ console.error(`
18
+ ╭─────────────────────────────────────────────────────────────╮
19
+ │ apple-notes-mcp requires Bun runtime │
20
+ │ │
21
+ │ Install Bun: │
22
+ │ curl -fsSL https://bun.sh/install | bash │
23
+ │ │
24
+ │ Or with Homebrew: │
25
+ │ brew install bun │
26
+ │ │
27
+ │ Then run again: │
28
+ │ apple-notes-mcp │
29
+ ╰─────────────────────────────────────────────────────────────╯
30
+ `);
31
+ process.exit(1);
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Check if running in interactive terminal (TTY).
37
+ */
38
+ export function isTTY(): boolean {
39
+ return process.stdin.isTTY === true && process.stdout.isTTY === true;
40
+ }