awc_shorts: refuse a catalog that would overwrite an input bank (carry of #934) #3078
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3078"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T09:50:13Z.
Claimed in the coordination issue as: DRAFT-196 (the claim of the original author, fin-github, in #14)
What and why
Carry of #934 (fin-github, itself a cherry-pick of draft #196 by neoisg8), unchanged since 24 November after two rebase requests. This branch is
mainplus the head of #934 (the author's commit is kept), the test conflict resolved by keepingmain's tests and the pull request's tests, and one commit of mine.tools/awc_shorts.pywrites its catalog to<out>/shorts.csv. Without a guard, an input bank namedshorts.csvin the output folder was overwritten, and a bank that exports to<out>/shorts.csvcollided with the catalog after clips were already written. #934 refuses both with exit code 2. My commit follows PierreEbele's review note: the second check ran afteros.makedirs, so a refused run left an empty output folder; both checks now run before it, and a test checks that the folder is not created.Tested
Windows 11, no GPU, no game files, on
maina917c54d6plus this branch:python -I tests/test_awc_shorts.py: 21 tests OK (1 skipped).main'stools/awc_shorts.py, the three new tests fail.python -I scripts/check_no_game_data.pyon both changed files: clean.GPUs tested: n/a (unit tests only)
AI-assisted: yes. Models: Claude Opus 5.5 in Claude Code (carry, conflict resolution, fix, tests); separate read-only reviewer agent: Claude Opus 5.5.
Checklist
mainand merges cleanly.docs/design.md. (n/a: tool guard and tests only)Supersedes #934 once merged; the original stays open until a maintainer decides.
🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-12-02T10:17:33Z.
RUN (independent run on Windows, #3078 head
2948cf3e4, merged locally intomaina917c54d6withgit merge --no-ff, no conflicts. CI on the head: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass.)dc4c32ac9, by its original author, is an ancestor of the head through the merge92c713e76. The carrier adds one commit on top.python -I tests/test_awc_shorts.py -v: main 18 tests OK (1 skipped); merge 21 tests OK (1 skipped, "input volume does not support case-distinct files").python -m pytest tests/test_awc_shorts.py tests/test_csv_line_endings.py tests/test_pool_workers.py -q(the files that nameawc_shorts): main 31 passed / 1 skipped; merge 34 passed / 1 skipped.main'stools/awc_shorts.pywith this pull request's test file gives 21 tests and 3 failures. The input-bank case exits 0, and the two export-folder cases exit 1, where 2 is wanted.<out>/shorts.csv:mainexits 0 and the input file now holds the catalog header (bank,stream,duration_s,...), so the input is lost. The merge exits 2 with "catalog would overwrite the input bank" and leaves the input unchanged.<out>/Shorts.CSV, a case variant on a case-insensitive volume:mainoverwrites it the same way. The merge refuses it, becausesame_report_pathcompares the paths.src/shorts.csv.awcwithout/as the output:maincreatesout/shorts.csvas the bank's export folder, then cannot write the catalog over it (Permission denied, exit 1), and leavesout/behind. The merge exits 2 beforeout/exists.tools/awc_shorts.py, each run with the whole test file and restored afterwards (git statusclean):os.makedirs, as in #934 before the follow-up commit: killed bytest_catalog_collision_refusal_creates_no_output_folder.same_report_pathreplaced by==on the joined paths: survives the test file, because the tests spell both paths the same way. The case-variant probe above catches it: the mutated tool overwritesShorts.CSVand exits 0. A case-variant test, skipped on a case-sensitive volume like the existing one, would pin it.Not covered here: Linux and macOS, and a real AWC bank. The input was synthetic junk, and the guard runs before any bank is read.
Verdict: PASS. The guard stops a real loss of input on Windows that
mainhas (exit 0 with the input overwritten), the three new tests are red onmainand green on the merge, and the refusal leaves nothing behind. Only the case-insensitive comparison is not pinned by a test.Machine: Windows 11 Pro 26300 (NTFS), i9-13900K, 64 GB, CPython 3.13.12 (CI uses 3.12); unit tests and synthetic inputs only, no GPU or game files used.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T10:26:46Z.
Merging. Head
2948cf3e4merges cleanly withmain80910637fand does not force a rebase of #2566. Independent check on head2948cf3e4: enlight3d's red/green on main + PR (3 failures on main, 21 green, comment 7342252079); neoisg8's commit from #934 is an ancestor of the head; CI 5/5 green incl. no-game-data; no open review or question; item DRAFT-196 claimed in #14. Merged by MoonEyes.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-02T10:36:16Z.
VERIFY-3078 — Linux, Fedora 45, Python 3.15.2, no GPU device, no game files
Verdict: PASS. The change refuses, with exit code 2, the two ways
awc_shorts.py's catalog<out>/shorts.csvcan collide with its own work: an input bank that is the catalog path (single-filesrcnamedshorts.csvin the output folder), and a bank whose export directory is the catalog path (ashorts.csv.awcbank, whose stem isshorts.csv). I reproduced both overwrites on the merge base (the first one silently clobbered the input bank and returned 0; the second created the export directory and then failed the catalog write with 1, leaving the output folder behind) and confirmed the fix refuses both with 2, leaves the bank bytes untouched, and — because the author's follow-up commit moved both checks beforeos.makedirs— leaves no output folder behind on refusal. The three new tests fail on the base and pass with the pull request; nothing regressed.head
2948cf3e49c1e47ff92f5bf3f1ebba2577e7ffba("awc_shorts: refuse a catalog collision before creating the output folder"), merge baseorigin/mainat the time =a917c54d6aff8c9ef5dda2d8ebf938cb5c693902(the pull request sits on it;mainhas since moved to80910637). Two commits beyond the base:92c713e7(carry merge ofrefs/pr-all/934, keeping the original author's commitdc4c32acby neoisg8) and2948cf3e(the review follow-up). Two files, +51/−1:tools/awc_shorts.py,tests/test_awc_shorts.py.1. What it changes
tools/awc_shorts.pywrites its catalog to<out>/shorts.csv.main()gained a guard loop (lines 163–172) that runs after the source is listed and beforeos.makedirs(a.out)(line 174). For every bank(path, bank)it asks two questions withreport_paths.same_report_path:same_report_path(catalog, path)— is the catalog the same file as an input bank? (line 166–168,catalog would overwrite the input bank.)same_report_path(catalog, os.path.join(a.out, bank))— is the catalog the same path as a bank's export directory? (line 169–172,catalog would collide with bank export directory.)Either answer is a refusal: a one-line message on
stderrandreturn 2. This is the body of #934 (the original author's commit is kept asdc4c32ac), plus the follow-up commit2948cf3e: #934 had put the second check afteros.makedirs(in the destination-dedup loop), so a refused run had already created the output folder; the follow-up moved both checks before it (and deleted the check from the dedup loop,git show 2948cf3e).The first check fires only for a single-file
srcnamedshorts.csvwhose directory is the output folder (a directory scan lists only*.awc, so a bank file can never be namedshorts.csvthere). The second fires for any bank whose stem isshorts.csv— i.e. ashorts.csv.awcfile (or a single-filesrcnamedshorts.csv.awc), whose export directory<out>/shorts.csv/is the catalog's own path.2. The two claims, checked
Claim: "an input bank named
shorts.csvin the output folder was overwritten." Confirmed, and I reproduced it. With the merge-base tool (rg-3078/tree, the base commit):The bank was silently replaced by the catalog header (exit 0, no error). With the pull-request tool the same invocation prints
awc_shorts: error: catalog would overwrite the input bank shorts.csv, exits 2, and the bank still holdsoriginal input bank data. This is the tool's own path-checking (same_report_pathon the resolved paths), not a test artifact.Claim: "a bank that exports to
<out>/shorts.csvcollided with the catalog after clips were already written." Confirmed in behaviour. With the pull-request tool,awc_shorts.py shorts.csv.awc .exits 2 withcatalog would collide with bank export directory ./shorts.csv;awc_shorts.py shorts.csv.awc out(whereoutdoes not exist) exits 2 with... out/shorts.csvand, per the third test,out/is not created. On the merge base the same collision is not refused before the work happens: the red side shows the run returned 1 (not 2) — the export directory was created first, then the catalog write failed becauseshorts.csvwas already a directory (test_catalog_collision_with_bank_export_directory_rejectedfails withAssertionError: 1 != 2).Claim: "both checks now run before
os.makedirs, so a refused run leaves nothing behind." Confirmed from the code (lines 163–172 before line 174) and bytest_catalog_collision_refusal_creates_no_output_folder, which assertsrc == 2andnot os.path.exists(out). On the base that test fails withAssertionError: 1 != 2— the old code createdout/first.Claim: refusal is exit code 2 with a one-line message. Confirmed: both branches
return 2; the tests assertrc == 2, the message viaassertIn, and thatstderrhas exactly one line (len(err.getvalue().splitlines()) == 1). A usage error rather than a failed run, consistent with the tool's other refusals (--jobs < 1, a bad range, a missing source) and withtest_missing_input_exit_codes's BUILD-1046 convention.3. What the tests do here
python3 -I tests/test_awc_shorts.pyon the head: 21 tests, OK (no skip on Linux). The author's "21 tests OK (1 skipped)" is the same run on Windows, wheretest_bank_extensions_cannot_collapse_two_banks_into_one_exportskips (self.skipTest("input volume does not support case-distinct files"), line 143) because NTFS does not normally allowclip.awcandclip.AWCside by side; ext4 does, so it runs here.python3 -I scripts/red_green.py 3078 --no-cargo(work-dirrg-3078): verdict "red then green" — the three new tests go red→green, 0 regressions, 0 fail on both, 18 pass on both. The red side (merge base + the pull request's test file) is exactly the base tool with the three new tests, and I ran it by hand to see the failures:test_catalog_collision_with_input_bank_rejectedAssertionError: 0 != 2— the base tool ran the bank and returned 0 (the overwrite)test_catalog_collision_with_bank_export_directory_rejectedAssertionError: 1 != 2— the base tool created the export dir, then failed the catalog writetest_catalog_collision_refusal_creates_no_output_folderAssertionError: 1 != 2— the base tool createdout/before failingThe three tests are not vacuous: each fails on the base with exactly the behaviour the fix changes, and each asserts the consequence (bank bytes unchanged; no output folder) not just the exit code.
Also run:
python3 -I scripts/check_no_game_data.py tools/awc_shorts.py tests/test_awc_shorts.py— exit 0 (clean);python3 -m compileall— clean;python3 -I -m unittest discover -s tests -p "test_docs_*.py"— 57 OK.4. Anything wrong
Nothing blocking. Three observations, none a defect of the change:
shorts.csv, socatalog would overwrite the input bankonly fires for a single-filesrcnamedshorts.csv. That is exactly the case the PR describes, and the guard is still the right place for it; it is not a gap, just worth knowing that the directory-scan path only ever hits the second check.targetis now computed twice per bank (the guard loop and the destination-dedup loop both doos.path.join(a.out, bank)). That is a redundantjoinand one extrasame_report_path(arealpath+samefile) per bank in the guard — negligible for an offline asset export, not a hot path.same_report_pathvspath_key: the guard usessame_report_path, the pre-existing dedup usespath_key. Both come fromreport_paths; the guard's is the stricter of the two (it also folds hard links and case aliases). Consistent with the report-path rules inCONTRIBUTING.md.5. What I did not check
awc_shorts.pyover a game's AWC directory (no game files, and the point of the PR is the catalog guard, not the exporter).tests/suite (semantic translator, viewer.cjs,rpf9dump,runtime/CTest, the D3D12 Rust crates) — the change touches none of those, andred_greenran the only Python test file the pull request changes.same_report_pathcase-folding path for a case-insensitive volume is not exercised here.os.makedirs), but I did not read #934's own review comments — that is a different pull request and I was asked to verify only #3078.