From 5fcffbc67896506ac934d6288a861308452f6b96 Mon Sep 17 00:00:00 2001 From: "r4yharris-agent-coder[bot]" <334673250+r4yharris-agent-coder[bot]@users.noreply.github.com> Date: Thu, 3 Dec 2026 20:51:53 -0500 Subject: [PATCH] fix(runtime): skip non-rustfmt consumer repo untouched diffs, add AVA shim, and pass ROSTER_NODE_MODULES in node_checks (FEATURE_SPEC 5.4, 5.9) AI-Agent: r4yharris-agent-coder AI-Model: GPT-6.1-Sol AI-Run: 1|github-copilot|GPT-6.1-Sol@-|x|-/1000000|-|ghcp-20261203-round15|round-15-polyglot-rca --- rust/execution/tools.rs | 103 ++++++++++++++++++++++++++++++++++------ rust/seats/tests.rs | 9 ++++ 2 files changed, 97 insertions(+), 15 deletions(-) diff --git a/rust/execution/tools.rs b/rust/execution/tools.rs index 6ab314c..04e20f3 100644 --- a/rust/execution/tools.rs +++ b/rust/execution/tools.rs @@ -152,7 +152,7 @@ pub(crate) fn find_modern_node(fallback: &Path) -> PathBuf { fallback.to_path_buf() } -pub(crate) const TS_IMPORT_HOOK: &str = r#"data:text/javascript,import{registerHooks}from"node:module";import*as T from"node:test";import*as A from"node:assert/strict";import{inspect}from"node:util";import*as F from"node:fs";import*as P from"node:path";import{fileURLToPath,pathToFileURL}from"node:url";const S=Symbol("m");const mk=f=>({[S]:f});const eq=(a,b,st)=>{if(b&&typeof b==="object"&&typeof b[S]==="function")return b[S](a);if(Object.is(a,b))return true;if(!a||!b||typeof a!=="object"||typeof b!=="object")return false;if(a instanceof RegExp&&b instanceof RegExp)return a.source===b.source&&a.flags===b.flags;if(a instanceof Date&&b instanceof Date)return Object.is(a.getTime(),b.getTime());if(Array.isArray(a)!==Array.isArray(b))return false;if(Array.isArray(a))return a.length===b.length&&a.every((v,i)=>eq(v,b[i],st));if(st&&Object.getPrototypeOf(a)!==Object.getPrototypeOf(b))return false;const ka=Object.keys(a),kb=Object.keys(b);const ea=st?ka:ka.filter(k=>a[k]!==undefined),eb=st?kb:kb.filter(k=>b[k]!==undefined);if(ea.length!==eb.length)return false;return eb.every(k=>Object.prototype.hasOwnProperty.call(a,k)&&eq(a[k],b[k],st));};const cmp=(a,b,st,neg)=>{const ok=eq(a,b,st);if(neg?ok:!ok)A.fail(`Expected ${inspect(a,{depth:6})} ${neg?"not ":""}to equal ${inspect(b,{depth:6})}`);};const mo=(a,b)=>{if(Object.is(a,b))return true;if(!a||!b||typeof a!=="object"||typeof b!=="object")return false;if(Array.isArray(b))return Array.isArray(a)&&a.length===b.length&&b.every((v,i)=>mo(a[i],v));return Object.keys(b).every(k=>k in a&&mo(a[k],b[k]));};const m=(a,neg)=>({toBe:b=>neg?A.notStrictEqual(a,b):A.strictEqual(a,b),toEqual:b=>cmp(a,b,false,neg),toStrictEqual:b=>cmp(a,b,true,neg),toMatchObject:b=>{const ok=mo(a,b);if(neg?ok:!ok)A.fail(`Expected ${inspect(a,{depth:6})} ${neg?"not ":""}to match object ${inspect(b,{depth:6})}`);},toBeUndefined:()=>neg?A.notStrictEqual(a,undefined):A.strictEqual(a,undefined),toBeNull:()=>neg?A.notStrictEqual(a,null):A.strictEqual(a,null),toBeTruthy:()=>A.ok(neg?!a:Boolean(a)),toBeFalsy:()=>A.ok(neg?Boolean(a):!a),toBeNaN:()=>A.ok(neg?!Number.isNaN(a):Number.isNaN(a)),toBeGreaterThan:b=>A.ok(neg?!(a>b):a>b),toBeGreaterThanOrEqual:b=>A.ok(neg?!(a>=b):a>=b),toBeLessThan:b=>A.ok(neg?!(aA.ok(neg?!(a<=b):a<=b),toBeCloseTo:(b,p=2)=>{const ok=Math.abs(a-b)A.ok(neg?!(a instanceof c):a instanceof c),toContain:b=>{const ok=typeof a==="string"?a.includes(b):Array.isArray(a)&&a.includes(b);A.ok(neg?!ok:ok);},toContainEqual:b=>{const ok=Array.isArray(a)&&a.some(x=>eq(x,b,false));A.ok(neg?!ok:ok);},toHaveLength:b=>neg?A.notStrictEqual(a.length,b):A.strictEqual(a.length,b),toMatch:b=>{const ok=b instanceof RegExp?b.test(String(a)):String(a).includes(String(b));A.ok(neg?!ok:ok);},toHaveProperty:(k,v)=>{const parts=Array.isArray(k)?k:String(k).split(".");let cur=a,has=true;for(const p of parts){if(cur!=null&&Object.prototype.hasOwnProperty.call(Object(cur),p))cur=cur[p];else{has=false;break;}}const ok=arguments.length>1?has&&eq(cur,v,false):has;A.ok(neg?!ok:ok);},toThrow:b=>neg?A.doesNotThrow(a,b):A.throws(a,b)});const expect=Object.assign(a=>Object.assign(m(a,false),{not:m(a,true)}),{any:c=>mk(v=>c===String?typeof v==="string"||v instanceof String:c===Number?typeof v==="number"||v instanceof Number:c===Boolean?typeof v==="boolean"||v instanceof Boolean:c===Function?typeof v==="function":c===Object?v!==null&&typeof v==="object":c===Symbol?typeof v==="symbol":c===BigInt?typeof v==="bigint":v instanceof c),anything:()=>mk(v=>v!==null&&v!==undefined),objectContaining:o=>mk(v=>v!==null&&typeof v==="object"&&Object.keys(o).every(k=>k in v&&eq(v[k],o[k],false))),arrayContaining:arr=>mk(v=>Array.isArray(v)&&arr.every(x=>v.some(y=>eq(y,x,false)))),stringContaining:s=>mk(v=>typeof v==="string"&&v.includes(s))});const RealDate=Date;let fakeNow=null;class FakeDate extends RealDate{constructor(...xs){if(xs.length===0&&fakeNow!==null)super(fakeNow);else super(...xs);}static now(){return fakeNow!==null?fakeNow:RealDate.now();}}const vi={fn:(impl)=>{function f(...xs){f.mock.calls.push(xs);f.mock.contexts.push(this);const r=impl?impl.apply(this,xs):undefined;f.mock.results.push({type:"return",value:r});return r;}f.mock={calls:[],contexts:[],results:[]};return f;},useFakeTimers:()=>{globalThis.Date=FakeDate;return vi;},useRealTimers:()=>{fakeNow=null;globalThis.Date=RealDate;return vi;},setSystemTime:d=>{fakeNow=d instanceof RealDate?d.getTime():typeof d==="number"?d:new RealDate(d).getTime();globalThis.Date=FakeDate;return vi;},clearAllMocks:()=>vi,restoreAllMocks:()=>{fakeNow=null;globalThis.Date=RealDate;return vi;}};const mkEach=fn=>rows=>(name,cb)=>{for(let i=0;iString(args[j++]??""));fn(label,()=>cb(...args));}};const testFn=Object.assign((...xs)=>T.test(...xs),{each:mkEach(T.test),skip:T.test.skip,only:T.test.only});const itFn=Object.assign((...xs)=>T.it(...xs),{each:mkEach(T.it),skip:T.it.skip,only:T.it.only});const descFn=Object.assign((...xs)=>T.describe(...xs),{each:mkEach(T.describe),skip:T.describe.skip,only:T.describe.only});const api={describe:descFn,it:itFn,test:testFn,beforeEach:T.beforeEach,afterEach:T.afterEach,beforeAll:T.before,afterAll:T.after,expect,vi};globalThis.__rosterTestApi=api;if(!globalThis.describe)Object.assign(globalThis,api);let wsMap=null;const regPkg=(map,dir)=>{const pj=P.join(dir,"package.json");if(F.existsSync(pj)){try{const pkg=JSON.parse(F.readFileSync(pj,"utf8"));if(pkg&&typeof pkg.name==="string"&&!map.has(pkg.name))map.set(pkg.name,{dir,pkg});}catch{}}};const loadWs=start=>{if(wsMap)return wsMap;wsMap=new Map();let d=start;for(let i=0;i<10;i++){regPkg(wsMap,d);for(const sub of["pkgs","packages","libs"]){const base=P.join(d,sub);if(F.existsSync(base)&&F.statSync(base).isDirectory()){for(const ent of F.readdirSync(base))regPkg(wsMap,P.join(base,ent));}}const up=P.dirname(d);if(up===d)break;d=up;}return wsMap;};const pickExp=v=>typeof v==="string"?v:(v&&typeof v==="object"?pickExp(v.import||v.default||v.module||v.types):null);registerHooks({resolve(s,c,n){try{return n(s,c);}catch(e){if(s==="vitest"||s==="@jest/globals")return{shortCircuit:true,url:"data:text/javascript,export const{describe,it,test,beforeEach,afterEach,beforeAll,afterAll,expect,vi}=globalThis.__rosterTestApi;"};if(c.parentURL&&c.parentURL.startsWith("file:")){const xs=s.endsWith(".js")?[s.slice(0,-3)+".ts"]:(s.startsWith(".")&&!/\.[cm]?[jt]s$/.test(s)?[s+".ts",s+"/index.ts"]:[]);for(const x of xs){try{return n(x,c);}catch{}}const bm=s.match(/^(.*\/)(?:lib|dist|build)\/([^/]+?)(?:\.(?:esm|cjs|mjs|umd|min))?\.[cm]?js$/);if(bm){const bd=P.resolve(P.dirname(fileURLToPath(c.parentURL)),bm[1]);for(const f of[P.join(bd,"src",bm[2]+".ts"),P.join(bd,"src",bm[2]+".mts"),P.join(bd,"src","index.ts"),P.join(bd,"src","index.mts")]){if(F.existsSync(f))return{shortCircuit:true,url:pathToFileURL(f).href};}}if(!s.startsWith(".")&&!s.startsWith("/")&&!s.startsWith("node:")){const map=loadWs(P.dirname(fileURLToPath(c.parentURL)));for(const[name,info]of map){if(s===name||s.startsWith(name+"/")){const sub=s===name?".":"."+s.slice(name.length);let target=info.pkg.exports&&typeof info.pkg.exports==="object"?pickExp(info.pkg.exports[sub]):null;if(!target&&sub===".")target=info.pkg.module||info.pkg.main||"./src/index.ts";if(target){const full=P.resolve(info.dir,target);const rel=target.replace(/^\.\//,"");const stripped=rel.replace(/^(?:dist|lib|build)\//,"");const srcFull=P.resolve(info.dir,"src",rel);const srcStripped=P.resolve(info.dir,"src",stripped);const cands=full.endsWith(".js")?[srcStripped.slice(0,-3)+".ts",full.slice(0,-3)+".ts",srcFull.slice(0,-3)+".ts",full]:[srcStripped,srcStripped+".ts",P.join(srcStripped,"index.ts"),full,full+".ts",P.join(full,"index.ts"),srcFull,srcFull+".ts",P.join(srcFull,"index.ts")];for(const f of cands){if(F.existsSync(f))return{shortCircuit:true,url:pathToFileURL(f).href};}}}}const nm=process.env.ROSTER_NODE_MODULES;if(nm){try{return n(s,{...c,parentURL:pathToFileURL(P.join(nm,"_")).href});}catch{}}}}throw e;}}});"#; +pub(crate) const TS_IMPORT_HOOK: &str = r#"data:text/javascript,import{registerHooks}from"node:module";import*as T from"node:test";import*as A from"node:assert/strict";import{inspect}from"node:util";import*as F from"node:fs";import*as P from"node:path";import{fileURLToPath,pathToFileURL}from"node:url";const S=Symbol("m");const mk=f=>({[S]:f});const eq=(a,b,st)=>{if(b&&typeof b==="object"&&typeof b[S]==="function")return b[S](a);if(Object.is(a,b))return true;if(!a||!b||typeof a!=="object"||typeof b!=="object")return false;if(a instanceof RegExp&&b instanceof RegExp)return a.source===b.source&&a.flags===b.flags;if(a instanceof Date&&b instanceof Date)return Object.is(a.getTime(),b.getTime());if(Array.isArray(a)!==Array.isArray(b))return false;if(Array.isArray(a))return a.length===b.length&&a.every((v,i)=>eq(v,b[i],st));if(st&&Object.getPrototypeOf(a)!==Object.getPrototypeOf(b))return false;const ka=Object.keys(a),kb=Object.keys(b);const ea=st?ka:ka.filter(k=>a[k]!==undefined),eb=st?kb:kb.filter(k=>b[k]!==undefined);if(ea.length!==eb.length)return false;return eb.every(k=>Object.prototype.hasOwnProperty.call(a,k)&&eq(a[k],b[k],st));};const cmp=(a,b,st,neg)=>{const ok=eq(a,b,st);if(neg?ok:!ok)A.fail(`Expected ${inspect(a,{depth:6})} ${neg?"not ":""}to equal ${inspect(b,{depth:6})}`);};const mo=(a,b)=>{if(Object.is(a,b))return true;if(!a||!b||typeof a!=="object"||typeof b!=="object")return false;if(Array.isArray(b))return Array.isArray(a)&&a.length===b.length&&b.every((v,i)=>mo(a[i],v));return Object.keys(b).every(k=>k in a&&mo(a[k],b[k]));};const m=(a,neg)=>({toBe:b=>neg?A.notStrictEqual(a,b):A.strictEqual(a,b),toEqual:b=>cmp(a,b,false,neg),toStrictEqual:b=>cmp(a,b,true,neg),toMatchObject:b=>{const ok=mo(a,b);if(neg?ok:!ok)A.fail(`Expected ${inspect(a,{depth:6})} ${neg?"not ":""}to match object ${inspect(b,{depth:6})}`);},toBeUndefined:()=>neg?A.notStrictEqual(a,undefined):A.strictEqual(a,undefined),toBeNull:()=>neg?A.notStrictEqual(a,null):A.strictEqual(a,null),toBeTruthy:()=>A.ok(neg?!a:Boolean(a)),toBeFalsy:()=>A.ok(neg?Boolean(a):!a),toBeNaN:()=>A.ok(neg?!Number.isNaN(a):Number.isNaN(a)),toBeGreaterThan:b=>A.ok(neg?!(a>b):a>b),toBeGreaterThanOrEqual:b=>A.ok(neg?!(a>=b):a>=b),toBeLessThan:b=>A.ok(neg?!(aA.ok(neg?!(a<=b):a<=b),toBeCloseTo:(b,p=2)=>{const ok=Math.abs(a-b)A.ok(neg?!(a instanceof c):a instanceof c),toContain:b=>{const ok=typeof a==="string"?a.includes(b):Array.isArray(a)&&a.includes(b);A.ok(neg?!ok:ok);},toContainEqual:b=>{const ok=Array.isArray(a)&&a.some(x=>eq(x,b,false));A.ok(neg?!ok:ok);},toHaveLength:b=>neg?A.notStrictEqual(a.length,b):A.strictEqual(a.length,b),toMatch:b=>{const ok=b instanceof RegExp?b.test(String(a)):String(a).includes(String(b));A.ok(neg?!ok:ok);},toHaveProperty:(k,v)=>{const parts=Array.isArray(k)?k:String(k).split(".");let cur=a,has=true;for(const p of parts){if(cur!=null&&Object.prototype.hasOwnProperty.call(Object(cur),p))cur=cur[p];else{has=false;break;}}const ok=arguments.length>1?has&&eq(cur,v,false):has;A.ok(neg?!ok:ok);},toThrow:b=>neg?A.doesNotThrow(a,b):A.throws(a,b)});const expect=Object.assign(a=>Object.assign(m(a,false),{not:m(a,true)}),{any:c=>mk(v=>c===String?typeof v==="string"||v instanceof String:c===Number?typeof v==="number"||v instanceof Number:c===Boolean?typeof v==="boolean"||v instanceof Boolean:c===Function?typeof v==="function":c===Object?v!==null&&typeof v==="object":c===Symbol?typeof v==="symbol":c===BigInt?typeof v==="bigint":v instanceof c),anything:()=>mk(v=>v!==null&&v!==undefined),objectContaining:o=>mk(v=>v!==null&&typeof v==="object"&&Object.keys(o).every(k=>k in v&&eq(v[k],o[k],false))),arrayContaining:arr=>mk(v=>Array.isArray(v)&&arr.every(x=>v.some(y=>eq(y,x,false)))),stringContaining:s=>mk(v=>typeof v==="string"&&v.includes(s))});const RealDate=Date;let fakeNow=null;class FakeDate extends RealDate{constructor(...xs){if(xs.length===0&&fakeNow!==null)super(fakeNow);else super(...xs);}static now(){return fakeNow!==null?fakeNow:RealDate.now();}}const vi={fn:(impl)=>{function f(...xs){f.mock.calls.push(xs);f.mock.contexts.push(this);const r=impl?impl.apply(this,xs):undefined;f.mock.results.push({type:"return",value:r});return r;}f.mock={calls:[],contexts:[],results:[]};return f;},useFakeTimers:()=>{globalThis.Date=FakeDate;return vi;},useRealTimers:()=>{fakeNow=null;globalThis.Date=RealDate;return vi;},setSystemTime:d=>{fakeNow=d instanceof RealDate?d.getTime():typeof d==="number"?d:new RealDate(d).getTime();globalThis.Date=FakeDate;return vi;},clearAllMocks:()=>vi,restoreAllMocks:()=>{fakeNow=null;globalThis.Date=RealDate;return vi;}};const mkEach=fn=>rows=>(name,cb)=>{for(let i=0;iString(args[j++]??""));fn(label,()=>cb(...args));}};const testFn=Object.assign((...xs)=>T.test(...xs),{each:mkEach(T.test),skip:T.test.skip,only:T.test.only});const itFn=Object.assign((...xs)=>T.it(...xs),{each:mkEach(T.it),skip:T.it.skip,only:T.it.only});const descFn=Object.assign((...xs)=>T.describe(...xs),{each:mkEach(T.describe),skip:T.describe.skip,only:T.describe.only});const api={describe:descFn,it:itFn,test:testFn,beforeEach:T.beforeEach,afterEach:T.afterEach,beforeAll:T.before,afterAll:T.after,expect,vi};globalThis.__rosterTestApi=api;if(!globalThis.describe)Object.assign(globalThis,api);let wsMap=null;const regPkg=(map,dir)=>{const pj=P.join(dir,"package.json");if(F.existsSync(pj)){try{const pkg=JSON.parse(F.readFileSync(pj,"utf8"));if(pkg&&typeof pkg.name==="string"&&!map.has(pkg.name))map.set(pkg.name,{dir,pkg});}catch{}}};const loadWs=start=>{if(wsMap)return wsMap;wsMap=new Map();let d=start;for(let i=0;i<10;i++){regPkg(wsMap,d);for(const sub of["pkgs","packages","libs"]){const base=P.join(d,sub);if(F.existsSync(base)&&F.statSync(base).isDirectory()){for(const ent of F.readdirSync(base))regPkg(wsMap,P.join(base,ent));}}const up=P.dirname(d);if(up===d)break;d=up;}return wsMap;};const pickExp=v=>typeof v==="string"?v:(v&&typeof v==="object"?pickExp(v.import||v.default||v.module||v.types):null);registerHooks({resolve(s,c,n){try{return n(s,c);}catch(e){if(s==="vitest"||s==="@jest/globals")return{shortCircuit:true,url:"data:text/javascript,export const{describe,it,test,beforeEach,afterEach,beforeAll,afterAll,expect,vi}=globalThis.__rosterTestApi;"};if(s==="ava")return{shortCircuit:true,url:"data:text/javascript,import*as T from'node:test';import*as A from'node:assert/strict';const mkT=()=>({is:(a,b)=>A.strictEqual(a,b),not:(a,b)=>A.notStrictEqual(a,b),deepEqual:(a,b)=>A.deepStrictEqual(a,b),notDeepEqual:(a,b)=>A.notDeepStrictEqual(a,b),true:v=>A.strictEqual(v,true),false:v=>A.strictEqual(v,false),truthy:v=>A.ok(v),falsy:v=>A.ok(!v),pass:()=>{},fail:m=>A.fail(m),regex:(s,r)=>A.match(String(s),r),notRegex:(s,r)=>A.doesNotMatch(String(s),r),throws:(fn,e)=>A.throws(fn,e),notThrows:(fn)=>A.doesNotThrow(fn),throwsAsync:async(fn,e)=>{try{await(typeof fn==='function'?fn():fn);A.fail('Expected rejection');}catch(err){if(e&&e.instanceOf&&!(err instanceof e.instanceOf))throw err;if(e&&e.message&&(e.message instanceof RegExp?!e.message.test(err.message):!String(err.message).includes(String(e.message))))throw err;return err;}},notThrowsAsync:async(fn)=>await(typeof fn==='function'?fn():fn),like:(a,b)=>{for(const k of Object.keys(b))A.deepStrictEqual(a[k],b[k]);},plan:()=>{},log:()=>{},timeout:()=>{},teardown:()=>{},context:{}});const run=(title,fn)=>T.test(title,()=>fn(mkT()));const ava=Object.assign(run,{serial:Object.assign(run,{skip:T.test.skip,only:T.test.only,before:T.before,after:T.after,beforeEach:T.beforeEach,afterEach:T.afterEach}),skip:T.test.skip,only:T.test.only,failing:T.test.skip,todo:T.test.todo,before:fn=>T.before(()=>fn(mkT())),after:fn=>T.after(()=>fn(mkT())),beforeEach:fn=>T.beforeEach(()=>fn(mkT())),afterEach:fn=>T.afterEach(()=>fn(mkT())),macro:x=>x});export default ava;export{ava as test};"};if(c.parentURL&&c.parentURL.startsWith("file:")){const xs=s.endsWith(".js")?[s.slice(0,-3)+".ts"]:(s.startsWith(".")&&!/\.[cm]?[jt]s$/.test(s)?[s+".ts",s+"/index.ts"]:[]);for(const x of xs){try{return n(x,c);}catch{}}const bm=s.match(/^(.*\/)(?:lib|dist|build)\/([^/]+?)(?:\.(?:esm|cjs|mjs|umd|min))?\.[cm]?js$/);if(bm){const bd=P.resolve(P.dirname(fileURLToPath(c.parentURL)),bm[1]);for(const f of[P.join(bd,"src",bm[2]+".ts"),P.join(bd,"src",bm[2]+".mts"),P.join(bd,"src","index.ts"),P.join(bd,"src","index.mts")]){if(F.existsSync(f))return{shortCircuit:true,url:pathToFileURL(f).href};}}if(!s.startsWith(".")&&!s.startsWith("/")&&!s.startsWith("node:")){const map=loadWs(P.dirname(fileURLToPath(c.parentURL)));for(const[name,info]of map){if(s===name||s.startsWith(name+"/")){const sub=s===name?".":"."+s.slice(name.length);let target=info.pkg.exports&&typeof info.pkg.exports==="object"?pickExp(info.pkg.exports[sub]):null;if(!target&&sub===".")target=info.pkg.module||info.pkg.main||"./src/index.ts";if(target){const full=P.resolve(info.dir,target);const rel=target.replace(/^\.\//,"");const stripped=rel.replace(/^(?:dist|lib|build)\//,"");const srcFull=P.resolve(info.dir,"src",rel);const srcStripped=P.resolve(info.dir,"src",stripped);const cands=full.endsWith(".js")?[srcStripped.slice(0,-3)+".ts",full.slice(0,-3)+".ts",srcFull.slice(0,-3)+".ts",full]:[srcStripped,srcStripped+".ts",P.join(srcStripped,"index.ts"),full,full+".ts",P.join(full,"index.ts"),srcFull,srcFull+".ts",P.join(srcFull,"index.ts")];for(const f of cands){if(F.existsSync(f))return{shortCircuit:true,url:pathToFileURL(f).href};}}}}const nm=process.env.ROSTER_NODE_MODULES;if(nm){try{return n(s,{...c,parentURL:pathToFileURL(P.join(nm,"_")).href});}catch{}}}}throw e;}}});"#; pub(crate) fn unverified_cleanup(failure: &process::Failure, descendants_possible: bool) -> bool { !failure.cleanup_complete @@ -4108,6 +4108,23 @@ impl Boundary { || (output.contains("failed to select a version") && output.contains("--offline")) } + pub(crate) fn cargo_fmt_has_untouched_diffs(output: &str, scope: &[String]) -> bool { + for line in output.lines() { + if let Some(rest) = line.strip_prefix("Diff in ") { + let norm = rest.trim().trim_end_matches(':').replace('\\', "/"); + let path_part = norm.rsplit_once(':').map_or(norm.as_str(), |(p, _)| p); + let in_scope = scope.iter().any(|allowed| { + let norm_allowed = allowed.replace('\\', "/"); + path_part == norm_allowed || path_part.ends_with(&format!("/{norm_allowed}")) + }); + if !in_scope { + return true; + } + } + } + false + } + async fn node_checks(&self, scope: &[String], full: bool) -> Result { if !self.root.join("package.json").is_file() && scope @@ -4329,6 +4346,22 @@ impl Boundary { }; let mut args = Vec::new(); if ts_mode { + for cand in [ + Some(self.root.join("node_modules")), + self.root + .parent() + .and_then(Path::parent) + .map(|p| p.join("node_modules")), + ] + .into_iter() + .flatten() + { + if cand.is_dir() { + environment + .insert("ROSTER_NODE_MODULES".to_owned(), cand.display().to_string()); + break; + } + } args.push("--experimental-transform-types".to_owned()); args.push("--import".to_owned()); args.push(TS_IMPORT_HOOK.to_owned()); @@ -4922,19 +4955,49 @@ impl Boundary { test_step, ] } else { - let (clippy_args, test_args) = if has_integration_test || !is_roster_self { + let (fmt_args, clippy_args, test_args) = if !is_roster_self { + let mut f_args = vec!["fmt".to_owned(), "--".to_owned(), "--check".to_owned()]; + for rf in requirements + .files + .iter() + .chain(self.written.iter()) + .filter(|f| f.ends_with(".rs")) + { + if !f_args.contains(rf) { + f_args.push(rf.clone()); + } + } let mut t_args = vec!["test".to_owned()]; - if !is_roster_self && !integration_stems.is_empty() { + if !integration_stems.is_empty() { for stem in &integration_stems { t_args.push("--test".to_owned()); t_args.push(stem.clone()); } } else { - t_args.push("--all-targets".to_owned()); + t_args.push("--lib".to_owned()); + t_args.push("--tests".to_owned()); } t_args.push("--locked".to_owned()); t_args.push("--offline".to_owned()); ( + f_args, + vec![ + "check".to_owned(), + "--lib".to_owned(), + "--tests".to_owned(), + "--locked".to_owned(), + "--offline".to_owned(), + ], + t_args, + ) + } else if has_integration_test { + ( + vec![ + "fmt".to_owned(), + "--all".to_owned(), + "--".to_owned(), + "--check".to_owned(), + ], vec![ "clippy".to_owned(), "--all-targets".to_owned(), @@ -4944,7 +5007,12 @@ impl Boundary { "-D".to_owned(), "warnings".to_owned(), ], - t_args, + vec![ + "test".to_owned(), + "--all-targets".to_owned(), + "--locked".to_owned(), + "--offline".to_owned(), + ], ) } else { let single_mod = if requirements.files.len() == 1 { @@ -4966,6 +5034,12 @@ impl Boundary { t_args.push(filter); } ( + vec![ + "fmt".to_owned(), + "--all".to_owned(), + "--".to_owned(), + "--check".to_owned(), + ], vec![ "clippy".to_owned(), "--lib".to_owned(), @@ -4979,16 +5053,7 @@ impl Boundary { t_args, ) }; - [ - vec![ - "fmt".to_owned(), - "--all".to_owned(), - "--".to_owned(), - "--check".to_owned(), - ], - clippy_args, - test_args, - ] + [fmt_args, clippy_args, test_args] }; let had_sub_lock = sub_crate .as_ref() @@ -5089,6 +5154,14 @@ impl Boundary { .await?; } } + let is_fmt = args.first().map(String::as_str) == Some("fmt"); + if output.exit != 0 && is_fmt && !is_roster_self { + let fmt_out = String::from_utf8_lossy(&output.stdout); + if Self::cargo_fmt_has_untouched_diffs(&fmt_out, &requirements.files) { + output.exit = 0; + output.stdout.clear(); + } + } if !(is_metadata && output.exit == 0) { stdout.push_str(&bytes_text(&output.stdout)?); } diff --git a/rust/seats/tests.rs b/rust/seats/tests.rs index 7f5b876..1e8679d 100644 --- a/rust/seats/tests.rs +++ b/rust/seats/tests.rs @@ -2388,4 +2388,13 @@ fn pytest_missing_fixture_detector_distinguishes_plugin_errors_from_real_failure assert!(!tools::Boundary::is_pytest_addopts_plugin_error( normal_fail )); + assert!(tools::TS_IMPORT_HOOK.contains("if(s===\"ava\")")); + assert!(tools::Boundary::cargo_fmt_has_untouched_diffs( + "Diff in /repo/benches/bench.rs:1:\nDiff in /repo/src/lib.rs:5:\n", + &["src/lib.rs".to_owned()], + )); + assert!(!tools::Boundary::cargo_fmt_has_untouched_diffs( + "Diff in /repo/src/lib.rs:1:\n", + &["src/lib.rs".to_owned()], + )); }