/ opencodehub / tests / smoke / boot-smoke.test.ts
Swadhin Biswas Feature/ai code reviewer (#79) · 8/16/2026
cfd400d
66 lines · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
 * Smoke: boot-critical module wiring
 *
 * Fast checks that the app's foundation modules (env validation, DB factory,
 * storage factory, auth primitives) initialize correctly on a clean boot.
 * These run in seconds and catch import-time/dependency regressions.
 */
import { describe, expect, it } from "vitest";

describe("boot smoke: environment validation", () => {
  it("validates environment without throwing when values are defaulted", async () => {
    const { validateEnvironment } = await import("@/lib/env-validation");
    // Must return boolean (true when valid, false when invalid) — never throw
    const result = validateEnvironment(false);
    expect(typeof result).toBe("boolean");
  });
});

describe("boot smoke: storage factory", () => {
  it("resolves the local adapter and exposes the StorageAdapter interface", async () => {
    const { getStorage, LocalStorageAdapter } = await import(
      "@/lib/storage"
    );
    expect(LocalStorageAdapter).toBeTruthy();
    const storage = await getStorage();
    expect(storage).toBeTruthy();
    // Core interface methods exist
    for (const m of ["put", "get", "delete", "exists", "list"]) {
      expect(typeof (storage as any)[m], `missing method ${m}`).toBe(
        "function",
      );
    }
  });

  it("reports a valid storage type", async () => {
    const { getStorageConfig } = await import("@/lib/storage");
    expect(["local", "s3"]).toContain(getStorageConfig().type);
  });
});

describe("boot smoke: db factory", () => {
  it("reports a valid driver type without connecting", async () => {
    const { getDriverType } = await import("@/db");
    expect(["postgres", "sqlite", "libsql"]).toContain(getDriverType());
  });
});

describe("boot smoke: auth primitives", () => {
  it("exposes password hashing and verification", async () => {
    const { hashPassword, verifyPassword } = await import("@/lib/auth");
    const hash = await hashPassword("smoke-test-password-123");
    expect(hash).not.toBe("smoke-test-password-123");
    expect(hash.length).toBeGreaterThan(20);
    expect(await verifyPassword("smoke-test-password-123", hash)).toBe(true);
    expect(await verifyPassword("wrong", hash)).toBe(false);
  });
});

describe("boot smoke: git utilities", () => {
  it("imports the git wrapper without native module errors", async () => {
    const mod = await import("@/lib/git");
    expect(mod).toBeTruthy();
    expect(typeof mod.getGit).toBe("function");
  });
});