Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(ci): catch grouped embed reexports and char literals in crate chain check

Steven Enamakela750d585429a
diff --git a/scripts/__tests__/check-crate-chain.test.mjs b/scripts/__tests__/check-crate-chain.test.mjs
index 0cf86d0bbe..60f93015a4 100644
--- a/scripts/__tests__/check-crate-chain.test.mjs
+++ b/scripts/__tests__/check-crate-chain.test.mjs
@@ -213,6 +213,20 @@ test('a host, root test or example naming the internal list is flagged, aliased
assert.deepEqual(flagged('use openhuman_rpc::embed::config;\n'), []);
});
+test('char literals do not desynchronize the stripper; grouped embed is flagged', () => {
+ const flagged = text =>
+ findPatternHits(text, 'lib.rs', WHOLESALE_REEXPORT_PATTERNS).map(h => h.line);
+ assert.deepEqual(flagged("let t = s.trim_matches('\"');\npub use openhuman_embed as e;\n"), [2]);
+ assert.deepEqual(flagged('pub use openhuman_tinyhumans::{embed, RuntimeBuilder};\n'), [1]);
+ assert.deepEqual(
+ flagged('pub use openhuman_tinyhumans::{embed::process, RuntimeBuilder};\n'),
+ []
+ );
+ const internal = text =>
+ findPatternHits(text, 'lib.rs', RPC_INTERNAL_REEXPORT_PATTERNS).map(h => h.line);
+ assert.deepEqual(internal('pub use crate::core_host::{core::unwrap_rpc, secret};\n'), [1]);
+});
+
test('string literals and comments are not code', () => {
const flagged = text =>
findPatternHits(text, 'lib.rs', WHOLESALE_REEXPORT_PATTERNS).map(h => h.pattern);
diff --git a/scripts/ci/check-crate-chain.mjs b/scripts/ci/check-crate-chain.mjs
index ddf7fb83b2..b4125794ca 100644
--- a/scripts/ci/check-crate-chain.mjs
+++ b/scripts/ci/check-crate-chain.mjs
@@ -92,6 +92,10 @@ export const WHOLESALE_REEXPORT_PATTERNS = [
name: 'pub use openhuman_embed / openhuman_tinyhumans (the bare crate)',
regex: /\bpub(?:\([^)]*\))?\s+use\s+openhuman_(?:embed|tinyhumans)\s*;/,
},
+ {
+ name: 'pub use openhuman_tinyhumans::{embed, …} (grouped)',
+ regex: /\bpub(?:\([^)]*\))?\s+use\s+openhuman_tinyhumans::\{[^}]*\bembed\b(?!\s*::)[^}]*\}/,
+ },
{
name: 'pub use openhuman_tinyhumans::embed (the crate, not a list)',
regex: /\bpub(?:\([^)]*\))?\s+use\s+openhuman_tinyhumans::embed\s*(?:as\s+\w+\s*)?;/,
@@ -110,7 +114,7 @@ export const CORE_WHOLESALE_REEXPORT_PATTERNS = [
export const RPC_INTERNAL_REEXPORT_PATTERNS = [
{
name: 'pub use of anything under __host / core_host (bar unwrap_rpc)',
- regex: /\bpub\s+use\b(?![^;]*::unwrap_rpc\s*;)[^;]*\b(?:__host|core_host)\b/,
+ regex: /\bpub\s+use\b(?!\s+[^;{},]*::unwrap_rpc\s*;)[^;]*\b(?:__host|core_host)\b/,
},
];
@@ -157,6 +161,9 @@ export function stripRustComments(text) {
const stop = end === -1 ? text.length : end + close.length;
out += blank(text.slice(i, stop));
i = stop;
+ } else if ((m = /^b?'(?:\\(?:x[0-9a-fA-F]{2}|u\{[0-9a-fA-F]+\}|.)|[^\\'])'/.exec(rest))) {
+ out += blank(m[0]);
+ i += m[0].length;
} else if (rest.startsWith('"') || rest.startsWith('b"')) {
let j = i + (rest.startsWith('b') ? 2 : 1);
while (j < text.length && text[j] !== '"') j += text[j] === '\\' ? 2 : 1;