Test: Soul s1 findings as behavioural tests, red at the h1 head (job ids, seed, link swap) or pinning gates (lease, LD_LIBRARY_PATH, record links, header time, key loss)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
385a7e5733
commit
a9413d4444
3 changed files with 215 additions and 8 deletions
|
|
@ -1,7 +1,7 @@
|
|||
// Stands in for kimodo-resident-worker.py in the daemon's tests. It binds port 0, prints the ready line the
|
||||
// daemon waits for, and answers /health and /generate with what the daemon gave it. The --model value picks a
|
||||
// misbehaviour: crash-before-ready, hang-before-ready, sick, slow-health, stubborn, fail-generate,
|
||||
// refuse-generate, drop-generate, slow-generate, writer (appends to <output>.writes every 50 ms, never answers, ignores SIGTERM), slow-to-stop (no answer; prints a line and exits 1.5 s after SIGTERM), chatty (prints a line the moment it is healthy), encoder (a grandchild, then no answer), graceful (exits 0.5 s after SIGTERM), die-after-ready, bvh-outside (lists a BVH outside the job's directory), bvh-link (lists a symlink as its BVH). A request with bvh writes <output>.bvh (motion/motion_NN.bvh for several samples) and lists it. Any other value is just the model the worker serves.
|
||||
// refuse-generate, drop-generate, slow-generate, writer (appends to <output>.writes every 50 ms, never answers, ignores SIGTERM), slow-to-stop (no answer; prints a line and exits 1.5 s after SIGTERM), chatty (prints a line the moment it is healthy), encoder (a grandchild, then no answer), graceful (exits 0.5 s after SIGTERM), die-after-ready, bvh-outside (lists a BVH outside the job's directory), bvh-link (lists a symlink as its BVH), plant-link (a normal answer with a file symlink and a directory symlink planted beside the BVH). A request with bvh writes <output>.bvh (motion/motion_NN.bvh for several samples) and lists it. Any other value is just the model the worker serves.
|
||||
import http from "node:http";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
|
@ -102,6 +102,13 @@ if (model === "hang-before-ready") {
|
|||
files = [`${payload.output}.npz`, `${payload.output}.bvh`];
|
||||
}
|
||||
}
|
||||
if (model === "plant-link") {
|
||||
const outside = path.join(path.dirname(payload.output), "..", "outside.bvh");
|
||||
writeFileSync(outside, "BVH-OUTSIDE
|
||||
");
|
||||
symlinkSync(outside, `${payload.output}.link`);
|
||||
symlinkSync(path.dirname(outside), `${payload.output}-linkdir`);
|
||||
}
|
||||
send(200, {
|
||||
ok: true,
|
||||
files,
|
||||
|
|
@ -134,6 +141,7 @@ if (model === "hang-before-ready") {
|
|||
LANG: process.env.LANG,
|
||||
LEAK_CHECK: process.env.LEAK_CHECK,
|
||||
},
|
||||
envKeys: Object.keys(process.env).sort(),
|
||||
argv,
|
||||
});
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
import assert from "node:assert/strict";
|
||||
import { spawn } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { chmodSync, copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, symlinkSync, writeFileSync } from "node:fs";
|
||||
import { chmodSync, copyFileSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, symlinkSync, writeFileSync } from "node:fs";
|
||||
import http from "node:http";
|
||||
import net from "node:net";
|
||||
import os from "node:os";
|
||||
|
|
@ -818,13 +818,13 @@ for (let trial = 1; trial <= 10; trial += 1) {
|
|||
}
|
||||
});
|
||||
}
|
||||
const idunnDaemon = async ({ leased = false, extraEnv = {}, loseWhenExists = null } = {}) => {
|
||||
const idunnDaemon = async ({ leased = false, extraEnv = {}, loseWhenExists = null, python = undefined } = {}) => {
|
||||
const root = mkdtempSync(path.join(os.tmpdir(), "vili-test-"));
|
||||
const lease = path.join(root, "lease");
|
||||
const healthLog = path.join(root, "health.log");
|
||||
if (leased) writeFileSync(lease, "");
|
||||
const daemon = await startDaemon({
|
||||
root, nested: true, entry: fakeIdunnEntry, extraEnv: {
|
||||
root, nested: true, entry: fakeIdunnEntry, ...(python ? { python } : {}), extraEnv: {
|
||||
FAKE_IDUNN_LEASE: lease, FAKE_IDUNN_HEALTH_LOG: healthLog, ...extraEnv,
|
||||
...(loseWhenExists ? { FAKE_IDUNN_STATE_ROOT: path.join(root, "a", "b", "state"), FAKE_IDUNN_LOSE_WHEN_EXISTS: loseWhenExists } : {}),
|
||||
},
|
||||
|
|
@ -1174,6 +1174,8 @@ test("the entry derives the daemon's host, port, interpreter and environment ide
|
|||
assert.equal(derived.GAMECULT_IDUNN_CANDIDATE_BIND, "http://127.0.0.1:18861", "cultnet-ts compares the bind to the Expected route's endpoint, which carries the scheme Idunn's bare host:port lacks");
|
||||
assert.equal(derived.VILI_PYTHON, path.join(release, "python", "bin", "python3.12"));
|
||||
assert.equal(derived.VILI_BLENDER, path.join(release, "blender", "blender"));
|
||||
assert.deepEqual(Object.keys(derived).sort(), ["GAMECULT_IDUNN_CANDIDATE_BIND", "VILI_BLENDER", "VILI_DAEMON_HOST", "VILI_DAEMON_PORT", "VILI_PYTHON", "VILI_PYTHON_ENV"],
|
||||
"the entry sets exactly these: no LD_LIBRARY_PATH for the whole unit");
|
||||
assert.equal(derived.VILI_PYTHON_ENV, `locks-sha256:${createHash("sha256").update("build lock bytes\nruntime lock bytes\n").digest("hex")}`);
|
||||
}
|
||||
} finally {
|
||||
|
|
@ -1630,14 +1632,20 @@ test("the artifact read route serves only a job's own FBX and BVH files", async
|
|||
}
|
||||
});
|
||||
|
||||
test("rest-fbx is a job whose FBX is readable", async () => {
|
||||
const pyRoot = mkdtempSync(path.join(os.tmpdir(), "vili-py-"));
|
||||
const python = path.join(pyRoot, "bin", "python3.12");
|
||||
// A worker interpreter whose site-packages carry Kimodo's rest skeleton, as the release's does: the stub worker runs on node.
|
||||
function restPython() {
|
||||
const root = mkdtempSync(path.join(os.tmpdir(), "vili-py-"));
|
||||
const python = path.join(root, "bin", "python3.12");
|
||||
mkdirSync(path.dirname(python), { recursive: true });
|
||||
symlinkSync(process.execPath, python);
|
||||
const skeletons = path.join(pyRoot, "lib", "python3.12", "site-packages", "kimodo", "assets", "skeletons", "somaskel77");
|
||||
const skeletons = path.join(root, "lib", "python3.12", "site-packages", "kimodo", "assets", "skeletons", "somaskel77");
|
||||
mkdirSync(skeletons, { recursive: true });
|
||||
writeFileSync(path.join(skeletons, "somaskel77_standard_tpose.bvh"), "REST-BVH\n");
|
||||
return { root, python };
|
||||
}
|
||||
|
||||
test("rest-fbx is a job whose FBX is readable", async () => {
|
||||
const { root: pyRoot, python } = restPython();
|
||||
const daemon = await startDaemon({ python });
|
||||
try {
|
||||
const answer = await request(daemon.port, "POST", "/motion/rest-fbx", { body: "{}", headers: { "content-type": "application/json" } });
|
||||
|
|
@ -1698,3 +1706,151 @@ test("operator state and the command boundary name the export", async () => {
|
|||
await daemon.stop();
|
||||
}
|
||||
});
|
||||
|
||||
// ---- Findings of Soul's pass s1 on the FBX export (motion-pipeline:verdict:cut-vili-fbx-export.s1).
|
||||
|
||||
const readJson = (file) => JSON.parse(readFileSync(file, "utf8"));
|
||||
const restRequest = (daemon) => request(daemon.port, "POST", "/motion/rest-fbx", { body: "{}", headers: { "content-type": "application/json" } });
|
||||
|
||||
test("concurrent generate and rest-fbx requests never share a job id, a directory, a record or a file", async () => {
|
||||
const rest = restPython();
|
||||
const daemon = await startDaemon({ python: rest.python });
|
||||
try {
|
||||
const answers = [];
|
||||
for (let round = 0; round < 10; round += 1) {
|
||||
answers.push(...await Promise.all([
|
||||
generate(daemon, exportRequest({ clipName: `a${round}` })),
|
||||
generate(daemon, exportRequest({ clipName: `b${round}` })),
|
||||
restRequest(daemon),
|
||||
restRequest(daemon),
|
||||
]));
|
||||
}
|
||||
assert.equal(answers.length, 40);
|
||||
for (const answer of answers) {
|
||||
assert.equal(answer.status, 200, answer.raw.slice(0, 300));
|
||||
assert.equal(answer.body.ok, true);
|
||||
}
|
||||
const ids = answers.map((answer) => answer.body.jobId);
|
||||
assert.equal(new Set(ids).size, 40, "every job has its own id");
|
||||
assert.equal(new Set(answers.map((answer) => answer.body.artifactDir)).size, 40, "and its own directory");
|
||||
assert.deepEqual(readdirSync(path.join(daemon.stateRoot, "artifacts")).sort(), [...ids].sort());
|
||||
assert.deepEqual(readdirSync(path.join(daemon.stateRoot, "jobs")).sort(), ids.map((id) => `${id}.json`).sort(), "and its own record");
|
||||
for (const { body } of answers) {
|
||||
assert.deepEqual(readJson(path.join(daemon.stateRoot, "jobs", `${body.jobId}.json`)), body, "the record is the job's own answer");
|
||||
assert.equal(body.export.clips.length, 1);
|
||||
}
|
||||
const names = answers.filter((answer) => answer.body.jobId.startsWith("vili-")).map((answer) => answer.body.export.clips[0].clipName).sort();
|
||||
assert.deepEqual(names, Array.from({ length: 10 }, (_, round) => [`a${round}`, `b${round}`]).flat().sort(), "each generate job exported its own clip");
|
||||
const first = answers[0].body.jobId;
|
||||
assert.equal((await getArtifact(daemon, `/motion/artifacts/${first}/motion.fbx`)).status, 200, "the read route serves the minted ids");
|
||||
} finally {
|
||||
await daemon.stop();
|
||||
rmSync(rest.root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("a seed that is not an integer from 0 to 2^31 is refused before anything is written, without echoing it", async () => {
|
||||
const daemon = await startDaemon();
|
||||
try {
|
||||
const bad = [7.9, "7", "canary", [], [3], true, -1, 2 ** 31, 1e21, { canary: 1 }];
|
||||
for (const seed of bad) {
|
||||
for (const payload of [exportRequest({ seed }), exportRequest({ meta: { seed } })]) {
|
||||
const answer = await generate(daemon, payload);
|
||||
assert.equal(answer.status, 400, JSON.stringify(payload));
|
||||
assert.ok(!answer.raw.includes("canary"), "the refusal repeated the input");
|
||||
assert.ok(!answer.raw.includes("7.9"), "the refusal repeated the input");
|
||||
}
|
||||
}
|
||||
assert.equal(existsSync(path.join(daemon.stateRoot, "artifacts")), false, "nothing was written");
|
||||
assert.deepEqual(daemon.spawns(), [], "no worker was started");
|
||||
assert.equal(exportStarts(daemon).length, 0);
|
||||
for (const seed of [0, 2 ** 31 - 1]) {
|
||||
const job = (await generate(daemon, exportRequest({ seed }))).body;
|
||||
assert.equal(job.seed, seed);
|
||||
assert.equal(job.worker.seed, seed, "the seed recorded is the seed the worker was given");
|
||||
}
|
||||
} finally {
|
||||
await daemon.stop();
|
||||
}
|
||||
});
|
||||
|
||||
test("a BVH or FBX path swapped for a symlink after the job was checked is never followed", async () => {
|
||||
for (const swap of ["bvh", "fbx", "both"]) {
|
||||
const daemon = await startDaemon();
|
||||
try {
|
||||
const outside = path.join(daemon.root, "outside-secret");
|
||||
const victim = path.join(daemon.root, "victim");
|
||||
writeFileSync(outside, "SECRET");
|
||||
writeFileSync(victim, "VICTIM");
|
||||
// sample 0 ("slow_00") exports for six seconds; the swap lands while it does, before sample 1 is touched
|
||||
const pending = generate(daemon, exportRequest({ clipName: "slow", numSamples: 2 }));
|
||||
await until(() => exportStarts(daemon).length === 1, "the first export to start");
|
||||
const [job] = readdirSync(path.join(daemon.stateRoot, "artifacts"));
|
||||
const motion = path.join(daemon.stateRoot, "artifacts", job, "motion");
|
||||
if (swap !== "fbx") {
|
||||
rmSync(path.join(motion, "motion_01.bvh"));
|
||||
symlinkSync(outside, path.join(motion, "motion_01.bvh"));
|
||||
}
|
||||
if (swap !== "bvh") symlinkSync(victim, path.join(motion, "motion_01.fbx"));
|
||||
const answer = await pending;
|
||||
assert.equal(answer.status, 502, swap);
|
||||
assert.equal(answer.body.ok, false);
|
||||
assert.equal(readFileSync(victim, "utf8"), "VICTIM", `${swap}: nothing was written through the planted link`);
|
||||
assert.equal(readFileSync(outside, "utf8"), "SECRET");
|
||||
for (const name of readdirSync(motion)) {
|
||||
if (name.endsWith(".fbx") && !lstatSync(path.join(motion, name)).isSymbolicLink()) {
|
||||
assert.ok(!readFileSync(path.join(motion, name), "utf8").includes("SECRET"), `${swap}: ${name} holds bytes read through the planted link`);
|
||||
}
|
||||
}
|
||||
assert.ok(!answer.raw.includes("SECRET") && !answer.raw.includes("VICTIM"));
|
||||
} finally {
|
||||
await daemon.stop();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("the worker's environment is its named keys, and LD_LIBRARY_PATH reaches Blender only", async () => {
|
||||
const daemon = await startDaemon({ extraEnv: { LD_LIBRARY_PATH: "/canary-lib" } });
|
||||
try {
|
||||
const job = (await generate(daemon, exportRequest({ clipName: "wave" }))).body;
|
||||
assert.equal(job.ok, true);
|
||||
const named = ["HF_HOME", "HF_HUB_OFFLINE", "TRANSFORMERS_OFFLINE", "VILI_EMBEDDINGS_DIR", "VILI_THREADS", "OMP_NUM_THREADS", "MKL_NUM_THREADS",
|
||||
"PYTHONPATH", "PYTHONDONTWRITEBYTECODE", "PYTHONUNBUFFERED", "VILI_KIMODO_COMMIT", "VILI_PYTHON_ENV"];
|
||||
const forwarded = ["PATH", "HOME", "LANG"].filter((name) => process.env[name] !== undefined || name === "LANG");
|
||||
assert.deepEqual(job.worker.envKeys, [...named, ...forwarded].sort(), "the worker gets exactly these keys, LD_LIBRARY_PATH not among them");
|
||||
const run = daemon.starts().find((start) => start.argv.includes("--"));
|
||||
assert.equal(run.env.LD_LIBRARY_PATH, path.join(daemon.blenderDir, "lib"), "Blender gets the release's libraries, not the host's");
|
||||
} finally {
|
||||
await daemon.stop();
|
||||
}
|
||||
});
|
||||
|
||||
test("the lease goes between rest-fbx's directory and its copy: nothing is copied, nothing is exported", async () => {
|
||||
const rest = restPython();
|
||||
const daemon = await idunnDaemon({ leased: true, loseWhenExists: "artifacts/*", python: rest.python });
|
||||
try {
|
||||
await until(() => existsSync(path.join(daemon.stateRoot, "vili.service.cc")), "the service store", 10);
|
||||
const answer = await restRequest(daemon);
|
||||
assert.equal(answer.status, 503);
|
||||
assert.equal(answer.body.code, "write-lease-lost");
|
||||
for (const job of readdirSync(path.join(daemon.stateRoot, "artifacts"))) {
|
||||
assert.deepEqual(readdirSync(path.join(daemon.stateRoot, "artifacts", job)), [], "the job's directory is empty");
|
||||
}
|
||||
assert.equal(exportStarts(daemon).length, 0);
|
||||
} finally {
|
||||
await daemon.stop();
|
||||
rmSync(rest.root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("the job record lists regular files only: a planted symlink, to a file or to a directory, is not listed", async () => {
|
||||
const daemon = await startDaemon();
|
||||
try {
|
||||
const job = (await generate(daemon, exportRequest({ model: "plant-link", clipName: "plant" }))).body;
|
||||
assert.equal(job.ok, true);
|
||||
assert.equal(readdirSync(job.artifactDir).filter((name) => name.includes("link")).length, 2, "both symlinks are in the job directory");
|
||||
assert.deepEqual(job.files.map((file) => file.name), ["meta.json", "motion.bvh", "motion.fbx", "motion.npz", "request.json"]);
|
||||
} finally {
|
||||
await daemon.stop();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ if action is not None:
|
|||
frames = range(first, last + 3)
|
||||
out["hips_travel"] = max((world("Hips", f) - world("Hips", first)).length for f in frames)
|
||||
out["hips_mid"] = (world("Hips", first + 1 + 15) - world("Hips", first)).length
|
||||
out["hips_curve"] = [list(world("Hips", first + 1 + i)) for i in range(31)]
|
||||
out["root_wander"] = max((world("Root", f) - world("Root", first)).length for f in frames)
|
||||
out["head_from_hips"] = list(world("Head", first + 1 + 15) - world("Hips", first + 1 + 15))
|
||||
if len(argv) > 1:
|
||||
|
|
@ -56,6 +57,7 @@ if action is not None:
|
|||
scene = bpy.context.scene
|
||||
arm = bpy.context.view_layer.objects.active
|
||||
out["reference_head_from_hips"] = list(world("Head", 1 + 15) - world("Hips", 1 + 15))
|
||||
out["reference_hips_curve"] = [list(world("Hips", 1 + i)) for i in range(31)]
|
||||
print("INSPECT " + json.dumps(out))
|
||||
'''
|
||||
|
||||
|
|
@ -100,6 +102,35 @@ def unit_scale_factor(fbx):
|
|||
return struct.unpack("<d", raw[position + 1:position + 9])[0]
|
||||
|
||||
|
||||
def fbx_header_time(fbx):
|
||||
"""The FBXHeaderExtension's CreationTimeStamp fields (Year ... Millisecond), read from a binary FBX. Each is a node
|
||||
whose one property is an int32: name length, name, type code 'I', value."""
|
||||
raw = pathlib.Path(fbx).read_bytes()
|
||||
position = raw.index(b"CreationTimeStamp")
|
||||
fields = []
|
||||
for name in ("Year", "Month", "Day", "Hour", "Minute", "Second", "Millisecond"):
|
||||
tag = bytes([len(name)]) + name.encode()
|
||||
position = raw.index(tag, position) + len(tag)
|
||||
assert raw[position:position + 1] == b"I", name
|
||||
fields.append(struct.unpack("<i", raw[position + 1:position + 5])[0])
|
||||
position += 5
|
||||
return fields
|
||||
|
||||
|
||||
def fbx_key_counts(fbx):
|
||||
"""The key count of every animation curve in a binary FBX: each KeyTime node's one property is an int64 array,
|
||||
whose header is type code 'l', element count, encoding, compressed length."""
|
||||
raw = pathlib.Path(fbx).read_bytes()
|
||||
counts, position = [], 0
|
||||
while True:
|
||||
position = raw.find(b"\x07KeyTime", position)
|
||||
if position < 0:
|
||||
return counts
|
||||
position += len(b"\x07KeyTime")
|
||||
assert raw[position:position + 1] == b"l"
|
||||
counts.append(struct.unpack("<I", raw[position + 1:position + 5])[0])
|
||||
|
||||
|
||||
def rest_bvh():
|
||||
spec = importlib.util.find_spec("kimodo")
|
||||
return pathlib.Path(spec.submodule_search_locations[0]) / "assets" / "skeletons" / "somaskel77" / "somaskel77_standard_tpose.bvh"
|
||||
|
|
@ -145,6 +176,11 @@ class BvhToFbx(unittest.TestCase):
|
|||
self.assertEqual(convert(self.rest, target, "twin").returncode, 0)
|
||||
self.assertEqual(first.read_bytes(), second.read_bytes())
|
||||
|
||||
def test_the_header_is_stamped_with_the_epoch_not_the_clock(self):
|
||||
fbx = self.dir / "epoch.fbx"
|
||||
self.assertEqual(convert(self.rest, fbx, "epoch").returncode, 0)
|
||||
self.assertEqual(fbx_header_time(fbx), [1970, 1, 1, 0, 0, 0, 0])
|
||||
|
||||
def test_without_a_fixed_hash_seed_the_script_exits_3(self):
|
||||
env = export_env()
|
||||
del env["PYTHONHASHSEED"]
|
||||
|
|
@ -176,6 +212,13 @@ class BvhToFbx(unittest.TestCase):
|
|||
self.assertAlmostEqual(seen["hips_travel"], 1.0, delta=0.001, msg=json.dumps(seen))
|
||||
self.assertAlmostEqual(seen["hips_mid"], 0.25, delta=0.002, msg="every key is kept, none simplified away")
|
||||
self.assertLess(seen["root_wander"], 1e-4)
|
||||
for index, (got, want) in enumerate(zip(seen["hips_curve"], seen["reference_hips_curve"])):
|
||||
for axis in range(3):
|
||||
self.assertAlmostEqual(got[axis] - seen["hips_curve"][0][axis], want[axis] - seen["reference_hips_curve"][0][axis],
|
||||
delta=2e-4, msg=f"frame {index} axis {axis}: no key is dropped or resampled")
|
||||
counts = fbx_key_counts(fbx)
|
||||
self.assertTrue(counts, "the FBX carries animation curves")
|
||||
self.assertEqual(set(counts), {frames}, "every curve keeps one key per BVH frame, none simplified away")
|
||||
for got, want in zip(seen["head_from_hips"], seen["reference_head_from_hips"]):
|
||||
self.assertAlmostEqual(got, want, delta=0.002, msg="the rotated pose is Blender's own native reading of the BVH")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue