Skip to content
Closed
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4220c0b
feat(review): dispatch Step 3A's fan-out from a generated workflow sc…
qqqys Aug 11, 2026
c8065a5
feat(review): route Step 3A's fan-out through the workflow engine, be…
qqqys Aug 17, 2026
40263b4
fix(review): include workflow helper in command contract
qqqys Aug 17, 2026
e0429e1
fix(review): scope generated workflow cleanup
qqqys Aug 17, 2026
feb59f8
fix(review): harden generated workflow cleanup
qqqys Aug 17, 2026
7a498f1
fix(review): harden generated workflow writes
qqqys Aug 17, 2026
94d525b
Merge branch 'main' into feat/review-workflow-fanout
qqqys Aug 18, 2026
1a56ea9
Merge remote-tracking branch 'origin/main' into feat/review-workflow-…
qwen-code-ci-bot Aug 18, 2026
1d8f58b
fix(review): sweep emit-workflow temp orphans and pin routing verdict…
qwen-code-ci-bot Aug 18, 2026
90b7472
Merge remote-tracking branch 'origin/main' into feat/review-workflow-…
qwen-code-ci-bot Aug 19, 2026
1de088e
merge: bring upstream/main into feat/review-workflow-fanout
qqqys Aug 19, 2026
9d7d9d5
fix(review): route the fan-out on what the runtime does, not on a sta…
qqqys Aug 19, 2026
7bcb12b
test(review): pin the /review gate ahead of the structural blocker
qqqys Aug 19, 2026
3b93342
merge: bring upstream/main into feat/review-workflow-fanout
qqqys Aug 21, 2026
eb0b995
fix(review): satisfy main's wider lstatSync mock type in the cleanup …
qqqys Aug 21, 2026
2100dbf
fix(review): bake worktree residue into emit-workflow briefs (#8943)
Aug 21, 2026
0e1098a
Merge remote-tracking branch 'origin/main' into feat/review-workflow-…
Aug 22, 2026
edfa41a
fix(review): fail closed on empty fan-out deliveries (#8943)
Aug 22, 2026
adade5c
Merge remote-tracking branch 'origin/main' into feat/review-workflow-…
Aug 24, 2026
669c141
fix(review): anchor residue fixtures to the fetchedSha contract (#8943)
Aug 24, 2026
fe5b7f0
Merge branch 'main' into feat/review-workflow-fanout
qwen-code-dev-bot Aug 24, 2026
8ebc622
fix(review): dispatch fan-out as review-agent and keep its gate user-…
Aug 24, 2026
253c784
fix(review): fail closed on unsized plans in the workflow routing gat…
Aug 25, 2026
edb4d0c
fix(review): sweep both plan-path spellings of a cleanup target (#8943)
Aug 25, 2026
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
1 change: 1 addition & 0 deletions packages/cli/src/commands/review.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('reviewCommand', () => {
'comment-status',
'load-rules',
'agent-prompt',
'emit-workflow',
'build-test',
'base-tree',
'scratch-tree',
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/commands/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { publishAssetsCommand } from './review/publish-assets.js';
import { resolveAnchorsCommand } from './review/resolve-anchors.js';
import { checkCoverageCommand } from './review/check-coverage.js';
import { agentPromptCommand } from './review/agent-prompt.js';
import { emitWorkflowCommand } from './review/emit-workflow.js';
import { buildTestCommand } from './review/build-test.js';
import { baseTreeCommand } from './review/base-tree.js';
import { scratchTreeCommand } from './review/scratch-tree.js';
Expand Down Expand Up @@ -67,6 +68,7 @@ export const reviewCommand: CommandModule = {
.command(commentStatusCommand)
.command(loadRulesCommand)
.command(agentPromptCommand)
.command(emitWorkflowCommand)
.command(buildTestCommand)
.command(baseTreeCommand)
.command(scratchTreeCommand)
Expand All @@ -90,7 +92,7 @@ export const reviewCommand: CommandModule = {
.command(cleanupCommand)
.demandCommand(
1,
'Specify a subcommand: run, parse-args, match-remote, meta, issue-context, fetch-diff, comment-body, fetch-pr, capture-local, plan-diff, repo-context, pr-context, comment-status, load-rules, agent-prompt, build-test, base-tree, scratch-tree, test-delta, drive, mock-provider, extract-step, script-lint, resolve-anchors, check-coverage, cost-ledger, presubmit, test-efficacy, test-plan, findings, recover-findings, publish-assets, compose-review, save-artifact, submit, or cleanup.',
'Specify a subcommand: run, parse-args, match-remote, meta, issue-context, fetch-diff, comment-body, fetch-pr, capture-local, plan-diff, repo-context, pr-context, comment-status, load-rules, agent-prompt, emit-workflow, build-test, base-tree, scratch-tree, test-delta, drive, mock-provider, extract-step, script-lint, resolve-anchors, check-coverage, cost-ledger, presubmit, test-efficacy, test-plan, findings, recover-findings, publish-assets, compose-review, save-artifact, submit, or cleanup.',
)
.version(false),
handler: () => {
Expand Down
19 changes: 13 additions & 6 deletions packages/cli/src/commands/review/agent-prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1348,8 +1348,12 @@ function fetchedShaOf(report: PlanReport): string | undefined {
* have any. Resolved against the process cwd, like every other use of
* `worktreePath` here: the report stores it repo-relative and review commands
* run from the project root.
*
* Exported for `emit-workflow`, which must probe the tree exactly the way this
* command's handler does: both paths build through `buildLaunch`, and a probe
* only one of them ran is a divergence in the briefs the two paths bake.
*/
function worktreeResidueOf(report: PlanReport): WorktreeResidue {
export function worktreeResidueOf(report: PlanReport): WorktreeResidue {
const wt = report.worktreePath;
if (typeof wt !== 'string' || !wt) return { paths: [], total: 0 };
// Hand over the sha fetch-pr recorded: committing the contamination moves
Expand Down Expand Up @@ -2302,12 +2306,15 @@ export function findingsSection(
* Build one agent's brief and launch prompt, write the brief beside the plan, and
* return the key and the prompt for the caller to record and print.
*
* One body for both callers on purpose: the single-agent path and `--roster` must
* emit byte-identical prompts for the same agent, because the delivery check
* compares agents against records — a drift between the two paths would read as a
* rewritten launch on a run that did everything right.
* One body for every caller on purpose: the single-agent path, `--roster` and
* `emit-workflow` must emit byte-identical prompts for the same agent, because
* the delivery check compares agents against records — a drift between the
* paths would read as a rewritten launch on a run that did everything right.
* Exported for that reason: a caller that rebuilt this would be a second
* implementation of the invariant, and byte-parity would become something a
* test asserts rather than something the code cannot break.
*/
function buildLaunch(
export function buildLaunch(
report: PlanReport,
planPath: string,
spec: {
Expand Down
239 changes: 238 additions & 1 deletion packages/cli/src/commands/review/cleanup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ import { join } from 'node:path';
const mocks = vi.hoisted(() => ({
execFileSync: vi.fn(),
existsSync: vi.fn((_path: string): boolean => false),
// The parameter is declared so the path-dependent implementations the
// symlink and workflow tests install stay assignable to this mock's type.
lstatSync: vi.fn(
(): { isSymbolicLink: () => boolean; isDirectory: () => boolean } => ({
(
_path: string,
): {
isSymbolicLink: () => boolean;
isDirectory: () => boolean;
} => ({
isSymbolicLink: () => false,
isDirectory: () => true,
}),
),
findSymlinkedReviewWorkflowPath: vi.fn((): string | undefined => undefined),
// The return type is declared so `mockReturnValue` can take string arrays —
// the sweep-retention tests hand it the tmp-dir listing.
readdirSync: vi.fn((_path: string): string[] => []),
Expand Down Expand Up @@ -136,6 +144,13 @@ vi.mock('./lib/paths.js', async (importOriginal) => {
tmpFile: (target: string, suffix: string) =>
`/repo/.qwen/tmp/qwen-review-${target}-${suffix}`,
tmpPrefix: (target: string) => `qwen-review-${target}-`,
REVIEW_WORKFLOWS_DIR: '/repo/.qwen/workflows',
findSymlinkedReviewWorkflowPath: mocks.findSymlinkedReviewWorkflowPath,
reviewWorkflowScriptPath: (planPath: string) =>
`/repo/.qwen/workflows/${planPath
.split('/')
.at(-1)!
.replace(/\.json$/u, '.js')}`,
};
});

Expand All @@ -161,6 +176,13 @@ describe('runCleanup', () => {
isDirectory: () => true,
});
mocks.existsSync.mockReturnValue(false);
mocks.findSymlinkedReviewWorkflowPath.mockReturnValue(undefined);
mocks.lstatSync.mockImplementation((path: string) => {
if (path === '/repo/.qwen/workflows') {
return { isSymbolicLink: () => false, isDirectory: () => true };
}
throw Object.assign(new Error('ENOENT'), { code: 'ENOENT' });
});
// Implementations survive clearAllMocks — restore the fail-open throw
// so one retention test's mtimes cannot leak into the next test. The
// readFileSync default is the same story (#9272): a leaked
Expand Down Expand Up @@ -209,6 +231,221 @@ describe('runCleanup', () => {
expect(mocks.clearReviewWorktreeLease).not.toHaveBeenCalled();
});

// `emit-workflow` has to write its generated fan-out script into the
// saved-workflow dir — the Workflow loader refuses anything outside it — and
// that dir is also the user's own saved workflows, where each file is a
// `/<name>` slash command. A review that left one behind would hand the user
// a permanent command for a diff that no longer exists.
it('removes only this target generated fan-out scripts', () => {

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.

Deferred to the next round. The non-PR sweep coverage gap stands: every workflow-removal test runs runCleanup('pr-123'), while local/file reviews are the only shapes that can actually take the workflow path today. A runCleanup('local') removal test asserting the exact derived path (plus a filename target) will land next round.

中文说明

延后到下一轮。非 PR 清扫覆盖缺口属实:所有 workflow 删除测试都跑 runCleanup('pr-123'),而 local/file review 才是当前唯一能走 workflow 路径的形状。下一轮将补 runCleanup('local') 的删除测试(断言精确推导路径,外加文件名 target)。

mocks.execFileSync.mockReturnValue(Buffer.from(''));
mocks.existsSync.mockImplementation(
((p: string) =>
p === '/repo/.qwen/workflows' ||
p === '/repo/.qwen/workflows/qwen-review-pr-123-plan.js' ||
p === '/repo/.qwen/workflows/qwen-review-pr-123-fetch.js') as never,
);
mocks.lstatSync.mockReturnValue({
isSymbolicLink: () => false,
isDirectory: () => false,
});
// The foreign entries sit in the listing an enumeration would read, so a
// future sweep that over-deletes past this target's exact paths turns
// the negative assertions below red instead of seeing an empty dir.
mocks.readdirSync.mockImplementation(((path: string) =>
path === '/repo/.qwen/workflows'
? ['qwen-review-a749ec7145.js', 'qwen-review-checklist.js']
: []) as never);

runCleanup('pr-123');

expect(mocks.rmSync).toHaveBeenCalledWith(
'/repo/.qwen/workflows/qwen-review-pr-123-plan.js',
{ force: true },
);
expect(mocks.rmSync).toHaveBeenCalledWith(
'/repo/.qwen/workflows/qwen-review-pr-123-fetch.js',
{ force: true },
);
expect(mocks.rmSync).not.toHaveBeenCalledWith(
'/repo/.qwen/workflows/qwen-review-a749ec7145.js',
expect.anything(),
);
expect(mocks.rmSync).not.toHaveBeenCalledWith(
'/repo/.qwen/workflows/qwen-review-checklist.js',
expect.anything(),
);
});

it('does not remove a workflow through a symlinked root', () => {
mocks.execFileSync.mockReturnValue(Buffer.from(''));
mocks.refExists.mockReturnValue(false);
mocks.existsSync.mockImplementation(
((p: string) =>
p === '/repo/.qwen/workflows' ||
p === '/repo/.qwen/workflows/qwen-review-pr-123-plan.js' ||
p === '/repo/.qwen/workflows/qwen-review-pr-123-fetch.js') as never,
);
mocks.lstatSync.mockImplementation((path: string) => {
if (
path === '/repo/.qwen/workflows' ||
path === '/repo/.qwen/workflows/qwen-review-pr-123-plan.js' ||
path === '/repo/.qwen/workflows/qwen-review-pr-123-fetch.js'
) {
return {
isSymbolicLink: () => false,
isDirectory: () => path === '/repo/.qwen/workflows',
};
}
throw Object.assign(new Error('ENOENT'), { code: 'ENOENT' });
});
mocks.findSymlinkedReviewWorkflowPath.mockReturnValue(
'/repo/.qwen/workflows',
);

runCleanup('pr-123');

expect(mocks.rmSync).not.toHaveBeenCalledWith(
'/repo/.qwen/workflows/qwen-review-pr-123-plan.js',
expect.anything(),
);
expect(mocks.rmSync).not.toHaveBeenCalledWith(
'/repo/.qwen/workflows/qwen-review-pr-123-fetch.js',
expect.anything(),
);
expect(mocks.writeStderrLine).toHaveBeenCalledWith(
'Skipping workflow cleanup: /repo/.qwen/workflows is a symlink.',
);
expect(mocks.writeStdoutLine).not.toHaveBeenCalledWith(
'Nothing to clean for target "pr-123".',
);
});

it('does not remove a workflow through a symlinked ancestor', () => {
mocks.execFileSync.mockReturnValue(Buffer.from(''));
mocks.refExists.mockReturnValue(false);
mocks.existsSync.mockReturnValue(true);
mocks.findSymlinkedReviewWorkflowPath.mockReturnValue('/repo/.qwen');

runCleanup('pr-123');

expect(mocks.rmSync).not.toHaveBeenCalledWith(
expect.stringContaining('/workflows/'),
expect.anything(),
);
expect(mocks.writeStderrLine).toHaveBeenCalledWith(
'Skipping workflow cleanup: /repo/.qwen is a symlink.',
);
expect(mocks.writeStdoutLine).not.toHaveBeenCalledWith(
'Nothing to clean for target "pr-123".',
);
});

it('does not claim nothing when workflow-root inspection fails', () => {
mocks.execFileSync.mockReturnValue(Buffer.from(''));
mocks.refExists.mockReturnValue(false);
mocks.existsSync.mockImplementation(
((p: string) => p === '/repo/.qwen/workflows') as never,
);
mocks.findSymlinkedReviewWorkflowPath.mockImplementation(() => {
throw new Error('EACCES');
});

runCleanup('pr-123');

expect(mocks.writeStderrLine).toHaveBeenCalledWith(
'Failed to inspect /repo/.qwen/workflows: EACCES',
);
expect(mocks.writeStdoutLine).not.toHaveBeenCalledWith(
'Nothing to clean for target "pr-123".',
);
});

it('unlinks a dangling generated workflow without following it', () => {
const planPath = '/repo/.qwen/workflows/qwen-review-pr-123-plan.js';
const fetchPath = '/repo/.qwen/workflows/qwen-review-pr-123-fetch.js';
mocks.execFileSync.mockReturnValue(Buffer.from(''));
mocks.existsSync.mockImplementation(
((p: string) => p === '/repo/.qwen/workflows') as never,
);
mocks.lstatSync.mockImplementation((path: string) => {
if (path === '/repo/.qwen/workflows' || path === planPath) {
return {
isSymbolicLink: () => path === planPath,
isDirectory: () => path === '/repo/.qwen/workflows',
};
}
throw Object.assign(new Error('ENOENT'), { code: 'ENOENT' });
});

runCleanup('pr-123');

expect(mocks.rmSync).toHaveBeenCalledWith(planPath, { force: true });
expect(mocks.rmSync).not.toHaveBeenCalledWith(fetchPath, expect.anything());
});

it('sweeps this target killed-run temp files, and nothing else', () => {
const planOrphan =
'qwen-review-pr-123-plan.js.8095c532-aaaa-4bbb-8ccc-1234567890ab.tmp';
const fetchOrphan =
'qwen-review-pr-123-fetch.js.91a6d643-bbbb-4ccc-9ddd-234567890abc.tmp';
const foreignOrphan =
'qwen-review-pr-456-plan.js.02b7e754-cccc-4ddd-8eee-34567890abcd.tmp';
mocks.execFileSync.mockReturnValue(Buffer.from(''));
mocks.existsSync.mockImplementation(
((p: string) => p === '/repo/.qwen/workflows') as never,
);
mocks.readdirSync.mockImplementation(((path: string) =>
path === '/repo/.qwen/workflows'
? [planOrphan, fetchOrphan, foreignOrphan, 'qwen-review-checklist.js']
: []) as never);

runCleanup('pr-123');

expect(mocks.rmSync).toHaveBeenCalledWith(
`/repo/.qwen/workflows/${planOrphan}`,
{ force: true },
);
expect(mocks.rmSync).toHaveBeenCalledWith(
`/repo/.qwen/workflows/${fetchOrphan}`,
{ force: true },
);
expect(mocks.rmSync).not.toHaveBeenCalledWith(
`/repo/.qwen/workflows/${foreignOrphan}`,
expect.anything(),
);
expect(mocks.rmSync).not.toHaveBeenCalledWith(
'/repo/.qwen/workflows/qwen-review-checklist.js',
expect.anything(),
);
});

it('does not claim nothing when generated-workflow inspection fails', () => {
const planPath = '/repo/.qwen/workflows/qwen-review-pr-123-plan.js';
mocks.execFileSync.mockReturnValue(Buffer.from(''));
mocks.refExists.mockReturnValue(false);
mocks.existsSync.mockImplementation(
((p: string) => p === '/repo/.qwen/workflows') as never,
);
mocks.lstatSync.mockImplementation((path: string) => {
if (path === '/repo/.qwen/workflows') {
return { isSymbolicLink: () => false, isDirectory: () => true };
}
if (path === planPath) {
throw new Error('EACCES');
}
throw Object.assign(new Error('ENOENT'), { code: 'ENOENT' });
});

runCleanup('pr-123');

expect(mocks.writeStderrLine).toHaveBeenCalledWith(
`Failed to inspect ${planPath}: EACCES`,
);
expect(mocks.writeStdoutLine).not.toHaveBeenCalledWith(
'Nothing to clean for target "pr-123".',
);
});

it('clears the lease when cleanup succeeds', () => {
mocks.execFileSync.mockReturnValue(Buffer.from(''));

Expand Down
Loading
Loading