Skip to content
Testaroo
yaml708 B

YAML Duplicate Keys

Duplicate keys at three nesting levels, including a duplicated top-level sequence. The spec forbids them; most loaders keep the last silently, a few keep the first, and strict linters reject the document. The file publishes the last-wins answer.

Preview, first 30 linesyaml
# Duplicate keys. YAML 1.2 says a mapping MUST NOT have duplicate keys, but loaders disagree
# about what to do: most keep the LAST occurrence silently, some keep the first, a few raise,
# and strict linters reject the document outright. A config file that quietly loses a setting
# this way is very hard to debug, which is why this fixture exists.
job:
  image: registry.example.invalid/ci/runner:1.4
  timeout: 10
  retries: 1
  timeout: 30
  image: registry.example.invalid/ci/runner:2.0

stages:
  - build
  - test

stages:
  - deploy

nested:
  a:
    x: 1
  a:
    y: 2

expected_last_wins:
  job_timeout: 30
  job_image: registry.example.invalid/ci/runner:2.0
  stages: deploy
  nested_a_has_x: false

Specifications

Duplicated Keys
5
Spec Says
must not appear
Common Behaviour
last wins
Publishes Expected Last Wins
true

Testing contract

Expected to recover
Scenario
Load a mapping containing duplicate keys and record which occurrence the loader keeps
Expected result
A last-wins loader yields job.timeout 30 and stages [deploy]; a strict loader rejects the document with a duplicate-key error instead

What is a .yaml file?

YAML (YAML Ain't Markup Language) is a human-readable data-serialization format using indentation, key-value pairs, and lists, and is a superset of JSON. It supports comments, anchors, and multiple documents per file, favoring readability for configuration. Its indentation sensitivity makes it error-prone to hand-edit.

How to use this file

Use an example YAML file to test config parsers, indentation and anchor handling, multi-document streams, and safe-loading to avoid arbitrary object construction.

How to use this file for testing

“YAML Duplicate Keys” is a deterministic Testaroo fixture for Config parsing, Encoding detection, Editor testing. TOML and INI configuration files with nested sections and typed values, for testing config parsers and loaders.

Documented properties for this file: YAML · 708 bytes. Compare results against paired or grouped companions on this page when present (clean↔damaged, searchable↔scanned, or format twins) so scores stay reproducible across runs.

Download the file once, keep the path stable in CI or local scripts, and treat the spec table as the contract: dimensions, seeds, field lists, and roles are intentional. Corrupt or invalid samples are labelled as such, expect parsers to fail loudly rather than silently accept them.

Pipeline and infrastructure fixtures are inert configuration: steps reference fictional images and scripts, and nothing here executes. Run your linter, schema validator, migrator, or policy engine against them, and expect the deprecated-syntax and intentionally invalid variants to be rejected.

Point your config loader at the file and assert it reads the documented sections and typed values, including any deliberately-tricky nesting or comments.

Code examples

import yaml  # pip install pyyaml

with open("duplicate-keys.yaml") as f:
    data = yaml.safe_load(f)
print(data)

Generated by generation/pipelines.py. Free for any use, no attribution required, license.