#!/usr/bin/env bash
# Koldflux test: what changes in an SRT after translation, 2026-11-21.
# Inputs: Tears of Steel (CC BY 3.0, Blender Foundation) SRTs en, de, es, it, nl, ru from download.blender.org/demo/movies/ToS/subtitles/.
# Methods: 1) ref.py (our independent Python parser), 2) shell one-liners published in the guide (commands.log), 3) live subtitle checker via Playwright (tool.cjs).
# Known answers: three deliberately broken translations of the English file (dropped cue, merged cues, shifted time) built below; a CRLF+BOM copy is the edge input.
# Usage: bash test-run.sh  (needs python3, node + playwright, curl)
set -uo pipefail
cd "$(dirname "$0")"; mkdir -p files edge
for l in en de es it nl ru; do [ -s files/TOS-$l.srt ] || curl -sL -o files/TOS-$l.srt https://download.blender.org/demo/movies/ToS/subtitles/TOS-$l.srt; done
sha256sum files/TOS-*.srt
echo "## ref.py on the six files"; python3 -I ref.py TOS-en TOS-de TOS-es TOS-it TOS-nl TOS-ru
python3 -I - <<"PY"
import re, sys; sys.path.insert(0, ".")
import ref
raw = open("files/TOS-en.srt", encoding="utf-8-sig").read().replace("\r\n", "\n").strip().split("\n\n")
open("edge/broken-dropped.srt", "w").write("\n\n".join(raw[:10] + raw[11:]) + "\n")
m = raw[:5] + ["\n".join(raw[5].split("\n")[:2] + raw[5].split("\n")[2:] + raw[6].split("\n")[2:])] + raw[7:]
open("edge/broken-merged.srt", "w").write("\n\n".join(m) + "\n")
s = list(raw); b = raw[20].split("\n"); b[1] = re.sub(r"^(\d+):(\d+):(\d+)", lambda x: "%s:%s:%02d" % (x.group(1), x.group(2), int(x.group(3)) + 5), b[1]); s[20] = "\n".join(b)
open("edge/broken-shifted.srt", "w").write("\n\n".join(s) + "\n")
t = open("files/TOS-de.srt", encoding="utf-8").read().replace("\r\n", "\n")
open("edge/TOS-de-crlf-bom.srt", "w", encoding="utf-8", newline="").write("﻿" + t.replace("\n", "\r\n"))
en = ref.parse("files/TOS-en.srt")
print("## known answers")
print("control en vs en:", ref.compare(en, en))
for k, want in [("dropped", "cue count 75, timestamps shift after cue 11"), ("merged", "cue count 75"), ("shifted", "76 cues, exactly 75 of 76 identical")]:
    c = ref.parse(f"edge/broken-{k}.srt"); print(f"broken-{k} (expected: {want}):", len(c), ref.compare(en, c))
PY
echo "## tool on six files + broken + edge"
export PATH="$HOME/.nvm/versions/node/v24.21.0/bin:$PATH"
node tool.cjs files/TOS-en.srt files/TOS-de.srt files/TOS-es.srt files/TOS-it.srt files/TOS-nl.srt files/TOS-ru.srt edge/broken-dropped.srt edge/TOS-de-crlf-bom.srt > out-tool.json; cat out-tool.json
bash commands.sh > commands.log 2>&1; echo "commands.log lines: $(wc -l < commands.log)"
