@altairalabs/promptarena 1.6.0 → 1.6.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.
@@ -1,27 +1,25 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { spawn } from 'node:child_process';
4
- import path from 'node:path';
5
- import fs from 'node:fs';
6
- import { fileURLToPath } from 'node:url';
4
+ import { createRequire } from 'node:module';
5
+ import { resolveBinary } from '../lib/resolve.js';
7
6
 
8
- const __filename = fileURLToPath(import.meta.url);
9
- const __dirname = path.dirname(__filename);
7
+ const require = createRequire(import.meta.url);
10
8
 
11
- const binaryName = process.platform === 'win32' ? 'promptarena.exe' : 'promptarena';
12
- const binaryPath = path.join(__dirname, '..', binaryName);
13
-
14
- // Check if binary exists
15
- if (!fs.existsSync(binaryPath)) {
16
- console.error('Error: promptarena binary not found.');
17
- console.error('Please try reinstalling: npm install @altairalabs/promptarena');
9
+ let binaryPath;
10
+ try {
11
+ // Bind through an arrow so require.resolve keeps its receiver.
12
+ binaryPath = resolveBinary('promptarena', {
13
+ resolve: (id) => require.resolve(id),
14
+ });
15
+ } catch (err) {
16
+ console.error(`Error: ${err.message}`);
18
17
  process.exit(1);
19
18
  }
20
19
 
21
- // Spawn the Go binary with all arguments
22
20
  const child = spawn(binaryPath, process.argv.slice(2), {
23
21
  stdio: 'inherit',
24
- windowsHide: false
22
+ windowsHide: false,
25
23
  });
26
24
 
27
25
  child.on('error', (err) => {
package/lib/resolve.js ADDED
@@ -0,0 +1,80 @@
1
+ // Locates the prebuilt Go binary that ships in a per-platform sibling package.
2
+ //
3
+ // This replaces the old postinstall downloader. npm 12 blocks dependency
4
+ // lifecycle scripts unless the consumer allowlists them, so a `postinstall`
5
+ // that fetches the binary silently never runs and every invocation dies with
6
+ // "binary not found". Platform packages listed as optionalDependencies are
7
+ // plain resolution instead: npm/pnpm/yarn/bun filter them by the `os` and `cpu`
8
+ // fields and unpack only the one that matches, with no scripts involved.
9
+
10
+ const SCOPE = '@altairalabs';
11
+
12
+ // Targets we publish a binary package for, spelled the way Node spells them
13
+ // (`process.platform`-`process.arch`) so a target string can be compared
14
+ // against the running interpreter without a lookup table. GoReleaser builds
15
+ // linux/darwin/windows against amd64/arm64, which is exactly these six.
16
+ export const TARGETS = Object.freeze([
17
+ 'darwin-arm64',
18
+ 'darwin-x64',
19
+ 'linux-arm64',
20
+ 'linux-x64',
21
+ 'win32-arm64',
22
+ 'win32-x64',
23
+ ]);
24
+
25
+ export function targetFor(platform = process.platform, arch = process.arch) {
26
+ return `${platform}-${arch}`;
27
+ }
28
+
29
+ export function isSupported(target) {
30
+ return TARGETS.includes(target);
31
+ }
32
+
33
+ export function packageFor(tool, target) {
34
+ return `${SCOPE}/${tool}-${target}`;
35
+ }
36
+
37
+ export function binaryFor(tool, platform = process.platform) {
38
+ return platform === 'win32' ? `${tool}.exe` : tool;
39
+ }
40
+
41
+ /**
42
+ * Resolve the on-disk path of the binary for the running platform.
43
+ *
44
+ * @param {string} tool Binary name, e.g. 'promptarena'.
45
+ * @param {object} options
46
+ * @param {(id: string) => string} options.resolve Resolver, normally
47
+ * `createRequire(import.meta.url).resolve`. Injected so tests can drive the
48
+ * failure paths without installing real platform packages.
49
+ * @param {string} [options.platform] Defaults to process.platform.
50
+ * @param {string} [options.arch] Defaults to process.arch.
51
+ * @returns {string} Absolute path to the executable.
52
+ */
53
+ export function resolveBinary(tool, { resolve, platform, arch } = {}) {
54
+ const target = targetFor(platform, arch);
55
+
56
+ if (!isSupported(target)) {
57
+ throw new Error(
58
+ `${tool} does not ship a prebuilt binary for ${target}.\n` +
59
+ `Supported targets: ${TARGETS.join(', ')}.\n` +
60
+ `Build from source instead: https://github.com/AltairaLabs/promptarena`
61
+ );
62
+ }
63
+
64
+ const pkg = packageFor(tool, target);
65
+
66
+ try {
67
+ return resolve(`${pkg}/${binaryFor(tool, platform ?? process.platform)}`);
68
+ } catch (cause) {
69
+ // The optional dependency is declared but absent. The usual causes are an
70
+ // install that opted out of optional deps, or a lockfile carried over from
71
+ // a different platform.
72
+ throw new Error(
73
+ `${tool} could not find its platform binary package ${pkg}.\n` +
74
+ `This normally means the install ran with --no-optional or ` +
75
+ `--omit=optional, or a lockfile from another platform was reused.\n` +
76
+ `Reinstall with optional dependencies enabled: npm install ${SCOPE}/${tool}`,
77
+ { cause }
78
+ );
79
+ }
80
+ }
@@ -0,0 +1,164 @@
1
+ import { jest } from '@jest/globals';
2
+ import {
3
+ TARGETS,
4
+ targetFor,
5
+ isSupported,
6
+ packageFor,
7
+ binaryFor,
8
+ resolveBinary,
9
+ } from './resolve.js';
10
+
11
+ describe('resolve', () => {
12
+ describe('TARGETS', () => {
13
+ it('covers the six goos/goarch combinations goreleaser builds', () => {
14
+ expect([...TARGETS].sort()).toEqual([
15
+ 'darwin-arm64',
16
+ 'darwin-x64',
17
+ 'linux-arm64',
18
+ 'linux-x64',
19
+ 'win32-arm64',
20
+ 'win32-x64',
21
+ ]);
22
+ });
23
+
24
+ it('is frozen so a caller cannot widen the supported set', () => {
25
+ expect(Object.isFrozen(TARGETS)).toBe(true);
26
+ });
27
+ });
28
+
29
+ describe('targetFor', () => {
30
+ it('joins platform and arch', () => {
31
+ expect(targetFor('darwin', 'arm64')).toBe('darwin-arm64');
32
+ });
33
+
34
+ it('defaults to the running interpreter', () => {
35
+ expect(targetFor()).toBe(`${process.platform}-${process.arch}`);
36
+ });
37
+ });
38
+
39
+ describe('isSupported', () => {
40
+ it('accepts a published target', () => {
41
+ expect(isSupported('linux-x64')).toBe(true);
42
+ });
43
+
44
+ it('rejects a target we do not build', () => {
45
+ expect(isSupported('freebsd-x64')).toBe(false);
46
+ });
47
+ });
48
+
49
+ describe('packageFor', () => {
50
+ it('builds the scoped platform package name', () => {
51
+ expect(packageFor('promptarena', 'darwin-arm64')).toBe(
52
+ '@altairalabs/promptarena-darwin-arm64'
53
+ );
54
+ });
55
+ });
56
+
57
+ describe('binaryFor', () => {
58
+ it('appends .exe on Windows', () => {
59
+ expect(binaryFor('promptarena', 'win32')).toBe('promptarena.exe');
60
+ });
61
+
62
+ it('leaves the name bare elsewhere', () => {
63
+ expect(binaryFor('promptarena', 'linux')).toBe('promptarena');
64
+ expect(binaryFor('promptarena', 'darwin')).toBe('promptarena');
65
+ });
66
+ });
67
+
68
+ describe('resolveBinary', () => {
69
+ it('resolves the platform package subpath', () => {
70
+ const resolve = jest.fn(() => '/pkgs/promptarena-linux-x64/promptarena');
71
+ const got = resolveBinary('promptarena', {
72
+ resolve,
73
+ platform: 'linux',
74
+ arch: 'x64',
75
+ });
76
+
77
+ expect(resolve).toHaveBeenCalledWith(
78
+ '@altairalabs/promptarena-linux-x64/promptarena'
79
+ );
80
+ expect(got).toBe('/pkgs/promptarena-linux-x64/promptarena');
81
+ });
82
+
83
+ it('asks for the .exe subpath on Windows', () => {
84
+ const resolve = jest.fn(() => 'C:\\pkgs\\promptarena.exe');
85
+ resolveBinary('promptarena', {
86
+ resolve,
87
+ platform: 'win32',
88
+ arch: 'x64',
89
+ });
90
+
91
+ expect(resolve).toHaveBeenCalledWith(
92
+ '@altairalabs/promptarena-win32-x64/promptarena.exe'
93
+ );
94
+ });
95
+
96
+ it('throws a build-from-source hint on an unsupported target', () => {
97
+ const resolve = jest.fn();
98
+
99
+ expect(() =>
100
+ resolveBinary('promptarena', {
101
+ resolve,
102
+ platform: 'freebsd',
103
+ arch: 'x64',
104
+ })
105
+ ).toThrow(/does not ship a prebuilt binary for freebsd-x64/);
106
+ expect(resolve).not.toHaveBeenCalled();
107
+ });
108
+
109
+ it('throws a reinstall hint when the optional dependency is missing', () => {
110
+ const resolve = jest.fn(() => {
111
+ throw new Error('Cannot find module');
112
+ });
113
+
114
+ expect(() =>
115
+ resolveBinary('promptarena', {
116
+ resolve,
117
+ platform: 'linux',
118
+ arch: 'x64',
119
+ })
120
+ ).toThrow(/--omit=optional/);
121
+ });
122
+
123
+ it('keeps the underlying resolution error as the cause', () => {
124
+ const cause = new Error('Cannot find module');
125
+ const resolve = jest.fn(() => {
126
+ throw cause;
127
+ });
128
+
129
+ try {
130
+ resolveBinary('promptarena', {
131
+ resolve,
132
+ platform: 'linux',
133
+ arch: 'x64',
134
+ });
135
+ throw new Error('expected resolveBinary to throw');
136
+ } catch (err) {
137
+ expect(err.cause).toBe(cause);
138
+ }
139
+ });
140
+ });
141
+
142
+ describe('defaults from the running interpreter', () => {
143
+ it('binaryFor falls back to process.platform', () => {
144
+ const expected = process.platform === 'win32' ? 'promptarena.exe' : 'promptarena';
145
+ expect(binaryFor('promptarena')).toBe(expected);
146
+ });
147
+
148
+ it('resolveBinary falls back to the host target', () => {
149
+ const resolve = jest.fn(() => '/resolved/promptarena');
150
+ resolveBinary('promptarena', { resolve });
151
+
152
+ const host = `${process.platform}-${process.arch}`;
153
+ expect(resolve).toHaveBeenCalledWith(
154
+ `@altairalabs/promptarena-${host}/${binaryFor('promptarena')}`
155
+ );
156
+ });
157
+
158
+ it('resolveBinary rejects a call with no options at all', () => {
159
+ // No resolver supplied: the missing-package path must still produce the
160
+ // actionable error rather than a TypeError.
161
+ expect(() => resolveBinary('promptarena')).toThrow(/promptarena/);
162
+ });
163
+ });
164
+ });
package/package.json CHANGED
@@ -1,19 +1,26 @@
1
1
  {
2
2
  "name": "@altairalabs/promptarena",
3
- "version": "1.6.0",
3
+ "version": "1.6.3",
4
4
  "type": "module",
5
5
  "description": "PromptKit Arena - Multi-turn conversation simulation and testing tool for LLM applications",
6
6
  "bin": {
7
7
  "promptarena": "./bin/promptarena.js"
8
8
  },
9
9
  "scripts": {
10
- "postinstall": "node postinstall.js",
11
10
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
12
11
  "test:ci": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --ci",
13
12
  "test:binary": "node bin/promptarena.js --version",
14
13
  "test:init": "node test-init.js",
15
14
  "lint": "eslint *.js bin/*.js"
16
15
  },
16
+ "optionalDependencies": {
17
+ "@altairalabs/promptarena-darwin-arm64": "1.6.3",
18
+ "@altairalabs/promptarena-darwin-x64": "1.6.3",
19
+ "@altairalabs/promptarena-linux-arm64": "1.6.3",
20
+ "@altairalabs/promptarena-linux-x64": "1.6.3",
21
+ "@altairalabs/promptarena-win32-arm64": "1.6.3",
22
+ "@altairalabs/promptarena-win32-x64": "1.6.3"
23
+ },
17
24
  "devDependencies": {
18
25
  "@eslint/js": "^10.0.1",
19
26
  "eslint": "^10.0.0",
@@ -48,19 +55,9 @@
48
55
  "engines": {
49
56
  "node": ">=18.0.0"
50
57
  },
51
- "os": [
52
- "darwin",
53
- "linux",
54
- "win32"
55
- ],
56
- "cpu": [
57
- "x64",
58
- "arm64"
59
- ],
60
58
  "files": [
61
59
  "bin/",
62
60
  "lib/",
63
- "postinstall.js",
64
61
  "README.md",
65
62
  "schemas/",
66
63
  "schema-map.json"
package/lib/installer.js DELETED
@@ -1,112 +0,0 @@
1
- import https from 'node:https';
2
- import http from 'node:http';
3
- import fs from 'node:fs';
4
- import path from 'node:path';
5
- import { execSync } from 'node:child_process';
6
- import { pipeline } from 'node:stream';
7
- import { promisify } from 'node:util';
8
-
9
- const streamPipeline = promisify(pipeline);
10
-
11
- // Platform mapping to match GoReleaser output
12
- export const PLATFORM_MAP = {
13
- darwin: 'Darwin',
14
- linux: 'Linux',
15
- win32: 'Windows'
16
- };
17
-
18
- export const ARCH_MAP = {
19
- x64: 'x86_64',
20
- arm64: 'arm64'
21
- };
22
-
23
- export function getPlatformInfo(platform = process.platform, arch = process.arch) {
24
- const mappedPlatform = PLATFORM_MAP[platform];
25
- const mappedArch = ARCH_MAP[arch];
26
-
27
- if (!mappedPlatform || !mappedArch) {
28
- throw new Error(`Unsupported platform: ${platform}-${arch}`);
29
- }
30
-
31
- return { platform: mappedPlatform, arch: mappedArch };
32
- }
33
-
34
- export function getDownloadUrl(version, platform, arch, repo = 'AltairaLabs/promptarena') {
35
- const archiveExt = platform === 'Windows' ? 'zip' : 'tar.gz';
36
- const archiveName = `promptarena_${version}_${platform}_${arch}.${archiveExt}`;
37
- return `https://github.com/${repo}/releases/download/v${version}/${archiveName}`;
38
- }
39
-
40
- export async function downloadFile(url, destPath) {
41
- return new Promise((resolve, reject) => {
42
- const client = url.startsWith('https:') ? https : http;
43
-
44
- client.get(url, (response) => {
45
- // Follow redirects
46
- if (response.statusCode === 302 || response.statusCode === 301) {
47
- downloadFile(response.headers.location, destPath)
48
- .then(resolve)
49
- .catch(reject);
50
- return;
51
- }
52
-
53
- if (response.statusCode !== 200) {
54
- reject(new Error(`Failed to download: HTTP ${response.statusCode}`));
55
- return;
56
- }
57
-
58
- const fileStream = fs.createWriteStream(destPath);
59
- streamPipeline(response, fileStream)
60
- .then(resolve)
61
- .catch(reject);
62
- }).on('error', reject);
63
- });
64
- }
65
-
66
- export function extractBinary(archivePath, platform, binaryName, destDir) {
67
- const binaryWithExt = platform === 'Windows' ? `${binaryName}.exe` : binaryName;
68
- const destPath = path.join(destDir, binaryWithExt);
69
-
70
- if (platform === 'Windows') {
71
- execSync(`unzip -j "${archivePath}" "${binaryWithExt}" -d "${destDir}"`, {
72
- stdio: 'inherit'
73
- });
74
- } else {
75
- execSync(`tar -xzf "${archivePath}" -C "${destDir}" "${binaryWithExt}"`, {
76
- stdio: 'inherit'
77
- });
78
- }
79
-
80
- // Make executable on Unix-like systems. 0o755 = owner rwx, group/other r-x
81
- // (NOT world-writable) — the minimal mode that lets every user run the CLI
82
- // while keeping write access owner-only. The binary must be executable to run.
83
- if (platform !== 'Windows') {
84
- fs.chmodSync(destPath, 0o755); // NOSONAR S2612: 0o755 is not world-writable; required to run the CLI
85
- }
86
-
87
- return destPath;
88
- }
89
-
90
- export async function install(binaryName, version, baseDir) {
91
- console.log(`Installing ${binaryName} v${version}...`);
92
-
93
- const { platform, arch } = getPlatformInfo();
94
- console.log(`Platform: ${platform} ${arch}`);
95
-
96
- const url = getDownloadUrl(version, platform, arch);
97
- const archiveExt = platform === 'Windows' ? 'zip' : 'tar.gz';
98
- const archivePath = path.join(baseDir, `archive.${archiveExt}`);
99
-
100
- console.log('Downloading binary from GitHub Releases...');
101
- await downloadFile(url, archivePath);
102
- console.log('✓ Download complete');
103
-
104
- console.log('Extracting binary...');
105
- extractBinary(archivePath, platform, binaryName, baseDir);
106
- console.log(`✓ Extracted ${binaryName}`);
107
-
108
- // Clean up archive
109
- fs.unlinkSync(archivePath);
110
-
111
- console.log(`✓ ${binaryName} installed successfully!`);
112
- }
@@ -1,121 +0,0 @@
1
- import {
2
- getPlatformInfo,
3
- getDownloadUrl,
4
- PLATFORM_MAP,
5
- ARCH_MAP
6
- } from './installer.js';
7
-
8
- describe('installer', () => {
9
- describe('PLATFORM_MAP', () => {
10
- it('should map darwin to Darwin', () => {
11
- expect(PLATFORM_MAP.darwin).toBe('Darwin');
12
- });
13
-
14
- it('should map linux to Linux', () => {
15
- expect(PLATFORM_MAP.linux).toBe('Linux');
16
- });
17
-
18
- it('should map win32 to Windows', () => {
19
- expect(PLATFORM_MAP.win32).toBe('Windows');
20
- });
21
- });
22
-
23
- describe('ARCH_MAP', () => {
24
- it('should map x64 to x86_64', () => {
25
- expect(ARCH_MAP.x64).toBe('x86_64');
26
- });
27
-
28
- it('should map arm64 to arm64', () => {
29
- expect(ARCH_MAP.arm64).toBe('arm64');
30
- });
31
- });
32
-
33
- describe('getPlatformInfo', () => {
34
- it('should return mapped platform and arch for darwin x64', () => {
35
- const result = getPlatformInfo('darwin', 'x64');
36
- expect(result).toEqual({ platform: 'Darwin', arch: 'x86_64' });
37
- });
38
-
39
- it('should return mapped platform and arch for darwin arm64', () => {
40
- const result = getPlatformInfo('darwin', 'arm64');
41
- expect(result).toEqual({ platform: 'Darwin', arch: 'arm64' });
42
- });
43
-
44
- it('should return mapped platform and arch for linux x64', () => {
45
- const result = getPlatformInfo('linux', 'x64');
46
- expect(result).toEqual({ platform: 'Linux', arch: 'x86_64' });
47
- });
48
-
49
- it('should return mapped platform and arch for linux arm64', () => {
50
- const result = getPlatformInfo('linux', 'arm64');
51
- expect(result).toEqual({ platform: 'Linux', arch: 'arm64' });
52
- });
53
-
54
- it('should return mapped platform and arch for win32 x64', () => {
55
- const result = getPlatformInfo('win32', 'x64');
56
- expect(result).toEqual({ platform: 'Windows', arch: 'x86_64' });
57
- });
58
-
59
- it('should throw error for unsupported platform', () => {
60
- expect(() => getPlatformInfo('freebsd', 'x64')).toThrow(
61
- 'Unsupported platform: freebsd-x64'
62
- );
63
- });
64
-
65
- it('should throw error for unsupported arch', () => {
66
- expect(() => getPlatformInfo('darwin', 'ia32')).toThrow(
67
- 'Unsupported platform: darwin-ia32'
68
- );
69
- });
70
-
71
- it('should throw error for unsupported platform and arch', () => {
72
- expect(() => getPlatformInfo('aix', 'ppc64')).toThrow(
73
- 'Unsupported platform: aix-ppc64'
74
- );
75
- });
76
- });
77
-
78
- describe('getDownloadUrl', () => {
79
- it('should generate correct URL for Darwin x86_64', () => {
80
- const url = getDownloadUrl('1.0.0', 'Darwin', 'x86_64');
81
- expect(url).toBe(
82
- 'https://github.com/AltairaLabs/PromptKit/releases/download/v1.0.0/promptarena_1.0.0_Darwin_x86_64.tar.gz'
83
- );
84
- });
85
-
86
- it('should generate correct URL for Darwin arm64', () => {
87
- const url = getDownloadUrl('1.0.0', 'Darwin', 'arm64');
88
- expect(url).toBe(
89
- 'https://github.com/AltairaLabs/PromptKit/releases/download/v1.0.0/promptarena_1.0.0_Darwin_arm64.tar.gz'
90
- );
91
- });
92
-
93
- it('should generate correct URL for Linux x86_64', () => {
94
- const url = getDownloadUrl('2.1.0', 'Linux', 'x86_64');
95
- expect(url).toBe(
96
- 'https://github.com/AltairaLabs/PromptKit/releases/download/v2.1.0/promptarena_2.1.0_Linux_x86_64.tar.gz'
97
- );
98
- });
99
-
100
- it('should generate correct URL for Windows (zip extension)', () => {
101
- const url = getDownloadUrl('1.0.0', 'Windows', 'x86_64');
102
- expect(url).toBe(
103
- 'https://github.com/AltairaLabs/PromptKit/releases/download/v1.0.0/promptarena_1.0.0_Windows_x86_64.zip'
104
- );
105
- });
106
-
107
- it('should use custom repository when provided', () => {
108
- const url = getDownloadUrl('1.0.0', 'Darwin', 'x86_64', 'MyOrg/MyRepo');
109
- expect(url).toBe(
110
- 'https://github.com/MyOrg/MyRepo/releases/download/v1.0.0/promptarena_1.0.0_Darwin_x86_64.tar.gz'
111
- );
112
- });
113
-
114
- it('should handle prerelease versions', () => {
115
- const url = getDownloadUrl('1.0.0-beta.1', 'Linux', 'arm64');
116
- expect(url).toBe(
117
- 'https://github.com/AltairaLabs/PromptKit/releases/download/v1.0.0-beta.1/promptarena_1.0.0-beta.1_Linux_arm64.tar.gz'
118
- );
119
- });
120
- });
121
- });
package/postinstall.js DELETED
@@ -1,28 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import path from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
- import { createRequire } from 'node:module';
6
- import { install, getDownloadUrl, getPlatformInfo } from './lib/installer.js';
7
-
8
- const require = createRequire(import.meta.url);
9
- const __filename = fileURLToPath(import.meta.url);
10
- const __dirname = path.dirname(__filename);
11
-
12
- const BINARY_NAME = 'promptarena';
13
- const VERSION = require('./package.json').version;
14
-
15
- try {
16
- await install(BINARY_NAME, VERSION, __dirname);
17
- } catch (error) {
18
- const { platform, arch } = getPlatformInfo();
19
- const url = getDownloadUrl(VERSION, platform, arch);
20
-
21
- console.error(`\n❌ Installation failed: ${error.message}`);
22
- console.error('\nTroubleshooting:');
23
- console.error('1. Verify version exists: https://github.com/AltairaLabs/PromptKit/releases');
24
- console.error('2. Check your internet connection');
25
- console.error('3. Try downloading manually from GitHub Releases');
26
- console.error(` URL: ${url}`);
27
- process.exit(1);
28
- }