Skip to content

Commit 30d148b

Browse files
committed
improvement(ci): scope reviewed root audits to their checks
1 parent e46bc84 commit 30d148b

3 files changed

Lines changed: 119 additions & 39 deletions

File tree

‎.github/CI.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ The `changes` job runs Turborepo 2.11.10's `affectedTasks` query before installi
44

55
A PR compares the checked-out GitHub merge commit with its first parent: the actual target revision tested by that merge. The PR event's base SHA can become stale when the target advances. Scoping requires a matching GitHub merge ref and SHA, exactly two merge parents, and a usable target parent; otherwise every check runs. This works with the existing depth-two checkout without fetching older ancestry. Main/staging pushes execute all checks; the parent `ci` workflow skips checks on `dev` pushes, while PRs targeting `dev` still run checks. A manual `checks` run executes all checks unless supplied a full base commit SHA to reproduce a scoped plan. Missing history, an empty diff, unknown files outside the workspace graph, root script/CI changes, or a planner error run every check. Missing selection outputs fail the aggregate gate. The gate also rejects an omitted dependency, any failed/cancelled job, and any skip that its explicit selection flag did not authorize.
66

7+
Changes exclusively to the reviewed library-content or utils-enforcement audit scripts and their adjacent tests run the always-on lint/audit gate and the complete root script test suite on one GitHub runner. They do not change application runtime. Mixed changes, deleted inputs, unknown scripts, and CI or generator changes retain full fallback. The attribution artifact records this explicit audit-only owner.
8+
79
Dedicated docs verification uses the same planner, comparing pushes with their previous commit and PRs with the tested merge's first parent. Site acceptance follows `docs#build` and its transitive package dependencies. The app's docs-consumer task depends on server runtime and that docs build: backend-only changes run the platform consumer against the docs app, while site changes also run corpus and browser checks. Standalone package and unit-only edits skip those production jobs. The required `docs HTTP` gate verifies explicit site/platform selections before accepting any skip.
810

911
Docs production builds run once and publish an artifact to isolated HTTP, corpus, Chromium, and WebKit jobs. Source checks keep their own checkout because generator verification mutates inputs. Content caches use separate lint/source/build namespaces; generation validates every restore, repairs missing declarations, and removes obsolete modules. The Next build cache keeps its supported incremental behavior. Content and Next caches have size limits, and Next cache files expire after seven days; successful content eviction happens after all consumers finish.

‎scripts/ci-changes.test.ts‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,69 @@ afterEach(() => {
172172
for (const repo of fixtures.splice(0)) rmSync(repo, { recursive: true, force: true })
173173
})
174174
describe('CI task attribution through real Turborepo', () => {
175+
describe('reviewed root audits', () => {
176+
it.each([
177+
{ files: ['scripts/check-library-content.ts', 'scripts/check-library-content.test.ts'] },
178+
{ files: ['scripts/check-utils-enforcement.test.ts'] },
179+
])('runs audits and script tests without app infrastructure for $files', ({ files }) => {
180+
const plan = classifyFiles(files)
181+
expect(plan.fallback).toBeUndefined()
182+
expect(plan.flags).toEqual({
183+
docs: false,
184+
docs_site: false,
185+
docs_platform: false,
186+
integration: false,
187+
http: false,
188+
production: false,
189+
e2e_build: false,
190+
desktop_live: false,
191+
test: true,
192+
test_app: false,
193+
build: false,
194+
})
195+
expect(groups(plan)).toEqual([])
196+
expect(plan.testPackages).toEqual([])
197+
expect(plan.typecheckPackages).toEqual([])
198+
expect(plan.docsGroups).toEqual([])
199+
})
200+
it.each(['apps/sim/lib/server.ts', 'scripts/check-example.ts', 'AGENTS.md'])(
201+
'runs everything when a reviewed audit changes alongside %s',
202+
(file) => {
203+
const plan = classifyFiles(['scripts/check-library-content.ts', file])
204+
expect(plan.fallback).toBeDefined()
205+
expect(Object.values(plan.flags).every(Boolean)).toBe(true)
206+
}
207+
)
208+
it.each(['delete', 'move'])('runs everything for a reviewed audit %s', (operation) => {
209+
const { repo } = fixture()
210+
const file = 'scripts/check-library-content.ts'
211+
write(repo, file, 'export const audit = true\n')
212+
git(repo, 'add', '-A')
213+
git(repo, 'commit', '--quiet', '-m', 'audit owner')
214+
const base = git(repo, 'rev-parse', 'HEAD')
215+
if (operation === 'delete') git(repo, 'rm', file)
216+
else git(repo, 'mv', file, 'scripts/unknown-audit.ts')
217+
git(repo, 'commit', '--quiet', '-am', 'remove audit owner')
218+
const plan = classify(repo, base)
219+
expect(plan.fallback).toBeDefined()
220+
expect(Object.values(plan.flags).every(Boolean)).toBe(true)
221+
})
222+
it('requires PR merge provenance even for a reviewed audit', () => {
223+
const { repo, base, environment } = pullRequestFixture(['scripts/check-library-content.ts'])
224+
const plan = classify(repo, base, { ...environment, GITHUB_REF: 'refs/heads/staging' })
225+
expect(plan.fallback).toBeDefined()
226+
expect(Object.values(plan.flags).every(Boolean)).toBe(true)
227+
})
228+
it('keeps unscoped pushes full even for a reviewed audit', () => {
229+
const { repo } = fixture()
230+
write(repo, 'scripts/check-library-content.ts', 'export const audit = true\n')
231+
git(repo, 'add', '-A')
232+
git(repo, 'commit', '--quiet', '-m', 'audit change')
233+
const plan = classify(repo, '', { GITHUB_EVENT_NAME: 'push' })
234+
expect(plan.fallback).toBeDefined()
235+
expect(Object.values(plan.flags).every(Boolean)).toBe(true)
236+
})
237+
})
175238
it('scopes a shallow multi-commit PR against its tested target after the event base goes stale', () => {
176239
const files = ['packages/sim-setup/src/index.ts', 'packages/sim-setup/src/second.ts']
177240
const { repo, base, target, environment } = pullRequestFixture(files)

‎scripts/ci-plan.ts‎

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { spawnSync } from 'node:child_process'
2-
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
2+
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
33
import { tmpdir } from 'node:os'
44
import { join, resolve } from 'node:path'
55

@@ -23,6 +23,13 @@ interface QueryResult {
2323
docsSite: { items: { fullName: string }[] }
2424
}
2525
}
26+
/** These audit-only inputs belong to lint and test:scripts, rather than application runtime. */
27+
const ROOT_AUDIT_INPUTS = new Set([
28+
'scripts/check-library-content.ts',
29+
'scripts/check-library-content.test.ts',
30+
'scripts/check-utils-enforcement.ts',
31+
'scripts/check-utils-enforcement.test.ts',
32+
])
2633
const root = process.cwd()
2734
const suites: { http: Suite[]; production: Suite[] } = JSON.parse(
2835
readFileSync(resolve(root, '.github/ci-suites.json'), 'utf8')
@@ -31,6 +38,7 @@ const sourceBase = process.argv[2]
3138
let files: string[] = []
3239
let tasks: ChangedTask[] = []
3340
let docsSiteChanged = false
41+
let rootAuditOnly = false
3442
let base = sourceBase
3543
let fallback: string | undefined
3644

@@ -66,42 +74,47 @@ try {
6674
.split('\0')
6775
.filter(Boolean)
6876
if (files.length === 0) throw new Error('Empty diff; verify the complete suite')
69-
if (files.some((file) => /^(\.github\/|scripts\/)/.test(file)))
70-
throw new Error('CI orchestration or root scripts changed')
71-
const temp = mkdtempSync(join(tmpdir(), 'sim-ci-plan-'))
72-
let result: QueryResult
73-
try {
74-
const variables = join(temp, 'variables.json')
75-
writeFileSync(variables, JSON.stringify({ base, head: 'HEAD' }))
76-
result = JSON.parse(
77-
command('turbo', ['query', '.github/scripts/ci-plan.gql', '--variables', variables])
78-
)
79-
} finally {
80-
rmSync(temp, { recursive: true, force: true })
81-
}
82-
if (
83-
result.errors?.length ||
84-
!Array.isArray(result.data?.affectedTasks?.items) ||
85-
!Array.isArray(result.data?.docsSite?.items) ||
86-
!Array.isArray(result.data?.packages?.items)
87-
)
88-
throw new Error('Turborepo did not return a complete task plan')
89-
const workspacePaths = result.data.packages.items
90-
.filter((pkg) => pkg.name !== '//')
91-
.map((pkg) => `${pkg.path}/`)
92-
const guidance = /^(\.agents|\.claude|\.cursor)\/|(^|\/)(AGENTS|CLAUDE)\.md$|^README\.md$/
93-
const unowned = files.find(
94-
(file) => !guidance.test(file) && !workspacePaths.some((path) => file.startsWith(path))
77+
rootAuditOnly = files.every(
78+
(file) => ROOT_AUDIT_INPUTS.has(file) && existsSync(resolve(root, file))
9579
)
96-
if (unowned) throw new Error(`Changed file outside the workspace graph: ${unowned}`)
97-
tasks = result.data.affectedTasks.items
98-
if (
99-
tasks.some(
100-
(task) => typeof task.fullName !== 'string' || typeof task.package?.name !== 'string'
80+
if (!rootAuditOnly) {
81+
if (files.some((file) => /^(\.github\/|scripts\/)/.test(file)))
82+
throw new Error('CI orchestration or root scripts changed')
83+
const temp = mkdtempSync(join(tmpdir(), 'sim-ci-plan-'))
84+
let result: QueryResult
85+
try {
86+
const variables = join(temp, 'variables.json')
87+
writeFileSync(variables, JSON.stringify({ base, head: 'HEAD' }))
88+
result = JSON.parse(
89+
command('turbo', ['query', '.github/scripts/ci-plan.gql', '--variables', variables])
90+
)
91+
} finally {
92+
rmSync(temp, { recursive: true, force: true })
93+
}
94+
if (
95+
result.errors?.length ||
96+
!Array.isArray(result.data?.affectedTasks?.items) ||
97+
!Array.isArray(result.data?.docsSite?.items) ||
98+
!Array.isArray(result.data?.packages?.items)
10199
)
102-
)
103-
throw new Error('Malformed task attribution')
104-
docsSiteChanged = result.data.docsSite.items.some((task) => task.fullName === 'docs#build')
100+
throw new Error('Turborepo did not return a complete task plan')
101+
const workspacePaths = result.data.packages.items
102+
.filter((pkg) => pkg.name !== '//')
103+
.map((pkg) => `${pkg.path}/`)
104+
const guidance = /^(\.agents|\.claude|\.cursor)\/|(^|\/)(AGENTS|CLAUDE)\.md$|^README\.md$/
105+
const unowned = files.find(
106+
(file) => !guidance.test(file) && !workspacePaths.some((path) => file.startsWith(path))
107+
)
108+
if (unowned) throw new Error(`Changed file outside the workspace graph: ${unowned}`)
109+
tasks = result.data.affectedTasks.items
110+
if (
111+
tasks.some(
112+
(task) => typeof task.fullName !== 'string' || typeof task.package?.name !== 'string'
113+
)
114+
)
115+
throw new Error('Malformed task attribution')
116+
docsSiteChanged = result.data.docsSite.items.some((task) => task.fullName === 'docs#build')
117+
}
105118
} catch (error) {
106119
fallback = String(error)
107120
}
@@ -141,7 +154,7 @@ const flags = {
141154
production: production.length > 0,
142155
e2e_build: http.length > 0 || production.length > 0 || desktopLive,
143156
desktop_live: desktopLive,
144-
test: appTest || packages.length > 0,
157+
test: rootAuditOnly || appTest || packages.length > 0,
145158
test_app: appTest,
146159
build: affected('build'),
147160
}
@@ -159,6 +172,7 @@ const report = {
159172
head: command('git', ['rev-parse', 'HEAD']),
160173
files,
161174
fallback,
175+
rootAuditOnly,
162176
tasks,
163177
flags,
164178
http,
@@ -169,9 +183,10 @@ const report = {
169183
}
170184
if (process.env.CI_PLAN_PATH)
171185
writeFileSync(process.env.CI_PLAN_PATH, `${JSON.stringify(report, null, 2)}\n`)
172-
process.stderr.write(
173-
`${fallback ? `Full CI: ${fallback}` : `Affected CI: ${tasks.map((task) => task.fullName).join(', ') || 'no executable tasks'}`}\n`
174-
)
186+
const attribution = rootAuditOnly
187+
? 'reviewed root audits and script tests'
188+
: tasks.map((task) => task.fullName).join(', ') || 'no executable tasks'
189+
process.stderr.write(`${fallback ? `Full CI: ${fallback}` : `Affected CI: ${attribution}`}\n`)
175190
process.stdout.write(
176191
Object.entries(outputs)
177192
.map(([key, value]) => `${key}=${value}\n`)

0 commit comments

Comments
 (0)