Files
raea/sdk/cloud/test/units.ts
shinyobjectz 1a913e6b06 raea frames check on raea cloud boxes: what a cut's pictures get wrong that a viewer sees at once, measured (11-25, Shane on StreetTalk's cuts: "it cuts out faces all the time and also does split frame shots when they make no sense", "it makes text too small on some things, we should have a text/glyph readability check and measurement").
Faces: the export's frames, two a second, go through the farm's new POST /v1/faces (OpenCV's YuNet, 232 KB on CPU, pinned by hash). A box has no vision backend (raea-perceive isn't in raea's Linux build), so raea frame and framing="face" refuse there. A face of someone in the shot touching the frame's edge or a split screen's seam for a second or more is an error; a split screen showing a face in only one half is a warning. Seams are lone lines where the picture jumps across 70% of the frame, held a second, in its middle 60% (a caption's box is two lines close together and doesn't count).

Text: every text's font size from the render's manifest, scaled to a 1080-wide frame: under 40 px is an error, under 48 px a warning.

offload.ts adds --manifest OUT.render.json to a video render that has none and runs the check after the words pass; an error fails the render. OUT.despite.txt says why a face at the edge is meant and turns its errors to warnings. image/raea.sh routes raea frames.

Checked on StreetTalk's delivered cuts: The Body Shop 5 and 6 and Dutch 2, 3 and 4 fail on faces cut at the edge (1 to 6.5 s each), and Dutch 4 on a face cut by a split's seam; a 28 px disclaimer fails a render on raea-2. test/units.ts covers the rules. Farm deployed; the three files copied onto raea-2.
2026-11-26 10:29:22 -08:00

138 lines
8.2 KiB
TypeScript

// raea cloud's pure parts, checked without a container: node test/units.ts
// (gpu.ts reads vulkaninfo's summary and picks the device; offload.ts plans which project a render sends and how its
// paths read on the worker)
import assert from "node:assert/strict"
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"
import os from "node:os"
import path from "node:path"
import { parseSummary, pick } from "../server/gpu.ts"
import { cutFaces, smallText, splitsOf } from "../server/frames.ts"
import { plan, projectRoot } from "../server/offload.ts"
import { shellEnv } from "../server/shell-os.ts"
import { landedQuery, linkIn, packCredential, unpackCredential } from "../server/google-token.ts"
const L4 = `Devices:
========
GPU0:
apiVersion = 1.3.289
driverVersion = 580.95.5.0
vendorID = 0x10de
deviceID = 0x27b8
deviceType = PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
deviceName = NVIDIA L4
driverID = DRIVER_ID_NVIDIA_PROPRIETARY
driverName = NVIDIA
driverInfo = 580.95.05
GPU1:
apiVersion = 1.4.305
vendorID = 0x10005
deviceType = PHYSICAL_DEVICE_TYPE_CPU
deviceName = llvmpipe (LLVM 19.1.7, 256 bits)
driverName = llvmpipe
driverInfo = Mesa 25.0.7-2 (LLVM 19.1.7)
`
const gpus = parseSummary(L4)
assert.equal(gpus.length, 2)
assert.deepEqual(gpus[0], { name: "NVIDIA L4", type: "discrete", driver: "NVIDIA 580.95.05", vendor: "0x10de" })
assert.equal(gpus[1].type, "cpu")
assert.deepEqual(pick(gpus), { renders: "gpu", name: "NVIDIA L4" })
assert.deepEqual(pick([gpus[1]]), { renders: "cpu", name: "llvmpipe (LLVM 19.1.7, 256 bits)" })
assert.deepEqual(pick([]), { renders: "cpu", name: "llvmpipe" })
const root = mkdtempSync(path.join(os.tmpdir(), "raea-units-"))
try {
const proj = path.join(root, "work", "card")
mkdirSync(path.join(proj, "scenes"), { recursive: true })
writeFileSync(path.join(proj, "package.json"), "{}")
writeFileSync(path.join(proj, "scenes", "edit.tsx"), "")
writeFileSync(path.join(proj, "words.json"), "[]")
writeFileSync(path.join(root, "work", "elsewhere.json"), "[]")
const work = path.join(root, "work")
// the composition's project is the nearest folder above it with a project's files
assert.equal(projectRoot("card/scenes/edit.tsx", work, root), proj)
// from the workspace root: paths made relative to the project, the flags' values left alone
assert.deepEqual(plan(["render", "card/scenes/edit.tsx", "-o", "card/out/x.mp4", "--frames", "30"], work), {
root: proj,
args: ["render", "scenes/edit.tsx", "-o", "out/x.mp4", "--frames", "30"],
moves: [],
})
// an output outside the project is written at its top as .raea-cloud-out-N-NAME (no folder to make) and moved after
const p = plan(["render", "scenes/edit.tsx", "-o", "/tmp/x.mp4", "--words", "words.json"], proj)
assert.ok(typeof p !== "string")
assert.deepEqual(p.args, ["render", "scenes/edit.tsx", "-o", ".raea-cloud-out-0-x.mp4", "--words", "words.json"])
assert.deepEqual(p.moves, [{ from: ".raea-cloud-out-0-x.mp4", to: "/tmp/x.mp4" }])
// an input outside the project can't go
assert.match(plan(["render", "scenes/edit.tsx", "-o", "x.mp4", "--words", "../elsewhere.json"], proj) as string, /outside the project/)
// no composition: nothing to send
assert.match(plan(["render", "--help"], proj) as string, /names no composition/)
// RAEA_CLOUD_GPU_ROOT widens what's sent
assert.equal((plan(["render", "card/scenes/edit.tsx", "-o", "x.mp4", "--words", "elsewhere.json"], work, ".") as { root: string }).root, work)
} finally {
rmSync(root, { recursive: true, force: true })
}
// the box's shell on Windows: its own folder first on PATH, whatever case Windows gave the name; untouched elsewhere
assert.deepEqual(shellEnv({ Path: "C:\\w" }, true, "C:\\g\\usr\\bin\\sh.exe"), { Path: "C:\\g\\usr\\bin;C:\\w" })
assert.deepEqual(shellEnv({ PATH: "C:\\w" }, true, "bash"), { PATH: "C:\\w" })
assert.deepEqual(shellEnv({ PATH: "/usr/bin" }, false, "/bin/bash"), { PATH: "/usr/bin" })
console.log("units: ok")
// google-token.ts: Antigravity's Google sign-in link, the address the browser lands on, the credential's files
{
const out = `I1124 credential_manager.py:561] Launching browser login flow...\nhttps://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=x.apps.googleusercontent.com&redirect_uri=http%3A%2F%2F127.0.0.1%3A54616%2F&state=abc123&access_type=offline\n`
const l = linkIn(out)!
assert.equal(l.port, 54616)
assert.equal(l.state, "abc123")
assert.equal(linkIn("https://accounts.google.com/o/oauth2/v2/auth?redirect_uri=https%3A%2F%2Fevil.example%2F&state=x"), undefined, "a link back anywhere but this box is refused")
assert.equal(landedQuery("http://127.0.0.1:54616/?state=abc123&code=4/0Ab&scope=email", l), "/?state=abc123&code=4/0Ab&scope=email")
assert.throws(() => landedQuery("http://127.0.0.1:54616/?state=other&code=4/0Ab", l), /another sign-in/)
assert.throws(() => landedQuery("http://127.0.0.1:9999/?state=abc123&code=4/0Ab", l), /isn't the page/)
assert.throws(() => landedQuery("http://127.0.0.1:54616/?state=abc123", l), /no code/)
assert.throws(() => landedQuery("http://127.0.0.1:54616/?error=access_denied&state=abc123", l), /access_denied/)
assert.throws(() => landedQuery("4/0Ab-just-a-code", l), /whole address/)
const home = mkdtempSync(path.join(os.tmpdir(), "units-gemini-"))
mkdirSync(path.join(home, "antigravity-acp"), { recursive: true })
writeFileSync(path.join(home, "antigravity-acp", "oauth.json"), '{"refresh_token":"1//x","email":"[email protected]"}')
writeFileSync(path.join(home, "antigravity-acp", "settings.json"), '{"theme":"dark"}')
const c = packCredential(home)!
assert.ok(c.startsWith("agy1:"))
assert.deepEqual(Object.keys(JSON.parse(Buffer.from(c.slice(5), "base64").toString())), ["antigravity-acp/oauth.json"], "only the token file goes")
const other = mkdtempSync(path.join(os.tmpdir(), "units-gemini-"))
unpackCredential(c, other)
assert.equal(packCredential(other), c)
assert.throws(() => unpackCredential(`agy1:${Buffer.from(JSON.stringify({ "../../etc/x": "y" })).toString("base64")}`, other), /outside its folder/)
rmSync(home, { recursive: true, force: true })
rmSync(other, { recursive: true, force: true })
console.log("ok google-token")
}
{
// frames.ts: a face at the frame's edge for a second is an error, for half a second a warning; a face too small to be
// someone in the shot is left alone
const fr = (faces: number[][], seams: [string, number, number][] = []) => ({ w: 540, h: 960, faces, seams })
const edge = [0, 400, 40, 90, 0.9]
const whole = [200, 300, 80, 100, 0.9]
let f = cutFaces([fr([whole]), fr([edge]), fr([edge]), fr([whole]), fr([edge]), fr([[0, 50, 10, 12, 0.9]])])
assert.deepEqual(f.map((x) => [x.level, x.at, x.until]), [["error", 0.5, 1.5], ["warn", 2, 2.5]])
assert.match(f[0].says, /left edge/)
// a split screen: a lone line held; a caption's box (two lines close together) isn't one
assert.deepEqual(splitsOf(fr([], [["h", 480, 0.8]])), [{ axis: "h", at: 480 }])
assert.deepEqual(splitsOf(fr([], [["h", 446, 0.8], ["h", 513, 0.8]])), [])
assert.deepEqual(splitsOf(fr([], [["h", 60, 0.9]])), [], "near the edge: a letterbox or a header")
const seam: [string, number, number][] = [["h", 480, 0.8]]
f = cutFaces([fr([[200, 430, 80, 50, 0.9]], seam), fr([[200, 430, 80, 50, 0.9]], seam), fr([[200, 430, 80, 50, 0.9]], seam)])
assert.ok(f.some((x) => x.kind === "face-cut" && /seam/.test(x.says) && x.level === "error"))
f = cutFaces([fr([[200, 200, 80, 100, 0.9]], seam), fr([[200, 200, 80, 100, 0.9]], seam), fr([[200, 200, 80, 100, 0.9]], seam)])
assert.deepEqual(f.map((x) => x.kind), ["split"], "one face over a split: a split for nothing")
f = cutFaces([0, 1, 2].map(() => fr([[200, 200, 80, 100, 0.9], [200, 650, 80, 100, 0.9]], seam)))
assert.deepEqual(f, [], "two people, one each side")
// text sizes in pixels of a 1080-wide frame: a 720-wide render's 28 px is 42 px
const m = (w: number, size: number) => ({ width: w, height: (w * 16) / 9, fps: 30, frames: [{ frame: 0, text: [{ text: "Not for surgeries", size, opacity: 1 }] }] })
assert.equal(smallText(m(1080, 28))[0].level, "error")
assert.equal(smallText(m(720, 28))[0].level, "warn")
assert.deepEqual(smallText(m(1080, 64)), [])
console.log("ok frames")
}