@checkstack/backend 0.15.0 → 0.16.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.
@@ -1,28 +1,53 @@
1
- import { describe, it, expect, beforeEach, mock } from "bun:test";
1
+ import { describe, it, expect, beforeEach, afterAll, mock } from "bun:test";
2
2
  import {
3
3
  extractPluginMetadata,
4
4
  discoverLocalPlugins,
5
5
  syncPluginsToDatabase,
6
6
  type PluginMetadata,
7
7
  } from "./plugin-discovery";
8
+ import * as realFs from "node:fs";
8
9
  import fs from "node:fs";
9
10
  import path from "node:path";
10
11
 
11
- // Mock filesystem for testing
12
+ // Mock filesystem for testing.
13
+ //
14
+ // `mock.module("node:fs", …)` is PROCESS-GLOBAL in bun and is NOT undone by
15
+ // `mock.restore()`, so a partial stub would leak the broken module to every
16
+ // fs-using test that sorts after this file (e.g. the scaffold tests that call
17
+ // `mkdtempSync`/`statSync`/`writeFileSync`). Two safeguards:
18
+ // 1. The stub spreads the REAL module and overrides only the three functions
19
+ // these tests assert on — so even while active, every other fs API works.
20
+ // 2. `afterAll` re-mocks `node:fs` back to the pristine real module, undoing
21
+ // the override for subsequently-loaded test files.
22
+ // Named exports (namespace) and the default export, captured before mocking.
23
+ const realFsModule: typeof realFs = { ...realFs };
24
+ const realFsDefault = fs;
25
+
12
26
  const mockExistsSync = mock(() => true);
13
27
  const mockReadFileSync = mock(() => "{}");
14
28
  const mockReaddirSync = mock(() => []);
15
29
 
16
- mock.module("node:fs", () => {
30
+ function mockFsModule() {
17
31
  const exports = {
32
+ ...realFsModule,
18
33
  existsSync: mockExistsSync,
19
34
  readFileSync: mockReadFileSync,
20
35
  readdirSync: mockReaddirSync,
21
36
  };
22
37
  return {
23
38
  ...exports,
24
- default: exports,
39
+ default: { ...realFsDefault, ...exports },
25
40
  };
41
+ }
42
+
43
+ mock.module("node:fs", mockFsModule);
44
+
45
+ afterAll(() => {
46
+ // Restore the pristine fs module so later test files don't inherit the stub.
47
+ mock.module("node:fs", () => ({
48
+ ...realFsModule,
49
+ default: realFsDefault,
50
+ }));
26
51
  });
27
52
 
28
53
  describe("extractPluginMetadata", () => {