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.
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_mainandbase_demo_subcommand_mainrepeat 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:
cli/bash/commands/basectl/subcommands/test.sh:36-188cli/bash/commands/basectl/subcommands/demo.sh:36-184cli/bash/commands/basectl/subcommands/project_command_helpers.sh:1-109Follow-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
--workspace=..., separator arguments, usage errors and exit codes.Validation
Run
test.bats,demo.bats, andproject-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
Agent Assignment
Implementation-ready scoped follow-up, assigned to
codeforester. FollowAGENTS.mdanddocs/github-workflow.md: start throughbasectl gh issue start, use the canonical issue worktree, characterize current behavior before extraction, and open an issue-linked PR. Keep each refactor independently reviewable.