Skip to content

Add --reverse to fedify lookup output ordering#609

Merged
dahlia merged 9 commits into
fedify-dev:mainfrom
dahlia:cli/lookup-reverse
Mar 8, 2026
Merged

Add --reverse to fedify lookup output ordering#609
dahlia merged 9 commits into
fedify-dev:mainfrom
dahlia:cli/lookup-reverse

Conversation

@dahlia
Copy link
Copy Markdown
Member

@dahlia dahlia commented Mar 8, 2026

Summary

This PR adds a new --reverse option to fedify lookup so users can reverse the presentation order of emitted results without changing lookup semantics across default multi-input lookup, --traverse collection output, and --recurse chain output.

Changes

Added --reverse option parsing to the lookup command, added lookup.reverse support in the config schema, and applied reverse ordering logic to default multi-input output, recurse chain output, and traversal output.

Preserved existing behavior and failure semantics by keeping streaming traversal when --reverse is not enabled, preserving already-fetched items in --traverse --reverse when traversal fails later, and preserving root-object emission in recurse-mode failure paths after the root object has been fetched.

Updated documentation in docs/cli.md by adding a --reverse option section and adding reverse = false to the [lookup] config example, and updated changelog entries in CHANGES.md.

Tests

Added parser/config tests for --reverse, added ordering helper tests, and added async collection tests to verify partial-item preservation on iterator failure, all in packages/cli/src/lookup.test.ts.

Ran deno test --allow-all packages/cli/src/lookup.test.ts, and all tests passed.

References

Closes #607

Implement the new --reverse option for fedify lookup and apply it
across default multi-input lookup, recurse chains, and traversal
output while preserving existing error and partial-output behavior.

Traversal now keeps streaming semantics when --reverse is disabled,
and reverse mode preserves already-fetched items even if traversal
fails later. Recurse mode also preserves root-object emission when a
later recursive fetch fails.

Update CLI docs and lookup config documentation, add changelog
entries, and expand lookup tests for option parsing, ordering, and
partial-collection behavior.

Fixes fedify-dev#607

Co-Authored-By: OpenAI Codex <codex@openai.com>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the fedify lookup command by introducing a --reverse option. This feature provides users with greater control over how results are displayed, allowing them to view fetched data in reverse order across various lookup modes. The implementation prioritizes maintaining existing functionality and error handling, ensuring a seamless and robust user experience while offering new flexibility in data presentation.

Highlights

  • New --reverse option: Introduced a --reverse option to the fedify lookup command, allowing users to reverse the presentation order of emitted results.
  • Output Ordering: The --reverse option now applies across default multi-input lookup, --traverse collection output, and --recurse chain output, affecting only presentation order without altering lookup semantics.
  • Error Handling and Preservation: Existing behavior and failure semantics are preserved, including streaming traversal when --reverse is not enabled, retaining already-fetched items in --traverse when traversal fails, and preserving root-object emission in recurse-mode failure paths.
  • Documentation and Changelog: Updated docs/cli.md with a new section for the --reverse option and added it to the config example. Changelog entries in CHANGES.md were also updated.
  • Testing: Comprehensive tests were added for parser/config, ordering helpers, and async collection to verify partial-item preservation on iterator failure.
Changelog
Activity
  • The author, dahlia, added parser/config tests for --reverse in packages/cli/src/lookup.test.ts.
  • Ordering helper tests were added to ensure correct functionality of the new toPresentationOrder utility.
  • Async collection tests were included to verify partial-item preservation on iterator failure, specifically for the collectAsyncItems utility.
  • All 63 tests in packages/cli/src/lookup.test.ts passed successfully, confirming the stability and correctness of the changes.
  • The pull request addresses and closes issue Add --reverse to fedify lookup to reverse output order in traversal/recurse modes #607.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@issues-auto-labeler issues-auto-labeler Bot added component/cli CLI tools related component/federation Federation object related component/collections Collections related labels Mar 8, 2026
@dahlia dahlia changed the title Add --reverse to fedify lookup output ordering Add --reverse to fedify lookup output ordering Mar 8, 2026
@dahlia dahlia requested a review from Copilot March 8, 2026 12:29
@dahlia dahlia added this to the Fedify 2.1 milestone Mar 8, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a --reverse option to the fedify lookup command, allowing users to reverse the presentation order of results for multi-input lookups, collection traversals, and recursive chains. The implementation correctly handles the necessary buffering for reversal while preserving existing streaming behavior when the option is not used. The changes are well-documented and include thorough tests.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a --reverse presentation option to fedify lookup so users can invert the output ordering of results across default multi-input lookups, --traverse collection traversal, and --recurse chain output, without changing lookup semantics.

Changes:

  • Added --reverse CLI parsing + config binding (lookup.reverse) and config schema support.
  • Implemented presentation-order helpers and applied reversal to recurse/traverse/default output paths.
  • Updated CLI docs and changelog to document the new option.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/cli/src/lookup.ts Adds --reverse option, introduces ordering/buffering helpers, and applies reversed presentation logic across modes.
packages/cli/src/lookup.test.ts Adds tests for --reverse parsing/config and helper behavior (toPresentationOrder, collectAsyncItems).
packages/cli/src/config.ts Extends lookup config schema with optional reverse boolean.
docs/cli.md Documents --reverse and adds reverse = false to lookup config example.
CHANGES.md Records the new --reverse option in the unreleased changelog.
Comments suppressed due to low confidence (1)

packages/cli/src/lookup.ts:1204

  • The default multi-URL lookup path now always buffers into successfulObjects and prints in a second pass, even when command.reverse is false. That changes the write/error behavior vs the prior one-pass write-in-loop (e.g., write failures occur after all spinner statuses are emitted) and adds an unnecessary extra pass. Consider only buffering when command.reverse is true; otherwise keep the original one-pass write flow.
  const successfulObjects: APObject[] = [];
  for (const [i, obj] of objects.entries()) {
    const url = command.urls[i];
    if (obj == null) {
      spinner.fail(`Failed to fetch ${colors.red(url)}`);

Comment thread packages/cli/src/lookup.test.ts
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 8, 2026

Codecov Report

❌ Patch coverage is 60.61947% with 89 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/cli/src/lookup.ts 60.44% 89 Missing ⚠️
Files with missing lines Coverage Δ
packages/cli/src/config.ts 83.49% <100.00%> (+0.16%) ⬆️
packages/cli/src/lookup.ts 66.37% <60.44%> (+22.86%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Add runLookup-level tests that verify emitted output order for
multi-input default lookup, recurse mode, and traverse mode when
--reverse is enabled.

To keep these tests deterministic and network-free, runLookup now
accepts injectable lookup/traverse dependencies with defaults bound to
the existing implementations. Production behavior is unchanged.

The new tests execute the real runLookup control flow, capture output,
and assert final ordering in each mode.

fedify-dev#609 (comment)

Co-Authored-By: OpenAI Codex <codex@openai.com>
@dahlia dahlia requested a review from Copilot March 8, 2026 12:45
@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Mar 8, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a --reverse option to the fedify lookup command, allowing users to reverse the output order of results. The feature is implemented across all relevant modes: default multi-input, collection traversal (--traverse), and recursive chain lookup (--recurse). The implementation correctly handles buffering when necessary (for traversal and multi-input modes) while preserving existing streaming behavior and failure semantics. The changes are well-tested, with new unit and integration tests covering the reverse ordering logic and error handling. Documentation and changelog have also been updated accordingly. The implementation appears solid and well-executed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread packages/cli/src/lookup.ts Outdated
Comment thread packages/cli/src/lookup.test.ts Outdated
Restore recurse-mode output timing so the root object is emitted
immediately when --reverse is not used, preserving prior
streaming/visibility semantics.

Also make runLookup accept an injected exit dependency and update
the runLookup ordering tests to use that injection instead of
global process.exit monkeypatching.

fedify-dev#609 (comment)
fedify-dev#609 (comment)

Co-Authored-By: OpenAI Codex <codex@openai.com>
@dahlia dahlia requested a review from Copilot March 8, 2026 13:02
@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Mar 8, 2026

/gemini review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread packages/cli/src/lookup.ts Outdated
Comment thread docs/cli.md Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a --reverse option to the fedify lookup command, allowing users to reverse the output order for various lookup modes. However, it introduces a potential memory exhaustion vulnerability when used with the --traverse option, as the tool buffers the entire collection in memory, which can lead to crashes with large ActivityPub collections.

Comment thread packages/cli/src/lookup.ts
Comment thread packages/cli/src/lookup.ts
Avoid an unnecessary array clone in toPresentationOrder() for non-reverse paths when input is already an array, and tighten the --reverse docs wording for clarity.
@dahlia dahlia requested a review from Copilot March 8, 2026 13:16
@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Mar 8, 2026

/gemini review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread packages/cli/src/lookup.ts Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a --reverse option to the fedify lookup command, allowing users to reverse the output order of results. The changes are well-implemented across the default, traverse, and recurse modes, with thoughtful consideration for failure semantics to preserve partial results. The documentation and tests have been updated accordingly, making this a solid feature addition. I have one minor suggestion to improve the consistency of a helper function.

Comment thread packages/cli/src/lookup.ts Outdated
@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Mar 8, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a --reverse option to the fedify lookup command, enabling users to reverse the output order of results. The implementation correctly handles this for default, traverse, and recurse modes, preserving streaming for non-reversed cases while buffering for reversed ones. The changes are well-documented and thoroughly tested.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread packages/cli/src/lookup.ts
Comment thread packages/cli/src/lookup.ts
Add runLookup integration tests for reverse-mode failure paths: traverse+reverse now verifies reversed partial item emission with non-zero exit, and recurse+reverse verifies root object emission on recursive failure.
@dahlia dahlia requested a review from Copilot March 8, 2026 13:46
@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Mar 8, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a --reverse option to the fedify lookup command, allowing users to reverse the output order of results. The implementation correctly handles this for default multi-URL lookups, recursive lookups, and collection traversals. The changes also include updates to documentation, configuration, and comprehensive tests for the new functionality.

I've found one issue in the implementation for collection traversal (--traverse) where the logic for printing separators between items has a regression. This affects both normal and reversed traversal modes. My review includes a detailed comment and a code suggestion to fix this, aligning with the rule on managing state for independent processing chains.

Comment thread packages/cli/src/lookup.ts
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Add runLookup regression coverage to verify separators are emitted between
adjacent traversed items in both normal and reverse traversal modes.
This locks in the current behavior and prevents false-positive regressions
around same-collection item boundaries.

fedify-dev#609 (comment)

Co-Authored-By: Codex <codex@openai.com>
@dahlia dahlia requested a review from Copilot March 8, 2026 13:56
@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Mar 8, 2026

/gemini review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread packages/cli/src/lookup.ts Outdated
Comment thread packages/cli/src/lookup.ts Outdated
Comment thread packages/cli/src/lookup.test.ts Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a --reverse option to the fedify lookup command, allowing users to reverse the output order of results. The implementation correctly handles this new option across default, traverse, and recurse modes, including failure scenarios. The changes are well-tested and include necessary documentation updates. I have one suggestion to improve the readability of the recursive lookup logic.

Avoid extra array cloning in reverse output paths by iterating buffered
entries in reverse order for recurse and traverse modes.

Also tighten test helper typing by replacing the direct command-object
type assertion with a `satisfies`-checked base command shape.

fedify-dev#609 (comment)
fedify-dev#609 (comment)
fedify-dev#609 (comment)

Co-Authored-By: Codex <codex@openai.com>
@dahlia dahlia requested a review from Copilot March 8, 2026 14:15
@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Mar 8, 2026

/gemini review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread packages/cli/src/lookup.test.ts Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a --reverse option to the fedify lookup command, allowing users to reverse the output order of results. The changes are well-implemented across default, traverse, and recurse modes, with thorough test coverage for the new functionality and its edge cases. The documentation has also been updated accordingly. I have one suggestion to improve the readability of the new logic in runLookup.

Comment thread packages/cli/src/lookup.ts
Keep runLookupAndCaptureExitCode() fully typed by accepting the exact
runLookup command parameter type, and move the conversion responsibility
into createLookupRunCommand().

fedify-dev#609 (comment)

Co-Authored-By: Codex <codex@openai.com>
@dahlia dahlia requested a review from Copilot March 8, 2026 14:27
@dahlia
Copy link
Copy Markdown
Member Author

dahlia commented Mar 8, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a --reverse option to the fedify lookup command, allowing users to reverse the output order of results. A security audit found no vulnerabilities meeting the severity threshold. The implementation is well-tested and documented.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@dahlia dahlia merged commit 1172d43 into fedify-dev:main Mar 8, 2026
33 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/cli CLI tools related component/collections Collections related component/federation Federation object related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add --reverse to fedify lookup to reverse output order in traversal/recurse modes

2 participants