pinokiod 8.3.2 → 8.3.4

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,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
+ })
@@ -4,7 +4,7 @@ const test = require('node:test')
4
4
 
5
5
  const GitBin = require('../kernel/bin/git')
6
6
 
7
- function createGitBin(platform, packages) {
7
+ function createGitBin(platform, packages, executed = []) {
8
8
  const git = new GitBin()
9
9
  git.kernel = {
10
10
  platform,
@@ -15,45 +15,60 @@ function createGitBin(platform, packages) {
15
15
  conda: new Set(packages),
16
16
  conda_versions: { git: '2.51.0' },
17
17
  },
18
+ exec: async (req) => {
19
+ executed.push(req.message)
20
+ },
18
21
  },
19
22
  }
20
23
  return git
21
24
  }
22
25
 
23
- test('Git bin installs Git Credential Manager with the Git bundle', () => {
26
+ test('Git bin installs Git, Git LFS and GitHub CLI without Git Credential Manager', () => {
24
27
  assert.equal(
25
28
  createGitBin('darwin', []).cmd(),
26
- '"git>=2.51.0" git-lfs git-credential-manager=2.7.3 gh=2.82.1'
29
+ '"git>=2.51.0" git-lfs gh=2.82.1'
27
30
  )
28
31
  assert.equal(
29
32
  createGitBin('linux', []).cmd(),
30
- '"git>=2.51.0" git-lfs git-credential-manager=2.7.3 gh=2.82.1'
33
+ '"git>=2.51.0" git-lfs gh=2.82.1'
31
34
  )
32
35
  assert.equal(
33
36
  createGitBin('win32', []).cmd(),
34
- '"git>=2.51.0" git-lfs git-credential-manager=2.7.3 gh=2.82.1 m2-base'
37
+ '"git>=2.51.0" git-lfs gh=2.82.1 m2-base'
35
38
  )
36
39
  })
37
40
 
38
- test('Git bin readiness requires Git Credential Manager and GitHub CLI', async () => {
41
+ test('Git bin readiness requires Git and GitHub CLI', async () => {
39
42
  assert.equal(
40
43
  await createGitBin('darwin', ['git', 'git-lfs']).installed(),
41
44
  false
42
45
  )
43
46
  assert.equal(
44
- await createGitBin('darwin', ['git', 'git-lfs', 'git-credential-manager']).installed(),
45
- false
46
- )
47
- assert.equal(
48
- await createGitBin('darwin', ['git', 'git-lfs', 'git-credential-manager', 'gh']).installed(),
47
+ await createGitBin('darwin', ['git', 'git-lfs', 'gh']).installed(),
49
48
  true
50
49
  )
51
50
  assert.equal(
52
- await createGitBin('win32', ['git', 'git-lfs', 'git-credential-manager', 'gh']).installed(),
51
+ await createGitBin('win32', ['git', 'git-lfs', 'gh']).installed(),
53
52
  false
54
53
  )
55
54
  assert.equal(
56
- await createGitBin('win32', ['git', 'git-lfs', 'git-credential-manager', 'gh', 'm2-base']).installed(),
55
+ await createGitBin('win32', ['git', 'git-lfs', 'gh', 'm2-base']).installed(),
57
56
  true
58
57
  )
59
58
  })
59
+
60
+ test('Git bin treats a leftover Git Credential Manager as not installed so it gets removed', async () => {
61
+ assert.equal(
62
+ await createGitBin('darwin', ['git', 'git-lfs', 'gh', 'git-credential-manager']).installed(),
63
+ false
64
+ )
65
+
66
+ const executed = []
67
+ await createGitBin('darwin', ['git', 'git-lfs', 'gh', 'git-credential-manager'], executed).install({}, () => {})
68
+ assert.equal(executed[0], 'conda remove -y git-credential-manager')
69
+ assert.match(executed[executed.length - 1].join('\n'), /conda install -y -c conda-forge "git>=2\.51\.0" git-lfs gh=2\.82\.1/)
70
+
71
+ const fresh = []
72
+ await createGitBin('darwin', [], fresh).install({}, () => {})
73
+ assert.equal(fresh.some((message) => /git-credential-manager/.test(String(message))), false)
74
+ })
@@ -22,6 +22,7 @@ async function withTempHome(fn) {
22
22
  function createKernel(homedir) {
23
23
  return {
24
24
  homedir,
25
+ platform: process.platform,
25
26
  path: (...parts) => path.resolve(homedir, ...parts),
26
27
  }
27
28
  }
@@ -30,43 +31,60 @@ function githubCredentialSection(config) {
30
31
  return config['credential "https://github'] && config['credential "https://github']['com"']
31
32
  }
32
33
 
33
- test('Git defaults configure Git Credential Manager for new Pinokio gitconfig files', async () => {
34
+ test('Git defaults point new Pinokio gitconfig files at the GitHub CLI credential helper', async () => {
34
35
  await withTempHome(async (homedir) => {
35
- const git = new KernelGit(createKernel(homedir))
36
+ const kernel = createKernel(homedir)
37
+ const git = new KernelGit(kernel)
36
38
 
37
39
  await git.ensureDefaults()
38
40
 
39
- const config = ini.parse(await fs.readFile(path.join(homedir, 'gitconfig'), 'utf8'))
40
- assert.equal(config.credential.helper, 'manager')
41
- assert.equal(config.credential.gitHubAuthModes, 'oauth')
42
- assert.equal(config.credential.namespace, 'pinokio')
43
- assert.equal(githubCredentialSection(config).helper, 'manager')
44
- assert.equal(githubCredentialSection(config).provider, 'github')
41
+ const content = await fs.readFile(path.join(homedir, 'gitconfig'), 'utf8')
42
+ assert.doesNotMatch(content, /manager/)
43
+ const config = ini.parse(content)
44
+ assert.equal(config.credential, undefined)
45
+ assert.equal(githubCredentialSection(config).helper, '!gh auth git-credential')
46
+ assert.equal(githubCredentialSection(config).provider, undefined)
47
+ const { stdout } = await execFileAsync('git', ['config', '--file', path.join(homedir, 'gitconfig'), '--get', 'credential.https://github.com.helper'])
48
+ assert.equal(stdout.trim(), '!gh auth git-credential')
45
49
  })
46
50
  })
47
51
 
48
- test('Git defaults migrate the legacy gh GitHub helper to Git Credential Manager', async () => {
52
+ test('Git defaults migrate Git Credential Manager settings to the GitHub CLI helper', async () => {
49
53
  await withTempHome(async (homedir) => {
50
54
  await fs.writeFile(path.join(homedir, 'gitconfig'), [
55
+ '[credential]',
56
+ ' helper = manager',
57
+ ' gitHubAuthModes = oauth',
58
+ ' namespace = pinokio',
51
59
  '[credential "https://github.com"]',
52
- ' helper = !gh auth git-credential',
60
+ ' helper = manager',
61
+ ' provider = github',
53
62
  '[user]',
54
63
  ' name = custom',
55
64
  ' email = custom@example.test',
56
65
  '',
57
66
  ].join('\n'))
58
- const git = new KernelGit(createKernel(homedir))
67
+ const kernel = createKernel(homedir)
68
+ const git = new KernelGit(kernel)
59
69
 
60
70
  await git.ensureDefaults()
61
71
 
62
- const config = ini.parse(await fs.readFile(path.join(homedir, 'gitconfig'), 'utf8'))
63
- assert.equal(config.credential.helper, 'manager')
64
- assert.equal(config.credential.gitHubAuthModes, 'oauth')
65
- assert.equal(config.credential.namespace, 'pinokio')
66
- assert.equal(githubCredentialSection(config).helper, 'manager')
67
- assert.equal(githubCredentialSection(config).provider, 'github')
72
+ const content = await fs.readFile(path.join(homedir, 'gitconfig'), 'utf8')
73
+ assert.doesNotMatch(content, /manager/)
74
+ assert.doesNotMatch(content, /gitHubAuthModes/)
75
+ const config = ini.parse(content)
76
+ assert.equal(config.credential, undefined)
77
+ assert.equal(githubCredentialSection(config).helper, '!gh auth git-credential')
78
+ assert.equal(githubCredentialSection(config).provider, undefined)
68
79
  assert.equal(config.user.name, 'custom')
69
80
  assert.equal(config.user.email, 'custom@example.test')
81
+
82
+ // running again leaves the file untouched
83
+ const before = await fs.stat(path.join(homedir, 'gitconfig'))
84
+ await new Promise((resolve) => setTimeout(resolve, 20))
85
+ await git.ensureDefaults()
86
+ const after = await fs.stat(path.join(homedir, 'gitconfig'))
87
+ assert.equal(after.mtimeMs, before.mtimeMs)
70
88
  })
71
89
  })
72
90
 
@@ -100,17 +118,18 @@ test('Git defaults reset credential sections to built-in defaults before Git rea
100
118
  ' email = custom@example.test',
101
119
  '',
102
120
  ].join('\n'))
103
- const git = new KernelGit(createKernel(caseHome))
121
+ const kernel = createKernel(caseHome)
122
+ const git = new KernelGit(kernel)
104
123
 
105
124
  await git.ensureDefaults()
106
125
 
107
126
  const content = await fs.readFile(gitconfigPath, 'utf8')
108
- assert.doesNotMatch(content, /git-credential/i)
127
+ assert.doesNotMatch(content, /custom-helper|gh\.exe|Any Folder/)
109
128
  const { stdout } = await execFileAsync('git', ['config', '--file', gitconfigPath, '--list'])
110
- assert.match(stdout, /credential\.helper=manager/)
111
- assert.match(stdout, /credential\.githubauthmodes=oauth/)
112
- assert.match(stdout, /credential\.namespace=pinokio/)
113
- assert.match(stdout, /credential\.https:\/\/github\.com\.helper=manager/)
129
+ assert.match(stdout, /credential\.https:\/\/github\.com\.helper=!gh auth git-credential$/m)
130
+ assert.doesNotMatch(stdout, /^credential\.helper=/m)
131
+ assert.doesNotMatch(stdout, /credential\.githubauthmodes/)
132
+ assert.doesNotMatch(stdout, /credential\.namespace/)
114
133
  assert.doesNotMatch(stdout, /credential\.https:\/\/gist\.github\.com/)
115
134
  assert.doesNotMatch(stdout, /credential\.https:\/\/enterprise\.example/)
116
135
  const config = ini.parse(content)
@@ -120,7 +139,7 @@ test('Git defaults reset credential sections to built-in defaults before Git rea
120
139
  })
121
140
  })
122
141
 
123
- test('Git isomorphic auth callback returns GCM credentials for GitHub URLs', async () => {
142
+ test('Git isomorphic auth callback returns stored credentials for GitHub URLs', async () => {
124
143
  const git = new KernelGit(createKernel('/tmp/pinokio'))
125
144
  let requestedUrl = ''
126
145
  git.getCredentialForUrl = async (url) => {
@@ -140,7 +159,7 @@ test('Git isomorphic auth callback returns GCM credentials for GitHub URLs', asy
140
159
  })
141
160
  })
142
161
 
143
- test('Git isomorphic auth callback stays anonymous when GCM has no credential', async () => {
162
+ test('Git isomorphic auth callback stays anonymous when no credential is stored', async () => {
144
163
  const git = new KernelGit(createKernel('/tmp/pinokio'))
145
164
  git.getCredentialForUrl = async () => null
146
165