diff --git a/v3/@claude-flow/browser/package.json b/v3/@claude-flow/browser/package.json index 8c8327c385..a9f2cf43d9 100644 --- a/v3/@claude-flow/browser/package.json +++ b/v3/@claude-flow/browser/package.json @@ -23,7 +23,7 @@ "test:e2e": "vitest run tests/e2e", "lint": "eslint src/", "typecheck": "tsc --noEmit", - "postinstall": "node -e \"const{execSync}=require('child_process');try{execSync('agent-browser --version',{stdio:'ignore'});}catch{console.log('\\n📦 Installing agent-browser globally...');try{execSync('npm install -g agent-browser@latest',{stdio:'inherit'});console.log('✅ agent-browser installed successfully!');}catch(e){console.log('⚠️ Could not install agent-browser globally. Run manually:\\n npm install -g agent-browser@latest');}}\"" + "postinstall": "node -e \"const{execSync}=require('child_process');const v=require('./package.json').dependencies['agent-browser'];try{execSync('agent-browser --version',{stdio:'ignore'});}catch{console.log('\\n📦 Installing agent-browser globally...');try{execSync('npm install -g agent-browser@'+v,{stdio:'inherit'});console.log('✅ agent-browser installed successfully!');}catch(e){console.log('⚠️ Could not install agent-browser globally. Run manually:\\n npm install -g agent-browser@'+v);}}\"" }, "dependencies": { "agent-browser": "^0.41.0", diff --git a/v3/@claude-flow/browser/tests/postinstall-agent-browser-pin.test.ts b/v3/@claude-flow/browser/tests/postinstall-agent-browser-pin.test.ts new file mode 100644 index 0000000000..73a2f6ec77 --- /dev/null +++ b/v3/@claude-flow/browser/tests/postinstall-agent-browser-pin.test.ts @@ -0,0 +1,21 @@ +import { describe, it, expect } from 'vitest'; +import { readFileSync } from 'node:fs'; +import { fileURLToPath } from 'node:url'; +import { dirname, join } from 'node:path'; + +const pkgPath = join(dirname(fileURLToPath(import.meta.url)), '..', 'package.json'); +const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')); + +describe('postinstall agent-browser install', () => { + const postinstall: string = pkg.scripts.postinstall; + + it('never installs an unpinned agent-browser@latest', () => { + expect(postinstall).not.toMatch(/agent-browser@latest/); + }); + + it('installs the same agent-browser range the package depends on', () => { + expect(pkg.dependencies['agent-browser']).toBeTruthy(); + expect(postinstall).toContain("require('./package.json').dependencies['agent-browser']"); + expect(postinstall).toContain("'npm install -g agent-browser@'+v"); + }); +});