Skip to content

Commit 823d604

Browse files
donislawdevclaude
andcommitted
The cut guards reach every case they plan and keep a witness behind the content
An MP4 no longer cuts in the padding behind its pictures, and it was the case that showed the manifest's note for a cut there. The note's case moves to the one format that still cuts there: a WebP of 4 KiB cut by 1%, whose picture grows to fill the file and leaves more behind it than the cut takes. The share sweep asked only the files its manifest listed, so a format that lost one planned file passed on the others. A planned file the manifest leaves out is now an error, with a canary. A switch over the roles of a film's map names its padding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4931768 commit 823d604

3 files changed

Lines changed: 36 additions & 8 deletions

File tree

‎internal/guard/cutmanifest_test.go‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ type cutCase struct {
3737
// the content is left, and gets a note when the cut missed the content.
3838
//
3939
// The shapes a cut takes (docs/TRUNCATE-2026-11-11.md sections 2, 7 and 8).
40-
// An MP4 of 1 MiB is nearly all padding after its video, so 90% missing still
41-
// leaves all of it. A PNG splits its padding around the picture
40+
// A WebP grows its picture to fill the file and keeps what is left over
41+
// behind it, which at 4 KiB is more than the 41 B a cut of 1% takes, so the
42+
// cut leaves all of the picture. A PNG splits its padding around the picture
4243
// for a cut, so the cut takes the share asked for, and so does a tar.gz. A
4344
// text is its words, so the cut falls in them. Two cuts in a row end the file where the second one does, and
4445
// the cut is said of that one. A damage that cuts nothing has no cut to report.
@@ -47,9 +48,9 @@ type cutCase struct {
4748
// one that claims content it does not have.
4849
func TestACutFileSaysWhereTheCutFellAndWhatIsLeft(t *testing.T) {
4950
cases := []cutCase{
50-
// A GIF and then a PDF were this case until each split its padding
51-
// for the cut.
52-
{name: "behind", format: "mp4", size: 1 << 20, missing: "90", in: "padding", kept: "all", note: "after the content"},
51+
// A GIF, a PDF and an MP4 were this case until each split its
52+
// padding for the cut.
53+
{name: "behind", format: "webp", size: 4 << 10, missing: "1", in: "padding", kept: "all", note: "after the content"},
5354
{name: "picture", format: "png", size: 1 << 20, missing: "90", in: "content", kept: "share"},
5455
// 4 KiB on disk is 40 KiB whole. It was the case of a cut in the padding
5556
// in front of the content, with an icon and a JPEG before it, until it
@@ -96,7 +97,7 @@ func TestACutFileSaysWhereTheCutFellAndWhatIsLeft(t *testing.T) {
9697
}
9798
}
9899

99-
// Canary: the GIF's entry, told the cut fell in its content, and the
100+
// Canary: the WebP's entry, told the cut fell in its content, and the
100101
// text's, told none of its content is left.
101102
behind := byTarget["behind"]
102103
if len(behind.Damage) == 1 && behind.Damage[0].Cut != nil {
@@ -180,7 +181,7 @@ func TestTheRecordOfACutRunIsNeverLongerThanItsForecast(t *testing.T) {
180181
}
181182
opt := engine.Options{OutDir: t.TempDir(), Seed: 7, Command: "test"}
182183
planned, err := engine.Plan([]engine.Target{
183-
cut("picture", "png", 1<<20, "90"), cut("behind", "mp4", 1<<20, "90"), cut("text", "txt", 1000, "50"),
184+
cut("picture", "png", 1<<20, "90"), cut("behind", "webp", 4<<10, "1"), cut("text", "txt", 1000, "50"),
184185
}, opt)
185186
if err != nil {
186187
t.Fatalf("planning: %v", err)

‎internal/guard/cutshare_test.go‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ var (
9898
// structure by TestEveryFormatsMapIsTheOneItsStructureReadsBack.
9999
//
100100
// Canaries: a cut that kept all its content must be reported, and so must a
101-
// format listed as not yet cutting at the share that does.
101+
// format listed as not yet cutting at the share that does, and a file planned
102+
// for the sweep that the manifest leaves out.
102103
func TestACutTakesTheShareOfTheContentItIsAskedFor(t *testing.T) {
103104
missingOf := map[string]int64{}
104105
var targets []engine.Target
@@ -128,7 +129,9 @@ func TestACutTakesTheShareOfTheContentItIsAskedFor(t *testing.T) {
128129
plannedOf[f.Target.ID] = f
129130
}
130131
problems := map[string]string{}
132+
inManifest := map[string]bool{}
131133
for _, m := range res.Manifest.Files {
134+
inManifest[m.TargetID] = true
132135
missing, ok := missingOf[m.TargetID]
133136
if !ok || m.Failed {
134137
t.Errorf("%s: no file was written (%s)", m.TargetID, m.Error)
@@ -152,6 +155,12 @@ func TestACutTakesTheShareOfTheContentItIsAskedFor(t *testing.T) {
152155
for _, problem := range shareVerdicts(problems, notYetCutAtTheShare) {
153156
t.Error(problem)
154157
}
158+
for _, problem := range absentFromTheManifest(missingOf, inManifest) {
159+
t.Error(problem)
160+
}
161+
if len(absentFromTheManifest(map[string]int64{"webp-4096-1": 1}, map[string]bool{})) != 1 {
162+
t.Errorf("canary: a planned file the manifest left out passed")
163+
}
155164
for _, problem := range listedAfterTheRule(notYetCutAtTheShare) {
156165
t.Error(problem)
157166
}
@@ -191,6 +200,21 @@ func TestACutTakesTheShareOfTheContentItIsAskedFor(t *testing.T) {
191200
}
192201
}
193202

203+
// absentFromTheManifest is every file planned for the sweep that the manifest
204+
// has no entry for. shareVerdicts asks only the cases a file was written for,
205+
// so without this a format that loses one of its files to the run still
206+
// passes on the others.
207+
func absentFromTheManifest(missingOf map[string]int64, inManifest map[string]bool) []string {
208+
var out []string
209+
for id := range missingOf {
210+
if !inManifest[id] {
211+
out = append(out, id+": planned for the sweep and not in the manifest, so its cut was never asked")
212+
}
213+
}
214+
slices.Sort(out)
215+
return out
216+
}
217+
194218
// cutInTheEnd is what shareProblem says of a cut that fell in the end a file
195219
// closes with: a central directory, a trailer.
196220
const cutInTheEnd = "the cut fell in the end"

‎internal/guard/filmcut_test.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ func filmParts(t *testing.T, regions []format.Region) (head int64, pics format.R
131131
end += r.Length
132132
case format.RoleContent:
133133
pics, seen = r, true
134+
case format.RolePadding:
135+
// What the parts around it leave of the file - filmLayoutOf
136+
// reads the two sides of it.
134137
}
135138
}
136139
if !seen || pics.Length < 0 {

0 commit comments

Comments
 (0)