Skip to content

Commit 6fdfe11

Browse files
committed
chore(patches): mirror the arch-docs test change into patches/ds-bot/files
1 parent 7af546b commit 6fdfe11

2 files changed

Lines changed: 68 additions & 4 deletions

File tree

‎core/test/check-arch-docs.test.js‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ test('#3322: a pull request needs the trailer in the branch commits and in its o
151151
assert.deepEqual(bodyOnly.trailer, { log: false, body: true, event: 'pull_request' });
152152
// Neither: red as before.
153153
assert.equal(gate().ok, false);
154-
// A merge-queue entry and a local run keep judging the log alone.
155-
for (const event of [{ name: 'merge_group' }, undefined]) {
154+
// A merge-queue entry and a local run keep judging the log alone. `null` is "no event supplied":
155+
// `undefined` is the default parameter, which reads the runner's own event (#3329).
156+
for (const event of [{ name: 'merge_group' }, null]) {
156157
const entry = filesNeedDocs({
157158
ref: 'HEAD',
158159
map,
@@ -162,13 +163,44 @@ test('#3322: a pull request needs the trailer in the branch commits and in its o
162163
event,
163164
});
164165
assert.equal(entry.ok, true);
166+
assert.equal(entry.trailer.event, event?.name ?? 'local');
165167
}
166168
// The documented remedy still works: the subsystem doc in the same pull request.
167169
assert.equal(gate({ changed: () => true }).ok, true);
168170
// No owned file changed: nothing to document, whatever the event says.
169171
assert.equal(gate({ files: ['README.md'] }).ok, true);
170172
});
171173

174+
// #3329: a `pull_request` run whose event cannot be read must fail closed, and only an explicit
175+
// `null` says "no event". The default parameter is the runner's own event, so the case above used to
176+
// read the ambient pull request and depended on that pull request's body having the trailer.
177+
test('#3329: an unreadable pull_request event fails closed', async (t) => {
178+
const { filesNeedDocs } = await import('../scripts/check-arch-docs.mjs');
179+
const savedName = process.env.GITHUB_EVENT_NAME;
180+
const savedPath = process.env.GITHUB_EVENT_PATH;
181+
t.after(() => {
182+
if (savedName === undefined) delete process.env.GITHUB_EVENT_NAME;
183+
else process.env.GITHUB_EVENT_NAME = savedName;
184+
if (savedPath === undefined) delete process.env.GITHUB_EVENT_PATH;
185+
else process.env.GITHUB_EVENT_PATH = savedPath;
186+
});
187+
process.env.GITHUB_EVENT_NAME = 'pull_request';
188+
process.env.GITHUB_EVENT_PATH = join(tmpdir(), 'no-such-arch-docs-event.json');
189+
const map = new Map([['demo', { path: 'docs/subsystems/demo.md', ownedPaths: ['core/x.js'] }]]);
190+
const run = (logText) => filesNeedDocs({ ref: 'HEAD', map, files: ['core/x.js'], changed: () => false, logText });
191+
const noTrailer = run('');
192+
assert.equal(noTrailer.ok, false, 'an unreadable body counts as no trailer, never as a pass');
193+
assert.deepEqual(noTrailer.trailer, { log: false, body: false, event: 'pull_request' });
194+
const commitOnly = run('Docs-not-needed: comments only');
195+
assert.equal(commitOnly.ok, false, 'a branch-commit trailer alone cannot prove the body it cannot read');
196+
assert.deepEqual(commitOnly.trailer, { log: true, body: false, event: 'pull_request' });
197+
// With no event at all this is a local run: no second place exists, so the log decides.
198+
delete process.env.GITHUB_EVENT_NAME;
199+
const local = run('Docs-not-needed: comments only');
200+
assert.equal(local.ok, true);
201+
assert.equal(local.trailer.event, 'local');
202+
});
203+
172204
test('#3322: the refusal names the place where the trailer is missing', async () => {
173205
const { failureLines } = await import('../scripts/check-arch-docs.mjs');
174206
const missing = [{ file: 'core/x.js', subsystem: 'demo', doc: join(tmpdir(), 'docs/subsystems/demo.md') }];

‎patches/ds-bot/files/test/check-arch-docs.test.js‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ test('#3322: a pull request needs the trailer in the branch commits and in its o
151151
assert.deepEqual(bodyOnly.trailer, { log: false, body: true, event: 'pull_request' });
152152
// Neither: red as before.
153153
assert.equal(gate().ok, false);
154-
// A merge-queue entry and a local run keep judging the log alone.
155-
for (const event of [{ name: 'merge_group' }, undefined]) {
154+
// A merge-queue entry and a local run keep judging the log alone. `null` is "no event supplied":
155+
// `undefined` is the default parameter, which reads the runner's own event (#3329).
156+
for (const event of [{ name: 'merge_group' }, null]) {
156157
const entry = filesNeedDocs({
157158
ref: 'HEAD',
158159
map,
@@ -162,13 +163,44 @@ test('#3322: a pull request needs the trailer in the branch commits and in its o
162163
event,
163164
});
164165
assert.equal(entry.ok, true);
166+
assert.equal(entry.trailer.event, event?.name ?? 'local');
165167
}
166168
// The documented remedy still works: the subsystem doc in the same pull request.
167169
assert.equal(gate({ changed: () => true }).ok, true);
168170
// No owned file changed: nothing to document, whatever the event says.
169171
assert.equal(gate({ files: ['README.md'] }).ok, true);
170172
});
171173

174+
// #3329: a `pull_request` run whose event cannot be read must fail closed, and only an explicit
175+
// `null` says "no event". The default parameter is the runner's own event, so the case above used to
176+
// read the ambient pull request and depended on that pull request's body having the trailer.
177+
test('#3329: an unreadable pull_request event fails closed', async (t) => {
178+
const { filesNeedDocs } = await import('../scripts/check-arch-docs.mjs');
179+
const savedName = process.env.GITHUB_EVENT_NAME;
180+
const savedPath = process.env.GITHUB_EVENT_PATH;
181+
t.after(() => {
182+
if (savedName === undefined) delete process.env.GITHUB_EVENT_NAME;
183+
else process.env.GITHUB_EVENT_NAME = savedName;
184+
if (savedPath === undefined) delete process.env.GITHUB_EVENT_PATH;
185+
else process.env.GITHUB_EVENT_PATH = savedPath;
186+
});
187+
process.env.GITHUB_EVENT_NAME = 'pull_request';
188+
process.env.GITHUB_EVENT_PATH = join(tmpdir(), 'no-such-arch-docs-event.json');
189+
const map = new Map([['demo', { path: 'docs/subsystems/demo.md', ownedPaths: ['core/x.js'] }]]);
190+
const run = (logText) => filesNeedDocs({ ref: 'HEAD', map, files: ['core/x.js'], changed: () => false, logText });
191+
const noTrailer = run('');
192+
assert.equal(noTrailer.ok, false, 'an unreadable body counts as no trailer, never as a pass');
193+
assert.deepEqual(noTrailer.trailer, { log: false, body: false, event: 'pull_request' });
194+
const commitOnly = run('Docs-not-needed: comments only');
195+
assert.equal(commitOnly.ok, false, 'a branch-commit trailer alone cannot prove the body it cannot read');
196+
assert.deepEqual(commitOnly.trailer, { log: true, body: false, event: 'pull_request' });
197+
// With no event at all this is a local run: no second place exists, so the log decides.
198+
delete process.env.GITHUB_EVENT_NAME;
199+
const local = run('Docs-not-needed: comments only');
200+
assert.equal(local.ok, true);
201+
assert.equal(local.trailer.event, 'local');
202+
});
203+
172204
test('#3322: the refusal names the place where the trailer is missing', async () => {
173205
const { failureLines } = await import('../scripts/check-arch-docs.mjs');
174206
const missing = [{ file: 'core/x.js', subsystem: 'demo', doc: join(tmpdir(), 'docs/subsystems/demo.md') }];

0 commit comments

Comments
 (0)