feat(reporting-governance): add profile artifact binding slice

This commit is contained in:
Eve
2026-05-08 10:07:26 +08:00
parent 000f6b6a8b
commit 6366f70491
15 changed files with 695 additions and 6 deletions

View File

@@ -0,0 +1,54 @@
import fs from 'node:fs';
import path from 'node:path';
const packageRoot = path.resolve(import.meta.dirname, '..', '..');
const repoRoot = path.resolve(packageRoot, '..', '..');
function readJsonFile(filePath) {
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
}
export function resolvePackageArtifactPath(...segments) {
return path.resolve(packageRoot, ...segments);
}
export function loadDeploymentProfileArtifact({ artifactPath, profileId } = {}) {
const resolvedPath = path.resolve(
artifactPath
?? resolvePackageArtifactPath('profiles', `${profileId ?? 'strict-manager-mode'}.profile.json`)
);
const artifact = readJsonFile(resolvedPath);
return {
artifactPath: resolvedPath,
artifact,
};
}
export function createDeploymentBindingContract({ artifact, repoRootOverride } = {}) {
if (!artifact?.spec?.bindings) {
throw new Error('deployment profile artifact bindings are required');
}
const root = path.resolve(repoRootOverride ?? repoRoot);
const scripts = Object.fromEntries(
Object.entries(artifact.spec.bindings.scripts ?? {}).map(([key, relativePath]) => [key, path.resolve(root, relativePath)])
);
const artifactRoots = Object.fromEntries(
Object.entries(artifact.spec.bindings.artifact_roots ?? {}).map(([key, relativePath]) => [key, path.resolve(root, relativePath)])
);
return {
runtime: artifact.spec.bindings.runtime ?? artifact.metadata?.runtime ?? 'unknown-runtime',
entrypoint: path.resolve(root, artifact.spec.bindings.entrypoint),
pluginVersion: artifact.spec?.package?.pluginVersion ?? null,
compatibilityMode: artifact.metadata?.compatibility_mode ?? 'strict_envelope',
scripts,
artifactRoots,
};
}
export const __testables = {
packageRoot,
repoRoot,
readJsonFile,
};