dsh-ensp 0.2.0 → 0.2.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/core/doctor.mjs +33 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ensp",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Automate Huawei eNSP labs: generate .topo files, start and stop devices, and push configuration one command at a time with per-command error reporting.",
5
5
  "keywords": [
6
6
  "dsh",
@@ -109,20 +109,32 @@ export function probeInputInjection({ timeoutMs = 30000 } = {}) {
109
109
  }
110
110
  }
111
111
 
112
- /** Free physical memory in MB, or null when it cannot be read. */
112
+ /**
113
+ * Free physical memory in MB, or null when it cannot be read.
114
+ *
115
+ * On Windows Win32_OperatingSystem is the accurate number, but it needs
116
+ * PowerShell. Everything else (and any Windows box where PowerShell is not on
117
+ * PATH) falls back to os.freemem(), so the check still says something useful
118
+ * instead of giving up on the platform it happens to run on.
119
+ */
113
120
  export function freeMemoryMb() {
114
- const r = spawnSync(
115
- 'powershell',
116
- [
117
- '-NoProfile',
118
- '-Command',
119
- "Get-CimInstance Win32_OperatingSystem | ForEach-Object { [int]($_.FreePhysicalMemory / 1024) }",
120
- ],
121
- { encoding: 'utf8', windowsHide: true, timeout: 20000 },
122
- )
123
- if (r.status !== 0) return null
124
- const n = Number((r.stdout || '').trim())
125
- return Number.isFinite(n) && n > 0 ? n : null
121
+ if (process.platform === 'win32') {
122
+ const r = spawnSync(
123
+ 'powershell',
124
+ [
125
+ '-NoProfile',
126
+ '-Command',
127
+ "Get-CimInstance Win32_OperatingSystem | ForEach-Object { [int]($_.FreePhysicalMemory / 1024) }",
128
+ ],
129
+ { encoding: 'utf8', windowsHide: true, timeout: 20000 },
130
+ )
131
+ if (r.status === 0) {
132
+ const n = Number((r.stdout || '').trim())
133
+ if (Number.isFinite(n) && n > 0) return n
134
+ }
135
+ }
136
+ const fallback = Math.floor(os.freemem() / (1024 * 1024))
137
+ return Number.isFinite(fallback) && fallback > 0 ? fallback : null
126
138
  }
127
139
 
128
140
  /** Ports in eNSP's console range that are already listening. */
@@ -244,7 +256,14 @@ export function doctor(options = {}) {
244
256
  // 6. Memory headroom: each AR_Base needs 256 MB, WLAN images 530-650 MB
245
257
  const free = freeMemoryMb()
246
258
  if (free === null) {
247
- checks.push(check('memory', 'warn', 'could not read free physical memory'))
259
+ checks.push(
260
+ check(
261
+ 'memory',
262
+ 'warn',
263
+ 'could not read free physical memory',
264
+ 'Check free memory yourself (Task Manager on Windows) and keep at least 1 GB spare; a device needs ~256 MB to boot.',
265
+ ),
266
+ )
248
267
  } else {
249
268
  const okMem = free >= MIN_FREE_MEMORY_MB
250
269
  checks.push(