pinokiod 8.3.3 → 8.3.6

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.
@@ -42,6 +42,8 @@ const MOBILE_OS = new Set(['ios', 'ipados', 'android'])
42
42
 
43
43
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
44
44
 
45
+ const unowned = () => Object.assign(new Error('Cannot verify ownership of tailscaled; its process and PID record were preserved.'), { code: 'ERR_ANYWHERE_UNOWNED' })
46
+
45
47
  class Anywhere {
46
48
  constructor(kernel) {
47
49
  this.kernel = kernel
@@ -344,7 +346,10 @@ class Anywhere {
344
346
  catch (e) { if (e.code === 'ENOENT') return null; throw e }
345
347
  if (!Number.isInteger(pid) || pid <= 0) return null
346
348
  try { process.kill(pid, 0) }
347
- catch (e) { if (e.code === 'ESRCH') return null; throw e }
349
+ catch (e) {
350
+ if (e.code === 'ESRCH') return null
351
+ if (e.code !== 'EPERM') throw e
352
+ }
348
353
  return { pid, file: this.platform === 'win32' ? 'powershell.exe' : '/bin/ps',
349
354
  args: this.platform === 'win32' ? ['-NoProfile', '-NonInteractive', '-Command',
350
355
  `[Console]::OutputEncoding=[Text.Encoding]::UTF8; (Get-CimInstance Win32_Process -Filter 'ProcessId=${pid}').CommandLine`]
@@ -353,6 +358,12 @@ class Anywhere {
353
358
  }
354
359
  ownedPid(inspection, command) {
355
360
  command = command.trim()
361
+ if (!command) {
362
+ // No identity (Windows gives none for an elevated process): unknown, not unrelated.
363
+ try { process.kill(inspection.pid, 0) }
364
+ catch (e) { if (e.code === 'ESRCH') return null }
365
+ throw unowned()
366
+ }
356
367
  let expected = [this.binPath(), ...this.daemonArgs()].join(' ')
357
368
  if (this.platform === 'win32') {
358
369
  command = command.replace(/"/g, '').toLowerCase()
@@ -388,7 +399,7 @@ class Anywhere {
388
399
  if (this.featureQuery) await this.featureQuery.catch(() => {})
389
400
  const pid = this.child && this.child.exitCode === null ? this.child.pid : await this.readPid()
390
401
  if (pid) process.kill(pid, 'SIGTERM')
391
- else if (await this.daemonAlive()) throw Object.assign(new Error('Cannot verify ownership of tailscaled; its process and PID record were preserved.'), { code: 'ERR_ANYWHERE_UNOWNED' })
402
+ else if (await this.daemonAlive()) throw unowned()
392
403
  const deadline = Date.now() + 5000
393
404
  while ((this.child && this.child.exitCode === null) || (pid && await this.readPid()) || await this.daemonAlive()) {
394
405
  if (Date.now() >= deadline) throw new Error('tailscaled did not stop; its state and PID record were preserved.')
package/kernel/git.js CHANGED
@@ -1211,6 +1211,13 @@ class Git {
1211
1211
 
1212
1212
  resetCredentialDefaults()
1213
1213
 
1214
+ // Git applies helpers in file order: the general reset must come before the GitHub helper.
1215
+ if (config.credential && Object.keys(config).find(isCredentialSection) !== "credential") {
1216
+ const { credential, ...rest } = config
1217
+ config = { credential, ...rest }
1218
+ dirty = true
1219
+ }
1220
+
1214
1221
  if (dirty) {
1215
1222
  await fs.promises.writeFile(gitconfigPath, ini.stringify(config))
1216
1223
  }
@@ -9,6 +9,8 @@
9
9
  smudge = git-lfs smudge -- %f
10
10
  process = git-lfs filter-process
11
11
  required = true
12
+ [credential]
13
+ helper =
12
14
  [credential "https://github.com"]
13
15
  helper = !gh auth git-credential
14
16
  [user]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "8.3.3",
3
+ "version": "8.3.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1723,3 +1723,29 @@ test('a replaced CLI client has its own pending status query and ignores the for
1723
1723
  assert.equal(anywhere.lastStatus.BackendState, 'Running')
1724
1724
  assert.equal(anywhere.statusQuery, null)
1725
1725
  })
1726
+
1727
+ test('a PID whose identity cannot be read is unknown, not unrelated', { skip: process.platform === 'win32' && 'uses /usr/bin/true' }, async () => {
1728
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'pk-anywhere-'))
1729
+ const idle = spawnIdle()
1730
+ try {
1731
+ const anywhere = new Anywhere(fakeKernel(tmp))
1732
+ await anywhere.saveConfig({ enabled: true })
1733
+ fs.mkdirSync(anywhere.stateDir(), { recursive: true })
1734
+ fs.writeFileSync(anywhere.pidPath(), String(idle.child.pid))
1735
+ // inspection answers with an empty command line, as Windows does for an elevated process
1736
+ const inspect = anywhere.pidInspection.bind(anywhere)
1737
+ anywhere.pidInspection = () => { const i = inspect(); return i && { ...i, file: '/usr/bin/true', args: [] } }
1738
+ anywhere.client = () => ({ ping: async () => false }) // and the daemon endpoint is unreachable
1739
+ await assert.rejects(() => anywhere.stop(), /Cannot verify ownership/)
1740
+ await assert.rejects(() => anywhere.start(), /Cannot verify ownership/)
1741
+ assert.throws(() => anywhere.killSync(), /Cannot verify ownership/) // shutdown logs this and moves on
1742
+ process.kill(idle.child.pid, 0)
1743
+ assert.equal(fs.readFileSync(anywhere.pidPath(), 'utf8'), String(idle.child.pid), 'the record stays while the process lives')
1744
+ idle.child.kill('SIGKILL')
1745
+ assert.equal(await idle.exited(), true)
1746
+ assert.equal(await anywhere.readPid(), null, 'a gone process is gone')
1747
+ } finally {
1748
+ idle.child.kill('SIGKILL')
1749
+ fs.rmSync(tmp, { recursive: true, force: true })
1750
+ }
1751
+ })
@@ -1,5 +1,5 @@
1
1
  const assert = require('node:assert/strict')
2
- const { execFile } = require('node:child_process')
2
+ const { execFile, execFileSync } = require('node:child_process')
3
3
  const fs = require('node:fs/promises')
4
4
  const os = require('node:os')
5
5
  const path = require('node:path')
@@ -41,7 +41,7 @@ test('Git defaults point new Pinokio gitconfig files at the GitHub CLI credentia
41
41
  const content = await fs.readFile(path.join(homedir, 'gitconfig'), 'utf8')
42
42
  assert.doesNotMatch(content, /manager/)
43
43
  const config = ini.parse(content)
44
- assert.equal(config.credential, undefined)
44
+ assert.equal(config.credential.helper, '')
45
45
  assert.equal(githubCredentialSection(config).helper, '!gh auth git-credential')
46
46
  assert.equal(githubCredentialSection(config).provider, undefined)
47
47
  const { stdout } = await execFileAsync('git', ['config', '--file', path.join(homedir, 'gitconfig'), '--get', 'credential.https://github.com.helper'])
@@ -73,7 +73,7 @@ test('Git defaults migrate Git Credential Manager settings to the GitHub CLI hel
73
73
  assert.doesNotMatch(content, /manager/)
74
74
  assert.doesNotMatch(content, /gitHubAuthModes/)
75
75
  const config = ini.parse(content)
76
- assert.equal(config.credential, undefined)
76
+ assert.equal(config.credential.helper, '')
77
77
  assert.equal(githubCredentialSection(config).helper, '!gh auth git-credential')
78
78
  assert.equal(githubCredentialSection(config).provider, undefined)
79
79
  assert.equal(config.user.name, 'custom')
@@ -127,7 +127,8 @@ test('Git defaults reset credential sections to built-in defaults before Git rea
127
127
  assert.doesNotMatch(content, /custom-helper|gh\.exe|Any Folder/)
128
128
  const { stdout } = await execFileAsync('git', ['config', '--file', gitconfigPath, '--list'])
129
129
  assert.match(stdout, /credential\.https:\/\/github\.com\.helper=!gh auth git-credential$/m)
130
- assert.doesNotMatch(stdout, /^credential\.helper=/m)
130
+ assert.match(stdout, /^credential\.helper=$/m)
131
+ assert.ok(stdout.indexOf('credential.helper=\n') < stdout.indexOf('credential.https://github.com.helper='), 'reset must come before the GitHub helper')
131
132
  assert.doesNotMatch(stdout, /credential\.githubauthmodes/)
132
133
  assert.doesNotMatch(stdout, /credential\.namespace/)
133
134
  assert.doesNotMatch(stdout, /credential\.https:\/\/gist\.github\.com/)
@@ -167,3 +168,44 @@ test('Git isomorphic auth callback stays anonymous when no credential is stored'
167
168
 
168
169
  assert.equal(auth, undefined)
169
170
  })
171
+
172
+ test('Git defaults put the helper reset before the GitHub helper on an already-migrated gitconfig', { skip: process.platform === 'win32' && 'needs sh helpers' }, async () => {
173
+ await withTempHome(async (homedir) => {
174
+ const gitconfigPath = path.join(homedir, 'gitconfig')
175
+ // the layout written before the general reset existed: GitHub section last, no [credential]
176
+ await fs.writeFile(gitconfigPath, [
177
+ '[user]',
178
+ ' name = custom',
179
+ '[credential "https://github.com"]',
180
+ ' helper = !gh auth git-credential',
181
+ '',
182
+ ].join('\n'))
183
+ const git = new KernelGit(createKernel(homedir))
184
+
185
+ await git.ensureDefaults()
186
+
187
+ const content = await fs.readFile(gitconfigPath, 'utf8')
188
+ assert.ok(content.indexOf('[credential]') < content.indexOf('[credential "https://github.com"]'))
189
+
190
+ // a helper inherited from the system config (Git for Windows ships helper-selector there)
191
+ // must not run for github.com: only gh does
192
+ const bin = path.join(homedir, 'bin')
193
+ const log = path.join(homedir, 'log')
194
+ await fs.mkdir(bin)
195
+ await fs.writeFile(path.join(bin, 'git-credential-inherited'), `#!/bin/sh\necho inherited >> "${log}"\n`, { mode: 0o755 })
196
+ await fs.writeFile(path.join(bin, 'gh'), `#!/bin/sh\necho gh >> "${log}"\n`, { mode: 0o755 })
197
+ const systemConfig = path.join(homedir, 'system-gitconfig')
198
+ await fs.writeFile(systemConfig, '[credential]\n helper = inherited\n')
199
+ const env = {
200
+ ...process.env,
201
+ PATH: `${bin}${path.delimiter}${process.env.PATH}`,
202
+ GIT_CONFIG_SYSTEM: systemConfig,
203
+ GIT_CONFIG_GLOBAL: gitconfigPath,
204
+ GIT_TERMINAL_PROMPT: '0',
205
+ }
206
+ try {
207
+ execFileSync('git', ['credential', 'fill'], { env, input: 'protocol=https\nhost=github.com\n\n', stdio: 'pipe' })
208
+ } catch (_) {}
209
+ assert.equal(await fs.readFile(log, 'utf8'), 'gh\n')
210
+ })
211
+ })