-
Notifications
You must be signed in to change notification settings - Fork 2
fix: codex update targets correct npm prefix on multi-prefix systems #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| import { test } from 'node:test'; | ||
| import assert from 'node:assert'; | ||
| import { mkdtempSync, mkdirSync, rmSync, cpSync, writeFileSync, readFileSync, chmodSync } from 'fs'; | ||
| import { spawnSync } from 'child_process'; | ||
| import path, { resolve, join } from 'path'; | ||
| import os from 'os'; | ||
| import { fileURLToPath } from 'url'; | ||
| import { dirname } from 'path'; | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = dirname(__filename); | ||
| const packageDir = resolve(__dirname, '..'); | ||
| const repoRoot = resolve(packageDir, '..', '..', '..'); | ||
|
|
||
| const manifestPath = join(packageDir, 'config', 'codex-termux-release-manifest.json'); | ||
| const manifest = JSON.parse(readFileSync(manifestPath, 'utf8')); | ||
| const latestAuditedVersion = manifest.latest_audited_version; | ||
| const testVersion = '0.144.4'; // Older version for testing | ||
|
|
||
| test('installTarget with prefixA uses correct --prefix', async (t) => { | ||
| const tmpdir = mkdtempSync(join(os.tmpdir(), 'codex-prefix-test-')); | ||
| try { | ||
| const prefixA = join(tmpdir, 'prefixA'); | ||
| const prefixANodeModules = join(prefixA, 'lib', 'node_modules', '@bash0816', 'codex-termux'); | ||
| const fakeNpmDir = join(tmpdir, 'fake-bin'); | ||
| const recordFileA = join(tmpdir, 'npm-args-a.json'); | ||
|
|
||
| // Create directory structure for prefixA | ||
| cpSync(packageDir, prefixANodeModules, { recursive: true }); | ||
|
|
||
| // Update package.json version to old version | ||
| const pkgJsonPath = join(prefixANodeModules, 'package.json'); | ||
| const pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf8')); | ||
| pkg.version = testVersion; | ||
| writeFileSync(pkgJsonPath, JSON.stringify(pkg, null, 2) + '\n'); | ||
|
|
||
| // Create fake npm binary | ||
| mkdirSync(fakeNpmDir, { recursive: true }); | ||
| const fakeNpmPath = join(fakeNpmDir, 'npm'); | ||
| writeFileSync( | ||
| fakeNpmPath, | ||
| `#!/usr/bin/env node | ||
| const fs = require('fs'); | ||
| fs.writeFileSync(process.env.FAKE_NPM_RECORD_FILE, JSON.stringify(process.argv.slice(2))); | ||
| process.exit(0); | ||
| ` | ||
| ); | ||
| chmodSync(fakeNpmPath, 0o755); | ||
|
|
||
| // Run check-updates.js from prefixA | ||
| const result = spawnSync('node', [join(prefixANodeModules, 'lib', 'check-updates.js'), 'update'], { | ||
| env: { | ||
| ...process.env, | ||
| PATH: `${fakeNpmDir}:${process.env.PATH}`, | ||
| CODEX_TERMUX_SKIP_UPDATE_CHECK: '1', | ||
| FAKE_NPM_RECORD_FILE: recordFileA, | ||
| }, | ||
| stdio: 'pipe', | ||
| }); | ||
|
|
||
| // Check recorded npm arguments | ||
| const recordedArgs = JSON.parse(readFileSync(recordFileA, 'utf8')); | ||
| const expectedArgs = ['install', '-g', '--prefix', prefixA, `@bash0816/codex-termux@${latestAuditedVersion}`]; | ||
| assert.deepStrictEqual(recordedArgs, expectedArgs, `Expected ${JSON.stringify(expectedArgs)} but got ${JSON.stringify(recordedArgs)}`); | ||
| } finally { | ||
| rmSync(tmpdir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| test('installTarget with prefixB uses correct --prefix', async (t) => { | ||
| const tmpdir = mkdtempSync(join(os.tmpdir(), 'codex-prefix-test-')); | ||
| try { | ||
| const prefixB = join(tmpdir, 'prefixB'); | ||
| const prefixBNodeModules = join(prefixB, 'lib', 'node_modules', '@bash0816', 'codex-termux'); | ||
| const fakeNpmDir = join(tmpdir, 'fake-bin'); | ||
| const recordFileB = join(tmpdir, 'npm-args-b.json'); | ||
|
|
||
| // Create directory structure for prefixB | ||
| cpSync(packageDir, prefixBNodeModules, { recursive: true }); | ||
|
|
||
| // Update package.json version to old version | ||
| const pkgJsonPath = join(prefixBNodeModules, 'package.json'); | ||
| const pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf8')); | ||
| pkg.version = testVersion; | ||
| writeFileSync(pkgJsonPath, JSON.stringify(pkg, null, 2) + '\n'); | ||
|
|
||
| // Create fake npm binary | ||
| mkdirSync(fakeNpmDir, { recursive: true }); | ||
| const fakeNpmPath = join(fakeNpmDir, 'npm'); | ||
| writeFileSync( | ||
| fakeNpmPath, | ||
| `#!/usr/bin/env node | ||
| const fs = require('fs'); | ||
| fs.writeFileSync(process.env.FAKE_NPM_RECORD_FILE, JSON.stringify(process.argv.slice(2))); | ||
| process.exit(0); | ||
| ` | ||
| ); | ||
| chmodSync(fakeNpmPath, 0o755); | ||
|
|
||
| // Run check-updates.js from prefixB | ||
| const result = spawnSync('node', [join(prefixBNodeModules, 'lib', 'check-updates.js'), 'update'], { | ||
| env: { | ||
| ...process.env, | ||
| PATH: `${fakeNpmDir}:${process.env.PATH}`, | ||
| CODEX_TERMUX_SKIP_UPDATE_CHECK: '1', | ||
| FAKE_NPM_RECORD_FILE: recordFileB, | ||
| }, | ||
| stdio: 'pipe', | ||
| }); | ||
|
|
||
| // Check recorded npm arguments | ||
| const recordedArgs = JSON.parse(readFileSync(recordFileB, 'utf8')); | ||
| const expectedArgs = ['install', '-g', '--prefix', prefixB, `@bash0816/codex-termux@${latestAuditedVersion}`]; | ||
| assert.deepStrictEqual(recordedArgs, expectedArgs, `Expected ${JSON.stringify(expectedArgs)} but got ${JSON.stringify(recordedArgs)}`); | ||
| } finally { | ||
| rmSync(tmpdir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the checked
.github/workflows/npm-package.ymlworkflow, the syntax-check step explicitly runs onlysync-public-release-from-manifest.test.jsandmagi-node-launcher.test.js, and this package has no test script that discovers suites automatically. Consequently, this newly added prefix regression suite is never executed on pull requests or pushes, so regressions in the behavior it covers can pass CI; addnode --test lib/check-updates.test.jsto that workflow.Useful? React with 👍 / 👎.