Distinguish production tags from complete diagnostic tags

This commit is contained in:
2026-12-06 03:21:39 +00:00
parent 0205f32f28
commit d5154cf59d
11 changed files with 155 additions and 10 deletions

View File

@@ -422,7 +422,7 @@ func runCIDelivery(ctx context.Context, invocation cli.Invocation, stdout, stder
return 1
}
if strings.HasPrefix(invocation.ExpectedTag, "releasekit-test/") {
if releaseidentity.IsDiagnosticTag(invocation.ExpectedTag) {
return runDiagnosticDelivery(ctx, invocation, stdout, stderr)
}

View File

@@ -49,13 +49,22 @@ func TestMultiModuleSelectorMapsSelectorsAndTags(t *testing.T) {
if output := runModuleSelectorError(t, helper, "tag", "feature/v1.2.3", mapPath); !strings.Contains(output, "ambiguous") {
t.Fatalf("ambiguous event error = %q", output)
}
if output := runModuleSelectorError(t, helper, "tag", "releasekit-test/ckconfig/invalid", ""); !strings.Contains(output, "invalid diagnostic") {
if output := runModuleSelectorError(t, helper, "tag", "releasekit-test/ckconfig/invalid", ""); !strings.Contains(output, "no module map row") {
t.Fatalf("malformed diagnostic error=%q", output)
}
if err := os.WriteFile(mapPath, []byte("space\tfeature/*\tintegrations/ck config\tprofiles/core release.json\n"), 0o600); err != nil {
t.Fatal(err)
}
reservedMap := filepath.Join(t.TempDir(), "production.tsv")
if err := os.WriteFile(reservedMap, []byte("product\treleasekit-test/product/*\t-\treleasekit.json\n"), 0600); err != nil {
t.Fatal(err)
}
for _, tag := range []string{"releasekit-test/product/v1.2.3", "releasekit-test/product/2026-12-01"} {
if got := runModuleSelector(t, helper, "tag", tag, reservedMap); !strings.HasPrefix(got, "product\t") {
t.Fatalf("production tag=%s mapping=%q", tag, got)
}
}
got := runModuleSelector(t, helper, "tag", "feature/v1.2.3", mapPath)
want := "space\tfeature/*\tintegrations/ck config\tprofiles/core release.json"
if strings.TrimSpace(got) != want {

View File

@@ -57,6 +57,39 @@ func TestCIDeliveryChecksFullCalendarTagAgainstProfile(t *testing.T) {
}
}
func TestCIDeliveryProductionTagsMayUseDiagnosticPrefix(t *testing.T) {
for _, legacy := range []bool{false, true} {
t.Run(fmt.Sprintf("legacy=%t", legacy), func(t *testing.T) {
repo := newCLIRepository(t)
version, tag := "2026-12-01", "releasekit-test/product/2026-12-01"
profile := `{"product":"Config","source":{"tag_prefix":"releasekit-test/product"},"version":{"format":"date"}}`
note := "docs/releases/" + version + ".md"
if legacy {
version, tag = "v1.2.3", "releasekit-test/product/v1.2.3"
profile = `{"product":"Config","module_dir":"releasekit-test/product"}`
note = "releasekit-test/product/docs/releases/" + version + ".md"
writeRepositoryFile(t, repo, "releasekit-test/product/go.mod", "module example.com/product\n\ngo 1.27.0\n")
writeRepositoryFile(t, repo, "releasekit-test/product/product.go", "package product\n")
}
writeRepositoryFile(t, repo, note, "# Config "+version+"\n")
writeRepositoryFile(t, repo, "releasekit.json", profile)
cliGitRun(t, repo, "add", ".")
cliGitRun(t, repo, "commit", "-m", "configure production tag prefix")
var out, diag bytes.Buffer
if code := run(t.Context(), []string{"check", "--repo", repo, version}, &out, &diag); code != 0 {
t.Fatalf("check code=%d diagnostic=%s", code, &diag)
}
commit := cliGitOutput(t, repo, "rev-parse", "HEAD")
cliGitRun(t, repo, "tag", "-a", "-m", "# Config "+version, tag)
out.Reset()
diag.Reset()
if code := run(t.Context(), []string{"ci-deliver", "--repo", repo, "--prepared", "--commit", commit, tag}, &out, &diag); code != 2 || !strings.Contains(diag.String(), "delivery.forge") {
t.Fatalf("production dispatch code=%d output=%s diagnostics=%s", code, &out, &diag)
}
})
}
}
func TestSourceCheckCommandUsesSelectedDirectoryAndEnvironment(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("POSIX shell check")

View File

@@ -181,6 +181,31 @@ func TestWoodpeckerTagDeliveryTemplate(t *testing.T) {
})
}
func TestSingleProductWorkflowClassifiesCompleteDiagnosticTags(t *testing.T) {
for _, file := range []string{"examples/woodpecker/tag-delivery.yml", "examples/woodpecker/releasekit-source-delivery.yml", "examples/source-only/.woodpecker/delivery.yml"} {
t.Run(file, func(t *testing.T) {
body := readWorkflowFile(t, cliRepositoryRoot(t), file)
block, err := extractWoodpeckerCommand(body, "deliver")
if err != nil {
t.Fatal(err)
}
guard, _, ok := strings.Cut(block, "git check-ref-format")
if !ok {
t.Fatal("workflow has no tag preparation boundary")
}
guard = strings.ReplaceAll(guard, "$${", "${")
for _, tag := range []string{"releasekit-test/product/v1.2.3", "releasekit-test/product/2026-12-01", "releasekit-test/root/" + strings.Repeat("a", 32)} {
if output, err := executeWoodpeckerBlock(guard, t.TempDir(), map[string]string{"CI_COMMIT_TAG": tag, "CI_COMMIT_SHA": strings.Repeat("b", 40)}); err != nil {
t.Fatalf("valid tag=%s output=%s error=%v", tag, output, err)
}
}
if output, err := executeWoodpeckerBlock(guard, t.TempDir(), map[string]string{"CI_COMMIT_TAG": "releasekit-test/foreign/" + strings.Repeat("a", 32), "CI_COMMIT_SHA": strings.Repeat("b", 40)}); err == nil {
t.Fatalf("foreign selector accepted: %s", output)
}
})
}
}
func TestWoodpeckerTagDeliveryUsesTaggedModuleVersion(t *testing.T) {
// Synthetic downloads must leave the caller's module cache untouched.
callerCache := t.TempDir()

View File

@@ -421,6 +421,11 @@ calendar, and diagnostic fixtures; review local links and prose whitespace.
## 10. Diagnostic dispatch intercepts valid production tag prefixes
**Completed:** CLI and maintained bootstrap dispatch classify the complete
diagnostic spelling. Production calendar and legacy nested-module tags beneath
the same prefix follow normal delivery; manifest and foreign-selector rejection
remain intact. Identity, selector, CLI, guard, and maintained-workflow tests pass.
**Priority:** P2. **Stages:** 2, 4, 11, 14.
**Relevant code:** `runCIDelivery` in the

View File

@@ -21,11 +21,15 @@ if [ "$mode" = tag ]; then
diagnostic=${value#releasekit-test/}
selector=${diagnostic%%/*}
attempt=${diagnostic#*/}
case "$diagnostic" in */*) ;; *) echo "invalid diagnostic tag" >&2; exit 2 ;; esac
case "$attempt" in *[!0-9a-f]*|'') echo "invalid diagnostic attempt" >&2; exit 2 ;; esac
[ "${#attempt}" -eq 32 ] && [ -n "$selector" ] || { echo "invalid diagnostic tag" >&2; exit 2; }
mode=selector
value=$selector
case "$attempt" in
*[!0-9a-f]*|'') ;;
*)
if [ "${#attempt}" -eq 32 ] && [ -n "$selector" ] && [ "$diagnostic" != "$attempt" ]; then
mode=selector
value=$selector
fi
;;
esac
;;
esac
fi

View File

@@ -17,7 +17,19 @@ steps:
set -eu
test -n "$${CI_COMMIT_TAG}"
test -n "$${CI_COMMIT_SHA}"
case "$${CI_COMMIT_TAG}" in releasekit-test/root/*) ;; releasekit-test/*) echo 'Unknown diagnostic selector' >&2; exit 2 ;; esac
case "$${CI_COMMIT_TAG}" in
releasekit-test/*)
releasekit_diagnostic=$${CI_COMMIT_TAG#releasekit-test/}
releasekit_selector=$${releasekit_diagnostic%%/*}
releasekit_attempt=$${releasekit_diagnostic#*/}
case "$${releasekit_attempt}" in
*[!0-9a-f]*|'') ;;
*)
if [ "$${#releasekit_attempt}" -eq 32 ] && [ -n "$${releasekit_selector}" ] && [ "$${releasekit_diagnostic}" != "$${releasekit_attempt}" ]; then
[ "$${releasekit_selector}" = root ] || { echo 'Unknown diagnostic selector' >&2; exit 2; }
fi ;;
esac ;;
esac
git check-ref-format "refs/tags/$${CI_COMMIT_TAG}"
git fetch origin "refs/tags/$${CI_COMMIT_TAG}:refs/tags/$${CI_COMMIT_TAG}"
tag_commit=$(git rev-parse --verify "refs/tags/$${CI_COMMIT_TAG}^{commit}")

View File

@@ -17,7 +17,19 @@ steps:
set -eu
test -n "$${CI_COMMIT_TAG}"
test -n "$${CI_COMMIT_SHA}"
case "$${CI_COMMIT_TAG}" in releasekit-test/root/*) ;; releasekit-test/*) echo 'Unknown diagnostic selector' >&2; exit 2 ;; esac
case "$${CI_COMMIT_TAG}" in
releasekit-test/*)
releasekit_diagnostic=$${CI_COMMIT_TAG#releasekit-test/}
releasekit_selector=$${releasekit_diagnostic%%/*}
releasekit_attempt=$${releasekit_diagnostic#*/}
case "$${releasekit_attempt}" in
*[!0-9a-f]*|'') ;;
*)
if [ "$${#releasekit_attempt}" -eq 32 ] && [ -n "$${releasekit_selector}" ] && [ "$${releasekit_diagnostic}" != "$${releasekit_attempt}" ]; then
[ "$${releasekit_selector}" = root ] || { echo 'Unknown diagnostic selector' >&2; exit 2; }
fi ;;
esac ;;
esac
git check-ref-format "refs/tags/$${CI_COMMIT_TAG}"
git fetch origin "refs/tags/$${CI_COMMIT_TAG}:refs/tags/$${CI_COMMIT_TAG}"
tag_commit=$(git rev-parse --verify "refs/tags/$${CI_COMMIT_TAG}^{commit}")

View File

@@ -21,7 +21,19 @@ steps:
set -eu
test -n "$${CI_COMMIT_TAG}"
test -n "$${CI_COMMIT_SHA}"
case "$${CI_COMMIT_TAG}" in releasekit-test/root/*) ;; releasekit-test/*) echo 'Unknown diagnostic selector' >&2; exit 2 ;; esac
case "$${CI_COMMIT_TAG}" in
releasekit-test/*)
releasekit_diagnostic=$${CI_COMMIT_TAG#releasekit-test/}
releasekit_selector=$${releasekit_diagnostic%%/*}
releasekit_attempt=$${releasekit_diagnostic#*/}
case "$${releasekit_attempt}" in
*[!0-9a-f]*|'') ;;
*)
if [ "$${#releasekit_attempt}" -eq 32 ] && [ -n "$${releasekit_selector}" ] && [ "$${releasekit_diagnostic}" != "$${releasekit_attempt}" ]; then
[ "$${releasekit_selector}" = root ] || { echo 'Unknown diagnostic selector' >&2; exit 2; }
fi ;;
esac ;;
esac
git check-ref-format "refs/tags/$${CI_COMMIT_TAG}"
git fetch origin "refs/tags/$${CI_COMMIT_TAG}:refs/tags/$${CI_COMMIT_TAG}"
tag_commit=$(git rev-parse --verify "refs/tags/$${CI_COMMIT_TAG}^{commit}")

View File

@@ -61,3 +61,18 @@ func ValidateDiagnosticSelector(ctx context.Context, repository, selector string
}
return git.CheckTagRef(ctx, repository, "releasekit-test/"+selector+"/"+strings.Repeat("0", 32))
}
// IsDiagnosticTag recognizes the complete diagnostic spelling before manifest
// verification. Production identifiers have their own version separators.
func IsDiagnosticTag(tag string) bool {
rest, ok := strings.CutPrefix(tag, "releasekit-test/")
if !ok {
return false
}
selector, attempt, ok := strings.Cut(rest, "/")
if !ok || selector == "" || len(attempt) != 32 || strings.ToLower(attempt) != attempt {
return false
}
_, err := hex.DecodeString(attempt)
return err == nil
}

View File

@@ -39,6 +39,24 @@ func TestNormalizeSource(t *testing.T) {
}
}
func TestDiagnosticClassificationUsesCompleteTag(t *testing.T) {
for _, test := range []struct {
tag string
want bool
}{
{"releasekit-test/root/" + strings.Repeat("a", 32), true},
{"releasekit-test/product/v1.2.3", false},
{"releasekit-test/product/2026-12-01", false},
{"releasekit-test/product/2026.12.0", false},
{"releasekit-test/root/invalid", false},
{"releasekit-test/" + strings.Repeat("a", 32), false},
} {
if got := IsDiagnosticTag(test.tag); got != test.want {
t.Fatalf("tag=%q result=%t", test.tag, got)
}
}
}
func TestLoadSourceUsesSelectedDeclaration(t *testing.T) {
repo := t.TempDir()
gitIdentityRun(t, repo, "init", "-q")