chore(deploy): add unit identity rollout artifacts

This commit is contained in:
Codex 2026-07-24 11:43:26 +03:00
parent abebb9fac6
commit 659f98ad8f
3 changed files with 494 additions and 0 deletions

View File

@ -0,0 +1,193 @@
#!/usr/bin/env node
import { createHash } from "node:crypto";
import { spawnSync } from "node:child_process";
import { copyFile, lstat, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const scriptDir = dirname(fileURLToPath(import.meta.url));
const workspaceRoot = resolve(scriptDir, "../../..");
const engineRoot = resolve(
process.env.NODEDC_ENGINE_SOURCE_ROOT || join(workspaceRoot, "NODEDC_ENGINE_INFRA"),
);
const artifactDir = resolve(
process.env.NODEDC_DEPLOY_ARTIFACT_DIR || resolve(scriptDir, "../deploy-artifacts"),
);
const [patchId = "engine-mcp-normalized-identity-search-20260724-040", ...extra] =
process.argv.slice(2);
if (
extra.length
|| !/^engine-mcp-normalized-identity-search-\d{8}-\d{3}$/.test(patchId)
) {
throw new Error(
"usage: build-engine-mcp-normalized-identity-search-artifact.mjs "
+ "[engine-mcp-normalized-identity-search-YYYYMMDD-NNN]",
);
}
const expectedSha256 = Object.freeze({
"nodedc-source/server/routes/n8n.js":
"a2bc69c72f68e57ed27120d0c88f4ffe6310bbf0c4360c8b0dba0953ccaaf522",
"nodedc-source/server/routes/engineAgentGateway.js":
"4a9524fd954320277042c783b7b19cbb2172f075f27652c0eebfd743ffc47872",
"nodedc-source/server/l2ExecutionPlan/compiler.js":
"01958d541c778002d33e3aead0cfe02df2084eb7222ce941cc7149d73a10f135",
"nodedc-source/server/assets/execution-plans/v1/catalog.json":
"2b8e5ee3d73d16f3cd6e34d1f7394946a6270a17b0e9e6511f12921ba2561fd3",
"nodedc-source/server/assets/provider-packages/v1/catalog.json":
"fe5256fd2ba295819daecc8d2acae34687e807978a6730dfa20703cb3bab0c1b",
"nodedc-source/server/deployTransitions/normalizedIdentitySearchV1.json":
"41738185fe103642912b0aa1c29c51860970c38f9f916cc3725e79e258b9ea7e",
"nodedc-source/services/node-intelligence/activation.json":
"98d2a068ddf1cccfa3b7a0617f94b25948184961655c755465ee84ec4cfbb3c3",
});
const files = Object.freeze(Object.keys(expectedSha256));
const artifact = join(artifactDir, `nodedc-${patchId}.tgz`);
const checksum = `${artifact}.sha256`;
const stage = await mkdtemp(join(tmpdir(), "nodedc-engine-normalized-identity-"));
await assertFresh(artifact);
await assertExactSources();
try {
for (const relativePath of files) {
const destination = join(stage, "payload", relativePath);
await mkdir(dirname(destination), { recursive: true });
await copyFile(join(engineRoot, relativePath), destination);
}
await writeFile(
join(stage, "manifest.env"),
`id=${patchId}\ncomponent=engine\ntype=app-overlay\n`,
"utf8",
);
await writeFile(join(stage, "files.txt"), `${files.join("\n")}\n`, "utf8");
await mkdir(artifactDir, { recursive: true });
run("python3", ["-c", canonicalTarScript(), artifact, stage]);
const sha256 = digest(await readFile(artifact));
await writeFile(checksum, `${sha256} ${artifact.split("/").at(-1)}\n`, "utf8");
console.log(JSON.stringify({
ok: true,
patchId,
artifact,
checksum,
sha256,
services: ["nodedc-backend"],
mcpVersion: "0.11.0",
mcpSurface: "external-codex",
tool: "engine_find_normalized_subjects",
providerPackage: "gelios.provider.v11",
compilerVersionAdded: "1.4.0",
rawProviderPayload: "forbidden",
commandSurface: "absent",
files,
}, null, 2));
} finally {
await rm(stage, { recursive: true, force: true });
}
async function assertExactSources() {
for (const [relativePath, expected] of Object.entries(expectedSha256)) {
const sourcePath = join(engineRoot, relativePath);
const info = await lstat(sourcePath);
if (!info.isFile() || info.isSymbolicLink()) {
throw new Error(`engine_normalized_identity_source_unsafe:${relativePath}`);
}
const actual = digest(await readFile(sourcePath));
if (actual !== expected) {
throw new Error(
`engine_normalized_identity_target_mismatch:${relativePath}:`
+ `expected=${expected}:actual=${actual}`,
);
}
}
const gateway = await readFile(
join(engineRoot, "nodedc-source/server/routes/engineAgentGateway.js"),
"utf8",
);
const route = await readFile(
join(engineRoot, "nodedc-source/server/routes/n8n.js"),
"utf8",
);
const compiler = await readFile(
join(engineRoot, "nodedc-source/server/l2ExecutionPlan/compiler.js"),
"utf8",
);
if (
!gateway.includes("const ENGINE_AGENT_MCP_VERSION = '0.11.0'")
|| !gateway.includes("engine_find_normalized_subjects")
|| !route.includes("normalized-fact-search")
|| !route.includes("rawExecutionDataIncluded: false")
|| !compiler.includes("boundedStringList")
|| !compiler.includes("boundedNamedValues")
|| /gelios|robot2b/i.test(compiler)
) {
throw new Error("engine_normalized_identity_runtime_boundary_invalid");
}
const transition = JSON.parse(await readFile(
join(
engineRoot,
"nodedc-source/server/deployTransitions/normalizedIdentitySearchV1.json",
),
"utf8",
));
const activation = JSON.parse(await readFile(
join(engineRoot, "nodedc-source/services/node-intelligence/activation.json"),
"utf8",
));
if (
transition?.id !== "engine-mcp-normalized-identity-search-v1"
|| transition?.normalizedFactSearch?.commandSurface !== false
|| transition?.providerPackageTrust?.addedPackageId !== "gelios.provider.v11"
|| activation?.source?.gatewaySha256
!== expectedSha256["nodedc-source/server/routes/engineAgentGateway.js"]
|| activation?.predecessor?.gatewaySha256
!== "17c5f502b3ceacc45278eef7418d08e1e55a8b3e46e00942e559d25566fdba41"
) {
throw new Error("engine_normalized_identity_transition_invalid");
}
}
async function assertFresh(path) {
try {
await lstat(path);
} catch (error) {
if (error?.code === "ENOENT") return;
throw error;
}
throw new Error("artifact_already_exists");
}
function canonicalTarScript() {
return [
"import gzip,io,pathlib,sys,tarfile",
"root=pathlib.Path(sys.argv[2])",
"with open(sys.argv[1],'xb') as out:",
" with gzip.GzipFile(filename='',mode='wb',fileobj=out,compresslevel=9,mtime=0) as gz:",
" with tarfile.open(fileobj=gz,mode='w',format=tarfile.PAX_FORMAT) as tar:",
" for top in ('manifest.env','files.txt','payload'):",
" p=root/top; paths=[p]+(sorted(p.rglob('*')) if p.is_dir() else [])",
" for x in paths:",
" info=tar.gettarinfo(str(x),arcname=x.relative_to(root).as_posix())",
" info.uid=info.gid=0; info.uname=info.gname='root'; info.mtime=0; info.mode=0o755 if info.isdir() else 0o644",
" with (open(x,'rb') if info.isfile() else io.BytesIO()) as src: tar.addfile(info,src if info.isfile() else None)",
].join("\n");
}
function digest(value) {
return createHash("sha256").update(value).digest("hex");
}
function run(command, args) {
const result = spawnSync(command, args, {
encoding: "utf8",
maxBuffer: 128 * 1024 * 1024,
});
if (result.status !== 0) {
throw new Error(`${command}_failed:${result.stderr || result.stdout}`);
}
}

View File

@ -0,0 +1,131 @@
#!/usr/bin/env node
import { createHash } from "node:crypto";
import { spawnSync } from "node:child_process";
import { copyFile, lstat, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const scriptDir = dirname(fileURLToPath(import.meta.url));
const platformRoot = resolve(scriptDir, "../..");
const artifactDir = resolve(
process.env.NODEDC_DEPLOY_ARTIFACT_DIR || resolve(scriptDir, "../deploy-artifacts"),
);
const [patchId = "external-data-plane-unit-identity-20260724-015", ...extra] =
process.argv.slice(2);
if (extra.length || !/^external-data-plane-unit-identity-\d{8}-\d{3}$/.test(patchId)) {
throw new Error(
"usage: build-external-data-plane-unit-identity-artifact.mjs "
+ "[external-data-plane-unit-identity-YYYYMMDD-NNN]",
);
}
const sourceRelative =
"services/external-data-plane/definitions/fleet.units.identity.current.v1.json";
const destinationRelative = `platform/${sourceRelative}`;
const expectedSha256 =
"1bc017cf71f4705875e735550ec4589cea77e1d2e8c8450162148a051a7ceffe";
const artifact = join(artifactDir, `nodedc-${patchId}.tgz`);
const checksum = `${artifact}.sha256`;
const stage = await mkdtemp(join(tmpdir(), "nodedc-edp-unit-identity-artifact-"));
await assertFresh(artifact);
await assertDefinition();
try {
const payloadFile = join(stage, "payload", destinationRelative);
await mkdir(dirname(payloadFile), { recursive: true });
await copyFile(join(platformRoot, sourceRelative), payloadFile);
await writeFile(
join(stage, "manifest.env"),
`id=${patchId}\ncomponent=platform\ntype=app-overlay\n`,
"utf8",
);
await writeFile(join(stage, "files.txt"), `${destinationRelative}\n`, "utf8");
await mkdir(artifactDir, { recursive: true });
run("python3", ["-c", canonicalTarScript(), artifact, stage]);
const sha256 = digest(await readFile(artifact));
await writeFile(checksum, `${sha256} ${artifact.split("/").at(-1)}\n`, "utf8");
console.log(JSON.stringify({
ok: true,
patchId,
artifact,
checksum,
sha256,
services: ["external-data-plane"],
dataProductId: "fleet.units.identity.current.v1",
dataClass: "restricted",
files: [destinationRelative],
}, null, 2));
} finally {
await rm(stage, { recursive: true, force: true });
}
async function assertDefinition() {
const source = await readFile(join(platformRoot, sourceRelative));
if (digest(source) !== expectedSha256) {
throw new Error("unit_identity_definition_target_mismatch");
}
const definition = JSON.parse(source);
const fields = Array.isArray(definition?.fields) ? definition.fields : [];
if (
definition?.id !== "fleet.units.identity.current.v1"
|| definition?.version !== "1.0.0"
|| definition?.ontologyRevision !== "ontology.map.moving_object.v3"
|| JSON.stringify(definition?.semanticTypes) !== JSON.stringify(["map.moving_object"])
|| !fields.includes("provider_unit_id")
|| !fields.includes("device_imei")
|| !fields.includes("assigned_driver_phone")
|| definition?.fieldContracts?.available_user_logins?.type !== "string_array"
|| definition?.fieldContracts?.custom_fields?.type !== "string_array"
) {
throw new Error("unit_identity_definition_contract_invalid");
}
if (/(token|secret|password|authorization|decrypt|raw_provider_payload)/i.test(
JSON.stringify(definition),
)) {
throw new Error("unit_identity_definition_secret_boundary_violation");
}
}
async function assertFresh(path) {
try {
await lstat(path);
} catch (error) {
if (error?.code === "ENOENT") return;
throw error;
}
throw new Error("artifact_already_exists");
}
function canonicalTarScript() {
return [
"import gzip,io,pathlib,sys,tarfile",
"root=pathlib.Path(sys.argv[2])",
"with open(sys.argv[1],'xb') as out:",
" with gzip.GzipFile(filename='',mode='wb',fileobj=out,compresslevel=9,mtime=0) as gz:",
" with tarfile.open(fileobj=gz,mode='w',format=tarfile.PAX_FORMAT) as tar:",
" for top in ('manifest.env','files.txt','payload'):",
" p=root/top; paths=[p]+(sorted(p.rglob('*')) if p.is_dir() else [])",
" for x in paths:",
" info=tar.gettarinfo(str(x),arcname=x.relative_to(root).as_posix())",
" info.uid=info.gid=0; info.uname=info.gname='root'; info.mtime=0; info.mode=0o755 if info.isdir() else 0o644",
" with (open(x,'rb') if info.isfile() else io.BytesIO()) as src: tar.addfile(info,src if info.isfile() else None)",
].join("\n");
}
function digest(value) {
return createHash("sha256").update(value).digest("hex");
}
function run(command, args) {
const result = spawnSync(command, args, {
encoding: "utf8",
maxBuffer: 64 * 1024 * 1024,
});
if (result.status !== 0) {
throw new Error(`${command}_failed:${result.stderr || result.stdout}`);
}
}

View File

@ -0,0 +1,170 @@
#!/usr/bin/env node
import { createHash } from "node:crypto";
import { spawnSync } from "node:child_process";
import { copyFile, lstat, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const scriptDir = dirname(fileURLToPath(import.meta.url));
const workspaceRoot = resolve(scriptDir, "../../..");
const foundryRoot = resolve(workspaceRoot, "NODEDC_DESIGN_GUIDELINE");
const artifactDir = resolve(
process.env.NODEDC_DEPLOY_ARTIFACT_DIR || resolve(scriptDir, "../deploy-artifacts"),
);
const [patchId = "module-foundry-unit-identity-20260724-011", ...extra] =
process.argv.slice(2);
if (extra.length || !/^module-foundry-unit-identity-\d{8}-\d{3}$/.test(patchId)) {
throw new Error(
"usage: build-module-foundry-unit-identity-artifact.mjs "
+ "[module-foundry-unit-identity-YYYYMMDD-NNN]",
);
}
const expectedSha256 = Object.freeze({
"apps/catalog/src/MapFixturePreview.tsx":
"0ab08a872a8ec4cfb5144c808e361fa42e261bc14a23350843c487e3639d3cf7",
"apps/catalog/src/mapSubjectCard.d.mts":
"3a1afd1b2da42fe843bd50a9199137b5a490cc87759375033e17e18368ad019f",
"apps/catalog/src/mapSubjectCard.mjs":
"e235ca0b33ebed687ab62d2a3a5ff0cc865af4c51d42f1b920822077ddd67de1",
"registry/data-product-consumer-policies.json":
"7817e9ffbb8eb0e20445c97e3c2684d4dfa4e217ead569241052b9f29789ab44",
"server/foundry-data-product-consumer.mjs":
"3a21d887368bd28bf538e8bcda45cbd3e1fa775b8e21092ade50dd913ad29305",
"server/foundry-mcp.mjs":
"1a80ba6398e1a038fd07cb118de48f23402433863559b310942a0f6cb01d974b",
"server/map-subject-detail-profile.mjs":
"2d3d466c1798bd9a0c0c8c766235bde1792285498309fbbe58d4c1892ed62862",
});
const files = Object.freeze(Object.keys(expectedSha256));
const artifact = join(artifactDir, `nodedc-${patchId}.tgz`);
const checksum = `${artifact}.sha256`;
const stage = await mkdtemp(join(tmpdir(), "nodedc-foundry-unit-identity-"));
await assertFresh(artifact);
await assertExactSources();
try {
for (const relativePath of files) {
const destination = join(stage, "payload", relativePath);
await mkdir(dirname(destination), { recursive: true });
await copyFile(join(foundryRoot, relativePath), destination);
}
await writeFile(
join(stage, "manifest.env"),
`id=${patchId}\ncomponent=module-foundry\ntype=app-overlay\n`,
"utf8",
);
await writeFile(join(stage, "files.txt"), `${files.join("\n")}\n`, "utf8");
await mkdir(artifactDir, { recursive: true });
run("python3", ["-c", canonicalTarScript(), artifact, stage]);
const sha256 = digest(await readFile(artifact));
await writeFile(checksum, `${sha256} ${artifact.split("/").at(-1)}\n`, "utf8");
console.log(JSON.stringify({
ok: true,
patchId,
artifact,
checksum,
sha256,
services: ["nodedc-module-foundry"],
presentation: "provider-neutral-restricted-string-lists",
files,
}, null, 2));
} finally {
await rm(stage, { recursive: true, force: true });
}
async function assertExactSources() {
for (const [relativePath, expected] of Object.entries(expectedSha256)) {
const sourcePath = join(foundryRoot, relativePath);
const info = await lstat(sourcePath);
if (!info.isFile() || info.isSymbolicLink()) {
throw new Error(`foundry_unit_identity_source_unsafe:${relativePath}`);
}
const actual = digest(await readFile(sourcePath));
if (actual !== expected) {
throw new Error(
`foundry_unit_identity_target_mismatch:${relativePath}:`
+ `expected=${expected}:actual=${actual}`,
);
}
}
const profile = await readFile(
join(foundryRoot, "server/map-subject-detail-profile.mjs"),
"utf8",
);
const card = await readFile(
join(foundryRoot, "apps/catalog/src/mapSubjectCard.mjs"),
"utf8",
);
const consumer = await readFile(
join(foundryRoot, "server/foundry-data-product-consumer.mjs"),
"utf8",
);
if (
!profile.includes("string_list")
|| !card.includes("string_list")
|| !consumer.includes("string_array")
|| /gelios\.provider/i.test(profile)
|| /gelios\.provider/i.test(card)
) {
throw new Error("foundry_unit_identity_provider_neutral_boundary_invalid");
}
const policies = JSON.parse(await readFile(
join(foundryRoot, "registry/data-product-consumer-policies.json"),
"utf8",
));
const policy = policies?.policies?.find(
(entry) => entry?.dataProductId === "fleet.units.identity.current.v1",
);
if (
policy?.dataClass !== "restricted"
|| policy?.consumerContract?.fieldTypes?.device_imei !== "string"
|| policy?.consumerContract?.fieldTypes?.custom_fields !== "string_array"
) {
throw new Error("foundry_unit_identity_policy_invalid");
}
}
async function assertFresh(path) {
try {
await lstat(path);
} catch (error) {
if (error?.code === "ENOENT") return;
throw error;
}
throw new Error("artifact_already_exists");
}
function canonicalTarScript() {
return [
"import gzip,io,pathlib,sys,tarfile",
"root=pathlib.Path(sys.argv[2])",
"with open(sys.argv[1],'xb') as out:",
" with gzip.GzipFile(filename='',mode='wb',fileobj=out,compresslevel=9,mtime=0) as gz:",
" with tarfile.open(fileobj=gz,mode='w',format=tarfile.PAX_FORMAT) as tar:",
" for top in ('manifest.env','files.txt','payload'):",
" p=root/top; paths=[p]+(sorted(p.rglob('*')) if p.is_dir() else [])",
" for x in paths:",
" info=tar.gettarinfo(str(x),arcname=x.relative_to(root).as_posix())",
" info.uid=info.gid=0; info.uname=info.gname='root'; info.mtime=0; info.mode=0o755 if info.isdir() else 0o644",
" with (open(x,'rb') if info.isfile() else io.BytesIO()) as src: tar.addfile(info,src if info.isfile() else None)",
].join("\n");
}
function digest(value) {
return createHash("sha256").update(value).digest("hex");
}
function run(command, args) {
const result = spawnSync(command, args, {
encoding: "utf8",
maxBuffer: 64 * 1024 * 1024,
});
if (result.status !== 0) {
throw new Error(`${command}_failed:${result.stderr || result.stdout}`);
}
}