Skip to content

Deduplicate test and demo argument parsing and resolved-command setup #2297

Description

@codeforester

Goal

Extract the common test/demo option parsing and resolved project-context setup into narrowly named helpers in the existing project command helper boundary. Leave command-specific resolution, preflight and execution in each command.

Background

Repository-wide duplication review against f9c18f3294873cbbcda9acc7af7f1bc6b17eed45 (2026-09-17).

base_test_subcommand_main and base_demo_subcommand_main repeat the same option declarations, forwarding loop, project-selection checks, wrapper lookup, decoded route-field extraction and history-context setup. The token comparison is 88.8% similar across their roughly 150-line bodies. Existing shared execution helpers are already used, so the remaining duplication is above that layer.

Verified source locations:

Follow-up to closed #428 and #1097, which already extracted venv/argument-formatting and execution helpers. This issue targets the remaining parser/context orchestration. Open #1606 owns canonical command metadata and is related, but does not replace this runtime extraction.

This is a maintainability refactor. Similarity alone is not evidence of a production failure; any demonstrated differences are called out above.

Scope

Extract the common test/demo option parsing and resolved project-context setup into narrowly named helpers in the existing project command helper boundary. Leave command-specific resolution, preflight and execution in each command.

Acceptance Criteria

  • Both commands call the same parser for their common options and the same helper for common route fields.
  • Preserve explicit/positional/current project selection, duplicate-option handling, --workspace=..., separator arguments, usage errors and exit codes.
  • Preserve test dependency preflight after trust; preserve direct demo-script execution when no runner is declared.
  • Dry runs remain nonexecuting and all argv quoting remains intact.

Validation

Run test.bats, demo.bats, and project-command-helpers.bats; add a shared behavior matrix covering malformed options, paths/arguments with spaces and control characters, trust denial and uv/mise runners. The current three suites passed 41 tests during this audit.

Run focused checks first, then the repository-required broader checks for the actual implementation. Preserve public command contracts and review .ai-context/ impact in the PR.

Non-Goals

No generic command execution framework; no merge of build/run/test/demo into one handler; no change to manifest trust or runner semantics.

Project Fields

  • Status: Ready
  • Priority: P2
  • Area: CLI
  • Initiative: Contract Hardening
  • Size: M
  • Milestone: Unscheduled; no release commitment is implied by this audit.

Agent Assignment

Implementation-ready scoped follow-up, assigned to codeforester. Follow AGENTS.md and docs/github-workflow.md: start through basectl gh issue start, use the canonical issue worktree, characterize current behavior before extraction, and open an issue-linked PR. Keep each refactor independently reviewable.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or product improvement

Type

No type

Projects

  • Status
    Done

Relationships

None yet

Development

No branches or pull requests

Issue actions