Skip to content

fix: preserve classic openspec version passthrough - #300

Open
googs1025 wants to merge 1 commit into
rpamis:masterfrom
googs1025:fix/issue-296-openspec-version
Open

fix: preserve classic openspec version passthrough#300
googs1025 wants to merge 1 commit into
rpamis:masterfrom
googs1025:fix/issue-296-openspec-version

Conversation

@googs1025

@googs1025 googs1025 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • route comet classic ... directly to the Classic facade before top-level Commander parsing
  • add regression coverage for comet classic openspec -- --version
  • bump package/changelog to 0.4.0-beta.18

Fixes #296.

Tests

  • npx vitest run test/app/classic-command.test.ts
  • npx prettier --check CHANGELOG.md app/cli/index.ts package.json test/app/classic-command.test.ts
  • pnpm build
  • manual: COMET_OPENSPEC=node node bin/comet.js classic openspec -- --version

Summary by Sourcery

Route classic CLI invocations directly to the Classic facade before global option parsing to preserve OpenSpec version passthrough behavior and bump the package version.

Bug Fixes:

  • Ensure comet classic openspec -- --version is handled by the Classic facade so the OpenSpec CLI version is reported instead of the main Comet version.

Enhancements:

  • Add a dedicated routing path for the classic command group in the top-level CLI entrypoint.

Build:

  • Bump package.json version to 0.4.0-beta.18.

Documentation:

  • Document the Classic OpenSpec version passthrough fix in the changelog for version 0.4.0-beta.18.

Tests:

  • Add a regression test verifying that comet classic openspec -- --version bypasses global version parsing and is handled by the Classic facade.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed comet classic openspec -- --version so it reports the OpenSpec CLI version instead of Comet’s version.
    • Ensured Classic command output and exit codes are handled correctly, including commands using argument separators.
  • Chores

    • Updated the release version to 0.4.0-beta.18.
    • Added changelog entries documenting the fix and verified the updated version across release metadata.

@sourcery-ai

sourcery-ai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Reviewer's Guide

Routes the classic command group directly to the Classic facade before Commander’s global CLI parsing, adds a regression test for the OpenSpec version passthrough behavior, and bumps the package version/changelog to 0.4.0-beta.18.

Sequence diagram for classic command routing in runCli

sequenceDiagram
    actor User
    participant NodeProcess as node
    participant CometCli as runCli
    participant ClassicFacade as runClassicGroupFacade
    participant Commander as program

    User->>NodeProcess: comet classic openspec -- --version
    NodeProcess->>CometCli: runCli()
    CometCli->>CometCli: [process.argv[2] === classic]
    CometCli->>ClassicFacade: runClassicGroupFacade(process.argv.slice(3))
    ClassicFacade-->>CometCli: exitCode
    CometCli->>NodeProcess: set process.exitCode
    CometCli-->>NodeProcess: return

    alt non-classic command
      CometCli->>Commander: program.parseAsync()
      Commander-->>CometCli: parse result
    end
Loading

File-Level Changes

Change Details Files
Route comet classic ... invocations directly through the Classic group facade before top-level CLI parsing so OpenSpec CLI flags are preserved.
  • Short-circuit runCli when the second argv token is classic, importing and delegating to runClassicGroupFacade with the remaining arguments.
  • Set process.exitCode from the Classic facade result and return early instead of calling the global Commander program parser.
app/cli/index.ts
Add regression coverage for preserving OpenSpec --version passthrough via the Classic facade.
  • Spy on process.stdout.write and runClassicCli to assert Classic CLI execution and output.
  • Set up process.argv for comet classic openspec -- --version, reset modules, import the CLI entry, and assert that the Classic facade receives the correct argv and exit code.
  • Restore process.argv and process.exitCode in a finally block to avoid test pollution.
test/app/classic-command.test.ts
Update version metadata and changelog for 0.4.0-beta.18 describing the Classic OpenSpec passthrough fix.
  • Document the fix in the changelog under the new 0.4.0-beta.18 section.
  • Bump the package version field from 0.4.0-beta.17 to 0.4.0-beta.18.
CHANGELOG.md
package.json

Assessment against linked issues

Issue Objective Addressed Explanation
#296 comet classic openspec -- --version should bypass the top-level Comet CLI --version option and be fully passed through to the Classic/OpenSpec adapter, returning the OpenSpec CLI version.
#296 Ensure that /comet-open’s OpenSpec compatibility check compares the OpenSpec CLI version (from comet classic openspec -- --version) rather than Comet’s own version, so the classic flow can proceed when OpenSpec ≥ 1.5.0.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 28f6ef6c-78ac-4cbf-a389-1325b5332c44

📥 Commits

Reviewing files that changed from the base of the PR and between fde8b95 and 20a386a.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • assets/manifest.json
  • test/app/cli-help.test.ts
  • test/repository/release-metadata.test.ts

📝 Walkthrough

Walkthrough

The CLI now dispatches top-level classic invocations to the Classic facade before Commander parses global options. Integration coverage verifies OpenSpec version passthrough and process-state restoration. Release metadata identifies version 0.4.0-beta.18.

Changes

Classic version passthrough

Layer / File(s) Summary
Early Classic dispatch and integration coverage
app/cli/index.ts, test/app/classic-command.test.ts
runCli detects classic arguments, routes them to runClassicGroupFacade before Commander parsing, and preserves the Classic exit code. The integration test verifies argument forwarding, output, exit code 0, and process-state restoration.
Release metadata and version expectations
package.json, assets/manifest.json, CHANGELOG.md, test/app/cli-help.test.ts, test/repository/release-metadata.test.ts
The package and manifest versions change to 0.4.0-beta.18. The changelog records the passthrough fix. Release tests expect the new version.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: benym

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: preserving Classic OpenSpec version passthrough.
Linked Issues check ✅ Passed The CLI routes Classic invocations before Commander parses --version, and regression coverage verifies the passthrough required by issue #296.
Out of Scope Changes check ✅ Passed The implementation, regression test, release metadata, and changelog directly support the version passthrough fix.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In runCli, the direct process.argv[2] === 'classic' check is a bit brittle; consider using a more explicit argument parsing or Commander hook so subcommand routing stays consistent if the CLI invocation pattern changes (e.g., prefixed global flags).
  • The new test spies on process.stdout.write but never restores the spy; adding explicit restoration (e.g., via stdout.mockRestore() or vi.restoreAllMocks() in an afterEach) would reduce potential side effects across tests.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `runCli`, the direct `process.argv[2] === 'classic'` check is a bit brittle; consider using a more explicit argument parsing or Commander hook so subcommand routing stays consistent if the CLI invocation pattern changes (e.g., prefixed global flags).
- The new test spies on `process.stdout.write` but never restores the spy; adding explicit restoration (e.g., via `stdout.mockRestore()` or `vi.restoreAllMocks()` in an `afterEach`) would reduce potential side effects across tests.

## Individual Comments

### Comment 1
<location path="test/app/classic-command.test.ts" line_range="107-127" />
<code_context>
     }
   });
+
+  it('routes Classic group argv before global version parsing', async () => {
+    const stdout = vi.spyOn(process.stdout, 'write').mockImplementation(() => true);
+    runClassicCli.mockResolvedValue({ exitCode: 0, stdout: 'openspec version\n' });
+    const originalArgv = process.argv;
+    const originalExitCode = process.exitCode;
+    process.argv = [process.execPath, 'comet', 'classic', 'openspec', '--', '--version'];
+    process.exitCode = undefined;
+    vi.resetModules();
+
+    try {
+      await import('../../app/cli/index.js');
+      await vi.waitFor(() => {
+        expect(runClassicCli).toHaveBeenCalledWith(['openspec', '--', '--version']);
+        expect(stdout).toHaveBeenCalledWith('openspec version\n');
+        expect(process.exitCode).toBe(0);
+      });
+    } finally {
+      process.argv = originalArgv;
+      process.exitCode = originalExitCode;
+    }
+  });
 });
</code_context>
<issue_to_address>
**suggestion (testing):** Restore the stdout spy after the test to avoid side effects on subsequent tests

This test mocks `process.stdout.write` but never restores it. Even if Vitest resets mocks between tests, we should explicitly restore `stdout` in the `finally` block alongside `process.argv` and `process.exitCode` to avoid unintended interactions with other tests that depend on the original `stdout.write` behavior.

```suggestion
  it('routes Classic group argv before global version parsing', async () => {
    const stdout = vi.spyOn(process.stdout, 'write').mockImplementation(() => true);
    runClassicCli.mockResolvedValue({ exitCode: 0, stdout: 'openspec version\n' });
    const originalArgv = process.argv;
    const originalExitCode = process.exitCode;
    process.argv = [process.execPath, 'comet', 'classic', 'openspec', '--', '--version'];
    process.exitCode = undefined;
    vi.resetModules();

    try {
      await import('../../app/cli/index.js');
      await vi.waitFor(() => {
        expect(runClassicCli).toHaveBeenCalledWith(['openspec', '--', '--version']);
        expect(stdout).toHaveBeenCalledWith('openspec version\n');
        expect(process.exitCode).toBe(0);
      });
    } finally {
      stdout.mockRestore();
      process.argv = originalArgv;
      process.exitCode = originalExitCode;
    }
  });
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +107 to +127
it('routes Classic group argv before global version parsing', async () => {
const stdout = vi.spyOn(process.stdout, 'write').mockImplementation(() => true);
runClassicCli.mockResolvedValue({ exitCode: 0, stdout: 'openspec version\n' });
const originalArgv = process.argv;
const originalExitCode = process.exitCode;
process.argv = [process.execPath, 'comet', 'classic', 'openspec', '--', '--version'];
process.exitCode = undefined;
vi.resetModules();

try {
await import('../../app/cli/index.js');
await vi.waitFor(() => {
expect(runClassicCli).toHaveBeenCalledWith(['openspec', '--', '--version']);
expect(stdout).toHaveBeenCalledWith('openspec version\n');
expect(process.exitCode).toBe(0);
});
} finally {
process.argv = originalArgv;
process.exitCode = originalExitCode;
}
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (testing): Restore the stdout spy after the test to avoid side effects on subsequent tests

This test mocks process.stdout.write but never restores it. Even if Vitest resets mocks between tests, we should explicitly restore stdout in the finally block alongside process.argv and process.exitCode to avoid unintended interactions with other tests that depend on the original stdout.write behavior.

Suggested change
it('routes Classic group argv before global version parsing', async () => {
const stdout = vi.spyOn(process.stdout, 'write').mockImplementation(() => true);
runClassicCli.mockResolvedValue({ exitCode: 0, stdout: 'openspec version\n' });
const originalArgv = process.argv;
const originalExitCode = process.exitCode;
process.argv = [process.execPath, 'comet', 'classic', 'openspec', '--', '--version'];
process.exitCode = undefined;
vi.resetModules();
try {
await import('../../app/cli/index.js');
await vi.waitFor(() => {
expect(runClassicCli).toHaveBeenCalledWith(['openspec', '--', '--version']);
expect(stdout).toHaveBeenCalledWith('openspec version\n');
expect(process.exitCode).toBe(0);
});
} finally {
process.argv = originalArgv;
process.exitCode = originalExitCode;
}
});
it('routes Classic group argv before global version parsing', async () => {
const stdout = vi.spyOn(process.stdout, 'write').mockImplementation(() => true);
runClassicCli.mockResolvedValue({ exitCode: 0, stdout: 'openspec version\n' });
const originalArgv = process.argv;
const originalExitCode = process.exitCode;
process.argv = [process.execPath, 'comet', 'classic', 'openspec', '--', '--version'];
process.exitCode = undefined;
vi.resetModules();
try {
await import('../../app/cli/index.js');
await vi.waitFor(() => {
expect(runClassicCli).toHaveBeenCalledWith(['openspec', '--', '--version']);
expect(stdout).toHaveBeenCalledWith('openspec version\n');
expect(process.exitCode).toBe(0);
});
} finally {
stdout.mockRestore();
process.argv = originalArgv;
process.exitCode = originalExitCode;
}
});

@googs1025
googs1025 force-pushed the fix/issue-296-openspec-version branch from dab1f6f to fde8b95 Compare August 11, 2026 05:32
@googs1025
googs1025 force-pushed the fix/issue-296-openspec-version branch from fde8b95 to 20a386a Compare August 11, 2026 05:39
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.

comet classic openspec -- --version 返回 Comet 自身版本,导致 /comet-open 的 OpenSpec 兼容性检查误判

1 participant