Export the reviewed allowlisted snapshot from private source commit 07c1655921f21ee5e4fc4d85639d199e8867b17d. This records the Docker Compose activation, schema-compatible rollback, and stateful migration resource findings from Observatory Preview 19 dogfooding. AI-Assisted: OpenAI Codex Signed-off-by: Cole Speelman <crspeelman@gmail.com>
53 lines
1.8 KiB
Go
53 lines
1.8 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
package provenance
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
type recordingRunner struct {
|
|
responses map[string][]byte
|
|
calls []string
|
|
}
|
|
|
|
func (runner *recordingRunner) Run(_ context.Context, _ string, _ map[string]string, name string, args ...string) ([]byte, error) {
|
|
key := name + " " + strings.Join(args, " ")
|
|
runner.calls = append(runner.calls, key)
|
|
response, ok := runner.responses[key]
|
|
if !ok {
|
|
return nil, errors.New("unexpected command: " + key)
|
|
}
|
|
return response, nil
|
|
}
|
|
|
|
func TestInspectAcceptsStandaloneExactPushedCheckout(t *testing.T) {
|
|
commit := strings.Repeat("a", 40)
|
|
runner := &recordingRunner{responses: map[string][]byte{
|
|
"git rev-parse --git-dir": []byte(".git\n"),
|
|
"git rev-parse --git-common-dir": []byte(".git\n"),
|
|
"git status --porcelain=v1 --untracked-files=all": nil,
|
|
"git rev-parse HEAD": []byte(commit + "\n"),
|
|
"git ls-remote --exit-code origin refs/heads/main": []byte(commit + "\trefs/heads/main\n"),
|
|
"git show -s --format=%ct " + commit: []byte("1720000000\n"),
|
|
}}
|
|
result, err := Inspect(context.Background(), runner, "/source", "main")
|
|
if err != nil || result.Commit != commit || result.Epoch != 1720000000 {
|
|
t.Fatalf("result=%+v err=%v", result, err)
|
|
}
|
|
}
|
|
|
|
func TestInspectExplainsUnsupportedLinkedWorktreeBeforeRemoteOrBuildWork(t *testing.T) {
|
|
runner := &recordingRunner{responses: map[string][]byte{
|
|
"git rev-parse --git-dir": []byte("/repo/.git/worktrees/release\n"),
|
|
"git rev-parse --git-common-dir": []byte("/repo/.git\n"),
|
|
}}
|
|
_, err := Inspect(context.Background(), runner, "/source", "main")
|
|
if err == nil || !strings.Contains(err.Error(), "linked Git worktrees") || len(runner.calls) != 2 {
|
|
t.Fatalf("calls=%#v err=%v", runner.calls, err)
|
|
}
|
|
}
|