Separate example contracts and relax run ID format test

This commit is contained in:
2026-11-26 03:07:43 +00:00
parent fef0530533
commit fed376351f
4 changed files with 57 additions and 29 deletions

View File

@@ -630,6 +630,9 @@ for a general deadline framework.
**Assessment:** Test readability/refactoring opportunity; original low.
**Status:** Resolved. Loading, composition, inheritance, and listing have focused
checks; the parent is resolved independently. Repeated focused and CLI tests pass.
**Source:** [CPLX-008](03-complexity.md#cplx-008--maintained-example-testing-combines-several-independent-concerns).
One nested test combines loading, transcript handling, composition, generated
@@ -642,6 +645,9 @@ and local expectations; do not replace it with an assertion DSL or new snapshots
**Assessment:** Incidental test restriction; original P3, small cleanup.
**Status:** Resolved. Uniqueness and safety remain covered without a private
format regex; allocation, partial-write, and versioned session checks are retained.
**Source:** [TEST-006](08-testing.md#test-006--run-id-test-freezes-an-incidental-private-format).
Remove the exact timestamp/hex-width run-ID regex while retaining uniqueness,

View File

@@ -885,6 +885,8 @@ prefix-length/live-quality gates, or production prompt rewrite.
## Stage 33 — Separate Example Tests And Unfreeze Run-ID Format
**Completed.**
**Coverage:** CAT-028/CAT-029. **Prerequisites:** Stages 20, 25–26.
Refactor cli/example_contract_test.go into independent resolved fixtures and focused

View File

@@ -26,9 +26,7 @@ import (
"go.maximumdirect.net/promptkit"
)
func TestMaintainedExamplesLoadResolveAndList(t *testing.T) {
components := productionTestComponents(t)
completePipelines := make(map[string]pipeline.ResolvedPipeline)
func TestMaintainedExamplesLoadAndParse(t *testing.T) {
for _, example := range maintainedExampleFiles(t) {
t.Run(example.name, func(t *testing.T) {
cfg := loadMaintainedExample(t, example.path)
@@ -39,16 +37,22 @@ func TestMaintainedExamplesLoadResolveAndList(t *testing.T) {
if err != nil {
t.Fatalf("read maintained transcript %q: %v", example.transcriptPath, err)
}
document, err := transcript.New().Parse(context.Background(), contracts.ParseRequest{
Path: example.transcriptPath,
Raw: raw,
})
if err != nil {
document, err := transcript.New().Parse(context.Background(), contracts.ParseRequest{Path: example.transcriptPath, Raw: raw})
if err != nil || document == nil {
t.Fatalf("parse maintained transcript %q: %v", example.transcriptPath, err)
}
if len(document.Units) == 0 {
t.Fatalf("maintained transcript %q has no parsed units", example.transcriptPath)
}
})
}
}
func TestMaintainedExamplesResolveComposition(t *testing.T) {
components := productionTestComponents(t)
for _, example := range maintainedExampleFiles(t) {
t.Run(example.name, func(t *testing.T) {
cfg := loadMaintainedExample(t, example.path)
for _, pipelineID := range example.pipelineIDs {
effective, err := cfg.Resolve(resolveInputForMaintainedExample(components, pipelineID))
if err != nil {
@@ -62,25 +66,9 @@ func TestMaintainedExamplesLoadResolveAndList(t *testing.T) {
t.Fatalf("materialize maintained example references for %q: %v", pipelineID, err)
}
if example.name == "complete" {
if pipelineID == "dnd-session-development" {
if materialized.ChunkControls.MaxAdditionalTurns != 0 || materialized.Chunk.LLMProfile != "notarius/dnd-extraction-development" {
t.Fatalf("development native controls=%#v profile=%q", materialized.ChunkControls, materialized.Chunk.LLMProfile)
}
parent, found := completePipelines["dnd-session"]
if !found {
t.Fatal("complete parent pipeline was not resolved before its development variant")
}
if strings.Join(exampleStepLaneIDs(materialized), "|") != strings.Join(exampleStepLaneIDs(parent), "|") {
t.Fatalf("development variant steps and lanes = %v, want parent composition %v", exampleStepLaneIDs(materialized), exampleStepLaneIDs(parent))
}
if got, want := strings.Join(generatedReferenceBindingDescriptions(materialized), "|"), strings.Join(generatedReferenceBindingDescriptions(parent), "|"); got != want {
t.Fatalf("development generated reference bindings = %q, want parent bindings %q", got, want)
}
}
if got := exampleStepLaneIDs(materialized); strings.Join(got, "|") != "describe-session:item-registry,location-registry,npc-registry,scene-descriptions|extract-events:combat-turns,item-occurrences,location-occurrences,npc-occurrences,spells|track-enemies:enemy-events" {
t.Fatalf("complete example steps and lanes = %v, want the documented D&D extractor composition", got)
}
completePipelines[pipelineID] = materialized
locationLane := referenceContractLane(t, materialized, "location-registry")
if locationLane.ArtifactKind != dnd.LocationRegistryKind || locationLane.Extract.Module != locationextract.Key || locationLane.Merge.Module != pipeline.DefaultMergeModule || locationLane.Normalize.Module != locationnormalize.Key {
t.Fatalf("location lane = %#v, want typed registry composition", locationLane)
@@ -131,6 +119,43 @@ func TestMaintainedExamplesLoadResolveAndList(t *testing.T) {
}
}
}
})
}
}
func TestMaintainedExampleDevelopmentInheritsComposition(t *testing.T) {
path := repositoryPath("examples", "dnd-complete", "config.yml")
cfg := loadMaintainedExample(t, path)
components := productionTestComponents(t)
resolve := func(id string) pipeline.ResolvedPipeline {
t.Helper()
effective, err := cfg.Resolve(resolveInputForMaintainedExample(components, id))
if err != nil {
t.Fatalf("resolve %q: %v", id, err)
}
result, _, err := pipeline.MaterializeReferences(effective.ResolvedPipeline, catalogFromRegistries(components.registries), pipeline.ReferenceMaterializationOptions{ConfigPath: path, WorkingDir: filepath.Dir(path)})
if err != nil {
t.Fatalf("materialize %q: %v", id, err)
}
return result
}
development := resolve("dnd-session-development")
parent := resolve("dnd-session")
if development.ChunkControls.MaxAdditionalTurns != 0 || development.Chunk.LLMProfile != "notarius/dnd-extraction-development" {
t.Fatalf("development native controls=%#v profile=%q", development.ChunkControls, development.Chunk.LLMProfile)
}
if got, want := exampleStepLaneIDs(development), exampleStepLaneIDs(parent); !reflect.DeepEqual(got, want) {
t.Fatalf("development variant steps and lanes = %v, want %v", got, want)
}
if got, want := generatedReferenceBindingDescriptions(development), generatedReferenceBindingDescriptions(parent); !reflect.DeepEqual(got, want) {
t.Fatalf("development generated reference bindings = %v, want %v", got, want)
}
}
func TestMaintainedExamplesList(t *testing.T) {
components := productionTestComponents(t)
for _, example := range maintainedExampleFiles(t) {
t.Run(example.name, func(t *testing.T) {
var stdout, stderr strings.Builder
code := RunWithOptions([]string{"pipeline", "list", "--config", example.path, "--format", "json"}, &stdout, &stderr, productionOptionsFromComponents(components))
var ids []string

View File

@@ -3,7 +3,6 @@ package cli
import (
"os"
"path/filepath"
"regexp"
"strings"
"testing"
"time"
@@ -13,16 +12,12 @@ import (
func TestDefaultRunIDGeneratorProducesUniqueSafeIDs(t *testing.T) {
startedAt := time.Unix(0, 123456789).UTC()
pattern := regexp.MustCompile(`^run-123456789-[0-9a-f]{32}$`)
seen := make(map[string]struct{}, 256)
for i := 0; i < 256; i++ {
runID, err := defaultRunIDGenerator(startedAt)
if err != nil {
t.Fatal(err)
}
if !pattern.MatchString(runID) {
t.Fatalf("run ID %q does not match production format", runID)
}
if err := validateRunID(runID); err != nil {
t.Fatalf("run ID %q is not path-safe: %v", runID, err)
}