Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions packages/cli/src/commands/review/run-skill-parity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ const repoRoot = resolve(
'..',
);

const SKILL_PATH = join(
repoRoot,
'packages/core/src/skills/bundled/review/SKILL.md',
);
const SKILL_DIR = join(repoRoot, 'packages/core/src/skills/bundled/review');

/** The `{target}` token, rendered per class exactly as the skill defines it. */
const TARGETS = {
Expand All @@ -46,14 +43,28 @@ const TARGETS = {
};

describe('run pins match the bundled skill templates', () => {
const skill = existsSync(SKILL_PATH)
? readFileSync(SKILL_PATH, 'utf8').replace(/\r\n/g, '\n')
// The skill is a corpus since #9787, and each oracle reads only the
// files the owning step is GUARANTEED to see: the composed-name template
// lives in the core SKILL.md (injected on every run), the report stems in
// references/persistence.md (the one reference loaded before Step 8 on
// every run that has a Step 8). Accepting a template from ANY corpus file
// would stay green on a move into a verdict-gated file that many runs
// never load, while those runs improvise artifact names.
const coreSkill = existsSync(join(SKILL_DIR, 'SKILL.md'))
? readFileSync(join(SKILL_DIR, 'SKILL.md'), 'utf8').replace(/\r\n/g, '\n')
: null;
const step8Corpus = (() => {
if (coreSkill === null) return null;
const persistence = join(SKILL_DIR, 'references', 'persistence.md');
return existsSync(persistence)
? `${coreSkill}\n${readFileSync(persistence, 'utf8').replace(/\r\n/g, '\n')}`
: coreSkill;
})();

// A sparse or partial checkout has no skill to read; the pins are still
// covered by run.test.ts's own cases. Failing here would report a checkout
// shape as a contract drift.
const itWithSkill = skill === null ? it.skip : it;
const itWithSkill = coreSkill === null ? it.skip : it;

itWithSkill('composedNameFor renders Step 6’s --out template', () => {
// The template as the skill writes it, e.g.
Expand All @@ -66,7 +77,7 @@ describe('run pins match the bundled skill templates', () => {
// class, so no future suffix character has to be foreseen.
const m =
/--out\s+\.qwen\/tmp\/(qwen-review-\{target\}-composed\.json)(?=\s|$)/.exec(
skill as string,
coreSkill as string,
);
// A null here means SKILL.md no longer writes that `--out` line: update
// composedNameFor and this oracle together to the new template.
Expand All @@ -82,7 +93,7 @@ describe('run pins match the bundled skill templates', () => {
// The stems as the skill lists them, e.g.
// `.qwen/reviews/<YYYY-MM-DD>-<HHMMSS>-pr-<number>.md`
const stems = [
...(skill as string).matchAll(
...(step8Corpus as string).matchAll(
/`\.qwen\/reviews\/<YYYY-MM-DD>-<HHMMSS>-([^`]+)\.md`/g,
),
].map((s) => s[1]);
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/skills/bundled-skills.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,15 @@ describe('bundled SKILL.md files', () => {
fs.existsSync(path.join(datavizDir, 'references', 'anti-patterns.md')),
).toBe(true);
});

it('ships the review verdict-gated reference files with the bundled skill', () => {
const reviewDir = path.join(bundledDir, 'review');

expect(fs.existsSync(path.join(reviewDir, 'SKILL.md'))).toBe(true);
for (const name of ['posting.md', 'persistence.md', 'aone.md']) {
expect(fs.existsSync(path.join(reviewDir, 'references', name))).toBe(
true,
);
}
});
});
416 changes: 31 additions & 385 deletions packages/core/src/skills/bundled/review/SKILL.md

Large diffs are not rendered by default.

128 changes: 127 additions & 1 deletion packages/core/src/skills/bundled/review/SKILL.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,24 @@ const skillDir = path.dirname(fileURLToPath(import.meta.url));
const POINTER_RE = /\(measured; DESIGN\.md — ([^()\n]+(?:\([^()\n]*\))?)\)/g;
const POINTER_OPEN = '(measured; DESIGN.md — ';

function skillBody(): string {
// The verdict-gated reference files (#9787): Step 7, Step 8 and the Aone
// paths live beside the core body and are read on demand. The split moved
// whole sections verbatim, so every revert guard below governs the full
// corpus, whichever file the guarded text now lives in.
const REFERENCE_FILES = ['posting.md', 'persistence.md', 'aone.md'];

function coreBody(): string {
return fs.readFileSync(path.join(skillDir, 'SKILL.md'), 'utf8');
}

function referenceBody(name: string): string {
return fs.readFileSync(path.join(skillDir, 'references', name), 'utf8');
}

function skillBody(): string {
return [coreBody(), ...REFERENCE_FILES.map(referenceBody)].join('\n');
}

function incidentPointers(body: string): string[] {
return [...body.matchAll(POINTER_RE)].map(([, title]) => title.trim());
}
Expand Down Expand Up @@ -845,6 +859,17 @@ describe('bundled review skill', () => {
expect(body).not.toContain(
'`pr-context` and `comment-status` have no Aone backing',
);
// The last three skip residues this change removes — the setup-batch
// parenthetical, the comment-status guard clause, and the Step 6
// no-report clause. The positive assertions above stay green if a
// merge resolution or partial revert re-adds any of them, while Aone
// runs skip comment-status again; the replacement contract is the
// a1-backed report's existence in Step 6's re-check.
expect(body).not.toContain('drops out of the batch');
expect(body).not.toContain('leaving a two-call batch');
expect(body).not.toContain('the command has no backing');
expect(body).not.toContain('skips the command with the Step 1 batch');
expect(body).toContain('on an Aone target it runs a1-backed');
});

it('keeps the corrected Aone --comment contract, not merge residue', () => {
Expand Down Expand Up @@ -951,4 +976,105 @@ describe('bundled review skill', () => {
);
expect(new Set(advertised)).toEqual(new Set(declared));
});

it('ships the verdict-gated reference files beside the core body', () => {
// The split (#9787) moves whole steps, not rules: the core keeps the
// gates and the invariants that bind runs which never load a file, and
// each reference owns one conditional territory.
for (const name of REFERENCE_FILES) {
expect(referenceBody(name).length).toBeGreaterThan(1000);
}
expect(referenceBody('posting.md')).toContain('# Step 7: Submit PR review');
expect(referenceBody('persistence.md')).toContain(
'# Step 8: Save review report and cache',
);
expect(referenceBody('aone.md')).toContain('# Aone Code paths');
});

it('gates every reference file on the verdict in the core body', () => {
// A run must learn from the injected core alone WHICH file to read and
// when; a gate that moved into the file it gates would be unreadable.
const core = coreBody();
expect(core).toContain('**Reference files, gated by this verdict.**');
expect(core).toContain('`references/posting.md` — Step 7');
expect(core).toContain('`references/persistence.md` — Step 8');
expect(core).toContain('`references/aone.md` — the Aone paths');
// The enumeration prefixes alone do not pin WHEN a file loads:
// rewriting a load-condition clause with its prefix intact ships
// green. Pin the clauses themselves — the gating is the mechanism
// this split introduces.
expect(core).toContain('Load it when, and only when, posting is live');
expect(core).toContain(
'Load it before Step 8 on every run except cross-repo lightweight mode',
);
expect(core).toContain(
'Load it before `match-remote` when the target is Aone',
);
});

it('keeps the write prohibition and the posting gates in the core body', () => {
// The one-sentence write ban and the PR-only/high-only posting rule must
// bind a run that never loads posting.md — the bypass they guard against
// does not wait for the gate file.
const core = coreBody();
expect(core).toContain(
'`qwen review submit` is the only write path in this skill',
);
expect(core).toContain('Posting is a PR-only, high-only action');
// The step headings stay in core so every "Step 7" / "Step 8" cross-
// reference in the corpus resolves to the pointer that forwards.
expect(core).toContain('## Step 7: Submit PR review');
expect(core).toContain('## Step 8: Save review report and cache');
// The compose-state field list relocated to Step 6 references the
// never-in-body rule whose full text moved to posting.md; the entry must
// restate the rule's substance so a report-only run (which never loads
// posting.md) still sees why a Suggestion must not ride the review body.
expect(core).toContain('does not filter review bodies');
});

it('moved the sections whole — no step body duplicated across files', () => {
const core = coreBody();
const corpus = skillBody();
// Distinctive openings of the moved sections: present in exactly one
// file of the corpus, and absent from the core. The corpus-wide count
// alone would pass a revert that keeps a section in the core, and the
// absence-from-core alone passes a copy duplicated BETWEEN the
// reference files — an Aone --comment run loads both posting.md and
// aone.md, so one run would then obey two potentially divergent
// copies of the same step.
expect(corpus.match(/\*\*Use the "Create Review" API/g)).toHaveLength(1);
expect(corpus.match(/### Report persistence/g)).toHaveLength(1);
expect(
corpus.match(/run `\/review` \*\*from inside a clone of that repo\*\*/g),
).toHaveLength(1);
expect(core).not.toContain(
'**Use the "Create Review" API to submit verdict + inline comments',
);
expect(core).not.toContain('### Report persistence');
expect(core).not.toContain(
'run `/review` **from inside a clone of that repo**',
);
// The compose-state field list relocated from Step 7 to Step 6's Verdict
// section: one copy in the corpus, in the core.
expect(corpus.match(/- `modelId` — for the footer\./g)).toHaveLength(1);
expect(core).toContain('- `modelId` — for the footer.');
});

it('keeps template tokens out of the raw-loaded reference files', () => {
// BundledSkillLoader interpolates only the core body it injects; the
// reference files are read raw via read_file, so a token there reaches
// the run unreplaced: a literal `(v{{cliVersion}})` draft footer is
// one stripReviewFooter cannot match (the version span excludes
// braces), so every posted comment carries the broken token above the
// canonical footer, and a `{{model}}` copied into the cache JSON
// fails the next round's same-model anchor gate.
for (const name of REFERENCE_FILES) {
expect(referenceBody(name)).not.toMatch(/\{\{[^}]+\}\}/);
}
// The reference files' footer templates name YOUR_MODEL_ID, whose
// value the loader prepends to the injected core body — but only when
// the core body carries a model token; without one the declaration
// vanishes and the templates dangle.
expect(/{{model}}|YOUR_MODEL_ID/.test(coreBody())).toBe(true);
});
});
18 changes: 18 additions & 0 deletions packages/core/src/skills/bundled/review/references/aone.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Aone Code paths

_Reference file of the `review` skill, loaded on demand — the core body is
already in your context. Read this file BEFORE `match-remote` or `fetch-pr`
when the target is an Aone Code review: a `…/codereview/<id>` URL, a
`pr-url` whose verdict `host` is `code.alibaba-inc.com` or
`gitlab.alibaba-inc.com`, or a bare PR number where `review meta` reports
`platform: "aone"`. GitHub runs never read it._

**`match-remote` on an Aone nested-group target** (`…/<group>/<subgroup…>/<project>/codereview/<id>`): also pass `--group-path <group>/<subgroup…>/<project>` (the URL's full path before `/codereview/`) — owner/repo collapse to the last two segments, and without the full path the matcher could pick a different group's same-named repo.

For an **Aone Code** target, run `/review` **from inside a clone of that repo** (origin on `gitlab.alibaba-inc.com`). The platform is detected from the clone's remote — the read subcommands (`meta`, `fetch-pr`, `issue-context`, `fetch-diff`, `pr-context`, `comment-body` — the fetch the truncation notes pr-context emits name — `test-plan`, which reads the MR description through the same reader, `comment-status`, `presubmit`) work unchanged, backed by the `a1` CLI instead of `gh`, and `--comment` posts through the a1-backed `submit`. (`comment-status` and `presubmit` ARE a1-backed — presubmit fully: self-PR detection, head drift, merge-gate CI, and existing-comment dedup.) The provider refuses an `a1` older than `0.1.90` at authentication time with an upgrade message — that floor is the version the a1-backed flows were probed against. The target number is the global MR id. `fetch-pr` fetches `refs/merge-requests/<id>/head` and builds the worktree + diff as usual, so agents still review the worktree. A `…/codereview/<id>` URL pasted from OUTSIDE a clone of that repo cannot be resolved — the URL's host does pin detection (passed as `--host`), but there is then no clone to fetch the MR ref into and build the worktree/diff from — stop and tell the user to run inside the clone. Pass `--host gitlab.alibaba-inc.com` on the subcommands for Aone targets: it is harmless for the a1-backed commands and makes detection fire regardless of cwd. Aone is one platform under TWO host names — the CR URL carries the web host (`code.alibaba-inc.com`), the clone's remote the git host (`gitlab.alibaba-inc.com`) — and `submit` treats them as one, so passing either to `--host` authorises the post; do not hand-"correct" one into the other.

`pr-context` is Aone-backed — it runs like GitHub (same failure handling: warn, continue, **context-unavailable** state on failure) and reads the MR's metadata, discussion threads, and posted qwen summaries (the machine ledger recovers from them the same way GitHub's does from review bodies). Aone reports no diff stats, so the context file's Diff line degrades — that is expected, not an error. A few flows still must be skipped rather than allowed to hit github.com's same-named repo:

- Agent 0 (issue fidelity) is gated on `pr-context` success; with `pr-context` now Aone-backed it runs as on GitHub. (`issue-context` works standalone for the workitem evidence, but it is not wired to Agent 0.)
- Step 9's bypass audit is platform-aware: on an Aone target it lists the MR's comments through the `a1` CLI and flags any comment the authenticated account posted — or edited — inside the window that `submit`'s receipt does not vouch for. It never queries GitHub for an Aone report.
- `--comment` posts through `qwen review submit` exactly as on GitHub — it routes the write at the `a1` CLI itself (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 block the merge while their discussions stay unresolved — but they carry NO AI-comment flag (`a1` cannot set one), so the platform's dedicated `ai_comment` merge gate does not track them and the discussion gate is the only mechanical block. Relay the `Note:` line `submit` prints about this (it names whether inline Criticals actually posted — and, when they did, which gate they join). The native `a1 repo mr approve` fires for an APPROVE verdict exactly when the run read the MR's context (the same gate as GitHub; a context-unavailable run stays capped at COMMENT). Five failure/refusal shapes are Aone-specific: a **head-drift** refusal (the MR was amended between review and post — re-review the new head, do not re-submit the stale payload, but ONLY while the per-review head-movement restart bound is unspent; once spent, Aone has no submit-at-reviewed-SHA fallback (a1 comments carry no commit anchor), so report that the review cannot be posted against the moved head, leave the findings in the terminal output and the saved report, and leave further re-review/posting to the user); a **mid-batch failure** (stdout carries `"partial": true` with the landed counts/ids and an `ambiguous` flag — part of the review IS on the MR; never re-run `submit`; report what landed and what remains, and leave posting the remainder to the user; when `ambiguous` is true, the FAILED write itself may have reached the MR — a zero count is not proof nothing landed, so tell the user to inspect the MR before hand-posting anything); an **oversized-comment** refusal (a single comment or the summary exceeds a1's 131072-byte single-argument limit — the whole batch refuses before anything lands, there is nothing to re-run, and the user can post by hand); an **ordinary pre-write error** (auth expiry, a network blip — nothing landed, it surfaces as a normal command failure, and a re-run is safe); and the **anchor check** — Aone Code performs NO server-side anchor validation and cannot anchor the old side at all (a `--line` number that names a removed line posts silently on the same-numbered NEW-side line), so `submit` itself validates every inline anchor against the review's captured diff before anything posts: when that diff is not on disk it refuses the whole post (re-run the review so the diff is captured — nothing was written; a `--dry-run` preview is the exception — it writes nothing, so it skips the gate, discloses that anchors went unchecked, and reports `wouldPost: false` with `reason: 'aone-diff-missing'`), and any comment whose anchor it cannot vouch for degrades exactly like GitHub's 422 recovery — a Critical is relocated into the summary body, a Suggestion is discarded and counted — with each one named in the terminal (`Aone anchor check: …`); relay the disclosure. This is also the anchoring PROMISE for an Aone target: new-side only, and a finding on a removed line reaches the MR through the summary body or not at all — never on a wrong line. `submit` also discloses a head that moved DURING posting (`WARNING: the MR head MOVED during posting`) — relay it, and when the post-batch head re-read itself fails, `could not verify` is not `verified stable`: `submit` prints `WARNING: could not re-verify the MR head after posting` (a mid-batch failure prints the same warning naming the failed post) — relay that too. On a second-or-later Aone round, `presubmit`'s overlap dedup applies exactly as on GitHub — a finding already on the MR at the same `(path, line)` is dropped and logged, and only genuinely new findings post; self-PR detection works too (the MR author is matched against `a1 auth whoami`). Two Aone shape notes for that dedup: a1 comments carry no commit anchor, so every `comment-status` thread's code facts (`changedSinceComment`, `touchedBy`) read `unknown`, and a thread the platform marks `outdated` (its line no longer maps after an amend) buckets as stale — so a new finding at a rewritten line still posts — while a resolved (`closed`) thread buckets as `resolved`, exactly like a replied-to thread on GitHub. `publish-assets` stays skipped: the Contents-API write is not Aone-backed.
Loading
Loading