Compare commits

...
13 changed files with 385 additions and 19 deletions

No files matched your search

+4
View File
@@ -60,6 +60,10 @@ RUN curl -fsSL -o /opt/yunet.onnx https://media.githubusercontent.com/media/open
# goal.ts named-imports spawn, which raea's runtime hasn't got, and every raea goal check on a box died (raea #329)
RUN f=/opt/raea/share/raea/sdk/goal/src/packs/goal.ts; \
if grep -q 'import { spawn } from "node:child_process"' "$f"; then cp image/sdk-overlay/goal/src/packs/goal.ts "$f" && echo "overlay: goal.ts"; fi
# 12-06: 0.1.17-rc5's CTA check read "Dutch.com" and "$60" heard as one word each against the brief's two, so a CTA said
# whole was an ERROR (raea #367)
RUN f=/opt/raea/share/raea/sdk/goal/src/packs/cut.ts; \
if grep -q 'const spoken = words.map((w) => norm(w.text)).filter(Boolean)' "$f"; then cp image/sdk-overlay/goal/src/packs/cut.ts "$f" && echo "overlay: cut.ts"; fi
COPY deploy/git deploy/git
COPY deploy/fly/start.sh image/fly-start.sh
# readable by raea whatever modes the files had where the image was built (12-03: a checkout made with umask 077 gave
+3 -1
View File
@@ -83,7 +83,9 @@ export default function Title({ children, region = "top", size = 64, style, face
fontWeight: 800,
fontSize: size,
lineHeight: 1.1,
color: "var(--brand-text, #fff)",
// white on its own dark plate, as raea's captions are (brand.ts CAPTION): never the website's text colour, which
// is dark for a light page (12-06, Dutch on rc5: every hook black on the plate, 1.3:1, five floor errors)
color: "#fff",
// a dark plate, as raea's captions have: a hook over a beige coat or a sky read under 3:1 with a shadow alone
background: "rgba(0,0,0,0.6)",
padding: `${Math.round(px * 0.08)}px ${Math.round(px * 0.3)}px`,
@@ -0,0 +1,240 @@
// The cut packs (docs/goal.feature MK25-MK27, MK38; Rust's cut gates until 11-29, now here alone): a client's brief as rules
// (`goal: cut({ cut: {...} })`), held from what's on disk and heard, never from what the agent says.
// quotes every rule's `from` is in the brief's text, word for word
// count as many cuts as the brief asks for, or an `open` item about "count" a person answered
// open each open item answered, with who answered it
// shape each delivered cut in its format and length
// say every phrase each cut must say, heard or shown; `every: false` phrases once across the cuts
// never no banned phrase heard or shown
// cta each cut ends on the CTA (in its last `within` seconds, 8 by default), heard or shown
import { existsSync, readdirSync, readFileSync } from "node:fs"
import path from "node:path"
import { check, found } from "raea/check"
import type { CutGoal, CutPlan } from "raea/brief.gen"
import type { FileFacts, Job, Manifest } from "../facts.ts"
import { has, inOrder, joined, norm, SAY_GAP, saidAt } from "../text.ts"
import { quote } from "../text.ts"
import { asDigits } from "./numbers.ts"
export const CTA_WITHIN = 8
/** how much of the CTA a run of words must have, in order */
export const CTA_SHARE = 0.85
export const ratio = (f: string): [number, number] | null => {
const [w, h] = f.split(":").map((x) => Number(x.trim()))
return w > 0 && h > 0 ? [w, h] : null
}
export const formatsOf = (c: CutGoal, p: CutPlan) => (p.formats?.length ? p.formats : (c.formats ?? []))
export const secondsOf = (c: CutGoal, p: CutPlan) => p.seconds ?? c.seconds ?? null
/** where a cut lands: out/cuts/ID_WxH.mp4 */
export const fileOf = (p: CutPlan, format: string) => `out/cuts/${p.id}_${format.replace(":", "x")}.mp4`
export const deliverables = (c: CutGoal) => (c.cuts ?? []).flatMap((p) => formatsOf(c, p).map((f) => fileOf(p, f)))
/** every rule and the brief's words it quotes */
export function quotes(c: CutGoal): [string, string][] {
const q: [string, string][] = []
if (c.count) q.push(["count", c.count.from])
for (const [what, list] of [["say", c.say ?? []], ["never", c.never ?? []]] as const) for (const p of list) q.push([`${what} "${p.text}"`, p.from])
if (c.cta) {
q.push(["cta", c.cta.from])
for (const line of c.cta.also ?? []) q.push([`cta "${line}"`, line])
}
for (const o of c.open ?? []) q.push([`open "${o.question}"`, o.from])
return q
}
/** the cut a delivered file is, and its format, when it's one of the brief's */
export function cutOf(c: CutGoal, rel: string): { plan: CutPlan; format: string } | null {
for (const p of c.cuts ?? []) for (const format of formatsOf(c, p)) if (fileOf(p, format) === rel) return { plan: p, format }
return null
}
/** what a file shows: each text of its render manifest, normed, and the second it's first on screen */
export function shown(m: Manifest | null): [string, number][] {
if (!m) return []
const fps = m.fps && m.fps > 0 ? m.fps : 30
const out: [string, number][] = []
for (const fr of m.frames ?? [])
for (const t of fr.text ?? []) {
const s = norm(t.text ?? "")
if (s && (t.opacity ?? 1) > 0.05 && !out.some(([o]) => o === s)) out.push([s, fr.frame / fps])
}
return out
}
/** what each frame from `from` (s) on shows, its texts read together in the order drawn: an end card draws its CTA as
* lines (12-04, Elfster run 4: "Make your Wishlist and organize your Gift Exchange on Elfster." over "It's free.", each
* alone under the CTA's share, and a cut ending on its CTA was failed for none) */
export function shownTogether(m: Manifest | null, from: number): string[] {
if (!m) return []
const fps = m.fps && m.fps > 0 ? m.fps : 30
const out = new Set<string>()
for (const fr of m.frames ?? []) {
if (fr.frame / fps < from) continue
const s = (fr.text ?? []).filter((t) => (t.opacity ?? 1) > 0.05).map((t) => norm(t.text ?? "")).filter(Boolean).join(" ")
if (s) out.add(s)
}
return [...out]
}
const cutJob = (j: Job) => (j.contract?.kind === "cut" ? (j.contract.cut ?? null) : null)
const cutFile = (f: FileFacts) => {
const c = f.contract?.kind === "cut" ? f.contract.cut : undefined
const at = c ? cutOf(c, f.path) : null
return c && at ? { c, ...at } : null
}
/** what a cut says and shows */
async function heardOf(f: FileFacts) {
// numbers said in words as the brief writes them ("pets sixty" is PETS60, "sixty dollars" $60): 12-05, Dutch run 10
// one word heard can be two as the brief writes it, and the brief's line is split on its spaces: "Dutch.com" is "dutch
// com", "$60" is "60 dollars" (12-06, Dutch: the whole CTA said, read as 73% of it, so every such cut was an ERROR)
const words = asDigits(await f.words()).flatMap((w) => norm(w.text).split(" ").filter(Boolean).map((text) => ({ ...w, text })))
return { spoken: words.map((w) => w.text), times: words, screen: shown(f.manifest) }
}
const onScreen = (s: string, p: string, gap: number) => saidAt(s.split(" "), p, gap) !== null
export const quotesPack = check<Job>({ id: "quotes", text: "every rule quotes the brief's own words", over: "job", at: ["edit", "done"] }, async (j) => {
const c = cutJob(j)
if (!c) return
const file = path.resolve(j.root, c.brief)
if (!existsSync(file)) return found({ says: `no brief text at ${c.brief}: pdftotext -layout BRIEF.pdf ${c.brief}`, fix: `pdftotext -layout BRIEF.pdf ${c.brief}` })
const text = norm(readFileSync(file, "utf8"))
const unfound = quotes(c).filter(([, from]) => !has(text, norm(from)))
if (unfound.length) found({ says: `not in the brief's text, word for word: ${unfound.map(([what, from]) => `${what} ("${quote(from, 60)}")`).join("; ")}` })
})
export const countPack = check<Job>({ id: "count", text: "as many cuts as the brief asks for, or a person's answer saying why not", over: "job", at: ["edit", "done"] }, async (j) => {
const c = cutJob(j)
if (!c?.count) return
const have = c.cuts?.length ?? 0
if (have >= c.count.value) return
// answered: it holds nothing here, but it's said, so raea cloud can show a person a brief made smaller by an answer
// the agent may have written itself (the brief is gospel: only a person lowers its numbers)
const answer = (c.open ?? []).find((o) => o.about === "count" && o.answer?.trim())
if (answer) return found({ level: "note", says: `${have} of the brief's ${c.count.value} cuts, as answered: ${answer.answer}${answer.by ? ` (${answer.by})` : ""}` })
found({ says: `${have} cuts planned; the brief asks for ${c.count.value} ("${c.count.from}"): plan them, or add an \`open\` item about "count" and have a person answer it` })
})
export const openPack = check<Job>({ id: "open", text: "every open item answered by a person", over: "job", at: ["publish", "done"] }, async (j) => {
for (const o of cutJob(j)?.open ?? []) if (!o.answer?.trim()) found({ says: `unanswered: ${o.question} (brief: "${o.from}"): ask at the review, then write the answer and who gave it`, about: o.about ? [o.about] : [] })
})
export const shapePack = check<FileFacts>({ id: "shape", text: "each cut in its format and length", over: "file", at: ["render", "publish", "done"] }, async (f) => {
const at = cutFile(f)
if (!at) return
const want = ratio(at.format)
if (!f.width || !f.height) return found({ says: "not an MP4 or MOV with a video track" })
const wrong: string[] = []
if (want && Math.abs(f.width / f.height / (want[0] / want[1]) - 1) > 0.02) wrong.push(`${f.width}x${f.height} isn't ${at.format}`)
const len = secondsOf(at.c, at.plan)
if (len && f.seconds !== null && (f.seconds + 0.05 < len[0] || f.seconds > len[1] + 0.05)) wrong.push(`${f.seconds.toFixed(1)} s isn't ${len[0]}-${len[1]} s`)
if (wrong.length) found({ says: wrong.join("; ") })
})
export const sayPack = check<FileFacts>({ id: "say", text: "every phrase the brief says each cut says, heard or shown", over: "file", at: ["render", "publish", "done"], needs: "words" }, async (f) => {
const at = cutFile(f)
if (!at?.c.say?.length) return
const { spoken } = await heardOf(f)
const together = shownTogether(f.manifest, 0)
const on = (p: string) => saidAt(spoken, p, SAY_GAP) !== null || together.some((s) => onScreen(s, p, SAY_GAP))
const missing = at.c.say.filter((p) => p.every !== false && !on(norm(p.text)))
if (missing.length) found({ says: `never says or shows: ${missing.map((m) => `"${m.text}"`).join(", ")}` })
})
export const neverPack = check<FileFacts>({ id: "never", text: "no banned phrase heard or shown", over: "file", at: ["render", "publish", "done"], needs: "words" }, async (f) => {
const at = cutFile(f)
if (!at?.c.never?.length) return
const { spoken, times, screen } = await heardOf(f)
for (const p of at.c.never) {
const n = norm(p.text)
const i = saidAt(spoken, n, 1)
if (i !== null) {
found({ says: `"${p.text}" heard at ${times[i].start.toFixed(1)} s (brief: ${p.from})`, seconds: times[i].start })
continue
}
const s = screen.find(([s]) => onScreen(s, n, 1))
if (s) found({ says: `"${p.text}" on screen at ${s[1].toFixed(1)} s (brief: ${p.from})`, seconds: s[1] })
}
})
export const ctaPack = check<FileFacts>({ id: "cta", text: "each cut ends on the CTA", over: "file", at: ["render", "publish", "done"], needs: "words" }, async (f) => {
const at = cutFile(f)
const cta = at?.c.cta
if (!cta) return
const { times } = await heardOf(f)
const within = cta.within ?? CTA_WITHIN
const end = f.seconds ?? times[times.length - 1]?.end ?? 0
const last = times.filter((w) => w.end >= end - within).map((w) => norm(w.text))
const share = (line: string, got: string[]) => {
const want = norm(line).split(" ")
return inOrder(want, joined(got, want).map(([w]) => w))
}
const lines = [cta.text, ...(cta.also ?? [])]
const heard = lines.map((l) => share(l, last))
const best = Math.max(0, ...heard)
const line = best > 0 ? lines[heard.indexOf(best)] : cta.text
// said and shown together: 12-05, Dutch run 10, the host said "use code PETS60 for sixty dollars off your first" as the
// end card showed "Code PETS60: $60 off your first year", and neither alone was 85% of the line
const late = shownTogether(f.manifest, end - within)
const shownLate = late.some((s) => lines.some((l) => share(l, s.split(" ")) >= CTA_SHARE || share(l, [...last, ...s.split(" ")]) >= CTA_SHARE || share(l, [...s.split(" "), ...last]) >= CTA_SHARE))
if (best < CTA_SHARE && !shownLate) {
// the takes that say it, so the fix is one `raea cut` away (12-05, a street interview run: every cut ended on a host take
// that says "download the app", while two other takes say the brief's "Go to the site" line word for word)
const takes = takesSaying(f.root, lines)
const where = takes.length ? `; said in ${takes.map((t) => `${t.take} at ${t.at.toFixed(1)} s`).join(", ")}: cut it from there` : "; no take says it: show it on the end card"
found({ says: `no CTA in its last ${within.toFixed(0)} s (${(best * 100).toFixed(0)}% of the nearest one's words heard there): "${line}"${where}`, seconds: [Math.max(0, end - within), end] })
}
})
/** the takes in footage/ whose words say one of `lines` (CTA_SHARE of its words in order, inside a window a little longer
* than it), the closest first, three at most */
export function takesSaying(root: string, lines: string[]): { take: string; at: number; share: number }[] {
const dir = path.join(root, "footage")
if (!existsSync(dir)) return []
const out: { take: string; at: number; share: number }[] = []
let names: string[] = []
try {
names = readdirSync(dir).filter((n) => n.endsWith(".words.json"))
} catch {
return []
}
const wants = lines.map((l) => norm(l).split(" ").filter(Boolean)).filter((w) => w.length)
for (const n of names) {
let ws: { text: string; start_ms: number; end_ms?: number }[] = []
try {
ws = JSON.parse(readFileSync(path.join(dir, n), "utf8"))
} catch {
continue
}
if (!Array.isArray(ws)) continue
const heard = asDigits(ws.map((w) => ({ text: String(w.text ?? ""), start: w.start_ms / 1000, end: (w.end_ms ?? w.start_ms) / 1000 })))
// one token per word of norm's (it makes "acme.com" two), each at its word's time
const flat = heard.flatMap((w) => norm(w.text).split(" ").filter(Boolean).map((t) => ({ t, start: w.start })))
const toks = flat.map((x) => x.t)
let best: { at: number; share: number } | null = null
for (const want of wants)
for (let i = 0; i < toks.length; i++) {
if (!want.includes(toks[i])) continue
const win = toks.slice(i, i + want.length + 3)
const sh = inOrder(want, joined(win, want).map(([w]) => w))
if (sh >= CTA_SHARE && (!best || sh > best.share)) best = { at: flat[i].start, share: sh }
}
if (best) out.push({ take: n.replace(/\.words\.json$/, ""), ...best })
}
return out.sort((a, b) => b.share - a.share).slice(0, 3)
}
/** a phrase one cut is enough for (`every: false`): some delivered cut says or shows it */
export const sayOncePack = check<Job>({ id: "say-once", text: "each phrase one cut is enough for, said or shown by one", over: "job", at: ["publish", "done"], needs: "words" }, async (j) => {
const c = cutJob(j)
const once = (c?.say ?? []).filter((p) => p.every === false)
if (!c || !once.length) return
const cuts = j.files.filter((f) => cutOf(c, f.path))
const heard = await Promise.all(cuts.map(async (f) => ({ ...(await heardOf(f)), together: shownTogether(f.manifest, 0) })))
for (const p of once) {
const n = norm(p.text)
const by = heard.some(({ spoken, together }) => saidAt(spoken, n, SAY_GAP) !== null || together.some((s) => onScreen(s, n, SAY_GAP)))
if (!by) found({ says: `no cut says or shows "${p.text}" (brief: "${p.from}")` })
}
})
+23
View File
@@ -376,3 +376,26 @@ exit 0
assert.equal(otherRaea("0.1.16", "reading", false), undefined)
console.log("ok a box refuses a worker on another raea")
}
// a cut's titles and captions draw white on raea's dark plate, never in a brand's own text colour, which is dark for a
// light website (12-06, Dutch on 0.1.17-rc5: every hook black on the plate at 1.3:1, five floor errors)
{
const title = readFileSync(new URL("../image/Title.tsx", import.meta.url), "utf8")
const colour = title.match(/^\s*color: (.+),$/m)?.[1]
assert.equal(colour, '"#fff"', `Title's words are ${colour}`)
assert.match(title, /background: "rgba\(0,0,0,0\.6\)"/)
const brand = readFileSync(new URL("../image/brand.ts", import.meta.url), "utf8")
assert.match(brand, /export const CAPTION = \{[^}]*color: "#fff"/)
console.log("ok titles and captions draw white on their dark plate")
}
// each file the box image lays over the release's SDK (image/sdk-overlay, deploy/fly/Dockerfile) is the repo's own, so an
// overlay never carries an older copy of a fix (12-06: the CTA check's cut.ts, raea #367)
{
for (const f of ["goal/src/packs/cut.ts"]) {
const over = readFileSync(new URL(`../image/sdk-overlay/${f}`, import.meta.url), "utf8")
const repo = readFileSync(new URL(`../../${f}`, import.meta.url), "utf8")
assert.equal(over, repo, `image/sdk-overlay/${f} isn't sdk/${f}`)
}
console.log("ok the box image's SDK overlays are the repo's files")
}
+4 -4
View File
@@ -87,10 +87,10 @@ const cutFile = (f: FileFacts) => {
/** what a cut says and shows */
async function heardOf(f: FileFacts) {
// numbers said in words as the brief writes them ("pets sixty" is PETS60, "sixty dollars" $60): 12-05, Dutch run 10
const words = asDigits(await f.words())
const spoken = words.map((w) => norm(w.text)).filter(Boolean)
const times = words.filter((w) => norm(w.text)).map((w) => w)
return { spoken, times, screen: shown(f.manifest) }
// one word heard can be two as the brief writes it, and the brief's line is split on its spaces: "Dutch.com" is "dutch
// com", "$60" is "60 dollars" (12-06, Dutch: the whole CTA said, read as 73% of it, so every such cut was an ERROR)
const words = asDigits(await f.words()).flatMap((w) => norm(w.text).split(" ").filter(Boolean).map((text) => ({ ...w, text })))
return { spoken: words.map((w) => w.text), times: words, screen: shown(f.manifest) }
}
const onScreen = (s: string, p: string, gap: number) => saidAt(s.split(" "), p, gap) !== null
+16 -8
View File
@@ -9,16 +9,18 @@ import { bookkeeping } from "./naming.ts"
type Said = { check?: string; level?: string; says?: string; fix?: string | null; frames?: [number, number] | null }
/** what the floor pack measures again on the video itself (the app's UI zones): read there, not twice */
/** what the floor pack measures again on the video itself (the app's UI zones): read there, not twice, when the floor
* pack runs; a goal without it (rules, a scene, a playable) keeps the render's own line (12-06: a desktop title card's
* render found SUNMELT in the right-hand button zone, and its kept check said nothing) */
const MEASURED_AGAIN = new Set(["safe-area"])
/** the manifest's findings, one a kind: the first of each (by check and level), with how many more there were */
export function renderFindings(manifest: unknown): Said[] {
export function renderFindings(manifest: unknown, floorRuns = true): Said[] {
const all = ((manifest as { findings?: Said[] } | null)?.findings ?? []).filter((x) => x && (x.level === "error" || x.level === "warn"))
const firsts = new Map<string, Said & { more: number }>()
for (const x of all) {
const k = x.check ?? "render"
if (MEASURED_AGAIN.has(k)) continue
if (floorRuns && MEASURED_AGAIN.has(k)) continue
const key = `${k} ${x.level}`
const had = firsts.get(key)
if (had) had.more++
@@ -27,8 +29,14 @@ export function renderFindings(manifest: unknown): Said[] {
return [...firsts.values()].map((x) => ({ ...x, says: `${x.check ?? "render"}: ${x.says ?? ""}${x.more ? ` (and ${x.more} more like it)` : ""}` }))
}
export default check<FileFacts>({ id: "render", text: "nothing the render's own end checks found", over: "file", at: ["render", "publish", "done"] }, async (f) => {
if (!f.made || bookkeeping(f.path) || !f.manifest) return
for (const x of renderFindings(f.manifest))
found({ level: x.level as "error" | "warn", says: x.says ?? "", fix: x.fix ?? undefined, frames: x.frames ?? undefined })
})
const renderPack = (floorRuns: boolean) =>
check<FileFacts>({ id: "render", text: "nothing the render's own end checks found", over: "file", at: ["render", "publish", "done"] }, async (f) => {
if (!f.made || bookkeeping(f.path) || !f.manifest) return
for (const x of renderFindings(f.manifest, floorRuns))
found({ level: x.level as "error" | "warn", says: x.says ?? "", fix: x.fix ?? undefined, frames: x.frames ?? undefined })
})
/** beside the floor pack, which measures the app's UI zones on the video itself */
export default renderPack(true)
/** with no floor pack to measure them: the render's own UI-zone lines kept */
export const renderAlone = renderPack(false)
+5 -1
View File
@@ -20,6 +20,7 @@ import { fileFacts, type FileFacts, type Job, kindOf, runIn } from "./facts.ts"
import * as media from "./media.ts"
import { loadProject, type Project } from "./project.ts"
import { PACK_CHECKS } from "./packs/index.ts"
import { renderAlone } from "./packs/render.ts"
import { deliverablesOf } from "./packs/job.ts"
import { bookkeeping } from "./packs/naming.ts"
import { placeReport } from "./packs/place.ts"
@@ -144,7 +145,10 @@ function madeUnder(root: string): string[] {
/** the checks that hold a goal at a moment: its packs', then its own */
export function checksOf(contract: Contract | null, at: Moment, only?: string[]): Check[] {
const all = [...packsOf(contract).flatMap((p) => PACK_CHECKS[p]), ...((contract?.checks ?? []) as Check[])]
const packs = packsOf(contract)
// the render's own UI-zone lines are the floor pack's to measure when it runs, else the render pack keeps them
const of = (p: (typeof packs)[number]) => (p === "render" && !packs.includes("floor") ? [renderAlone as Check] : PACK_CHECKS[p])
const all = [...packs.flatMap(of), ...((contract?.checks ?? []) as Check[])]
const seen = new Set<string>()
return all.filter((c) => {
if (!c?.id || seen.has(c.id) || !c.once) return false
+12 -2
View File
@@ -3,8 +3,8 @@ import { expect, test } from "bun:test"
import { mkdtempSync, utimesSync, writeFileSync } from "node:fs"
import { tmpdir } from "node:os"
import path from "node:path"
import { renderFindings } from "../src/packs/render.ts"
import { collapse, keptCheck } from "../src/run.ts"
import { renderAlone, renderFindings } from "../src/packs/render.ts"
import { checksOf, collapse, keptCheck } from "../src/run.ts"
const at = (s: number, says = "a caption under the app's buttons") => ({ goal: null, check: "floor", file: "a.mp4", level: "error" as const, says, seconds: [s, s + 1] as [number, number] })
@@ -38,6 +38,16 @@ test("CK2: the render's own findings, one line a kind; safe-area is measured on
expect(said[0].says).toBe("font-missing: Inter isn't installed (and 1 more like it)")
})
test("CK2b: with no floor pack to measure the app's buttons, the render's own safe-area line is kept (12-06)", () => {
const m = { findings: [{ check: "safe-area", level: "warn", says: "SUNMELT sits in the app's UI zone at the right" }] }
expect(renderFindings(m, false).map((x) => x.says)).toEqual(["safe-area: SUNMELT sits in the app's UI zone at the right"])
// a title card's goal (rules) holds no floor pack, so its render pack keeps the line; a cut's holds both, and drops it
const ids = (c: any) => checksOf(c, "render").filter((k) => k.id === "render" || k.id === "floor").map((k) => k.id)
expect(ids({ kind: "rules", rules: [] })).toEqual(["render"])
expect(checksOf({ kind: "rules", rules: [] } as any, "render").find((k) => k.id === "render")).toBe(renderAlone as any)
expect(checksOf({ kind: "cut" } as any, "render").find((k) => k.id === "render")).not.toBe(renderAlone as any)
})
test("CK3: one line a rule a file across levels: the worst leads, the rest counted under it (12-05, run 5)", () => {
const f = (level: string, check: string, s: number, says: string) => ({ goal: "g", check, file: "out/cuts/a.mp4", level, says, seconds: [s, s + 1], fix: null, by: "raea" })
const xs = collapse([f("warn", "place", 3.5, "text covers a person"), f("error", "place", 0, "text covers a dog"), f("warn", "frames", 4, "face cut by the bottom edge"), f("error", "frames", 3, "face cut by the right edge"), f("warn", "sound", 8.8, "a tight cut"), f("error", "sound", 14.1, "cuts a word")] as never)
+10
View File
@@ -158,6 +158,16 @@ test("a CTA said in part and shown in part lands, numbers said in words included
expect(of(await run(d), "cta")).toHaveLength(1)
})
test("a CTA heard whole lands when a heard word is two of the brief's: Dutch.com, $60 (12-06, Dutch)", async () => {
const cta = { text: "Go to Dutch.com today and use code PETS60 for $60 off your first year.", from: "Go to Dutch.com today and use code PETS60 for $60 off your first year." }
const d = project(contract({ cta, cuts: [{ id: "a1_s1" }] }))
put(d, "media/brief.txt", `${BRIEF}"Go to Dutch.com today and use code PETS60 for $60 off your first year."\n`)
// as the box's transcript wrote it: the site one word, the money in digits, the code misheard
deliver(d, S1, "go to Dutch.com today and use code PET60 for $60 off for your first year")
put(d, S1.replace(/\.mp4$/, ".render.json"), JSON.stringify({ fps: 30, frames: [{ frame: 0, text: [{ text: "Dutch", opacity: 1 }] }] }))
expect(of(await run(d), "cta")).toEqual([])
})
test("a CTA no cut ends on is found in the takes that say it, so the fix is one raea cut away (12-05)", async () => {
const { mkdtempSync, mkdirSync, writeFileSync } = await import("node:fs")
const { tmpdir } = await import("node:os")
+1 -1
Submodule skills updated: d8a0dc738e...7f083c16ac.
+9 -1
View File
@@ -132,6 +132,12 @@ fn insets(parts: &[Part]) -> Vec<Option<usize>> {
.collect()
}
/// Whether `inner` lies wholly in `outer`'s box (within a millimetre): what `outer` holds, never what it stands on.
fn holds(outer: &Part, inner: &Part) -> bool {
let e = Vec3::splat(0.001);
inner.lo.cmpge(outer.lo - e).all() && inner.hi.cmple(outer.hi + e).all()
}
fn rest_of(parts: &[Part], grid: &Grid, insets: &[Option<usize>], i: usize) -> Rest {
let p = &parts[i];
let height = p.hi.y - p.lo.y;
@@ -147,7 +153,9 @@ fn rest_of(parts: &[Part], grid: &Grid, insets: &[Option<usize>], i: usize) -> R
let mut col = grid.column(parts, f.x, f.z, i);
// a part and the wall it's set into don't stand on each other, nor do a wall's pieces (a corner, the wall over
// a window)
col.retain(|&(y, j, _)| y <= f.y + up && insets[i] != Some(j) && insets[j] != Some(i) && !(wall(p) && wall(&parts[j])));
// nor does a part stand on what it holds: coffee in its mug, soil in its pot, a box's contents (12-06, the 3D
// proof: "mug is sunk 12.0 mm into coffee", the coffee's top a floor's thickness above the mug's foot)
col.retain(|&(y, j, _)| y <= f.y + up && insets[i] != Some(j) && insets[j] != Some(i) && !(wall(p) && wall(&parts[j])) && !holds(p, &parts[j]));
let Some(&(y, j, k)) = col.iter().max_by(|a, b| a.0.total_cmp(&b.0)) else { continue };
let gap = f.y - y;
tested += 1;
+16
View File
@@ -170,3 +170,19 @@ fn a_thing_left_in_the_air_is_an_error_unless_it_glows_or_is_floating() {
let (_, level, _, errors) = air(json!({}), json!({"emissive": {"red": 2200.0, "green": 120.0, "blue": 80.0, "alpha": 1.0}}));
assert_eq!((level.as_str(), errors), ("note", 0));
}
#[test]
fn a_mug_stands_on_the_table_not_on_its_coffee() {
let floor = part("floor", Vec3::new(0.0, -0.05, 0.0), Vec3::new(4.0, 0.1, 4.0));
let mug = part("mug", Vec3::new(0.3, 0.05, 0.2), Vec3::new(0.08, 0.1, 0.08));
// the coffee in it: its top 12 mm above the mug's foot, wholly inside the mug's box
let coffee = part("coffee", Vec3::new(0.3, 0.007, 0.2), Vec3::new(0.06, 0.01, 0.06));
let parts = [floor, mug, coffee];
match rest(&parts, 1) {
Rest::On { under, gap, .. } => {
assert_eq!(parts[under].label, "floor");
assert!(gap.abs() <= TOUCH, "{gap}");
}
r => panic!("the mug should rest on the floor: {r:?}"),
}
}
+42 -1
View File
@@ -122,8 +122,36 @@ pub fn load_now(family: &str) -> usize {
faces.len()
}
/// A family's Latin faces from Google Fonts, or none
/// A family's Latin faces from Google Fonts; for a family Google doesn't have, its free stand-in's (`stand_in`); or none
fn fetch(family: &str) -> Vec<(Bytes, f32, bool)> {
let faces = fetch_google(family);
if !faces.is_empty() {
return faces;
}
match stand_in(family) {
Some(s) => {
bevy::log::info!("raea-page: {family:?} isn't on Google Fonts: drawn in {s:?}, its closest free family");
fetch_google(s)
}
None => faces,
}
}
/// The free family a page's font is drawn in where Google Fonts hasn't got it and the machine hasn't either (12-06: box
/// cuts named "Inter Display" and "Helvetica Neue", and drew in DejaVu Sans on the farm): a size of a Google family by
/// its own name, or a licensed face's closest free one on its metrics (Arimo is Arial's and Helvetica's)
pub fn stand_in(family: &str) -> Option<&'static str> {
let f = family.trim().trim_matches(|c| c == '"' || c == '\'').to_ascii_lowercase();
match f.as_str() {
"inter display" | "inter var" | "inter variable" => Some("Inter"),
"helvetica neue" | "helvetica" | "arial" | "helveticaneue" => Some("Arimo"),
"sf pro" | "sf pro display" | "sf pro text" => Some("Inter"),
_ => None,
}
}
/// A family's Latin faces from Google Fonts, or none
fn fetch_google(family: &str) -> Vec<(Bytes, f32, bool)> {
let url = format!("https://fonts.googleapis.com/css?family={}:{WEIGHTS}", family.replace(' ', "+"));
let css = match raea_io_net::cache::read(&url).and_then(|b| String::from_utf8(b).map_err(|e| e.to_string())) {
Ok(css) => css,
@@ -165,3 +193,16 @@ pub fn face_now(family: &str, url: &str) -> usize {
LOADED.lock().unwrap().push(key);
1
}
#[cfg(test)]
mod tests {
use super::stand_in;
#[test]
fn a_family_google_has_not_got_draws_in_its_free_stand_in() {
assert_eq!(stand_in("Inter Display"), Some("Inter"));
assert_eq!(stand_in("\"Helvetica Neue\""), Some("Arimo"));
assert_eq!(stand_in("Arial"), Some("Arimo"));
assert_eq!(stand_in("Roboto Slab"), None);
}
}