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
12 changes: 10 additions & 2 deletions packages/cli/src/commands/review/lib/authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,19 @@ export function reviewWriteAuthorization(req: WriteAuthorizationRequest): {
} catch {
// No args file means no arguments — which means no `--comment`. Fail
// closed: a missing authorisation record is not an absent objection.
// The wording must not send a setting-driven operator to type a flag
// they never needed: with `review.comment` on, the real blocker is that
// no recorded invocation names a pull request to bind the write to, and
// a plain re-run of the review fixes that — typing `--comment` does not.
return {
ok: false,
why:
`no review arguments were recorded at ${path}, so this run cannot ` +
'show that `--comment` was requested',
req.defaultComment === true
? `no review arguments were recorded at ${path}, so no recorded ` +
'invocation names a pull request to bind this write to — re-run ' +
'the review naming the pull request'
Comment thread
wenshao marked this conversation as resolved.
Resolved
: `no review arguments were recorded at ${path}, so this run ` +
'cannot show that `--comment` was requested',
};
}

Expand Down
18 changes: 18 additions & 0 deletions packages/cli/src/commands/review/parse-args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,20 @@ describe('parseReviewArgs — settings-provided defaults', () => {
expect(got.warnings.some((w) => w.includes('review.comment'))).toBe(true);
});

it('a flag-forced high names the flag in the forcing warning, not the setting', () => {
// The flag branch of the same ternary: with no setting enabled, the
// warning must not send the operator hunting a setting that is off.
const got = parseReviewArgs('6711 --comment --effort low');
expect(got.effort).toBe('high');
expect(got.effortSource).toBe('forced-by-comment');
expect(got.warnings).toContain(
'`--comment` requires a verified review; running at high effort.',
);
expect(
got.warnings.some((w) => w.includes('`review.comment` is enabled')),
).toBe(false);
});

it('the standing comment setting stays inert on a local target', () => {
const got = parseReviewArgs('', { comment: true });
expect(got.comment.effective).toBe(false);
Expand Down Expand Up @@ -569,6 +583,10 @@ describe('parseReviewArgs — repeated --effort warnings state what is actually
const invalidWarning = got.warnings.find((w) => w.includes('"typo"'));
expect(invalidWarning).toContain('forces high effort');
expect(invalidWarning).not.toContain('default');
// The flag drove the forcing — the resolution must name the flag, not a
// setting that is off (both branches contain 'forces high effort').
expect(invalidWarning).toContain('`--comment` forces high effort');
expect(invalidWarning).not.toContain('review.comment');
});

it('with no valid occurrence anywhere the warning still says the default applies', () => {
Expand Down
24 changes: 24 additions & 0 deletions packages/cli/src/commands/review/publish-assets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,30 @@ describe('publish-assets', () => {
expect(ghWithInputMock).toHaveBeenCalled();
});

it('the handler refuses when neither flag nor setting authorises — the polluted view must not decide', async () => {
Comment thread
wenshao marked this conversation as resolved.
Resolved
// The refusal counterpart of the wiring leg above: setting off, no
// `--comment` in the recorded arguments. If the handler's loadSettings
// call drops `skipWorkspaceSettings`, the workspace-polluted mock view
// answers comment:true and this refusal becomes a publish — the exact
// regression review-settings.ts documents (a repository-controlled
// .qwen/settings.json deciding to publish for every reviewer).
writeFileSync(argsFile, '8346\n'); // no --comment
reviewSettingsMock.mockReturnValue({}); // setting off
happyGh();
await publishAssetsCommand.handler?.({
_: [],
$0: 'qwen',
pr: 8346,
files: [pngFile('refused.png')],
out: join(dir, 'manifest.json'),
'user-authorized': false,
'skill-args': argsFile,
} as never);
Comment thread
wenshao marked this conversation as resolved.
Resolved
expect(process.exitCode).toBe(3);
expect(ghWithInputMock).not.toHaveBeenCalled();
expect(ghMock).not.toHaveBeenCalled();
});

it('publishes, writes a manifest with commit-pinned URLs', () => {
happyGh();
const f = pngFile('evidence.png');
Expand Down
28 changes: 28 additions & 0 deletions packages/cli/src/commands/review/submit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,34 @@ describe('authorization — URL-shaped host and repo binding at the submit call
'`--comment` was not in the review arguments',
);
});

it('a missing args file names the missing invocation, not a missing flag, when the setting authorises', () => {
// With `review.comment` on, telling the operator to re-run with
// `--comment` misdirects: the blocker is that no recorded invocation
// names a PR, and a plain re-run fixes it. Flag-driven operators keep
// the flag wording — for them the flag IS the missing piece.
const missing = join(dir, 'no-such-args.txt');
const base = {
userAuthorized: false,
skillArgs: missing,
pr: 123,
repo: 'o/r',
};

const bySetting = reviewWriteAuthorization({
...base,
defaultComment: true,
});
expect(bySetting.ok).toBe(false);
expect(bySetting.why).toContain(
'no recorded invocation names a pull request',
);
expect(bySetting.why).not.toContain('`--comment`');

const byFlag = reviewWriteAuthorization(base);
expect(byFlag.ok).toBe(false);
expect(byFlag.why).toContain('cannot show that `--comment` was requested');
Comment thread
wenshao marked this conversation as resolved.
Resolved
});
});

describe('the posting gate', () => {
Expand Down
Loading