pinokiod 8.3.1 → 8.3.3

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,390 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>GitHub Login</title>
7
+ <link href="/css/fontawesome.min.css" rel="stylesheet">
8
+ <link href="/css/solid.min.css" rel="stylesheet">
9
+ <link href="/css/regular.min.css" rel="stylesheet">
10
+ <link href="/css/brands.min.css" rel="stylesheet">
11
+ <link href="/noty.css" rel="stylesheet">
12
+ <link href="/style.css" rel="stylesheet">
13
+ <link href="/task-launcher.css" rel="stylesheet">
14
+ <% if (agent === "electron") { %>
15
+ <link href="/electron.css" rel="stylesheet"/>
16
+ <% } %>
17
+ <style>
18
+ .gh-login-shell {
19
+ max-width: 980px;
20
+ }
21
+ .gh-state-panel {
22
+ display: flex;
23
+ align-items: flex-start;
24
+ gap: 14px;
25
+ }
26
+ .gh-state-icon {
27
+ width: 36px;
28
+ height: 36px;
29
+ border-radius: 8px;
30
+ display: inline-flex;
31
+ align-items: center;
32
+ justify-content: center;
33
+ flex: 0 0 auto;
34
+ background: var(--task-chip-bg, var(--task-soft));
35
+ border: 1px solid var(--task-border);
36
+ color: var(--task-text);
37
+ }
38
+ .gh-state-copy {
39
+ min-width: 0;
40
+ }
41
+ .gh-state-title {
42
+ margin: 0;
43
+ color: var(--task-text);
44
+ font-size: 18px;
45
+ font-weight: 800;
46
+ line-height: 1.25;
47
+ letter-spacing: 0;
48
+ }
49
+ .gh-state-detail {
50
+ margin: 8px 0 0;
51
+ color: var(--task-muted);
52
+ font-size: 14px;
53
+ line-height: 1.55;
54
+ }
55
+ .gh-action-row {
56
+ display: flex;
57
+ flex-wrap: wrap;
58
+ gap: 10px;
59
+ margin-top: 20px;
60
+ }
61
+ .gh-code-panel {
62
+ display: grid;
63
+ gap: 10px;
64
+ max-width: 520px;
65
+ margin-top: 18px;
66
+ padding: 14px;
67
+ border: 1px solid var(--task-border);
68
+ border-radius: 8px;
69
+ background: var(--task-panel);
70
+ }
71
+ .gh-code-panel.hidden {
72
+ display: none;
73
+ }
74
+ .gh-code-label {
75
+ margin: 0;
76
+ color: var(--task-muted);
77
+ font-size: 13px;
78
+ line-height: 1.45;
79
+ }
80
+ .gh-code-row {
81
+ display: flex;
82
+ flex-wrap: wrap;
83
+ align-items: center;
84
+ gap: 10px;
85
+ }
86
+ .gh-code-value {
87
+ display: inline-flex;
88
+ align-items: center;
89
+ padding: 9px 11px;
90
+ border: 1px solid var(--task-border);
91
+ border-radius: 6px;
92
+ color: var(--task-text);
93
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
94
+ font-size: 15px;
95
+ font-weight: 800;
96
+ letter-spacing: 0.08em;
97
+ }
98
+ .gh-code-link {
99
+ margin: 0;
100
+ color: var(--task-muted);
101
+ font-size: 12px;
102
+ line-height: 1.45;
103
+ overflow-wrap: anywhere;
104
+ }
105
+ .gh-error {
106
+ margin-top: 16px;
107
+ }
108
+ </style>
109
+ </head>
110
+ <%
111
+ const selected = "connect";
112
+ %>
113
+ <body class="<%= theme %> main-sidebar-page task-launcher-page task-page setup-page" data-agent="<%= agent %>" data-page="github-login">
114
+ <%- include('partials/app_navheader', { agent }) %>
115
+ <main>
116
+ <div class="task-container">
117
+ <section class="task-shell gh-login-shell">
118
+ <header class="task-shell-header">
119
+ <div class="task-shell-header-main">
120
+ <div class="task-shell-topline">
121
+ <p class="task-eyebrow">Login / GitHub</p>
122
+ </div>
123
+ <h1 class="task-title">Authorize GitHub</h1>
124
+ <p class="task-description">Copy the device code, open GitHub, then approve the login. Pinokio will continue when the token is saved.</p>
125
+ <div class="task-badge-row task-header-badges">
126
+ <span class="task-badge task-badge-accent" id="gh-badge">Starting</span>
127
+ <span class="task-badge task-badge-neutral">Works from any device</span>
128
+ </div>
129
+ </div>
130
+ </header>
131
+
132
+ <div class="task-shell-body">
133
+ <section class="task-section task-section-subtle">
134
+ <div class="gh-state-panel">
135
+ <div class="gh-state-icon" aria-hidden="true">
136
+ <i class="fa-solid fa-circle-notch fa-spin" id="gh-icon"></i>
137
+ </div>
138
+ <div class="gh-state-copy">
139
+ <h2 class="gh-state-title" id="gh-title">Checking GitHub login</h2>
140
+ <p class="gh-state-detail" id="gh-detail">Pinokio is checking whether a GitHub token is already saved.</p>
141
+ <div class="gh-action-row">
142
+ <button class="task-button primary hidden" id="gh-login" type="button">
143
+ <i class="fa-solid fa-key" aria-hidden="true"></i>
144
+ <span>Log In</span>
145
+ </button>
146
+ <a class="task-button hidden" id="gh-done" href="/github">
147
+ <i class="fa-solid fa-check" aria-hidden="true"></i>
148
+ <span>Done</span>
149
+ </a>
150
+ </div>
151
+ <div class="gh-code-panel hidden" id="gh-code">
152
+ <p class="gh-code-label">GitHub is asking for this device code.</p>
153
+ <div class="gh-code-row">
154
+ <div class="gh-code-value" id="gh-code-value"></div>
155
+ <button class="task-button primary" id="gh-open" type="button">
156
+ <i class="fa-solid fa-arrow-up-right-from-square" aria-hidden="true"></i>
157
+ <span>Copy and Open GitHub</span>
158
+ </button>
159
+ </div>
160
+ <p class="gh-code-link">Or enter the code yourself at <a id="gh-code-href" href="https://github.com/login/device" target="_blank" rel="noopener">github.com/login/device</a>.</p>
161
+ </div>
162
+ <div class="task-status error hidden gh-error" id="gh-error"></div>
163
+ </div>
164
+ </div>
165
+ </section>
166
+ </div>
167
+ </section>
168
+ </div>
169
+ <%- include('partials/main_sidebar', { selected }) %>
170
+ </main>
171
+
172
+ <script>
173
+ const START_URL = "/github/login/start"
174
+ const STATUS_URL = "/github/login/status"
175
+ const POLL_INTERVAL = 3000
176
+
177
+ const badgeElement = document.getElementById("gh-badge")
178
+ const iconElement = document.getElementById("gh-icon")
179
+ const titleElement = document.getElementById("gh-title")
180
+ const detailElement = document.getElementById("gh-detail")
181
+ const openButton = document.getElementById("gh-open")
182
+ const loginButton = document.getElementById("gh-login")
183
+ const doneLink = document.getElementById("gh-done")
184
+ const codeElement = document.getElementById("gh-code")
185
+ const codeValueElement = document.getElementById("gh-code-value")
186
+ const codeHrefElement = document.getElementById("gh-code-href")
187
+ const errorElement = document.getElementById("gh-error")
188
+
189
+ let loginUrl = null
190
+ let pollTimer = null
191
+ let polling = false // one status request at a time: each one may run git on the server
192
+
193
+ function setState({ badge, icon, title, detail, done = false }) {
194
+ if (badge) badgeElement.textContent = badge
195
+ if (icon) iconElement.className = icon
196
+ if (title) titleElement.textContent = title
197
+ if (detail) detailElement.textContent = detail
198
+ doneLink.classList.toggle("hidden", !done)
199
+ }
200
+
201
+ function setLoginLabel(label) {
202
+ const labelElement = loginButton.querySelector("span")
203
+ if (labelElement) labelElement.textContent = label
204
+ }
205
+
206
+ function hideCode() {
207
+ codeElement.classList.add("hidden")
208
+ codeValueElement.textContent = ""
209
+ loginUrl = null
210
+ }
211
+
212
+ function showError(message) {
213
+ stopPolling()
214
+ hideCode()
215
+ errorElement.textContent = message
216
+ errorElement.classList.remove("hidden")
217
+ setLoginLabel("Try Again")
218
+ loginButton.classList.remove("hidden")
219
+ setState({
220
+ badge: "Needs attention",
221
+ icon: "fa-solid fa-triangle-exclamation",
222
+ title: "Login needs attention",
223
+ detail: "Pinokio could not complete the GitHub login."
224
+ })
225
+ }
226
+
227
+ function clearError() {
228
+ errorElement.textContent = ""
229
+ errorElement.classList.add("hidden")
230
+ loginButton.classList.add("hidden")
231
+ }
232
+
233
+ function stopPolling() {
234
+ if (pollTimer) {
235
+ clearInterval(pollTimer)
236
+ pollTimer = null
237
+ }
238
+ }
239
+
240
+ // A login is saved. If a GH_TOKEN in the environment wins over it, say so.
241
+ function showConnected(status) {
242
+ stopPolling()
243
+ clearError()
244
+ hideCode()
245
+ const who = status.login ? ` as ${status.login}` : ""
246
+ setState({
247
+ badge: status.source === "pinokio" ? "Connected" : "Overridden",
248
+ icon: status.source === "pinokio" ? "fa-solid fa-circle-check" : "fa-solid fa-triangle-exclamation",
249
+ title: status.source === "pinokio" ? "GitHub connected" : "Pinokio login saved, but not in use",
250
+ detail: status.source === "pinokio"
251
+ ? `Pinokio is signed in${who}. Git and gh in Pinokio shells use this login.`
252
+ : `Pinokio saved the login${who}, but a GH_TOKEN in your environment overrides it for git and gh in Pinokio shells.`,
253
+ done: true
254
+ })
255
+ }
256
+
257
+ function showWaiting(session) {
258
+ loginUrl = session.verification_uri || "https://github.com/login/device"
259
+ codeHrefElement.href = loginUrl
260
+ codeHrefElement.textContent = loginUrl.replace(/^https?:\/\//, "")
261
+ codeValueElement.textContent = session.user_code || ""
262
+ codeElement.classList.remove("hidden")
263
+ setState({
264
+ badge: "Waiting",
265
+ icon: "fa-solid fa-circle-notch fa-spin",
266
+ title: "Authorize GitHub",
267
+ detail: "Use the button to copy the code and open GitHub, then approve the login there. Keep this page open while Pinokio waits."
268
+ })
269
+ }
270
+
271
+ async function postJSON(url, body = {}) {
272
+ const res = await fetch(url, {
273
+ method: "POST",
274
+ headers: { "Content-Type": "application/json" },
275
+ body: JSON.stringify(body)
276
+ })
277
+ return res.json()
278
+ }
279
+
280
+ async function fetchStatus() {
281
+ return fetch(STATUS_URL, { cache: "no-store" }).then((res) => res.json())
282
+ }
283
+
284
+ async function pollLoginStatus() {
285
+ if (polling) return
286
+ polling = true
287
+ let status
288
+ try {
289
+ status = await fetchStatus()
290
+ } catch (_) {
291
+ return
292
+ } finally {
293
+ polling = false
294
+ }
295
+ if (status.saved) {
296
+ showConnected(status)
297
+ return
298
+ }
299
+ const session = status.session
300
+ if (session && session.status === "error") {
301
+ showError(session.error || "GitHub login failed.")
302
+ }
303
+ }
304
+
305
+ function startPolling() {
306
+ stopPolling()
307
+ pollTimer = setInterval(pollLoginStatus, POLL_INTERVAL)
308
+ }
309
+
310
+ async function copyAndOpen() {
311
+ if (!loginUrl) return
312
+ let copied = false
313
+ const value = codeValueElement.textContent.trim()
314
+ if (value) {
315
+ try {
316
+ await navigator.clipboard.writeText(value)
317
+ copied = true
318
+ } catch (_) {}
319
+ }
320
+ // The Electron app opens the system browser; a browser client opens its own tab.
321
+ if (document.body.dataset.agent === "electron") {
322
+ await fetch("/pinokio/open", {
323
+ method: "POST",
324
+ headers: { "Content-Type": "application/json" },
325
+ body: JSON.stringify({ url: loginUrl, surface: "browser" })
326
+ }).catch(() => {})
327
+ } else {
328
+ window.open(loginUrl, "_blank", "noopener")
329
+ }
330
+ openButton.querySelector("span").textContent = copied ? "Copied and Opened" : "Opened"
331
+ setTimeout(() => {
332
+ openButton.querySelector("span").textContent = "Copy and Open GitHub"
333
+ }, 1500)
334
+ }
335
+
336
+ async function startLogin() {
337
+ stopPolling()
338
+ clearError()
339
+ hideCode()
340
+ setState({
341
+ badge: "Preparing",
342
+ icon: "fa-solid fa-circle-notch fa-spin",
343
+ title: "Preparing GitHub",
344
+ detail: "Pinokio is requesting a GitHub device code."
345
+ })
346
+
347
+ let response
348
+ try {
349
+ response = await postJSON(START_URL)
350
+ } catch (error) {
351
+ showError(error.message)
352
+ return
353
+ }
354
+ if (response.error || response.status === "error") {
355
+ showError(response.error || "Unknown GitHub login error.")
356
+ return
357
+ }
358
+ if (!response.login || !response.login.user_code) {
359
+ showError("GitHub did not return a device code.")
360
+ return
361
+ }
362
+ showWaiting(response.login)
363
+ startPolling()
364
+ }
365
+
366
+ openButton.addEventListener("click", copyAndOpen)
367
+ loginButton.addEventListener("click", startLogin)
368
+
369
+ window.addEventListener("load", async () => {
370
+ try {
371
+ const status = await fetchStatus()
372
+ if (status.saved) {
373
+ showConnected(status)
374
+ return
375
+ }
376
+ if (status.session && status.session.status === "pending") {
377
+ clearError()
378
+ showWaiting(status.session)
379
+ startPolling()
380
+ return
381
+ }
382
+ startLogin()
383
+ } catch (error) {
384
+ showError(error.message)
385
+ }
386
+ })
387
+ </script>
388
+ <%- include('partials/app_common_scripts') %>
389
+ </body>
390
+ </html>
@@ -32,6 +32,15 @@ function render(t, status, agent = 'electron') {
32
32
  return { state, document, poll: () => state.timers.shift().callback(), text: (id) => document.getElementById(id).textContent }
33
33
  }
34
34
 
35
+ test('the off card answers a Tailscale newcomer before Turn on', (t) => {
36
+ const h = render(t, { phase: 'off' })
37
+ const card = h.document.querySelector('[data-state=off] .anywhere-card')
38
+ assert.match(card.textContent, /free for personal use.*personal account.*Google, Apple, GitHub or Microsoft.*What is Tailscale\?/s)
39
+ assert.deepEqual([...card.querySelectorAll('a')].map(a => a.getAttribute('href')),
40
+ ['https://tailscale.com/pricing', 'https://tailscale.com/kb/1151/what-is-tailscale'])
41
+ assert.ok(card.querySelector('[data-action=start]'), 'Turn on follows the explanation')
42
+ })
43
+
35
44
  test('before any device joins, the ready state is the connect card alone, with sign out', (t) => {
36
45
  const h = render(t, { phase: 'ready', peers: [] })
37
46
  const card = h.document.querySelector('[data-state=ready] .anywhere-card')
@@ -113,16 +113,16 @@ test('tailscaled checks both package versions, binary versions and missing execu
113
113
  for (const platform of ['darwin', 'win32', 'linux']) {
114
114
  const mod = new context.module.exports()
115
115
  mod.kernel = { platform, bin: { path: (...parts) => path.join('/managed', ...parts),
116
- installed: { conda: new Set(['tailscaled', 'tailscale']), conda_versions: { tailscaled: '1.104.1', tailscale: '1.104.1' } } } }
117
- assert.equal(mod.cmd(), 'tailscaled=1.104.1 tailscale=1.104.1')
116
+ installed: { conda: new Set(['tailscaled', 'tailscale']), conda_versions: { tailscaled: '1.104.5', tailscale: '1.104.5' } } } }
117
+ assert.equal(mod.cmd(), 'tailscaled=1.104.5 tailscale=1.104.5')
118
118
  files.clear()
119
- files.set(mod.binPath(), '1.104.1\n')
119
+ files.set(mod.binPath(), '1.104.5\n')
120
120
  assert.equal(await mod.installed(), false, 'missing CLI fails setup')
121
- files.set(mod.cliPath(), '1.104.1\n')
121
+ files.set(mod.cliPath(), '1.104.5\n')
122
122
  assert.equal(await mod.installed(), true)
123
123
  mod.kernel.bin.installed.conda_versions.tailscale = '1.102.2'
124
124
  assert.equal(await mod.installed(), false, 'mismatched CLI package fails setup')
125
- mod.kernel.bin.installed.conda_versions.tailscale = '1.104.1'
125
+ mod.kernel.bin.installed.conda_versions.tailscale = '1.104.5'
126
126
  mod.verified.clear()
127
127
  files.set(mod.cliPath(), '1.102.2\n')
128
128
  assert.equal(await mod.installed(), false, 'binary version is verified independently')
@@ -0,0 +1,239 @@
1
+ const assert = require('node:assert/strict')
2
+ const fs = require('node:fs/promises')
3
+ const os = require('node:os')
4
+ const path = require('node:path')
5
+ const test = require('node:test')
6
+ const { spawnSync } = require('node:child_process')
7
+
8
+ const Cuda = require('../kernel/bin/cuda')
9
+ const Shell = require('../kernel/shell')
10
+ const Guard = require('../kernel/shell_conda_runtime_guard')
11
+
12
+ async function createCuda(t, platform = 'win32', gpu = 'nvidia') {
13
+ const root = await fs.mkdtemp(path.join(os.tmpdir(), 'pinokio cuda & hooks-'))
14
+ t.after(() => fs.rm(root, { recursive: true, force: true }))
15
+ const cuda = new Cuda()
16
+ cuda.kernel = {
17
+ homedir: root,
18
+ platform,
19
+ gpu,
20
+ path: (...parts) => path.join(root, ...parts),
21
+ bin: {
22
+ path: (...parts) => path.join(root, 'bin', ...parts),
23
+ activationCommands: () => [],
24
+ },
25
+ }
26
+ const folder = cuda.kernel.bin.path('miniforge/etc/conda/activate.d')
27
+ await fs.mkdir(folder, { recursive: true })
28
+ return { cuda, folder }
29
+ }
30
+
31
+ async function exists(file) {
32
+ return fs.access(file).then(() => true, () => false)
33
+ }
34
+
35
+ test('Windows CUDA install avoids activation and stashes new hooks between transactions and on reinstall', async (t) => {
36
+ const { cuda, folder } = await createCuda(t)
37
+ const prefix = cuda.kernel.bin.path('miniforge')
38
+ const executable = '.\\Scripts\\conda.exe'
39
+ const scripts = ['vs2022_compiler_vars.bat', '~cuda-nvcc_activate.bat']
40
+ const calls = []
41
+ const ondata = () => {}
42
+ const shell = new Shell(cuda.kernel)
43
+ shell.platform = 'win32'
44
+ shell.shell = 'cmd.exe'
45
+ shell.env = {}
46
+ shell.condaRuntimeGuard = true
47
+
48
+ cuda.kernel.bin.exec = async (params, callback) => {
49
+ const step = calls.length % 2
50
+ calls.push(structuredClone(params))
51
+ assert.equal(callback, ondata)
52
+ assert.equal(params.path, prefix)
53
+ assert.deepEqual(params.conda, { skip: true })
54
+ assert.deepEqual(params.message[0], { _: [executable, 'clean', '-y', '--all'] })
55
+ assert.deepEqual(params.message[1]._.slice(0, 5), [executable, 'install', '-y', '--prefix', '.'])
56
+ assert.deepEqual(params.message[1]._.slice(5), step === 0
57
+ ? ['cudnn', 'libzlib-wapi', '-c', 'conda-forge']
58
+ : ['nvidia/label/cuda-12.8.1::cuda', 'conda-forge::cuda-cccl'])
59
+
60
+ // Exercise the real shell activation and command rendering used by bin.exec.
61
+ const activated = await shell.activate(structuredClone(params))
62
+ assert.deepEqual(activated.message, params.message)
63
+ const command = shell.build(activated)
64
+ assert.doesNotMatch(command, /conda_hook|conda (?:activate|deactivate)|compiler_vars|vcvars/i)
65
+ assert.ok(command.includes(`"${executable}"`))
66
+ assert.ok(command.includes('"--prefix" "."'))
67
+ assert.equal(command.includes(prefix), false)
68
+
69
+ for (const script of scripts) assert.equal(await exists(path.join(folder, script)), false)
70
+ if (step === 1) assert.equal(await exists(path.join(folder, 'pinokio', scripts[0])), true)
71
+ await fs.writeFile(path.join(folder, scripts[step]), `@rem transaction ${calls.length}\r\n`)
72
+ return {}
73
+ }
74
+
75
+ for (let attempt = 0; attempt < 2; attempt++) {
76
+ await cuda.install({}, ondata)
77
+ for (const script of scripts) {
78
+ assert.equal(await exists(path.join(folder, script)), false)
79
+ assert.equal(await exists(path.join(folder, 'pinokio', script)), true)
80
+ }
81
+ }
82
+ assert.equal(calls.length, 4)
83
+ assert.match(await fs.readFile(path.join(folder, 'pinokio', scripts[0]), 'utf8'), /transaction 3/)
84
+ assert.match(await fs.readFile(path.join(folder, 'pinokio', scripts[1]), 'utf8'), /transaction 4/)
85
+ })
86
+
87
+ test('failed CUDA transactions still stash hooks and do not continue installing', async (t) => {
88
+ for (const failedStep of [1, 2]) {
89
+ for (const failure of ['result', 'exception']) {
90
+ await t.test(`${failure} at transaction ${failedStep}`, async (t) => {
91
+ const { cuda, folder } = await createCuda(t)
92
+ let calls = 0
93
+ cuda.kernel.bin.exec = async () => {
94
+ calls++
95
+ await fs.writeFile(path.join(folder, 'vs2022_compiler_vars.bat'), '@rem compiler\r\n')
96
+ if (calls === failedStep) {
97
+ if (failure === 'exception') throw new Error('transaction rejected')
98
+ return { error: ['ERROR: package installation failed'] }
99
+ }
100
+ return {}
101
+ }
102
+ await assert.rejects(cuda.install({}, () => {}), failure === 'exception'
103
+ ? /transaction rejected/ : /CUDA dependency installation failed/)
104
+ assert.equal(calls, failedStep)
105
+ assert.equal(await exists(path.join(folder, 'vs2022_compiler_vars.bat')), false)
106
+ assert.equal(await exists(path.join(folder, 'pinokio/vs2022_compiler_vars.bat')), true)
107
+ })
108
+ }
109
+ }
110
+ })
111
+
112
+ test('CUDA installation stops if a compiler hook cannot be stashed', async (t) => {
113
+ const { cuda, folder } = await createCuda(t)
114
+ const script = path.join(folder, 'vs2022_compiler_vars.bat')
115
+ const rename = fs.rename.bind(fs)
116
+ t.mock.method(fs, 'rename', async (source, destination) => {
117
+ if (source === script) throw Object.assign(new Error('compiler hook is locked'), { code: 'EACCES' })
118
+ return rename(source, destination)
119
+ })
120
+ let calls = 0
121
+ cuda.kernel.bin.exec = async () => {
122
+ calls++
123
+ await fs.writeFile(script, '@rem compiler\r\n')
124
+ return {}
125
+ }
126
+ await assert.rejects(cuda.install({}, () => {}), /compiler hook is locked/)
127
+ assert.equal(calls, 1)
128
+ assert.equal(await exists(script), true)
129
+ })
130
+
131
+ test('CUDA install reports stash directory failures and leaves compiler hooks intact', async (t) => {
132
+ const { cuda, folder } = await createCuda(t)
133
+ const mkdir = fs.mkdir.bind(fs)
134
+ t.mock.method(fs, 'mkdir', async (target, options) => {
135
+ if (target === path.join(folder, 'pinokio')) {
136
+ throw Object.assign(new Error('stash directory is inaccessible'), { code: 'EACCES' })
137
+ }
138
+ return mkdir(target, options)
139
+ })
140
+ let calls = 0
141
+ cuda.kernel.bin.exec = async () => {
142
+ calls++
143
+ await fs.writeFile(path.join(folder, 'vs2022_compiler_vars.bat'), '@rem compiler\r\n')
144
+ return {}
145
+ }
146
+ await assert.rejects(cuda.install({}, () => {}), /stash directory is inaccessible/)
147
+ assert.equal(calls, 1)
148
+ assert.equal(await exists(path.join(folder, 'vs2022_compiler_vars.bat')), true)
149
+ })
150
+
151
+ test('Windows CUDA install migrates legacy disabled hooks and keeps the CUDA activation patch', async (t) => {
152
+ const { cuda, folder } = await createCuda(t)
153
+ await fs.writeFile(path.join(folder, 'vs2019_compiler_vars.bat.disabled'), '@rem legacy compiler\r\n')
154
+ const cudaScript = '~cuda-nvcc_activate.bat'
155
+ await fs.writeFile(path.join(folder, cudaScript), [
156
+ '@set CUDA_PATH=preserved',
157
+ 'if not defined CUDAARCHS (',
158
+ ' set CUDAARCHS=old-default',
159
+ ')',
160
+ '@set TORCH_CUDA_ARCH_LIST=old-default',
161
+ '',
162
+ ].join('\r\n'))
163
+ cuda.kernel.bin.exec = async () => ({})
164
+ await cuda.install({}, () => {})
165
+ assert.equal(await exists(path.join(folder, 'vs2019_compiler_vars.bat.disabled')), false)
166
+ assert.equal(await exists(path.join(folder, 'pinokio/vs2019_compiler_vars.bat')), true)
167
+ assert.equal(await fs.readFile(path.join(folder, 'pinokio', cudaScript), 'utf8'), '@set CUDA_PATH=preserved\r\n')
168
+ })
169
+
170
+ test('explicit CUDA target retains managed Conda runtime protections', () => {
171
+ const prefix = 'C:\\pinokio\\bin\\miniforge'
172
+ const executable = `${prefix}\\Scripts\\conda.exe`
173
+ const context = { platform: 'win32', shellName: 'cmd.exe', managedBasePrefix: prefix, cwd: 'C:\\pinokio\\bin' }
174
+ for (const [pkg, skipped] of [['cudnn', 0], ['python=3.12', 1], ['conda=25.5.1', 1]]) {
175
+ for (const [binary, target, cwd] of [[executable, prefix, context.cwd], ['.\\Scripts\\conda.exe', '.', prefix]]) {
176
+ const params = { conda: { skip: true }, message: { _: [binary, 'install', '-y', '--prefix', target, pkg] } }
177
+ assert.equal(Guard.applyCondaRuntimeGuard(params, { ...context, cwd }).skipped.length, skipped)
178
+ }
179
+ }
180
+ })
181
+
182
+ test('CUDA commands execute from a Windows home containing spaces and ampersands', {
183
+ skip: process.platform !== 'win32' && 'requires Windows cmd.exe',
184
+ }, async (t) => {
185
+ const { cuda, folder } = await createCuda(t)
186
+ const prefix = cuda.kernel.bin.path('miniforge')
187
+ await fs.mkdir(path.join(prefix, 'Scripts'), { recursive: true })
188
+ // Use a real executable that records argv instead of downloading CUDA.
189
+ await fs.copyFile(process.execPath, path.join(prefix, 'Scripts/conda.exe'))
190
+ const recorder = `require('node:fs').appendFileSync('commands.jsonl', JSON.stringify(process.argv.slice(1)) + '\\n')`
191
+ for (const command of ['clean', 'install']) await fs.writeFile(path.join(prefix, command), recorder)
192
+ const shell = new Shell(cuda.kernel)
193
+ shell.platform = 'win32'
194
+ shell.shell = 'cmd.exe'
195
+ shell.env = {}
196
+ cuda.kernel.bin.exec = async params => {
197
+ const activated = await shell.activate(structuredClone(params))
198
+ const command = shell.build(activated)
199
+ const result = spawnSync('cmd.exe', ['/D', '/Q'], {
200
+ cwd: params.path,
201
+ input: `${command}\r\nexit\r\n`,
202
+ encoding: 'utf8',
203
+ timeout: 15000,
204
+ windowsHide: true,
205
+ })
206
+ assert.ifError(result.error)
207
+ assert.equal(result.status, 0, result.stdout + result.stderr)
208
+ await fs.writeFile(path.join(folder, 'vs2022_compiler_vars.bat'), '@exit /b 1\r\n')
209
+ return {}
210
+ }
211
+ await cuda.install({}, () => {})
212
+ const commands = (await fs.readFile(path.join(prefix, 'commands.jsonl'), 'utf8')).trim().split('\n').map(JSON.parse)
213
+ assert.equal(commands.length, 4)
214
+ for (const index of [1, 3]) {
215
+ assert.equal(path.basename(commands[index][0]), 'install')
216
+ assert.deepEqual(commands[index].slice(1, 4), ['-y', '--prefix', '.'])
217
+ }
218
+ assert.equal(await exists(path.join(folder, 'vs2022_compiler_vars.bat')), false)
219
+ })
220
+
221
+ test('CUDA installation preserves other platforms and skips non-NVIDIA GPUs', async (t) => {
222
+ for (const platform of ['darwin', 'linux']) {
223
+ const { cuda } = await createCuda(t, platform)
224
+ const calls = []
225
+ cuda.kernel.bin.exec = async (params) => { calls.push(params) }
226
+ await cuda.install({}, () => {})
227
+ const expected = [
228
+ { message: ['conda clean -y --all', 'conda install -y cudnn -c conda-forge'] },
229
+ { message: ['conda clean -y --all', 'conda install -y nvidia/label/cuda-12.8.1::cuda'] },
230
+ ]
231
+ if (platform === 'linux') expected.push({ message: ['conda install -y -c conda-forge nccl'] })
232
+ assert.deepEqual(calls, expected)
233
+ }
234
+ for (const platform of ['win32', 'darwin', 'linux']) {
235
+ const { cuda } = await createCuda(t, platform, 'amd')
236
+ cuda.kernel.bin.exec = async () => { assert.fail('non-NVIDIA CUDA install must be skipped') }
237
+ await cuda.install({}, () => {})
238
+ }
239
+ })