Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 22, 2025

The tsort implementation was missing critical POSIX-required error detection and stdin handling. It would silently fail on cycles, ignore incomplete pairs, and reject - as stdin.

Changes

Cycle detection

  • Track all items during parsing vs successfully sorted items
  • Items remaining after topological sort indicate cycles
  • Report cycle members to stderr with exit code 1

Odd token validation

  • Detect incomplete pairs (odd number of whitespace-separated tokens)
  • Report error to stderr with exit code 1

Stdin handling

  • Changed from input_stream_opt to input_stream(path, dashed_stdin=true)
  • Now correctly treats - argument as stdin

Test coverage

  • Added 18 integration tests covering basic functionality, edge cases, and error conditions
  • Tests include chains, cycles, empty input, self-loops, and various input formats

Example

Before (silently fails):

$ echo "a b b a" | tsort
# no output, exit 0

After (detects cycle):

$ echo "a b b a" | tsort
stdin: input contains a loop:
stdin: a
stdin: b
a
b
# exit 1

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • pubs.opengroup.org
    • Triggering command: /usr/bin/curl curl -s REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Audit tsort utility</issue_title>
<issue_description>Study the attached POSIX spec for tsort:

tsort.html

then audit the tsort implementation for correctness, completeness and integration test completeness. identify any gaps, and plan and implement changes to address gaps. DO NOT add tests that require special test environments (i.e. other that non-root user in GH CI/CD).
</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…en validation, and comprehensive tests

Co-authored-by: jgarzik <[email protected]>
Copilot AI changed the title [WIP] Audit and improve tsort utility implementation Audit and fix tsort: add cycle detection, odd token validation, and stdin support Dec 22, 2025
Copilot AI requested a review from jgarzik December 22, 2025 07:34
@jgarzik jgarzik closed this Dec 22, 2025
@jgarzik jgarzik deleted the copilot/audit-tsort-utility branch December 22, 2025 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audit tsort utility

2 participants