@xulongzhe/clawbench 0.79.0 → 0.81.0

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.
package/bin/clawbench.js CHANGED
@@ -4,31 +4,20 @@ import { resolve, dirname } from "path";
4
4
  import { fileURLToPath } from "url";
5
5
  import { createRequire } from "module";
6
6
  import os from "os";
7
+ import { resolvePlatformPackage, resolveBinName } from "./platform.js";
7
8
 
8
9
  const __dirname = dirname(fileURLToPath(import.meta.url));
9
10
  const require = createRequire(import.meta.url);
10
11
 
11
- const PLATFORM_MAP = {
12
- "linux-x64": "@xulongzhe/clawbench-linux-x64",
13
- "linux-arm64": "@xulongzhe/clawbench-linux-arm64",
14
- "darwin-x64": "@xulongzhe/clawbench-darwin-x64",
15
- "darwin-arm64": "@xulongzhe/clawbench-darwin-arm64",
16
- "win32-x64": "@xulongzhe/clawbench-win32-x64",
17
- };
12
+ const resolved = resolvePlatformPackage(process.platform, process.arch);
18
13
 
19
- // Termux 上报 process.platform === "android",但它运行的是 Linux 用户态,
20
- // 其中 linux-arm64 的 Go 二进制可以直接执行,因此归一化到 linux。
21
- const platform = process.platform === "android" ? "linux" : process.platform;
22
-
23
- const key = `${platform}-${process.arch}`;
24
- const pkg = PLATFORM_MAP[key];
25
-
26
- if (!pkg) {
14
+ if (!resolved) {
27
15
  console.error(`clawbench: 不支持的平台 ${process.platform}-${process.arch}`);
28
16
  process.exit(1);
29
17
  }
30
18
 
31
- const binName = platform === "win32" ? "clawbench.exe" : "clawbench";
19
+ const { pkg } = resolved;
20
+ const binName = resolveBinName(process.platform);
32
21
 
33
22
  let binPath;
34
23
  if (process.env.CLAWBENCH_BINARY_PATH) {
@@ -0,0 +1,32 @@
1
+ // Platform → npm package resolution for the @xulongzhe/clawbench platform
2
+ // binaries. Kept as a pure module (no side effects) so it can be unit tested
3
+ // independently of the launcher's spawn logic.
4
+
5
+ export const PLATFORM_MAP = {
6
+ "linux-x64": "@xulongzhe/clawbench-linux-x64",
7
+ "linux-arm64": "@xulongzhe/clawbench-linux-arm64",
8
+ "android-arm64": "@xulongzhe/clawbench-android-arm64",
9
+ "darwin-x64": "@xulongzhe/clawbench-darwin-x64",
10
+ "darwin-arm64": "@xulongzhe/clawbench-darwin-arm64",
11
+ "win32-x64": "@xulongzhe/clawbench-win32-x64",
12
+ };
13
+
14
+ // Termux 上报 process.platform === "android",它运行在 Android 之上,
15
+ // 只接受 PIE(e_type 3 / ET_DYN)的可执行文件。linux-arm64 二进制是
16
+ // 非 PIE(e_type 2 / ET_EXEC),无法在 Android 上执行,因此 android
17
+ // 必须单独映射到 GOOS=android 编译的 PIE 包,而不是复用 linux。
18
+ export function resolvePlatformKey(platform, arch) {
19
+ return `${platform}-${arch}`;
20
+ }
21
+
22
+ // Returns { key, pkg } for a supported platform/arch, or null if unsupported.
23
+ export function resolvePlatformPackage(platform, arch) {
24
+ const key = resolvePlatformKey(platform, arch);
25
+ const pkg = PLATFORM_MAP[key];
26
+ if (!pkg) return null;
27
+ return { key, pkg };
28
+ }
29
+
30
+ export function resolveBinName(platform) {
31
+ return platform === "win32" ? "clawbench.exe" : "clawbench";
32
+ }
@@ -0,0 +1,55 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import {
3
+ PLATFORM_MAP,
4
+ resolvePlatformPackage,
5
+ resolveBinName,
6
+ } from './platform.js'
7
+
8
+ describe('resolvePlatformPackage', () => {
9
+ it('maps android/arm64 to the PIE android binary package', () => {
10
+ expect(resolvePlatformPackage('android', 'arm64')).toEqual({
11
+ key: 'android-arm64',
12
+ pkg: '@xulongzhe/clawbench-android-arm64',
13
+ })
14
+ })
15
+
16
+ it('keeps linux/arm64 mapped to the linux-arm64 package', () => {
17
+ expect(resolvePlatformPackage('linux', 'arm64')).toEqual({
18
+ key: 'linux-arm64',
19
+ pkg: '@xulongzhe/clawbench-linux-arm64',
20
+ })
21
+ })
22
+
23
+ it('maps darwin/arm64 and linux/x64 to their packages', () => {
24
+ expect(resolvePlatformPackage('darwin', 'arm64').pkg).toBe('@xulongzhe/clawbench-darwin-arm64')
25
+ expect(resolvePlatformPackage('linux', 'x64').pkg).toBe('@xulongzhe/clawbench-linux-x64')
26
+ })
27
+
28
+ it('maps win32/x64 to the win32 package', () => {
29
+ expect(resolvePlatformPackage('win32', 'x64').pkg).toBe('@xulongzhe/clawbench-win32-x64')
30
+ })
31
+
32
+ it('returns null for unsupported platform/arch combos', () => {
33
+ expect(resolvePlatformPackage('win32', 'ia32')).toBeNull()
34
+ expect(resolvePlatformPackage('freebsd', 'x64')).toBeNull()
35
+ expect(resolvePlatformPackage('android', 'x64')).toBeNull()
36
+ })
37
+ })
38
+
39
+ describe('resolveBinName', () => {
40
+ it('uses clawbench.exe for win32', () => {
41
+ expect(resolveBinName('win32')).toBe('clawbench.exe')
42
+ })
43
+
44
+ it('uses the plain name for every other platform including android', () => {
45
+ expect(resolveBinName('android')).toBe('clawbench')
46
+ expect(resolveBinName('linux')).toBe('clawbench')
47
+ expect(resolveBinName('darwin')).toBe('clawbench')
48
+ })
49
+ })
50
+
51
+ describe('PLATFORM_MAP', () => {
52
+ it('contains an android-arm64 entry so Termux selects the PIE binary', () => {
53
+ expect(PLATFORM_MAP['android-arm64']).toBe('@xulongzhe/clawbench-android-arm64')
54
+ })
55
+ })
package/install.js CHANGED
@@ -5,30 +5,20 @@ import { readFileSync } from "fs";
5
5
  import { dirname, join } from "path";
6
6
  import { fileURLToPath } from "url";
7
7
  import { createRequire } from "module";
8
+ import { resolvePlatformPackage } from "./bin/platform.js";
8
9
 
9
10
  const __dirname = dirname(fileURLToPath(import.meta.url));
10
11
  const require = createRequire(import.meta.url);
11
12
 
12
- const PLATFORM_MAP = {
13
- "linux-x64": "@xulongzhe/clawbench-linux-x64",
14
- "linux-arm64": "@xulongzhe/clawbench-linux-arm64",
15
- "darwin-x64": "@xulongzhe/clawbench-darwin-x64",
16
- "darwin-arm64": "@xulongzhe/clawbench-darwin-arm64",
17
- "win32-x64": "@xulongzhe/clawbench-win32-x64",
18
- };
13
+ const resolved = resolvePlatformPackage(process.platform, process.arch);
19
14
 
20
- // Termux 上报 process.platform === "android",但它运行的是 Linux 用户态,
21
- // 其中 linux-arm64 的 Go 二进制可以直接执行,因此归一化到 linux。
22
- const platform = process.platform === "android" ? "linux" : process.platform;
23
-
24
- const key = `${platform}-${process.arch}`;
25
- const pkg = PLATFORM_MAP[key];
26
-
27
- if (!pkg) {
15
+ if (!resolved) {
28
16
  // 不支持的平台,静默跳过
29
17
  process.exit(0);
30
18
  }
31
19
 
20
+ const { pkg } = resolved;
21
+
32
22
  // 检查平台包是否已通过 optionalDependencies 安装
33
23
  try {
34
24
  require.resolve(`${pkg}/package.json`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xulongzhe/clawbench",
3
- "version": "0.79.0",
3
+ "version": "0.81.0",
4
4
  "description": "Mobile-first AI workstation — Go backend + Vue3 frontend",
5
5
  "type": "module",
6
6
  "bin": {
@@ -14,12 +14,12 @@
14
14
  "postinstall": "node install.js"
15
15
  },
16
16
  "optionalDependencies": {
17
- "@xulongzhe/clawbench-linux-x64": "0.79.0",
18
- "@xulongzhe/clawbench-linux-arm64": "0.79.0",
19
- "@xulongzhe/clawbench-android-arm64": "0.79.0",
20
- "@xulongzhe/clawbench-darwin-x64": "0.79.0",
21
- "@xulongzhe/clawbench-darwin-arm64": "0.79.0",
22
- "@xulongzhe/clawbench-win32-x64": "0.79.0"
17
+ "@xulongzhe/clawbench-linux-x64": "0.81.0",
18
+ "@xulongzhe/clawbench-linux-arm64": "0.81.0",
19
+ "@xulongzhe/clawbench-android-arm64": "0.81.0",
20
+ "@xulongzhe/clawbench-darwin-x64": "0.81.0",
21
+ "@xulongzhe/clawbench-darwin-arm64": "0.81.0",
22
+ "@xulongzhe/clawbench-win32-x64": "0.81.0"
23
23
  },
24
24
  "engines": {
25
25
  "node": ">=14"