fix(test): increase test timeout for update checks and tune fetch timeout

This commit is contained in:
gitea committed 2026-09-02 15:47:25 +08:00
1 parent 70367cc058
commit 3098c8f5bc
3 files changed
+6 -6

No files matched your search

+1 -1
View File
@@ -1530,7 +1530,7 @@ seal-use corps hose-staffs --json '{
\`\`\`
* 直接使用指定 ID 完成接入并进行连通性验证。
`;var uy={"SKILL.md":zL,"agents/openai.yaml":CL,"references/rule-lightweight.md":RL,"references/approval-bad-cases.md":hL,"references/cli.md":mL,"references/approval-run-lightweight.md":xL,"references/approval-attachment-trace.md":aL,"references/customer-feedback-rule-remediation.md":sL,"references/enterprise-onboarding.md":ny,"references/hose-enterprise-auth.md":iy,"references/hose-enterprise-init.md":ty};function ey(){return uy["SKILL.md"]||""}function zu(){return z4(oy(),".agents","skills","seal-use")}function ly(){return z4(oy(),".agents","skills","seal-home")}function vy(){let n=ly();if(M4(n))try{return WK(n,{recursive:!0,force:!0}),!0}catch{return!1}return!1}function C4(n=zu()){vy(),ry(n,{recursive:!0});let i=[];for(let[r,o]of Object.entries(uy)){let t=z4(n,r);ry(XK(t),{recursive:!0}),JK(t,o,"utf8"),i.push(r)}return{targetDir:n,files:i}}function R4(){let n=ly(),i=zu(),r=M4(n),o=M4(i);if(r||o)return vy(),C4(i),{synced:!0,targetDir:i};return{synced:!1}}function Iy(n,i,r){if(n==="dump"||n==="cat"||n==="show"){process.stdout.write(`${ey()}
`);return}if(n==="install"||n==="init"||n==="sync"){let o=_(r.options.local)||_(r.options.workspace),t=D(r.options.dir)??D(r.options.target)??i,u=t?t:o?w$(process.cwd(),".agents","skills","seal-use"):zu(),e=C4(u);B({installed:!0,targetDir:e.targetDir,fileCount:e.files.length,files:e.files});return}if(n==="status"||n==="get"||!n){let o=zu(),t=w$(process.cwd(),".agents","skills","seal-use");B({global:{dir:o,installed:$y(w$(o,"SKILL.md"))},local:{dir:t,installed:$y(w$(t,"SKILL.md"))}});return}throw Error(`Unknown skill command: ${n}. Run 'seal-use help' for available commands.`)}async function gy(n,i){if(n==="config"){B(await xr(i));return}throw Error(`Unknown source command: ${n??""}. Run 'seal-use help' for available commands.`)}async function by(n,i,r,o){if(!n)throw Error("Usage: seal-use tool <toolName> [--json '{...}']");await X(n,i,r,ri(o.json),J(o.options))}function wy(){B(Vu.map((n)=>({name:n.name,description:n.description})))}import{chmodSync as HK,mkdirSync as YK,renameSync as h4,rmSync as PK,unlinkSync as Sy,writeFileSync as fy}from"node:fs";import{dirname as pK,join as cy}from"node:path";import{spawnSync as Zt}from"node:child_process";function f$(n=process.execPath,i=import.meta.url){if(i.includes("/$bunfs/")||i.includes("\\$bunfs\\"))return!0;let r=n.toLowerCase().replace(/\\/g,"/");return!r.endsWith("/bun")&&!r.endsWith("/bun.exe")&&!r.endsWith("/node")&&!r.endsWith("/node.exe")}var Ay="yunyingk/seal-home",sr="yunyingk/seal-home";var QK="SEAL_USE_GITHUB_REPO",FK="SEAL_HOME_GITHUB_REPO";async function Oy(n,i={}){let r={appRoot:n.appRoot,entryFile:n.entryFile,stateDir:Z4,version:m,launcher:n.launcher},o=i.repo||process.env[QK]?.trim()||process.env[FK]?.trim()||Ay,t=i.targetVersion?.trim(),u=t&&t.toLowerCase()!=="latest"?t:void 0;if(u){let G=u.replace(/^v/,""),N=ky(G,m);if(N<0){B({updated:!1,currentVersion:m,targetVersion:G,mode:f$()?"binary":"source",message:`Cannot downgrade seal-use from v${m} to older version v${G}. Updates must be forward-only.`});return}if(N===0&&!i.force){B({updated:!1,currentVersion:m,targetVersion:G,mode:f$()?"binary":"source",message:`seal-use is already at version v${m}. Use --force to reinstall.`});return}}if(i.changelogOnly){let G=await m4(o,i.limit??10);B({currentVersion:m,totalQueried:G.length,releases:G.map((N)=>({version:N.version,tagName:N.tagName,publishedAt:N.publishedAt,author:N.author,releaseNotes:N.notes,releaseUrl:N.htmlUrl,isCurrent:N.version===m,isNewer:Cu(N.version,m)}))});return}if(!f$()){if(i.checkOnly){let N=await m4(o,30),E=N[0],x=E?.version??m,yn=N.find((un)=>un.version===m),Wn=Cu(x,m),On=N.filter((un)=>Cu(un.version,m));B({updated:!1,updateAvailable:Wn,currentVersion:m,currentVersionPublishedAt:yn?.publishedAt,latestVersion:x,latestVersionPublishedAt:E?.publishedAt,behindCount:On.length,pendingReleases:On.map((un)=>({version:un.version,tagName:un.tagName,publishedAt:un.publishedAt,author:un.author,releaseNotes:un.notes,releaseUrl:un.htmlUrl})),releaseNotes:E?.notes??"",releaseUrl:E?.htmlUrl??"",mode:"source",message:"Running in source development mode. Run 'seal-use update' to git pull & bun install."});return}let G=ar(r).running;if(G)await _t("stop",r);try{Dy("git",["-C",n.appRoot,"pull","--ff-only"])}catch(N){console.error(`git pull skipped: ${N instanceof Error?N.message:String(N)}`)}if(Dy("bun",["install"],{cwd:n.appRoot}),G)await _t("start",r);B({updated:!0,serviceRestarted:G,version:m,mode:"source"});return}let e=KK(),l=BK(),$=await m4(o,30),I=u?$.find((G)=>G.version===u||G.tagName===u||G.tagName===`v${u}`)??await Uy(o,u):$[0]??await Uy(o);if(!I){B({updated:!1,currentVersion:m,mode:"binary",message:`Failed to query releases from repository '${o}'`});return}let g=I.version,b=$.find((G)=>G.version===m),w=Cu(g,m),f=w||Boolean(i.force),c=$.filter((G)=>Cu(G.version,m));if(i.checkOnly){B({updated:!1,updateAvailable:w,currentVersion:m,currentVersionPublishedAt:b?.publishedAt,latestVersion:g,latestVersionPublishedAt:I.publishedAt,behindCount:c.length,pendingReleases:c.map((G)=>({version:G.version,tagName:G.tagName,publishedAt:G.publishedAt,author:G.author,releaseNotes:G.notes,releaseUrl:G.htmlUrl})),releaseNotes:I.notes,releaseUrl:I.htmlUrl,mode:"binary"});return}if(!f){B({updated:!1,currentVersion:m,currentVersionPublishedAt:b?.publishedAt,latestVersion:g,latestVersionPublishedAt:I.publishedAt,mode:"binary",message:`seal-use is already up to date (v${m})`});return}let S=TK(I.assets,e,l);if(!S)throw Error(`No compatible binary found for ${e}-${l} in release v${g}. Available assets: ${I.assets.map((G)=>G.name).join(", ")}`);let k=ar(r).running;if(k)await _t("stop",r);let d=process.execPath,Q=pK(d),Y=cy(Q,`.tmp-update-${Date.now()}`);YK(Y,{recursive:!0});try{let G=cy(Y,S.name);await VK(S.downloadUrl,G,I.tagName,S.name);let N=G;if(S.name.endsWith(".tar.gz")||S.name.endsWith(".tgz"))N=qK(G,Y,e);else if(S.name.endsWith(".zip"))N=EK(G,Y,e);if(HK(N,493),process.platform==="darwin")try{Zt("/usr/bin/codesign",["--remove-signature",N],{stdio:"ignore"}),Zt("/usr Line truncated
`);return}if(n==="install"||n==="init"||n==="sync"){let o=_(r.options.local)||_(r.options.workspace),t=D(r.options.dir)??D(r.options.target)??i,u=t?t:o?w$(process.cwd(),".agents","skills","seal-use"):zu(),e=C4(u);B({installed:!0,targetDir:e.targetDir,fileCount:e.files.length,files:e.files});return}if(n==="status"||n==="get"||!n){let o=zu(),t=w$(process.cwd(),".agents","skills","seal-use");B({global:{dir:o,installed:$y(w$(o,"SKILL.md"))},local:{dir:t,installed:$y(w$(t,"SKILL.md"))}});return}throw Error(`Unknown skill command: ${n}. Run 'seal-use help' for available commands.`)}async function gy(n,i){if(n==="config"){B(await xr(i));return}throw Error(`Unknown source command: ${n??""}. Run 'seal-use help' for available commands.`)}async function by(n,i,r,o){if(!n)throw Error("Usage: seal-use tool <toolName> [--json '{...}']");await X(n,i,r,ri(o.json),J(o.options))}function wy(){B(Vu.map((n)=>({name:n.name,description:n.description})))}import{chmodSync as HK,mkdirSync as YK,renameSync as h4,rmSync as PK,unlinkSync as Sy,writeFileSync as fy}from"node:fs";import{dirname as pK,join as cy}from"node:path";import{spawnSync as Zt}from"node:child_process";function f$(n=process.execPath,i=import.meta.url){if(i.includes("/$bunfs/")||i.includes("\\$bunfs\\"))return!0;let r=n.toLowerCase().replace(/\\/g,"/");return!r.endsWith("/bun")&&!r.endsWith("/bun.exe")&&!r.endsWith("/node")&&!r.endsWith("/node.exe")}var Ay="yunyingk/seal-home",sr="yunyingk/seal-home";var QK="SEAL_USE_GITHUB_REPO",FK="SEAL_HOME_GITHUB_REPO";async function Oy(n,i={}){let r={appRoot:n.appRoot,entryFile:n.entryFile,stateDir:Z4,version:m,launcher:n.launcher},o=i.repo||process.env[QK]?.trim()||process.env[FK]?.trim()||Ay,t=i.targetVersion?.trim(),u=t&&t.toLowerCase()!=="latest"?t:void 0;if(u){let G=u.replace(/^v/,""),N=ky(G,m);if(N<0){B({updated:!1,currentVersion:m,targetVersion:G,mode:f$()?"binary":"source",message:`Cannot downgrade seal-use from v${m} to older version v${G}. Updates must be forward-only.`});return}if(N===0&&!i.force){B({updated:!1,currentVersion:m,targetVersion:G,mode:f$()?"binary":"source",message:`seal-use is already at version v${m}. Use --force to reinstall.`});return}}if(i.changelogOnly){let G=await m4(o,i.limit??10);B({currentVersion:m,totalQueried:G.length,releases:G.map((N)=>({version:N.version,tagName:N.tagName,publishedAt:N.publishedAt,author:N.author,releaseNotes:N.notes,releaseUrl:N.htmlUrl,isCurrent:N.version===m,isNewer:Cu(N.version,m)}))});return}if(!f$()){if(i.checkOnly){let N=await m4(o,30),E=N[0],x=E?.version??m,yn=N.find((un)=>un.version===m),Wn=Cu(x,m),On=N.filter((un)=>Cu(un.version,m));B({updated:!1,updateAvailable:Wn,currentVersion:m,currentVersionPublishedAt:yn?.publishedAt,latestVersion:x,latestVersionPublishedAt:E?.publishedAt,behindCount:On.length,pendingReleases:On.map((un)=>({version:un.version,tagName:un.tagName,publishedAt:un.publishedAt,author:un.author,releaseNotes:un.notes,releaseUrl:un.htmlUrl})),releaseNotes:E?.notes??"",releaseUrl:E?.htmlUrl??"",mode:"source",message:"Running in source development mode. Run 'seal-use update' to git pull & bun install."});return}let G=ar(r).running;if(G)await _t("stop",r);try{Dy("git",["-C",n.appRoot,"pull","--ff-only"])}catch(N){console.error(`git pull skipped: ${N instanceof Error?N.message:String(N)}`)}if(Dy("bun",["install"],{cwd:n.appRoot}),G)await _t("start",r);B({updated:!0,serviceRestarted:G,version:m,mode:"source"});return}let e=KK(),l=BK(),$=await m4(o,30),I=u?$.find((G)=>G.version===u||G.tagName===u||G.tagName===`v${u}`)??await Uy(o,u):$[0]??await Uy(o);if(!I){B({updated:!1,currentVersion:m,mode:"binary",message:`Failed to query releases from repository '${o}'`});return}let g=I.version,b=$.find((G)=>G.version===m),w=Cu(g,m),f=w||Boolean(i.force),c=$.filter((G)=>Cu(G.version,m));if(i.checkOnly){B({updated:!1,updateAvailable:w,currentVersion:m,currentVersionPublishedAt:b?.publishedAt,latestVersion:g,latestVersionPublishedAt:I.publishedAt,behindCount:c.length,pendingReleases:c.map((G)=>({version:G.version,tagName:G.tagName,publishedAt:G.publishedAt,author:G.author,releaseNotes:G.notes,releaseUrl:G.htmlUrl})),releaseNotes:I.notes,releaseUrl:I.htmlUrl,mode:"binary"});return}if(!f){B({updated:!1,currentVersion:m,currentVersionPublishedAt:b?.publishedAt,latestVersion:g,latestVersionPublishedAt:I.publishedAt,mode:"binary",message:`seal-use is already up to date (v${m})`});return}let S=TK(I.assets,e,l);if(!S)throw Error(`No compatible binary found for ${e}-${l} in release v${g}. Available assets: ${I.assets.map((G)=>G.name).join(", ")}`);let k=ar(r).running;if(k)await _t("stop",r);let d=process.execPath,Q=pK(d),Y=cy(Q,`.tmp-update-${Date.now()}`);YK(Y,{recursive:!0});try{let G=cy(Y,S.name);await VK(S.downloadUrl,G,I.tagName,S.name);let N=G;if(S.name.endsWith(".tar.gz")||S.name.endsWith(".tgz"))N=qK(G,Y,e);else if(S.name.endsWith(".zip"))N=EK(G,Y,e);if(HK(N,493),process.platform==="darwin")try{Zt("/usr/bin/codesign",["--remove-signature",N],{stdio:"ignore"}),Zt("/usr Line truncated
`)}catch{}}async function VK(n,i,r,o){let t=[],u=r?r.startsWith("v")?r:`v${r}`:void 0,e=o||n.split("/").pop()||"";if(u&&e)t.push(`https://git.ying-qing.cn/gitea/seal-home/releases/download/${u}/${e}`);if(n.startsWith("https://git.ying-qing.cn"))t.push(n);if(u&&e){let c=`https://github.com/${Ay}/releases/download/${u}/${e}`;t.push(`https://ghfast.top/${c}`),t.push(`https://gh.ddlc.top/${c}`),t.push(c)}else if(n.includes("github.com"))t.push(`https://ghfast.top/${n}`),t.push(`https://gh.ddlc.top/${n}`),t.push(n);else t.push(n);let l=Array.from(new Set(t)),$,I=6000,g=6000,b=307200,w=1e4,f=180000;for(let c=0;c<l.length;c++){let S=l[c],k=new AbortController,d="",Q=(E)=>{d=E;try{k.abort()}catch{}},Y=setTimeout(()=>{Q("Connection timed out (no response headers within 6s)")},I),G,N;try{c$(`==> [${c+1}/${l.length}] Downloading via: ${S}`);let E=await fetch(S,{signal:k.signal});if(Y)clearTimeout(Y),Y=void 0;if(!E.ok)throw Error(`HTTP ${E.status} ${E.statusText}`);G=setTimeout(()=>{Q("Overall download time exceeded 3 minutes")},f);let x=Number(E.headers.get("content-length"))||0,yn=E.body?.getReader();if(!yn){let wi=Buffer.from(await E.arrayBuffer());if(wi.length<1000)throw Error(`Downloaded content is suspiciously small (${wi.length} bytes)`);fy(i,wi),c$(`✓ Download succeeded (${(wi.length/1024/1024).toFixed(1)} MB)`);return}let Wn=[],On=0,un=0;N=setTimeout(()=>{if(On<b){let wi=(On/1024).toFixed(1);Q(`Initial transfer too slow (${wi} KB < 300 KB in 6s), switching mirror...`)}},g);while(!0){let wi=yn.read(),no,Wy=new Promise((D$,S$)=>{no=setTimeout(()=>{S$(Error("Data transfer stalled (no chunk received for 10s)"))},w)}),s4;try{s4=await Promise.race([wi,Wy])}finally{if(no)clearTimeout(no)}let{done:Jy,value:U$}=s4;if(Jy)break;if(U$){if(Wn.push(U$),On+=U$.length,N&&On>=b)clearTimeout(N),N=void 0;let D$=Date.now();if(D$-un>200){un=D$;let S$=x?Math.round(On/x*100):0,Xy=(On/1048576).toFixed(1),Hy=x?(x/1048576).toFixed(1):"?";try{process.stderr.write(`\r ↳ Progress: ${S$}% (${Xy} / ${Hy} MB)...`)}catch{}}}}try{process.stderr.write(`
`)}catch{}let Ot=Buffer.concat(Wn);if(Ot.length<1000)throw Error(`Downloaded content is suspiciously small (${Ot.length} bytes)`);fy(i,Ot),c$(`✓ Download completed successfully (${(Ot.length/1024/1024).toFixed(1)} MB)`);return}catch(E){if(Y)clearTimeout(Y);if(N)clearTimeout(N);if(G)clearTimeout(G);let x=d||(E instanceof Error?E.message:String(E));$=Error(x),c$(`
↳ Mirror failed: ${$.message}`)}finally{if(Y)clearTimeout(Y);if(N)clearTimeout(N);if(G)clearTimeout(G)}}throw Error(`Failed to download asset from all mirrors: ${$?.message}`)}function qK(n,i,r){let o=Zt("tar",["-xzf",n,"-C",i],{stdio:"pipe"});if(o.status!==0)throw Error(`Failed to extract tar archive: ${o.stderr.toString()}`);Sy(n);let t=r==="windows"?"seal-use.exe":"seal-use",u=Zt("find",[i,"-type","f"],{encoding:"utf8"}).stdout.trim().split(`
+3 -3
View File
@@ -178,7 +178,7 @@ describe("CLI version & help handling", () => {
expect(parsed).toHaveProperty("behindCount");
expect(parsed).toHaveProperty("pendingReleases");
expect(Array.isArray(parsed.pendingReleases)).toBe(true);
});
}, 20000);
test("changelog command outputs release history list", () => {
const result = runCli(["changelog", "--limit", "5"]);
@@ -186,7 +186,7 @@ describe("CLI version & help handling", () => {
const parsed = JSON.parse(result.stdout.trim());
expect(parsed.currentVersion).toBe(VERSION);
expect(Array.isArray(parsed.releases)).toBe(true);
});
}, 20000);
test("rejects downgrade to older version when target version is lower", () => {
const result = runCli(["update", "0.3.3"]);
@@ -204,7 +204,7 @@ describe("CLI version & help handling", () => {
const parsed = JSON.parse(result.stdout.trim());
expect(parsed).toHaveProperty("latestVersion");
expect(parsed.updated).toBe(false);
});
}, 20000);
});
function makeConfigEnv(): Record<string, string> {
+2 -2
View File
@@ -326,7 +326,7 @@ async function fetchGitHubReleases(repo: string, limit = 20): Promise<GitHubRele
for (const url of urls) {
try {
const res = await fetch(url, { headers, signal: AbortSignal.timeout(5000) });
const res = await fetch(url, { headers, signal: AbortSignal.timeout(3000) });
if (!res.ok) continue;
const json = (await res.json()) as Array<{
tag_name?: string;
@@ -397,7 +397,7 @@ async function fetchGitHubRelease(repo: string, targetVersion?: string): Promise
for (const url of urls) {
try {
const res = await fetch(url, { headers, signal: AbortSignal.timeout(5000) });
const res = await fetch(url, { headers, signal: AbortSignal.timeout(3000) });
if (!res.ok) continue;
const json = (await res.json()) as {
tag_name?: string;