Changed sow-tools HAK split planning to preserve previous split membership

This commit is contained in:
2026-04-18 18:39:15 +02:00
parent e0b3164427
commit f249108cf0
2 changed files with 208 additions and 6 deletions
+64
View File
@@ -1874,6 +1874,70 @@ func TestPlanHAKChunksPutsNewestAssetsInLastChunk(t *testing.T) {
}
}
func TestPlanHAKChunksKeepsPreviousSplitsAndPacksNewAssetsAtTail(t *testing.T) {
oldB := testAssetResource("core/old_b.tga", "old_b", "b", time.Date(2002, 1, 1, 0, 0, 0, 0, time.UTC))
oldC := testAssetResource("core/old_c.tga", "old_c", "c", time.Date(2003, 1, 1, 0, 0, 0, 0, time.UTC))
newA := testAssetResource("core/new_a.tga", "new_a", "a", time.Date(1999, 1, 1, 0, 0, 0, 0, time.UTC))
twoAssetSize := erf.ArchiveSize([]erf.Resource{oldB.Resource, oldC.Resource})
p := &project.Project{
Config: project.Config{
HAKs: []project.HAKConfig{
{
Name: "core",
Priority: 1,
MaxBytes: twoAssetSize,
Split: true,
Include: []string{"core/**"},
},
},
},
}
previous := &BuildManifest{
HAKs: []BuildManifestHAK{
{Name: "core_01", Group: "core", Priority: 1, MaxBytes: twoAssetSize, Assets: []string{"core/old_b.tga"}},
{Name: "core_02", Group: "core", Priority: 1, MaxBytes: twoAssetSize, Assets: []string{"core/old_c.tga"}},
},
}
chunks, err := planHAKChunksWithPrevious(p, []assetResource{oldB, oldC, newA}, previous)
if err != nil {
t.Fatalf("plan hak chunks: %v", err)
}
if len(chunks) != 2 {
t.Fatalf("expected 2 chunks, got %d", len(chunks))
}
if got, want := strings.Join(chunkAssetRels(chunks[0]), ","), "core/old_b.tga"; got != want {
t.Fatalf("unexpected first chunk assets: got %q want %q", got, want)
}
if got, want := strings.Join(chunkAssetRels(chunks[1]), ","), "core/old_c.tga,core/new_a.tga"; got != want {
t.Fatalf("unexpected tail chunk assets: got %q want %q", got, want)
}
}
func testAssetResource(rel, name, payload string, createdAt time.Time) assetResource {
resource := erf.Resource{
Name: strings.ToLower(name),
Type: 0x0003,
Data: []byte(strings.Repeat(payload, 80)),
}
return assetResource{
Rel: rel,
Resource: resource,
Size: erf.ArchiveSize([]erf.Resource{resource}),
CreatedAt: createdAt,
ContentID: "test:" + name,
}
}
func chunkAssetRels(chunk hakChunk) []string {
rels := make([]string, 0, len(chunk.Assets))
for _, asset := range chunk.Assets {
rels = append(rels, asset.Rel)
}
return rels
}
func TestCollectLFSAssetInfoUsesGitCommonDirForWorktree(t *testing.T) {
if _, err := exec.LookPath("git"); err != nil {
t.Skip("git not available")