Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 84 additions & 76 deletions docs/performance/01-compile-performance.md

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions scripts/check-core-boundaries.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import {
} from './core-boundaries/cargo-dependency-boundaries.mjs';
import {
checkCliIntegrationTestTopology,
checkServicesCoreIntegrationTestTopology,
checkServicesIntegrationsIntegrationTestTopology,
cliIntegrationTestTargets,
servicesCoreIntegrationTestTargets,
servicesIntegrationsIntegrationTestTargets,
validateExplicitIntegrationTestTopology,
} from './core-boundaries/explicit-test-topology.mjs';
import { crateLayoutRules } from './core-boundaries/rules/crate-layout.mjs';
Expand Down Expand Up @@ -120,6 +124,21 @@ test('feature-gated integration targets require every positive crate feature', (
assert.doesNotMatch(violations[0].message, /remote-ssh-concrete.*missing/);
});

test('feature-gated integration target parsing skips a Rust shebang', () => {
const sourcePath = join(TEST_ROOT, 'tests', 'remote.rs');
const pkg = {
...packageAt('example', 'src/crates/services/example/Cargo.toml'),
targets: [integrationTarget('remote', sourcePath, ['remote-ssh'])],
};

const violations = findFeatureGatedTestTargetViolations([pkg], {
readSource: () => '#!/usr/bin/env rustx\n#![cfg(all(feature = "remote-ssh", feature = "workspace-search"))]\n',
});

assert.equal(violations.length, 1);
assert.match(violations[0].message, /workspace-search/);
});

test('matching integration target requirements cover all positive crate features', () => {
const sourcePath = join(TEST_ROOT, 'tests', 'remote.rs');
const pkg = {
Expand Down Expand Up @@ -242,6 +261,42 @@ test('CLI integration tests keep the reviewed three-target topology', () => {
assert.deepEqual(checkCliIntegrationTestTopology(repositoryRoot), []);
});

test('service integration tests keep their reviewed explicit target topology', () => {
const repositoryRoot = fileURLToPath(new URL('..', import.meta.url));

assert.deepEqual(servicesCoreIntegrationTestTargets, [
{ name: 'markdown_owner_contracts', path: 'tests/markdown_owner_contracts.rs' },
{ name: 'declarative_workspace_instruction_contracts', path: 'tests/declarative_workspace_instruction_contracts.rs' },
{ name: 'lsp_plugin_registry_contracts', path: 'tests/lsp_plugin_registry_contracts.rs' },
{ name: 'runtime_ownership_contracts', path: 'tests/runtime_ownership_contracts.rs' },
{ name: 'local_runtime_ports', path: 'tests/local_runtime_ports.rs' },
{ name: 'permission_store_contracts', path: 'tests/permission_store_contracts.rs' },
{ name: 'workspace_instruction_contracts', path: 'tests/workspace_instruction_contracts.rs' },
{ name: 'session_write_lock_contracts', path: 'tests/session_write_lock_contracts.rs' },
{ name: 'process_runtime_contracts', path: 'tests/process_runtime_contracts.rs' },
{ name: 'service_contracts', path: 'tests/service_contracts.rs' },
{ name: 'storage_owner_contracts', path: 'tests/storage_owner_contracts.rs' },
{ name: 'session_contracts', path: 'tests/session_contracts.rs' },
{ name: 'session_usage_contracts', path: 'tests/session_usage_contracts.rs' },
]);
assert.deepEqual(servicesIntegrationsIntegrationTestTargets, [
{ name: 'debug_log_owner_contracts', path: 'tests/debug_log_owner_contracts.rs' },
{ name: 'script_tool_runtime', path: 'tests/script_tool_runtime.rs' },
{ name: 'announcement_contracts', path: 'tests/announcement_contracts.rs' },
{ name: 'file_watch_contracts', path: 'tests/file_watch_contracts.rs' },
{ name: 'function_agent_contracts', path: 'tests/function_agent_contracts.rs' },
{ name: 'git_contracts', path: 'tests/git_contracts.rs' },
{ name: 'mcp_contracts', path: 'tests/mcp_contracts.rs' },
{ name: 'mcp_streamable_http_contracts', path: 'tests/mcp_streamable_http_contracts.rs' },
{ name: 'remote_connect_contracts', path: 'tests/remote_connect_contracts.rs' },
{ name: 'remote_ssh_contracts', path: 'tests/remote_ssh_contracts.rs' },
{ name: 'remote_workspace_search_disabled_contracts', path: 'tests/remote_workspace_search_disabled_contracts.rs' },
{ name: 'workspace_search_contracts', path: 'tests/workspace_search_contracts.rs' },
]);
assert.deepEqual(checkServicesCoreIntegrationTestTopology(repositoryRoot), []);
assert.deepEqual(checkServicesIntegrationsIntegrationTestTopology(repositoryRoot), []);
});

test('runtime-services test support is absent from ordinary library builds', async () => {
const [manifest, library] = await Promise.all([
readFile(
Expand Down
132 changes: 101 additions & 31 deletions scripts/core-boundaries/cargo-dependency-boundaries.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,44 @@ export function findProductEntrypointCoreFeatureViolations(
return violations;
}

function skipRustComment(source, startIndex) {
if (source.startsWith('//', startIndex)) {
const lineEnd = source.indexOf('\n', startIndex + 2);
return lineEnd === -1 ? source.length : lineEnd + 1;
}
if (!source.startsWith('/*', startIndex)) {
return startIndex;
}

let depth = 1;
let index = startIndex + 2;
while (index < source.length && depth > 0) {
if (source.startsWith('/*', index)) {
depth += 1;
index += 2;
} else if (source.startsWith('*/', index)) {
depth -= 1;
index += 2;
} else {
index += 1;
}
}
return index;
}

function skipRustRawString(source, startIndex) {
if (!['b', 'c', 'r'].includes(source[startIndex])) {
return startIndex;
}
const opening = /^(?:b|c)?r(#{0,255})"/.exec(source.slice(startIndex));
if (opening === null) {
return startIndex;
}
const closing = `"${opening[1]}`;
const closingIndex = source.indexOf(closing, startIndex + opening[0].length);
return closingIndex === -1 ? source.length : closingIndex + closing.length;
}

function matchingClosingDelimiter(
source,
openingIndex,
Expand All @@ -1067,6 +1105,16 @@ function matchingClosingDelimiter(
}
continue;
}
const rawStringEnd = skipRustRawString(source, index);
if (rawStringEnd !== index) {
index = rawStringEnd - 1;
continue;
}
const commentEnd = skipRustComment(source, index);
if (commentEnd !== index) {
index = commentEnd - 1;
continue;
}
if (character === '"' || character === "'") {
quote = character;
} else if (character === openingCharacter) {
Expand All @@ -1086,57 +1134,79 @@ function matchingClosingParenthesis(source, openingIndex) {
return matchingClosingDelimiter(source, openingIndex, '(', ')');
}

function crateCfgBodies(source) {
const bodies = [];
let index = source.charCodeAt(0) === 0xFEFF ? 1 : 0;

function skipRustTrivia(source, startIndex) {
let index = startIndex;
while (index < source.length) {
if (/\s/.test(source[index])) {
index += 1;
continue;
}
if (source.startsWith('//', index)) {
const commentEnd = skipRustComment(source, index);
if (commentEnd !== index) {
index = commentEnd;
continue;
}
break;
}
return index;
}

function leadingCrateAttributes(source) {
const attributes = [];
let index = source.charCodeAt(0) === 0xFEFF ? 1 : 0;
if (source.startsWith('#!', index)) {
const afterBang = skipRustTrivia(source, index + 2);
if (source[afterBang] !== '[') {
const lineEnd = source.indexOf('\n', index + 2);
index = lineEnd === -1 ? source.length : lineEnd + 1;
continue;
}
if (source.startsWith('/*', index)) {
let depth = 1;
index += 2;
while (index < source.length && depth > 0) {
if (source.startsWith('/*', index)) {
depth += 1;
index += 2;
} else if (source.startsWith('*/', index)) {
depth -= 1;
index += 2;
} else {
index += 1;
}
}
continue;
}

while (index < source.length) {
index = skipRustTrivia(source, index);
if (source[index] !== '#') {
break;
}
if (!source.startsWith('#![', index)) {
let cursor = skipRustTrivia(source, index + 1);
if (source[cursor] !== '!') {
break;
}
cursor = skipRustTrivia(source, cursor + 1);
if (source[cursor] !== '[') {
break;
}

const closingBracket = matchingClosingDelimiter(source, index + 2, '[', ']');
const closingBracket = matchingClosingDelimiter(source, cursor, '[', ']');
if (closingBracket === -1) {
break;
}
const attribute = source.slice(index, closingBracket + 1);
const cfgStart = /^#!\s*\[\s*cfg\s*\(/.exec(attribute);
if (cfgStart !== null) {
const openingIndex = cfgStart[0].length - 1;
const closingIndex = matchingClosingParenthesis(attribute, openingIndex);
if (closingIndex !== -1) {
bodies.push(attribute.slice(openingIndex + 1, closingIndex));
const nameStart = skipRustTrivia(source, cursor + 1);
const nameMatch = /^(?:r#)?([A-Za-z_][A-Za-z0-9_]*)/.exec(source.slice(nameStart));
const name = nameMatch?.[1] ?? '';
const argumentStart = skipRustTrivia(source, nameStart + (nameMatch?.[0].length ?? 0));
let body = null;
if (source[argumentStart] === '(') {
const closingParenthesis = matchingClosingParenthesis(source, argumentStart);
if (closingParenthesis !== -1 && closingParenthesis < closingBracket) {
body = source.slice(argumentStart + 1, closingParenthesis);
}
}
attributes.push({ name, body });
index = closingBracket + 1;
}

return bodies;
return attributes;
}

export function crateCfgBodies(source) {
return leadingCrateAttributes(source)
.filter(({ name, body }) => name === 'cfg' && body !== null)
.map(({ body }) => body);
}

export function hasCrateCfgAttr(source) {
return leadingCrateAttributes(source)
.some(({ name }) => name === 'cfg_attr');
}

function removeCfgBranches(expression, branchName) {
Expand Down
2 changes: 2 additions & 0 deletions scripts/core-boundaries/checker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
agentRuntimeIntegrationTestTargets,
checkAgentRuntimeIntegrationTestTopology,
checkCliIntegrationTestTopology,
checkServiceIntegrationTestTopologies,
cliIntegrationTestTargets,
validateExplicitIntegrationTestTopology,
} from './explicit-test-topology.mjs';
Expand Down Expand Up @@ -1122,6 +1123,7 @@ export function runCoreBoundaryCheck() {
failures.push(...checkCargoDependencyBoundariesSafely({ root: ROOT, crateLayoutRules }));
failures.push(...checkAgentRuntimeIntegrationTestTopology(ROOT));
failures.push(...checkCliIntegrationTestTopology(ROOT));
failures.push(...checkServiceIntegrationTestTopologies(ROOT));

for (const rule of forbiddenManifestDependencyRules) {
checkForbiddenManifestDependencyRule(rule);
Expand Down
Loading