build(foundry): harden map release artifacts
This commit is contained in:
@@ -13,7 +13,7 @@ const foundryRoot = resolve(workspaceRoot, "NODEDC_DESIGN_GUIDELINE");
|
||||
const artifactDir = resolve(
|
||||
process.env.NODEDC_DEPLOY_ARTIFACT_DIR || resolve(scriptDir, "../deploy-artifacts"),
|
||||
);
|
||||
const [patchId = "module-foundry-map-grid-lod-20260805-001", ...extra] =
|
||||
const [patchId = "module-foundry-map-grid-lod-20260805-002", ...extra] =
|
||||
process.argv.slice(2);
|
||||
|
||||
if (extra.length || !/^module-foundry-map-grid-lod-\d{8}-\d{3}$/.test(patchId)) {
|
||||
@@ -28,9 +28,10 @@ const files = Object.freeze([
|
||||
"apps/catalog/src/MapFixturePreview.tsx",
|
||||
"apps/catalog/src/mapGridPolicy.d.mts",
|
||||
"apps/catalog/src/mapGridPolicy.mjs",
|
||||
"package.json",
|
||||
"apps/catalog/src/styles.css",
|
||||
"runtime-seed/page-layouts/map.json",
|
||||
"scripts/map-grid-lod.test.mjs",
|
||||
"scripts/map-object-layers.test.mjs",
|
||||
"server/catalog-server.mjs",
|
||||
"server/foundry-mcp.mjs",
|
||||
]);
|
||||
@@ -69,7 +70,7 @@ try {
|
||||
checksum,
|
||||
sha256,
|
||||
services: ["nodedc-module-foundry"],
|
||||
transition: "five-band-grid-lod-with-seamless-layer-swap",
|
||||
transition: "five-lod-mmap-parity-fast-grid-and-focus-recovery",
|
||||
files,
|
||||
}, null, 2));
|
||||
} finally {
|
||||
@@ -80,31 +81,40 @@ async function assertGridLodBoundary() {
|
||||
const policy = await readFile(join(foundryRoot, "apps/catalog/src/mapGridPolicy.mjs"), "utf8");
|
||||
const renderer = await readFile(join(foundryRoot, "apps/catalog/src/CesiumMapRenderer.tsx"), "utf8");
|
||||
const inspector = await readFile(join(foundryRoot, "apps/catalog/src/MapFixturePreview.tsx"), "utf8");
|
||||
const styles = await readFile(join(foundryRoot, "apps/catalog/src/styles.css"), "utf8");
|
||||
const server = await readFile(join(foundryRoot, "server/catalog-server.mjs"), "utf8");
|
||||
const tests = await readFile(join(foundryRoot, "scripts/map-grid-lod.test.mjs"), "utf8");
|
||||
const focusTests = await readFile(join(foundryRoot, "scripts/map-object-layers.test.mjs"), "utf8");
|
||||
|
||||
for (const marker of ["gridLod1MaxHeightKm", "gridLod5StepKm", "GRID_LOD_HYSTERESIS_RATIO"]) {
|
||||
for (const marker of ["gridLodProfile", "gridLodProfiles", "GRID_LOD_HYSTERESIS_RATIO"]) {
|
||||
if (!policy.includes(marker)) throw new Error(`grid_policy_marker_missing:${marker}`);
|
||||
}
|
||||
for (const marker of ["class GridLayerController", "corridor:", "gridLineDiameterMeters"]) {
|
||||
for (const marker of ["class GridLayerController", "gridLegacyMode", "lineDiameterMeters", "viewer.flyTo(entity"]) {
|
||||
if (!renderer.includes(marker)) throw new Error(`grid_renderer_marker_missing:${marker}`);
|
||||
}
|
||||
if (/function rebuildElevatedGrid[\s\S]*?entities\.removeAll\(\)/.test(renderer)) {
|
||||
throw new Error("grid_renderer_destructive_layer_swap_detected");
|
||||
}
|
||||
for (const marker of ["LOD 5: режим", "3D-линии: диаметр", "Гратикула: толщина"]) {
|
||||
for (const marker of ["LOD ${index + 1}", "Конус видимости 3D", "Размер major-тайла ENU", "Радиус ENU-поля", "Диаметр 3D-линий", "Кружки: диаметр", "Кресты: длина"]) {
|
||||
if (!inspector.includes(marker)) throw new Error(`grid_inspector_marker_missing:${marker}`);
|
||||
}
|
||||
for (const marker of ["gridLod5Mode", "gridLineDiameterMeters", "gridRebuildOnMoveEnd"]) {
|
||||
for (const marker of ["catalog-map-grid-lod-tabs", "flex: 1 1 0"]) {
|
||||
if (!styles.includes(marker)) throw new Error(`grid_styles_marker_missing:${marker}`);
|
||||
}
|
||||
for (const marker of ["gridLodProfiles", "validateGridLodProfiles", "gridRebuildOnMoveEnd"]) {
|
||||
if (!server.includes(marker)) throw new Error(`grid_server_contract_missing:${marker}`);
|
||||
}
|
||||
for (const marker of [
|
||||
"five grid LODs preserve the close 3D and distant graticule contract",
|
||||
"LOD hysteresis holds the previous band around a threshold",
|
||||
"renderer swaps double-buffered data sources and never clears the live grid first",
|
||||
"canonical defaults preserve the exact effective MMAP/MOSCOWMAP five-LOD donor profile",
|
||||
"every LOD owns independent metric and angular spacing and visual fields",
|
||||
"LOD hysteresis holds the previous band for eight percent on either side of a threshold",
|
||||
"renderer uses fixed ENU sectors, angular graticules and a non-blank double-buffer swap",
|
||||
]) {
|
||||
if (!tests.includes(marker)) throw new Error(`grid_regression_missing:${marker}`);
|
||||
}
|
||||
for (const marker of ["void viewer\\.flyTo\\(entity", "HeadingPitchRange\\(0, -0\\.9, 8_000\\)"]) {
|
||||
if (!focusTests.includes(marker)) throw new Error(`map_focus_regression_missing:${marker}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function assertFresh(path) {
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
#!/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-map-focus-recovery-20260805-001", ...extra] =
|
||||
process.argv.slice(2);
|
||||
|
||||
if (extra.length || !/^module-foundry-map-focus-recovery-\d{8}-\d{3}$/.test(patchId)) {
|
||||
throw new Error(
|
||||
"usage: build-module-foundry-map-focus-artifact.mjs "
|
||||
+ "[module-foundry-map-focus-recovery-YYYYMMDD-NNN]",
|
||||
);
|
||||
}
|
||||
|
||||
const files = Object.freeze([
|
||||
"apps/catalog/src/CesiumMapRenderer.tsx",
|
||||
"scripts/map-object-layers.test.mjs",
|
||||
]);
|
||||
const artifact = join(artifactDir, `nodedc-${patchId}.tgz`);
|
||||
const checksum = `${artifact}.sha256`;
|
||||
const stage = await mkdtemp(join(tmpdir(), "nodedc-foundry-map-focus-"));
|
||||
|
||||
await assertFresh(artifact);
|
||||
await assertMapFocusBoundary();
|
||||
|
||||
try {
|
||||
for (const relativePath of files) {
|
||||
const source = join(foundryRoot, relativePath);
|
||||
const info = await lstat(source);
|
||||
if (!info.isFile() || info.isSymbolicLink()) {
|
||||
throw new Error(`source_file_rejected:${relativePath}`);
|
||||
}
|
||||
const destination = join(stage, "payload", relativePath);
|
||||
await mkdir(dirname(destination), { recursive: true });
|
||||
await copyFile(source, 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"],
|
||||
transition: "restore-entity-aware-map-focus-flight",
|
||||
files,
|
||||
}, null, 2));
|
||||
} finally {
|
||||
await rm(stage, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
async function assertMapFocusBoundary() {
|
||||
const renderer = await readFile(join(foundryRoot, files[0]), "utf8");
|
||||
const regression = await readFile(join(foundryRoot, files[1]), "utf8");
|
||||
|
||||
for (const marker of [
|
||||
"void viewer.flyTo(entity, {",
|
||||
"duration: 0.45",
|
||||
"offset: new HeadingPitchRange(0, -0.9, 8_000)",
|
||||
]) {
|
||||
if (!renderer.includes(marker)) throw new Error(`map_focus_renderer_marker_missing:${marker}`);
|
||||
}
|
||||
for (const marker of [
|
||||
"void viewer\\.flyTo\\(entity, \\{",
|
||||
"duration: 0\\.45",
|
||||
"offset: new HeadingPitchRange\\(0, -0\\.9, 8_000\\)",
|
||||
]) {
|
||||
if (!regression.includes(marker)) {
|
||||
throw new Error(`map_focus_regression_marker_missing:${marker}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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],'wb') 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}`);
|
||||
}
|
||||
}
|
||||
@@ -22,9 +22,10 @@ EXPECTED_FILES = (
|
||||
"apps/catalog/src/MapFixturePreview.tsx",
|
||||
"apps/catalog/src/mapGridPolicy.d.mts",
|
||||
"apps/catalog/src/mapGridPolicy.mjs",
|
||||
"package.json",
|
||||
"apps/catalog/src/styles.css",
|
||||
"runtime-seed/page-layouts/map.json",
|
||||
"scripts/map-grid-lod.test.mjs",
|
||||
"scripts/map-object-layers.test.mjs",
|
||||
"server/catalog-server.mjs",
|
||||
"server/foundry-mcp.mjs",
|
||||
)
|
||||
@@ -81,9 +82,16 @@ class ModuleFoundryGridLodArtifactTest(unittest.TestCase):
|
||||
inspector = (payload / EXPECTED_FILES[1]).read_text(encoding="utf-8")
|
||||
policy = (payload / EXPECTED_FILES[3]).read_text(encoding="utf-8")
|
||||
self.assertIn("class GridLayerController", renderer)
|
||||
self.assertIn("gridLineDiameterMeters", renderer)
|
||||
self.assertIn("LOD 5: режим", inspector)
|
||||
self.assertIn("viewer.flyTo(entity", renderer)
|
||||
self.assertIn("lineDiameterMeters", renderer)
|
||||
self.assertIn("LOD ${index + 1}", inspector)
|
||||
self.assertIn("Конус видимости 3D", inspector)
|
||||
self.assertIn("Размер major-тайла ENU", inspector)
|
||||
self.assertIn("Радиус ENU-поля", inspector)
|
||||
self.assertIn("Диаметр 3D-линий", inspector)
|
||||
self.assertIn("Кресты: длина", inspector)
|
||||
self.assertIn("GRID_LOD_HYSTERESIS_RATIO", policy)
|
||||
self.assertIn("gridLodProfiles", policy)
|
||||
|
||||
with tarfile.open(first_artifact, "r:gz") as archive:
|
||||
members = archive.getmembers()
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import hashlib
|
||||
import importlib.machinery
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import tarfile
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
SCRIPT_DIR = Path(__file__).resolve().parent
|
||||
PLATFORM_ROOT = SCRIPT_DIR.parent.parent
|
||||
BUILDER = SCRIPT_DIR / "build-module-foundry-map-focus-artifact.mjs"
|
||||
RUNNER_PATH = SCRIPT_DIR / "nodedc-deploy"
|
||||
PATCH_ID = "module-foundry-map-focus-recovery-20260805-999"
|
||||
EXPECTED_FILES = (
|
||||
"apps/catalog/src/CesiumMapRenderer.tsx",
|
||||
"scripts/map-object-layers.test.mjs",
|
||||
)
|
||||
|
||||
|
||||
def load_runner():
|
||||
loader = importlib.machinery.SourceFileLoader(
|
||||
"nodedc_module_foundry_map_focus_artifact",
|
||||
str(RUNNER_PATH),
|
||||
)
|
||||
spec = importlib.util.spec_from_loader(loader.name, loader)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
RUNNER = load_runner()
|
||||
|
||||
|
||||
class ModuleFoundryMapFocusArtifactTest(unittest.TestCase):
|
||||
def build(self, artifact_dir):
|
||||
environment = os.environ.copy()
|
||||
environment["NODEDC_DEPLOY_ARTIFACT_DIR"] = str(artifact_dir)
|
||||
completed = subprocess.run(
|
||||
["node", str(BUILDER), PATCH_ID],
|
||||
cwd=PLATFORM_ROOT,
|
||||
env=environment,
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
return json.loads(completed.stdout)
|
||||
|
||||
def test_builder_is_deterministic_exact_scope_and_runner_compatible(self):
|
||||
with tempfile.TemporaryDirectory(prefix="nodedc-foundry-map-focus-") as directory:
|
||||
root = Path(directory)
|
||||
first = self.build(root / "first")
|
||||
second = self.build(root / "second")
|
||||
first_artifact = Path(first["artifact"])
|
||||
second_artifact = Path(second["artifact"])
|
||||
|
||||
self.assertEqual(first_artifact.read_bytes(), second_artifact.read_bytes())
|
||||
self.assertEqual(first["sha256"], hashlib.sha256(first_artifact.read_bytes()).hexdigest())
|
||||
self.assertEqual(tuple(first["files"]), EXPECTED_FILES)
|
||||
|
||||
extracted = root / "loaded"
|
||||
extracted.mkdir()
|
||||
manifest, entries, payload = RUNNER.load_artifact(first_artifact, extracted)
|
||||
self.assertEqual(manifest["component"], "module-foundry")
|
||||
self.assertEqual(tuple(entries), EXPECTED_FILES)
|
||||
self.assertEqual(RUNNER.component_services("module-foundry", entries), ("nodedc-module-foundry",))
|
||||
|
||||
renderer = (payload / EXPECTED_FILES[0]).read_text(encoding="utf-8")
|
||||
regression = (payload / EXPECTED_FILES[1]).read_text(encoding="utf-8")
|
||||
self.assertIn("void viewer.flyTo(entity, {", renderer)
|
||||
self.assertIn("offset: new HeadingPitchRange(0, -0.9, 8_000)", renderer)
|
||||
self.assertIn("void viewer\\.flyTo\\(entity, \\{", regression)
|
||||
|
||||
with tarfile.open(first_artifact, "r:gz") as archive:
|
||||
members = archive.getmembers()
|
||||
names = [member.name for member in members]
|
||||
regular_payloads = [
|
||||
archive.extractfile(member).read()
|
||||
for member in members
|
||||
if member.isfile()
|
||||
]
|
||||
self.assertFalse(any(Path(name).name.startswith("._") for name in names))
|
||||
self.assertFalse(any("/.git/" in name or "/node_modules/" in name or "/runtime-data/" in name for name in names))
|
||||
self.assertNotIn(b"-----BEGIN PRIVATE KEY-----", b"\n".join(regular_payloads))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(verbosity=2)
|
||||
Reference in New Issue
Block a user