diff --git a/packages/vx/src/cli/why.ts b/packages/vx/src/cli/why.ts index 1024737713..0337bec05e 100644 --- a/packages/vx/src/cli/why.ts +++ b/packages/vx/src/cli/why.ts @@ -264,6 +264,10 @@ async function resolveTarget( if (matches.length > 1) { throw ambiguousTask('why', target, matches) } + // Asked outside the one project declaring it, a group read as a task + // that never ran, pointed at `vx last --stats`. + const kind = await declared() + if (kind === 'group' || kind === 'no-op task') throw groupRefusal(target, kind) } const ids = new LocalHistoryProvider(db).recentTaskIds() const invoked = ids.length === 0 && db.query('SELECT 1 FROM invocations LIMIT 1').get() !== null diff --git a/packages/vx/tests/why.test.ts b/packages/vx/tests/why.test.ts index 4740f2aa98..0a596c94ad 100644 --- a/packages/vx/tests/why.test.ts +++ b/packages/vx/tests/why.test.ts @@ -973,6 +973,9 @@ describe('vx why of a declared task that never ran', () => { for (const [cwd, target, id] of [ [app, 'all', 'app#all'], [root, 'app#all', 'app#all'], + // Bare from the root it read "no recorded runs for task", as if it + // could have run. + [root, 'all', 'all'], ] as const) { const r = await vx(cwd, ['why', target]) expect({ code: r.code, err: r.err }).toEqual({