Read blob sizes only for selected validation inputs
This commit is contained in:
@@ -46,6 +46,59 @@ func TestSourceOperationsRejectUnavailableNoteWithoutTransport(t *testing.T) {
|
||||
assertInspectionStayedLocal(t, repository, attempts, before)
|
||||
}
|
||||
|
||||
func TestScopedValidationReadsOnlyRequiredBlobsInPartialClone(t *testing.T) {
|
||||
source := newPublishFixture(t)
|
||||
addNestedReleaseModule(t, source.work, "nested", "example.com/nested", "v1.2.3")
|
||||
writeFile(t, source.work, "nested/NOTICE.txt", "nested notice\n")
|
||||
writeFile(t, source.work, "nested/README.md", "# Nested guide\n")
|
||||
writeFile(t, source.work, "nested/go.work", "go 1.26.0\nuse .\n")
|
||||
writeFile(t, source.work, "docs/links.md", "# Links\n\n[Guide](../nested/README.md#nested-guide)\n")
|
||||
gitRun(t, source.work, "add", ".")
|
||||
gitRun(t, source.work, "commit", "-m", "Add independently scoped module")
|
||||
repository := newFilteredSparseCheckout(t, source.work,
|
||||
"/go.mod", "/fixture_test.go", "/race_fixture_test.go", "/source.txt", "/docs/")
|
||||
before := gitText(t, repository, "cat-file", "--batch-all-objects", "--batch-check=%(objectname)")
|
||||
for _, name := range []string{"nested/fixture_test.go", "nested/NOTICE.txt", "nested/README.md"} {
|
||||
object := gitText(t, repository, "rev-parse", "HEAD:"+name)
|
||||
if strings.Contains(before, object) {
|
||||
t.Fatalf("fixture already contains excluded blob %q", name)
|
||||
}
|
||||
}
|
||||
attempts := forbidInspectionTransport(t, repository)
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
selection releasekit.ValidationSpec
|
||||
wantCheck releasekit.ValidationCheck
|
||||
wantPath string
|
||||
}{
|
||||
{name: "formatting", selection: releasekit.ValidationSpec{GoFormat: true, SharedFiles: []string{}}},
|
||||
{name: "file sizes", selection: releasekit.ValidationSpec{FileSize: &releasekit.FileSizeValidationSpec{}, SharedFiles: []string{}}},
|
||||
{name: "workspace metadata", selection: releasekit.ValidationSpec{ModuleDistribution: releasekit.ModuleDistributionValidationSpec{WorkspaceFiles: true}, SharedFiles: []string{}}},
|
||||
{name: "explicit shared metadata", selection: releasekit.ValidationSpec{SharedFiles: []string{"nested/NOTICE.txt"}}},
|
||||
{name: "excluded shared size", selection: releasekit.ValidationSpec{FileSize: &releasekit.FileSizeValidationSpec{Exclusions: []string{"nested/NOTICE.txt"}}, SharedFiles: []string{"nested/NOTICE.txt"}}},
|
||||
{name: "required shared size", selection: releasekit.ValidationSpec{FileSize: &releasekit.FileSizeValidationSpec{}, SharedFiles: []string{"nested/NOTICE.txt"}}, wantCheck: "file-size", wantPath: "nested/NOTICE.txt"},
|
||||
{name: "required shared source", selection: releasekit.ValidationSpec{GoFormat: true, SharedFiles: []string{"nested/fixture_test.go"}}, wantCheck: "go-format", wantPath: "nested/fixture_test.go"},
|
||||
{name: "required reference", selection: releasekit.ValidationSpec{Markdown: &releasekit.MarkdownValidationSpec{}, SharedFiles: []string{}}, wantCheck: "markdown-links", wantPath: "nested/README.md"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
_, err := releasekit.Check(t.Context(), releasekit.ReleaseRequest{
|
||||
RepositoryDir: repository, Product: "Sample App", Version: "v1.2.3", Validation: tc.selection,
|
||||
})
|
||||
if tc.wantCheck == "" {
|
||||
if err != nil {
|
||||
t.Fatalf("scoped validation failed: %v", err)
|
||||
}
|
||||
} else {
|
||||
var failure *releasekit.ValidationError
|
||||
if !errors.As(err, &failure) || failure.Check != tc.wantCheck || !strings.Contains(err.Error(), tc.wantPath) {
|
||||
t.Fatalf("validation error = %v; want %s inspection of %q", err, tc.wantCheck, tc.wantPath)
|
||||
}
|
||||
}
|
||||
assertInspectionStayedLocal(t, repository, attempts, before)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func newFilteredSparseCheckout(t *testing.T, source string, paths ...string) string {
|
||||
t.Helper()
|
||||
gitRun(t, source, "config", "uploadpack.allowFilter", "true")
|
||||
|
||||
Reference in New Issue
Block a user