Skip to content

fix(source): exit 1 when a source command refuses - #2041

Merged
jeff-r2026 merged 1 commit into
Tencent:mainfrom
Kiko0301:fix/source-refusal-exit-code
Nov 26, 2026
Merged

jeff-r2026 merged 1 commit into
Tencent:mainfrom
Kiko0301:fix/source-refusal-exit-code

Conversation

@Kiko0301

Copy link
Copy Markdown
Contributor

Summary

teamai source add, teamai source remove, teamai source browse and teamai source add-http printed an error and returned with exit status 0 when they refused a change, so a script or CI job read the refusal as success. Every one of those refusals now goes through a local refuse() helper that also sets process.exitCode = 1, which is the behaviour teamRepoEditable in the same file already had for a detached clone (and what #1731 and #1741 did for roles/projects and remove).

Fixes #2040.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature causing existing behavior to change)
  • Documentation only
  • Refactor / internal cleanup

Test Plan

Failing test first: src/__tests__/source-refusal-exit-code.test.ts fails on main with expected undefined to be 1 in all five cases, and passes with the fix.

$ npx vitest run src/__tests__/source-refusal-exit-code.test.ts   # on main 11138d4
 FAIL  source-refusal-exit-code.test.ts > source commands exit 1 when they refuse > ...
 AssertionError: expected undefined to be 1
 Tests  5 failed (5)

$ npx vitest run src/__tests__/source-refusal-exit-code.test.ts   # on this branch
 Tests  5 passed (5)
$ npx tsc --noEmit                                                 # pass
$ npx tsc -p oxlint-plugin-teamai                                  # pass

The test covers a duplicate name, a duplicate repository, a missing source for remove, a missing source for browse, and an empty add-http endpoint. source.test.ts and dry-run-load-path.test.ts also run here; their Windows failures (\ vs / in manifest paths, and EBUSY on temp-dir cleanup) reproduce on unmodified main, and neither file is in windows-tests.ts.

npm run lint does not pass on this Windows checkout: it reports the 26 pre-existing teamai(family-facts) errors from the Windows path bug described in #1889 (fixed by the open #1967), before the docs step, and check-docs sees CRLF against LF fixtures (#1942). The changed files themselves are clean:

$ npx oxlint --type-aware --deny-warnings --report-unused-disable-directives \
    src/source.ts src/__tests__/source-refusal-exit-code.test.ts
# no warnings or errors

Real CLI

npm run verify:world refuses on Windows: A world needs a POSIX shell; Windows is not supported. Say so in the PR instead. The record below uses the built CLI (npm run build) in a temporary HOME and project whose team repo declares one source, with no real tool home or TEAMAI_* variable in the environment.

Built from main at 11138d4:

=== source remove missing ===
✖ Source "missing" not found. Run `teamai source list` to see configured sources.
exit=0
=== source browse missing ===
✖ Source "missing" not found. ...
exit=0
=== source add duplicate name ===
✖ Source "shared" already exists. Use a different name or remove it first.
exit=0
=== source add duplicate repo ===
✖ Source repo "https://example.test/shared.git" already configured (as "shared").
exit=0
=== source add-http empty endpoint ===
✖ Endpoint is required. Usage: teamai source add-http <endpoint> --token <key>
exit=0

Built from this branch at 64391e2:

=== source remove missing ===
✖ Source "missing" not found. ...
exit=1
=== source browse missing ===
✖ Source "missing" not found. ...
exit=1
=== source add duplicate name ===
✖ Source "shared" already exists. ...
exit=1
=== source add duplicate repo ===
✖ Source repo "https://example.test/shared.git" already configured (as "shared").
exit=1
=== source add-http empty endpoint ===
✖ Endpoint is required. ...
exit=1
  • npx tsc --noEmit passes
  • npm run lint passes — blocked on the two pre-existing Windows defects above; the changed files pass oxlint and CI runs the full lint.
  • The test files that cover what I changed pass (npx vitest run src/__tests__/source-refusal-exit-code.test.ts)
  • Added/updated tests for the change
  • Runtime change: a real-CLI run is pasted above; the verify world itself is unavailable on Windows, as the command says.

Related Issues

Fixes #2040. No other issue or open PR covered these exit codes (searched titles and bodies for source add/source remove/exit, and for the two error strings).

Notes for Reviewers

  • Only the log.error(...) refusals changed. source remove's two log.warn paths that keep state for manual review still exit 0; they are deliberate "kept, review this" outcomes rather than a failed command, and changing them would widen this PR.
  • source add with an unreachable repository leaves the source clone it made in ~/.teamai/sources/; this PR only reports the failure with exit 1, as before.
  • Hit every surface: these commands write the team clone and the local source manifest; there is no driver, tool, workflow or dashboard entry point. Scopes share the same code, and the refusals happen before any provider call. Verified on Windows 11; Linux/macOS are covered by CI.
  • No documentation describes CLI exit codes for these commands, so no docs change.

teamai source add, remove, browse and add-http printed an error and returned with exit status 0, so a script or CI job read the refusal as success. Route every refusal through a helper that also sets process.exitCode, as teamRepoEditable already does for a detached clone.

Refs Tencent#2040
@github-actions

Copy link
Copy Markdown

No findings in the specified diff.

The PR description documents failing-first regression tests and representative real-CLI runs showing exit status changing from 0 to 1. It also explains the Windows verify-world limitation and pre-existing lint failures; no missing-testing blocker applies.

Review was read-only. I did not run, build, or install anything from the PR.

@jeff-r2026 jeff-r2026 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verified on latest main (fdc845e + this PR) in the 2026-11-26 audit round: typecheck, build, lint, targeted unit tests and e2e all pass. Squash-merging.

@jeff-r2026
jeff-r2026 merged commit ec3a25c into Tencent:main Nov 26, 2026
3 checks passed
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.

[bug] teamai source add, remove, browse and add-http exit 0 when they refuse

2 participants