Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/reqstream/modeling/requirements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,16 @@ sections:
- lint
tests:
- Linter_Lint_WithMultipleCycles_ReportsAllCycles

- id: ReqStream-Lint-UnknownChildReference
title: >-
The requirements loader shall report an error when a requirement references a child
requirement ID that does not exist.
justification: |
References to non-existent child requirement IDs indicate typos or stale references.
Reporting these as errors ensures that requirement hierarchies remain consistent and
prevents silent failures in trace matrix generation.
tags:
- lint
tests:
- Requirements_Load_WithMissingChild_ReportsError
9 changes: 9 additions & 0 deletions src/DemaConsulting.ReqStream/Modeling/RequirementsLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,15 @@ private static void ValidateCyclesFrom(
{
foreach (var childId in requirement.Children)
{
if (!allRequirements.ContainsKey(childId))
{
issues.Add(new LintIssue(
requirement.Location ?? reqId,
LintSeverity.Error,
$"Requirement '{reqId}' references unknown child '{childId}'"));
continue;
}
Comment thread
Malcolmnixon marked this conversation as resolved.

if (visiting.Contains(childId))
{
var cycleStart = currentPath.IndexOf(childId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ public void Requirements_Load_RequirementWithChildren_ParsesChildrenCorrectly()
children:
- ""AUTH-001""
- ""AUTH-002""
- id: ""AUTH-001""
title: ""The system shall validate user credentials.""
- id: ""AUTH-002""
title: ""The system shall reject invalid credentials.""
";
var filePath = Path.Combine(_testDirectory, "requirements.yaml");
File.WriteAllText(filePath, yamlContent);
Expand Down
65 changes: 65 additions & 0 deletions test/DemaConsulting.ReqStream.Tests/Tracing/TestMissingChild.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) 2026 DEMA Consulting
Comment thread
Malcolmnixon marked this conversation as resolved.
Outdated
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using DemaConsulting.ReqStream.Modeling;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DemaConsulting.ReqStream.Tests.Tracing;

/// <summary>
/// Tests verifying that requirements with missing child references are reported as errors.
/// </summary>
[TestClass]
public class TestMissingChildRequirement
{
/// <summary>
/// Verifies that loading a requirements file where a requirement references a
/// non-existent child ID produces an error-level lint issue.
/// </summary>
[TestMethod]
public void Requirements_Load_WithMissingChild_ReportsError()
{
var yaml = @"---
sections:
- title: ""Test""
requirements:
- id: ""PARENT""
title: ""Parent requirement""
children:
- ""NONEXISTENT""
";
var path = Path.Combine(Path.GetTempPath(), $"test_{Guid.NewGuid()}.yaml");
File.WriteAllText(path, yaml);
try
{
var result = Requirements.Load(path);

Assert.IsTrue(result.HasErrors, "Expected errors for missing child reference");
Assert.IsNull(result.Requirements, "Requirements should be null when errors exist");
Assert.IsTrue(
result.Issues.Any(i => i.Severity == LintSeverity.Error && i.Description.Contains("NONEXISTENT")),
"Expected an error mentioning the unknown child 'NONEXISTENT'");
}
finally
{
File.Delete(path);
}
}
}