Skip to content
16 changes: 16 additions & 0 deletions docs/design/2026-08-13-review-platform-provider-abstraction.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,22 @@ Enterprise paragraph.
documented for the user. Still open: dedup/self-PR backing for Aone,
`composeUrl`, cleanup audit, AI-comment marking (Q4), the
render-adjudication carve-out.
- **Self-PR backing (2026-08-21, #9616):** `presubmit` became
platform-aware. On an Aone target it runs the backed slice —
self-PR detection (`a1 auth whoami`'s `account` vs the `mr view`
author, one fetch, case-insensitive, fail-soft on a missing author,
fail-closed on a thrown `mr view`) and head drift (`sourceBranch` IS
the head under AGit-Flow; no compare API exists, so `compare` is
null and a drifted head is always anchors-at-risk) — and reports the
unbacked slice neutral (`no_checks` with zero checks, zero existing
comments: no downgrades from them, no overlap blocks). Same report
shape as GitHub, so Step 7's apply-the-report rules and
compose-review's downgrade fields are unchanged; the verdict cap
stays forced in `submit` (pr-context is still unbacked). SKILL.md's
Aone list names presubmit as reduced-backing instead of skipped, and
the "no self-PR detection" caveat is gone from both docs. Still
open: dedup backing for Aone, `composeUrl`, cleanup audit,
AI-comment marking (Q4), the render-adjudication carve-out.
- **Phase 4 — semantic gaps.** Incremental-cache ancestry fallback, build-test
repo-config escape hatch, publish-assets gating polish, generic-GitLab
(glab) evaluation.
Expand Down
2 changes: 1 addition & 1 deletion docs/users/features/code-review.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ The deterministic halves of the pipeline — argument parsing (`qwen review pars

**GitHub Enterprise:** reviewing a PR URL on a non-`github.com` host routes every GitHub call at that host — the review subcommands (`match-remote`, `meta`, `fetch-pr`, `pr-context`, `comment-status`, `issue-context`, `fetch-diff`, `comment-body`, `plan-diff`, `test-plan`, `presubmit`, `compose-review`, `submit`, `publish-assets`) accept `--host` and set it in code, so a forgotten host cannot silently retarget the review at `github.com`.

**Aone Code:** for a clone whose origin is on `gitlab.alibaba-inc.com`, run `/review` from inside that clone — the platform is detected from the remote and the subcommands work, backed by the `a1` CLI — the target number is the global MR id. `fetch-pr` fetches `refs/merge-requests/<id>/head` and builds the worktree + diff, so the agent review of the worktree is unchanged. Every Aone run is context-unavailable and several flows are skipped (rather than hitting github.com's same-named repo): `pr-context`/`comment-status`/`presubmit` have no Aone backing (verdict caps at `COMMENT`), `test-plan` is unbacked, Agent 0 is skipped, and the `publish-assets` write is skipped. `--comment` **posts** the review through the `a1` CLI: one comment per inline finding, then the summary comment. Aone has no native request-changes state — on that verdict the summary comment carries a blocking header, and any inline Criticals that were actually posted block the merge through the discussion gate while their discussions stay unresolved (when no inline Critical posted, the header is advisory and nothing mechanically blocks the merge). The native `a1 repo mr approve` is wired for an Approve verdict but does not fire this phase: the context-unavailable cap keeps every Aone verdict at Comment. Two caveats for repeat rounds: there is no dedup backing yet, so a second `--comment` round re-posts every still-valid finding as a new comment, and self-PR detection has no Aone backing. See `docs/design/2026-08-15-review-aone-provider.md`.
**Aone Code:** for a clone whose origin is on `gitlab.alibaba-inc.com`, run `/review` from inside that clone — the platform is detected from the remote and the subcommands work, backed by the `a1` CLI — the target number is the global MR id. `fetch-pr` fetches `refs/merge-requests/<id>/head` and builds the worktree + diff, so the agent review of the worktree is unchanged. Every Aone run is context-unavailable and several flows are skipped (rather than hitting github.com's same-named repo): `pr-context`/`comment-status` have no Aone backing (verdict caps at `COMMENT`), `presubmit` is backed only for self-PR detection (the `a1 auth whoami` account vs the MR author) and head drift — its CI and existing-comment checks come back neutral — `test-plan` is unbacked, Agent 0 is skipped, and the `publish-assets` write is skipped. `--comment` **posts** the review through the `a1` CLI: one comment per inline finding, then the summary comment. Aone has no native request-changes state — on that verdict the summary comment carries a blocking header, and any inline Criticals that were actually posted block the merge through the discussion gate while their discussions stay unresolved (when no inline Critical posted, the header is advisory and nothing mechanically blocks the merge). The native `a1 repo mr approve` is wired for an Approve verdict but does not fire this phase: the context-unavailable cap keeps every Aone verdict at Comment. One caveat for repeat rounds: there is no dedup backing yet, so a second `--comment` round re-posts every still-valid finding as a new comment (self-PR detection IS backed: reviewing your own MR gets the same verdict downgrade as on GitHub). See `docs/design/2026-08-15-review-aone-provider.md`.

Every run ends with one machine-readable line (`Review complete: <target> — <disposition>`), so scripts and CI wrappers can detect completion and outcome with a single `^Review complete: ` match.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ vi.mock('node:child_process', () => ({
execFileSync: mockExecFileSync,
}));

import { a1, a1JsonOnce, a1Once } from './aone-client.js';
import { a1, a1JsonOnce, a1Once, aoneCurrentUser } from './aone-client.js';

function transientError(): Error {
// The message shape execFileSync produces, carrying a transient marker
Expand Down Expand Up @@ -170,3 +170,37 @@ describe('a1 (the read path) transient-error retry — the POSITIVE side', () =>
expect(mockExecFileSync).toHaveBeenCalledTimes(3); // 1 initial + 2 retries
});
});

describe('aoneCurrentUser — the whoami sibling of gh.ts currentUser', () => {
beforeEach(() => {
vi.clearAllMocks();
});

it('returns the account field of `a1 auth whoami --format json`', () => {
mockExecFileSync.mockReturnValue('{"account":"wenshao"}\n');
expect(aoneCurrentUser()).toBe('wenshao');
// Pin the FULL argv: the self-PR comparison presubmit runs reads this
// account, and a botched spread here would exec a different whoami
// shape without any other test noticing (aone.test.ts mocks the module
// wholesale).
const args = mockExecFileSync.mock.calls[0][1] as string[];
expect(args).toEqual(['auth', 'whoami', '--format', 'json']);
});

it('returns empty (fail-soft) when whoami names no account', () => {
// An empty login makes presubmit's self-PR comparison fail soft —
// isSelfPr false — exactly like the GitHub path's empty login; a throw
// here would kill the whole presubmit over a shape quirk.
mockExecFileSync.mockReturnValue('{}\n');
expect(aoneCurrentUser()).toBe('');
mockExecFileSync.mockReturnValue('{"account":42}\n');
expect(aoneCurrentUser()).toBe('');
});

it('trims the account — parity with gh.ts currentUser().trim()', () => {
// A padded account would silently miss the self-PR comparison against a
// clean MR author (fail-open on exactly the protection this exists for).
mockExecFileSync.mockReturnValue('{"account":" wenshao\\n"}\n');
expect(aoneCurrentUser()).toBe('wenshao');
});
});
12 changes: 12 additions & 0 deletions packages/cli/src/commands/review/lib/platform/aone-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ export function a1JsonOnce<T>(...args: string[]): T | undefined {
}
}

/**
* Login of the currently authenticated Aone account — the sibling of
* gh.ts's `currentUser`. Reads the `account` field of
* `a1 auth whoami --format json`; empty when whoami succeeds but names no
* account (presubmit's self-PR comparison then fails soft, like the GitHub
* path's empty login).
*/
export function aoneCurrentUser(): string {
const out = a1Json<{ account?: unknown }>('auth', 'whoami');
return typeof out.account === 'string' ? out.account.trim() : '';
}

/**
* Fail fast with an actionable message when `a1` cannot run. A missing
* binary (ENOENT — the dominant first-run state for this new dependency) is
Expand Down
90 changes: 90 additions & 0 deletions packages/cli/src/commands/review/lib/platform/aone.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ vi.mock('../git.js', () => ({
import {
AonePartialPostError,
aoneReader,
mrPresubmitFacts,
parseRemoteUrl,
submitAoneReview,
} from './aone.js';
Expand Down Expand Up @@ -455,6 +456,95 @@ describe('aoneReader.getFetchMeta / fetchHeadRefSpec', () => {
});
});

describe("mrPresubmitFacts (the presubmit gate's Aone seam)", () => {
beforeEach(() => {
vi.clearAllMocks();
});

it('reads the author account and the live head from ONE mr view fetch', () => {
a1JsonMock.mockReturnValue({
mergeRequest: {
sourceBranch: 'sha123',
author: { username: 'wenshao' },
},
});
expect(mrPresubmitFacts(29295886, 'maxcompute/odps_src')).toEqual({
author: 'wenshao',
headSha: 'sha123',
});
expect(a1JsonMock).toHaveBeenCalledTimes(1);
expect(a1JsonMock).toHaveBeenCalledWith(
'repo',
'mr',
'view',
'29295886',
'--repo',
'maxcompute/odps_src',
);
});

it('fails soft (empty author) when the author was deleted or is absent', () => {
// The GitHub path's `author: null` parity: a readable MR with no author
// must yield isSelfPr false, not a throw that kills the presubmit.
a1JsonMock.mockReturnValue({
mergeRequest: { sourceBranch: 'sha123' },
});
expect(mrPresubmitFacts(7, 'g/p')).toEqual({
author: '',
headSha: 'sha123',
});
a1JsonMock.mockReturnValue({
mergeRequest: { sourceBranch: 'sha123', author: {} },
});
expect(mrPresubmitFacts(7, 'g/p').author).toBe('');
});

it('type-guards a non-string username instead of letting it crash presubmit', () => {
// `username` is server-controlled; a non-string surviving `?? ''` would
// reach `.toLowerCase()` outside presubmit's fetch try/catch and die
// with no report. Parity with aoneCurrentUser's `typeof === 'string'`.
a1JsonMock.mockReturnValue({
mergeRequest: { sourceBranch: 'sha123', author: { username: 42 } },
});
expect(mrPresubmitFacts(7, 'g/p').author).toBe('');
a1JsonMock.mockReturnValue({
mergeRequest: { sourceBranch: 'sha123', author: { username: null } },
});
expect(mrPresubmitFacts(7, 'g/p').author).toBe('');
});

it('trims a padded sourceBranch and username, tolerating their absence', () => {
// A padded head must not manufacture drift against a clean commit sha,
// and a padded username must not miss the self-PR comparison against a
// clean whoami account (fail-open on exactly the protection this exists
// for). Absent values report '' — drift stays off, isSelfPr false.
a1JsonMock.mockReturnValue({
mergeRequest: {
sourceBranch: ' sha123\n',
author: { username: ' wenshao\n' },
},
});
expect(mrPresubmitFacts(7, 'g/p')).toEqual({
author: 'wenshao',
headSha: 'sha123',
});
a1JsonMock.mockReturnValue({ mergeRequest: { author: {} } });
expect(mrPresubmitFacts(7, 'g/p').headSha).toBe('');
});

it('rejects a malformed owner/repo before any a1 call', () => {
expect(() => mrPresubmitFacts(7, 'bogus')).toThrow(TypeError);
expect(a1JsonMock).not.toHaveBeenCalled();
});

it('propagates a missing mergeRequest as a throw (fail-closed upstream)', () => {
// presubmit catches this as metaUnavailable and caps the verdict; the
// seam itself must not paper over it with empty facts.
a1JsonMock.mockReturnValue({});
expect(() => mrPresubmitFacts(7, 'g/p')).toThrow(/no mergeRequest for #7/);
});
});

describe('aoneReader.fetchDiff', () => {
beforeEach(() => {
vi.clearAllMocks();
Expand Down
26 changes: 26 additions & 0 deletions packages/cli/src/commands/review/lib/platform/aone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,32 @@ function mrHeadRefSpec(prNumber: number): string {
return `refs/merge-requests/${prNumber}/head`;
}

/**
* The two MR facts presubmit's gate compares, from ONE `mr view` fetch:
* the author's account name (self-PR detection — compared against
* `aoneCurrentUser`'s whoami account) and the live head SHA (the drift
* check — under AGit-Flow `sourceBranch` IS the head). A missing author
* (deleted account) reports '', which fails the comparison soft, like the
* GitHub path's `author: null`. `username` is server-controlled, so it is
* type-guarded to a string and trimmed exactly like `aoneCurrentUser`'s
* `account` — a non-string reaching `.toLowerCase()` would crash the
* command outside presubmit's fetch try/catch instead of failing soft.
*/
export function mrPresubmitFacts(
prNumber: number,
ownerRepo: string,
): { author: string; headSha: string } {
checkOwnerRepo(ownerRepo);
const view = mrView(prNumber, ownerRepo);
return {
author:
typeof view.author?.username === 'string'
? view.author.username.trim()
: '',
headSha: (view.sourceBranch ?? '').trim(),
};
}

/**
* Allowlist shape for a server-controlled branch name reaching git's argv:
* a plain branch name and nothing else — no option spellings, no refspec
Expand Down
Loading
Loading