packages.wenpai.net/internal/deploy/r2_test.go
Scott Walkinshaw ab59f27840
Drop Composer v1 support (#34)
* Drop Composer v1 support

Removes all code and support related to Composer v1 support and the
generated `p/` build files. No uploaded in R2 are deleted; no data in
the database is deleted.

Impact:

1. DB: Dropped index (`idx_packages_provider_group`), not the column. New writes stop populating `provider_group` but the column stays as dead weight.
2. `packages.json` content changes. The root `packages.json` loses:
- `providers-url`
- `provider-includes`
- `build-id`
- `packages` changes from `{}` to `[]`

  Composer v2 clients only use `metadata-url` so they're unaffected. But any Composer v1 client would break (which is the intent — Packagist.org already dropped v1 in Sep 2025).

3. New builds on disk no longer contain a `p/` directory — only `p2/`.
4. R2 uploads stop writing to `releases/<build-id>/` prefixes and stop uploading `p/` files. Only `p2/` + `packages.json` go up.
5. Orphaned R2 data — existing `p/` objects, `releases/` prefixes, and content-addressed files remain on R2 but are no longer referenced. These can be deleted later manually.

* More cleanup

* Add warning to packages.json for v1 support
2026-03-19 01:10:09 -04:00

55 lines
1.4 KiB
Go

package deploy
import (
"os"
"path/filepath"
"testing"
)
func TestValidateBuildRejectsInvalid(t *testing.T) {
// Build with no packages.json should fail validation
buildDir := t.TempDir()
_ = os.WriteFile(filepath.Join(buildDir, "manifest.json"), []byte(`{}`), 0644)
err := ValidateBuild(buildDir)
if err == nil {
t.Fatal("expected ValidateBuild to reject build missing packages.json")
}
// Build with no manifest.json should fail
buildDir2 := t.TempDir()
_ = os.WriteFile(filepath.Join(buildDir2, "packages.json"), []byte(`{}`), 0644)
err = ValidateBuild(buildDir2)
if err == nil {
t.Fatal("expected ValidateBuild to reject build missing manifest.json")
}
// Valid build should pass
buildDir3 := t.TempDir()
_ = os.WriteFile(filepath.Join(buildDir3, "packages.json"), []byte(`{}`), 0644)
_ = os.WriteFile(filepath.Join(buildDir3, "manifest.json"), []byte(`{}`), 0644)
err = ValidateBuild(buildDir3)
if err != nil {
t.Fatalf("expected ValidateBuild to accept valid build, got: %v", err)
}
}
func TestCacheControlForPaths(t *testing.T) {
tests := []struct {
path string
want string
}{
{"packages.json", "public, max-age=300"},
{"p2/wp-plugin/akismet.json", "public, max-age=300"},
}
for _, tt := range tests {
t.Run(tt.path, func(t *testing.T) {
got := CacheControlForPath(tt.path)
if got != tt.want {
t.Errorf("CacheControlForPath(%q) = %q, want %q", tt.path, got, tt.want)
}
})
}
}