Brings together #191 (CN managed gateway), #196 (request shaping and identity lines) and the #183 sign-in fix. - autoclaw-cn chat goes to AutoClaw 2.1.0's managed gateway (autoglm-acceleration-api.zhipuai.cn/autoclaw-proxy/proxy/autoclaw/chat/completions, on Zhipu's domain) with 2.1.0's headers and its four-model catalog. A 401/403 there marks the sign-in expired. - Both providers get the same request shaping: - the official one-sentence system prefix, merged into the caller's system message (string or array); - max_tokens and max_completion_tokens dropped; - other agents' identity lines in system/developer messages rewritten (FLAGGED/unflag, from #196); - no X-Harness-Type. - On the overseas path, a 406 explains itself and keeps the sign-in. Overseas chat now sends AutoClaw's own User-Agent instead of the host's. Its catalog drops zai_glm-5-turbo and the tdpsk models (400 upstream) and keeps the old limits. - Overseas OAuth: authorize returns the loopback guide URL once the listener is up, and the host opens it, so there is no shell spawn any more. Navigating to the authorization page no longer aborts the session. - autoclaw 0.2.0 -> 0.2.1. What was run at 1fe91be (reviewer): - bun test packages/autoclaw: 21 pass, 0 fail. bun scripts/check.mjs autoclaw: ok. git diff --check: clean. Merges cleanly onto main. - magpie plugin host (magpie main cb05dc2d1), sandbox HOME, with a copy whose three hosts point at a local fake: - overseas: authorize gave http://127.0.0.1:18432/, the guide returned 200, and /open-auth plus /auth/callback-google finished the sign-in; - CN: SMS sign-in worked; - streamed chat on both providers returned 200; - the fake received the prefix with "You are Claude Code" rewritten and no max_tokens on both paths; User-Agent AutoClaw/2.1.0 on CN and AutoClaw/1.18.1 overseas; no X-Harness-Type. - Not tried: real accounts or the live gateways (no credentials used). Co-authored-by: HuHong_Tao <3596843010@qq.com>
24 lines
1.6 KiB
JavaScript
24 lines
1.6 KiB
JavaScript
import { test, expect } from 'bun:test';
|
|
import vm from 'node:vm';
|
|
import { _internal } from './index.mjs';
|
|
function guide(fail=false){
|
|
const html=_internal.guidePageHtml('google');
|
|
const start=html.indexOf('let leavingForAuthorization');
|
|
const at=html.indexOf('document.getElementById("goBtn").addEventListener');
|
|
const script=html.slice(start>=0?start:at,html.indexOf('boot().catch'));
|
|
const listeners={},elements=new Map(),sent=[];
|
|
const ctx={Blob,document:{getElementById(id){if(!elements.has(id))elements.set(id,{style:{},addEventListener(type,fn){listeners[id+':'+type]=fn}});return elements.get(id)}},window:{addEventListener(type,fn){listeners[type]=fn}},navigator:{sendBeacon(url){sent.push(url)}},fetch:async()=>{if(fail)throw Error('connection refused');return{json:async()=>({url:'https://accounts.google.test/authorize'})}},msg(){},setTimeout(fn){fn()},location:{}};
|
|
Object.defineProperty(ctx.location,'href',{set(){listeners.beforeunload?.()}});
|
|
vm.runInNewContext(script,ctx);
|
|
return{sent,listeners,elements};
|
|
}
|
|
test('leaving the guide for authorization must not abort the localhost callback',async()=>{
|
|
const x=guide();await x.listeners['goBtn:click']();expect(x.sent).toEqual([]);
|
|
});
|
|
test('closing a guide before authorization still cancels its own session',()=>{
|
|
const x=guide();x.listeners.beforeunload();expect(x.sent).toEqual(['/abort']);
|
|
});
|
|
test('an expired or disconnected guide restores its action instead of navigating',async()=>{
|
|
const x=guide(true);await x.listeners['goBtn:click']();expect(x.elements.get('goBtn').disabled).toBe(false);expect(x.sent).toEqual([]);
|
|
});
|