Skip to content

Fix suggest() ignoring withDefault() on dependency sources#522

Merged
dahlia merged 6 commits intomainfrom
fix/issue-186
Mar 15, 2026
Merged

Fix suggest() ignoring withDefault() on dependency sources#522
dahlia merged 6 commits intomainfrom
fix/issue-186

Conversation

@dahlia
Copy link
Copy Markdown
Owner

@dahlia dahlia commented Mar 15, 2026

Summary

  • When a dependency source was wrapped with withDefault() and no explicit CLI value was provided, suggest() returned an empty array instead of suggesting values based on the default. parse() handled this correctly because its Phase 1 pre-completes dependency sources, but the suggestion path lacked equivalent logic.
  • Added completeDependencySourceDefaults() (sync) and completeDependencySourceDefaultsAsync() (async) to pre-complete dependency source parsers during suggestion, mirroring Phase 1 of parse-time dependency resolution.
  • The async version properly awaits complete() results, which return a Promise for async parsers with transformsDependencyValue (e.g., withDefault(map(...), default)).

Test plan

  • Added regression test: sync suggest() with withDefault() dependency source returns correct suggestions based on default value
  • Added test: explicit source value still works correctly
  • Added test: async parser with withDefault() dependency source
  • Added test: async parser with map() + withDefault() dependency source (exercises the transformsDependencyValue path)
  • All existing tests pass (mise check, mise test:deno)

Closes #186

dahlia and others added 2 commits March 15, 2026 21:11
When a dependency source was wrapped with withDefault() and no explicit
CLI value was provided, suggest() returned an empty array because the
default value was never registered in the dependency registry.

Added completeDependencySourceDefaults() to pre-complete dependency
source parsers during suggestion, mirroring Phase 1 of parse-time
dependency resolution.

#186

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Split completeDependencySourceDefaults into sync and async versions so
that suggestObjectAsync properly awaits complete() results.  Async
parsers with transformsDependencyValue (e.g., withDefault wrapping map)
return a Promise from complete(), which the sync version would silently
ignore.

Also added async test cases for dependency-aware completion.

#186

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Copy Markdown

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 addresses a critical bug in the suggest() functionality of the optique library, ensuring that command-line argument suggestions correctly account for default values specified via withDefault() on dependency sources. The change aligns the suggestion mechanism with the parsing logic, providing a more consistent and reliable user experience for CLI completion. This fix prevents scenarios where valid default-based suggestions were erroneously omitted.

Highlights

  • Bug Fix: suggest() with withDefault(): Resolved an issue where suggest() failed to provide suggestions based on default values when a dependency source was wrapped with withDefault() and no explicit CLI value was provided. Previously, it returned an empty array, unlike parse() which correctly pre-completed dependency sources.
  • New Dependency Pre-completion Logic: Introduced completeDependencySourceDefaults() (sync) and completeDependencySourceDefaultsAsync() (async) functions. These functions pre-complete dependency source parsers during suggestion, mirroring the Phase 1 dependency resolution logic found in parse().
  • Asynchronous withDefault() Handling: The asynchronous pre-completion function, completeDependencySourceDefaultsAsync(), now correctly awaits complete() results, which are Promises for async parsers that use transformsDependencyValue (e.g., withDefault(map(...), default)).
Changelog
Activity
  • Added regression test for sync suggest() with withDefault() dependency source to ensure correct suggestions based on default value.
  • Added test to confirm explicit source values still function correctly.
  • Added test for async parser with withDefault() dependency source.
  • Added test for async parser with map() and withDefault() dependency source, specifically exercising the transformsDependencyValue path.
  • Verified that all existing tests pass (mise check, mise test:deno).
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.

@dahlia dahlia requested a review from Copilot March 15, 2026 12:34
@dahlia
Copy link
Copy Markdown
Owner Author

dahlia commented Mar 15, 2026

@codex review

@dahlia dahlia self-assigned this Mar 15, 2026
@dahlia dahlia added the bug Something isn't working label Mar 15, 2026
@dahlia dahlia added this to the Optique 1.0 milestone Mar 15, 2026
Copy link
Copy Markdown

@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 effectively fixes a bug where suggest() was ignoring withDefault() on dependency sources by adding logic to pre-complete these sources, mirroring the behavior of parse(). The changes are well-reasoned and accompanied by a comprehensive set of regression tests for both synchronous and asynchronous scenarios. My review includes a few suggestions to improve maintainability by reducing code duplication in the implementation, as well as a minor clarification for a JSDoc comment.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 15, 2026

Codecov Report

❌ Patch coverage is 96.61017% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.18%. Comparing base (e3db1f1) to head (0b1ec10).
⚠️ Report is 7 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/core/src/constructs.ts 96.61% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #522   +/-   ##
=======================================
  Coverage   96.18%   96.18%           
=======================================
  Files          38       38           
  Lines       15679    15738   +59     
  Branches     4026     4038   +12     
=======================================
+ Hits        15081    15138   +57     
- Misses        591      593    +2     
  Partials        7        7           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

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

This PR fixes a bug where suggest() returned an empty array when a dependency source was wrapped with withDefault() and no explicit CLI value was provided, despite parse() handling this correctly. The fix adds pre-completion of dependency source defaults during the suggest path, mirroring Phase 1 of parse-time dependency resolution.

Changes:

  • Added completeDependencySourceDefaults() (sync) and completeDependencySourceDefaultsAsync() (async) helper functions that pre-complete unpopulated dependency sources wrapped in withDefault(), registering their default values in the dependency registry before child parsers are queried for suggestions.
  • Added registerCompletedDependency() helper to factor out the common dependency registration logic.
  • Added four regression tests covering sync/async suggest with withDefault() dependency sources.

Reviewed changes

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

File Description
packages/core/src/constructs.ts Added completeDependencySourceDefaults, completeDependencySourceDefaultsAsync, and registerCompletedDependency helpers; integrated them into suggestObjectSync and suggestObjectAsync.
packages/core/src/suggest.test.ts Added four tests: sync default, sync explicit, async with map(), and async without map() — covering the bug fix.
CHANGES.md Documented the fix with issue/PR references.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7be673b7c5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

dahlia and others added 4 commits March 15, 2026 21:45
The comment claimed the function handles Promise-wrapped results,
but it only receives already-resolved values; the async caller
awaits before passing the result.

#522 (comment)
#522 (comment)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Deduplicate the asyncChoice helper that was defined identically
in two test cases.

#522 (comment)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
registerCompletedDependency() now checks registry.has() before
calling registry.set(), so parsed dependency values from
collectDependencies() are never overwritten by withDefault()
fallbacks.

#522 (comment)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Deduplicate the shared iteration logic between
completeDependencySourceDefaults() and its async variant
into a single generator function.

#522 (comment)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dahlia dahlia requested a review from Copilot March 15, 2026 12:53
@dahlia
Copy link
Copy Markdown
Owner Author

dahlia commented Mar 15, 2026

@codex review

@dahlia
Copy link
Copy Markdown
Owner Author

dahlia commented Mar 15, 2026

/gemini review

Copy link
Copy Markdown

@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 effectively addresses a bug where suggest() failed to provide correct completions for dependency-aware parsers wrapped with withDefault(). The fix correctly mirrors the dependency resolution logic from the parse() function by introducing new helper functions to pre-complete dependency sources and populate their default values into the dependency registry before generating suggestions. The implementation is well-structured, with clear separation for synchronous and asynchronous paths, and is supported by a comprehensive set of regression tests that cover all relevant cases. The changes are clean, well-documented, and align with the existing architecture of the library.

Copy link
Copy Markdown

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

This PR fixes a bug where suggest() returned empty results when a dependency source was wrapped with withDefault() and no explicit CLI value was provided, despite parse() handling this correctly. The fix adds pre-completion of dependency source defaults during the suggestion phase, mirroring the Phase 1 logic already present in the parse-time path.

Changes:

  • Added completeDependencySourceDefaults() (sync) and completeDependencySourceDefaultsAsync() (async) helper functions, along with shared pendingDependencyDefaults() generator and registerCompletedDependency() utility, to pre-complete defaulted dependency sources during suggestion.
  • Integrated these helpers into suggestObjectSync and suggestObjectAsync to populate the dependency registry with default values before child parsers generate suggestions.
  • Added four regression tests covering sync/async scenarios with withDefault() dependency sources, including the map() + withDefault() path that exercises transformsDependencyValue.

Reviewed changes

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

File Description
packages/core/src/constructs.ts Added dependency source default pre-completion logic for suggest paths and integrated into object suggest functions
packages/core/src/suggest.test.ts Added regression tests for dependency-aware completion with withDefault()
CHANGES.md Documented the bug fix with issue/PR references

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@dahlia dahlia merged commit 29c3a50 into main Mar 15, 2026
12 checks passed
@dahlia dahlia deleted the fix/issue-186 branch March 15, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dependency-aware completion ignores withDefault() source values

2 participants