bambu-printer-mcp 1.1.79 → 1.1.80

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.
@@ -9,9 +9,9 @@ const generations = new Map();
9
9
  export function cancelPendingPrinterOperations(_host, serial) {
10
10
  generations.set(serial, (generations.get(serial) ?? 0) + 1);
11
11
  }
12
- const retained = new Set();
12
+ const ownedSnapshots = new Set();
13
13
  process.once("exit", () => {
14
- for (const directory of retained) {
14
+ for (const directory of ownedSnapshots) {
15
15
  try {
16
16
  rmSync(directory, { recursive: true, force: true });
17
17
  }
@@ -42,6 +42,8 @@ export async function withPrinterOperation(_host, serial, operation) {
42
42
  */
43
43
  export async function withPrintSnapshot(source, operation, root = os.tmpdir()) {
44
44
  const directory = await fs.mkdtemp(path.join(root, "bambu-print-"));
45
+ // Register before any operation can exit without unwinding its finally.
46
+ ownedSnapshots.add(directory);
45
47
  const snapshot = path.join(directory, path.basename(source));
46
48
  let retainUntilExit = false;
47
49
  try {
@@ -51,10 +53,10 @@ export async function withPrintSnapshot(source, operation, root = os.tmpdir()) {
51
53
  }
52
54
  finally {
53
55
  // Native bridge APIs may return before their asynchronous upload completes.
54
- if (retainUntilExit)
55
- retained.add(directory);
56
- else
56
+ if (!retainUntilExit) {
57
57
  await fs.rm(directory, { recursive: true, force: true });
58
+ ownedSnapshots.delete(directory);
59
+ }
58
60
  }
59
61
  }
60
62
  export function uniquePrintName(filename) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bambu-printer-mcp",
3
- "version": "1.1.79",
3
+ "version": "1.1.80",
4
4
  "description": "MCP server for Bambu Lab 3D printers with STL manipulation, slicing, and print management",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -13,7 +13,7 @@
13
13
  "start:stdio": "MCP_TRANSPORT=stdio node dist/index.js",
14
14
  "start:http": "MCP_TRANSPORT=streamable-http node dist/index.js",
15
15
  "build": "tsc",
16
- "test": "npm run build && node --test --import ./tests/support/isolate-studio-config.mjs tests/*.test.mjs tests/**/*.test.mjs",
16
+ "test": "npm run build && node scripts/test-with-temp-guard.mjs --import ./tests/support/isolate-studio-config.mjs tests/*.test.mjs tests/**/*.test.mjs",
17
17
  "package:mcpb": "npm run build && node scripts/package-mcpb.mjs",
18
18
  "version": "node scripts/sync-manifest-version.mjs",
19
19
  "postinstall": "node scripts/install-patches.mjs",
@@ -10,9 +10,9 @@ const generations = new Map<string, number>();
10
10
  export function cancelPendingPrinterOperations(_host: string, serial: string): void {
11
11
  generations.set(serial, (generations.get(serial) ?? 0) + 1);
12
12
  }
13
- const retained = new Set<string>();
13
+ const ownedSnapshots = new Set<string>();
14
14
  process.once("exit", () => {
15
- for (const directory of retained) {
15
+ for (const directory of ownedSnapshots) {
16
16
  try { rmSync(directory, { recursive: true, force: true }); } catch { /* OS temp cleanup remains available. */ }
17
17
  }
18
18
  });
@@ -35,6 +35,8 @@ export async function withPrinterOperation<T>(_host: string, serial: string, ope
35
35
  */
36
36
  export async function withPrintSnapshot<T>(source: string, operation: (snapshot: string, retainForDispatchedUpload: () => void) => Promise<T>, root = os.tmpdir()): Promise<T> {
37
37
  const directory = await fs.mkdtemp(path.join(root, "bambu-print-"));
38
+ // Register before any operation can exit without unwinding its finally.
39
+ ownedSnapshots.add(directory);
38
40
  const snapshot = path.join(directory, path.basename(source));
39
41
  let retainUntilExit = false;
40
42
  try {
@@ -43,8 +45,10 @@ export async function withPrintSnapshot<T>(source: string, operation: (snapshot:
43
45
  return await operation(snapshot, () => { retainUntilExit = true; });
44
46
  } finally {
45
47
  // Native bridge APIs may return before their asynchronous upload completes.
46
- if (retainUntilExit) retained.add(directory);
47
- else await fs.rm(directory, { recursive: true, force: true });
48
+ if (!retainUntilExit) {
49
+ await fs.rm(directory, { recursive: true, force: true });
50
+ ownedSnapshots.delete(directory);
51
+ }
48
52
  }
49
53
  }
50
54