fix(sdk): enforce runtime dependency boundary

This commit is contained in:
2026-09-05 08:01:07 +08:00
parent 471e2e9479
commit dfaa4f0ef4
4 changed files with 45 additions and 11 deletions
@@ -221,6 +221,7 @@ function findViolation(context) {
const filePath = displayPath(file);
const resolvedPath = resolved ? displayPath(resolved) : specifier;
const isContract = CONTRACTS_PATH.test(filePath);
const isSdk = SDK_ALLOWED.test(filePath);
const isGame = isInside(file, gamesDir);
const isFramework = isInside(file, frameworkDir);
@@ -232,6 +233,14 @@ function findViolation(context) {
return violation(filePath, specifier, `sdk/contracts may import only sibling contracts; sdk path resolved to ${resolvedPath}`);
}
if (isSdk
&& !isSdkMigrationBarrel(filePath, frameworkDir)
&& resolved
&& isInside(resolved, frameworkDir)
&& !SDK_ALLOWED.test(resolvedPath)) {
return violation(filePath, specifier, `sdk cannot import framework implementation ${resolvedPath}`);
}
if (isGame && resolved && isFrameworkReference(resolved, frameworkDir) && !SDK_ALLOWED.test(resolvedPath)) {
return violation(filePath, specifier, `game code may import only framework/sdk; game import resolved to ${resolvedPath}`);
}
@@ -264,6 +273,10 @@ function isLegacyRuntimeImporter(filePath, frameworkDir) {
return filePath === `${normalizedFrameworkDir}/sdk/index.ts` || LEGACY_RUNTIME.test(filePath);
}
function isSdkMigrationBarrel(filePath, frameworkDir) {
return filePath === `${displayPath(frameworkDir)}/sdk/index.ts`;
}
/**
* ActiveGame is the retained compatibility owner of IGameModule until Task 11
* removes both it and the migration-only declarations from sdk/index.ts.