Skip to content

Commit 417a391

Browse files
fix(lanes): portable POSIX pickaxe pattern for schedule registration (#1414, #1430)
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 46f788a commit 417a391

2 files changed

Lines changed: 61 additions & 3 deletions

File tree

‎scripts/scheduled-lane/health-model.test.ts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,30 @@ describe('lane health', () => {
123123
});
124124
});
125125

126+
function git(cwd: string, args: string[], date?: string): void {
127+
const stamp = date === undefined ? {} : { GIT_AUTHOR_DATE: date, GIT_COMMITTER_DATE: date };
128+
runCmdSync('git', args, { cwd, timeoutMs: 30_000, env: { ...process.env, ...stamp } });
129+
}
130+
131+
/** A workflow that exists for a year, then gains a `schedule:` trigger — the transition that broke. */
132+
function repoWithLaterSchedule(): { dir: string; scheduledAt: string } {
133+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'lane-git-'));
134+
temporaryDirs.push(dir);
135+
const workflowDir = path.join(dir, '.github/workflows');
136+
const file = path.join(workflowDir, 'old.yml');
137+
fs.mkdirSync(workflowDir, { recursive: true });
138+
git(dir, ['init', '--quiet', '--initial-branch=main']);
139+
git(dir, ['config', 'user.email', '[email protected]']);
140+
git(dir, ['config', 'user.name', 'Lane Test']);
141+
fs.writeFileSync(file, 'name: Old\non:\n workflow_dispatch:\njobs: {}\n');
142+
git(dir, ['add', '.']);
143+
git(dir, ['commit', '--quiet', '-m', 'add workflow'], '2025-01-02T03:04:05+00:00');
144+
fs.writeFileSync(file, 'name: Old\non:\n schedule:\n - cron: "0 3 * * *"\njobs: {}\n');
145+
git(dir, ['add', '.']);
146+
git(dir, ['commit', '--quiet', '-m', 'schedule it'], '2026-06-07T08:09:10+00:00');
147+
return { dir, scheduledAt: '2026-06-07T08:09:10+00:00' };
148+
}
149+
126150
describe('schedule registration', () => {
127151
// Anchored on the commit that introduced `schedule:`, not the workflow's creation date.
128152
it('reads when a lane was scheduled out of git history', () => {
@@ -131,6 +155,29 @@ describe('schedule registration', () => {
131155
expect(Number.isFinite(Date.parse(scheduled ?? ''))).toBe(true);
132156
});
133157

158+
// The pattern must be POSIX (`[[:space:]]`, not `\s`): the shorthand matches nothing on macOS,
159+
// and a silent no-match is indistinguishable from "cannot tell" — every lane stuck pending.
160+
it('finds the schedule commit, not the workflow creation commit', () => {
161+
const { dir, scheduledAt } = repoWithLaterSchedule();
162+
const scheduled = scheduleRegisteredAt('.github/workflows', 'old.yml', dir);
163+
expect(scheduled).not.toBeNull();
164+
expect(Date.parse(scheduled ?? '')).toBe(Date.parse(scheduledAt));
165+
expect(Date.parse(scheduled ?? '')).toBeGreaterThan(Date.parse('2025-01-02T03:04:05+00:00'));
166+
});
167+
168+
it('keeps that lane pending right after scheduling, and only alerts two cadences later', () => {
169+
const { dir, scheduledAt } = repoWithLaterSchedule();
170+
const history = {
171+
known: true,
172+
scheduleRegisteredAt: scheduleRegisteredAt('.github/workflows', 'old.yml', dir),
173+
runs: [],
174+
};
175+
const scheduled = Date.parse(scheduledAt);
176+
const hour = 60 * 60 * 1000;
177+
expect(laneHealth(NIGHTLY, history, scheduled + hour).state).toBe('pending');
178+
expect(laneHealth(NIGHTLY, history, scheduled + 49 * hour).state).toBe('dark');
179+
});
180+
134181
it('returns null — never a guess — for a file git knows nothing about', () => {
135182
expect(scheduleRegisteredAt('.github/workflows', 'no-such-workflow.yml')).toBeNull();
136183
});

‎scripts/scheduled-lane/schedule-registration.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,24 @@
88

99
import { runCmdSync } from '../../src/utils/exec.ts';
1010

11+
/**
12+
* POSIX character class, not the `\s` shorthand: git's pickaxe regex goes through the platform's
13+
* POSIX engine, where BSD/macOS does not understand `\s` and silently matches nothing — which would
14+
* pin every lane to `pending` forever on a macOS checkout.
15+
*/
16+
const SCHEDULE_KEY = '^[[:space:]]*schedule:';
17+
1118
/** Commit date of the newest commit that changed the number of `schedule:` occurrences. */
12-
export function scheduleRegisteredAt(workflowDir: string, workflow: string): string | null {
19+
export function scheduleRegisteredAt(
20+
workflowDir: string,
21+
workflow: string,
22+
cwd?: string,
23+
): string | null {
1324
const file = `${workflowDir}/${workflow}`;
1425
const result = runCmdSync(
1526
'git',
16-
['log', '-1', '--format=%cI', '--pickaxe-regex', '-S', '^\\s*schedule:', '--', file],
17-
{ timeoutMs: 10_000, allowFailure: true },
27+
['log', '-1', '--format=%cI', '--pickaxe-regex', '-S', SCHEDULE_KEY, '--', file],
28+
{ timeoutMs: 10_000, allowFailure: true, cwd },
1829
);
1930
if (result.exitCode !== 0) return null;
2031
const date = result.stdout.trim();

0 commit comments

Comments
 (0)