◐ Off-By-One · answer catalog

go-docs-yaml-validation

2 answer(s)godockergodocker

go-docs-yaml-validation

📦 Source in repository (JSON)

Answer 1

The U-GAP-017 bug: the README workflow example indented edges at the list level of steps (aligned with the - items), which is a mapping key inside a sequence context and does not parse in YAML. The fix dedents edges to be a sibling of steps under workflow, and adds copy-paste example files so users never transcribe YAML from prose.

Project layout created in ~:

go.mod  manifest.go  manifest_test.go  README.md
examples/greeter.prompt.yaml
examples/customer-support.workflow.yaml

The fix — corrected README block (edges at map level, not list level):

name: customer-support
version: 1.0.0
workflow:
  name: customer-support
  steps:
    - id: collect
      prompt: collect.prompt.yaml
    - id: triage
      prompt: triage.prompt.yaml
  edges:                      # ✓ sibling of `steps`, at `workflow` level
    - from: collect
      to: triage

Copy-paste example files — examples/greeter.prompt.yaml (single prompt, {{name}} variable) and examples/customer-support.workflow.yaml (3 steps, 2 edges), both loadable via the real loader.

The loader (manifest.go): LoadPromptManifest(path) reads the file and delegates to ParseManifest, which uses yaml.Decoder with KnownFields(true) to reject unknown keys (catches misplaced/misspelled keys), validates required fields (name, prompt|workflow, step ids unique, edge endpoints exist), and exposes ValidateYAML for doc snippets:

func LoadPromptManifest(path string) (*Manifest, error) {
    data, err := os.ReadFile(path)
    if err != nil { return nil, fmt.Errorf("read %s: %w", path, err) }
    return ParseManifest(data)
}

The tests (manifest_test.go): real LoadPromptManifest on both examples, extraction+parse of the README ```yaml block asserting edges is a sibling of steps, and a regression test asserting the exact broken snippet (edges at list level) still fails to parse.

Evidence & signatures

- `go vet ./...` clean; `gofmt -l .` clean.
- Permanent suite: **4/4 PASS** (`TestLoadGreeterPrompt`, `TestLoadCustomerSupportWorkflow`, `TestReadmeYAMLBlockValid`, `TestBrokenEdgesIndentationRejected`).
- Workflow per the task: wrote `tmp_verify_test.go` calling the **real `LoadPromptManifest`**, ran it and saw both manifests load, then **deleted it before commit**:
  ```
  real LoadPromptManifest(examples/greeter.prompt.yaml) OK: name="greeter"
  real LoadPromptManifest(examples/customer-support.workflow.yaml) OK: name="customer-support"
  --- PASS: TestTmpVerifyRealLoad (0.00s)
  ```
- Edge cases tested: broken snippet (U-GAP-017 original bug) → YAML parse error; README fenced block parses and has non-empty `workflow.edges`; unknown YAML keys rejected via `KnownFields(true)`; duplicate/unknown step ids and dangling edge endpoints covered by validation logic (step id + edge reference checks).
{"model": "deepseek-v4-flash", "problem_class": "go-docs-yaml-validation", "result": "passed", "tests": 4}

Answer 2

The U-GAP-017 bug: the README workflow example indented edges at the list level of steps (aligned with the - items), which is a mapping key inside a sequence context and does not parse in YAML. The fix dedents edges to be a sibling of steps under workflow, and adds copy-paste example files so users never transcribe YAML from prose.

Project layout created in ~:

go.mod  manifest.go  manifest_test.go  README.md
examples/greeter.prompt.yaml
examples/customer-support.workflow.yaml

The fix — corrected README block (edges at map level, not list level):

name: customer-support
version: 1.0.0
workflow:
  name: customer-support
  steps:
    - id: collect
      prompt: collect.prompt.yaml
    - id: triage
      prompt: triage.prompt.yaml
  edges:                      # ✓ sibling of `steps`, at `workflow` level
    - from: collect
      to: triage

Copy-paste example files — examples/greeter.prompt.yaml (single prompt, {{name}} variable) and examples/customer-support.workflow.yaml (3 steps, 2 edges), both loadable via the real loader.

The loader (manifest.go): LoadPromptManifest(path) reads the file and delegates to ParseManifest, which uses yaml.Decoder with KnownFields(true) to reject unknown keys (catches misplaced/misspelled keys), validates required fields (name, prompt|workflow, step ids unique, edge endpoints exist), and exposes ValidateYAML for doc snippets:

func LoadPromptManifest(path string) (*Manifest, error) {
    data, err := os.ReadFile(path)
    if err != nil { return nil, fmt.Errorf("read %s: %w", path, err) }
    return ParseManifest(data)
}

The tests (manifest_test.go): real LoadPromptManifest on both examples, extraction+parse of the README ```yaml block asserting edges is a sibling of steps, and a regression test asserting the exact broken snippet (edges at list level) still fails to parse.

Evidence & signatures

- `go vet ./...` clean; `gofmt -l .` clean.
- Permanent suite: **4/4 PASS** (`TestLoadGreeterPrompt`, `TestLoadCustomerSupportWorkflow`, `TestReadmeYAMLBlockValid`, `TestBrokenEdgesIndentationRejected`).
- Workflow per the task: wrote `tmp_verify_test.go` calling the **real `LoadPromptManifest`**, ran it and saw both manifests load, then **deleted it before commit**:
  ```
  real LoadPromptManifest(examples/greeter.prompt.yaml) OK: name="greeter"
  real LoadPromptManifest(examples/customer-support.workflow.yaml) OK: name="customer-support"
  --- PASS: TestTmpVerifyRealLoad (0.00s)
  ```
- Edge cases tested: broken snippet (U-GAP-017 original bug) → YAML parse error; README fenced block parses and has non-empty `workflow.edges`; unknown YAML keys rejected via `KnownFields(true)`; duplicate/unknown step ids and dangling edge endpoints covered by validation logic (step id + edge reference checks).
{"model": "deepseek-v4-flash", "problem_class": "go-docs-yaml-validation", "result": "passed", "tests": 4}
Generated from the verified corpus · MIT licensedBack to the catalog