Compare commits

...
1 Commits
Author SHA1 Message Date
shinyobjectz 36298b4166 A video's scene reading is kept beside it, and a kept reading isn't the work changing
A cut checked at its render was read again at publish and again at done, 30 s a file each time: a done check of 11 files took 334 s. And a done check that heard a cut's words wrote them beside it, so the critic's verdict of a minute before read as older than the work and every says rule failed again.
2026-12-01 18:45:58 -08:00
4 changed files with 59 additions and 3 deletions

No files matched your search

+18
View File
@@ -208,10 +208,23 @@ export async function words(file: string, anyAge = false): Promise<Word[]> {
/** frames read a second for the scene, and the width they're read at (places are in shares of the picture) */
export const RATE = 2
const SIDE = 540
/** a video's scene reading, kept beside it */
export const SCENE_EXT = "scene.json"
/** what's in a file's frames (`at`: those seconds, else RATE a second): each frame's faces and seams, and its scene
* (people, faces, things, words in the shot) for placement. The farm reads them; with no farm here, Unmet */
export async function scene(file: string, at?: number[]): Promise<{ rate: number; faces: Faces[]; scenes: Scene[] }> {
// a video's whole reading is kept beside it, as its words are, and read again only when the file is newer: a cut
// checked at its render was read again at publish and again at done, 30 s a file each time, so a done check of 11
// files took 334 s (12-01)
const whole = !at?.length && !/\.(png|jpe?g|webp)$/i.test(file)
if (whole) {
const kept = freshBeside(file, SCENE_EXT)
try {
const k = kept ? (JSON.parse(readFileSync(kept, "utf8")) as { rate: number; side: number; faces: Faces[]; scenes: Scene[] }) : null
if (k && k.rate === RATE && k.side === SIDE && Array.isArray(k.scenes) && k.scenes.length) return { rate: k.rate, faces: k.faces, scenes: k.scenes }
} catch {}
}
if (!farm()) throw new Unmet(`no scene reader on this machine for ${path.basename(file)} (people, faces and things are read by raea cloud's farm: set RAEA_CLOUD_GPU_URL)`)
const dir = mkdtempSync(path.join(os.tmpdir(), "raea-scene-"))
try {
@@ -238,6 +251,11 @@ export async function scene(file: string, at?: number[]): Promise<{ rate: number
scenes.push({ w: g.w, h: g.h, grid: g.grid, things: g.things ?? [], faces: fs, ...(Array.isArray(g.texts) ? { texts: g.texts } : {}) } as Scene)
}
}
if (whole && scenes.length) {
try {
writeFileSync(`${stem(file)}.${SCENE_EXT}`, `${JSON.stringify({ rate: RATE, side: SIDE, faces, scenes })}\n`)
} catch {}
}
return { rate: at?.length ? 0 : RATE, faces, scenes }
} finally {
rmSync(dir, { recursive: true, force: true })
+6 -1
View File
@@ -19,6 +19,11 @@ export const TIMEOUT = 300
/** folders that aren't the work: what the job writes about itself, and what tools keep */
const NOT_WORK = new Set(["review", ".git", "node_modules", ".raea", "target", ".cache", ".raea-cloud"])
/** what a check keeps beside a file it read (its report, its words, its scene): a reading of the work, not a change
* to it. A done check that heard a cut's words wrote them beside it, and the critic's verdict of a minute before read
* as older than the work (12-01) */
const READING = /\.(check|words|scene)\.json$/
/** when the work last changed (ms): the newest file under dir, its own bookkeeping left out (a bounded walk) */
export function newest(dir: string): number | null {
let best: number | null = null
@@ -43,7 +48,7 @@ export function newest(dir: string): number | null {
}
if (st.isDirectory()) {
if (!(d === dir && NOT_WORK.has(name)) && name !== "node_modules" && name !== ".git") stack.push(p)
} else if (st.isFile() && name !== "NOTES.md" && !name.endsWith(".check.json")) best = Math.max(best ?? 0, st.mtimeMs)
} else if (st.isFile() && name !== "NOTES.md" && !READING.test(name)) best = Math.max(best ?? 0, st.mtimeMs)
}
}
return best
+13 -1
View File
@@ -1,7 +1,7 @@
// The rule packs (MK29, ported from Rust's goal gate tests): run rules pass or say why, says rules need a fresh critic;
// any goal carries rules.
import { expect, test } from "bun:test"
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs"
import { mkdirSync, mkdtempSync, utimesSync, writeFileSync } from "node:fs"
import { tmpdir } from "node:os"
import path from "node:path"
import { clefVerdict, lastVerdict, newest } from "../src/packs/goal.ts"
@@ -80,3 +80,15 @@ test("clef judges a rule on the file it names, else on every video made, and say
const empty = mkdtempSync(path.join(tmpdir(), "raea-goal-clef-"))
expect(clefVerdict(g, empty, () => []).all?.why).toContain("names no file on disk")
})
test("a reading kept beside a file isn't the work changing", () => {
const d = mkdtempSync(path.join(tmpdir(), "raea-newest-"))
mkdirSync(path.join(d, "out/cuts"), { recursive: true })
const cut = path.join(d, "out/cuts/a_b_c_v1_9x16.mp4")
writeFileSync(cut, "x")
utimesSync(cut, 1000, 1000)
for (const ext of ["words.json", "scene.json", "check.json"]) writeFileSync(path.join(d, `out/cuts/a_b_c_v1_9x16.${ext}`), "{}")
expect(newest(d)).toBe(1_000_000)
writeFileSync(path.join(d, "out/cuts/a_b_c_v1_9x16.render.json"), "{}")
expect(newest(d)!).toBeGreaterThan(1_000_000)
})
+22 -1
View File
@@ -1,6 +1,9 @@
import { test } from "bun:test"
import assert from "node:assert/strict"
import { readFileSync } from "node:fs"
import { mkdtempSync, readFileSync, writeFileSync } from "node:fs"
import { tmpdir } from "node:os"
import path from "node:path"
import { RATE, scene, SCENE_EXT, useSender } from "../src/media.ts"
import { placeReport, textOver } from "../src/packs/place.ts"
test("the place pack's model", async () => {
@@ -43,3 +46,21 @@ test("the place pack's model", async () => {
ok("a caption over a person who fills the frame is at most a warning")
})
test("a video's scene reading is kept beside it and read again only when the video is newer", async () => {
const d = mkdtempSync(path.join(tmpdir(), "raea-scene-kept-"))
const cut = path.join(d, "a_b_c_v1_9x16.mp4")
writeFileSync(cut, "not a real video")
const kept = { rate: RATE, side: 540, faces: [null], scenes: [{ w: 540, h: 960, grid: { cols: 1, rows: 1, people: ["0"] }, things: [], faces: [] }] }
writeFileSync(path.join(d, `a_b_c_v1_9x16.${SCENE_EXT}`), JSON.stringify(kept))
let asked = 0
useSender(async () => (asked++, { status: 500, ok: false, text: "" }))
delete process.env.RAEA_CLOUD_GPU_URL
// no farm here at all, and the reading still comes back: from beside the file
const r = await scene(cut)
assert.equal(r.scenes.length, 1)
assert.equal(r.rate, RATE)
assert.equal(asked, 0)
// a reading at named seconds is never the whole file's
await assert.rejects(scene(cut, [1, 2]), /no scene reader/)
})